8. January, 2007
27. June, 2007
in by Michael Neumann

I lately came aross Google Web Toolkit. It’s amazing. Except, well, Java. If you write the server side in Java, perfect! If not, then you have a mixed feeling. But really, it’s a great toolkit, except that I’d like to be more free in how and what is generated, and I’ve not yet understood why they are generating all those files. Then I dislike Java’s package naming which leads to very deeply nested directories (which is okay if you use an IDE).

Then I saw Pyjamas aka py-gwt. Wow! Impressive! Much better to use Python instead of Java. And more important, it’s easier to modify parts of the generator!

I also read about converting Ruby to Javascript as described here.

Before I started my own :). You can get the code from here: http://ntecs.de/hg-projects/. Or use Mercurial to get your own repository:

hg clone static-http://ntecs.de/hg-projects/rubyjs/

So what is RubyJS?

In simple words: It converts Ruby to JS. You have to write some kind of “static” code, i.e. the converter introspects the classes as they are in-memory and then converts this version to Javascript. You cannot neither add/remove methods at runtime nor add classes at runtime. Method calls inside the same class (self as receiver) can be compile-time checked (not yet, but simple to add in one line). Inheritance and Mixins are supported. Compile-time constant lookup. Class methods as well (and inheritance of class methods). My brain still hurts from thinking about Ruby’s Metaclass model. Even the core classes are written in Ruby (with inline JavaScript). Method calls on immediate objects like true, false, nil and numbers are supported. Other objects can be boxed (numbers can be as well if you like). So it converts “1 + 2” into a method call, instead of assuming that JavaScript’s ”+” operator will work right!

Of course a lot is still missing, mainly compiling constrol structure, blocks, instance variables and of course the whole core library.

But it is really cool, because you can use all sort of Ruby’s meta-programming tricks, like “attr_accessor” for free. Or “require”. It executes as Ruby before it is being translated.

Update 1

Instance variables and super calls are now implemented.

Update 2

Compile time selection of method for calls within the same object (includes “super” calls).

Update 3

implemented iterators, while, break