altos/lisp: Deal with memory compation in the middle of operations
authorKeith Packard <keithp@keithp.com>
Fri, 11 Nov 2016 07:29:21 +0000 (23:29 -0800)
committerKeith Packard <keithp@keithp.com>
Fri, 18 Nov 2016 06:18:39 +0000 (22:18 -0800)
Handle memory compaction in places where we've got pointers into the
heap across an allocation operation. Either re-compute the values from
managed global references or add new roots across the allocation.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/lisp/ao_lisp.h
src/lisp/ao_lisp_atom.c
src/lisp/ao_lisp_cons.c
src/lisp/ao_lisp_eval.c
src/lisp/ao_lisp_frame.c
src/lisp/ao_lisp_lambda.c
src/lisp/ao_lisp_mem.c

index 6122a2edf5f6406ad991afe10a29bc459ecad3f2..60a97f2c9d98ca96a83fd3b62e7dc7cc16fa237c 100644 (file)
@@ -510,8 +510,8 @@ ao_lisp_frame_ref(struct ao_lisp_frame *frame, ao_poly atom);
 struct ao_lisp_frame *
 ao_lisp_frame_new(int num);
 
-struct ao_lisp_frame *
-ao_lisp_frame_add(struct ao_lisp_frame *frame, ao_poly atom, ao_poly val);
+int
+ao_lisp_frame_add(struct ao_lisp_frame **frame, ao_poly atom, ao_poly val);
 
 void
 ao_lisp_frame_print(ao_poly p);
@@ -538,8 +538,7 @@ ao_poly
 ao_lisp_macro(struct ao_lisp_cons *cons);
 
 ao_poly
-ao_lisp_lambda_eval(struct ao_lisp_lambda *lambda,
-                   struct ao_lisp_cons *cons);
+ao_lisp_lambda_eval(void);
 
 /* error */
 
index 5c6d5a67dc72bac26d4abb1afd14a955e7165136..efa4f6214705d78623e27ad01ba686c9bf1f0e9f 100644 (file)
@@ -147,7 +147,7 @@ ao_lisp_atom_set(ao_poly atom, ao_poly val)
        if (ref)
                *ref = val;
        else
-               ao_lisp_frame_global = ao_lisp_frame_add(ao_lisp_frame_global, atom, val);
+               ao_lisp_frame_add(&ao_lisp_frame_global, atom, val);
        return val;
 }
 
index 855079b8b483022040a5124bef3b4ea0c77cf09e..cd8a8d1d03b9920716fece9c834e101f3d70b55f 100644 (file)
@@ -67,7 +67,13 @@ const struct ao_lisp_type ao_lisp_cons_type = {
 struct ao_lisp_cons *
 ao_lisp_cons_cons(ao_poly car, struct ao_lisp_cons *cdr)
 {
-       struct ao_lisp_cons     *cons = ao_lisp_alloc(sizeof (struct ao_lisp_cons));
+       struct ao_lisp_cons     *cons;
+
+       ao_lisp_root_add(&ao_lisp_cons_type, &cdr);
+       ao_lisp_root_poly_add(&car);
+       cons = ao_lisp_alloc(sizeof (struct ao_lisp_cons));
+       ao_lisp_root_clear(&car);
+       ao_lisp_root_clear(&cdr);
        if (!cons)
                return NULL;
        cons->car = car;
index c5addcb0abd1baae60afe6ea76a51dd9e8da6420..ae2436b8cd86d7026bde5b1bc7347abaced9ba00 100644 (file)
@@ -12,7 +12,7 @@
  * General Public License for more details.
  */
 
-#define DBG_EVAL 1
+#define DBG_EVAL 0
 #include "ao_lisp.h"
 #include <assert.h>
 
@@ -46,19 +46,20 @@ stack_move(void *addr)
        struct ao_lisp_stack    *stack = addr;
 
        while (stack) {
-               void    *prev;
+               struct ao_lisp_stack    *prev;
                int     ret;
                (void) ao_lisp_poly_move(&stack->sexprs, 0);
                (void) ao_lisp_poly_move(&stack->values, 0);
                (void) ao_lisp_poly_move(&stack->values_tail, 0);
                (void) ao_lisp_poly_move(&stack->frame, 0);
                prev = ao_lisp_poly_stack(stack->prev);
-               ret = ao_lisp_move(&ao_lisp_stack_type, &prev);
+               ret = ao_lisp_move_memory((void **) &prev,
+                                         sizeof (struct ao_lisp_stack));
                if (prev != ao_lisp_poly_stack(stack->prev))
                        stack->prev = ao_lisp_stack_poly(prev);
                if (ret)
                        break;
-               stack = ao_lisp_poly_stack(stack->prev);
+               stack = prev;
        }
 }
 
@@ -101,8 +102,8 @@ ao_lisp_stack_push(void)
        ao_lisp_stack = stack;
        ao_lisp_stack_reset(stack);
        DBGI("stack push\n");
-       DBG_IN();
        DBG_FRAMES();
+       DBG_IN();
        return 1;
 }
 
