Reset ◼
Load image
Step ▹
Run ▶

Return ⬆
Send ⬇︎

Over ▷
Export File...

no image loaded

Break on do-it:
SqueakJS a Lively Squeak VM by Bert Freudenberg
Press "Execute" to step through bytecodes, "Return" to run until returning from the current method.
(work in progress - please visit the SqueakJS project homepage) This VM is inspired by Dan Ingalls' "JSqueak/Potato" VM for Java. It represents regular Squeak objects as Javascript objects with direct object references. SmallIntegers are represented as Javascript numbers, there is no need for tagging. Instance variables and indexable fields are held in a single array named "pointers". Word and byte binary objects store their data in arrays named "bytes" or "words". CompiledMethod instances have both "pointers" and "bytes". Float instances are not stored as words as in Squeak, but have a single "float" property that stores the actual number (and the words are generated on-the-fly when needed). Spur's "immediate" characters are regular objects made unique using a character table. For garbage collection, I came up with a hybrid scheme: the bulk of the work is delegated to the Javascript garbage collector. Only in relatively rare circumstances is a "manual" garbage collection needed. This hybrid GC is a generational GC with an old space and a new space. Old space is a linked list of objects, but newly allocated objects are not added to the list, yet. Therefore, unreferenced new objects will be automatically garbage-collected by Javascript. This is like Squeak's incremental GC, which only looks at objects in new space. The full GC is a regular mark-and-sweep: it's marking all reachable objects (old and new), then unmarked old objects get removed (a very cheap operation in a linked list), and new objects (identified by their missing link) are added to the old-space list. One nice feature of this scheme is that its implementation does not need weak references, which Javascript currently does not support. This scheme also trivially supports object enumeration (Squeak's nextObject/nextInstance primitives): If the object is old, the next object is just the next link in the list. Otherwise, if there are new objects (newSpaceCount > 0) a GC is performed, which creates the next object link. But if newSpaceCount is 0, then this was the last object, and we're done. To avoid having to do a full GC (which needs to scan all objects) we now have a partial GC which only scans new space: instead of starting the mark phase from the system roots we start from "dirty" old objects. Every store operation marks an object "dirty", and only those objects can possibly point to newly created objects. This optimization speeds up new object discovery considerably (5x-10x). Besides the regular bytecode interpreter there is a simple, fast, non-optimizing JIT compiler. It inlines all bytecodes for a method, but sends are not accelerated at all. For major speed gains it would have to avoid a full context activation for each send. Other speed gains come from primitive functions. Several plugins are translated from the original Squeak VM code to JavaScript (see plugins directory), others are hand-coded. The UI for now copies the Squeak display bitmap pixel-by-pixel to a typed array and shows it on the HTML 2D canvas using putImageData(). Clipboard copying injects a synthetic CMD-C keyboard event into the VM, then runs the interpreter until it has executed the clipboard primitive in response, then answers that string. This is because the web browser only allows clipboard access inside the copy/paste event handlers. You can drag files from your disk into this page (including Squeak image files). Files are stored in indexedDB and directory entries in localStorage. Use the "Save File ..." button to get files out. Contributing: The VM source code is on GitHub. Pull requests are very welcome, or send patches to
System Console