BT

JRuby compiler finished

| by Werner Schuster Follow 9 Followers on Sep 28, 2007. Estimated reading time: 2 minutes |
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
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

Adoption Stage
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Tell us what you think

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Congratulations by Zak Mandhro

Congratulations to Charles Nutter and the JRuby team. Excellet work! It just keeps getting better. Java compatibility is great but I am more excited about the potential speed improvements.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Email me replies to any of my messages in this thread

1 Discuss
BT