ERR/E3.0 (slice 3c): source snippet + caret in traces

Each trace frame now shows the offending source line with a `^` caret
under the column — in the catch-handler formatter, the failable-main C
reporter, and the comptime path.

The source line is embedded at compile time as a 5th Frame field
(line_text), not read from disk at runtime: the file field is a
basename and a runtime read would add a filesystem dependency that
fails under the test harness and on locked-down targets.

- errors.lineAt(src, offset): shared helper for the whole source line.
- Frame gains line_text (mirrored in emit_llvm getFrameStructType,
  trace.sx Frame, sx_trace.c SxFrame). emitTraceFrame embeds it; the
  interp .trace_resolve extracts it from the source map.
- trace.sx (new spaces helper) and the C reporter render the line +
  a col-aligned caret, guarded on a non-empty line_text.

Snapshots 243/244/247/253 regenerated. Gates: zig build, zig build
test, run_examples.sh -> 291 passed.
This commit is contained in:
agra
2026-06-01 15:43:22 +03:00
parent b5241243e6
commit 178449b548
10 changed files with 72 additions and 10 deletions

View File

@@ -85,10 +85,12 @@ context (next section).
### The frame: an embedded `Frame`, not a PC
**A runtime frame is a pointer to a compile-time-interned
`Frame {file, line, col, func}`.** The lowerer already knows the push
`Frame {file, line, col, func, line_text}`.** The lowerer already knows the push
site's source location (the instruction's span + the enclosing function),
so the location is baked into read-only data at compile time and the
formatter reads it directly. No PC capture, no DWARF, no symbolizer.
so the location *and the offending source line itself* (`line_text`, for the
`^` caret snippet) — is baked into read-only data at compile time and the
formatter reads it directly. No PC capture, no DWARF, no symbolizer, no runtime
file read.
A comptime frame is instead a packed `(func_id: u32, ir_offset: u32)`,
resolved through the interpreter's in-memory IR/source tables. The
@@ -435,7 +437,7 @@ a Mach-O debug map, never register JIT DWARF.
| DWARF emission (compile unit / subprogram / line table) | ✅ done — E3.0 slice 2 (`c32d694`) |
| Niladic trace-push op + interned `Frame` table (runtime) | ✅ done — E3.3 slice 3a (`1b6cbc1`) |
| Comptime resolver (`func_id, ir_offset` → location) | ✅ done — slice 3b |
| Source snippet + `^` caret | ⏳ planned — slice 3c |
| Source snippet + `^` caret | ✅ done — slice 3c (line embedded in `Frame`) |
| `--emit-obj` / `--debug` artifact plumbing | ⏳ planned — slice 3d |
| Stepping verification ladder (macOS → sim → device) | ⏳ planned — slice 3e (capstone) |
| DWARF variable info (`DILocalVariable`, for `p x`) | ⏳ optional follow-on |