--- story: E04-S07 owner: codebuff status: done started: 2026-11-10 completed: 2026-11-10 depends-on: [E04-S06] --- # E04-S07 Claim ## Intended change Finish the pass-3 address path: count-mode sizing with zero mismatch, final section and method addresses in the MAP, unresolved-reference diagnostics, deterministic PRGs, and a real source file running in x128. ## File area - `src/compiler/flow.s`, `emit.s`, `sizing.s`, `parser.s`, `diagnostics.s` - `src/compiler/output.s`, `src/common/formats.inc`, `diagcat.inc` - `tests/compiler/counter.n8`, `tests/compiler/counter-test.s` - `tests/runtime/class-test.s`, `tests/parser/unresolved.n8` - `scripts/build-*.ps1`, `scripts/verify-*.ps1` - `docs/decisions.md`, `docs/architecture.md`, `docs/memory-map.md`, `docs/diagnostics.md` ## Acceptance evidence - [x] `sizing.s` measures each routine in count mode so pass 2 and pass 3 produce identical lengths and label offsets; `sz_mismatch` is 0. - [x] Pass 3 patches absolute `JMP`/`JSR` label fixups; relative branches stay offset-based. `counter.n8` runs from `CODE 1C4F` with `total = 15`. - [x] MAP `ENTRY` and `SECTION` records carry final addresses; class records and `METHOD` entry addresses are emitted and checked by the class fixture. - [x] Forward references resolve; `tests/parser/unresolved.n8` reports exactly one `SEM_UNKNOWN_NAME` (E61) and no bad-operand follow-up. - [x] Recompiling the same source is byte-identical: `COUNTER.PRG` and `COUNTB.PRG` compare equal. - [x] E202 overwrite refusal still holds; the output suite leaves `COLLIDE.PRG`/`COLLIDE.MAP` unchanged and leaves no output after abort. - [x] `counter.n8` compiles from source and runs in x128 with `total = 15`. ## Work log - `flow.s` now resolves absolute `JMP`/`JSR` operands against `fl_code_base`; ordinary fixtures keep the default `cg_code` base. - `sizing.s` computes `PRG_ENTRY_ADDR + bytes-before-CODE` and installs it for the emitting pass. `sz_capture`/`sz_verify` compare code length, entry offset, per-routine sizes, and all label offsets. - `emit.s` records routine sizes in `em_routine_sizes` and selects count mode through `em_count`. `parse_file` clears count mode, diagnostic suppression, and any base request; `parse_file_sized` opts into the counted path. - `diag_suppress` prevents duplicate diagnostics during the emitting pass. `RES_SIZE_MISMATCH` (E228) reports a count/emit disagreement. - `output.s`/`formats.inc` add bounded `METHOD name address` MAP records after class records. The class fixture checks `METHOD DESTROY` and `METHOD STUB`. - Added the one-reference `unresolved.n8` parser fixture and the matching `SEM_UNKNOWN_NAME` expectation. ## Completion - Tests run: statements, calls, member, control, scalar, hello, parser, counter, output; class test separately. All PASS. - Parser: 42 fixtures, including `unresolved.n8` with exactly one diagnostic. - Counter: 175 code bytes; `sz_mismatch = 0`; MAP `ENTRY 1C0D`, `START 1C0D 0042`, `CODE 1C4F 00AF`; `COUNTER.PRG` and `COUNTB.PRG` byte-identical; generated PRG reports `total = 15`. - Class MAP: `CLASS EMPTY`, `CLASS BOX`, `METHOD DESTROY 2A56`, `METHOD STUB 2A57`; all descriptor/MAP flags pass. - Remaining risks: the code buffer remains 255 bytes and `em_entry` remains an offset; general runtime startup and frame sizing remain separate work.