From 144875f4687e8cfa77f8b1b7e5ff8790f8f5b684 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Tue, 29 Jul 2025 19:39:22 +0900 Subject: feat: properly calculate stack offset of local variables --- codegen.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'codegen.c') diff --git a/codegen.c b/codegen.c index 234b4e5..0a90602 100644 --- a/codegen.c +++ b/codegen.c @@ -268,9 +268,8 @@ void codegen_func_call(CodeGen* g, AstNode* ast) { } void codegen_lvar(CodeGen* g, AstNode* ast, GenMode gen_mode) { - int offset = 8 + ast->node_idx * 8; printf(" mov rax, rbp\n"); - printf(" sub rax, %d\n", offset); + printf(" sub rax, %d\n", ast->node_stack_offset); printf(" push rax\n"); if (gen_mode == GenMode_rval) { codegen_lval2rval(ast->ty); -- cgit v1.2.3-70-g09d2