What does Rubinius.primitive do?

87 views Asked by At

I'm reading through the Rubinius source code, and I keep coming across methods that go something like this:

def self.do_something
  Rubinius.primitive :vm_do_something
  raise SomeError, "primitive failed to do something"
end

For example, kernel/alpha.rb and kernel/bootstrap/rubinius.rb both have a lot of these. They're all over the place, and I can't seem to find where Rubinius.primitive is defined. Since I have no idea what it does, I'm having a lot of trouble understanding how Rubinius gets stuff done.

1

There are 1 answers

0
Michael Francis On BEST ANSWER

I went on IRC at freenode.net #rubinius, and learned that the behavior of Rubinius.primitive is to replace the method it's called in with a call to C++ code. The calls to raise that commonly follow calls to primitive are only executed if primitive somehow fails.