Browse Source

added a function to collects expended routines

main
Ludovic 'Archivist' Lagouardette 5 days ago
parent
commit
61bc4e6359
2 changed files with 22 additions and 0 deletions
  1. +6
    -0
      include/ink.h
  2. +16
    -0
      lib.c

+ 6
- 0
include/ink.h View File

@ -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

+ 16
- 0
lib.c View File

@ -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;

Loading…
Cancel
Save