From d408f4f80670ed7f73d09f8ccfefdcb8a7835406 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 27 Aug 2023 21:56:25 +0100 Subject: Add Patio code gen for loop instructions --- .../compiler/patio/PatioCodeGenLoopBreakTests.java | 24 +++++++++++++++++ .../patio/PatioCodeGenLoopContinueTests.java | 24 +++++++++++++++++ .../compiler/patio/PatioCodeGenLoopTests.java | 30 ++++++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 src/test/java/org/shedlang/compiler/patio/PatioCodeGenLoopBreakTests.java create mode 100644 src/test/java/org/shedlang/compiler/patio/PatioCodeGenLoopContinueTests.java create mode 100644 src/test/java/org/shedlang/compiler/patio/PatioCodeGenLoopTests.java (limited to 'src/test/java/org') diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLoopBreakTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLoopBreakTests.java new file mode 100644 index 00000000..76a3799c --- /dev/null +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLoopBreakTests.java @@ -0,0 +1,24 @@ +package org.shedlang.compiler.patio; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +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 PatioCodeGenLoopBreakTests { + @Test + public void canGenerateCodeForLoopBreak(Snapshotter snapshotter) throws IOException { + var instruction = Instructions.loopBreak(); + var context = PatioCodeGenContext.EMPTY; + + var result = PatioCodeGen.generateInstruction(instruction, context); + + snapshotter.assertSnapshot(serialize(result)); + } +} diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLoopContinueTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLoopContinueTests.java new file mode 100644 index 00000000..281f6dcd --- /dev/null +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLoopContinueTests.java @@ -0,0 +1,24 @@ +package org.shedlang.compiler.patio; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +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 PatioCodeGenLoopContinueTests { + @Test + public void canGenerateCodeForLoopContinue(Snapshotter snapshotter) throws IOException { + var instruction = Instructions.loopContinue(); + var context = PatioCodeGenContext.EMPTY; + + var result = PatioCodeGen.generateInstruction(instruction, context); + + snapshotter.assertSnapshot(serialize(result)); + } +} diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLoopTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLoopTests.java new file mode 100644 index 00000000..ff74a17b --- /dev/null +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLoopTests.java @@ -0,0 +1,30 @@ +package org.shedlang.compiler.patio; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +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 PatioCodeGenLoopTests { + @Test + public void canGenerateCodeForLoop(Snapshotter snapshotter) throws IOException { + var instruction = Instructions.loop( + List.of( + Instructions.pushInt(1), + Instructions.discard() + ) + ); + var context = PatioCodeGenContext.EMPTY; + + var result = PatioCodeGen.generateInstruction(instruction, context); + + snapshotter.assertSnapshot(serialize(result)); + } +} -- cgit v1.2.3