While I was at Rails Summit LA 2008 I got interested again in take a look to NekoVM
While talking with Manuel Aristarán last night, I explained to him the coolness factor of mod_tora, what could be the analog of mod_rails (Phusion Passenger) for Neko, but without the nasty fork()
So after eating pizza, we decided to hack something to convert Ruby code to basic Neko language, just for the sake of testing.
Tools involved
NekoVM
Is not only cool that this complete VM was created and maintained by one guy, but it’s even cooler that hey package binaries for most important platforms: Linux, OSX, and of course, Windows.
We downloaded the packages, setup the PATH and LD_LIBRARY_PATH and start playing with Neko compiler (nekoc) ready the docs at the same time.
AST of Ruby
The question was, how to generate the Abstract Syntax Tree of a Ruby program?. That was easy: ParseTree
After digging a bit into the documentation, we found that inheriting from SexpProcessor opens you the door of heaven and unleash the power of ParseTree. We followed Ruby2Ruby implementation jsut to get started.
Something to test
What to test? I wondered how cool will perform my sudoku solver script after going through this converter, but after looking at the Sexp it generates, realized that will take more than a couple of hours of hacking
Going back to basics, we decided to start with a Fibonacci function instead and from there move forward.
Hacking
So we started with the Ruby code and added the required tokens indicated in the sexp to successfully build the code shown below.
You can find the Neko SexpProcessor on github, under nekro project we started.
Performance
Well, I know is just plain silly do a performance comparison between a VM like Ruby with one that couldn’t compare or match all the functionality, but bear with me for a second
| platform | interpreter | version | fib(30) avg sec. |
|---|---|---|---|
| linux | ruby | 1.8.6-p114 | 1.66 |
| linux | rbx | 1.8.6 (1b300ca64) | 1.66 |
| linux | nekovm | 1.8.0 | 0.25 |
| windows (vc6) | ruby | 1.8.6-p114 | 2.39 |
| windows (gcc) | ruby | 1.8.6-p114 | 1.77 |
| windows | nekovm | 1.8.0 | 0.22 |
Get your own conclusions, I’m just playing and experimenting… Thanks Manuel for your time!. I’m going now to the airport, one more flight to catch!
what is rbx?
@roger: rubinius
can you compare it with YARV?
@Joe (hidden Roger): yes, possible, when I update my building scripts I’ll put some numbers.
Anyway, is just fibonacci, not rocket science. The fun was on using ParseTree
That’s true, I didn’t think of that.. If you could do the whole shootout (http://antoniocangiano.com/2007/12/03/the-great-ruby-shootout/) that’d be pretty cool, but I understand it’d take time to get it running on NekoVM.