aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-08-27 22:07:14 +0100
committerMichael Williamson <mike@zwobble.org>2023-08-27 22:07:14 +0100
commitf914488506c83ae98ee699d88501d7df756dbae5 (patch)
treedff208a90456c77fece89e653072bc870459ce75 /src/main/java
parentd408f4f80670ed7f73d09f8ccfefdcb8a7835406 (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.java11
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);