aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-07-23 21:54:45 +0100
committerMichael Williamson <mike@zwobble.org>2023-07-23 21:54:45 +0100
commit2fe51eb35031a9dd0c0b740fd893b9704614464e (patch)
tree3938c0bad6b30851ba086525f17f37e58ce5cc26 /src
parenta55cc3b70005e66b1435907d81f2d0b762e8fbb0 (diff)
Support int-sub in Patio code gen
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java12
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioCodeGenIntSubTests.java28
2 files changed, 40 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 1b4aa18c..505d351d 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java
@@ -344,6 +344,18 @@ public class PatioCodeGen {
context
);
+ case IntSubInstruction intSub ->
+ generateBinaryOperation(
+ (target, left, right, operationContext) ->
+ operationContext.addInstruction(new PatioIntSub(
+ target,
+ left,
+ right,
+ intSub.source()
+ )),
+ context
+ );
+
case LocalLoadInstruction localLoad -> {
var local = context.stackIrLocalNameToLocal(localLoad.name());
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenIntSubTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenIntSubTests.java
new file mode 100644
index 00000000..9c0ccae9
--- /dev/null
+++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenIntSubTests.java
@@ -0,0 +1,28 @@
+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 PatioCodeGenIntSubTests {
+ @Test
+ public void canGenerateCodeForIntSub(Snapshotter snapshotter) throws IOException {
+ var stackIr = Instructions.intSub();
+ var context = PatioCodeGenContext.EMPTY
+ .temporaryPush(new PatioLocalRef("a"))
+ .temporaryPush(new PatioLocalRef("b"))
+ .temporaryPush(new PatioLocalRef("c"));
+
+ var result = PatioCodeGen.generateInstruction(stackIr, context);
+
+ snapshotter.assertSnapshot(serialize(result));
+ }
+}