Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

InfoQ Homepage News JRuby compiler finished

JRuby compiler finished

This item in japanese

Charles Nutter has been working on the JRuby Ruby to Java Bytecode compiler for some time - and now it's finished:
I just finished up compilation on BEGIN and END blocks, which brings the compiler to completion. I've also successfully been able to compile the entire standard library and run IRB and RubyGems entirely off compiled scripts (i.e. I deleted all the .rb files).
This completes some of the items in the mentioned in the JRuby 1.1 plans. With this done, JRuby 1.1, scheduled to be released in time for RubyConf 2007 in early November, can be shipped with the compiler.

More details can be found in the blog announcement of the JRuby compiler:
For the first time ever, there is a complete, fully-functional Ruby 1.8 compiler. There have been other compilers announced that were able to handle all Ruby syntax, and perhaps even compile the entire standard library. But they have never gotten to what in my eyes is really "complete": being able to dump the stdlib .rb files and continue running nontrivial applications like IRB or RubyGems. I think I'm allowed to be a little proud of that accomplishment. JRuby has the first complete and functional 1.8-semantics compiler. That's pretty cool.
Another type of compiler is already planned. This is supposed to further facilitate integration between Java and Ruby:
Compiler #2 will basically take a Ruby class in a given file (or multiple Ruby classes, if you so choose) and generate a normal Java type. This type will look and feel like any other Java class:
  • You can instantiate it with a normal new MyClass(arg1, arg2) from Java code
  • You can invoke all its methods with normal Java invocations
  • You can extend it with your own Java classes
This integration also needs some enhancements to make it possible to use these classes from Java. For instance, defining methods with a certain signature. As Ruby doesn't have explicit type information for signatures, some kind of workaround would be needed:
I've been thinking through implementation-independent ways to specify signatures for Ruby methods. The requirement in my mind is that the same code can run in JRuby and any other Ruby without modification, but in JRuby it will gain additional static type signatures for calls from Java. The syntax I'm kicking around right now looks something like this:
class MyClass
{String => [Integer, Array]}
def mymethod(num, ary); end
If you're unfamiliar with it, this is basically just a literal hash syntax. The return type, String, is associated with the types of the two method arguments, Integer and Array. In any normal Ruby implementation, this line would be executed, a hash constructed, and execution would proceed with the hash likely getting quickly garbage collected. However Compiler #2 would encounter these lines in the class body and use them to create method signatures like this:
    public String mymethod(int num, List ary) {

Rate this Article