glassbox
A COMPILER WORKSHOPHow it works Source
SOURCE IN. UNDERSTANDING OUT.

A small language.
A real compiler.

Follow your code from its first token to running WebAssembly. Open the box. See what changes, and why.

Written from scratch.

Typed functions, loops, optimizations, and a binary backend. Every result below comes from your code.

i32 + boolZero dependencies
COMPILER LAB v0.1
Ready to compile
main.glass
Runs in your browser

Less work. Same answer.

Constants folded, dead branches removed.

STRUCTURED IR
Compiling the first example…
PROGRAM RESULT
—i32
Reference interpreter—
Wasm · unoptimized—
Wasm · optimized—
Waiting for execution100,000 units of execution fuel

Compile a program to inspect its transformations.

Click a transformation to select its source. Module size includes execution-budget instrumentation; smaller code does not necessarily run faster.

UNDER THE HOOD

No magic.
Just a pipeline.

A real lexer, parser, type checker, structured intermediate representation, optimizer, and WebAssembly binary encoder. The browser validates and executes the generated module.

Read the architecture
  1. 01

    Give source a shape

    Tokens become a syntax tree. Names resolve to numbered slots. Types are checked before execution.

  2. 02

    Remove unnecessary work

    Fold constant expressions and remove unreachable branches while preserving overflow, traps, and short-circuit behavior.

  3. 03

    Emit actual machine-readable code

    Encode a WebAssembly module directly, then compare its answer with an independent execution path.

The language, its limits, and execution safety

Small by design

Use fn, let, return, if / else, and while. Every variable, parameter, and function result has type i32 or bool. Locals are mutable. Arithmetic wraps to signed 32 bits; division by zero and signed division overflow trap. Boolean && and || short-circuit.

Explicit boundaries

No strings, arrays, heap, imports, or I/O. Every function must visibly return on all paths. This uses structured IR, not SSA, and does not perform register allocation. The reference interpreter limits call depth to 128 in this demo; browser Wasm recursion limits can differ.

A bounded experiment

Each execution has 100,000 units of fuel: one per function entry and loop-condition check. Optimization can reduce fuel use, so exhaustion is a resource limit, not a claim of semantic disagreement. Work happens in a fresh Worker, terminated after three seconds. Source stays in this page and is not sent to a service.