From 1c89809ea205455ec78ad89152b37bd15893e7c9 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 19 Dec 2023 13:39:01 +0000 Subject: Handle returns from try bodies --- .../compiler/patio/PatioCodeGenTryTests.java | 30 ++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/test/java') diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenTryTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenTryTests.java index a0f71ed4..c64ed1d8 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenTryTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenTryTests.java @@ -47,4 +47,34 @@ public class PatioCodeGenTryTests { snapshotter.assertSnapshot(serialize(result)); } + + @Test + public void effectHandlerIsPoppedBeforeReturn(Snapshotter snapshotter) throws IOException { + var namespaceName = new NamespaceName(List.of("Example", "Project")); + var effect = Effects.userDefined(namespaceName, "State"); + var shidInstruction = Shid.try_( + effect, + List.of("a"), + Shid.block(List.of( + Shid.pushInt(42), + Shid.return_() + )) + ); + var typeInfos = TypeCheckerContext.EMPTY + .addUserDefinedEffectInfo( + effect, + UserDefinedEffectInfo.builder() + .addMethod("a", FunctionType.builder().build()) + .build() + ) + .toTypeInfos(); + var context = PatioCodeGenContext.forTypeInfos(typeInfos) + .stashGcRootStackIndex(new PatioLocalRef("gcRootStackIndex")) + .temporaryPush(new PatioLocalRef("other")) + .temporaryPush(new PatioLocalRef("handlerA")); + + var result = PatioCodeGen.generateInstruction(shidInstruction, context); + + snapshotter.assertSnapshot(serialize(result)); + } } -- cgit v1.2.3