aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-07-19 21:24:53 +0100
committerMichael Williamson <mike@zwobble.org>2023-07-19 21:25:06 +0100
commit7e1063d13f4d810ec8520367e7a5a1e9438d05aa (patch)
tree5755da462f498882160b2b4c05a4ff46afbc5177 /src
parentf5b3c08b6c0253ab1a0e4fd608c9e096cbbcbb04 (diff)
Add Patio code gen for push-int
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java3
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushIntTests.java23
2 files changed, 26 insertions, 0 deletions
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java
index 9e0b652a..c0d52b54 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java
@@ -22,6 +22,9 @@ public class PatioCodeGen {
case PushBoolInstruction pushBool ->
P.vector(new PatioPushInt(pushBool.value() ? 1 : 0, pushBool.source()));
+ case PushIntInstruction pushInt ->
+ P.vector(new PatioPushInt(pushInt.value().intValueExact(), pushInt.source()));
+
case PushUnitInstruction pushUnit ->
P.vector(new PatioPushInt(0, pushUnit.source()));
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushIntTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushIntTests.java
new file mode 100644
index 00000000..5b1d7064
--- /dev/null
+++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushIntTests.java
@@ -0,0 +1,23 @@
+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 PatioCodeGenPushIntTests {
+ @Test
+ public void pushIntInstructionGeneratesPushIntInstruction(Snapshotter snapshotter) throws IOException {
+ var stackIr = Instructions.pushInt(42);
+
+ var result = PatioCodeGen.generateInstruction(stackIr);
+
+ snapshotter.assertSnapshot(serialize(result));
+ }
+}