From 23a4308c22a0b8bff2400909449e3e34acc78cff Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 23 Jul 2023 21:22:04 +0100 Subject: Support Patio code gen for ifs --- .../compiler/patio/PatioCodeGenIfTests.java | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/test/java/org/shedlang/compiler/patio/PatioCodeGenIfTests.java (limited to 'src/test/java') 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)); + } +} -- cgit v1.2.3