This commit is contained in:
2026-01-20 01:23:52 -08:00
parent 243a012d3e
commit 4c04e71078
11 changed files with 145 additions and 33 deletions

View File

@ -49,6 +49,49 @@ void lisp_init() {
void lisp_shutdown() {}
DEFUN(eval, "eval", (LispVal * form), "(form)", "") {
if (!OBJECTP(form)) {
// fixnum or float
return form;
}
switch (((LispObject *) form)->type) {
case TYPE_HASH_TABLE:
case TYPE_FUNCTION:
case TYPE_STRING:
return form;
case TYPE_VECTOR: {
LispVector *vec = form;
LispVal **out_data = lisp_malloc(sizeof(LispVal *) * vec->length);
LispVector *newvec = make_vector(out_data, vec->length, true);
for (size_t i = 0; i < vec->length; ++i) {
out_data[i] = Qnil;
}
for (size_t i = 0; i < vec->length; ++i) {
out_data[i] = Feval(vec->data[i]);
}
return newvec;
}
case TYPE_SYMBOL: {
// TODO local bindings
LispSymbol *sym = form;
if (sym->value == Qunbound) {
printf("Unbound symbol: ");
debug_print(stdout, form);
fputc('\n', stdout);
abort();
}
return sym->value;
}
case TYPE_CONS: {
return Ffuncall(XCAR(form), XCDR(form));
}
case TYPE_FIXNUM:
case TYPE_FLOAT:
default:
abort();
}
}
void debug_print(FILE *file, LispVal *obj) {
switch (TYPE_OF(obj)) {
case TYPE_FIXNUM: