diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-08-28 11:47:29 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-08-28 11:47:29 +0100 |
| commit | 11d6ee8d4eeba3f73414a2325d7bd8bfd7ac6a11 (patch) | |
| tree | 0fdf6ed95f024e7948729f8f876044d672711fc2 /src/test/java/org/shedlang/compiler/stackir | |
| parent | 6a7df59852a7545f5a15955a167e33584330e296 (diff) | |
Support variable result count from if instruction
Diffstat (limited to 'src/test/java/org/shedlang/compiler/stackir')
3 files changed, 8 insertions, 13 deletions
diff --git a/src/test/java/org/shedlang/compiler/stackir/InstructionSerializerTests.java b/src/test/java/org/shedlang/compiler/stackir/InstructionSerializerTests.java index 407621fb..b8a45a0b 100644 --- a/src/test/java/org/shedlang/compiler/stackir/InstructionSerializerTests.java +++ b/src/test/java/org/shedlang/compiler/stackir/InstructionSerializerTests.java @@ -78,6 +78,7 @@ public class InstructionSerializerTests { @Test public void canSerializeIf() { var instruction = Instructions.if_( + 1, List.of( Instructions.pushUnit() ), @@ -93,6 +94,7 @@ public class InstructionSerializerTests { assertThat(string, equalTo(""" ( if + result-count=1 ( (push-unit) ) diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerWhileTests.java b/src/test/java/org/shedlang/compiler/stackir/StackCompilerWhileTests.java index 398a9827..c8fd1cdc 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerWhileTests.java +++ b/src/test/java/org/shedlang/compiler/stackir/StackCompilerWhileTests.java @@ -28,15 +28,11 @@ public class StackCompilerWhileTests { isSequence( isLocalLoadInstruction("c__0"), isIfInstruction( + isSequence(), isSequence( - isPushUnitInstruction() - ), - isSequence( - isLoopBreakInstruction(), - isPushUnitInstruction() + isLoopBreakInstruction() ) ), - isDiscardInstruction(), isPushIntInstruction(42), isDiscardInstruction(), isLoopContinueInstruction() @@ -65,15 +61,11 @@ public class StackCompilerWhileTests { isSequence( isLocalLoadInstruction("c__0"), isIfInstruction( + isSequence(), isSequence( - isPushUnitInstruction() - ), - isSequence( - isLoopBreakInstruction(), - isPushUnitInstruction() + isLoopBreakInstruction() ) ), - isDiscardInstruction(), isPushIntInstruction(42), isDiscardInstruction(), isLoopContinueInstruction() diff --git a/src/test/java/org/shedlang/compiler/stackir/instructions/Instructions.java b/src/test/java/org/shedlang/compiler/stackir/instructions/Instructions.java index 4bc3dc50..ee48a1bd 100644 --- a/src/test/java/org/shedlang/compiler/stackir/instructions/Instructions.java +++ b/src/test/java/org/shedlang/compiler/stackir/instructions/Instructions.java @@ -23,10 +23,11 @@ public class Instructions { } public static Instruction if_( + int resultCount, List<Instruction> trueBody, List<Instruction> falseBody ) { - return new IfInstruction(trueBody, falseBody, Sources.NULL); + return new IfInstruction(resultCount, trueBody, falseBody, Sources.NULL); } public static Instruction intAdd() { |
