Reset ◼
Load image
Step ▹
Run ▶


Return ⬆
Send ⬇︎

Over ▷
this

Save File...

no image loaded
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) 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 two 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). 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 semi-space 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. 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 a Squeak image file from your disk into this page to load it. Files are stored in indexedDB and directory entries in localStorage['squeak:/']. Contributing: The VM source code is on GitHub. Pull requests are very welcome, or send patches to bert@freudenbergs.de
SystemBrowser
X

M
N
GitControl
X
M

12:48:02 System console started successfully. 12:48:17 http://lively-web.org/users/bert/SqueakJS/vm.js loaded in 1189 ms 12:48:18 http://lively-web.org/users/bert/SqueakJS/ui.js loaded in 205 ms 12:48:18 Pasted <lively.morphic.World#1 - SqueakJS> 12:48:31 fetching http://lively-web.org/users/bert/SqueakJS/demo/mini.image 12:48:31 Got 602548 bytes from http://lively-web.org/users/bert/SqueakJS/demo/mini.image 12:48:31 loading mini.image (602548 bytes) 12:48:31 squeak: reading objects 12:48:31 squeak: mapping oops 12:48:31 squeak: initializing interpreter 12:48:31 squeak: interpreter ready
System Console
X
M

G
C