From e3ba72306045ab47978950c468022f0098610e46 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 19 Nov 2023 13:04:59 +0000 Subject: Generate Patio code for accessing effect method --- .../compiler/patio/PatioCodeGenFieldLoadTests.java | 28 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenFieldLoadTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenFieldLoadTests.java index ac03f724..1b313b84 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenFieldLoadTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenFieldLoadTests.java @@ -8,10 +8,7 @@ import org.shedlang.compiler.testing.snapshots.SnapshotResolver; import org.shedlang.compiler.testing.snapshots.Snapshotter; import org.shedlang.compiler.typechecker.TypeCheckerContext; import org.shedlang.compiler.typechecker.TypeInfos; -import org.shedlang.compiler.types.NamespaceName; -import org.shedlang.compiler.types.NamespaceTypeInfo; -import org.shedlang.compiler.types.StructTypeInfo; -import org.shedlang.compiler.types.Types; +import org.shedlang.compiler.types.*; import java.io.IOException; import java.util.List; @@ -65,4 +62,27 @@ public class PatioCodeGenFieldLoadTests { snapshotter.assertSnapshot(serialize(result)); } + + @Test + public void canGenerateCodeForUserDefinedEffectFieldLoad(Snapshotter snapshotter) throws IOException { + var namespaceName = NamespaceName.of("Example", "Project"); + var effect = Effects.userDefined(namespaceName, "State"); + var stackIrInstruction = Instructions.fieldLoad(effect, "fence"); + var typeInfos = TypeInfos.EMPTY + .addUserDefinedEffectInfo( + effect, + UserDefinedEffectInfo.builder() + .addMethod("write", FunctionType.builder().build()) + .addMethod("fence", FunctionType.builder().build()) + .addMethod("read", FunctionType.builder().build()) + .build() + ); + var context = PatioCodeGenContext.forTypeInfos(typeInfos) + .temporaryPush(new PatioLocalRef("a")) + .temporaryPush(new PatioLocalRef("b")); + + var result = PatioCodeGen.generateInstruction(stackIrInstruction, context); + + snapshotter.assertSnapshot(serialize(result)); + } } -- cgit v1.2.3