From 538d0c883cb5afaeef7a58a66a876b7c2cc80708 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 26 Dec 2023 18:35:46 +0000 Subject: Support constructed type field accesses in Shid code gen --- .../backends/llvm/LlvmPatioExampleTests.java | 2 +- .../backends/wasm/WasmPatioExampleTests.java | 2 +- .../compiler/shid/ShidCodeGenFieldAccessTests.java | 30 ++++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) (limited to 'src/test/java') 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; @@ -55,6 +58,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"); -- cgit v1.2.3