Initial (bad) gc
This commit is contained in:
+21
-4
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user