fix some rough edges around stack traces
hide irrelevant CallFrames fix span info for the implicit stack frame
This commit is contained in:
parent
e49885c83a
commit
7a52dbebd0
4 changed files with 34 additions and 11 deletions
|
@ -30,7 +30,7 @@ pub const Limits = struct {
|
|||
};
|
||||
|
||||
pub const CallFrame = struct {
|
||||
closure: *const value.Closure,
|
||||
closure: ?*const value.Closure,
|
||||
return_addr: ?[*]const u8,
|
||||
bottom: u32,
|
||||
};
|
||||
|
@ -100,7 +100,7 @@ pub fn outOfMemory(vm: *Vm) Error {
|
|||
|
||||
// NOTE: Different from CallFrame, this is a helper type for obtaining stack traces.
|
||||
pub const StackFrame = struct {
|
||||
closure: *const value.Closure,
|
||||
closure: ?*const value.Closure,
|
||||
ip: ?[*]const u8,
|
||||
};
|
||||
|
||||
|
@ -117,7 +117,17 @@ pub fn stackFrame(vm: *const Vm, index: usize) StackFrame {
|
|||
if (index == 0) {
|
||||
return .{
|
||||
.closure = closure,
|
||||
.ip = vm.ip,
|
||||
// Span info hairiness:
|
||||
// Because call frames place the instruction pointer past the call instruction,
|
||||
// the frontend subtracts 1 from it to get a position within the chunk that
|
||||
// has the correct line info.
|
||||
// This subtracting by one doesn't work for the implicit stack frame though, because
|
||||
// its ip gets updated at the _start_ of the instruction---meaning that if you
|
||||
// subtract one from it, it'll point to the _previous_ instruction, while the actual
|
||||
// error occurred in the current one.
|
||||
// To alleviate this, add one here to point to either the middle or the end of the
|
||||
// current instruction.
|
||||
.ip = if (vm.ip) |ip| ip + 1 else null,
|
||||
};
|
||||
} else {
|
||||
// NOTE: Minus two, because remember index == 0 is occupied by the current stack frame.
|
||||
|
@ -269,7 +279,7 @@ pub fn run(
|
|||
}
|
||||
|
||||
try vm.pushCall(.{
|
||||
.closure = closure,
|
||||
.closure = null,
|
||||
.return_addr = null, // nowhere to return to
|
||||
.bottom = bottom,
|
||||
});
|
||||
|
@ -591,7 +601,7 @@ pub fn run(
|
|||
try vm.push(result);
|
||||
|
||||
if (call_frame.return_addr) |addr| {
|
||||
closure = call_frame.closure;
|
||||
closure = call_frame.closure.?;
|
||||
ip = addr;
|
||||
bottom = call_frame.bottom;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue