The write-up

How Stepwise is built

a teaching language you can run backward

systems · compilers

What

A small teaching language that compiles to WebAssembly in the page, where any run scrubs backward as well as forward.

Why

When a student’s recursion returns the wrong answer, they drag back through the run and ask where a value came from, and Stepwise jumps to the step that set it.

How

A Rust compiler, running in the page as 88 KB of WebAssembly, marks every line it emits. Runs replay from a snapshot every thousand steps, so no jump replays more than a thousand.

Built with

  • Rust 2024
  • wasm-encoder
  • wasm-bindgen
  • wasm-pack
  • TypeScript
  • Vite 8
  • CodeMirror 6
  • three.js
  • Vitest
  • insta
  • wasmtime
  • wasmparser

By the numbers

recorded events, scrubbed both ways
1,000,000
lines of source
11,946
commits in 2 days
45
tests
248
compiler stages
4
wasm instructions emitted
27
KB of compiler, gzipped
88
golden programs
23
servers
0

Languages

Rust5,37445.0%
TypeScript4,29235.9%
CSS1,41811.9%
Stepwise itself7256.1%
HTML1371.1%

On the wire

Wasm
compiler and program both run in the page
Worker
1 request, 3 replies, trace transferred not copied
Trace ABI
8 host imports, 7 event kinds
Share link
deflate in the URL hash, capped at 256 KiB
Server
none: code never leaves the page

Compiler

  • Lexer
  • Parser
  • Type checker
  • Wasm codegen
  • Debug table
  • Rustc-style errors
  • Snapshot replay

APIs

  • WebAssembly
  • Web Workers
  • CompressionStream
  • Transferable buffers
  • GitHub Actions

Also

Every step is tested to look the same reached forward, backward or by jumping.