Skip to content

Commit

Permalink
fix(vm): OP_DEFINE_GLOBAL would exand globals slice to far
Browse files Browse the repository at this point in the history
closes #314
  • Loading branch information
giann committed Nov 13, 2024
1 parent 24711ea commit e27bc7b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/vm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit e27bc7b

Please sign in to comment.