haku2: VM logging

This commit is contained in:
りき萌 2025-06-11 10:43:22 +02:00
parent 5de4f9d7c6
commit 7658e0d4e8
5 changed files with 105 additions and 2 deletions

View file

@ -1,6 +1,7 @@
const std = @import("std");
const mem = std.mem;
const debug = std.debug;
const log = std.log;
const testAllocator = std.testing.allocator;
const bytecode = @import("bytecode.zig");
@ -54,6 +55,8 @@ pub fn init(a: mem.Allocator, defs: *const bytecode.Defs, limits: *const Limits)
}
pub fn throw(vm: *Vm, comptime fmt: []const u8, args: anytype) Error {
log.debug("throw: fmt={s}", .{fmt});
const Args = @TypeOf(args);
const max_args_size = @sizeOf(@TypeOf(vm.exception.?.args));
if (@sizeOf(Args) > max_args_size) {
@ -75,6 +78,7 @@ pub fn throw(vm: *Vm, comptime fmt: []const u8, args: anytype) Error {
.args = undefined,
};
@memcpy(exn.args[0..@sizeOf(Args)], mem.asBytes(&args));
vm.exception = exn;
return error.Exception;
}