hoodwink.d enhanced
RSS
2.0
XHTML
1.0

RedHanded

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

said on

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

More please.

said on

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

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

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

said on

Is there an English version of this mag?

said on

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

said on

Everyone is here in the future!

said on

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

MenTaLguY: Especially 5.gets.

said on

Bil: Yeah, totally.

said on DD Mon YYYY at HH:MM

* do fancy stuff in your comment.

PREVIEW PANE