From 96b78561204020df21703a5fe8922bf49dc6e1f4 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 2 Feb 2024 23:01:09 +0000 Subject: Store effect handler methods directly --- .../compiler/shidtopatio/ShidToPatioEffects.java | 31 +++++++--------------- 1 file changed, 10 insertions(+), 21 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioEffects.java b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioEffects.java index 8cf27d7d..648e62f1 100644 --- a/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioEffects.java +++ b/src/main/java/org/shedlang/compiler/shidtopatio/ShidToPatioEffects.java @@ -100,7 +100,7 @@ public class ShidToPatioEffects { return ShidToPatioGc.gcObjectDataLayout(PatioDataLayouts.struct(List.of( PatioDataLayouts.fromType(EFFECT_HANDLER_TYPE), PatioDataLayouts.struct(Lists.repeat( - PatioDataLayouts.fromType(EFFECT_HANDLER_METHOD_POINTER_TYPE), + PatioDataLayouts.fromType(EFFECT_HANDLER_METHOD_TYPE), methodCount )) ))); @@ -118,6 +118,10 @@ public class ShidToPatioEffects { public int gcChildrenCount() { return methodCount; } + + public List handlerMethodOffset(int handlerMethodIndex) { + return ShidToPatioGc.gcObjectOffset(List.of(1, handlerMethodIndex)); + } } private static final PatioFunctionDeclaration FIND_HANDLER_METHOD_DECLARATION = new PatioFunctionDeclaration( @@ -153,17 +157,6 @@ public class ShidToPatioEffects { Sources.RUNTIME ); - private static final PatioFunctionDeclaration SET_HANDLER_METHOD_DECLARATION = new PatioFunctionDeclaration( - "shed__runtime__effects_set_handler_method", - List.of( - PatioLocal.param("handler", EFFECT_HANDLER_TYPE), - PatioLocal.param("methodIndex", EFFECT_METHOD_INDEX_TYPE), - PatioLocal.param("handlerMethod", EFFECT_HANDLER_METHOD_TYPE) - ), - PatioTypes.VOID, - Sources.RUNTIME - ); - private static final PatioFunctionDeclaration POP_HANDLER_DECLARATION = new PatioFunctionDeclaration( "shed__runtime__effects_pop_handler", List.of(), @@ -347,7 +340,6 @@ public class ShidToPatioEffects { context = context .ensureCompilationUnitElement(PUSH_HANDLER_DECLARATION) - .ensureCompilationUnitElement(SET_HANDLER_METHOD_DECLARATION) .ensureCompilationUnitElement(POP_HANDLER_DECLARATION); var effectHandlerResult = context.allocateVal( @@ -376,14 +368,11 @@ public class ShidToPatioEffects { )); for (var handlerMethodInfo : effectInfo.methods()) { - context = context.addInstruction(new PatioCall( - Optional.empty(), - SET_HANDLER_METHOD_DECLARATION.name(), - List.of( - effectHandler, - PatioIntConst.of(handlerMethodInfo.fieldIndex()), - handlerMethodsByName.get(handlerMethodInfo.name()) - ), + context = context.addInstruction(new PatioMemoryStore( + effectHandler, + effectHandlerRuntimeType.layout(), + effectHandlerRuntimeType.handlerMethodOffset(handlerMethodInfo.fieldIndex()), + handlerMethodsByName.get(handlerMethodInfo.name()), source )); } -- cgit v1.2.3