From 41fcbdb71e6603919f0b751998452a45b8d9a0a3 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 2 Dec 2023 21:24:23 +0000 Subject: Support effects in effect handler methods --- .../patio/PatioCodeGenDefineFunctionTests.java | 21 +++++++++++++++++++++ .../compiler/patio/PatioCodeGenResumeTests.java | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) (limited to 'src/test/java') diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineFunctionTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineFunctionTests.java index bb8fb3ab..3fd914be 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineFunctionTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenDefineFunctionTests.java @@ -149,4 +149,25 @@ public class PatioCodeGenDefineFunctionTests { snapshotter.assertSnapshot(serialize(result)); } + + @Test + public void effectHandlerMethodSwapsEffectHandlerInBody(Snapshotter snapshotter) throws IOException { + var instruction = new ShidDefineFunction( + "f", + List.of(), + List.of(), + FreeVariables.empty(), + List.of( + Shid.pushUnit(), + Shid.resume() + ), + ShidDefineFunction.Variant.EFFECT_HANDLER_METHOD, + Sources.NULL + ); + var context = PatioCodeGenContext.EMPTY; + + var result = PatioCodeGen.generateInstruction(instruction, context); + + snapshotter.assertSnapshot(serialize(result)); + } } diff --git a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenResumeTests.java b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenResumeTests.java index 57d16015..b0a97f31 100644 --- a/src/test/java/org/shedlang/compiler/patio/PatioCodeGenResumeTests.java +++ b/src/test/java/org/shedlang/compiler/patio/PatioCodeGenResumeTests.java @@ -18,7 +18,8 @@ public class PatioCodeGenResumeTests { var shid = Shid.resume(); var context = PatioCodeGenContext.EMPTY .temporaryPush(new PatioLocalRef("a")) - .temporaryPush(new PatioLocalRef("b")); + .temporaryPush(new PatioLocalRef("b")) + .stashEffectHandler(new PatioLocalRef("effect_handler")); var result = PatioCodeGen.generateInstruction(shid, context); -- cgit v1.2.3