aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-12-13 23:34:49 +0000
committerMichael Williamson <mike@zwobble.org>2023-12-13 23:34:49 +0000
commit7c6fc48c7ab8a23f8568a2f0c57c66e77a5aa69c (patch)
treed202daa047112c06868bf15b7b0d8a511db7b039 /src/test/java
parent86b4a6cdb0e2c311bdcbdcb109e77d04b094a86f (diff)
Use Shid bound variables to generate Patio variables
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/shid/ShidCodeGenNamespaceTests.java8
-rw-r--r--src/test/java/org/shedlang/compiler/shid/ShidCodeGenReferenceTests.java4
-rw-r--r--src/test/java/org/shedlang/compiler/shid/ShidCodeGenValTests.java4
-rw-r--r--src/test/java/org/shedlang/compiler/shid/ShidSerializerTests.java66
-rw-r--r--src/test/java/org/shedlang/compiler/shid/instructions/Shid.java6
-rw-r--r--src/test/java/org/shedlang/compiler/typechecker/TypeCheckerFunctionBodyTests.java8
-rw-r--r--src/test/java/org/shedlang/compiler/typechecker/TypeCheckerIfTests.java4
-rw-r--r--src/test/java/org/shedlang/compiler/typechecker/TypeCheckerNamespaceTests.java4
8 files changed, 75 insertions, 29 deletions
diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenNamespaceTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenNamespaceTests.java
index af0bae77..8caf7ba6 100644
--- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenNamespaceTests.java
+++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenNamespaceTests.java
@@ -27,7 +27,7 @@ public class ShidCodeGenNamespaceTests {
.addStatement(Typed.expressionStatement(Typed.stringLiteral("hello")))
.build()
),
- List.of(BoundVariable.immutable("f")),
+ List.of(BoundVariable.val("f")),
List.of("f")
);
@@ -53,9 +53,9 @@ public class ShidCodeGenNamespaceTests {
public void importsAreLoaded() {
var node = TypedNamespaceNode.builder()
.addImport(Typed.import_(NamespaceName.of("A")))
- .addBoundVariable(BoundVariable.immutable("A"))
+ .addBoundVariable(BoundVariable.val("A"))
.addImport(Typed.import_(NamespaceName.of("B")))
- .addBoundVariable(BoundVariable.immutable("B"))
+ .addBoundVariable(BoundVariable.val("B"))
.build();
var shidNamespace = ShidCodeGen.compileNamespace(node);
@@ -87,7 +87,7 @@ public class ShidCodeGenNamespaceTests {
.withType(structType)
.build()
),
- List.of(BoundVariable.immutable("f"), BoundVariable.immutable("None")),
+ List.of(BoundVariable.val("f"), BoundVariable.val("None")),
List.of("f", "None")
);
diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenReferenceTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenReferenceTests.java
index 2a30266b..c60d54de 100644
--- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenReferenceTests.java
+++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenReferenceTests.java
@@ -13,7 +13,7 @@ public class ShidCodeGenReferenceTests {
public void referenceIsCompiledToLocalLoad() {
var node = Typed.reference("x");
var context = ShidCodeGen.Context.EMPTY
- .addShedVariable(BoundVariable.immutable("x"));
+ .addShedVariable(BoundVariable.val("x"));
var result = ShidCodeGen.compileExpression(node, context);
@@ -26,7 +26,7 @@ public class ShidCodeGenReferenceTests {
public void whenLocalIsVarThenReferenceIsCompiledToVarLoad() {
var node = Typed.reference("x");
var context = ShidCodeGen.Context.EMPTY
- .addShedVariable(BoundVariable.mutable("x"));
+ .addShedVariable(BoundVariable.var("x"));
context = ShidCodeGen.compileFunctionStatement(
Typed.var("x", Typed.intLiteral(0)),
context
diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenValTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenValTests.java
index 45f29904..fdf9300c 100644
--- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenValTests.java
+++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenValTests.java
@@ -54,7 +54,7 @@ public class ShidCodeGenValTests {
Typed.val("x", Typed.intLiteral(11)),
Typed.expressionStatement(Typed.reference("x"))
),
- List.of(BoundVariable.immutable("x"))
+ List.of(BoundVariable.val("x"))
)
)
),
@@ -63,7 +63,7 @@ public class ShidCodeGenValTests {
Typed.val("x", Typed.intLiteral(12)),
Typed.expressionStatement(Typed.reference("x"))
),
- List.of(BoundVariable.immutable("x"))
+ List.of(BoundVariable.val("x"))
),
Types.INT
)),
diff --git a/src/test/java/org/shedlang/compiler/shid/ShidSerializerTests.java b/src/test/java/org/shedlang/compiler/shid/ShidSerializerTests.java
index 0076b982..e97a503a 100644
--- a/src/test/java/org/shedlang/compiler/shid/ShidSerializerTests.java
+++ b/src/test/java/org/shedlang/compiler/shid/ShidSerializerTests.java
@@ -4,6 +4,7 @@ import org.junit.jupiter.api.Test;
import org.shedlang.compiler.shid.instructions.Shid;
import org.shedlang.compiler.shid.instructions.ShidDefineFunction;
import org.shedlang.compiler.shid.instructions.ShidInstruction;
+import org.shedlang.compiler.shid.instructions.ShidVariable;
import org.shedlang.compiler.types.Effects;
import org.shedlang.compiler.types.NamespaceName;
import org.shedlang.compiler.types.Types;
@@ -16,7 +17,10 @@ import static org.zwobble.precisely.Matchers.equalTo;
public class ShidSerializerTests {
@Test
public void canSerializeBlock() {
- var instruction = Shid.block(List.of(Shid.pushInt(1)));
+ var instruction = Shid.block(
+ List.of(new ShidVariable("x", ShidVariable.Variant.VAR)),
+ List.of(Shid.pushInt(1))
+ );
var string = serialize(instruction);
@@ -24,6 +28,9 @@ public class ShidSerializerTests {
(
block
(
+ (var "x")
+ )
+ (
(push-int 1)
)
)"""));
@@ -76,8 +83,13 @@ public class ShidSerializerTests {
named-params=("n1" "n2")
free-variables=("fv1" "fv2")
body=(
- (push-bool true)
- (push-bool false)
+ block
+ (
+ )
+ (
+ (push-bool true)
+ (push-bool false)
+ )
)
)"""));
}
@@ -188,12 +200,22 @@ public class ShidSerializerTests {
if
result-count=1
(
- (push-unit)
+ block
+ (
+ )
+ (
+ (push-unit)
+ )
)
(
- (local-load "x")
- (discard)
- (push-bool true)
+ block
+ (
+ )
+ (
+ (local-load "x")
+ (discard)
+ (push-bool true)
+ )
)
)"""));
}
@@ -276,8 +298,13 @@ public class ShidSerializerTests {
(
loop
(
- (local-load "x")
- (discard)
+ block
+ (
+ )
+ (
+ (local-load "x")
+ (discard)
+ )
)
)"""));
}
@@ -421,13 +448,23 @@ public class ShidSerializerTests {
(
"Example/Project.A"
(
- (return)
+ block
+ (
+ )
+ (
+ (return)
+ )
)
)
(
"Example/Project.B"
(
- (discard)
+ block
+ (
+ )
+ (
+ (discard)
+ )
)
)
)
@@ -456,7 +493,12 @@ public class ShidSerializerTests {
"write"
)
(
- (push-unit)
+ block
+ (
+ )
+ (
+ (push-unit)
+ )
)
)"""));
}
diff --git a/src/test/java/org/shedlang/compiler/shid/instructions/Shid.java b/src/test/java/org/shedlang/compiler/shid/instructions/Shid.java
index 11af1f25..2b9e711d 100644
--- a/src/test/java/org/shedlang/compiler/shid/instructions/Shid.java
+++ b/src/test/java/org/shedlang/compiler/shid/instructions/Shid.java
@@ -12,8 +12,12 @@ public class Shid {
private Shid() {
}
+ public static ShidBlock block(List<ShidVariable> boundVariables, List<ShidInstruction> instructions) {
+ return new ShidBlock(boundVariables, instructions, Sources.NULL);
+ }
+
public static ShidBlock block(List<ShidInstruction> instructions) {
- return new ShidBlock(List.of(), instructions, Sources.NULL);
+ return block(List.of(), instructions);
}
public static ShidInstruction call(int positionalArgCount, List<String> namedArgNames) {
diff --git a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerFunctionBodyTests.java b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerFunctionBodyTests.java
index 04445758..b2dc700e 100644
--- a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerFunctionBodyTests.java
+++ b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerFunctionBodyTests.java
@@ -507,10 +507,10 @@ public class TypeCheckerFunctionBodyTests {
typed.value(),
isTypedFunctionBodyNode()
.withBlock(isTypedBlockNodeWithBoundVariables(containsExactly(
- equalTo(BoundVariable.immutable("argPositional")),
- equalTo(BoundVariable.immutable("argNamed")),
- equalTo(BoundVariable.immutable("local1")),
- equalTo(BoundVariable.mutable("localMutable"))
+ equalTo(BoundVariable.param("argPositional")),
+ equalTo(BoundVariable.param("argNamed")),
+ equalTo(BoundVariable.val("local1")),
+ equalTo(BoundVariable.var("localMutable"))
)))
);
}
diff --git a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerIfTests.java b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerIfTests.java
index 25347042..fac401e2 100644
--- a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerIfTests.java
+++ b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerIfTests.java
@@ -178,12 +178,12 @@ public class TypeCheckerIfTests {
isTypedConditionalBranchNode(
anything(),
isTypedBlockNodeWithBoundVariables(containsExactly(
- equalTo(BoundVariable.immutable("local1"))
+ equalTo(BoundVariable.val("local1"))
))
)
),
isTypedBlockNodeWithBoundVariables(containsExactly(
- equalTo(BoundVariable.immutable("local2"))
+ equalTo(BoundVariable.val("local2"))
))
)
);
diff --git a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerNamespaceTests.java b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerNamespaceTests.java
index 65baadce..16890569 100644
--- a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerNamespaceTests.java
+++ b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerNamespaceTests.java
@@ -55,8 +55,8 @@ public class TypeCheckerNamespaceTests {
isTypedImportNode(NamespaceName.of("B"))
))
.withBoundVariableNames(isSequence(
- equalTo(BoundVariable.immutable("A")),
- equalTo(BoundVariable.immutable("B"))
+ equalTo(BoundVariable.val("A")),
+ equalTo(BoundVariable.val("B"))
))
);
}