Update function call stuff

This commit is contained in:
2026-07-19 00:14:16 -07:00
parent bd7ca2fa25
commit 67b68f8c61
10 changed files with 177 additions and 115 deletions
+40 -3
View File
@@ -75,14 +75,14 @@ static inline LispVal *lookup_variable(LispSymbol *name, LispVal *lexenv) {
if (lexval != Qunbound) {
return lexval;
}
if (name->value == Qunbound) {
if (SYMBOL_VALUE(name) == Qunbound) {
// TODO better error
printf("Unbound symbol: ");
debug_print(stdout, name);
fputc('\n', stdout);
abort();
}
return name->value;
return SYMBOL_VALUE(name);
}
DEFUN(eval, "eval", (LispVal * form, LispVal *lexenv),
@@ -131,6 +131,7 @@ DEFSPECIAL(progn, "progn", (LispVal * forms), "(&rest forms)", "") {
DEFSPECIAL(let, "let", (LispVal * bindings, LispVal *body),
"(bindings &rest body)", "") {
CHECK_LISTP(bindings);
StackFrame *stack_ref = LISP_STACK_REF();
LispVal *lexenv = Vlexical_environment;
DOLIST(binding, bindings) {
if (SYMBOLP(binding)) {
@@ -145,7 +146,43 @@ DEFSPECIAL(let, "let", (LispVal * bindings, LispVal *body),
}
}
push_dynamic_binding(Qlexical_environment, lexenv);
return Fprogn(body);
return UNWIND_AND_RETURN(stack_ref, Fprogn(body));
}
DEFSPECIAL(if, "if", (LispVal * cond, LispVal *then, LispVal *otherwise),
"(cond then &rest else)", "") {
StackFrame *stack_ref = LISP_STACK_REF();
LispVal *res = Feval(cond, Vlexical_environment);
if (!NILP(res)) {
return UNWIND_AND_RETURN(stack_ref, Feval(then, Vlexical_environment));
} else {
return UNWIND_AND_RETURN(stack_ref, Fprogn(otherwise));
}
}
DEFSPECIAL(and, "and", (LispVal * forms), "(&rest forms)", "") {
LispVal *res = Qt;
DOLIST(form, forms) {
res = Feval(form, Vlexical_environment);
if (NILP(res)) {
return Qnil;
}
}
return res;
}
DEFSPECIAL(or, "or", (LispVal * forms), "(&rest forms)", "") {
DOLIST(form, forms) {
LispVal *res = Feval(form, Vlexical_environment);
if (!NILP(res)) {
return res;
}
}
return Qnil;
}
DEFUN(null, "null", (LispVal * datum), "(datum)", "") {
return NILP(datum) ? Qt : Qnil;
}
void debug_print(FILE *file, LispVal *obj) {