Initial (bad) gc

This commit is contained in:
2026-01-21 20:52:18 -08:00
parent 4c04e71078
commit 656846ddc0
16 changed files with 650 additions and 79 deletions
+21 -4
View File
@@ -1,7 +1,9 @@
#include "base.h"
#include "gc.h"
#include "hashtable.h"
#include "lisp.h"
#include "stack.h"
#include <stdio.h>
#include <string.h>
@@ -17,17 +19,32 @@ const char *LISP_TYPE_NAMES[N_LISP_TYPES] = {
[TYPE_FUNCTION] = "function",
};
void *lisp_alloc_object(size_t size, LispValType type) {
void *lisp_alloc_object_no_gc(size_t size, LispValType type) {
assert(size >= sizeof(LispObject));
LispObject *obj = lisp_aligned_alloc(LISP_OBJECT_ALIGNMENT, size);
memset(obj, 0, size);
obj->type = type;
obj->gc.mark = false;
obj->gc.has_local_ref = false;
// TODO set the below
obj->gc.entry = NULL;
tss_create(&obj->gc.has_local_ref, NULL);
return obj;
}
void *lisp_alloc_object(size_t size, LispValType type) {
LispObject *obj = lisp_alloc_object_no_gc(size, type);
if (the_stack.depth > 0) {
add_local_reference_no_recurse(obj);
}
lisp_gc_register_object(obj);
return obj;
}
void lisp_release_object(LispVal *val) {
assert(OBJECTP(val));
LispObject *obj = val;
tss_delete(obj->gc.has_local_ref);
lisp_free(val);
}
void internal_CHECK_TYPE_signal_type_error(LispVal *obj, size_t count,
const LispValType types[count]) {
// TODO actually throw an error