Compiling Scheme to WebAssembly
4 months ago
- #Compiler
- #Scheme
- #WebAssembly
- Bob, a suite of Scheme implementations in Python, celebrated its 15th anniversary.
- Originally, Bob included an interpreter, compiler, and VM to explore CPython-like bytecode VMs.
- A C++ VM was later added to experiment with low-level VM implementation without Python's runtime support, featuring a custom mark-and-sweep GC.
- Recently, a new compiler was added to translate Scheme directly to WebAssembly (WASM).
- Goals included experimenting with lowering high-level languages to WASM and gaining hands-on experience with the WASM GC extension.
- Key Scheme objects like PAIR, BOOL, and SYMBOL were represented in WASM GC, utilizing features like i31 for unboxed integers.
- Symbols are stored in linear memory with offsets and lengths, enabling string interning.
- The 'write' builtin was implemented directly in WASM text, importing minimal host functions for character and integer output.
- The project provided valuable insights into realistic WASM code emission and Scheme's implementation challenges.