diff options
| author | Nic Gaffney <gaffney_nic@protonmail.com> | 2025-02-19 18:46:21 -0600 |
|---|---|---|
| committer | Nic Gaffney <gaffney_nic@protonmail.com> | 2025-02-19 18:46:21 -0600 |
| commit | 2c44d648157a6dbfd847e939016316032c6742a4 (patch) | |
| tree | 9d19f0face496f3e520f8c69536f6cffe2879364 /src | |
| parent | 4ea2876e8243a86276917e691a335caed7a8fd74 (diff) | |
| download | calico-2c44d648157a6dbfd847e939016316032c6742a4.tar.gz | |
Fixed while loops
Diffstat (limited to 'src')
| -rw-r--r-- | src/codegen.zig | 10 | ||||
| -rw-r--r-- | src/parser.zig | 2 |
2 files changed, 4 insertions, 8 deletions
diff --git a/src/codegen.zig b/src/codegen.zig index ef65cf6..c19dfbc 100644 --- a/src/codegen.zig +++ b/src/codegen.zig @@ -199,19 +199,14 @@ pub const Generator = struct { const func = self.currentFunc.?; const then = core.LLVMAppendBasicBlock(func, "then"); - const elsebb = core.LLVMAppendBasicBlock(func, "elsebb"); const cont = core.LLVMAppendBasicBlock(func, "continue"); - _ = core.LLVMBuildCondBr(self.builder, condition, then, elsebb); + _ = core.LLVMBuildCondBr(self.builder, condition, then, cont); _ = core.LLVMPositionBuilderAtEnd(self.builder, then); try self.genStmt(block.*); const newcondition = try self.genExpr(expr); - _ = core.LLVMBuildCondBr(self.builder, newcondition, then, elsebb); - _ = core.LLVMBuildBr(self.builder, cont); - - _ = core.LLVMPositionBuilderAtEnd(self.builder, elsebb); - _ = core.LLVMBuildBr(self.builder, cont); + _ = core.LLVMBuildCondBr(self.builder, newcondition, then, cont); _ = core.LLVMPositionBuilderAtEnd(self.builder, cont); } @@ -298,6 +293,7 @@ pub const Generator = struct { .slash => core.LLVMBuildSDiv(self.builder, lhs, rhs, "div"), .eqleql => core.LLVMBuildICmp(self.builder, types.LLVMIntPredicate.LLVMIntEQ, lhs, rhs, "eql"), .lessthan => core.LLVMBuildICmp(self.builder, types.LLVMIntPredicate.LLVMIntSLT, lhs, rhs, "slt"), + .greaterthan => core.LLVMBuildICmp(self.builder, types.LLVMIntPredicate.LLVMIntSGT, lhs, rhs, "sgt"), else => return error.Unimplemented, }; }, diff --git a/src/parser.zig b/src/parser.zig index ebd4b33..bd4627d 100644 --- a/src/parser.zig +++ b/src/parser.zig @@ -255,7 +255,7 @@ pub const Parser = struct { const precTable: []const []const tok.TokenType = &.{ &.{ .plus, .minus }, &.{ .star, .slash }, - &.{ .eqleql, .lessthan }, + &.{ .eqleql, .lessthan, .greaterthan }, }; return try self.genBinOp(precTable[0], typ, lhsptr) //. |
