Scala + GWT

A project to allow Scala source to be compiled by Google Web Toolkit.

We're making some progress!  Well, namely, Hello World is achievable.  But that's a major part of the battle.

Why?

Scala is a strongly typed language that is highly compatible with Java, but improves on it in several respects.  From the GWT developer's perspective:

OK then, Why Not?

The GWT compiler aggressively optimizes the Javascript executables it produces.  It requires a great deal of intelligence about the source code.  It does not simply translate JVM bytecode to Javascript.

Scala code cannot be transformed to strict Java.  It is not possible with present tools to produce bytecode with Scala, decompile it to valid Java, and put the resulting source into GWT, or even to produce valid Java directly from Scala, although the experimental java-src backend gets reasonably close.  Together, these issues make the problem set a little more challenging.

For more discussion of this issue, see this October 2009 thread on google-web-toolkit-contributors, which spawned this project.

Jribble == "Loose Java"

Java source code does not want to be a target language.  It has restrictions against logically sound constructs that would be bad Java practice to write by hand.  Lex Spoon proposed a plan for an intermediate step, "Loose Java," which we have christened Jribble (pronounced "Dribble").

Jribble is essentially Java with the interfering restrictions removed.  Lex: "It's like a puddle of Java. It's also like drivel, which is appropriate enough for a language no one writes and no one reads. Computers can entertain themselves with it well enough."

While far from a spec at this point, the general concepts of Jribble are:

  1. There is no rule in constructors about calling the super() constructor as the syntactically first thing in a constructor.
  2. There is a comma operator expression just like in JavaScript.
  3. Any expression can be used in an expression statement, even useless things like literals.
  4. Types are all Java erased types.
  5. Imports are removed.
  6. Overloading and overriding are as in Java byte code, including override on return type.
  7. Method calls are also as in Java bytecode, and specify the full method signature.

Our efforts so far have been to create a new "jribble" backend to Scala that produces output along these lines, and parallel patches to GWT to understand Jribble input.  As we expose more of the issues through this process, we'll formalize Jribble -- as a spec.  This hopefully will open some doors to translating other languages into a form that GWT can compile and optimize.

The Jribble concept is interesting as a target language, because it's likely to be an effective target for other JVM languages, not only Scala.  Any language that easily produces valid JVM bytecodes, but struggles to produce valid Java, might take advantage of Jribble as a bridge to GWT Javascript compilation.

Participation

Help is always welcome.  The project can use the support and energy of people who understand the technologies involved and problem set, as well as folks who are interested in documenting and testing.  We've opened some valuable infrastructure of late:

Google Code
http://code.google.com/p/scalagwt

Google Group
http://groups.google.com/group/scalagwt

To tweet about how awesome the whole idea is, and how you can't wait to start writing GWT code in Scala, follow @scalagwt,

Great, When Can I Use It?

We're keeping a sample project at http://github.com/rfc2616/scalagwt-sample that contains the latest built jars.  Git the code and off you go.  The build up as of this writing will fake-compile Hello World; after 2 code reviews clear into the repository (Iebf7afc7 and I57c79c6e) -- or build and apply all yourself -- you can compile Hello World for-real.

The Jribble AST is not complete, so simple things like conditionals ("if") still have work to do before they function, but we'll be chipping away at the complete syntax regularly now.  Your help is very welcome.  The object is, of course, to be able to compile a huge amount of the Scala library.

Finally, Grzegorz is optimistic about Dev Mode support, next up on the plan; the underpinnings of this are coming along.