From 155dec506b8f2cf381f08139017c3650f6ab7394 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Mon, 1 Jul 2024 20:00:00 +0200 Subject: Evaluate identifiers in other scopes --- src/codegen.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/codegen.c b/src/codegen.c index f81e9b9..246c176 100644 --- a/src/codegen.c +++ b/src/codegen.c @@ -198,8 +198,7 @@ codegentypedexpr(struct cgctx ctx, idx_t i, type_t type, LLVMValueRef *outv) case ASTIDENT: { strview_t sv = ctx.toks.strs[ctx.ast.lexemes[i]]; LLVMTypeRef t = type2llvm(ctx, ctx.types[i]); - LLVMValueRef ptrval = - symtab_insert(&ctx.scps[ctx.scpi].map, sv, NULL)->v; + LLVMValueRef ptrval = symtab_get_from_scopes(ctx, sv)->v; *outv = LLVMBuildLoad2(ctx.bob, t, ptrval, "load"); return fwdnode(ctx.ast, i); } @@ -414,6 +413,7 @@ codegendecl(struct cgctx ctx, idx_t i) char *name = tmpalloc(ctx.s, sv.len + 1, 1); LLVMTypeRef t = type2llvm(ctx, ctx.types[i]); LLVMValueRef globl = LLVMAddGlobal(ctx.mod, t, svtocstr(name, sv)); + symtab_insert(&ctx.scps[ctx.scpi].map, sv, NULL)->v = globl; LLVMValueRef v; if (p.rhs == AST_EMPTY) { -- cgit v1.2.3