altos/lisp: Check only cdr base type when moving cons cells
authorKeith Packard <keithp@keithp.com>
Mon, 4 Dec 2017 03:49:20 +0000 (19:49 -0800)
committerKeith Packard <keithp@keithp.com>
Mon, 4 Dec 2017 03:49:20 +0000 (19:49 -0800)
The cdr may have moved, so we can't look at the target object
type. Fortunately, the base type encoded in the reference itself is
sufficient to check for a non-cons cdr.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/lisp/ao_lisp_cons.c

index 06e9d361e65630bf7b35d66ca2fef0eb4416db4e..d3b97383fe655ad9dd28e8ed198445d84fb8307d 100644 (file)
@@ -58,8 +58,8 @@ static void cons_move(void *addr)
                cdr = cons->cdr;
                if (!cdr)
                        break;
-               if (ao_lisp_poly_type(cdr) != AO_LISP_CONS) {
-                       (void) ao_lisp_poly_move(&cons->cdr, 1);
+               if (ao_lisp_poly_base_type(cdr) != AO_LISP_CONS) {
+                       (void) ao_lisp_poly_move(&cons->cdr, 0);
                        break;
                }
                c = ao_lisp_poly_cons(cdr);
@@ -95,8 +95,8 @@ ao_lisp_cons_cons(ao_poly car, ao_poly cdr)
                ao_lisp_poly_stash(0, car);
                ao_lisp_poly_stash(1, cdr);
                cons = ao_lisp_alloc(sizeof (struct ao_lisp_cons));
-               car = ao_lisp_poly_fetch(0);
                cdr = ao_lisp_poly_fetch(1);
+               car = ao_lisp_poly_fetch(0);
                if (!cons)
                        return NULL;
        }