aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-07-19 22:10:39 +0100
committerMichael Williamson <mike@zwobble.org>2023-07-19 22:10:39 +0100
commit51c202c469f884d1c67987282ed952cc303f43d7 (patch)
tree448b564d29bfd779fec61393c404ac67cc972ad8 /src/test/java
parent7e1063d13f4d810ec8520367e7a5a1e9438d05aa (diff)
Add Patio code gen for call
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioCodeGenCallTests.java35
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioCodeGenDiscardTests.java3
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioCodeGenLocalLoadTests.java3
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioCodeGenLocalStoreTests.java3
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushBoolTests.java6
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushIntTests.java3
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushUnitTests.java3
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioCodeGenReturnTests.java3
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioTesting.java9
9 files changed, 56 insertions, 12 deletions
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenCallTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenCallTests.java
new file mode 100644
index 00000000..3c39eb11
--- /dev/null
+++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenCallTests.java
@@ -0,0 +1,35 @@
+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 PatioCodeGenCallTests {
+ @Test
+ public void canCallFunctionWithNoArgs(Snapshotter snapshotter) throws IOException {
+ var instruction = Instructions.call(0, List.of());
+ var context = PatioCodeGenContext.EMPTY;
+
+ var result = PatioCodeGen.generateInstruction(instruction, context);
+
+ snapshotter.assertSnapshot(serialize(result));
+ }
+
+ @Test
+ public void canCallFunctionWithArgs(Snapshotter snapshotter) throws IOException {
+ var instruction = Instructions.call(2, List.of("b", "a"));
+ var context = PatioCodeGenContext.EMPTY;
+
+ var result = PatioCodeGen.generateInstruction(instruction, context);
+
+ snapshotter.assertSnapshot(serialize(result));
+ }
+}
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDiscardTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDiscardTests.java
index 7edc2556..edee4d8d 100644
--- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDiscardTests.java
+++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDiscardTests.java
@@ -15,8 +15,9 @@ public class PatioCodeGenDiscardTests {
@Test
public void discardInstructionGeneratesDiscardInstruction(Snapshotter snapshotter) throws IOException {
var stackIr = Instructions.discard();
+ var context = PatioCodeGenContext.EMPTY;
- var result = PatioCodeGen.generateInstruction(stackIr);
+ var result = PatioCodeGen.generateInstruction(stackIr, context);
snapshotter.assertSnapshot(serialize(result));
}
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLocalLoadTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLocalLoadTests.java
index e379722f..eaf69d61 100644
--- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLocalLoadTests.java
+++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLocalLoadTests.java
@@ -15,8 +15,9 @@ public class PatioCodeGenLocalLoadTests {
@Test
public void localLoadGeneratesLocalLoad(Snapshotter snapshotter) throws IOException {
var stackIr = Instructions.localLoad("x");
+ var context = PatioCodeGenContext.EMPTY;
- var result = PatioCodeGen.generateInstruction(stackIr);
+ var result = PatioCodeGen.generateInstruction(stackIr, context);
snapshotter.assertSnapshot(serialize(result));
}
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLocalStoreTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLocalStoreTests.java
index 9f9461c5..94ed40bc 100644
--- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLocalStoreTests.java
+++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLocalStoreTests.java
@@ -15,8 +15,9 @@ public class PatioCodeGenLocalStoreTests {
@Test
public void localStoreGeneratesLocalStore(Snapshotter snapshotter) throws IOException {
var stackIr = Instructions.localStore("x");
+ var context = PatioCodeGenContext.EMPTY;
- var result = PatioCodeGen.generateInstruction(stackIr);
+ var result = PatioCodeGen.generateInstruction(stackIr, context);
snapshotter.assertSnapshot(serialize(result));
}
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushBoolTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushBoolTests.java
index 75c471f3..3b304c4d 100644
--- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushBoolTests.java
+++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushBoolTests.java
@@ -15,8 +15,9 @@ public class PatioCodeGenPushBoolTests {
@Test
public void pushBoolFalseInstructionGeneratesPushIntZeroInstruction(Snapshotter snapshotter) throws IOException {
var stackIr = Instructions.pushBool(false);
+ var context = PatioCodeGenContext.EMPTY;
- var result = PatioCodeGen.generateInstruction(stackIr);
+ var result = PatioCodeGen.generateInstruction(stackIr, context);
snapshotter.assertSnapshot(serialize(result));
}
@@ -24,8 +25,9 @@ public class PatioCodeGenPushBoolTests {
@Test
public void pushBoolTrueInstructionGeneratesPushIntOneInstruction(Snapshotter snapshotter) throws IOException {
var stackIr = Instructions.pushBool(true);
+ var context = PatioCodeGenContext.EMPTY;
- var result = PatioCodeGen.generateInstruction(stackIr);
+ var result = PatioCodeGen.generateInstruction(stackIr, context);
snapshotter.assertSnapshot(serialize(result));
}
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushIntTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushIntTests.java
index 5b1d7064..03a18aaa 100644
--- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushIntTests.java
+++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushIntTests.java
@@ -15,8 +15,9 @@ public class PatioCodeGenPushIntTests {
@Test
public void pushIntInstructionGeneratesPushIntInstruction(Snapshotter snapshotter) throws IOException {
var stackIr = Instructions.pushInt(42);
+ var context = PatioCodeGenContext.EMPTY;
- var result = PatioCodeGen.generateInstruction(stackIr);
+ var result = PatioCodeGen.generateInstruction(stackIr, context);
snapshotter.assertSnapshot(serialize(result));
}
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushUnitTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushUnitTests.java
index 333bbee1..11629e37 100644
--- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushUnitTests.java
+++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenPushUnitTests.java
@@ -15,8 +15,9 @@ public class PatioCodeGenPushUnitTests {
@Test
public void pushUnitInstructionGeneratesPushIntInstruction(Snapshotter snapshotter) throws IOException {
var stackIr = Instructions.pushUnit();
+ var context = PatioCodeGenContext.EMPTY;
- var result = PatioCodeGen.generateInstruction(stackIr);
+ var result = PatioCodeGen.generateInstruction(stackIr, context);
snapshotter.assertSnapshot(serialize(result));
}
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenReturnTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenReturnTests.java
index 59c5f436..0723459f 100644
--- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenReturnTests.java
+++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenReturnTests.java
@@ -15,8 +15,9 @@ public class PatioCodeGenReturnTests {
@Test
public void returnInstructionGeneratesReturnInstruction(Snapshotter snapshotter) throws IOException {
var stackIr = Instructions.return_();
+ var context = PatioCodeGenContext.EMPTY;
- var result = PatioCodeGen.generateInstruction(stackIr);
+ var result = PatioCodeGen.generateInstruction(stackIr, context);
snapshotter.assertSnapshot(serialize(result));
}
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioTesting.java b/src/test/java/org/shedlang/compiler/patio/PatioTesting.java
index 562b32f9..0a4387c4 100644
--- a/src/test/java/org/shedlang/compiler/patio/PatioTesting.java
+++ b/src/test/java/org/shedlang/compiler/patio/PatioTesting.java
@@ -2,14 +2,15 @@ package org.shedlang.compiler.patio;
import org.shedlang.compiler.patio.instructions.PatioInstruction;
-import java.util.List;
-
class PatioTesting {
private PatioTesting() {}
- static String serialize(List<PatioInstruction> instructions) {
+ static String serialize(PatioCodeGenContext context) {
var builder = new StringBuilder();
- PatioInstructionSerializer.serializeInstructions(instructions, builder);
+ PatioInstructionSerializer.serializeInstructions(
+ context.functionContext().instructions(),
+ builder
+ );
return builder.toString();
}