Saturday, March 1, 2014

SimTalk - Smalltalk for Mobile Devices

Ok, the secret is out. I'm busy developing a Smalltalk for Android and (later) iOS devices.  It's a new implementation of Smalltalk from the ground up. Here's what I have and what I'm planning.

I'm currently developing a pure interpreter.  Later I may consider either dynamic compilation or compilation direct to native instructions.  For now, however, the easiest way to start is with a pure bytecode interpreter.  I'm using the same bytecode set as VisualWorks.  This is mostly for convenience. It means that I can use the VisualWorks compiler to create the bytecodes for the new Smalltalk.

I don't yet have garbage collection but I have everything setup to allow me to implement garbage collection. I'll have generation scavenging for new and survivor spaces and mark and sweep for old space.

I'm developing the system using three different languages.  Java is used as a shell (for now) to start the system.  I'll also be using it to perform various primitive operations.  The core of the interpreter itself is written in C under the Android NDK.  It can call back to Java using JNI when needed.  It's the C code that loads the image from an asset and runs the Smalltalk bytecodes.

So far, I can do simple arithmetic, pushing and popping of the stack, message sends and super calls.  Any looping or branching that compiles to bytecodes also works.  I was able to write a non-recursive factorial method that worked well.

The image for the new Smalltalk is generated by VisualWorks and sent to the Android as an asset in the APK file.  When Smalltalk launches, it loads the image then sets up a socket listener and waits for a connection.  At that point, a bytecode debugger I wrote in VisualWorks connects to the image.  This debugger can provide information about the memory spaces, dump the stack, inspect objects (in a fashion), and single step through the bytecodes.

Here's what the debugger looks like so far:

This is a stack trace in the process of evaluating 3 + 4.  It's pushed the 3 and 4 onto the stack and is about to run the + method.  Remember, this is a temporary debugger for me to use at a very low level to make sure all the infrastructure is working.  Ultimately, I intend to tap into the VisualWorks debugger and direct its operations to run on the Android device.

Even though I have 95% of the VisualWorks bytecodes implemented, I'm still far away from getting the system as functional as I would like.  I need to properly implement blocks, add a lot of primitives, and develop a base class library for the new Smalltalk.  It's a lot of work but very exciting.

My current intention is to use this new Smalltalk to develop my own apps for commercial sale.  If, however, other people are interested in developing mobile apps in Smalltalk I can look into ways of licensing the application for others to use.  If this work interests you, drop me a line or leave me a comment.  I'd love to hear your thoughts.  You can also listen to the Independent Misinterpretations podcast episode 164 where I discuss the project with James.


  1. way back when, we ported Squeak to the proto-treos and used it to prototype some UI and System security behaviors. the biggest problem wasn't the VM, but the bit of IO above the VM that was constantly polling. this led to some pretty abysmal battery life.

    i'm unfamiliar with VisualAge beyond some rudimentary toying with the UI, so maybe you'll have a better experienc. in any event, go you! i would love to see a decent mobile smalltalk (or "another decent mobile smalltalk" depending on your definition of the terms "decent" and "mobile" and "smalltalk.")

    godspeed and watch out for polling IO!

  2. At this point, I'm far away from worrying about battery life, but it will be a concern. Fortunately, I have full control over this VM. All the code included is either Smalltalk code, C code or Java code that I've written or standard Android libraries. I should be able to get the IO to work properly. Thanks for the heads up, though. I'll have to watch for that once I get to that stage.

  3. hi! a new vm is not a requirement to execute smalltalk any more.
    try U8 (, it has a big set of framework for integration to web,mobile,.net,console platforms, fast execution and native adaptors (android+ios), complete framework for Cordova, etc.
    Widgets, browser, inspector, etc, used for image(and framework) based multiplatform development.
    U8 let us focus on system development with objects, and not in byetecodes, gc, and other traditional problems and code.