Skip to content

Lesson 9 of 9 · 23m

Shipping a Small Language

Turn an interpreter or bytecode VM into a usable implementation: CLI, tests, documentation, versioning, and a realistic project architecture.

A language implementation becomes real when someone can run a file, see a useful error, and trust that tomorrow's release will not silently change meaning. That last ten percent is unglamorous, but it is what separates a compiler demo from infrastructure.

Give it a boring CLI

minilang run examples/hello.ml
minilang check examples/hello.ml
minilang fmt examples/hello.ml

Start with run and check; add fmt when the parser is stable. Exit codes should be predictable: 0 success, 1 language error, 2 CLI usage error. Never print implementation tracebacks for user mistakes.

Architecture that survives feature additions

minilang/
  lexer.py      parser.py      ast.py
  resolver.py   interpreter.py compiler.py
  vm.py         values.py      errors.py
  cli.py
tests/
  lexer/ parser/ interpreter/ vm/ errors/
examples/

Keep one shared AST. Separate parse trees for the interpreter and compiler inevitably diverge, leaving you with two languages that merely resemble each other.

Test semantics, not trivia

A strong corpus is tiny programs plus expected outcomes:

tests/interpreter/closure-counter.ml
tests/interpreter/closure-counter.out
tests/errors/undefined-var.ml
tests/errors/undefined-var.err

Include adversarial cases: deep recursion, unterminated strings, integer overflow behavior, shadowing, closure capture, and nested control-flow jumps. If you have both a tree interpreter and VM, run the same corpus through both; divergence is a bug in at least one implementation and often in the specification.

Write the language down

A one-page LANGUAGE.md prevents accidental design. Define values, scope, equality, mutation, evaluation order, and error behavior. Then version the language separately from the implementation: minilang 0.3.0 implements language v0.2 is a perfectly respectable sentence. Silent semantic drift is not.

Field notes

  • Normalize source spans in snapshot tests or maintenance becomes miserable.
  • A formatter is a forcing function for a complete parser; if valid source cannot round-trip, the grammar has holes.
  • Package binaries only after the CLI contract stabilizes. Packaging churn often masks design indecision.
  • Ship one end-to-end example users care about — a templating script or automation task beats another Fibonacci demo.

Was this lesson helpful?

Sign in to rate