Developers / Compiler design
This section of the docs is written to help you understand compiler concepts in general, as well as Moth specific concepts.
This is to help break down what Moth does differently, why it does it and how it all fits into the bigger design picture.
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 know terms like intermediate representation, link plan or borrow validation yet.
Each term shows up when the example needs it and will be explained step by step.
These docs are focused on teaching rather than documenting the compiler's actual implemented behaviour.
compiler_walkthrough/
├── config.moth
└── src/
├── @page.moth
└── greeting.mothgreeting.moth
greeting_prefix #= "Hello"
greet |name String| -> String:
return [: [greeting_prefix], [name]!]
;@page.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.
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
-> 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 manifestEach article opens with the incoming representation and closes with the outgoing one. If a page jumps ahead, you have left the chronological route.
Question: which step still looks like source, and which first looks like something a host can run?
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.
Read in order. The path groups ideas by time of appearance, not by internal crate name.
This landing page acts as article 00.
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.
docs/compiler-design-overview.md for compiler stages, identities, artefacts and validationdocs/build-system-design.md for commands, graphs, builders, linking and outputsdocs/src/developer-docs/language/overview.mtf for language surfacedocs/src/developer-docs/memory-management/overview.mtf for reference semantics, borrow validation, lifetime regions, ownership and backend loweringdocs/src/docs/progress/@page.moth for what works todaydocs/roadmap/roadmap.md for order and deferred designEducational pages explain those authorities. They do not outrank them.
Next: what a compiler does between Priya's name and a paragraph on a page.