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:
6
library/vendors/sx_trace_runtime/sx_trace.c
vendored
6
library/vendors/sx_trace_runtime/sx_trace.c
vendored
@@ -74,7 +74,7 @@ uint64_t sx_trace_frame_at(uint32_t i) {
|
||||
// `string` is `{ const char* ptr; int64_t len; }`. This mirror MUST stay in
|
||||
// lockstep with `getFrameStructType` in emit_llvm.zig and `Frame` in trace.sx.
|
||||
typedef struct { const char *ptr; int64_t len; } SxStr;
|
||||
typedef struct { SxStr file; int32_t line; int32_t col; SxStr func; } SxFrame;
|
||||
typedef struct { SxStr file; int32_t line; int32_t col; SxStr func; SxStr line_text; } SxFrame;
|
||||
|
||||
// The failable-`main` entry-point reporter (ERR step E4.2). Called by the
|
||||
// emitted main wrapper when an error reaches the function boundary: prints the
|
||||
@@ -99,5 +99,9 @@ void sx_trace_report_unhandled(uint32_t tag, const char *name, size_t name_len)
|
||||
(int)f->func.len, f->func.ptr,
|
||||
(int)f->file.len, f->file.ptr,
|
||||
f->line, f->col);
|
||||
if (f->line_text.len > 0) {
|
||||
dprintf(2, " %.*s\n", (int)f->line_text.len, f->line_text.ptr);
|
||||
dprintf(2, " %*s^\n", f->col > 0 ? f->col - 1 : 0, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user