This section explains compiler concepts in general alongside the Moth-specific ones.

It breaks down what Moth does differently, why it does it and how the pieces fit the bigger design picture.

From Moth source to a webpage

We'll follow a small Moth program from files on disk to a generated HTML page.

If you write Rust, you already know functions, enums, structs and ownership as a user. You may not have met intermediate representation, link plan or borrow validation. Each term arrives when the example needs it and gets explained on the spot.

These docs teach the concepts rather than document every behaviour the compiler implements today.

The small example project we'll follow

The file structure

compiler_walkthrough/
├── @config.moth
├── @entry.moth
└── greeting.moth

The code

greeting.moth

greeting_prefix #= "Hello"

greet |name String| -> String:
    return [: [greeting_prefix], [name]!]
;

@entry.moth

@greeting greet

visitor = "Priya"

[$html:
    <p>[greet(visitor)]</p>
]

The final fragment the series aims at:

<p>Hello, Priya!</p>

Priya never changes. The file names never change. The fragment never changes. Side examples may wander for a paragraph, then come back to this greeting.

What each stage hands the next

One checkpoint strip runs through every article:

project tree
-> command and config
-> canonical source graph
-> located tokens
-> prepared shells
-> bound interfaces and ordered declarations
-> typed AST and semantic identities
-> folded constants, generated requests and TIR handoff
-> structured diagnostics
-> validated HIR
-> borrow and optional-transfer side-table facts
-> lifetime-region and escape-validation facts
-> conservative integer-proof side-table facts
-> immutable module artefacts and fingerprints
-> entry assembly and reachable function union
-> project/link lifetime topology validation
-> deterministic target assignment
-> JavaScript and Wasm outputs
-> HTML, runtime assets and output manifest

Each article opens with the incoming representation and closes with the outgoing one. If a page jumps ahead, you have left the chronological route.

Each box links to the walkthrough page that expands that stage. Side branches show important internal work without lengthening the main pipeline.

Question: which step still looks like source, and which first looks like something a host can run?

Four owners you will meet again

Build system. Selects the command, discovers source, builds graphs, schedules modules, plans entries and writes files to disk.

Compiler frontend and analysis. Prepares syntax, binds interfaces, checks semantics, lowers HIR and validates access.

Artefact builder. Assembles selected compiler facts into an output plan for one kind of project, such as an HTML page.

Target backends. Lower validated functions and runtime needs into JavaScript, Wasm and glue.

A fact has one owner. Later stages consume that fact. They do not rebuild it from source text.

How to read the series

Read in order. The path groups ideas by time of appearance, not by internal crate name.

  1. 01. What a compiler does
  2. 02. Why Moth makes different choices
  3. 03. Starting a build
  4. 04. Project graphs and modules
  5. 05. Tokenization
  6. 06. Declarations, dependencies and ordering
  7. 07. AST semantics and types
  8. 08. Compile-time semantics
  9. 09. Templates and TIR
  10. 10. Diagnostics
  11. 11. HIR
  12. 12. Memory topology and lowering
  13. 13. Borrow validation and drops
  14. 14. Module artefacts and reuse
  15. 15. Linking, entries and reachability
  16. 16. Target planning and validation
  17. 17. Backend lowering
  18. 18. HTML assembly and output

This landing page acts as article 00.

Status language on every page

Later articles label four kinds of claim:

The series links the progress matrix and roadmap. It does not paste either document into the articles. Accepted architecture stays the main teaching path.

Where authority lives

docs/developer-docs/wasm-optimisation/overview.mtf routes to the permanent authority for optimisation goals and the Moth/native-code boundary. It keeps pass policy separate from compiler-stage and memory-model contracts.

Educational pages explain those authorities. They do not outrank them.

Roadmap and current status

Read the series as the accepted destination, with each page's own status section marking where today diverges.

Next: what a compiler does between Priya's name and a paragraph on a page.