diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-11-19 13:04:59 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-11-19 13:04:59 +0000 |
| commit | e3ba72306045ab47978950c468022f0098610e46 (patch) | |
| tree | bed2d373824ad573bcc560a3bb611e22430660a2 /src/test/java | |
| parent | 6d71b87e4be3de27432e9efa4d601a0351d68cc4 (diff) | |
Generate Patio code for accessing effect method
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/patio/PatioCodeGenFieldLoadTests.java | 28 |
1 files changed, 24 insertions, 4 deletions
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)); + } } |
