aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-11-20 21:47:24 +0000
committerMichael Williamson <mike@zwobble.org>2023-11-20 21:47:24 +0000
commit9b528a87f563b439235bb926d6213d5b2d957991 (patch)
treeec3d48311504b0a914e9989232f0de17c0ce3c84 /src/test/java
parent33408bfd92902d88193ccadedc60c9203932bd83 (diff)
Declare variables up-front
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineFunctionTests.java16
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioCodeGenLocalLoadTests.java2
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioCodeGenLocalStoreTests.java1
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioCodeGenVarLoadTests.java2
-rw-r--r--src/test/java/org/shedlang/compiler/patio/PatioCodeGenVarStoreTests.java2
5 files changed, 14 insertions, 9 deletions
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineFunctionTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineFunctionTests.java
index 8868cd89..7fca6f96 100644
--- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineFunctionTests.java
+++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineFunctionTests.java
@@ -51,8 +51,8 @@ public class PatioCodeGenDefineFunctionTests {
Sources.NULL
);
var context = PatioCodeGenContext.EMPTY
- .addStackIrParam("a")
- .addStackIrParam("b");
+ .defineStackIrParam("a")
+ .defineStackIrParam("b");
var result = PatioCodeGen.generateInstruction(instruction, context);
@@ -72,7 +72,9 @@ public class PatioCodeGenDefineFunctionTests {
),
Sources.NULL
);
- var context = PatioCodeGenContext.EMPTY;
+ var context = PatioCodeGenContext.EMPTY
+ .declareStackIrVal("a").context()
+ .declareStackIrVal("b").context();
context = PatioCodeGen.generateInstruction(instruction, context);
@@ -81,9 +83,9 @@ public class PatioCodeGenDefineFunctionTests {
// into the closure upon closure creation (i.e. too soon) versus after
// the free variable is set.
context = context.addInstruction(Patio.localStore(Patio.localRef("a"), Patio.int_(42)));
- context = context.addStackIrParam("a");
+ context = context.initStackIrLocal("a");
context = context.addInstruction(Patio.localStore(Patio.localRef("b"), Patio.int_(47)));
- context = context.addStackIrParam("b");
+ context = context.initStackIrLocal("b");
snapshotter.assertSnapshot(serialize(context));
}
@@ -107,8 +109,8 @@ public class PatioCodeGenDefineFunctionTests {
Sources.NULL
);
var context = PatioCodeGenContext.EMPTY
- .addStackIrParam("a")
- .addStackIrParam("b");
+ .defineStackIrParam("a")
+ .defineStackIrParam("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 1a6302a2..7e6b5705 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
- .addStackIrParam("x");
+ .defineStackIrParam("x");
var result = PatioCodeGen.generateInstruction(stackIr, context);
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLocalStoreTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLocalStoreTests.java
index 1fc4f386..2cdec3e1 100644
--- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLocalStoreTests.java
+++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenLocalStoreTests.java
@@ -17,6 +17,7 @@ public class PatioCodeGenLocalStoreTests {
public void localStorePopsTemporaryIntoLocal(Snapshotter snapshotter) throws IOException {
var stackIr = Instructions.localStore("x");
var context = PatioCodeGenContext.EMPTY
+ .declareStackIrVal("x").context()
.temporaryPush(new PatioLocalRef("a"))
.temporaryPush(new PatioLocalRef("b"));
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenVarLoadTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenVarLoadTests.java
index ac51b8f1..0fe5582b 100644
--- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenVarLoadTests.java
+++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenVarLoadTests.java
@@ -16,7 +16,7 @@ public class PatioCodeGenVarLoadTests {
public void canGenerateCodeForVarLoad(Snapshotter snapshotter) throws IOException {
var stackIr = Instructions.varLoad("x");
var context = PatioCodeGenContext.EMPTY
- .addStackIrVarIfMissing("x");
+ .defineStackIrVar("x");
var result = PatioCodeGen.generateInstruction(stackIr, context);
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenVarStoreTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenVarStoreTests.java
index 837be982..5e7884ee 100644
--- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenVarStoreTests.java
+++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenVarStoreTests.java
@@ -17,6 +17,7 @@ public class PatioCodeGenVarStoreTests {
public void canGenerateCodeForVarStore(Snapshotter snapshotter) throws IOException {
var stackIr = Instructions.varStore("x");
var context = PatioCodeGenContext.EMPTY
+ .defineStackIrVar("x")
.temporaryPush(new PatioLocalRef("a"))
.temporaryPush(new PatioLocalRef("b"));
@@ -29,6 +30,7 @@ public class PatioCodeGenVarStoreTests {
public void canStoreIntoVarMultipleTimes(Snapshotter snapshotter) throws IOException {
var stackIr = Instructions.varStore("x");
var context = PatioCodeGenContext.EMPTY
+ .defineStackIrVar("x")
.temporaryPush(new PatioLocalRef("a"))
.temporaryPush(new PatioLocalRef("b"));