+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");
+ break;
+ case AO_LISP_LAMBDA:
+ DBGI(".. frame "); DBG_POLY(ao_lisp_frame_poly(ao_lisp_frame_current)); DBG("\n");
+ ao_lisp_stack->state = eval_progn;
+ v = ao_lisp_lambda_eval();
+ ao_lisp_stack->sexprs = v;
+ DBGI(".. sexprs "); DBG_POLY(ao_lisp_stack->sexprs); DBG("\n");
+ DBGI(".. frame "); DBG_POLY(ao_lisp_frame_poly(ao_lisp_frame_current)); DBG("\n");
+ break;
+ }
+ ao_lisp_stack->values = AO_LISP_NIL;
+ ao_lisp_stack->values_tail = AO_LISP_NIL;
+ return 1;
+}
+
+/*
+ * Start evaluating the next cond clause
+ *
+ * If the list of clauses is empty, then
+ * the result of the cond is nil.
+ *
+ * Otherwise, set the current stack state to 'cond_test' and create a
+ * new stack context to evaluate the test s-expression. Once that's
+ * complete, we'll land in 'cond_test' to finish the clause.
+ */
+static int
+ao_lisp_eval_cond(void)
+{
+ DBGI("cond: "); DBG_POLY(ao_lisp_stack->sexprs); DBG("\n");
+ DBGI(".. frame "); DBG_POLY(ao_lisp_frame_poly(ao_lisp_frame_current)); DBG("\n");
+ DBGI(".. saved frame "); DBG_POLY(ao_lisp_stack->frame); DBG("\n");
+ if (!ao_lisp_stack->sexprs) {
+ ao_lisp_v = AO_LISP_NIL;
+ ao_lisp_stack->state = eval_val;
+ } else {
+ ao_lisp_v = ao_lisp_poly_cons(ao_lisp_stack->sexprs)->car;
+ if (!ao_lisp_v || ao_lisp_poly_type(ao_lisp_v) != AO_LISP_CONS) {
+ ao_lisp_error(AO_LISP_INVALID, "invalid cond clause");
+ return 0;
+ }
+ ao_lisp_v = ao_lisp_poly_cons(ao_lisp_v)->car;
+ ao_lisp_stack->state = eval_cond_test;
+ if (!ao_lisp_stack_push())
+ return 0;
+ }
+ return 1;
+}