#ifdef BIG_ENDIAN #undef BIG_ENDIAN #endif #include #include #include #include #include /*#include "haskell2c.h"*/ #include "runtime.h" #include "mark.h" #include "stableptr.h" extern void mark(NodePtr*); extern void flip(NodePtr*); /* Whenever we get a stable ptr, it is given a reference number and placed in * a table, the StableTable, using makeStablePtr(NodePtr np). (For * convenience of testing, we never use the zero index in the table.) * * Nodes are looked up in the table using derefStablePtr(StablePtr ref). * If it returns zero, the node is not in the table. */ static long STABLE_ALLOCSIZE = 1024; static NodePtr *StableTable; static long StableFree; static long StableRefNr; NodePtr derefStablePtr(StablePtr ref) { return StableTable[(long)ref]; } void mapStablePtrs(void (*f)(NodePtr*)) { long i; for(i=0; i < STABLE_ALLOCSIZE; i++) { if (StableTable[i]) { f(&StableTable[i]); } } } StablePtr makeStablePtr(NodePtr np) { if (--StableFree == 0) { long i = STABLE_ALLOCSIZE; StableFree += STABLE_ALLOCSIZE; STABLE_ALLOCSIZE *= 2; if (!(StableTable = (NodePtr*)realloc((void*)StableTable,STABLE_ALLOCSIZE*sizeof(NodePtr*)))) { fprintf(stderr, "Couldn't increase size of stable pointer table.\n"); exit(1); } for (; i