diff options
| -rw-r--r-- | src/bootstrap/main.src | 14 | ||||
| -rw-r--r-- | src/codegen.zig | 27 |
2 files changed, 20 insertions, 21 deletions
diff --git a/src/bootstrap/main.src b/src/bootstrap/main.src index 22af2d1..508002d 100644 --- a/src/bootstrap/main.src +++ b/src/bootstrap/main.src @@ -8,6 +8,8 @@ extern fclose = (*i8) => *i8; extern malloc = (i64) => *i8; extern free = (*i8) => void; +import "!stdlib.src"; + import "tokenizer.src"; let file_size = 0; @@ -32,23 +34,23 @@ let read_file = (filename: *i8) => *i8 { let main = (argc: i64, argv: **i8) => i64 { let filename = *(argv + 1); - printf("%s\n", filename); + println("%s", filename); let buf = read_file(filename); - printf("File size: %d\n", file_size); + println("File size: %d", file_size); - printf("%s", buf); + println("%s", buf); let i = 0; while i < file_size { let c = (*(buf + i)); if c == '}' { - printf("BRACE!\n"); + println("BRACE!"); }; - printf("C: %c\n", c); + println("C: %c", c); i = i + 1; }; @@ -56,7 +58,7 @@ let main = (argc: i64, argv: **i8) => i64 { free(buf); fclose(file); - printf("TEST: %d\n", test()); + println("TEST: %d", test()); return 0; }; diff --git a/src/codegen.zig b/src/codegen.zig index f312a0d..bcac597 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -570,25 +570,22 @@ pub const CodeGen = struct { }, .TYPE => |typ| { std.debug.assert(typ == .FUNCTION_TYPE); - const function_type = try self.get_llvm_type(expression); - const function = llvm.LLVMAddFunction(self.llvm_module, try std.fmt.allocPrintZ(self.arena, "{s}", .{name.?}), function_type); + std.debug.assert(self.environment.scope_stack.items.len == 1); - // Global functions - if (self.environment.scope_stack.items.len == 1) { - return try self.create_variable(.{ - .value = function, - .stack_level = null, - .node = expression, - .node_type = expression, - }); + const variable = self.environment.get_variable(name.?); + if (variable) |v| { + return v; } - const ptr = self.environment.get_variable(name.?); - _ = llvm.LLVMBuildStore(self.builder, function, ptr.?.value) orelse return CodeGenError.CompilationError; - ptr.?.node = expression; - ptr.?.node_type = expression; + const function_type = try self.get_llvm_type(expression); + const function = llvm.LLVMAddFunction(self.llvm_module, try std.fmt.allocPrintZ(self.arena, "{s}", .{name.?}), function_type); - return ptr.?; + return try self.create_variable(.{ + .value = function, + .stack_level = null, + .node = expression, + .node_type = expression, + }); }, else => unreachable, }; |