hoodwink.d enhanced


Marshalling Ruby 2.0 Codes #

by why in inspect

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))

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.

said on 21 Aug 2006 at 04:45

Speaking of Rubyist Magazine, I miss the guest entries from our Japanese brethren that once graced this blog.

More please.

said on 21 Aug 2006 at 06:51

It could be used as an obfuscation method for those who really wanted it though. (At least if/when YARV becomes “the one true way” to run ruby.)

said on 21 Aug 2006 at 08:10

I don’t think that the compile hack would be any faster right now since YARV still has to load the plaintext parser in order to then load the bytecode file. But something interesting about YARV (0.4.1-r519) and speed is that for a couple million random flops, YARV is actually a little over a second faster than plain ruby 1.9/HEAD, and about 4 seconds faster than 1.8.5-r4. I can’t recall ever having a dire need to do alot of random floating point math quickly … but hey, faster is faster. :)

said on 21 Aug 2006 at 09:21

Bil: I think I’d also like to see the other sections besides “inspect” get some love.

said on 21 Aug 2006 at 10:06

Is there an English version of this mag?

said on 21 Aug 2006 at 10:30

Dr Nic: Don’t worry, in the future everyone will speak Ruby. We just have to hope we’re all there soon.

said on 21 Aug 2006 at 15:33

Everyone is here in the future!

said on 22 Aug 2006 at 15:50

Speed’s in the eye of the creater – MIPs is so out of date – it surely doesn’t serve a purpose with Ruby. When i’m writing firmare during the day MIPs fly by the window – but I’m doing more and more and more of the clever stuff at this level. And Ruby proper JIT will be here in good time – if everyone doesn’t sucumb to the petrol-head attitude. My 0.02

said on 23 Aug 2006 at 03:55

MenTaLguY: Especially 5.gets.

said on 23 Aug 2006 at 09:24

Bil: Yeah, totally.

11 Jul 2010 at 21:21

* do fancy stuff in your comment.