Skip to content
jiamoPublic

About

wabbit language write by golang (interpreter+vm+wasm+llvm)

Resources

Stars

5 stars

Watchers

1 watching

Forks

Repository files navigation

wabbit-go

A Wabbit compiler written in Go. The Wabbit language and compiler design course is by David Beazley (https://www.dabeaz.com/compiler.html), originally taught in Python — rewritten here in Go as a Golang learning project.

Backends

The same Wabbit source can run on four backends:

backend implementation how it executes
interpreter interpreter/ direct AST tree-walking
wvm wvm/ custom bytecode VM (fastest Go backend)
wasm wasm/ WebAssembly via wat2wasm + node
llvm llvm/ LLVM IR via clang (native code)

Run a program

# make sure you have clang
go run cmd/llvm/llvm_main.go tests/Programs/23_mandel.wb

# requires npm install (wabt provides wat2wasm) and node >= 22
go run cmd/wasm/wasm_main.go tests/Programs/23_mandel.wb

go run cmd/wvm/wvm_main.go tests/Programs/23_mandel.wb

go run cmd/interpreter/interpreter_main.go tests/Programs/23_mandel.wb

Example programs live in tests/Programs/ (numbered 00-25, e.g. 18_shortcircuit.wb, 25_tailrecurisve.wb). Programs expected to fail are in tests/Error/.

wvm performance

The wvm bytecode VM is optimized for the interpreter dispatch loop (measured with 23_mandel.wb, an 80x40 Mandelbrot render):

optimization dispatch loop allocations per run
baseline (string opcodes + map lookup + indirect call) 462 ms 4.22 M / 34.7 MB
int opcodes + direct switch dispatch 138 ms 2.12 M
compile-time LABEL folding 137 ms 2.12 M
unboxed stacks/locals ([]int + []float64, no interface{}) 85 ms 16.4 k / 744 KB
label table map → []int direct indexing 60 ms 16.4 k
superinstructions (FLOAD2, FCOPY, IDEC) 49 ms 16.4 k

Total: 9.4x faster dispatch, -99.6% allocations (end-to-end mandel 0.45 s → 0.06 s). Superinstructions are emitted only when semantics allow: FLOAD2 for a same-variable square (x*x), FCOPY for a float local copy assignment (x = xtemp), IDEC strictly for self-decrement assignments (n = n - 1) — never for a bare n-1 expression.

Benchmark (dispatch loop only, codegen excluded):

go test ./wvm/ -bench BenchmarkRun -benchmem

test

go test -v wabbit-go/tests

tests/right_test.go parses every .wb in tests/Programs/ and runs it through all four backends (output of wvm/interpreter must match; no crashes expected elsewhere).

Goal execution framework

docs/goal/ + scripts/goal_state.py implement a small task-board execution loop (ported from pcc). The board is docs/goal/task-board.yaml; evidence goes under docs/goal/evidence/.

python3 scripts/goal_state.py validate
python3 scripts/goal_state.py resume

See docs/goal/goal-prompt.md for the protocol.

About

wabbit language write by golang (interpreter+vm+wasm+llvm)

Resources

Stars

5 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages