aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-07-23 22:28:11 +0100
committerMichael Williamson <mike@zwobble.org>2023-07-23 22:28:11 +0100
commit3412aaafe67670b51a25b78bb4805c350820c5a5 (patch)
treead9b6572a8bdf90ad25f5644cb24dec52ec33d03 /src/test/java
parent4faec7c2c180569a06a5023fc1bcb77812705672 (diff)
Support mutual-recursion example in Patio
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/backends/llvm/LlvmPatioExampleTests.java3
-rw-r--r--src/test/java/org/shedlang/compiler/backends/wasm/WasmPatioExampleTests.java3
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineFunctionTests.java30
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioCodeGenLocalLoadTests.java2
4 files changed, 29 insertions, 9 deletions
diff --git a/src/test/java/org/shedlang/compiler/backends/llvm/LlvmPatioExampleTests.java b/src/test/java/org/shedlang/compiler/backends/llvm/LlvmPatioExampleTests.java
index 94ca5779..b43a7846 100644
--- a/src/test/java/org/shedlang/compiler/backends/llvm/LlvmPatioExampleTests.java
+++ b/src/test/java/org/shedlang/compiler/backends/llvm/LlvmPatioExampleTests.java
@@ -3,7 +3,6 @@ package org.shedlang.compiler.backends.llvm;
import org.shedlang.compiler.backends.Backend;
import org.shedlang.compiler.backends.ExampleTests;
-import java.util.List;
import java.util.Optional;
public class LlvmPatioExampleTests extends ExampleTests {
@@ -24,6 +23,6 @@ public class LlvmPatioExampleTests extends ExampleTests {
@Override
protected boolean isDisabled(String testName) {
- return !List.of("hello-world", "if", "string-add", "true", "val", "val-as-namespace-statement").contains(testName);
+ return false;
}
}
diff --git a/src/test/java/org/shedlang/compiler/backends/wasm/WasmPatioExampleTests.java b/src/test/java/org/shedlang/compiler/backends/wasm/WasmPatioExampleTests.java
index 74361506..611546e0 100644
--- a/src/test/java/org/shedlang/compiler/backends/wasm/WasmPatioExampleTests.java
+++ b/src/test/java/org/shedlang/compiler/backends/wasm/WasmPatioExampleTests.java
@@ -3,7 +3,6 @@ package org.shedlang.compiler.backends.wasm;
import org.shedlang.compiler.backends.Backend;
import org.shedlang.compiler.backends.ExampleTests;
-import java.util.List;
import java.util.Optional;
public class WasmPatioExampleTests extends ExampleTests {
@@ -24,6 +23,6 @@ public class WasmPatioExampleTests extends ExampleTests {
@Override
protected boolean isDisabled(String testName) {
- return !List.of("hello-world", "if", "string-add", "true", "val", "val-as-namespace-statement").contains(testName);
+ return false;
}
}
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineFunctionTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineFunctionTests.java
index 4f09ff3b..97a78a1f 100644
--- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineFunctionTests.java
+++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineFunctionTests.java
@@ -50,8 +50,8 @@ public class PatioCodeGenDefineFunctionTests {
Sources.NULL
);
var context = PatioCodeGenContext.EMPTY
- .addStackIrLocal("a").context()
- .addStackIrLocal("b").context();
+ .addStackIrArg("a")
+ .addStackIrArg("b");
var result = PatioCodeGen.generateInstruction(instruction, context);
@@ -59,6 +59,28 @@ public class PatioCodeGenDefineFunctionTests {
}
@Test
+ public void canCaptureFreeVariablesThatAreSetAfterDefinition(Snapshotter snapshotter) throws IOException {
+ var instruction = new DefineFunctionInstruction(
+ "f",
+ List.of(),
+ List.of(),
+ FreeVariables.builder().plus("a", Sources.NULL).plus("b", Sources.NULL).build(),
+ List.of(
+ Instructions.localLoad("a"),
+ Instructions.return_()
+ ),
+ Sources.NULL
+ );
+ var context = PatioCodeGenContext.EMPTY;
+
+ context = PatioCodeGen.generateInstruction(instruction, context);
+ context = context.addStackIrArg("a");
+ context = context.addStackIrArg("b");
+
+ snapshotter.assertSnapshot(serialize(context));
+ }
+
+ @Test
public void positionalAndNamedParamsAreDefined(Snapshotter snapshotter) throws IOException {
var instruction = new DefineFunctionInstruction(
"f",
@@ -76,8 +98,8 @@ public class PatioCodeGenDefineFunctionTests {
Sources.NULL
);
var context = PatioCodeGenContext.EMPTY
- .addStackIrLocal("a").context()
- .addStackIrLocal("b").context();
+ .addStackIrArg("a")
+ .addStackIrArg("b");
var result = PatioCodeGen.generateInstruction(instruction, context);
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLocalLoadTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLocalLoadTests.java
index 643c6d72..67412723 100644
--- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLocalLoadTests.java
+++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLocalLoadTests.java
@@ -16,7 +16,7 @@ public class PatioCodeGenLocalLoadTests {
public void localLoadPushesLocalOntoStack(Snapshotter snapshotter) throws IOException {
var stackIr = Instructions.localLoad("x");
var context = PatioCodeGenContext.EMPTY
- .addStackIrLocal("x").context();
+ .addStackIrArg("x");
var result = PatioCodeGen.generateInstruction(stackIr, context);