From 4fb0e6305743e265fec1b199210e77150b0216e1 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 2 Feb 2024 22:54:42 +0000 Subject: Use runtime type tags as effect tags in effect handler --- runtime/src/effects.c | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) (limited to 'runtime/src/effects.c') diff --git a/runtime/src/effects.c b/runtime/src/effects.c index 17996768..ffc78030 100644 --- a/runtime/src/effects.c +++ b/runtime/src/effects.c @@ -6,7 +6,6 @@ struct ShedEffectHandler { struct ShedGcObjectHeader gc_object_header; - ShedEffectTag effect_tag; struct ShedEffectHandler* parent; ShedClosurePointer methods[]; }; @@ -23,26 +22,12 @@ void shed__runtime__effects_set_handler(ShedEffectHandler* effect_handler) { shed__runtime__current_effect_handler = effect_handler; } -ShedEffectHandler* shed__runtime__effects_push_handler( - ShedEffectTag effect_tag, - ShedEffectMethodIndex method_count +void shed__runtime__effects_push_handler( + ShedEffectHandler* effect_handler ) { - ShedEffectHandler* handler = shed__runtime__gc_alloc( - sizeof(ShedEffectHandler) + sizeof(ShedClosurePointer) * method_count, - // TODO: in principle, treating this as a scalar is a bug. However, in - // practice, any methods will also be GC roots (since we only pop GC - // roots at the end of blocks, and effect handlers are not first-class - // values and therefore cannot live longer than the block they're - // defined in). We should definitely fix this though, probably by - // generating the code to alloc the handler. - 0 - ); - handler->effect_tag = effect_tag; - handler->parent = shed__runtime__current_effect_handler; - - shed__runtime__current_effect_handler = handler; + effect_handler->parent = shed__runtime__current_effect_handler; - return handler; + shed__runtime__current_effect_handler = effect_handler; } void shed__runtime__effects_set_handler_method( @@ -63,7 +48,7 @@ ShedClosurePointer shed__runtime__effects_find_handler_method( ) { ShedEffectHandler* handler = shed__runtime__current_effect_handler; while (handler != NULL) { - if (handler->effect_tag == effect_tag) { + if (handler->gc_object_header.runtime_type_tag == effect_tag) { return handler->methods[method_index]; } handler = handler->parent; -- cgit v1.2.3