diff options
| author | Nic Gaffney <gaffney_nic@protonmail.com> | 2024-08-13 17:28:34 -0500 |
|---|---|---|
| committer | Nic Gaffney <gaffney_nic@protonmail.com> | 2024-08-13 17:28:34 -0500 |
| commit | b1ad4a1c280d25f92fdb1103edf2faa5e3e1daac (patch) | |
| tree | 9c2cabee2c9ca5af94752efff2aed826a2b18f6a /src/codegen.zig | |
| parent | cf80bb7f1b6fb4ee1d08d3d6850966b4951274b5 (diff) | |
| download | calico-b1ad4a1c280d25f92fdb1103edf2faa5e3e1daac.tar.gz | |
Added type checking on function calls
Diffstat (limited to 'src/codegen.zig')
| -rw-r--r-- | src/codegen.zig | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/codegen.zig b/src/codegen.zig index 3922a75..cdcffdd 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -10,6 +10,7 @@ const types = llvm.types; const CodegenError = error{ Immutable, OutOfMemory, + IncorrectType, }; fn toLLVMtype(typ: parse.TypeIdent, sym: *symb.SymbolTable, expr: ?parse.NodeExpr) types.LLVMTypeRef { @@ -232,11 +233,16 @@ pub const Generator = struct { }, .call => |call| blk: { + std.debug.print("Function {s} requested\n", .{call.ident.ident}); + + 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); - for (call.args) |arg| + for (call.args, functype.input) |arg, intype| { + if (!std.meta.eql(expr.symtable.getType(arg.typ.?).?, intype)) return CodegenError.IncorrectType; try args.append(try self.genExpr(arg)); + } const funcType = core.LLVMGlobalGetValueType(function); // std.debug.print("FUNCTYPE: {s}\n", .{call.ident.ident}); |
