diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-12-02 14:25:46 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-12-02 14:26:37 +0000 |
| commit | 689c9c1e8af8fd2fff2b390649a59e613e85eb6a (patch) | |
| tree | c2172339570164b3d69db442bb971a5ba383cd8c /src/test/java | |
| parent | ae2db7337845cde0c56cd99564060b974e125f65 (diff) | |
Add resume instruction
Diffstat (limited to 'src/test/java')
7 files changed, 61 insertions, 3 deletions
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenResumeTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenResumeTests.java new file mode 100644 index 00000000..5f23b926 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenResumeTests.java @@ -0,0 +1,27 @@ +package org.shedlang.compiler.patio; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; +import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.testing.snapshots.SnapshotResolver; +import org.shedlang.compiler.testing.snapshots.Snapshotter; + +import java.io.IOException; + +import static org.shedlang.compiler.patio.PatioTesting.serialize; + +@ExtendWith({SnapshotResolver.class}) +public class PatioCodeGenResumeTests { + @Test + public void resumeInstructionGeneratesResumeInstruction(Snapshotter snapshotter) throws IOException { + var stackIr = Instructions.resume(); + var context = PatioCodeGenContext.EMPTY + .temporaryPush(new PatioLocalRef("a")) + .temporaryPush(new PatioLocalRef("b")); + + var result = PatioCodeGen.generateInstruction(stackIr, context); + + snapshotter.assertSnapshot(serialize(result)); + } +} diff --git a/src/test/java/org/shedlang/compiler/patio/PatioSerializerTests.java b/src/test/java/org/shedlang/compiler/patio/PatioSerializerTests.java index 8ff0ff96..626c2470 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioSerializerTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioSerializerTests.java @@ -456,6 +456,15 @@ public class PatioSerializerTests { } @Test + public void canSerializeResume() { + var instruction = Patio.resume(Patio.localRef("value")); + + var string = PatioTesting.serializeInstruction(instruction); + + assertThat(string, equalTo("(resume (local \"value\"))")); + } + + @Test public void canSerializeReturn() { var instruction = Patio.return_(Patio.localRef("value")); diff --git a/src/test/java/org/shedlang/compiler/patio/instructions/Patio.java b/src/test/java/org/shedlang/compiler/patio/instructions/Patio.java index bc44dd2f..2f0b2a61 100644 --- a/src/test/java/org/shedlang/compiler/patio/instructions/Patio.java +++ b/src/test/java/org/shedlang/compiler/patio/instructions/Patio.java @@ -242,6 +242,10 @@ public class Patio { return new PatioLocal(name, type, PatioLocalType.PARAM); } + public static PatioInstruction resume(PatioOperand value) { + return new PatioResume(value, Sources.NULL); + } + public static PatioInstruction return_(PatioOperand value) { return new PatioReturn(value, Sources.NULL); } diff --git a/src/test/java/org/shedlang/compiler/stackir/InstructionSerializerTests.java b/src/test/java/org/shedlang/compiler/stackir/InstructionSerializerTests.java index 2f8c4c44..c36977cf 100644 --- a/src/test/java/org/shedlang/compiler/stackir/InstructionSerializerTests.java +++ b/src/test/java/org/shedlang/compiler/stackir/InstructionSerializerTests.java @@ -333,6 +333,15 @@ public class InstructionSerializerTests { } @Test + public void canSerializeResume() { + var instruction = Instructions.resume(); + + var string = serialize(instruction); + + assertThat(string, equalTo("(resume)")); + } + + @Test public void canSerializeReturn() { var instruction = Instructions.return_(); diff --git a/src/test/java/org/shedlang/compiler/stackir/StackCompilerFunctionResumeTests.java b/src/test/java/org/shedlang/compiler/stackir/StackCompilerFunctionResumeTests.java index 1aa61a57..06c967f9 100644 --- a/src/test/java/org/shedlang/compiler/stackir/StackCompilerFunctionResumeTests.java +++ b/src/test/java/org/shedlang/compiler/stackir/StackCompilerFunctionResumeTests.java @@ -3,8 +3,7 @@ package org.shedlang.compiler.stackir; import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.typed.Typed; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.isPushStringInstruction; -import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.isReturnInstruction; +import static org.shedlang.compiler.stackir.instructions.InstructionMatchers.*; import static org.zwobble.precisely.AssertThat.assertThat; import static org.zwobble.precisely.Matchers.isSequence; @@ -18,7 +17,7 @@ public class StackCompilerFunctionResumeTests { assertThat(result.instructions(), isSequence( isPushStringInstruction("hello"), - isReturnInstruction() + isResumeInstruction() )); } } diff --git a/src/test/java/org/shedlang/compiler/stackir/instructions/InstructionMatchers.java b/src/test/java/org/shedlang/compiler/stackir/instructions/InstructionMatchers.java index a33f4f6c..34c94f0e 100644 --- a/src/test/java/org/shedlang/compiler/stackir/instructions/InstructionMatchers.java +++ b/src/test/java/org/shedlang/compiler/stackir/instructions/InstructionMatchers.java @@ -164,6 +164,12 @@ public class InstructionMatchers { ); } + public static Matcher<Instruction> isResumeInstruction() { + return instanceOf( + ResumeInstruction.class + ); + } + public static Matcher<Instruction> isReturnInstruction() { return instanceOf( ReturnInstruction.class 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 ae776fc7..ce6ebf37 100644 --- a/src/test/java/org/shedlang/compiler/stackir/instructions/Instructions.java +++ b/src/test/java/org/shedlang/compiler/stackir/instructions/Instructions.java @@ -139,6 +139,10 @@ public class Instructions { return new PushUnitInstruction(Sources.NULL); } + public static Instruction resume() { + return new ResumeInstruction(Sources.NULL); + } + public static Instruction return_() { return new ReturnInstruction(Sources.NULL); } |
