haku2: make server use haku2 (and make it work!)

This commit is contained in:
りき萌 2025-06-13 20:11:52 +02:00
parent c5e2892def
commit 48d03699bd
16 changed files with 329 additions and 174 deletions

View file

@ -17,13 +17,12 @@ stack_top: u32 = 0,
call_stack: []CallFrame,
call_stack_top: u32 = 0,
defs: []Value,
fuel: u32,
fuel: u32 = 0, // NOTE: VM must be refueled via reset() before running code
exception: ?Exception = null,
pub const Limits = struct {
stack_capacity: usize = 256,
call_stack_capacity: usize = 256,
fuel: u32 = 63336,
};
pub const CallFrame = struct {
@ -50,10 +49,16 @@ pub fn init(a: mem.Allocator, defs: *const bytecode.Defs, limits: *const Limits)
.stack = try a.alloc(Value, limits.stack_capacity),
.call_stack = try a.alloc(CallFrame, limits.call_stack_capacity),
.defs = try a.alloc(Value, defs.num_defs),
.fuel = limits.fuel,
};
}
pub fn reset(vm: *Vm, fuel: u32) void {
vm.stack_top = 0;
vm.call_stack_top = 0;
vm.fuel = fuel;
vm.exception = null;
}
pub fn throw(vm: *Vm, comptime fmt: []const u8, args: anytype) Error {
log.debug("throw: fmt={s}", .{fmt});