diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-08-27 22:07:14 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-08-27 22:07:14 +0100 |
| commit | f914488506c83ae98ee699d88501d7df756dbae5 (patch) | |
| tree | dff208a90456c77fece89e653072bc870459ce75 /src/main/java | |
| parent | d408f4f80670ed7f73d09f8ccfefdcb8a7835406 (diff) | |
Fix generation of if instruction for while loop
Diffstat (limited to 'src/main/java')
| -rw-r--r-- | src/main/java/org/shedlang/compiler/stackir/StackCompiler.java | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java b/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java index f4580e69..570ce62a 100644 --- a/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java +++ b/src/main/java/org/shedlang/compiler/stackir/StackCompiler.java @@ -418,11 +418,18 @@ public class StackCompiler { context = context.enterBlock(List.of()); context = compileExpression(node.condition(), context); + // TODO: support no yielding from if instruction? context = context.addInstruction(new IfInstruction( - List.of(), - List.of(new LoopBreakInstruction(node.source())), + List.of( + new PushUnitInstruction(node.source()) + ), + List.of( + new LoopBreakInstruction(node.source()), + new PushUnitInstruction(node.source()) + ), node.source() )); + context = context.addInstruction(new DiscardInstruction(node.source())); context = context.addInstructions(ifTrueInstructions); |
