README.md
miricl-web: a Common Lisp REPL that runs in the visitor's browser
One static page that loads miricl, Common Lisp compiled to WebAssembly, into a Web Worker in the visitor's own tab, and gives a prompt that reads a form, evaluates it and prints the result. Nothing runs on the server and nothing is shared between visitors: each tab has its own Lisp, gone when the tab closes. The backend is any plain static file server.
Files
index.html: the page (transcript, prompt, Eval and Stop buttons).worker.js: a module worker. It fetchesdist/miricl-precompiled.wasm, instantiates it withMiricl.instantiatefromdist/miricl.js, and answers eachevaluatemessage withevaluateAsync.dist/: miricl's own files, unmodified; seedist/README.mdfor where they come from, their checksums and their license.refresh-dist: copies those files out of theclfoundation/miriclimage on Docker Hub and makes their gzip copies.
Serve it
Any static file server works if it serves .js with a JavaScript
content type, which module scripts require. A file:// URL does not
work: module workers and fetch need http. No special headers are
needed (no COOP/COEP).
From a Lisp, with zaserve (AllegroServe)
In a Lisp that has zaserve loaded (AllegroServe on Allegro CL, or zaserve through zacl on other implementations; the Gendl images carry it), publish the directory under a prefix of a running server:
(net.aserve:publish-directory :prefix "/miricl/"
:destination "/path/to/miricl-web/")
and open /miricl/ on that server. Or give it a server of its own:
(net.aserve:publish-directory
:prefix "/" :destination "/path/to/miricl-web/"
:server (net.aserve:start :port 8731 :server :new))
and open http://127.0.0.1:8731/. Both paths end in a slash.
What zaserve sends, checked with zaserve on Clozure CL 1.14 in a Gendl image and the page run in Chromium 155:
.jsgoes out asapplication/x-javascript, which browsers accept for module scripts and module workers..wasmgoes out asapplication/wasmin a Gendl image, which adds that type at startup. Plain zaserve has no entry for it and sendsapplication/octet-stream; the page still works, since it does not use streaming compilation, but add the type anyway:(setf (gethash "wasm" net.aserve:*mime-types*) "application/wasm").- Compression:
dist/carries gzip copies of the two miricl files (*.gz, made byrefresh-dist). zaserve sends a.gzbeside a file, withContent-Encoding: gzip, to any browser that accepts gzip, as long as the.gzis not older than the file. That cuts the download from 765 KB to 292 KB. It needs no setting: leave the server's on-the-fly compression (enable-compression) off. On zacl that feature is not implemented, and with it on, responses whose length is not known in advance, such as 404 pages, are dropped. LICENSE,COPYINGand.mdfiles go out asapplication/octet-stream, so the license links in the footer download instead of displaying. To show them as text (this changes the Lisp's global table):
lisp
(dolist (key (list "md" '("LICENSE") '("COPYING")))
(setf (gethash key net.aserve:*mime-types*) "text/plain; charset=utf-8"))
With nginx
docker run --rm -p 8731:80 -v "$PWD":/usr/share/nginx/html:ro nginx:alpine
then open http://127.0.0.1:8731/. The stock nginx image does not use
the .gz files and sends uncompressed files (enable gzip_static to
use them).
Why a worker
On the page's main thread, an endless loop in Lisp would freeze the tab,
and miricl's sleep (which waits with Atomics.wait) is refused there.
In a worker the page stays responsive while Lisp runs, and Stop
terminates the worker and starts a fresh Lisp (earlier definitions are
lost; the page says so). A running evaluation cannot be interrupted any
other way.
What it downloads
About 775 KB uncompressed, 295 KB with gzip: miricl-precompiled.wasm
700 KB (275 KB gzip), miricl.js 65 KB (17 KB gzip), the page and
worker 8 KB. In Chromium 155 on a desktop the Lisp is ready 0.1 to 0.3
seconds after the files arrive.
What it needs from the browser
WebAssembly GC and exception handling, and module workers. Current Chrome and Edge have all three (checked in Chromium 155); Firefox and Safari are untested. JavaScript Promise Integration (JSPI), where present, enables miricl's green threads and asynchronous file access; without it evaluation still works, synchronously inside the worker. No COOP/COEP headers are needed.
Limits
- No persistence across reloads.
- ASDF is not loaded (miricl ships it separately as
miricl-asdf.wasm). - miricl's native compiler covers a subset of Common Lisp; forms it does not compile, such as macros, classes and methods, go through its evaluator by design.
License
The files of this repository outside dist/ are under the GNU Affero
General Public License, version 3 or (at your option) any later version
(LICENSE). The files in dist/ are
miricl's, under the GNU Lesser General Public License version 3
(dist/LICENSE, with the GNU GPL version 3 in dist/COPYING), and their
source is the miricl commit named in dist/README.md.