altos/telegps-v2.0: git ignore make results
[fw/altos] / src / lisp / ao_lisp_lambda.c
index 186236f6eb7e8f3e5373050dbac8a76b48684b61..526863c508e1187c24a3be251ecb5fcfba294998 100644 (file)
@@ -15,7 +15,6 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-#define DBG_EVAL 0
 #include "ao_lisp.h"
 
 int
@@ -78,8 +77,6 @@ ao_lisp_lambda_alloc(struct ao_lisp_cons *code, int args)
        if (!lambda)
                return AO_LISP_NIL;
 
-       if (!ao_lisp_check_argc(_ao_lisp_atom_lambda, code, 2, 2))
-               return AO_LISP_NIL;
        if (!ao_lisp_check_argt(_ao_lisp_atom_lambda, code, 0, AO_LISP_CONS, 1))
                return AO_LISP_NIL;
        f = 0;
@@ -135,7 +132,7 @@ ao_lisp_lambda_eval(void)
        int                     args_wanted;
        int                     args_provided;
        int                     f;
-       struct ao_lisp_cons     *vals
+       struct ao_lisp_cons     *vals;
 
        DBGI("lambda "); DBG_POLY(ao_lisp_lambda_poly(lambda)); DBG("\n");
 
@@ -161,36 +158,39 @@ ao_lisp_lambda_eval(void)
        args = ao_lisp_poly_cons(ao_lisp_arg(code, 0));
        vals = ao_lisp_poly_cons(cons->cdr);
 
+       next_frame->prev = lambda->frame;
+       ao_lisp_frame_current = next_frame;
+       ao_lisp_stack->frame = ao_lisp_frame_poly(ao_lisp_frame_current);
+
        switch (lambda->args) {
        case AO_LISP_FUNC_LAMBDA:
                for (f = 0; f < args_wanted; f++) {
                        DBGI("bind "); DBG_POLY(args->car); DBG(" = "); DBG_POLY(vals->car); DBG("\n");
-                       next_frame->vals[f].atom = args->car;
-                       next_frame->vals[f].val = vals->car;
+                       ao_lisp_frame_bind(next_frame, f, args->car, vals->car);
                        args = ao_lisp_poly_cons(args->cdr);
                        vals = ao_lisp_poly_cons(vals->cdr);
                }
-               ao_lisp_cons_free(cons);
+               if (!ao_lisp_stack_marked(ao_lisp_stack))
+                       ao_lisp_cons_free(cons);
+               cons = NULL;
                break;
        case AO_LISP_FUNC_LEXPR:
        case AO_LISP_FUNC_NLAMBDA:
        case AO_LISP_FUNC_MACRO:
                for (f = 0; f < args_wanted - 1; f++) {
                        DBGI("bind "); DBG_POLY(args->car); DBG(" = "); DBG_POLY(vals->car); DBG("\n");
-                       next_frame->vals[f].atom = args->car;
-                       next_frame->vals[f].val = vals->car;
+                       ao_lisp_frame_bind(next_frame, f, args->car, vals->car);
                        args = ao_lisp_poly_cons(args->cdr);
                        vals = ao_lisp_poly_cons(vals->cdr);
                }
-               DBGI("bind "); DBG_POLY(args->car); DBG(" = "); DBG_POLY(); DBG("\n");
-               next_frame->vals[f].atom = args->car;
-               next_frame->vals[f].val = ao_lisp_cons_poly(vals);
+               DBGI("bind "); DBG_POLY(args->car); DBG(" = "); DBG_POLY(ao_lisp_cons_poly(vals)); DBG("\n");
+               ao_lisp_frame_bind(next_frame, f, args->car, ao_lisp_cons_poly(vals));
+               break;
+       default:
                break;
        }
-       next_frame->prev = lambda->frame;
        DBGI("eval frame: "); DBG_POLY(ao_lisp_frame_poly(next_frame)); DBG("\n");
-       ao_lisp_frame_current = next_frame;
-       ao_lisp_stack->frame = ao_lisp_frame_poly(ao_lisp_frame_current);
        DBG_STACK();
-       return ao_lisp_arg(code, 1);
+       DBGI("eval code: "); DBG_POLY(code->cdr); DBG("\n");
+       return code->cdr;
 }