|
| 1 | +# Pipeline boundaries — who owns what |
| 2 | + |
| 3 | +This document **freezes responsibility** between syntax, semantics, IL, world, and built-ins so implementations stay aligned. It generalizes ideas from the teaching mission; see [governance/mission.md](../governance/mission.md). |
| 4 | + |
| 5 | +## End-to-end interaction model |
| 6 | + |
| 7 | +```text |
| 8 | +Syntax |
| 9 | + ↓ |
| 10 | +Bound semantic form |
| 11 | + ↓ |
| 12 | +IL lowering |
| 13 | + ↓ |
| 14 | +Interpreter dispatch |
| 15 | + ↓ |
| 16 | +Built-in runtime handler (or user function body) |
| 17 | + ↓ |
| 18 | +RobotWorld mutation (when applicable) |
| 19 | + ↓ |
| 20 | +Snapshot / render projection |
| 21 | +``` |
| 22 | + |
| 23 | +The interpreter is a **plain C# state machine** over fake IL, not CLR emission. Built-ins run as handlers against execution state and world contracts. |
| 24 | + |
| 25 | +## The key rule: syntax does not talk to the world |
| 26 | + |
| 27 | +Syntax expresses declarations, statements, expressions, and **calls**. The parser does **not** know about lessons, profiles, or grid state. |
| 28 | + |
| 29 | +- `move()` parses as a normal **call expression**. |
| 30 | +- **Semantic analysis** decides whether `move` resolves to a user function or a profile **built-in**. |
| 31 | +- **IL generation** emits **`Call`** for user functions or **`CallBuiltin`** for built-ins (see below). |
| 32 | +- **Runtime** dispatches to the handler, which may mutate **`RobotWorld`**. |
| 33 | +- **UI** sees **snapshots**, not live mutable engine internals. |
| 34 | + |
| 35 | +## Freeze: `Call` vs `CallBuiltin` |
| 36 | + |
| 37 | +| Callee kind | IL form | |
| 38 | +| ----------- | ------- | |
| 39 | +| User-defined function | `Call` (or equivalent direct call to function metadata) | |
| 40 | +| Built-in from active profile | `CallBuiltin` (operand identifies built-in) | |
| 41 | + |
| 42 | +Robot commands stay **ordinary calls** in source—no special parser syntax for `move` or `turnLeft`. |
| 43 | + |
| 44 | +Examples in source (all parse as calls): |
| 45 | + |
| 46 | +```text |
| 47 | +move() |
| 48 | +turnLeft() |
| 49 | +frontIsClear() |
| 50 | +print("x") |
| 51 | +count(values) |
| 52 | +takeLast(values) |
| 53 | +``` |
| 54 | + |
| 55 | +Binding chooses user vs built-in; lowering chooses `Call` vs `CallBuiltin`. |
| 56 | + |
| 57 | +## What each layer owns |
| 58 | + |
| 59 | +### Syntax spec |
| 60 | + |
| 61 | +- Grammar, precedence, statement/expression kinds, type syntax, parse recovery. |
| 62 | + |
| 63 | +### Semantic spec |
| 64 | + |
| 65 | +- Symbol resolution, built-in **availability** (profile), type checking, assignability, legality of calls/index/return. |
| 66 | + |
| 67 | +### IL spec |
| 68 | + |
| 69 | +- Opcode inventory, operand shapes, calling convention, evaluation stack / locals, function metadata, debug mapping hooks, meaning of **`CallBuiltin`**. |
| 70 | + |
| 71 | +### World spec |
| 72 | + |
| 73 | +- Grids/layers, actor state, movement / item / terrain rules, metrics hooks, **snapshot** format. |
| 74 | + |
| 75 | +### Built-in spec |
| 76 | + |
| 77 | +- Built-in ids, signatures, semantic meaning, **runtime handler** behavior (return value, world mutation, stdout/stderr). |
| 78 | + |
| 79 | +## IL and world: explicit non-goals |
| 80 | + |
| 81 | +- **IL never renders** — it only advances execution state. |
| 82 | +- **IL does not inspect syntax** — source is gone after lowering except via debug metadata. |
| 83 | +- **World mutations** go through **runtime handlers**, not parser or syntax visitors. |
| 84 | +- **Snapshots are the UI contract** — hosts consume runtime/world snapshots, not ad hoc shared mutable graphs. |
| 85 | + |
| 86 | +## World interaction (spec direction) |
| 87 | + |
| 88 | +The interpreter affects the world only through **defined APIs** (e.g. `IRobotWorld` / built-in handlers). Layered storage (`TerrainGrid`, `ItemGrid`, `ActorGrid`, `ActorsById`) stays authoritative; rendering uses **projection** over snapshots. Details: [world model](../world/world-model.md), [world actions](../world/world-actions.md), [movement rules](../world/movement-rules.md), [render projection](../rendering/render-projection.md). |
| 89 | + |
| 90 | +## Related |
| 91 | + |
| 92 | +- [Syntax-to-IL lowering](../compiler/syntax-to-il-lowering.md) |
| 93 | +- [IL instruction set (inventory)](../runtime/il-instruction-set.md) |
| 94 | +- [Built-ins and profiles](../semantics/builtins-and-profiles.md) |
| 95 | +- [Compilation pipeline](../compiler/compilation-pipeline.md) |
0 commit comments