diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-11-19 15:11:27 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-11-19 15:11:27 +0000 |
| commit | af335486c659fb6f5d065eb61014074045e4e81d (patch) | |
| tree | 47f34b5fd17739e4a74e004de4a47d8b6b61bdcb /src/test/java | |
| parent | 84f3a53ac9a784d13aa74f88993847beadd5904f (diff) | |
Generate Patio code for try statements
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/patio/PatioCodeGenTryTests.java | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenTryTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenTryTests.java new file mode 100644 index 00000000..1a9535d1 --- /dev/null +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenTryTests.java @@ -0,0 +1,50 @@ +package org.shedlang.compiler.patio; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.shedlang.compiler.patio.ast.operands.PatioLocalRef; +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.TypeCheckerContext; +import org.shedlang.compiler.types.*; + +import java.io.IOException; +import java.util.List; + +import static org.shedlang.compiler.patio.PatioTesting.serialize; + +@ExtendWith({SnapshotResolver.class}) +public class PatioCodeGenTryTests { + @Test + public void canGenerateCodeForTry(Snapshotter snapshotter) throws IOException { + var namespaceName = new NamespaceName(List.of("Example", "Project")); + var effect = Effects.userDefined(namespaceName, "State"); + var stackIrInstruction = Instructions.try_( + effect, + List.of("a", "c", "b"), + List.of( + Instructions.pushInt(42) + ) + ); + var typeInfos = TypeCheckerContext.EMPTY + .addUserDefinedEffectInfo( + effect, + UserDefinedEffectInfo.builder() + .addMethod("c", FunctionType.builder().build()) + .addMethod("a", FunctionType.builder().build()) + .addMethod("b", FunctionType.builder().build()) + .build() + ) + .toTypeInfos(); + var context = PatioCodeGenContext.forTypeInfos(typeInfos) + .temporaryPush(new PatioLocalRef("other")) + .temporaryPush(new PatioLocalRef("handlerA")) + .temporaryPush(new PatioLocalRef("handlerC")) + .temporaryPush(new PatioLocalRef("handlerB")); + + var result = PatioCodeGen.generateInstruction(stackIrInstruction, context); + + snapshotter.assertSnapshot(serialize(result)); + } +} |