@@ -236,37 +237,11 @@ static int
 ao_lisp_eval_val(void)
 {
        DBGI("val: "); DBG_POLY(ao_lisp_v); DBG("\n");
-#if 0
-       if (ao_lisp_stack->macro) {
-               DBGI(".. end macro %d\n", ao_lisp_stack->macro);
-               DBGI(".. sexprs       "); DBG_POLY(ao_lisp_stack->sexprs); DBG("\n");
-               DBGI(".. values       "); DBG_POLY(ao_lisp_stack->values); DBG("\n");
-               ao_lisp_frames_dump();
-
-               ao_lisp_stack_pop();
-#if 0
-               /*
-                * Re-use the current stack to evaluate
-                * the value from the macro
-                */
-               ao_lisp_stack->state = eval_sexpr;
-               ao_lisp_frame_current = ao_lisp_poly_frame(ao_lisp_stack->macro_frame);
-               ao_lisp_stack->frame = ao_lisp_stack->macro_frame;
-               ao_lisp_stack->macro = 0;
-               ao_lisp_stack->macro_frame = AO_LISP_NIL;
-               ao_lisp_stack->sexprs = AO_LISP_NIL;
-               ao_lisp_stack->values = AO_LISP_NIL;
-               ao_lisp_stack->values_tail = AO_LISP_NIL;
-#endif
-       } else
-#endif
-       {
-               /*
-                * Value computed, pop the stack
-                * to figure out what to do with the value
-                */
-               ao_lisp_stack_pop();
-       }
+       /*
+        * Value computed, pop the stack
+        * to figure out what to do with the value
+        */
+       ao_lisp_stack_pop();
        DBGI("..state %d\n", ao_lisp_stack ? ao_lisp_stack->state : -1);
        return 1;
 }
@@ -305,7 +280,6 @@ ao_lisp_eval_formal(void)
                        break;
                case AO_LISP_FUNC_MACRO:
                        /* Evaluate the result once more */
-                       prev = ao_lisp_stack;
                        ao_lisp_stack->state = eval_sexpr;
                        if (!ao_lisp_stack_push())
                                return 0;
@@ -313,6 +287,7 @@ ao_lisp_eval_formal(void)
                        /* After the function returns, take that
                         * value and re-evaluate it
                         */
+                       prev = ao_lisp_poly_stack(ao_lisp_stack->prev);
                        ao_lisp_stack->state = eval_sexpr;
                        ao_lisp_stack->sexprs = prev->sexprs;
                        prev->sexprs = AO_LISP_NIL;
@@ -400,8 +375,7 @@ ao_lisp_eval_exec(void)
        case AO_LISP_LAMBDA:
                ao_lisp_stack->state = eval_sexpr;
                DBGI(".. frame "); DBG_POLY(ao_lisp_frame_poly(ao_lisp_frame_current)); DBG("\n");
-               ao_lisp_v = ao_lisp_lambda_eval(ao_lisp_poly_lambda(ao_lisp_v),
-                                               ao_lisp_poly_cons(ao_lisp_stack->values));
+               ao_lisp_v = ao_lisp_lambda_eval();
                DBGI(".. sexpr "); DBG_POLY(ao_lisp_v); DBG("\n");
                DBGI(".. frame "); DBG_POLY(ao_lisp_frame_poly(ao_lisp_frame_current)); DBG("\n");
                break;
@@ -464,12 +438,11 @@ ao_lisp_eval_cond_test(void)
                struct ao_lisp_cons *car = ao_lisp_poly_cons(ao_lisp_poly_cons(ao_lisp_stack->sexprs)->car);
                struct ao_lisp_cons *c = ao_lisp_poly_cons(car->cdr);
 
-               ao_lisp_stack->state = eval_val;
                if (c) {
+                       ao_lisp_stack->state = eval_sexpr;
                        ao_lisp_v = c->car;
-                       if (!ao_lisp_stack_push())
-                               return 0;
-               }
+               } else
+                       ao_lisp_stack->state = eval_val;
        } else {
                ao_lisp_stack->sexprs = ao_lisp_poly_cons(ao_lisp_stack->sexprs)->cdr;
                DBGI("next cond: "); DBG_POLY(ao_lisp_stack->sexprs); DBG("\n");
index 7978f20add18c2ade7961730568eef539068991d..90344719afedc7881e5687cbc635a290f19acf7b 100644 (file)
@@ -174,8 +174,9 @@ ao_lisp_frame_new(int num)
 }
 
 static struct ao_lisp_frame *
-ao_lisp_frame_realloc(struct ao_lisp_frame *frame, int new_num)
+ao_lisp_frame_realloc(struct ao_lisp_frame **frame_ref, int new_num)
 {
+       struct ao_lisp_frame    *frame = *frame_ref;
        struct ao_lisp_frame    *new;
        int                     copy;
 
@@ -184,34 +185,45 @@ ao_lisp_frame_realloc(struct ao_lisp_frame *frame, int new_num)
        new = ao_lisp_frame_new(new_num);
        if (!new)
                return NULL;
+       /*
+        * Re-fetch the frame as it may have moved
+        * during the allocation
+        */
+       frame = *frame_ref;
        copy = new_num;
        if (copy > frame->num)
                copy = frame->num;
        memcpy(new->vals, frame->vals, copy * sizeof (struct ao_lisp_val));
-       if (frame)
-               new->next = frame->next;
+       new->next = frame->next;
        return new;
 }
 
-struct ao_lisp_frame *
-ao_lisp_frame_add(struct ao_lisp_frame *frame, ao_poly atom, ao_poly val)
+int
+ao_lisp_frame_add(struct ao_lisp_frame **frame_ref, ao_poly atom, ao_poly val)
 {
+       struct ao_lisp_frame *frame = *frame_ref;
        ao_poly *ref = frame ? ao_lisp_frame_ref(frame, atom) : NULL;
+
        if (!ref) {
                int f;
+               ao_lisp_root_poly_add(&atom);
+               ao_lisp_root_poly_add(&val);
                if (frame) {
                        f = frame->num;
-                       frame = ao_lisp_frame_realloc(frame, f + 1);
+                       frame = ao_lisp_frame_realloc(frame_ref, f + 1);
                } else {
                        f = 0;
                        frame = ao_lisp_frame_new(1);
                }
+               ao_lisp_root_clear(&atom);
+               ao_lisp_root_clear(&val);
                if (!frame)
-                       return NULL;
+                       return 0;
+               *frame_ref = frame;
                DBG ("add atom %s %d, val %d at %d\n", ao_lisp_poly_atom(atom)->name, OFFSET(atom), OFFSET(val), f);
                frame->vals[f].atom = atom;
                ref = &frame->vals[f].val;
        }
        *ref = val;
-       return frame;
+       return 1;
 }
index cc5af4bce23bd860b55203ad27bf99d568c6a72d..8eafb18794baf48cbf5e2f20a3cf7f9f981d9ac0 100644 (file)
@@ -133,18 +133,17 @@ ao_lisp_macro(struct ao_lisp_cons *cons)
 }
 
 ao_poly
-ao_lisp_lambda_eval(struct ao_lisp_lambda *lambda,
-                   struct ao_lisp_cons *cons)
+ao_lisp_lambda_eval(void)
 {
-       struct ao_lisp_cons     *code;
-       struct ao_lisp_cons     *args;
+       struct ao_lisp_lambda   *lambda = ao_lisp_poly_lambda(ao_lisp_v);
+       struct ao_lisp_cons     *cons = ao_lisp_poly_cons(ao_lisp_stack->values);
+       struct ao_lisp_cons     *code = ao_lisp_poly_cons(lambda->code);
+       struct ao_lisp_cons     *args = ao_lisp_poly_cons(ao_lisp_arg(code, 0));
        struct ao_lisp_frame    *next_frame;
        int                     args_wanted;
        int                     args_provided;
 
-       code = ao_lisp_poly_cons(lambda->code);
        DBGI("lambda "); DBG_POLY(ao_lisp_lambda_poly(lambda)); DBG("\n");
-       args = ao_lisp_poly_cons(ao_lisp_arg(code, 0));
 
        args_wanted = ao_lisp_cons_length(args);
 
@@ -156,7 +155,15 @@ ao_lisp_lambda_eval(struct ao_lisp_lambda *lambda,
                args_provided = 1;
        if (args_wanted != args_provided)
                return ao_lisp_error(AO_LISP_INVALID, "need %d args, not %d", args_wanted, args_provided);
+
        next_frame = ao_lisp_frame_new(args_wanted);
+
+       /* Re-fetch all of the values in case something moved */
+       lambda = ao_lisp_poly_lambda(ao_lisp_v);
+       cons = ao_lisp_poly_cons(ao_lisp_stack->values);
+       code = ao_lisp_poly_cons(lambda->code);
+       args = ao_lisp_poly_cons(ao_lisp_arg(code, 0));
+
        switch (lambda->args) {
        case AO_LISP_FUNC_LAMBDA: {
                int                     f;
index 66e09db0612f9eb4ce3d58a60dd20c75c6729b93..b763d78b14664fd5a3c0f995d8bb001422ef41e5 100644 (file)
@@ -28,32 +28,33 @@ uint8_t     ao_lisp_pool[AO_LISP_POOL] __attribute__((aligned(4)));
 #endif
 
 #if 0
-#define DBG_COLLECT_ALWAYS
+#define MDBG_COLLECT_ALWAYS
 #endif
 
 #if 0
-#define DBG_POOL
+#define MDBG_POOL
 #endif
 
 #if 0
-#define DBG_INCLUDE
-#define DBG_DUMP       0
-#define DBG_OFFSET(a)  ((int) ((uint8_t *) (a) - ao_lisp_pool))
-#define DBG(...) printf(__VA_ARGS__)
-#define DBG_DO(a)      a
-static int move_dump = 1;
+#define MDBG_INCLUDE
+#define MDBG_DUMP      1
+#define MDBG_MOVE      0
+#define MDBG_OFFSET(a) ((int) ((uint8_t *) (a) - ao_lisp_pool))
+#define MDBG(...) printf(__VA_ARGS__)
+#define MDBG_DO(a)     a
+static int move_dump = MDBG_MOVE;
 static int move_depth;
-#define DBG_RESET() (move_depth = 0)
-#define DBG_MOVE(...) do { if(move_dump) { int d; for (d = 0; d < move_depth; d++) printf ("  "); printf(__VA_ARGS__); } } while (0)
-#define DBG_MOVE_IN()  (move_depth++)
-#define DBG_MOVE_OUT() (move_depth--)
+#define MDBG_RESET() (move_depth = 0)
+#define MDBG_MOVE(...) do { if(move_dump) { int d; for (d = 0; d < move_depth; d++) printf ("  "); printf(__VA_ARGS__); } } while (0)
+#define MDBG_MOVE_IN() (move_depth++)
+#define MDBG_MOVE_OUT()        (move_depth--)
 #else
-#define DBG(...)
-#define DBG_DO(a)
-#define DBG_RESET()
-#define DBG_MOVE(...)
-#define DBG_MOVE_IN()
-#define DBG_MOVE_OUT()
+#define MDBG(...)
+#define MDBG_DO(a)
+#define MDBG_RESET()
+#define MDBG_MOVE(...)
+#define MDBG_MOVE_IN()
+#define MDBG_MOVE_OUT()
 #endif
 
 uint8_t        ao_lisp_exception;
@@ -69,7 +70,7 @@ static struct ao_lisp_root    ao_lisp_root[AO_LISP_ROOT];
 
 static uint8_t ao_lisp_busy[AO_LISP_POOL / 32];
 static uint8_t ao_lisp_moving[AO_LISP_POOL / 32];
-static uint8_t ao_lisp_cons[AO_LISP_POOL / 32];
+static uint8_t ao_lisp_cons_note[AO_LISP_POOL / 32];
 static uint8_t ao_lisp_cons_last[AO_LISP_POOL / 32];
 static uint8_t ao_lisp_cons_noted;
 
@@ -78,6 +79,7 @@ uint16_t      ao_lisp_top;
 static inline void mark(uint8_t *tag, int offset) {
        int     byte = offset >> 5;
        int     bit = (offset >> 2) & 7;
+
        tag[byte] |= (1 << bit);
 }
 
@@ -166,10 +168,11 @@ busy_object(uint8_t *tag, void *addr) {
 static void
 note_cons(void *addr)
 {
-       DBG_MOVE("note cons %d\n", DBG_OFFSET(addr));
+       MDBG_MOVE("note cons %d\n", MDBG_OFFSET(addr));
        if (AO_LISP_IS_POOL(addr)) {
+               int     offset = (uint8_t *) addr - ao_lisp_pool;
                ao_lisp_cons_noted = 1;
-               mark(ao_lisp_cons, (uint8_t *) addr - ao_lisp_pool);
+               mark(ao_lisp_cons_note, offset);
        }
 }
 
@@ -182,11 +185,11 @@ move_object(void)
 {
        int     i;
 
-       DBG_RESET();
-       DBG_MOVE("move %d -> %d\n", DBG_OFFSET(move_old), DBG_OFFSET(move_new));
-       DBG_MOVE_IN();
+       MDBG_RESET();
+       MDBG_MOVE("move %d -> %d\n", MDBG_OFFSET(move_old), MDBG_OFFSET(move_new));
+       MDBG_MOVE_IN();
        memset(ao_lisp_moving, '\0', sizeof (ao_lisp_moving));
-       memset(ao_lisp_cons, '\0', sizeof (ao_lisp_cons));
+       memset(ao_lisp_cons_note, '\0', sizeof (ao_lisp_cons_note));
        ao_lisp_cons_noted = 0;
        for (i = 0; i < AO_LISP_ROOT; i++) {
                if (!ao_lisp_root[i].addr)
@@ -195,10 +198,10 @@ move_object(void)
                        void *addr = *ao_lisp_root[i].addr;
                        if (!addr)
                                continue;
-                       DBG_MOVE("root %d\n", DBG_OFFSET(addr));
+                       MDBG_MOVE("root %d\n", MDBG_OFFSET(addr));
                        if (!ao_lisp_move(ao_lisp_root[i].type,
                                          ao_lisp_root[i].addr)) {
-                               DBG_MOVE("root moves from %p to %p\n",
+                               MDBG_MOVE("root moves from %p to %p\n",
                                         addr,
                                         *ao_lisp_root[i].addr);
                        }
@@ -207,31 +210,31 @@ move_object(void)
                        if (!p)
                                continue;
                        if (!ao_lisp_poly_move((ao_poly *) ao_lisp_root[i].addr, 0)) {
-                               DBG_MOVE("root poly move from %04x to %04x\n",
+                               MDBG_MOVE("root poly move from %04x to %04x\n",
                                         p, *(ao_poly *) ao_lisp_root[i].addr);
                        }
                }
        }
        while (ao_lisp_cons_noted) {
-               memcpy(ao_lisp_cons_last, ao_lisp_cons, sizeof (ao_lisp_cons));
-               memset(ao_lisp_cons, '\0', sizeof (ao_lisp_cons));
+               memcpy(ao_lisp_cons_last, ao_lisp_cons_note, sizeof (ao_lisp_cons_note));
+               memset(ao_lisp_cons_note, '\0', sizeof (ao_lisp_cons_note));
                ao_lisp_cons_noted = 0;
                for (i = 0; i < AO_LISP_POOL; i += 4) {
                        if (busy(ao_lisp_cons_last, i)) {
                                void *addr = ao_lisp_pool + i;
-                               DBG_MOVE("cons %d\n", DBG_OFFSET(addr));
+                               MDBG_MOVE("cons %d\n", MDBG_OFFSET(addr));
                                if (!ao_lisp_move(&ao_lisp_cons_type, &addr)) {
-                                       DBG_MOVE("cons moves from %p to %p\n",
+                                       MDBG_MOVE("cons moves from %p to %p\n",
                                                 ao_lisp_pool + i, addr);
                                }
                        }
                }
        }
-       DBG_MOVE_OUT();
-       DBG_MOVE("move done\n");
+       MDBG_MOVE_OUT();
+       MDBG_MOVE("move done\n");
 }
 
-#if DBG_DUMP
+#if MDBG_DUMP
 static void
 dump_busy(void)
 {
@@ -272,32 +275,32 @@ ao_lisp_mark_busy(void)
        int i;
 
        memset(ao_lisp_busy, '\0', sizeof (ao_lisp_busy));
-       memset(ao_lisp_cons, '\0', sizeof (ao_lisp_cons));
+       memset(ao_lisp_cons_note, '\0', sizeof (ao_lisp_cons_note));
        ao_lisp_cons_noted = 0;
-       DBG("mark\n");
+       MDBG("mark\n");
        for (i = 0; i < AO_LISP_ROOT; i++) {
                if (ao_lisp_root[i].type) {
                        void **a = ao_lisp_root[i].addr, *v;
                        if (a && (v = *a)) {
-                               DBG("root %d\n", DBG_OFFSET(v));
+                               MDBG("root %d\n", MDBG_OFFSET(v));
                                ao_lisp_mark(ao_lisp_root[i].type, v);
                        }
                } else {
                        ao_poly *a = (ao_poly *) ao_lisp_root[i].addr, p;
                        if (a && (p = *a)) {
-                               DBG("root 0x%04x\n", p);
+                               MDBG("root 0x%04x\n", p);
                                ao_lisp_poly_mark(p, 0);
                        }
                }
        }
        while (ao_lisp_cons_noted) {
-               memcpy(ao_lisp_cons_last, ao_lisp_cons, sizeof (ao_lisp_cons));
-               memset(ao_lisp_cons, '\0', sizeof (ao_lisp_cons));
+               memcpy(ao_lisp_cons_last, ao_lisp_cons_note, sizeof (ao_lisp_cons_note));
+               memset(ao_lisp_cons_note, '\0', sizeof (ao_lisp_cons_note));
                ao_lisp_cons_noted = 0;
                for (i = 0; i < AO_LISP_POOL; i += 4) {
                        if (busy(ao_lisp_cons_last, i)) {
                                void *v = ao_lisp_pool + i;
-                               DBG("cons %d\n", DBG_OFFSET(v));
+                               MDBG("cons %d\n", MDBG_OFFSET(v));
                                ao_lisp_mark(&ao_lisp_cons_type, v);
                        }
                }
@@ -310,13 +313,13 @@ ao_lisp_collect(void)
        int     i;
        int     top;
 
-       DBG("collect\n");
+       MDBG("collect\n");
        /* Mark */
        ao_lisp_mark_busy();
 
        DUMP_BUSY();
        /* Compact */
-       DBG("find first busy\n");
+       MDBG("find first busy\n");
        for (i = 0; i < ao_lisp_top; i += 4) {
                if (!busy(ao_lisp_busy, i))
                        break;
@@ -324,23 +327,25 @@ ao_lisp_collect(void)
        top = i;
        while(i < ao_lisp_top) {
                if (busy(ao_lisp_busy, i)) {
-                       DBG("busy %d -> %d\n", i, top);
+                       MDBG("busy %d -> %d\n", i, top);
                        move_old = &ao_lisp_pool[i];
                        move_new = &ao_lisp_pool[top];
                        move_size = 0;
                        move_object();
-                       DBG("\tbusy size %d\n", move_size);
+                       MDBG("\tbusy size %d\n", move_size);
                        if (move_size == 0)
                                ao_lisp_abort();
                        clear_object(ao_lisp_busy, move_old, move_size);
                        mark_object(ao_lisp_busy, move_new, move_size);
-                       if (busy_object(ao_lisp_cons, move_old)) {
-                               clear_object(ao_lisp_cons, move_old, move_size);
-                               mark_object(ao_lisp_cons, move_new, move_size);
+                       if (busy_object(ao_lisp_cons_note, move_old)) {
+                               clear_object(ao_lisp_cons_note, move_old, move_size);
+                               mark_object(ao_lisp_cons_note, move_new, move_size);
                        }
                        i += move_size;
                        top += move_size;
+#if MDBG_MOVE
                        DUMP_BUSY();
+#endif
                } else {
                        i += 4;
                }
@@ -404,9 +409,9 @@ static void *
 check_move(void *addr, int size)
 {
        if (addr == move_old) {
-               DBG_MOVE("mapping %d -> %d\n", DBG_OFFSET(addr), DBG_OFFSET(move_new));
+               MDBG_MOVE("mapping %d -> %d\n", MDBG_OFFSET(addr), MDBG_OFFSET(move_new));
                if (!busy_object(ao_lisp_moving, addr)) {
-                       DBG_MOVE("  copy %d\n", size);
+                       MDBG_MOVE("  copy %d\n", size);
                        memmove(move_new, move_old, size);
                        move_size = (size + 3) & ~3;
                }
@@ -429,24 +434,24 @@ ao_lisp_move(const struct ao_lisp_type *type, void **ref)
        if (AO_LISP_IS_CONST(addr))
                return 1;
 #endif
-       DBG_MOVE("object %d\n", DBG_OFFSET(addr));
+       MDBG_MOVE("object %d\n", MDBG_OFFSET(addr));
        if (!AO_LISP_IS_POOL(a))
                ao_lisp_abort();
-       DBG_MOVE_IN();
+       MDBG_MOVE_IN();
        addr = check_move(addr, size);
        if (addr != *ref)
                *ref = addr;
        if (mark_object(ao_lisp_moving, addr, size)) {
-               DBG_MOVE("already moved\n");
-               DBG_MOVE_OUT();
+               MDBG_MOVE("already moved\n");
+               MDBG_MOVE_OUT();
                return 1;
        }
-       DBG_MOVE_OUT();
-       DBG_MOVE("recursing...\n");
-       DBG_MOVE_IN();
+       MDBG_MOVE_OUT();
+       MDBG_MOVE("recursing...\n");
+       MDBG_MOVE_IN();
        type->move(addr);
-       DBG_MOVE_OUT();
-       DBG_MOVE("done %d\n", DBG_OFFSET(addr));
+       MDBG_MOVE_OUT();
+       MDBG_MOVE("done %d\n", MDBG_OFFSET(addr));
        return 0;
 }
 
@@ -457,17 +462,17 @@ ao_lisp_move_memory(void **ref, int size)
        if (!addr)
                return 1;
 
-       DBG_MOVE("memory %d\n", DBG_OFFSET(addr));
-       DBG_MOVE_IN();
+       MDBG_MOVE("memory %d\n", MDBG_OFFSET(addr));
+       MDBG_MOVE_IN();
        addr = check_move(addr, size);
        if (addr != *ref)
                *ref = addr;
        if (mark_object(ao_lisp_moving, addr, size)) {
-               DBG_MOVE("already moved\n");
-               DBG_MOVE_OUT();
+               MDBG_MOVE("already moved\n");
+               MDBG_MOVE_OUT();
                return 1;
        }
-       DBG_MOVE_OUT();
+       MDBG_MOVE_OUT();
        return 0;
 }
 
@@ -505,14 +510,14 @@ ao_lisp_poly_move(ao_poly *ref, uint8_t do_note_cons)
 
        if (addr != ao_lisp_ref(p)) {
                ao_poly np = ao_lisp_poly(addr, p & AO_LISP_TYPE_MASK);
-               DBG("poly %d moved %04x -> %04x\n",
+               MDBG("poly %d moved %04x -> %04x\n",
                    type, p, np);
                *ref = np;
        }
        return ret;
 }
 
-#ifdef DBG_POOL
+#ifdef MDBG_POOL
 static int AO_LISP_POOL_CUR = AO_LISP_POOL / 8;
 
 static void
@@ -557,18 +562,18 @@ ao_lisp_alloc(int size)
        void    *addr;
 
        size = ao_lisp_mem_round(size);
-#ifdef DBG_COLLECT_ALWAYS
+#ifdef MDBG_COLLECT_ALWAYS
        ao_lisp_collect();
 #endif
        if (ao_lisp_top + size > AO_LISP_POOL_CUR) {
-#ifdef DBG_POOL
+#ifdef MDBG_POOL
                if (AO_LISP_POOL_CUR < AO_LISP_POOL) {
                        AO_LISP_POOL_CUR += AO_LISP_POOL / 8;
                        ao_lisp_poison();
                } else
 #endif
                ao_lisp_collect();
-#ifdef DBG_POOL
+#ifdef MDBG_POOL
                {
                        int     i;
 
@@ -580,7 +585,7 @@ ao_lisp_alloc(int size)
 #endif
 
                if (ao_lisp_top + size > AO_LISP_POOL) {
-                       ao_lisp_exception |= AO_LISP_OOM;
+                       ao_lisp_error(AO_LISP_OOM, "out of memory");
                        return NULL;
                }
        }
@@ -593,7 +598,7 @@ int
 ao_lisp_root_add(const struct ao_lisp_type *type, void *addr)
 {
        int     i;
-       DBG("add root type %p addr %p\n", type, addr);
+       MDBG("add root type %p addr %p\n", type, addr);
        for (i = 0; i < AO_LISP_ROOT; i++) {
                if (!ao_lisp_root[i].addr) {
                        ao_lisp_root[i].addr = addr;