Global generation
This commit is contained in:
+27
-19
@@ -1,5 +1,8 @@
|
||||
#include "base.h"
|
||||
|
||||
#include "hashtable.h"
|
||||
#include "lisp.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
const char *LISP_TYPE_NAMES[N_LISP_TYPES] = {
|
||||
@@ -16,11 +19,11 @@ const char *LISP_TYPE_NAMES[N_LISP_TYPES] = {
|
||||
void *lisp_alloc_object(size_t size, LispValType type) {
|
||||
assert(size >= sizeof(LispObject));
|
||||
LispObject *obj = lisp_aligned_alloc(LISP_OBJECT_ALIGNMENT, size);
|
||||
obj->type = type;
|
||||
obj->gc.immortal = false;
|
||||
obj->gc.mark = false;
|
||||
// TODO set the below
|
||||
obj->gc.entry = NULL;
|
||||
obj->type = type;
|
||||
return obj;
|
||||
}
|
||||
|
||||
@@ -28,24 +31,23 @@ DEFINE_SYMBOL(nil, "nil");
|
||||
DEFINE_SYMBOL(t, "t");
|
||||
DEFINE_SYMBOL(unbound, "unbound");
|
||||
|
||||
DEFINE_SYMBOL(quote, "quote");
|
||||
DEFINE_SYMBOL(backquote, "`");
|
||||
DEFINE_SYMBOL(comma, ",");
|
||||
DEFINE_SYMBOL(comma_at, ",@");
|
||||
|
||||
DEFUN(id, "id", (LispVal * obj), "(id)", "") {
|
||||
// TODO not all values are handled here
|
||||
return MAKE_FIXNUM((uintptr_t) obj);
|
||||
}
|
||||
|
||||
DEFUN(eq, "eq", (LispVal * obj1, LispVal *obj2), "(obj1 obj2)", "") {
|
||||
return obj1 == obj2 ? Qt : Qnil;
|
||||
}
|
||||
|
||||
// ################
|
||||
// # Constructors #
|
||||
// ################
|
||||
LispVal *make_lisp_string(const char *data, size_t length, bool take,
|
||||
bool copy) {
|
||||
LispString *obj = lisp_alloc_object(sizeof(LispString), TYPE_STRING);
|
||||
obj->owned = take;
|
||||
obj->length = length;
|
||||
if (copy) {
|
||||
obj->data = lisp_malloc(length + 1);
|
||||
memcpy(obj->data, data, length);
|
||||
obj->data[length] = '\0';
|
||||
} else {
|
||||
obj->data = (char *) data;
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
LispVal *make_vector(LispVal **data, size_t length, bool take) {
|
||||
LispVector *obj = lisp_alloc_object(sizeof(LispVector), TYPE_VECTOR);
|
||||
obj->length = length;
|
||||
@@ -63,12 +65,18 @@ DEFUN(make_symbol, "make-symbol", (LispVal * name), "(name)",
|
||||
LispSymbol *obj = lisp_alloc_object(sizeof(LispSymbol), TYPE_SYMBOL);
|
||||
obj->name = name;
|
||||
obj->function = Qnil;
|
||||
obj->value = Qnil;
|
||||
obj->value = Qunbound;
|
||||
obj->plist = Qnil;
|
||||
return obj;
|
||||
}
|
||||
|
||||
DEFUN(intern, "intern", (LispVal * name), "(name)", "") {
|
||||
// TODO implement
|
||||
return Fmake_symbol(name);
|
||||
// TODO type checking
|
||||
LispVal *res = Fgethash(obarray, name, Qunbound);
|
||||
if (res != Qunbound) {
|
||||
return res;
|
||||
}
|
||||
LispVal *newsym = Fmake_symbol(name);
|
||||
Fputhash(obarray, name, newsym);
|
||||
return newsym;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user