A Rust Scheme runtime with WebAssembly bindings, a raw Wasm ABI, and a direct-Wasm backend for the documented public subset.
Scheme Wasm is a Scheme interpreter that compiles to Wasm using wasm-bindgen. It provides:
- Wasm Public API: A
Schemestruct exposed to JavaScript for evaluating Scheme code - Raw Wasm ABI: Low-level exports for non-JS Wasm hosts
- Bytecode VM: A stack-based virtual machine for executing compiled Scheme
# Build native (tests)
cargo build
# Build Wasm packages
wasm-pack build schemewasm --target web --out-dir pkg
wasm-pack build schemewasm --target nodejs --out-dir pkg-node./run.shcargo testimport init, { Scheme } from './pkg/schemewasm.js';
await init();
const scheme = new Scheme();
console.log(scheme.eval('(+ 2 3)')); // "5"const { Scheme } = require('./pkg-node/schemewasm.js');
const scheme = new Scheme();
console.log(scheme.eval('(+ 2 3)')); // "5"Evaluates Scheme source code. Returns result as string, throws JsValue on error.
Like eval but returns structured JSON with type tags.
Resets the Scheme interpreter to initial state.
- Numbers (f64), booleans, characters, symbols, strings
- Pairs and lists, vectors
- Closures (lambda) with lexical scope
- Arithmetic:
+,-,*,/,=,<,>,<=,>= - Special forms:
if,quote,lambda,define,set!,begin - Local bindings via
let let*,letrec,cond,and,or- Quasiquote, unquote, unquote-splicing
The following R7RS features are NOT supported (see feature-registry.md for full list):
- Continuations:
call/cc,call-with-values - File I/O and ports:
open-input-file,open-output-file, etc. - Dynamic wind:
dynamic-wind - Libraries:
import, library declarations - Delayed evaluation:
delay,force - Threads: thread-related operations
- Bytevectors: bytevector operations
- Bitwise operations:
logand,logor,logxor, etc.
Source Code
↓
Tokenizer (reader.rs)
↓
Parser (reader.rs - produces Value/Sexp)
↓
Expander (expand.rs - produces Core)
↓
Analyzer (analyze.rs - produces AnalyzedExpr)
↓
Compiler (compiler.rs - produces BytecodeFn)
↓
VM (vm.rs - executes bytecode)
- Raw Wasm ABI - Low-level Wasm interface documentation
- Examples - Browser and Node.js usage examples
schemewasm/src/
analyze.rs # AST analysis (AnalyzedExpr, AnalyzedKind)
ast.rs # Core AST types (Core, Sexp, Spanned)
bytecode.rs # Instruction set and BytecodeFn
compiler.rs # Compile AnalyzedExpr → BytecodeFn
error.rs # Error types
expand.rs # Sexp → Core expansion
gc.rs # Garbage collection
heap.rs # Heap management
lib.rs # Library root
prim.rs # Primitive procedures
reader.rs # Tokenizer and parser
scheme.rs # Wasm public API
syntax_rules.rs # Syntax-rules macro implementation
value.rs # Value enum and Handle
vm.rs # Virtual machine
examples/
browser.html # Browser demo
node-example.js # Node.js example
raw-wasm.c # C host example
raw-wasm-host.rs # Rust host example
BSD Zero Clause License (0BSD) - see LICENSE file