From 61bc4e6359cfa5b911cb29864576511aabe4b04b Mon Sep 17 00:00:00 2001 From: Ludovic 'Archivist' Lagouardette Date: Thu, 7 Nov 2024 10:10:44 +0100 Subject: [PATCH] added a function to collects expended routines --- include/ink.h | 6 ++++++ lib.c | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/ink.h b/include/ink.h index 665a28a..ede8912 100644 --- a/include/ink.h +++ b/include/ink.h @@ -338,6 +338,12 @@ struct elem ink_make_transparent(struct context* ctx, int type_id, void* ptr); */ void ink_gc(struct context* ctx); +/** + * Cleans up coroutine stacks before reuse + * @param ctx + */ +void ink_clean_routines(struct context* ctx); + /** * Obtains the type id from the declared name of the type * @param ctx The context where we want to detect the type diff --git a/lib.c b/lib.c index e433c2b..7008b69 100644 --- a/lib.c +++ b/lib.c @@ -1153,6 +1153,22 @@ struct elem ink_make_native(struct context* ctx, int type, void* ptr) { return ink_make_native_unsafe(ctx, type, ptr, 0); } +void ink_clean_routines(struct context* ctx) { + int i, j; + struct elem null; + + null.value = 0; + null.type = INK_INTEGER; + for(i = 0; i < ctx->routines_top; ++i) { + if(ctx->routines[i].panic == INK_ROUTINE_CAN_REUSE) { + for (j = 0; j < ctx->routines[i].top; ++j) { + ctx->routines[i].stack[j] = null; + } + ctx->routines[i].top = 0; + } + } +} + void ink_gc(struct context* ctx) { int i, j, k; int marked;