From e27bc7b311561ad36045000cb74038cccc70cf25 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Wed, 13 Nov 2024 08:43:15 +0100 Subject: [PATCH] fix(vm): OP_DEFINE_GLOBAL would exand globals slice to far closes #314 --- src/vm.zig | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/vm.zig b/src/vm.zig index 9ae615d3..02e4445a 100644 --- a/src/vm.zig +++ b/src/vm.zig @@ -446,6 +446,7 @@ pub const VM = struct { current_fiber: *Fiber, current_ast: Ast, globals: std.ArrayList(Value), + // FIXME: remove globals_count: usize = 0, import_registry: *ImportRegistry, jit: ?JIT = null, @@ -1034,8 +1035,9 @@ pub const VM = struct { self.panic("Out of memory"); unreachable; }; - self.globals.expandToCapacity(); + self.globals.items.len = arg + 1; self.globals.items[arg] = self.peek(0); + self.globals_count = @max(self.globals_count, arg); _ = self.pop(); @@ -2182,6 +2184,7 @@ pub const VM = struct { self.panic("Out of memory"); unreachable; }; + import_cache.append(global) catch { self.panic("Out of memory"); unreachable;