From 0a9f5702be163ede1a56f68fa304f5f1b2fd14a8 Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Tue, 2 May 2023 11:10:19 -0400 Subject: [PATCH] step: some more scaffolding for funcs. --- src/mumble.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/mumble.c b/src/mumble.c index 6aa73e5..686e886 100644 --- a/src/mumble.c +++ b/src/mumble.c @@ -646,16 +646,18 @@ lispval* builtin_functions(char* func, lispval* v, lispenv* env) // Evaluate the lispval lispval* evaluate_lispval(lispval* l, lispenv* env) { + // Check if this is neither an s-expression nor a symbol; otherwise return as is. + if (l->type != LISPVAL_SEXPR && l->type != LISPVAL_SYM) + return l; + // Check if this is a symbol if(l->type == LISPVAL_SYM){ get_from_lispenv(l->sym, env); } - // Check if this is an s-expression - if (l->type != LISPVAL_SEXPR) - return l; - // Evaluate the children if needed + + // Evaluate the children if needed for (int i = 0; i < l->count; i++) { - if (l->cell[i]->type == LISPVAL_SEXPR) { + if (l->cell[i]->type == LISPVAL_SEXPR || l->cell[i]->type == LISPVAL_SYM) { l->cell[i] = evaluate_lispval(l->cell[i], env); } } @@ -667,17 +669,18 @@ lispval* evaluate_lispval(lispval* l, lispenv* env) } // Check if the first element is an operation. - if (l->count >= 2 && ((l->cell[0])->type == LISPVAL_SYM)) { + if (l->count >= 2 && ((l->cell[0])->type == LISPVAL_FUNC)) { lispval* temp = clone_lispval(l->cell[0]); - lispval* operation = pop_lispval(l, 0); + lispval* f = pop_lispval(l, 0); lispval* operands = temp; // lispval* operation = clone_lispval(l->cell[0]); // lispval* operands = lispval_sexpr(); // for (int i = 1; i < l->count; i++) { // lispval_append_child(operands, l->cell[i]); // } - lispval* answer = builtin_functions(operation->sym, l, env); - delete_lispval(operation); + lispval* answer = f->func(env, operands); + // builtin_functions(operation->sym, l, env); + delete_lispval(f); delete_lispval(operands); return answer; }