diff options
| author | Nic Gaffney <gaffney_nic@protonmail.com> | 2025-10-24 23:49:56 -0500 |
|---|---|---|
| committer | Nic Gaffney <gaffney_nic@protonmail.com> | 2025-10-24 23:49:56 -0500 |
| commit | db11e3b10cc776fd337e473e2912ebe65380bcce (patch) | |
| tree | c355b529532f4f03ae0771ac2708b52d05776919 /src/codegen.zig | |
| parent | c658b86a0770ba99c51bdf4e2df9544363468253 (diff) | |
| download | calico-main.tar.gz | |
Diffstat (limited to 'src/codegen.zig')
| -rw-r--r-- | src/codegen.zig | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/codegen.zig b/src/codegen.zig index 252cf9c..3423a20 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -159,12 +159,13 @@ pub const Generator = struct { block = fun.block.?; codeSlice = block.kind.block; } - const funcName: [*:0]const u8 = "main"; + + const funcName: [*:0]const u8 = try self.allocator.dupeZ(u8, fun.ident.ident); const retType = toLLVMtype(fun.retType.?, table, null); - var params = std.ArrayList(types.LLVMTypeRef).init(self.allocator); + var params = std.ArrayList(types.LLVMTypeRef){}; for (fun.args) |arg| { - try params.append(toLLVMtype(arg.typ, table, null)); + try params.append(self.allocator, toLLVMtype(arg.typ, table, null)); } const funcType = core.LLVMFunctionType(retType, @ptrCast(params.items), @intCast(params.items.len), 0); @@ -323,10 +324,10 @@ pub const Generator = struct { const functype = expr.symtable.getValue(call.ident.ident).?.typ.Function; const ident = try self.allocator.dupeZ(u8, call.ident.ident); const function = core.LLVMGetNamedFunction(self.module, ident); - var args = std.ArrayList(types.LLVMValueRef).init(self.allocator); + var args = std.ArrayList(types.LLVMValueRef){}; for (call.args.items, functype.input) |arg, intype| { if (!std.meta.eql(expr.symtable.getType(arg.typ.?).?, intype)) return { - try util.comptimeError(.{ + util.comptimeError(.{ .line = expr.line, .err = CodegenError.IncorrectType, .got = try intype.toString(self.allocator), @@ -334,7 +335,7 @@ pub const Generator = struct { }); break :blk CodegenError.IncorrectType; }; - try args.append(try self.genExpr(arg)); + try args.append(self.allocator, try self.genExpr(arg)); } std.debug.print("FUNCTYPE: {s}\n", .{call.ident.ident}); std.debug.print("{any}\n", .{function}); |
