File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -486,18 +486,24 @@ static InterpretResult run(VM *vm) {
486486}
487487
488488InterpretResult 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 ;
You can’t perform that action at this time.
0 commit comments