--- story: E02-S03 owner: e02_names status: done started: 2026-11-07 depends-on: [E01-S05, E02-S02] --- # E02-S03 Claim ## Intended change Add the compiler's name table (`src/compiler/names.s`): case-insensitive interning of identifiers into 1-byte IDs held in bank 1, a 64-bucket chained hash, preservation of the first declaration's spelling, and a deterministic resource error when the table is full. ## File area - `src/compiler/names.s`, `src/common/names.inc` - `tests/names/` - `scripts/build-names-test.ps1`, `scripts/verify-names-test.ps1` - `docs/memory-map.md` (bank-1 usage), `docs/decisions.md` (capacity) - `planning/claims/E02-S03.md` - generated files under `build/` ## Acceptance evidence - [x] Equal normalized identifiers share an ID: the C128 dump equals the host model byte for byte; `TICKER`/`Ticker`, `count`/`Count`/`COUNT`, and the `$C1-$DA` respellings in `collide.n8` all reuse their IDs. - [x] First-declaration spelling is preserved for diagnostics/MAP output: `runner` (used first) is stored as `Runner` after `class Runner`; `tick` keeps its first declaration over a later `method Tick()`; `Main` survives later `main`/`MAIN`. `name_get` returns spelling and a declared flag. - [x] Hash collisions are tested: `collide.n8` puts 8 names in one bucket, including `x0`/`y2` with an identical 8-bit hash, plus near-miss names. A mutation that skips the text compare merges `y2` into `x0` and fails. - [x] Full tables report a resource error without memory corruption: `full.n8` interns 255 names, then 5 new names (and 2 repeats of them) get `NAMES_ERR_FULL` while existing names still resolve; an 8-byte guard directly after the table in bank 1 stays intact. ## Coordination notes The capacity (255 distinct names) is a user-visible limit, so it is recorded as a proposed decision. The resource error is a names return code; E02-S04 maps it to an `Exxx` diagnostic. ## Work log - Records keep the original spelling and fold case during comparison, so no separate normalized copy is stored (20-byte records). - Collision names are found by searching the hash function on the host; the build fails if the chain is shorter than 5 or spans buckets. - The test declares a name when the previous token is class, interface, program, method, or var. The real declaration rules belong to the parser. ## Completion - Tests run: `scripts/verify-names-test.ps1` (pass plus collision mutation). - Results: 2,217-byte dump identical to the host model; mutation detected. - Files changed: `src/compiler/names.s`, `src/common/names.inc`, `tests/names/`, `scripts/build-names-test.ps1`, `scripts/verify-names-test.ps1`, `docs/memory-map.md`, `docs/decisions.md` (D120, proposed), this claim. - Remaining risks: D120 (255 names) awaits approval; lookups compare at most a short chain but are not timed; NAMES_ERR_FULL still needs an `Exxx` diagnostic (E02-S04).