A proof-of-concept page that runs Self entirely in the browser. No server executes user code and nothing is uploaded.
TypeScript port / npm package:
ts-port/is@live-codes/self— a complete client-side TypeScript port of the same interpreter, built with Vite+. It has a real self-hosted parser and object model (no Python/Pyodide), 166 ported tests, and runs withnpm install && npm run devinside that directory. The publishable artifacts arets-port/dist/self.js(ESM) andts-port/dist/self.global.js(IIFE,self.selfTs); build them withnpm run build:package.
npm start # regenerates the bundle, then serves http://localhost:4180
npm test # 9 real interpreter cases, using the same vendored filesThe first load downloads Pyodide from a pinned CDN and boots the Self world (roughly 5–10 s). Runs after that take about 100 ms.
The page uses an existing implementation — pinneyja/self-interpreter
(MIT, Python) — running on CPython compiled to WebAssembly via Pyodide. That
interpreter implements the core Self language and reads the original Self core
modules (self_files/*.self).
It is not the official Self VM. See FINDINGS.md for why compiling that VM to WebAssembly was ruled out for a proof of concept.
Supported and verified:
- objects, data/constant/parent slots, methods, message sends
- blocks,
ifTrue:False:,whileTrue:,to:Do: - integers, floats, booleans, strings, lists/vectors, collections
- recursion and multiple top-level expressions
- Self
print/printLine
Not included: the Morphic/GUI, the process scheduler, snapshots, and primitives outside the vendored core modules.
The short version, with references and evidence in FINDINGS.md:
- The VM is a 32-bit x86/PPC/SPARC JIT with inline assembly, generated
machine code, precise frame walking, signals/timers,
mmap/sbrk, termios, anddlopen. - An
Interpret = truepath exists inshell.cppwhen neither compiler is defined, but it still runs on native frames and continuations. On i386,save1Argis explicitlyfatal("unimp intel"), andframe.cppsays "Interpreter does not work on OSX". - The Self compiler lives in the Self world, not in a standalone executable, so
"compiling the compiler" still requires booting a VM and a world snapshot or
worldBuilder.self. - GitHub's
language:selfsearch shows no browser/WASM Self VM. The available implementations are the official VM, Klein (a VM written in Self), and the Python interpreter used here.
If exact official-VM semantics are required later, the practical browser route
is to boot the real 32-bit Linux binary under an x86 emulator (v86), as the
browser-bash VM spike does for Bash — not a WASM compile.
Brython was also evaluated as a lighter alternative to Pyodide. It needs PLY compatibility shims, bundled core files, and is far slower (42–44 s for a numeric subset; the full core did not finish in five minutes). See BRYTHON.md.
index.htmlloads Pyodidev0.27.8from jsDelivr, thenapp.js.app.jsfetchesvendor/self/bundle.json(generated bynpm start/npm run bundle) and writes its 83 files into Pyodide's virtual FS at/self.vendor/self/playground.pyinstalls Kivy stubs (the interpreter imports GUI classes eagerly), loads the core Self modules, adds a stoppedscheduler, and fixes_StringPrintsoprintdoes not append a newline.- Running code passes the editor buffer to
playground.run(), which joins lines until each expression parses, interprets it, captures stdout, and returns{output, error, result}as JSON. app.jsrenders that result. Pyodide and the Self world are loaded once per page, not once per run.
| Path | What it is |
|---|---|
index.html, app.js |
The demo page and its driver. |
scripts/bundle.mjs |
Packs vendor/self into the one JSON file the page fetches. |
scripts/test_interpreter.py |
Runs the vendored interpreter locally. |
vendor/self/ |
Interpreter source, core self_files, vendored PLY, and notices. |
vendor/self/playground.py |
Our headless runner (the only Self-adjacent code we wrote). |
vendor/self/kivy_stub.py |
Import-time stubs so Kivy is not needed. |
serve.mjs |
Static file server; no backend. |
FINDINGS.md |
VM-to-WASM feasibility assessment. |
- One expression at a time. The parser parses a single expression; the runner accumulates lines until it parses, so multi-line object/block literals work, but two expressions on one line do not.
- Main-thread execution. There is no Stop button; a runaway Self program
freezes the tab until the browser kills it. Running Pyodide in a Worker is the
next step, matching the other
browser-*POCs. - Bootstrap cost. Loading
string.selfalone takes ~3.5 s locally; the full core is ~5 s. Pickling a booted world is a possible optimization. - Pyodide is a CDN dependency. It is pinned but fetched at runtime. Vendor the Pyodide distribution for offline use.
- Interpreter fidelity. This is the Python educational interpreter, not the official VM. Its README notes rough edges around error handling and methods defined outside objects.
- Add a
lang-selfentry undersrc/livecodes/languages/self/with a script editor andextensions: ['self']. - Put Pyodide + this bundle in a Worker and expose one call shaped like the
other WASM runners: input source, output
{output, errors, exitCode}. - Add a CodeMirror/Monaco Self grammar, a starter template, docs, and e2e tests.
- Longer term, port the Python interpreter to JavaScript or build a standalone WASM runtime to avoid Pyodide's ~10 MB runtime and bootstrap cost.
The demo code is MIT. The vendored interpreter is MIT; PLY is BSD-3-clause;
Pyodide is MPL-2.0 and is loaded from a CDN, not vendored. See
vendor/self/NOTICE.md.