Your Cart
Loading

Build a Compiler and the Model Checker That Checks Its Optimizer (TypeScript, no dependencies): a Localpane Lab Kit

On Sale
$39.00
$39.00
Added to cart

Build a small compiler in TypeScript, one tested step at a time: a lexer, an expression parser, type rules, lowering to basic blocks, a bytecode generator, a virtual machine and three optimization passes, every run checked against a reference interpreter. Then build a breadth-first model checker that finds the shortest path to a broken invariant, and use it to search every order of your optimizer's passes for a miscompilation. It clears the correct passes and catches a deliberately wrong one in one step. Each step has a starter, failing tests, plain explanations and hints. Node.js only; full solution included.


What's inside

  • WORKBOOK.md: 8 steps, each with the goal, key concepts in plain words, where the starter code is, the tests that must pass, hints and a check command
  • 8 starter projects (steps/step-01 to step-08): earlier steps solved, the current one stubbed
  • The finished solution: about 5,800 lines of TypeScript and 830 lines of tests; you write about 650 of those lines across the 8 steps, the rest is provided
  • 47 graded tests, and 4 tests for the code the kit provides
  • check.sh to check one step and everything before it
  • 13 example programs, a failure corpus, and 35 models (races, deadlocks, mutual exclusion, two-phase commit)
  • Command-line tools: compile and run a program, print its IR and bytecode, write a frame as SVG, check a model, check every pass order

The 8 steps:

  1. The lexer: characters to tokens
  2. The expression parser: precedence climbing
  3. The type checker: scopes, operator rules, recursion
  4. Lowering: control flow as basic blocks
  5. Code generation and the virtual machine
  6. The optimizer: folding, dead code, common subexpressions
  7. The model checker: breadth-first search and shortest counterexamples
  8. The bridge: model-checking every pass order


Who it's for

TypeScript or JavaScript developers who want to see how a compiler and a model checker work by finishing real ones: people curious about compilers after a first "write an interpreter" tutorial, engineers who have heard of TLA+ or model checking and want to know what the search actually does, and anyone who likes tests that tell them when they are done.

Not for: anyone looking for a production compiler or a TLA+ replacement, or for a from-scratch project with no provided code (the kit gives you the language's statement parser, the reference interpreter, the verifiers and the model language front end, and has you write the core of each stage).


Prerequisites

  • Node.js 24 or later; tested with Node.js 24.14.0 on macOS (Apple Silicon). Linux and Windows not yet tested.
  • Comfortable with TypeScript: union types, classes, Map and Set, closures
  • No compiler or formal-methods background needed
  • About 11 to 14 hours


Licence

Single-developer licence: use and modify the code, including in your own products; no redistribution and no public repositories. Free updates within 1.x. Built from the author's open-source project The Impossible Compiler Works (MIT): the kit is the guided path, the starters and the graded tests.


Open-source basis: the reference solution builds on my open-source projects The Impossible Compiler Works and Paper Tiger Compiler Works (MIT licence, public on GitHub). What this kit adds is the guided workbook, the step-by-step starter code with the solutions removed, the graded tests and the checker.

Refunds: within 14 days of purchase if a file is defective or not as described. Contact me through the store's Contact button. This doesn't affect any rights you have under the law where you live.

Licence summary: payhip.com/u1791141470733132530294/licences

You will get a ZIP (1MB) file