altos/lisp: Use poly stashes for stacks
authorKeith Packard <keithp@keithp.com>
Sat, 19 Nov 2016 05:14:47 +0000 (21:14 -0800)
committerKeith Packard <keithp@keithp.com>
Mon, 20 Feb 2017 19:16:52 +0000 (11:16 -0800)
Saves some memory.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/lisp/ao_lisp.h
src/lisp/ao_lisp_mem.c
src/lisp/ao_lisp_string.c

index cea834fcd03a161a78c0e0f467741ebaf568717a..e238d4fed8507af928939192f0be1527751ec4d9 100644 (file)
@@ -468,22 +468,26 @@ struct ao_lisp_cons *
 ao_lisp_cons_fetch(int id);
 
 void
-ao_lisp_string_stash(int id, char *string);
+ao_lisp_poly_stash(int id, ao_poly poly);
 
-char *
-ao_lisp_string_fetch(int id);
+ao_poly
+ao_lisp_poly_fetch(int id);
 
 void
-ao_lisp_stack_stash(int id, struct ao_lisp_stack *stack);
+ao_lisp_string_stash(int id, char *string);
 
-struct ao_lisp_stack *
-ao_lisp_stack_fetch(int id);
+char *
+ao_lisp_string_fetch(int id);
 
-void
-ao_lisp_poly_stash(int id, ao_poly poly);
+static inline void
+ao_lisp_stack_stash(int id, struct ao_lisp_stack *stack) {
+       ao_lisp_poly_stash(id, ao_lisp_stack_poly(stack));
+}
 
-ao_poly
-ao_lisp_poly_fetch(int id);
+static inline struct ao_lisp_stack *
+ao_lisp_stack_fetch(int id) {
+       return ao_lisp_poly_stack(ao_lisp_poly_fetch(id));
+}
 
 /* cons */
 extern const struct ao_lisp_type ao_lisp_cons_type;
index 0dfad1d7c87bcc6286b924698730a63a849c3dcb..2599f719f21ad48ab8af6c078c3447261295a49d 100644 (file)
@@ -144,8 +144,7 @@ struct ao_lisp_root {
 
 static struct ao_lisp_cons     *save_cons[2];
 static char                    *save_string[2];
-static struct ao_lisp_stack    *save_stack[3];
-static ao_poly                 save_poly[2];
+static ao_poly                 save_poly[3];
 
 static const struct ao_lisp_root       ao_lisp_root[] = {
        {
@@ -156,25 +155,13 @@ static const struct ao_lisp_root  ao_lisp_root[] = {
                .type = &ao_lisp_cons_type,
                .addr = (void **) &save_cons[1],
        },
-       {
-               .type = &ao_lisp_stack_type,
-               .addr = (void **) &save_stack[0]
-       },
-       {
-               .type = &ao_lisp_stack_type,
-               .addr = (void **) &save_stack[1]
-       },
-       {
-               .type = &ao_lisp_stack_type,
-               .addr = (void **) &save_stack[2]
-       },
        {
                .type = &ao_lisp_string_type,
-               .addr = (void **) &save_string[0]
+               .addr = (void **) &save_string[0],
        },
        {
                .type = &ao_lisp_string_type,
-               .addr = (void **) &save_string[1]
+               .addr = (void **) &save_string[1],
        },
        {
                .type = NULL,
@@ -184,6 +171,10 @@ static const struct ao_lisp_root   ao_lisp_root[] = {
                .type = NULL,
                .addr = (void **) &save_poly[1]
        },
+       {
+               .type = NULL,
+               .addr = (void **) &save_poly[2]
+       },
        {
                .type = &ao_lisp_atom_type,
                .addr = (void **) &ao_lisp_atoms
@@ -833,17 +824,17 @@ ao_lisp_cons_fetch(int id)
 }
 
 void
-ao_lisp_stack_stash(int id, struct ao_lisp_stack *stack)
+ao_lisp_poly_stash(int id, ao_poly poly)
 {
-       save_stack[id] = stack;
+       save_poly[id] = poly;
 }
 
-struct ao_lisp_stack *
-ao_lisp_stack_fetch(int id)
+ao_poly
+ao_lisp_poly_fetch(int id)
 {
-       struct ao_lisp_stack *stack = save_stack[id];
-       save_stack[id] = NULL;
-       return stack;
+       ao_poly poly = save_poly[id];
+       save_poly[id] = AO_LISP_NIL;
+       return poly;
 }
 
 void
@@ -859,16 +850,4 @@ ao_lisp_string_fetch(int id)
        save_string[id] = NULL;
        return string;
 }
-void
-ao_lisp_poly_stash(int id, ao_poly poly)
-{
-       save_poly[id] = poly;
-}
 
-ao_poly
-ao_lisp_poly_fetch(int id)
-{
-       ao_poly poly = save_poly[id];
-       save_poly[id] = AO_LISP_NIL;
-       return poly;
-}
index 207d4f3be8eae13c90e6e4869a8327ba64f0793c..cd7b27a97f1f67f7136f03f650cbf2aacaba0511 100644 (file)
@@ -104,9 +104,9 @@ ao_lisp_string_unpack(char *a)
                ao_lisp_cons_stash(1, tail);
                ao_lisp_string_stash(0, a);
                struct ao_lisp_cons     *n = ao_lisp_cons_cons(ao_lisp_int_poly(c), NULL);
+               a = ao_lisp_string_fetch(0);
                cons = ao_lisp_cons_fetch(0);
                tail = ao_lisp_cons_fetch(1);
-               a = ao_lisp_string_fetch(0);
 
                if (!n) {
                        cons = NULL;