Smalltalk in Java and JavaScript

January 2, 2011

Smalltalk implemented in JavaScript

Smalltalk implemented in JavaScript

http://www.silversmalltalk.com
http://www.silversmalltalk.com/index2.html

On Jan 1, 2011 I successfully ran the first tests of Silver Smalltalk ported to Java and JavaScript.

The image above shows the online test environment for the JavaScript version – see second link above for live demo. Highlight the code, right-click and “Show It”.

Here are some brief details on the timeline:

  • the C# SST source was ported to Java over a period of about two weeks
  • Java version finally compiled Dec 31
  • first test runs Jan 1
  • Jan 1 created a separate Java version for GWT
  • GWT compiled successfully to JavaScript
  • JavaScript runtime is 103kb

There is still very minimal support for reflection in either of the Java or JavaScript versions. Also, no support yet for building classes from a startup file – these will be added over the coming days and weeks.

So, at the moment, the Java/JavaScript Smalltalk interpreters can only handle some basic functions such as arithmetic and primitive class operations.

These are some of the current tests:
3.2 class class class
==> MetaClass

3 + 4 * 5
==> 35

3 + (4 * 5)
==> 23

'hello' + 'world'
==> helloworld

In summary, the Silver Smalltalk environment has been successfully ported to both Java and JavaScript. This includes the parser, compiler, bytecode interpreter, and Smalltalk class system.

The JavaScript version should run in any browser without the need for plugins; and (AFAICT) the Java version should run on any Java VM including the Android Dalvik VM.

Once the bugs have been fixed, these two versions should be able to run the same Smalltalk code and share serialized Smalltalk objects with the Silverlight version.

I will discuss this in more detail in future posts.

Advertisements

9 Responses to “Smalltalk in Java and JavaScript”

  1. Andy Burnett Says:

    And I have just run it on my iPhone 🙂

  2. Steffen Says:

    Hi,

    I really like your Silver Smalltalk project. Unfortunately the JavaScript version does not run in Opera. Do you have any idea why? Are features missing in Opera or is the rendering simply affected by the prefixed CSS attributes?

    Regards, Steffen

    • Peter Fisk Says:

      Hi Steffen,

      I have Opera 11.00 Build 1156 and it works for me.

      One problem that I have had with Opera in the past is that is doesn’t detect the right-click mouse button for context menus.

      If the problem persists, there are other ways to arrange menus (eg pull-down from top of window) so that they don’t use the mouse right-click button.

      There will be a Flash version of STVM released late this month, so that would be another way to fix the problem.

      I know that a lot of people use Opera, so I will do whatever is possible to make STVM work in the Opera environment.

      Cheers

  3. Steffen Says:

    Hi Peter,

    that’s interesting, because I am using that build too. Perhaps it’s somehow Mac related?

    Anyway, great work!
    Steffen

  4. Steffen Says:

    I’ve just played a bit and wonder why the follwing code snipped does not work. Is this a bug or a feature?

    |fac|
    fac := [:n |
    n = 1
    ifTrue: [1]
    ifFalse: [(fac value: (n-1)) * n]].
    fac value: 5

    Cheers!

    • Peter Fisk Says:

      Steffen,

      It looks like a bug.
      The problem occurs in the .Net version as well.

      Thanks for reporting it.

    • Peter Fisk Says:

      Steffen,

      Your example doesn’t work in Squeak Smalltalk either.
      So, the problem is in your code.

      I have added a factorial method to Number class:

      factorial: n
      n 120
      Number factorial: 11.34 => 103164421.480244
      Number factorial: 7 => 5040

  5. Carl Gundel Says:

    Wow, you’ve been busy. Keep it up!

    Happy New Year, BTW! 🙂


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: