[add a lot more sanity checking when compiling with -fdebug
John Meacham <john@repetae.net>**20070302075638] hunk ./data/jhc_rts2.c 2
-#include <assert.h>
-
hunk ./data/jhc_rts2.c 4
+#define GETTAG(x)   ((uintptr_t)(x) & 0x3)
hunk ./data/jhc_rts2.c 14
+
hunk ./data/jhc_rts2.c 100
+
hunk ./data/jhc_rts2.c 108
+
+
+static int A_UNUSED
+jhc_valid_whnf(wptr_t s)
+{
+        return ((GETTAG(s) == P_VALUE) || ((GETTAG(s) == P_WHNF) && jhc_malloc_sanity(s,P_WHNF)));
+}
+
+static int A_UNUSED
+jhc_valid_lazy(sptr_t s)
+{
+        if(jhc_valid_whnf((wptr_t)s))
+                return 1;
+        assert(GETTAG(s) == P_LAZY);
+        assert(jhc_malloc_sanity(s,P_LAZY));
+        if(ISLAZY(s->head)) {
+                if(s->head == BLACK_HOLE) return 1;
+                assert(GETTAG(s->head) == P_LAZY);
+                fptr_t dhead = DETAG(s->head);
+                assert(dhead >= &_start && dhead < &_end);
+                return 1;
+        } else
+                return jhc_valid_whnf((wptr_t)s->head);
+}
+
+#else
+
+#define jhc_valid_whnf(x) 1
+#define jhc_valid_lazy(x) 1
+
hunk ./data/jhc_rts2.c 140
+
hunk ./data/jhc_rts2.c 148
+        assert(jhc_valid_whnf((wptr_t)s));
hunk ./data/jhc_rts2.c 156
+        assert(jhc_valid_lazy(s));
hunk ./data/jhc_rts2.c 168
+        assert(jhc_valid_lazy(s));
hunk ./data/jhc_rts2.c 170
+                assert(GETTAG(s) == P_LAZY);
hunk ./data/jhc_rts2.c 187
+        assert(jhc_valid_whnf((wptr_t)s));
hunk ./data/jhc_rts_alloc.c 42
+
+extern void _start;
+extern void _end;
+
+static int
+jhc_malloc_sanity(void *p,int tag)
+{
+        assert((p >= jhc_memstart && p < jhc_mem) || (p >= &_start && p < &_end));
+        return 1;
+}
+
+
hunk ./data/jhc_rts_alloc.c 56
-static inline void * A_MALLOC
+static void * A_MALLOC
hunk ./data/jhc_rts_alloc.c 75
+#define jhc_malloc_sanity(p,t) do {} while(0)
+
hunk ./data/jhc_rts_header.h 12
+#include <assert.h>