about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorBaitinq <[email protected]>2025-05-28 22:13:43 +0200
committerBaitinq <[email protected]>2025-05-28 22:13:43 +0200
commit86afb18dd32711c26c24e9cebec7f3dd91d4a8ee (patch)
treee189568a3cc1debe8fff761fa874c792bbc9a948 /src
parentFeature: Add sizeof builtin function (diff)
downloadinterpreter-86afb18dd32711c26c24e9cebec7f3dd91d4a8ee.tar.gz
interpreter-86afb18dd32711c26c24e9cebec7f3dd91d4a8ee.tar.bz2
interpreter-86afb18dd32711c26c24e9cebec7f3dd91d4a8ee.zip
Feature: Support custom types in llvm_get_type
Diffstat (limited to 'src')
-rw-r--r--src/codegen.zig8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/codegen.zig b/src/codegen.zig
index d246853..3ab3a5c 100644
--- a/src/codegen.zig
+++ b/src/codegen.zig
@@ -151,7 +151,7 @@ pub const CodeGen = struct {
                 if (self.environment.scope_stack.items.len == 1) {
                     try self.environment.add_variable(identifier.name, try self.create_variable(.{
                         .value = variable.value,
-                        .type = null,
+                        .type = variable.type,
                         .node = variable.node,
                         .node_type = variable.node_type,
                         .stack_level = null,
@@ -190,7 +190,7 @@ pub const CodeGen = struct {
 
                 const new_variable = try self.create_variable(.{
                     .value = ptr,
-                    .type = null,
+                    .type = variable.type,
                     .node = variable.node,
                     .node_type = typ,
                     .stack_level = null,
@@ -848,6 +848,10 @@ pub const CodeGen = struct {
                 if (std.mem.eql(u8, t.name, "bool")) return llvm.LLVMInt1Type();
                 if (std.mem.eql(u8, t.name, "void")) return llvm.LLVMVoidType();
                 if (std.mem.eql(u8, t.name, "varargs")) return llvm.LLVMPointerType(llvm.LLVMInt64Type(), 0); // Hack for varargs (only used for printf)
+                if (self.environment.get_variable(t.name)) |v| {
+                    std.debug.assert(v.type != null);
+                    return v.type;
+                }
                 std.debug.print("Unknown type: {s}\n", .{t.name});
                 unreachable;
             },