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

@@ -27,6 +27,18 @@ Frame :: struct {
line: s32;
col: s32;
func: string;
line_text: string; // the source line, for the snippet + caret
}
// `n` spaces — used to position the `^` caret under a column.
spaces :: (n: s32) -> string {
s := "";
i : s32 = 0;
while i < n {
s = concat(s, " ");
i = i + 1;
}
s;
}
// The error-trace buffer C API (library/vendors/sx_trace_runtime/sx_trace.c),
@@ -54,8 +66,11 @@ to_string :: () -> string {
i : u32 = 0;
while i < n {
f := __trace_resolve_frame(sx_trace_frame_at(i));
line := format(" {} at {}:{}:{}\n", f.func, f.file, f.line, f.col);
result = concat(result, line);
result = concat(result, format(" {} at {}:{}:{}\n", f.func, f.file, f.line, f.col));
if f.line_text.len > 0 {
result = concat(result, format(" {}\n", f.line_text));
result = concat(result, concat(" ", concat(spaces(f.col - 1), "^\n")));
}
i = i + 1;
}
result;