--- story: E03-S06 owner: e03_iface status: done started: 2026-11-09 depends-on: [E03-S02, E03-S04] --- # E03-S06 Claim ## Intended change Add `src/compiler/interfaces.s`, which runs once after the declaration pass. It numbers each interface method in source order in a new `C_MEM_SLOT` member column, then checks every class against every interface in its implements list. A satisfying method is public and has the same parameter count, parameter types, and return type; one method may satisfy identical requirements from several interfaces. Missing and private methods report E130, signature mismatches E131, a class method that matches a same-named requirement of another implemented interface E132, and an implements entry that names a class or program E133. All are reported at the class declaration line, column 1. The parser harness emits an `$F9` slot record so a fixture can verify source order. ## File area - `src/compiler/interfaces.s` (new), `src/compiler/parser.s` - `src/common/parser.inc`, `src/common/diagcat.inc`, `docs/diagnostics.md` - `tests/parser/parser-test.s`, `scripts/build-parser-test.ps1`, `scripts/verify-parser-test.ps1`, `scripts/demo-write-check.ps1` - `tests/semantic/interfaces.n8`, `interfaces.expect`, `iface_bad.n8`, `iface_bad.expect`, `tests/parser/unknown.expect` - `docs/architecture.md`, `docs/memory-map.md` - `planning/claims/E03-S06.md` - generated files under `build/` ## Acceptance evidence - [x] Interface method slots follow interface source order: `interfaces.n8` declares Shape (`area`, `scale`, `name`), Named (`label`, `show`), and Display (`show`, declared after the class); the harness's `$F9` record and `interfaces.expect` list them as shape 0/1/2, named 0/1, display 0. `assign_slots` writes that order into `C_MEM_SLOT`. - [x] A public exact-signature method satisfies a requirement: Box's five public methods match all five interface signatures exactly, and `interfaces.n8` is accepted with no ERR file in the parser run. - [x] One method may satisfy identical requirements from multiple interfaces: Box's single public `show()` satisfies both `Named.show()` and `Display.show()`; no duplicate or conflict diagnostic is produced. - [x] Same-name incompatible requirements are rejected: `iface_bad.n8` has Left (`show()`) and Right (`show(x as byte)`) implemented by one class whose `show()` matches Left; Right reports E132 at 49:1, `SHOW HAS CONFLICTING SIGNATURES`. - [x] Missing, private, parameter-mismatched, and return-mismatched methods each have fixture coverage: `iface_bad.n8` expects E130 at 28:1 (`AREA`), E130 at 31:1 (`LABEL`, private), E131 at 37:1 (`SCALE`, word vs byte), and E131 at 43:1 (`OK`, word vs boolean). E133 at 54:1 covers a class used as an interface. All six exact diagnostics match their messages. ## Coordination notes - No other claim is active. E03-S05 is complete (`42a26c9`). - Conformance legitimately adds E130 to `tests/parser/unknown.n8` (Worker implements Printable without `print`); its exact expectation gained that first pass-1 line and still passes with six diagnostics. - E132 and E133 extend the approved E130-E149 interface category; they do not change source syntax or the interface ABI. Slot order is spec 5.2's source order, and C_MEM_SLOT is parser metadata for later dispatch/MAP work. ## Work log - `interfaces.s`: `assign_slots` numbers interface methods by declaration; `check_interfaces` walks classes and implements lists in source order and reports at the class line. `find_method` ignores fields; a private method is treated as not implemented. `same_sig` compares result type, parameter count, and all parameter types. `conflicting` decides E132 by looking for a same-named requirement in another implemented interface whose signature the class method does satisfy. `iface_err` spells the argument from `name_out` and reports through `diag_report`, returning carry when the error limit stops compilation. - `parser.s` exports `tb_set`, calls `assign_slots` then `check_interfaces` after `layout_classes`, and returns at once if the diagnostic limit is hit. - `parser.inc`: `C_MEM_SLOT = 26`, `TABLE_COLUMNS = 27`; the parser tables are now 6,912 bytes in `docs/memory-map.md`. - `parser-test.s`: `dump_ifaces` emits `$F9`, each interface name, member count, and each slot/name pair. Fixtures 40-41 added; `FIXTURE_COUNT = 41`. - `verify-parser-test.ps1`: decodes `$F9` before `$FA`, stops the type and member loops at it, treats the new `iface` group like an accepted fixture for diagnostics/member checks, and compares slot lines to `interfaces.expect`. - `diagcat.inc`: E132 `% HAS CONFLICTING SIGNATURES`, E133 `% IS NOT AN INTERFACE`; catalog is 70 entries and docs are regenerated. - First build failed on seven long `bcs @stop`/`beq @inext` branches in the 6502 code; each became a short branch plus `jmp` trampoline. ## Completion - Tests run: `scripts/build-parser-test.ps1`, `scripts/verify-parser-test.ps1 -Port 6530`, `scripts/build-diag-test.ps1 -UpdateDocs`, `scripts/verify-diag-test.ps1 -Port 6530`, `scripts/verify-lexer-test.ps1 -Port 6530`, `scripts/demo-write-check.ps1` (good.n8 and bad.n8), `scripts/demo-write-check.ps1 -Programs bad.n8`. - Results: all 41 parser fixtures pass (lowest expression SP `$A7`); `interfaces.n8` reports 6 interface slots and 11 members that match the source oracle, and `ifacebad.n8` matches all six exact diagnostics. The diagnostics catalog has 70 entries and its screen/ERR expectations and docs are in sync. The lexer still matches 10 fixtures / 6,733 bytes. The demo rebuilt and linked `interfaces.s`; good.n8 completed its Vim save and C128 check in the full run, and the bad.n8 rerun saved 258 PETSCII bytes identically and reported E151, E152, E120, and E061. - Files changed: as listed under File area. - Remaining risks: conformance positions are class-level (line, column 1) because member rows do not store a source column; the message names the method. E132 is anchored on a class method that matches another requirement; a class with no method at all still rejects each interface with E130. An implements entry naming no declared type is left to pass 2's unknown-name diagnostic, so E133 only covers declared classes/programs. The VICE verifier defaults on this machine (6532/6534/6535) can produce an empty monitor reply; all runs used `-Port 6530`. Interface dispatch tables and their MAP output remain E04/E05 work; C_MEM_SLOT is the stable input for them.