Standalone Squeak Applications

Smalltalk had, almost since its beginning, to fight against the myth that the creation of stand-alone executables was not possible. While it is true that most Smalltalks, including Squeak, do not compile into native instructions, it is possible for most Smalltalks to combine the virtual machine or runtime system with the virtual image into one file, or to modify the virtual image file so that it can be treated just as if it were an application program.

For Squeak on the Macintosh, a straightforward solution immediately comes to mind: Put the image into the data fork of a file, and put the VM into the resource fork. Voila, there's your double-clickable application.

There is a small problem: On PowerPC Macs, the executable code of the application is also in the data fork. The resource fork only contains a little 'cfrg' resource that tells the program loader where to look for the actual program.

But all is not lost. The PowerPC Mac can still execute 68k code (although at a somewhat lesser speed), and there is a cross-architecture calling mechanism called Mixed Mode. With this, you can call shared libraries from 68k code just as you can from PowerPC code.

Now the design of a double-clickable Squeak application is not so difficult anymore:

  1. The VM is compiled into a shared library.
  2. The library is called from a little 68k 'stub' that goes into the resource fork of the double-clickable application.
  3. The application image is put into the data fork of this application.
Things like this always sound easy... But in this fact, it was actually almost as easy as it sounds. Using MPW 3.2, I could compile a Squeak VM library with minimal changes to the sqMacWindow.c file, and the 68k stub is just a few lines of C code (granted, it does not have error alerts yet) that compiles to less than 4K of 68k code.

For those of you who want to try this, I make the stuff available here. You could use the source to build your own VM library, or you could just download the VM, the stub and a Squeak workspace that copies an image file to the data fork of a copy of the stub.

Hans-Martin

By the way, the primitive 149 mentioned is the start of a Squeak 3D engine. If you'd like to play with it, you can file in TriangleFill.st and execute "WarpBlt colorCircle" in a Workspace.


Binary Files
FileSizeDescription
SqueakVM.bin 144.128 MacBinary II+ encoded shared library containing the Squeak VM, including primitive 149 (triangle filler).
SQstub.bin 3.968MacBinary II+ encoded stub.
C Source Files and Makefiles
FileSizeDescription
sqMacWindow.c 28.476 The file contains a couple of #ifdef SHLIB that generate code for the shared library version of the VM.
SqueakVM.make 1.799 Makefile to generate the SqueakVM. You will probably have to adjust this for your environment.
SQstub.c 903 Source of the stub program. This needs some comments and a reasonable error handling mechanism in case the library is not found.
SQstub.make
Squeak Smalltalk Source Files
FileSizeDescription
CopyToStub.ws 276 A Squeak Workspace to copy an existing image file onto a copy of the stub. Note that you should always use a fresh copy of the stub with an empty data fork, as the code does not clear out the data fork before copying.