Learn the Amu compiler step by step
Amu checks Kotoba programs and turns them into artifacts for a selected execution target. This course starts with a program that returns 42, then gradually adds features while following the path from source to native execution. Along the way, it connects Kotoba forms, IPLD, Unison-inspired content-addressed definitions, the Kototama VM, and performance engineering.
You need to know functions, variables, and conditionals. Each chapter introduces the compiler, Lisp, and IPLD concepts it uses, with an example, an explanation, source references, and an exercise with an answer. Like Simple, the course follows a gradual learning path; it reads the real Amu implementation rather than copying a separate compiler into each chapter.
English is the default. The language links on each page switch between the English and Japanese versions of that page. Both versions share the executable examples and recorded observations.
Contents
| Chapter | What you learn | What you work with |
|---|---|---|
| 01 The first 42 and the big picture | The roles of Amu, Kotoba, Kototama, and AiueOS | Returning an integer |
| 02 Source and Kotoba forms | S-expressions, syntax trees, canonical forms, reader sugar | Reading addition as a tree |
| 03 Reading and name resolution | Lexing, reading, scope, and resolved references | let and an undefined name |
| 04 Type checking and intermediate representations | Checked KIR, the Seed tree, and SIR | Type errors and conditionals |
| 05 IPLD and content addressing | DAG-CBOR, CIDs, blocks, and handles | Distinguishing source from definitions |
| 06 Unison-inspired definition identity | Alpha normalization, dependency CIDs, recursive SCCs | Renaming and dependency updates |
| 07 Effects and authority | Static effects, grants, invocation admission | Refusing an unsupported operation |
| 08 Machine code and executables | Lowering, instruction selection, registers, fixups, ABI | Loops and function calls |
| 09 The Kototama VM | Transitions, IPLD state, admission, receipts, typed eval | Describing one execution |
| 10 Making generated code faster | Structural recognition, constants, loops, SIMD, fuel and bounds | Comparing observable behavior |
| 11 Faster builds and selfhosting | Compiler costs, DefCID caches, self-rebuilds | Designing reuse conditions |
| 12 Reading the implementation and running experiments | Source exploration, negative controls, measurements, Simple | Completing a small investigation |
Run the first example
Use the native CLI on an Apple Silicon Mac. Read the Amu checkout's public entry scope and instructions first. Replace /path/to with the actual locations.
/path/to/amu/bin/amu check /path/to/this/docs/learn/amu/examples/00-literal.kotoba
/path/to/amu/bin/amu run /path/to/this/docs/learn/amu/examples/00-literal.kotoba
The commands print ok and 42, respectively. Linux uses its own entry, target, and format; this Mac observation does not qualify Linux or browser execution. See the instructions and observations for all examples.
Four states to distinguish
A language or VM contract defines the behavior an implementation must preserve. Adopted source identifies the composition of a particular compiler. An experiment or candidate is an implementation being investigated. An execution result or measurement is an observation for the recorded artifact, input, and host.
For example, the existence of a DefCID contract does not mean every native build uses a persistent per-definition cache. Running a small native example also does not establish the complete Kototama state, authority, and receipt contract. Each chapter keeps these distinctions beside the feature concerned.
References and reading guide
These primary sources explain the ideas used in the course. Each chapter connects them to Kotoba's own contracts and pinned implementation; a comparison or compatibility profile needs its own implementation evidence.
| Topic | Primary source | Connection to this course |
|---|---|---|
| S-expressions and Lisp | McCarthy's Lisp paper, 1960 | Symbolic expressions and recursive computation; chapter 2 distinguishes source syntax, frontend trees, and canonical forms. |
| IPLD | IPLD Docs, Data Model, DAG-CBOR specification | Values, content-addressed links, and encoding; chapter 5 separates source, definition, artifact, and value identities. |
| Unison | The big idea | Definition identity and human-readable names; chapter 6 explains Kotoba's checked definition contract and its implementation scope. |
| Simple | SeaOfNodes/Simple | A chapter-by-chapter compiler learning path; chapter 12 explains which progression and graph ideas are useful when reading Amu. |
| Filecoin execution models | Filecoin Virtual Machine, Filecoin EVM runtime | An execution platform and a runtime layered on it; chapter 9 relates FVM/FEVM to Kototama's VM and compatibility-profile boundaries. |
Reference baseline
The reference date is 6 November 2026. Amu implementation links are pinned to a4c16e7c, and Kototama links to b7bbcc44. Relative links lead to language contracts in this repository. Pinned links keep the explanation reproducible when files later move. Check the owning contracts, manifests, and execution evidence when using a newer version.