move non essential opcodes to primitives and add userdata

This commit is contained in:
Lobo 2026-01-23 11:00:28 -03:00
parent e654143a90
commit 45e2c0d406
17 changed files with 234 additions and 37 deletions

View file

@ -6,6 +6,7 @@
#include "chunk.h"
#include "gc.h"
#include "object.h"
#include "userdata.h"
#include "vendor/yar.h"
#include "vm.h"
@ -110,6 +111,8 @@ V gc_collect(Vm *vm) {
chunk->constants.items[i] = forward(gc, chunk->constants.items[i]);
break;
}
case OBJ_USERDATA:
break;
case OBJ_FWD:
fprintf(stderr, "fatal GC error: forwarding pointer in to-space\n");
abort();
@ -129,6 +132,12 @@ V gc_collect(Vm *vm) {
chunk_release(*chunk_ptr);
break;
}
case OBJ_USERDATA: {
Ud *ud = (Ud *)(hdr + 1);
if (ud->kind->finalizer != NULL)
ud->kind->finalizer(ud->data);
break;
}
default:
break;
}