Browse Source

actually run the GC

master
Martin Dørum 3 years ago
parent
commit
08cd621d90
2 changed files with 20 additions and 8 deletions
  1. 1
    0
      include/lang2/vm/vm.h
  2. 19
    8
      lib/vm/vm.c

+ 1
- 0
include/lang2/vm/vm.h View File



struct l2_vm { struct l2_vm {
int halted; int halted;
int gc_scheduled;
l2_word *ops; l2_word *ops;
size_t opcount; size_t opcount;
l2_word iptr; l2_word iptr;

+ 19
- 8
lib/vm/vm.c View File



static l2_word alloc_val(struct l2_vm *vm) { static l2_word alloc_val(struct l2_vm *vm) {
size_t id = l2_bitset_set_next(&vm->valueset); size_t id = l2_bitset_set_next(&vm->valueset);
if (id >= vm->valuessize) {
if (vm->valuessize == 0) {
vm->valuessize = 16;
}
if (id + 16 >= vm->valuessize) {
if (id >= vm->valuessize) {
if (vm->valuessize == 0) {
vm->valuessize = 64;
}


while (id >= vm->valuessize) {
vm->valuessize *= 2;
}
while (id >= vm->valuessize) {
vm->valuessize *= 2;
}


vm->values = realloc(vm->values, sizeof(*vm->values) * vm->valuessize);
vm->values = realloc(vm->values, sizeof(*vm->values) * vm->valuessize);
} else {
vm->gc_scheduled = 1;
}
} }


return (l2_word)id; return (l2_word)id;


struct l2_vm_value *val = &vm->values[i]; struct l2_vm_value *val = &vm->values[i];
if (!(val->flags & L2_VAL_MARKED)) { if (!(val->flags & L2_VAL_MARKED)) {
l2_bitset_unset(&vm->valueset, i);
gc_free(vm, i); gc_free(vm, i);
freed += 1; freed += 1;
} else { } else {
vm->std_error = &std_error.w; vm->std_error = &std_error.w;


vm->halted = 0; vm->halted = 0;
vm->gc_scheduled = 0;
vm->ops = ops; vm->ops = ops;
vm->opcount = opcount; vm->opcount = opcount;
vm->iptr = 0; vm->iptr = 0;
vm->halted = 1; vm->halted = 1;
break; break;
} }

if (vm->gc_scheduled) {
l2_vm_gc(vm);
vm->gc_scheduled = 0;
}
} }

Loading…
Cancel
Save