Writing a Ruby compiler: Part 2

I finished implementing the most basic instructions (define class, module, method, local variables, Proc, opt_minus, opt_plus, opt_lt). There is not much to say yet, but I ran Fibonacci and at first the results were not so encouraging – For fib(39) I got 15 seconds while YARV got 19. This is not very significant.
But then I only changed that the recursive function was not called through YARV send, but directly (so with a CALL instruction). Now it completed in 4 seconds.
So the biggest benefit is when you are working with compiled classes, because then we can bypass YARV method dispatch. Now even class reopen and redefining methods can work in compiled mode. But only between compiled modules. So in theory even if you have a big project, if you compile everything then you can basically do everything. If one time the compiler would support the full Ruby specs, then we could easily run everything in compiled mode.
Also something to be learned from this is that send in Ruby is not very fast. And all method dispatch is basically done with send in the end.

Advertisements

2 thoughts on “Writing a Ruby compiler: Part 2

  1. Hi,
    I have been thinking in a similar direction lately. After having read a lot of llvm.
    So my approach is somewhat different, no c,but same goal I guess.
    I wrote some stuff on github, where my name is dancinglightning, under crystal.

    If you’re interested we could talk, I didn’t see where this went.

    Torsten

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s