aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-07-23 21:17:13 +0100
committerMichael Williamson <mike@zwobble.org>2023-07-23 21:17:13 +0100
commitd5707930a4e75c2fa47aa3b75fea13575e269009 (patch)
treea21ca6939784f0d299d71323e3f238e09ab5145e
parent576aa4821a810353e4a8eb3dbc92a4cbe1be723e (diff)
Add Patio code gen for int-eq
-rw-r--r--snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIntEqualsTests]/[method:canGenerateCodeForIntEquals(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected17
-rw-r--r--src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java17
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioCodeGenIntEqualsTests.java28
3 files changed, 58 insertions, 4 deletions
diff --git a/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIntEqualsTests]/[method:canGenerateCodeForIntEquals(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIntEqualsTests]/[method:canGenerateCodeForIntEquals(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
new file mode 100644
index 00000000..cd822316
--- /dev/null
+++ b/snapshots/[engine:junit-jupiter]/[class:org.shedlang.compiler.patio.PatioCodeGenIntEqualsTests]/[method:canGenerateCodeForIntEquals(org.shedlang.compiler.testing.snapshots.Snapshotter)].expected
@@ -0,0 +1,17 @@
+Compilation unit elements:
+
+
+Locals:
+ * ("tmp__0" int)
+
+Args:
+
+Instructions:
+
+(
+ (int-eq (local "tmp__0") (local "b") (local "c"))
+)
+
+Temporary stack:
+ * tmp__0
+ * a
diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java
index f9bfd38b..63d5cd5e 100644
--- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java
+++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGen.java
@@ -2,10 +2,7 @@ package org.shedlang.compiler.patio;
import org.shedlang.compiler.patio.ast.PatioCompilationUnit;
import org.shedlang.compiler.patio.ast.PatioVisibility;
-import org.shedlang.compiler.patio.ast.instructions.PatioDataPtrToInt;
-import org.shedlang.compiler.patio.ast.instructions.PatioIntAdd;
-import org.shedlang.compiler.patio.ast.instructions.PatioLocalStore;
-import org.shedlang.compiler.patio.ast.instructions.PatioReturn;
+import org.shedlang.compiler.patio.ast.instructions.*;
import org.shedlang.compiler.patio.ast.operands.PatioInt;
import org.shedlang.compiler.patio.ast.operands.PatioLocalRef;
import org.shedlang.compiler.patio.ast.types.PatioTypes;
@@ -266,6 +263,18 @@ public class PatioCodeGen {
context
);
+ case IntEqualsInstruction intEquals ->
+ generateBinaryOperation(
+ (target, left, right, operationContext) ->
+ operationContext.addInstruction(new PatioIntEquals(
+ target,
+ left,
+ right,
+ intEquals.source()
+ )),
+ context
+ );
+
case LocalLoadInstruction localLoad -> {
var local = context.stackIrLocalNameToLocal(localLoad.name());
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenIntEqualsTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenIntEqualsTests.java
new file mode 100644
index 00000000..cc1eaf2d
--- /dev/null
+++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenIntEqualsTests.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 PatioCodeGenIntEqualsTests {
+ @Test
+ public void canGenerateCodeForIntEquals(Snapshotter snapshotter) throws IOException {
+ var stackIr = Instructions.intEquals();
+ 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));
+ }
+}