From b99b938b2f33e4d12d63629f3d80e987c31d1892 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 19 Nov 2023 15:47:38 +0000 Subject: Implement basic effect handling in the runtime --- .../java/org/shedlang/compiler/patio/PatioCodeGenEffects.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenEffects.java b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenEffects.java index ad5d64de..dc97456e 100644 --- a/src/main/java/org/shedlang/compiler/patio/PatioCodeGenEffects.java +++ b/src/main/java/org/shedlang/compiler/patio/PatioCodeGenEffects.java @@ -42,7 +42,8 @@ public class PatioCodeGenEffects { private static final PatioFunctionDeclaration PUSH_HANDLER_DECLARATION = new PatioFunctionDeclaration( "shed__runtime__effects_push_handler", List.of( - new PatioLocal.Param("effectTag", EFFECT_TAG_TYPE) + new PatioLocal.Param("effectTag", EFFECT_TAG_TYPE), + new PatioLocal.Param("methodCount", PatioTypes.INT) ), EFFECT_HANDLER_TYPE, Sources.RUNTIME @@ -229,6 +230,8 @@ public class PatioCodeGenEffects { Source source, PatioCodeGenContext context ) { + var effectInfo = context.userDefinedEffectInfo(effect); + context = context .ensureCompilationUnitElement(PUSH_HANDLER_DECLARATION) .ensureCompilationUnitElement(SET_HANDLER_METHOD_DECLARATION) @@ -245,12 +248,12 @@ public class PatioCodeGenEffects { Optional.of(effectHandler), PUSH_HANDLER_DECLARATION.name(), List.of( - new PatioInt(context.effectTag(effect)) + new PatioInt(context.effectTag(effect)), + new PatioInt(effectInfo.methodCount()) ), source )); - var effectInfo = context.userDefinedEffectInfo(effect); for (var handlerMethodInfo : effectInfo.methods()) { context = context.addInstruction(new PatioCall( Optional.empty(), -- cgit v1.2.3