# m2comp step 6 — WITH + CASE (tag: `m2comp-step6`) Statement-level gap closed with v1 lowering recipes, ported to the tree-walking backend: `WITH` opens a record scope (bare fields, nesting, any record designator incl. `a[i]`), `CASE` lowers to compare-chains over int/char selectors (ranges, multi-labels, `ELSE`). Suite 61/61 (56 inherited + 2 run + 3 reject); new keywords `WITH`/`CASE`/`|` (token numbers shifted, `Msg` regenerated, no test depends on numbers). ## What was built - `src/AST`: `nkWith` (record designator + stmts), `nkCase` (selector + arm chain + else), `nkCaseArm` (label chain + body), `nkRange` (`num` = lo, `op` = hi, both folded) + constructors and `KindName` entries. - Grammar: `WithStat` (record check 215, `PushRecord`/`PopScope` around the body), `CaseStat` (ordinal selector check 213, `EqCheck` per label, `ConstFold` per bound with 230 on non-constant, ranges via `..`), wired into `Stat`. - `src/SymTab`: `ConstFold` accepts `nkChar` (char labels and char bounds; no other change needed — `PushRecord` and `EqCheck` already existed for this). - `src/MGen`: WITH address-temp stack (`withTmps`/`withTyps`, max 8, reset per module); `EmitWith` evaluates any record designator once; bare WITH-fields (`aux = KindField`, no tag) resolve in load/address paths via top-down search (stores flow through the generic address path); `EmitCase` evaluates the selector once and emits per-label `Eq` (ranges: `Ge`+`Le`+`And`) `Jz`-chains into arm bodies. - `run_tests.sh`: `expect_fail` gained an optional `.LST` message argument (existing single-arg calls unchanged). ## Tests — 61/61 `t_with` 51 (fields, nested WITH, `a[i]` argument); `t_case` 138 (multi-labels, `4..6` range, `ELSE`, char selector, fallthrough-free arms). Rejections: WITH on INTEGER (215), record selector (213), variable label (230). ## Bugs found (all fixed, all covered) - None in the compiler: the three rejections "aborted" only inside the suite because the new test lines passed bare filenames to `expect_fail` (it takes `tests/`-prefixed paths), so the driver `HALT`ed on "Could not open input file". Fixed the lines; no compiler change.