6 ms·
SqueakJS – A Squeak VM in JavaScript
- vaughan 5y agoPS. Based on Smalltalk.
- shaunxcode 5y agothis is super cool. The JS integration is very interesting.
- longhand 5y agoHow so? The functionality was problematic particularly in relation to multi-layer design compliance.
- TheErikOnBike 5y agoCould you elaborate? I do not understand your response in relation to the remark that JS integration is interesting.
- dang 5y agoOnly one small past thread that I could find: SqueakJS – A Squeak VM in JavaScript - https://news.ycombinator.com/item?id=8982251 https://news.ycombinator.com/item?id=8982251 - Feb 2015 (10 comments)
- faraaz98 5y agoSo a VM inside the js VM? Should be fast
- schpaencoder 5y agoit is actually suprisingly fast
- johnisgood 5y agoThe demos are very slow for me. I dunno if I can somehow display it but it feels like ~10 FPS.
- TheErikOnBike 5y agoDid you try different browsers? The speed is very reasonable for me (considering the amount of BitBlt). I use SqueakJS to develop business software (using only Smalltalk). In these applications I am running SqueakJS headless and create a GUI using WebComponents (created through Smalltalk classes). This also runs very fast (tested on Firefox, Chrome and Safari).
- jiriro 5y agoCould you elaborate how this works – Headless SqueakJS plus WebComponents GUI?
- TheErikOnBike 5y agoInstead of having a Smalltalk image which contains the typical GUI (Morphic or otherwise being BitBlt on a HTML Canvas) I run a Smalltalk image which has a number of Classes representing WebComponents. These classes have a small interface with Javascript (implemented as primitive calls in case you are familiar, similar to other SqueakJS plugins). When instantiating such a WebComponent, it will also instantiate a DOM element (the WebComponent). Events in the browser are wrapped in Smalltalk event classes and will be given to an event handler process (Smalltalk process) which will do the relevant work. So for example drag and drop is implemented fully in Smalltalk. The Smalltalk image I run to have this Web UI (and run only a Web UI, no business logic in the browser) is very small. It is only a little over 200Kb. My code is free to use. See https://github.com/ErikOnBike/CodeParadise https://github.com/ErikOnBike/CodeParadise I need to add some more documentation and more demos. I have been very busy with developing software and have been lacking a bit in giving some love to those. Edit: An explanation and demo can be found here: https://vimeo.com/457353130 https://vimeo.com/457353130
- DonHopkins 5y agoOne thing that's amazing about SqueakJS (and one reason this VM inside another VM runs so fast) is the way Vanessa Freudenberg elegantly and efficiently created a hybrid Smalltalk garbage collector that works with the JavaScript garbage collector. SqueakJS: A Modern and Practical Smalltalk That Runs in Any Browser http://www.freudenbergs.de/bert/publications/Freudenberg-2014-SqueakJS.pdf http://www.freudenbergs.de/bert/publications/Freudenberg-201... >The fact that SqueakJS represents Squeak objects as plain JavaScript objects and integrates with the JavaScript garbage collection (GC) allows existing JavaScript code to interact with Squeak objects. This has proven useful during development as we could re-use existing JavaScript tools to inspect and manipulate Squeak objects as they appear in the VM. This means that SqueakJS is not only a “Squeak in the browser”, but also that it provides practical support for using Smalltalk in a JavaScript environment. >[...] a hybrid garbage collection scheme to allow Squeak object enumeration without a dedicated object table, while delegating as much work as possible to the JavaScript GC, [...] >2.3 Cleaning up Garbage >Many core functions in Squeak depend on the ability to enumerate objects of a specific class using the firstInstance and nextInstance primitive methods. In Squeak, this is easily implemented since all objects are contiguous in memory, so one can simply scan from the beginning and return the next available instance. This is not possible in a hosted implementation where the host does not provide enumeration, as is the case for Java and JavaScript. Potato used a weak-key object table to keep track of objects to enumerate them. Other implementations, like the R/SqueakVM, use the host garbage collector to trigger a full GC and yield all objects of a certain type. These are then temporarily kept in a list for enumeration. In JavaScript, neither weak references, nor access to the GC is generally available, so neither option was possible for SqueakJS. Instead, we designed a hybrid GC scheme that provides enumeration while not requiring weak pointer support, and still retaining the benefit of the native host GC. >SqueakJS manages objects in an old and new space, akin to a semi-space GC. When an image is loaded, all objects are created in the old space. Because an image is just a snapshot of the object memory when it was saved, all objects are consecutive in the image. When we convert them into JavaScript objects, we create a linked list of all objects. This means, that as long as an object is in the SqueakJS old-space, it cannot be garbage collected by the JavaScript VM. New objects are created in a virtual new space. However, this space does not really exist for the SqueakJS VM, because it simply consists of Squeak objects that are not part of the old-space linked list. New objects that are dereferenced are simply collected by the JavaScript GC. >When full GC is triggered in SqueakJS (for example because the nextInstance primitive has been called on an object that does not have a next link) a two-phase collection is started. In the first pass, any new objects that are referenced from surviving objects are added to the end of the linked list, and thus become part of the old space. In a second pass, any objects that are already in the linked list, but were not referenced from surviving objects are removed from the list, and thus become eligible for ordinary JavaScript GC. Note also, that we append objects to the old list in the order of their creation, simply by ordering them by their object identifiers (IDs). In Squeak, these are the memory offsets of the object. To be able to save images that can again be opened with the standard Squeak VM, we generate object IDs that correspond to the offset the object would have in an image. This way, we can serialize our old object space and thus save binary compatible Squeak images from SqueakJS. >To implement Squeak’s weak references, a similar scheme can be employed: any weak container is simply added to a special list of root objects that do not let their references survive. If, during a full GC, a Squeak object is found to be only referenced from one of those weak roots, that reference is removed, and the Squeak object is again garbage collected by the JavaScript GC.
- galaxyLogic 5y agoIs it possible to "save the image" in this version?
- TheErikOnBike 5y agoYes it is. It will be stored in the browser using IndexDB. You can download these back onto your computer. See https://squeak.js.org/run/ https://squeak.js.org/run/
- galaxyLogic 5y agoCool. Totally cool, and shows the power of Smalltalk images. You could start a process in the image running in the browser, move the image to your PC and continue the process there.
- ladyattis 5y agoI loved to see a Cuis version of SqueakJS. Just pare it down to its essential classes just to give developers a clean base to experiment with the language on. No e-Toys, no Metacello, etc.
- chazu 5y agoThis. I went down this road for some time before I reached a point with Pharo where I feel comfortable doing things their way.
- alexshendi 5y agoBeen there, done that. You need SqueakJS, a browser an the changes, source and image files for Cuis. Startup is a bit slow, but it works. SqueakJS is just another VM.
- alexshendi 5y agoI should add that I only tried the 32bit images etc. (Cuis*-32.* files).