Browse Source

Made the garbage collector preserve object whose only reference are statically defined in function code #2

main
Ludovic 'Archivist' Lagouardette 1 week ago
parent
commit
acc5e366ad
1 changed files with 12 additions and 2 deletions
  1. +12
    -2
      lib.c

+ 12
- 2
lib.c View File

@ -1300,6 +1300,7 @@ void ink_gc(struct context* ctx) {
int i, j, k; int i, j, k;
int marked; int marked;
struct element_slab* v; struct element_slab* v;
struct elem* thing;
for(i = 0; i < ctx->types_top; ++i) { for(i = 0; i < ctx->types_top; ++i) {
for(j = 0; j < ctx->types[i].elements_top; ++j) { for(j = 0; j < ctx->types[i].elements_top; ++j) {
@ -1329,11 +1330,20 @@ void ink_gc(struct context* ctx) {
continue; continue;
} else for(j = 0; j < ctx->routines[i].top; ++j) { } else for(j = 0; j < ctx->routines[i].top; ++j) {
v = ink_get_value_link(ctx, ctx->routines[i].stack[j]); v = ink_get_value_link(ctx, ctx->routines[i].stack[j]);
if(v != NULL) ++v->uses;
if(v != NULL && !v->uses) ++v->uses;
} }
} }
/* TODO: Mark objects contained within function code */
for(i = 0; i < ctx->native_words_top; ++i) {
struct fn* function = ctx->words + i;
for(j = 0; j < function->size; ++j) {
thing = function->things + j;
v = ink_get_value_link(ctx, *thing);
if (v != NULL && !v->uses) {
++v->uses;
}
}
}
/* Mark the rest of the data */ /* Mark the rest of the data */
do { do {

Loading…
Cancel
Save