# V3 compiles itself (runtime) — stage-2 fixpoint for a test file Tag `v3-selfcompiles`. Main suite 111/111. ## The milestone The **self-compiled V3** (`/tmp/M2self`, built by V3 from its own sources) now runs, parses, and emits code. For a test file its output is **byte-identical** to the gm2-built V3's: ``` ./M2 tests/t_constfold.mod -> gen_ssa/TConstFold.ssa /tmp/M2self tests/t_constfold.mod -> gen_ssa/TConstFold.ssa cmp: *** IDENTICAL *** ``` That is a stage-2 self-hosting fixpoint for `t_constfold`. ## Fixes in this step 1. **Eager `OR`/`AND` NIL dereferences** — gm2 short-circuits, V3 does not. Rewrote `SymTab`'s guard sites (`(x = NIL) OR (x^.…)`) into sequential checks, and the driver's `PrintListing` loop (`(nextErr # NIL) AND (nextErr^.line = …)`) into a `done` flag. 2. **Off-by-one in string scans** — `QbeGen`'s `Len`/`Cpy`/`App`/`ParseInt` looped with `i < HIGH(s)`; for a string *literal* `HIGH = len-1`, so the last character was dropped. `App(fname, "gen_ssa/")` produced `"gen_ssa"`, mangling the output file name. Changed to `<= HIGH(s)`. ## Status - Self-compiled V3 compiles a small file correctly (byte-identical). - Compiling the **whole compiler source set** with the self-compiled V3 still aborts (rc 134) — the next runtime bug (likely a capacity or a construct in the compiler's own sources). This is the remaining path to the full 3-stage fixpoint. ## Remaining 1. Fix the self-image abort (diagnose with gdb on `/tmp/M2self` over the full set). 2. Cross-stage `FileIO` selection and `bootstrap/fixpoint.sh` (Stage1 gm2 → Stage2 V3 → Stage3 V3, byte-identical `.ssa`), with the stage-aware CR flag. ## Files `compiler/src/{SymTab.mod,compiler.frm,QbeGen.mod,M2.lst}`.