BT

Javascript as Compiler Target: Clamato, GWT Smalltalk, Python, Scheme

by Werner Schuster on Sep 30, 2009 |

Despite Javascript's ubiquity, it's a hard language to like. Until the advent of VMs like Google's V8, Apple/WebKit's Nitro/SquirrelFish Extreme and Firefox' TraceMonkey, Javascript's performance was abysmal.
Incompatible implementations across browser make development painful as well. Libraries like jQuery and many others offer convenient abstractions and allow to program to one API and even out the incompatibilities.

Another approach to solving the problems is to hide Javascript completely and use it as a compilation target. Google's GWT is a mature example that takes Java code, written to a subset of the Java API, and compiles it into browser specific Javascript. One example of a real world application of GWT is the Google Wave client. Recently, a few more language implementations have joined the trend.

Avi Bryant, creator of the Smalltalk Seaside web framework, has created Clamato, a Smalltalk dialect that compiles to idiomatic Javascript. Avi described the design principles of Clamato in the InfoQ interview with him taped at FutureRuby.

The tutorial page for Clamato allows to open a Clamato (Smalltalk) class browser in the web browser and inspect and edit the Clamato source code. To look for classes, use the text field in the left upper corner of the browser. Interesting bits are the selfhosting PEG-based Clamato parser (enter "PP" in the textfield to see the classes for the parser and the various combinators).
A certain Seaside influence is visible in the Seaside-style HTML builder (the HTMLCanvas class in the Clamato browser). Visual components can use it to build their GUIs, for instance, the counter component from the tutorial:

 
renderOn: html
  html h3 with: @counter.
  html button
    with: '+';
    onClick: [@counter := @counter + 1. self reload].
  html button
    with: '-';
    onClick: [@counter := @counter - 1. self reload].

The renderOn: html line defines a new method and the rest of the sample is the method body, which builds the HTML with a header and two buttons, which are set up with event handlers.

As it happens, another browser-based Smalltalk has appeared recently: GWT Smalltalk. The creator Peter Fisk has previously created the .NET and alternatively ActionScript-based Vista Smalltalk.  GWTSmalltalk is written using GWT which generates Javascript that runs in the browser.
GWT Smalltalk is in an early stage right now but progresses quickly. It has support for using XMPP, which puts it in a good place to interact with with Google Wave (XMPP is an essential part of Google Wave). More details are available in the Industry Misinterpretations podcast interview with Peter Fisk and on the GWT Smalltalk blog.

Stepping outside the Smalltalk sphere, Python also has its Javascript compiler in pyjamas:

pyjamas is a stand-alone python to javascript compiler, an AJAX framework / library and a Widget set API

The best place to start is the online pyjamas book.

Another language that compiles to Javascript is Moby Scheme. What makes Moby-Scheme stand out is the way it's targeting mobile devices, for the moment Android, by compiling to Javascript instead. This is possible because of PhoneGap and because Android ships an efficient Javascript VM with its WebKit based browser. PhoneGap is a library that allows Javascript to access native device functionality, such as accelerometers, GPS, cameras, as well as other features such as address books. The creators of PhoneGap built it to bridge all the disparate smartphone devices which have very different programming environments, yet share one thing: WebKit and fast Javascript VMs. By giving Javascript access to device features, cross platform apps are possible for smartphones. See InfoQ's interview with the PhoneGap creators for a thorough overview of PhoneGap.

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

Haxe by Sam Corder

haxe.org/ Haxe also has had Javascript as a compilation target for a few years. It is a nice looking language but has sadly remained on the fringe for a long while.

GWT Scala anyone?! by Stefan Frank

GWT Smalltalk looks promising: I really like the idea of using a language other than java to write GWT-Apps. Alas, Smalltalk wouldn't have been the first language to come to mind: A Scala-Version would be nice and would maybe reduce much of the bloat that currently comes with using Java for setting up widgets...

And aside: cappuccino.org/ certainly belongs in this list: It uses ObjectiveJ, which is a variant of ObjectiveC. It takes some time to get used to it, but the language is a rather good fit for gui-work and it also comes with a complete framework to build browser-based apps. They built 280 Slides with it, on of the best looking browser-based app around...

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

2 Discuss

Educational Content

General Feedback
Bugs
Advertising
Editorial
InfoQ.com and all content copyright © 2006-2014 C4Media Inc. InfoQ.com hosted at Contegix, the best ISP we've ever worked with.
Privacy policy
BT