Implementing Smalltalk in JavaScript

January 28, 2011

The JavaScript implementation of Silver Smalltalk is now working well enough to implement some basic tools. But the code is still very much alpha quality and contains many inelegant “hacks” and undoubtedly numerous bugs as well – it is still weeks away from being production quality.

However, it does work and it proves the feasibility of using Google’s GWT compiler to create a not-so-simple implementation of a Smalltalk interpreter running entirely in JavaScript (GWT converts Java source code to JavaScript).

There are now four separate implementations of the Silver Smalltalk interpreter:
— stvm.exe and stvm.xap in C# for .Net and Silverlight
— stvm.jar in Java targeting Google’s Android
— stvm.swf in ActionScript 3 targeting Flash player and Adobe AIR desktop
— stvm.js in JavaScript target any JavaScript environment (smart phones, tablets, browsers, etc)

My guess is that the JavaScript implementation will prove to be the most popular and the most flexible. Partly this will be due to the continuing performance improvements in the JavaScript language. And partly it will be due to the ability to access many of the new HTML5 features which are beginning to appear in WebKit-based devices. Sencha talks about HTML5 now becoming the *minimum* for mobile devices.

JavaScript can also be easily compiled dynamically in the client device (unlike C#, Java, and AS3). This will allow me to add some extra capabilities to the SST compiler.

1) multi-line compiled JavaScript primitives
currently SST primitives can call external JavaScript functions. I plan to extend this so that primitive methods can consist of multi-line JavaScript code.

2) generation of JavaScript code from Smalltalk
last year, I released GWT Smalltalk which converted Smalltalk code into JavaScript. I will add the same capability to SST/Js. The advantage would be that you could prototype in Smalltalk and produce JavaScript for production (speed, project requirements, etc).

I am *not* saying that any arbitrary Smalltalk code can be converted to JavaScript – there are some well-known issues that make this impossible. However, if the Smalltalk code is very carefully written to avoid these issues, then conversion is feasible – I will discuss this in future posts.

So, it should be largely possible to obtain compiled JavaScript speed within the highly productive Smalltalk development environment.

Advertisements

2 Responses to “Implementing Smalltalk in JavaScript”

  1. Andy Burnett Says:

    How are you planning to integrate backend services with SST? For example, it would be wonderful if the system shipped with the ability to access google docs quickly and easily (i would be perfectly happy if this only existed – to start with – on the GAE hosted version). Ideally I would like to have some google apps classes that talked with e.g. Spreadsheets.

    Do you think this would be something that we would include with the Java interpreter, or would there be a way to call external libraries that might already exist on the server?

    From my perspective, i would always choose simplicity over features, so if this is something that could be wrapped into some SST classes, that would be wonderful.

    • Peter Fisk Says:

      There is nothing required of SST to implement backend services.

      SST can generate HTTP requests and can encode/decode JSON data.

      For example, integrating Google ChannelAPI into SST apps is just a question of having the necessary JavaScript libraries loaded and making HTTP requests – no modifications were needed to the SST interpreter. It will be the same for Google Docs or any other backend service.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: