All posts
Internals8 min read

Seven stages from .chuchu source to executable

A tour of the Cheeku pipeline: lex, parse, resolve, check, lower, optimise and link. Nothing reaches LLVM that has not already passed the type checker.

Cheeku is deliberately one pipeline with clear hand-offs. Each stage produces a checked result for the next one, and a failure stops compilation before an executable can be published. This is the whole route from a source file to a native binary.

Lex and parse

The lexer turns source text into tokens: keywords, literals, symbols and newlines, each carrying the byte span it came from. The parser then builds an abstract syntax tree with precedence-based expressions, blocks, calls and indexing. Spans survive the whole way through, which is why diagnostics can point at the exact source that caused them.

Resolve and check

A symbol table tracks lexical lookup and scope, so shadowing and forward references resolve the way the source reads. The type checker then infers local types, validates signatures, conditions, arrays, scope and returns, and collects function signatures before checking any body. A program that fails here never reaches code generation.

Lower, optimise and link

Validated statements are lowered into an LLVM module: i64 integers, f64 floats, i1 booleans and fixed-size numeric arrays. The target triple and data layout are installed, the requested O-level runs, and a native object is emitted. The system Clang linker produces the executable, which is staged beside the destination and renamed only after linking succeeds.

terminalSH
.chuchu source
    ↓  lexer
tokens with byte spans
    ↓  parser
abstract syntax tree
    ↓  type checker + symbol table
validated program
    ↓  typed code generation
LLVM module
    ↓  target configuration + optimisation
host-native object
    ↓  Clang linker
executable

The pipeline is host-native by design. There is no cross-OS target flag and no JIT: Cheeku compiles and links, then stops. Running the program is a separate step, which keeps compiler timings honest and makes failures easy to reproduce.

Compilation never runs the generated program. Temporary objects are cleaned up, and the requested output is replaced only after linking succeeds.

The About page has the full stage-by-stage walkthrough, and the compiler repository is the source of truth for the implementation.

Read it. Then run it.

Install Cheeku, compile the example and see the native binary for yourself.