diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-07-23 21:22:04 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-07-23 21:22:04 +0100 |
| commit | 23a4308c22a0b8bff2400909449e3e34acc78cff (patch) | |
| tree | f5a3a50ad0db837e987a2ef9b7e57d913922cc45 /src/test/java | |
| parent | d5707930a4e75c2fa47aa3b75fea13575e269009 (diff) | |
Support Patio code gen for ifs
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/patio/PatioCodeGenIfTests.java | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenIfTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenIfTests.java new file mode 100644 index 00000000..f8fea8da --- /dev/null +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenIfTests.java @@ -0,0 +1,39 @@ +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 java.util.List; + +import static org.shedlang.compiler.patio.PatioTesting.serialize; + +@ExtendWith({SnapshotResolver.class}) +public class PatioCodeGenIfTests { + @Test + public void canGenerateCodeForIf(Snapshotter snapshotter) throws IOException { + var instruction = Instructions.if_( + List.of( + Instructions.pushInt(1), + Instructions.pushInt(2), + Instructions.intAdd() + ), + List.of( + Instructions.pushInt(101), + Instructions.pushInt(102), + Instructions.intAdd() + ) + ); + var context = PatioCodeGenContext.EMPTY + .temporaryPush(new PatioLocalRef("other")) + .temporaryPush(new PatioLocalRef("condition")); + + var result = PatioCodeGen.generateInstruction(instruction, context); + + snapshotter.assertSnapshot(serialize(result)); + } +} |
