+
+ /* Append formal to list of values */
+ formal = ao_lisp_cons_poly(ao_lisp_cons_cons(ao_lisp_v, NULL));
+ if (!formal)
+ return 0;
+
+ if (ao_lisp_stack->values_tail)
+ ao_lisp_poly_cons(ao_lisp_stack->values_tail)->cdr = formal;
+ else
+ ao_lisp_stack->values = formal;
+ ao_lisp_stack->values_tail = formal;
+
+ DBGI(".. values "); DBG_POLY(ao_lisp_stack->values); DBG("\n");
+
+ /*
+ * Step to the next argument, if this is last, then
+ * 'sexpr' will end up switching to 'exec'
+ */
+ ao_lisp_v = ao_lisp_poly_cons(ao_lisp_stack->sexprs)->cdr;
+
+ ao_lisp_stack->state = eval_sexpr;
+
+ DBGI(".. "); DBG_POLY(ao_lisp_v); DBG("\n");
+ return 1;
+}
+
+/*
+ * Start executing a function call
+ *
+ * Most builtins are easy, just call the function.
+ * 'cond' is magic; it sticks the list of clauses
+ * in 'sexprs' and switches to 'cond' state. That
+ * bit of magic is done in ao_lisp_set_cond.
+ *
+ * Lambdas build a new frame to hold the locals and
+ * then re-use the current stack context to evaluate
+ * the s-expression from the lambda.
+ */
+
+static int
+ao_lisp_eval_exec(void)
+{
+ ao_poly v;
+ struct ao_lisp_builtin *builtin;
+
+ DBGI("exec: "); DBG_POLY(ao_lisp_v); DBG(" values "); DBG_POLY(ao_lisp_stack->values); DBG ("\n");
+ ao_lisp_stack->sexprs = AO_LISP_NIL;
+ switch (ao_lisp_poly_type(ao_lisp_v)) {
+ case AO_LISP_BUILTIN:
+ ao_lisp_stack->state = eval_val;
+ builtin = ao_lisp_poly_builtin(ao_lisp_v);
+ v = ao_lisp_func(builtin) (
+ ao_lisp_poly_cons(ao_lisp_poly_cons(ao_lisp_stack->values)->cdr));
+ DBG_DO(if (!ao_lisp_exception && ao_lisp_poly_builtin(ao_lisp_v)->func == builtin_set) {
+ struct ao_lisp_cons *cons = ao_lisp_poly_cons(ao_lisp_stack->values);
+ ao_poly atom = ao_lisp_arg(cons, 1);
+ ao_poly val = ao_lisp_arg(cons, 2);
+ DBGI("set "); DBG_POLY(atom); DBG(" = "); DBG_POLY(val); DBG("\n");
+ });
+ builtin = ao_lisp_poly_builtin(ao_lisp_v);
+ if (builtin->args & AO_LISP_FUNC_FREE_ARGS)
+ ao_lisp_cons_free(ao_lisp_poly_cons(ao_lisp_stack->values));
+
+ ao_lisp_v = v;
+ DBGI(".. result "); DBG_POLY(ao_lisp_v); DBG ("\n");
+ DBGI(".. frame "); DBG_POLY(ao_lisp_frame_poly(ao_lisp_frame_current)); DBG("\n");