altos/scheme: Add start/end args to vector->list
[fw/altos] / src / scheme / ao_scheme_mem.c
index a336fdfe964fccecf901405c0f0b05152a13538f..c92150722d1e8dbe2439544f1b3e2293248094e6 100644 (file)
@@ -184,43 +184,34 @@ struct ao_scheme_root {
        void                            **addr;
 };
 
-static struct ao_scheme_cons   *save_cons[2];
-static struct ao_scheme_string *save_string[2];
-static struct ao_scheme_frame  *save_frame[1];
-static ao_poly                 save_poly[3];
+#define AO_SCHEME_NUM_STASH    6
+static ao_poly                 stash_poly[AO_SCHEME_NUM_STASH];
+static int                     stash_poly_ptr;
 
 static const struct ao_scheme_root     ao_scheme_root[] = {
        {
-               .type = &ao_scheme_cons_type,
-               .addr = (void **) &save_cons[0],
-       },
-       {
-               .type = &ao_scheme_cons_type,
-               .addr = (void **) &save_cons[1],
-       },
-       {
-               .type = &ao_scheme_string_type,
-               .addr = (void **) &save_string[0],
+               .type = NULL,
+               .addr = (void **) (void *) &stash_poly[0]
        },
        {
-               .type = &ao_scheme_string_type,
-               .addr = (void **) &save_string[1],
+               .type = NULL,
+               .addr = (void **) (void *) &stash_poly[1]
        },
        {
-               .type = &ao_scheme_frame_type,
-               .addr = (void **) &save_frame[0],
+               .type = NULL,
+               .addr = (void **) (void *) &stash_poly[2]
        },
        {
                .type = NULL,
-               .addr = (void **) (void *) &save_poly[0]
+               .addr = (void **) (void *) &stash_poly[3]
        },
        {
                .type = NULL,
-               .addr = (void **) (void *) &save_poly[1]
+               .addr = (void **) (void *) &stash_poly[4]
        },
        {
                .type = NULL,
-               .addr = (void **) (void *) &save_poly[2]
+               .addr = (void **) (void *) &stash_poly[5]
        },
        {
                .type = &ao_scheme_atom_type,
@@ -313,7 +304,7 @@ static struct ao_scheme_chunk ao_scheme_chunk[AO_SCHEME_NCHUNK];
 /* Offset of an address within the pool. */
 static inline uint16_t pool_offset(void *addr) {
 #if DBG_MEM
-       if (!AO_SCHEME_IS_POOL(addr))
+       if (!ao_scheme_is_pool_addr(addr))
                ao_scheme_abort();
 #endif
        return ((uint8_t *) addr) - ao_scheme_pool;
@@ -723,7 +714,7 @@ ao_scheme_cons_check(struct ao_scheme_cons *cons)
        reset_chunks();
        walk(ao_scheme_mark_ref, ao_scheme_poly_mark_ref);
        while (cons) {
-               if (!AO_SCHEME_IS_POOL(cons))
+               if (!ao_scheme_is_pool_addr(cons))
                        break;
                offset = pool_offset(cons);
                if (busy(ao_scheme_busy, offset)) {
@@ -752,7 +743,7 @@ int
 ao_scheme_mark_memory(const struct ao_scheme_type *type, void *addr)
 {
        int offset;
-       if (!AO_SCHEME_IS_POOL(addr))
+       if (!ao_scheme_is_pool_addr(addr))
                return 1;
 
        offset = pool_offset(addr);
@@ -804,7 +795,7 @@ ao_scheme_poly_mark(ao_poly p, uint8_t do_note_cons)
                return 1;
 
        addr = ao_scheme_ref(p);
-       if (!AO_SCHEME_IS_POOL(addr))
+       if (!ao_scheme_is_pool_addr(addr))
                return 1;
 
        if (type == AO_SCHEME_CONS && do_note_cons) {
@@ -864,7 +855,7 @@ ao_scheme_move_memory(const struct ao_scheme_type *type, void **ref)
        void            *addr = *ref;
        uint16_t        offset, orig_offset;
 
-       if (!AO_SCHEME_IS_POOL(addr))
+       if (!ao_scheme_is_pool_addr(addr))
                return 1;
 
        (void) type;
@@ -874,7 +865,7 @@ ao_scheme_move_memory(const struct ao_scheme_type *type, void **ref)
        offset = move_map(orig_offset);
        if (offset != orig_offset) {
                MDBG_MOVE("update ref %d %d -> %d\n",
-                         AO_SCHEME_IS_POOL(ref) ? MDBG_OFFSET(ref) : -1,
+                         ao_scheme_is_pool_addr(ref) ? MDBG_OFFSET(ref) : -1,
                          orig_offset, offset);
                *ref = ao_scheme_pool + offset;
        }
@@ -914,7 +905,7 @@ ao_scheme_poly_move(ao_poly *ref, uint8_t do_note_cons)
                return 1;
 
        addr = ao_scheme_ref(p);
-       if (!AO_SCHEME_IS_POOL(addr))
+       if (!ao_scheme_is_pool_addr(addr))
                return 1;
 
        orig_offset = pool_offset(addr);
@@ -991,63 +982,21 @@ ao_scheme_alloc(int size)
 }
 
 void
-ao_scheme_cons_stash(int id, struct ao_scheme_cons *cons)
-{
-       assert(save_cons[id] == 0);
-       save_cons[id] = cons;
-}
-
-struct ao_scheme_cons *
-ao_scheme_cons_fetch(int id)
-{
-       struct ao_scheme_cons *cons = save_cons[id];
-       save_cons[id] = NULL;
-       return cons;
-}
-
-void
-ao_scheme_poly_stash(int id, ao_poly poly)
+ao_scheme_poly_stash(ao_poly p)
 {
-       assert(save_poly[id] == AO_SCHEME_NIL);
-       save_poly[id] = poly;
+       assert(stash_poly_ptr < AO_SCHEME_NUM_STASH);
+       stash_poly[stash_poly_ptr++] = p;
 }
 
 ao_poly
-ao_scheme_poly_fetch(int id)
-{
-       ao_poly poly = save_poly[id];
-       save_poly[id] = AO_SCHEME_NIL;
-       return poly;
-}
-
-void
-ao_scheme_string_stash(int id, struct ao_scheme_string *string)
+ao_scheme_poly_fetch(void)
 {
-       assert(save_string[id] == NULL);
-       save_string[id] = string;
-}
+       ao_poly p;
 
-struct ao_scheme_string *
-ao_scheme_string_fetch(int id)
-{
-       struct ao_scheme_string *string = save_string[id];
-       save_string[id] = NULL;
-       return string;
-}
-
-void
-ao_scheme_frame_stash(int id, struct ao_scheme_frame *frame)
-{
-       assert(save_frame[id] == NULL);
-       save_frame[id] = frame;
-}
-
-struct ao_scheme_frame *
-ao_scheme_frame_fetch(int id)
-{
-       struct ao_scheme_frame *frame = save_frame[id];
-       save_frame[id] = NULL;
-       return frame;
+       assert (stash_poly_ptr > 0);
+       p = stash_poly[--stash_poly_ptr];
+       stash_poly[stash_poly_ptr] = AO_SCHEME_NIL;
+       return p;
 }
 
 int
@@ -1060,7 +1009,7 @@ ao_scheme_print_mark_addr(void *addr)
                ao_scheme_abort();
 #endif
 
-       if (!AO_SCHEME_IS_POOL(addr))
+       if (!ao_scheme_is_pool_addr(addr))
                return 0;
 
        if (!ao_scheme_print_cleared) {
@@ -1084,7 +1033,7 @@ ao_scheme_print_clear_addr(void *addr)
                ao_scheme_abort();
 #endif
 
-       if (!AO_SCHEME_IS_POOL(addr))
+       if (!ao_scheme_is_pool_addr(addr))
                return;
 
        if (!ao_scheme_print_cleared)