Hello fellow Lispers,
I’m pleased to share some progress made on porting uLisp to C and WebAssembly.
- Demo: https://eliot-akira.github.io/ulisp-wasm
- Source code: https://github.com/eliot-akira/ulisp-wasm
The C port is adapted from the ESP32 version written for Arduino (a variant/subset of C++).
For the conversion, I studied this prior art posted here:
Based on this example I gradually rewrote or patched the Arduino/ESP-related parts of ulisp-esp
(~8000 lines) into generic C99. It’s compiled with CMake and Clang.
It can now evaluate Lisp expressions but missing most features like I/O devices. So far I’ve run it on desktop Linux (Ubuntu) and Raspberry Pi Zero (32-bit Raspbian). A start of a tiny command-line interface (CLI) and interactive shell (REPL) in the terminal.
The WebAssembly binary is built from the same C code using Emscripten.
It runs in the browser, and on server-side JavaScript runtimes like V8, Node/Bun/Deno. A few functions were added to the uLisp interpreter to communicate to/from the host, to send messages or emulate ports and devices. This build target has potential to extend uLisp with features provided by the host, like network access (HTTP, WebSocket), servers, file system, database.
A much smaller bare Wasm binary can be built using Clang, that runs on Wasm runtimes with WebAssembly System Interface (WASI) - a kind of abstract interface for POSIX-like I/O. I’m still learning how to make it work.
The test suite from ulisp-builder
was ported to the project, and eventually I got ulisp-wasm
to pass all 640 tests.
For the code editor on the web, I used CodeMirror with language extension for Lisp syntax highlight and Paredit for basic structural editing (experimental).
It’s all still a rough prototype, made using tools I’m comfortable with, like TypeScript and Docker. I plan to extract the core into a small standalone C library - but in its current state it’s probably not usable by anyone yet. It’s been fun, technically challenging, and I’m learning a lot.
Next steps and ideas:
- Playground with editor and live preview
- Documentation with runnable code examples
- Import/export, shareable links
- Emulate ports and devices - LED lights, display/canvas, local storage
- Single-file executable binary for major operating systems: Linux, macOS, Windows
- uLisp-based OS with Wasm unikernel on bare metal :¬)