Sfoglia il codice sorgente

docs: session save 2026-09-25 — self-hosting runtime (nested modules, inline array fields, NUL strings); scanner Reset deref-pointer VAR-actual blocker

Eric Streit 2 settimane fa
parent
commit
1070dfe9a4
1 ha cambiato i file con 58 aggiunte e 0 eliminazioni
  1. 58 0
      docs/session-2026-09-25.md

+ 58 - 0
docs/session-2026-09-25.md

@@ -0,0 +1,58 @@
+# Session save — 2026-09-25: self-hosting runtime
+
+Started from "the whole compiler source set compiles under V3 and links"
+(`v3-selfcompile-image`) and pushed the **runtime** much further.
+
+## Landed
+
+| Tag | What |
+|---|---|
+| `v3-selfcompile-image` | nested modules (`ListHandler`); `HALT`; `Strings.Delete`/`Append`; 1-char literal to `VAR ARRAY OF CHAR`; nested anonymous-array bound-clobber fix; `sessBuf` 4 MiB + manual flush; `strNams/strTexts` 4096 |
+| `v3-inline-array-fields` | record array fields are **inline** (standard M2 layout), not pointers: SymTab layout, QbeGen data/access/copy, `InitHeap` in place, `SymTab` `ALLOCATE`→`NEW` |
+| `v3-nul-strings` | **NUL-terminated** CHAR arrays (terminator slot at index = count, index = count readable); stdlib `Strings` and the C shim are NUL-based; `m2arg` keeps capacity |
+| `af392e1` | scanner `Reset`: `NEW(buf[i])` (BufBlock needs a descriptor header) |
+
+Main suite 111/111 throughout.
+
+## Self-compiled compiler status
+
+It now:
+1. **runs** (no startup crash — the heap/inline-array fix),
+2. **opens its input** via the self-hosted `FileIO` + shim,
+3. **starts parsing** — and crashes in the scanner's `Reset`.
+
+## Current blocker (reproduced minimally)
+
+For a `VAR` actual that is a **dereferenced pointer** (`p^` where
+`p: POINTER TO ARRAY`), V3 passes the wrong address. Repro:
+
+```modula2
+TYPE Block = ARRAY [0..15] OF CHAR;
+TYPE Buf = ARRAY [0..3] OF POINTER TO Block;
+VAR b : Buf;
+PROCEDURE Fill (VAR a : ARRAY OF CHAR); BEGIN a[0] := 'z' END Fill;
+NEW(b[0]); Fill(b[0]^);          (* emitted: call Fill(l 0, l $Buf_b) *)
+```
+
+The SSA computes `%t = loadl(b[0])` (the pointee address) but the call
+passes `$Buf_b` — Fact's `NoteAddr(q, AddrOf("b"))` overwrites the
+correct address for a `^` result. This is exactly the scanner's
+`FileIO.ReadBytes(src, buf[i]^, read)` (`Reset`), which then writes the
+file contents over `buf`.
+
+**Fix direction**: `Design` must distinguish "q is the loaded value of a
+plain variable" (→ `NoteAddr(q, AddrOf(var))`) from "q is already an
+address" (deref of non-scalar, array/record designator) → `NoteAddr(q, q)`.
+Needs a Design output flag (e.g. `addrQ: BOOLEAN`).
+
+## Remaining after that
+
+- Re-run the self-compiled compiler on a file; iterate on further
+  runtime bugs.
+- Cross-stage `FileIO` selection and `bootstrap/fixpoint.sh`
+  (Stage1 gm2 → Stage2 V3 → Stage3 V3, byte-identical `.ssa`), with the
+  stage-aware CR flag (`-m` for gm2, no `-m` for V3).
+
+## Note
+
+`compiler/toto.mod` is the user's uncommitted edit (left alone).