d22a0a5756006bef2d430400332d2fe4646e8c7b
- Dictionary: linked-list word headers in simulated linear memory with create/find/reveal, case-insensitive lookup, IMMEDIATE flag support - WASM codegen: IR-to-WASM translation via wasm-encoder with full validation; all stack, arithmetic, comparison, logic, memory, control flow, and return stack operations; wasmtime execution tests - Outer interpreter: tokenizer, number parsing (decimal/$hex/#dec/%bin), interpret/compile dispatch, control structures (IF/ELSE/THEN, BEGIN/UNTIL, BEGIN/WHILE/REPEAT), RECURSE, comments, string output - 40+ primitive words registered via JIT-compiled WASM modules linked to shared memory/globals/table - Interactive REPL with rustyline, piped input, and file execution - 145 tests passing across dictionary, codegen, and runtime
WAFER
WebAssembly Forth Engine in Rust
An optimizing Forth 2012 compiler targeting WebAssembly.
Goals
- Full Forth 2012 compliance -- all word sets, 100% test suite pass rate
- Optimizing compiler -- constant folding, inlining, peephole optimization, stack-to-local promotion
- Multi-typed stack -- type inference uses WASM's native typed stack when possible, memory fallback for dynamic cases
- Self-hosting -- minimal Rust kernel (~35 primitives), everything else written in WAFER Forth
- Dual mode -- JIT for interactive development, consolidation recompilation into a single optimized WASM module
Architecture
Forth Source -> Outer Interpreter -> IR (with type inference) -> Optimization -> WASM Codegen
- Subroutine threading via WASM function tables
- JIT mode: each new word compiles to a separate WASM module
- Consolidation mode: recompile all words into a single module with direct calls
- IR-based pipeline enables optimization passes before WASM emission
Building
cargo build --workspace
Running
# Interactive REPL
cargo run -p wafer
# Run a Forth file
cargo run -p wafer -- file.fth
# Compile to optimized WASM
cargo run -p wafer -- --consolidate file.fth -o output.wasm
Testing
# All tests
cargo test --workspace
# Forth 2012 compliance dashboard
cargo test --test compliance
# Benchmarks
cargo bench --workspace
Project Structure
crates/
core/ wafer-core: compiler, IR, optimizer, codegen
cli/ wafer: CLI REPL and AOT compiler
web/ wafer-web: browser bindings (planned)
forth/ Standard library written in WAFER Forth
tests/ Integration tests and Forth 2012 compliance suite
Compliance Status
Targeting 100% Forth 2012 compliance, tested with Gerry Jackson's forth2012-test-suite.
| Word Set | Status |
|---|---|
| Core | Pending |
| Core Extensions | Pending |
| Block | N/A |
| Double-Number | Pending |
| Exception | Pending |
| Facility | Pending |
| File-Access | Pending |
| Floating-Point | Pending |
| Locals | Pending |
| Memory-Allocation | Pending |
| Programming-Tools | Pending |
| Search-Order | Pending |
| String | Pending |
| Extended-Character | Pending |
License
MIT OR Apache-2.0
Description
Languages
Rust
92.4%
Python
3.9%
Forth
1.3%
JavaScript
1%
CSS
0.8%
Other
0.6%