Skip to content

Commit 247c3a1

Browse files
committed
feat: implement bytecode generator for AST expressions, variables, and function calls.
1 parent f68b529 commit 247c3a1

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

src/compiler/bytecode_gen.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "../../include/common.h"
88
#include "../../include/value.h"
99
#include "../../include/object.h"
10+
#include "../../include/vm.h"
1011
#include <stddef.h>
1112

1213
// --- Compiler & Scope Types ---
@@ -479,12 +480,15 @@ static void genFunction(BytecodeGen* gen, Stmt* stmt, bool defineVar) {
479480
funcCompiler.function->isStatic = stmt->as.func_decl.isStatic;
480481
funcCompiler.function->isAbstract = stmt->as.func_decl.isAbstract;
481482

483+
// Protect function from GC during copyString
484+
push(&vm, OBJ_VAL(funcCompiler.function));
482485
if (stmt->as.func_decl.name != NULL) {
483486
funcCompiler.function->name = copyString(stmt->as.func_decl.name, strlen(stmt->as.func_decl.name));
484487
}
488+
pop(&vm);
485489

486-
bool isInitDebug = (stmt->as.func_decl.name != NULL && strcmp(stmt->as.func_decl.name, "init") == 0);
487-
fprintf(stderr, "Compiling function '%s' (isInit: %d)\n", stmt->as.func_decl.name ? stmt->as.func_decl.name : "NULL", isInitDebug);
490+
// bool isInitDebug = (stmt->as.func_decl.name != NULL && strcmp(stmt->as.func_decl.name, "init") == 0);
491+
// fprintf(stderr, "Compiling function '%s' (isInit: %d)\n", stmt->as.func_decl.name ? stmt->as.func_decl.name : "NULL", isInitDebug);
488492

489493
beginScope(gen);
490494

0 commit comments

Comments
 (0)