Posted on Oct 19, 2008

Experiment: Ruby to Neko, possible?

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


Is not only cool that this complete VM was created and maintained by one guy, but it’s even cooler that they 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) reading 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 just 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.


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.


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! ๐Ÿ™‚