Skip to content

Commit 67189b2

Browse files
committed
feat: implement the virtual machine with bytecode interpreter and instruction dispatch.
1 parent 69379a2 commit 67189b2

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/runtime/vm.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,18 +486,24 @@ static InterpretResult run(VM *vm) {
486486
}
487487

488488
InterpretResult interpretAST(VM* pvm, StmtList* statements) {
489+
// Disable GC during compilation to prevent freeing unrooted function/constants
490+
size_t oldNextGC = pvm->nextGC;
491+
pvm->nextGC = (size_t)-1; // SIZE_MAX
492+
489493
ObjFunction* function = newFunction();
490494

491495
// Connect the AST-based bytecode generator
492496
generateBytecode(statements, &function->chunk);
493497

494-
// Setup for execution
495498
// Setup for execution
496499
push(pvm, OBJ_VAL(function));
497500
ObjClosure* closure = newClosure(function);
498501
pop(pvm);
499502
push(pvm, OBJ_VAL(closure));
500503

504+
// Restore GC
505+
pvm->nextGC = oldNextGC;
506+
501507
CallFrame* frame = &pvm->frames[pvm->frameCount++];
502508
frame->closure = closure;
503509
frame->ip = function->chunk.code;

0 commit comments

Comments
 (0)