From f914488506c83ae98ee699d88501d7df756dbae5 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 27 Aug 2023 22:07:14 +0100 Subject: Fix generation of if instruction for while loop --- .../java/org/shedlang/compiler/stackir/StackCompiler.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/main/java') 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); -- cgit v1.2.3