Ruby Weekly is a weekly newsletter covering the latest Ruby and Rails news.

llvmruby: A Compiler Toolkit Available to Rubyists

By Peter Cooper / November 27, 2008

red-dragon-ref.png If you've ever investigated how to build your own compiler, you might be familiar with LLVM (Low Level Virtual Machine), a "compiler infrastructure" that makes it easy(ish) to create virtual machines, code generators, and optimizers of your own. It also has its own intermediate representation language that's architecture independent and the instruction sets and typing system available are similarly language independent. In theory, if you want to build your own programming language and a compiler for it, LLVM will get you most of the way.

llvmruby is an attempt to bring LLVM's power into the grasp of Rubyists. LLVM is typically used from C++, but llvmruby lets you use the LLVM compiler infrastructure directly from the Ruby interpreter. It's still pretty new and only a subset of LLVM is currently usable, but it's under semi-active development by Tom Bagby, and as well as a blog, there's also a Github repository you can check out.

On the topic of LLVM, Miura Hideki has developed YARV2LLVM, a YARV (Ruby 1.9's VM) to LLVM translator. While it currently only accepts a tiny subset of Ruby, it's interesting because it uses LLVM's power to compiler YARV into very fast native code. The page is in Japanese, but one of Miura's early benchmarks is not hard to decipher.

Comments

  1. Jan Wedekind says:

    Also note that there is ruby-libjit which is based on libJIT. libJIT is currently under GPL (there are plans to release under LGPL).

  2. Peter Cooper says:

    Bonus points to anyone who gets the relevance of the picture on this post to the topic.. :)

    Jan: Thanks!

  3. Edward OG says:

    @peter Umm... Aho & Ullman’s baby? “Compilers: Principles, Techniques, and Tools”, aka the Dragon Book?

    (Incidentally, I met Ullman last year at CUSEC; what a cool guy.)

  4. Peter Cooper says:

    Wow - you are very quick! You now have "bonus points". Unfortunately, I do not know how to redeem them, but at the very least I am impressed :)

Other Posts to Enjoy

Twitter Mentions