aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-12-26 18:35:46 +0000
committerMichael Williamson <mike@zwobble.org>2023-12-26 18:35:46 +0000
commit538d0c883cb5afaeef7a58a66a876b7c2cc80708 (patch)
tree2072c923999378dd117c12f64ce670ef40cfc0ab /src/test/java
parente0f232e9ad7fbe304e99bb4e880c761f06255791 (diff)
Support constructed type field accesses in Shid code gen
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/backends/llvm/LlvmPatioExampleTests.java2
-rw-r--r--src/test/java/org/shedlang/compiler/backends/wasm/WasmPatioExampleTests.java2
-rw-r--r--src/test/java/org/shedlang/compiler/shid/ShidCodeGenFieldAccessTests.java30
3 files changed, 32 insertions, 2 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 193f7f74..ab8b19be 100644
--- a/src/test/java/org/shedlang/compiler/backends/llvm/LlvmPatioExampleTests.java
+++ b/src/test/java/org/shedlang/compiler/backends/llvm/LlvmPatioExampleTests.java
@@ -23,6 +23,6 @@ public class LlvmPatioExampleTests extends ExampleTests {
@Override
protected boolean isDisabled(String testName) {
- return testName.equals("29-generic-structs");
+ 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 dfecd8bb..95585ee4 100644
--- a/src/test/java/org/shedlang/compiler/backends/wasm/WasmPatioExampleTests.java
+++ b/src/test/java/org/shedlang/compiler/backends/wasm/WasmPatioExampleTests.java
@@ -23,6 +23,6 @@ public class WasmPatioExampleTests extends ExampleTests {
@Override
protected boolean isDisabled(String testName) {
- return testName.equals("29-generic-structs");
+ return false;
}
}
diff --git a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenFieldAccessTests.java b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenFieldAccessTests.java
index 27559724..7dc159bd 100644
--- a/src/test/java/org/shedlang/compiler/shid/ShidCodeGenFieldAccessTests.java
+++ b/src/test/java/org/shedlang/compiler/shid/ShidCodeGenFieldAccessTests.java
@@ -6,8 +6,11 @@ import org.shedlang.compiler.shid.instructions.ShidFieldLoad;
import org.shedlang.compiler.shid.instructions.ShidMatchers;
import org.shedlang.compiler.types.Effects;
import org.shedlang.compiler.types.NamespaceName;
+import org.shedlang.compiler.types.TypeParam;
import org.shedlang.compiler.types.Types;
+import java.util.List;
+
import static org.shedlang.compiler.shid.instructions.ShidMatchers.isShidFieldLoad;
import static org.shedlang.compiler.shid.instructions.ShidMatchers.isShidLocalLoad;
import static org.zwobble.precisely.AssertThat.assertThat;
@@ -56,6 +59,33 @@ public class ShidCodeGenFieldAccessTests {
}
@Test
+ public void constructedTypeFieldAccessIsCompiledToFieldLoad() {
+ var structType = Types.struct(NamespaceName.of("Example", "Project"), "Box");
+ var typeConstructor = Types.typeConstructor(
+ List.of(TypeParam.forStructType(structType, "T")),
+ structType
+ );
+ var constructedType = Types.constructedType(
+ typeConstructor,
+ List.of(Types.STRING)
+ );
+ var node = Typed.fieldAccess(
+ Typed.reference("box", constructedType),
+ "value",
+ Types.STRING
+ );
+ var context = ShidCodeGen.Context.EMPTY
+ .addShedVal("box");
+
+ var result = ShidCodeGen.compileExpression(node, context);
+
+ assertThat(result.instructions(), isSequence(
+ isShidLocalLoad("box__0"),
+ isShidFieldLoad(structType, "value")
+ ));
+ }
+
+ @Test
public void userDefinedEffectFieldAccessIsCompiledToFieldLoad() {
var effect = Effects.userDefined(NamespaceName.of("Example", "Project"), "State");
var node = Typed.fieldAccess(