diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-11-19 12:16:39 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-11-19 12:16:39 +0000 |
| commit | f39ec01be157d0a93202dfbb1638ccf899e2e392 (patch) | |
| tree | 4c3253580aae6d538576d3d0a09caca4d51f1c77 /src/test/java | |
| parent | 090e353e9682024803747174241baf46b566b949 (diff) | |
Generate Patio code for defining an effect
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineEffectTests.java | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineEffectTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineEffectTests.java new file mode 100644 index 00000000..a6135d0a --- /dev/null +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineEffectTests.java @@ -0,0 +1,47 @@ +package org.shedlang.compiler.patio; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.shedlang.compiler.stackir.instructions.Instructions; +import org.shedlang.compiler.testing.snapshots.SnapshotResolver; +import org.shedlang.compiler.testing.snapshots.Snapshotter; +import org.shedlang.compiler.typechecker.TypeInfos; +import org.shedlang.compiler.types.*; + +import java.io.IOException; + +import static org.shedlang.compiler.patio.PatioTesting.serialize; + +@ExtendWith({SnapshotResolver.class}) +public class PatioCodeGenDefineEffectTests { + @Test + public void canGenerateCodeForDefineEffect(Snapshotter snapshotter) throws IOException { + var effect = Effects.userDefined(NamespaceName.of("Example", "Project"), "State"); + var instruction = Instructions.defineEffect(effect); + var typeInfos = TypeInfos.EMPTY + .addUserDefinedEffectInfo( + effect, + UserDefinedEffectInfo.builder() + .addMethod( + "read", + FunctionType.builder() + .addNamedParam("fence", Types.BOOL) + .withReturnType(Types.INT) + .build() + ) + .addMethod( + "write", + FunctionType.builder() + .addPositionalParam(Types.INT) + .withReturnType(Types.UNIT) + .build() + ) + .build() + ); + var context = PatioCodeGenContext.forTypeInfos(typeInfos); + + var result = PatioCodeGen.generateInstruction(instruction, context); + + snapshotter.assertSnapshot(serialize(result)); + } +} |
