#run failures now print the same `func at file:line:col` trace as runtime, resolved in-process via the interpreter's IR/source tables. - Read-side context-split op `.trace_resolve` (mirror of .trace_frame), lowered from a name-recognized `__trace_resolve_frame(u64) -> Frame`. - emit_llvm: inttoptr the operand to *Frame + load (the value .trace_frame stamped in). - interp: unpack (func_id << 32 | span.start); resolve func/file from module.functions and line/col via SourceLoc.compute over a new source_map (setSourceMap wired at every production interp site). - trace.sx: frame_at -> u64; to_string routes each frame through __trace_resolve_frame, so one source works in both machines. Compiled path behavior unchanged (243/244/247 identical; it now loads via the op). New examples/253-comptime-trace.sx exercises the comptime path. Gates: zig build, zig build test, run_examples.sh -> 291 passed.
34 lines
889 B
Plaintext
34 lines
889 B
Plaintext
// Comptime return-trace resolution (ERR E3.0 slice 3b). A `#run` block that
|
|
// raises, propagates via `try`, and catches the error, then formats the trace
|
|
// with `trace.print_current()`. At comptime a frame is a packed
|
|
// `(func_id, span.start)` (not a `*Frame`); the interpreter's `.trace_resolve`
|
|
// unpacks it and resolves `file:line:col` via the module + source map — so the
|
|
// comptime trace prints the same `func at file:line:col` form as a runtime one.
|
|
// Expected exit: 0 (the error is caught; the trace is printed during the build).
|
|
|
|
#import "modules/std.sx";
|
|
trace :: #import "modules/trace.sx";
|
|
|
|
TErr :: error { Bad };
|
|
|
|
leaf :: () -> !TErr {
|
|
raise error.Bad;
|
|
}
|
|
|
|
mid :: () -> !TErr {
|
|
try leaf();
|
|
}
|
|
|
|
probe :: () {
|
|
mid() catch e {
|
|
print("comptime caught {}\n", e);
|
|
trace.print_current();
|
|
};
|
|
}
|
|
|
|
#run probe();
|
|
|
|
main :: () -> s32 {
|
|
return 0;
|
|
}
|