Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

browser-self

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 with npm install && npm run dev inside that directory. The publishable artifacts are ts-port/dist/self.js (ESM) and ts-port/dist/self.global.js (IIFE, self.selfTs); build them with npm run build:package.

npm start          # regenerates the bundle, then serves http://localhost:4180
npm test           # 9 real interpreter cases, using the same vendored files

The first load downloads Pyodide from a pinned CDN and boots the Self world (roughly 5–10 s). Runs after that take about 100 ms.

What is running

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.

Why not the official Self VM → WASM

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, and dlopen.
  • An Interpret = true path exists in shell.cpp when neither compiler is defined, but it still runs on native frames and continuations. On i386, save1Arg is explicitly fatal("unimp intel"), and frame.cpp says "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:self search 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.

How the page works

  1. index.html loads Pyodide v0.27.8 from jsDelivr, then app.js.
  2. app.js fetches vendor/self/bundle.json (generated by npm start / npm run bundle) and writes its 83 files into Pyodide's virtual FS at /self.
  3. vendor/self/playground.py installs Kivy stubs (the interpreter imports GUI classes eagerly), loads the core Self modules, adds a stopped scheduler, and fixes _StringPrint so print does not append a newline.
  4. 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.
  5. app.js renders that result. Pyodide and the Self world are loaded once per page, not once per run.

Layout

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.

Limitations

  • 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.self alone 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.

LiveCodes integration

  1. Add a lang-self entry under src/livecodes/languages/self/ with a script editor and extensions: ['self'].
  2. Put Pyodide + this bundle in a Worker and expose one call shaped like the other WASM runners: input source, output {output, errors, exitCode}.
  3. Add a CodeMirror/Monaco Self grammar, a starter template, docs, and e2e tests.
  4. Longer term, port the Python interpreter to JavaScript or build a standalone WASM runtime to avoid Pyodide's ~10 MB runtime and bootstrap cost.

Licensing

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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages