#ifndef _AO_SCHEME_H_
#define _AO_SCHEME_H_
+#ifndef DBG_MEM
#define DBG_MEM 0
+#endif
+#ifndef DBG_EVAL
#define DBG_EVAL 0
+#endif
+#ifndef DBG_READ
#define DBG_READ 0
+#endif
+#ifndef DBG_FREE_CONS
#define DBG_FREE_CONS 0
+#endif
#define NDEBUG 1
#include <stdint.h>
/* debugging macros */
-#if DBG_EVAL || DBG_READ || DBG_MEM
-#define DBG_CODE 1
+#if DBG_EVAL || DBG_READ
int ao_scheme_stack_depth;
+#endif
+
+#if DBG_EVAL
#define DBG_DO(a) a
#define DBG_INDENT() do { int _s; for(_s = 0; _s < ao_scheme_stack_depth; _s++) printf(" "); } while(0)
#define DBG_IN() (++ao_scheme_stack_depth)
#endif
#if DBG_READ
-#define RDBGI(...) DBGI(__VA_ARGS__)
-#define RDBG_IN() DBG_IN()
-#define RDBG_OUT() DBG_OUT()
+#define RDBGI(...) do { printf("%4d: ", __LINE__); DBG_INDENT(); ao_scheme_printf(__VA_ARGS__); } while (0)
+#define RDBG_IN() (++ao_scheme_stack_depth)
+#define RDBG_OUT() (--ao_scheme_stack_depth)
#else
#define RDBGI(...)
#define RDBG_IN()
#define RDBG_OUT()
#endif
-#define DBG_MEM_START 1
+static inline int
+ao_scheme_mdbg_offset(void *a)
+{
+ uint8_t *u = a;
+
+ if (u == 0)
+ return -1;
+
+ if (ao_scheme_pool <= u && u < ao_scheme_pool + AO_SCHEME_POOL)
+ return u - ao_scheme_pool;
+
+#ifndef AO_SCHEME_MAKE_CONST
+ if (ao_scheme_const <= u && u < ao_scheme_const + AO_SCHEME_POOL_CONST)
+ return - (int) (u - ao_scheme_const);
+#endif
+ return -2;
+}
+
+#define MDBG_OFFSET(a) ao_scheme_mdbg_offset(a)
#if DBG_MEM
+#define DBG_MEM_START 1
+
#include <assert.h>
extern int dbg_move_depth;
#define MDBG_DUMP 1
-#define MDBG_OFFSET(a) ((a) ? (int) ((uint8_t *) (a) - ao_scheme_pool) : -1)
extern int dbg_mem;
-#define MDBG_DO(a) DBG_DO(a)
+#define MDBG_DO(a) a
#define MDBG_MOVE(...) do { if (dbg_mem) { int d; for (d = 0; d < dbg_move_depth; d++) printf (" "); printf(__VA_ARGS__); } } while (0)
#define MDBG_MORE(...) do { if (dbg_mem) printf(__VA_ARGS__); } while (0)
#define MDBG_MOVE_IN() (dbg_move_depth++)
#define ao_scheme_reset_stack()
#endif
+#if DBG_MEM
+#define DBG_MEM_RECORD 1
+#endif
+
#if DBG_MEM
int dbg_move_depth;
int dbg_mem = DBG_MEM_START;
int dbg_validate = 0;
+#endif
+#if DBG_MEM_RECORD
struct ao_scheme_record {
struct ao_scheme_record *next;
const struct ao_scheme_type *type;
}
static void
-ao_scheme_record_compare(char *where,
- struct ao_scheme_record *a,
- struct ao_scheme_record *b)
+ao_scheme_record_compare(const char *where,
+ struct ao_scheme_record *a,
+ struct ao_scheme_record *b)
{
while (a && b) {
if (a->type != b->type || a->size != b->size) {
#else
#define ao_scheme_record_reset()
+#define ao_scheme_record(t,a,s)
#endif
uint8_t ao_scheme_exception;
/* Off the left side */
if (l == 0 && chunk_last && offset > ao_scheme_chunk[0].old_offset)
ao_scheme_abort();
+
+ if (l < chunk_last && ao_scheme_chunk[l].old_offset == offset)
+ ao_scheme_abort();
#endif
/* Shuffle existing entries right */
dump_busy(void)
{
int i;
- MDBG_MOVE("busy:");
+ printf("busy:");
for (i = 0; i < ao_scheme_top; i += 4) {
if ((i & 0xff) == 0) {
- MDBG_MORE("\n");
- MDBG_MOVE("%s", "");
+ printf("\n\t");
}
else if ((i & 0x1f) == 0)
- MDBG_MORE(" ");
+ printf(" ");
if (busy(ao_scheme_busy, i))
- MDBG_MORE("*");
+ printf("*");
else
- MDBG_MORE("-");
+ printf("-");
}
- MDBG_MORE ("\n");
+ printf ("\n");
}
#define DUMP_BUSY() dump_busy()
#else
#if DBG_MEM_STATS
int loops = 0;
#endif
-#if DBG_MEM
+#if DBG_MEM_RECORD
struct ao_scheme_record *mark_record = NULL, *move_record = NULL;
-
- MDBG_MOVE("collect %d\n", ao_scheme_collects[style]);
#endif
+ MDBG_MOVE("collect %lu\n", ao_scheme_collects[style]);
+
MDBG_DO(ao_scheme_frame_write(ao_scheme_frame_poly(ao_scheme_frame_global)));
MDBG_DO(++ao_scheme_collecting);
chunk_low = top = ao_scheme_last_top;
}
for (;;) {
-#if DBG_MEM_STATS
- loops++;
-#endif
MDBG_MOVE("move chunks from %d to %d\n", chunk_low, top);
/* Find the sizes of the first chunk of objects to move */
reset_chunks();
walk(ao_scheme_mark_ref, ao_scheme_poly_mark_ref);
-#if DBG_MEM
+#if DBG_MEM_RECORD
ao_scheme_record_free(mark_record);
mark_record = ao_scheme_record_save();
if (mark_record && move_record)
/* Find the first moving object */
for (i = 0; i < chunk_last; i++) {
uint16_t size = ao_scheme_chunk[i].size;
-
#if DBG_MEM
if (!size)
ao_scheme_abort();
/* Relocate all references to the objects */
walk(ao_scheme_move, ao_scheme_poly_move);
-#if DBG_MEM
+#if DBG_MEM_RECORD
ao_scheme_record_free(move_record);
move_record = ao_scheme_record_save();
if (mark_record && move_record)
#endif
}
+#if DBG_MEM_STATS
+ loops++;
+#endif
/* If we ran into the end of the heap, then
* there's no need to keep walking
*/
return 1;
}
mark(ao_scheme_busy, offset);
- MDBG_DO(ao_scheme_record(type, addr, ao_scheme_size(type, addr)));
+ ao_scheme_record(type, addr, ao_scheme_size(type, addr));
return 0;
}
if (offset != orig_offset) {
ao_poly np = ao_scheme_poly(ao_scheme_pool + offset, ao_scheme_poly_base_type(p));
MDBG_MOVE("poly %d moved %d -> %d\n",
- type, orig_offset, offset);
+ ao_scheme_poly_type(np), orig_offset, offset);
*ref = np;
}
return ret;
}
#if DBG_MEM
-void
+static void
ao_scheme_validate(void)
{
chunk_low = 0;