Marshalling Ruby 2.0 Codes #
We’re all eager to see YARV spout real live bytecode, but ko1 has a fun sort of inbetween option: marshalling arrays containing Ruby 2.0 instructions to an .rbc file. All it is: 4 bytes reading RBCM and then the marshal.
Assuming you have YARV installed with the -yarv suffix, go to the root directory of your checked out source code. We’re interested in rb/compile.rb.
ruby-yarv rb/compile.rb ~/svn/camping/lib/camping.rb -o camping.rbc
This isn’t anything that exciting. The .rbc file will likely be four times the size of your original source. And, in my tests, it’s no quicker to parse. But it is an interesting way to store source code, for sure.
Load it like so:
open("camping.rbc") do |f|
exit "Not really an RBCM!" unless f.read(4) == "RBCM"
iseq = YARVCore::InstructionSequence.load(Marshal.load(f))
iseq.eval
end
This was all covered in issue no. 15 of the Rubyist Magazine, which has a bunch of quick dissections of the instruction set and YARV assembly.

