diff options
| author | Baitinq <[email protected]> | 2025-03-09 09:52:54 +0100 |
|---|---|---|
| committer | Baitinq <[email protected]> | 2025-03-09 09:52:54 +0100 |
| commit | 21432e8965403975a3f8e9175a46430b7b818241 (patch) | |
| tree | 32780c229213c6df29f68cbd90dbe1c5de7a5895 | |
| parent | Feature: Add support for mod operator (diff) | |
| download | interpreter-21432e8965403975a3f8e9175a46430b7b818241.tar.gz interpreter-21432e8965403975a3f8e9175a46430b7b818241.tar.bz2 interpreter-21432e8965403975a3f8e9175a46430b7b818241.zip | |
Codegen: Fix bug with if statements inside while loops
Diffstat (limited to '')
| -rw-r--r-- | examples/10.src | 8 | ||||
| -rw-r--r-- | src/codegen.zig | 8 |
2 files changed, 8 insertions, 8 deletions
diff --git a/examples/10.src b/examples/10.src index b840849..59f91e1 100644 --- a/examples/10.src +++ b/examples/10.src @@ -6,9 +6,11 @@ let main = () => i64 { counter = counter + 1; }; - while counter % 3 == 0 { - print(0); + while true { + if counter == 10 { + return counter; + }; }; - return counter; + return 1; }; diff --git a/src/codegen.zig b/src/codegen.zig index 98b7c16..45ebde6 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -203,7 +203,7 @@ pub const CodeGen = struct { for (if_statement.statements) |stmt| { try self.generate_statement(stmt); } - const merge_block = core.LLVMAppendBasicBlock(core.LLVMGetLastFunction(self.llvm_module), "else_block"); + const merge_block = core.LLVMAppendBasicBlock(core.LLVMGetLastFunction(self.llvm_module), "merge_block"); const last_instr = core.LLVMGetLastInstruction(then_block); if (core.LLVMIsATerminatorInst(last_instr) == null) { _ = core.LLVMBuildBr(self.builder, merge_block); @@ -233,10 +233,8 @@ pub const CodeGen = struct { for (while_statement.statements) |stmt| { try self.generate_statement(stmt); } - const last_instr = core.LLVMGetLastInstruction(inner_block); - if (core.LLVMIsATerminatorInst(last_instr) == null) { - _ = core.LLVMBuildBr(self.builder, while_block); - } + + _ = core.LLVMBuildBr(self.builder, while_block); core.LLVMPositionBuilderAtEnd(self.builder, outer_block); } |