@@ -1,5 +1,5 @@
1-------------------------------------------------------------------------------
1-------------------------------------------------------------------------------
2−-- Macros to access array pointers
2+-- Macros to access Storable pointers
3-------------------------------------------------------------------------------
3-------------------------------------------------------------------------------
5-- The Storable instance of () has size 0. We ensure that the size is non-zero
5-- The Storable instance of () has size 0. We ensure that the size is non-zero
@@ -8,7 +8,6 @@
9-- XXX Check the core to see if max can be statically eliminated. llvm can
9-- XXX Check the core to see if max can be statically eliminated. llvm can
10-- eliminate the comparison, but not sure if GHC NCG can.
10-- eliminate the comparison, but not sure if GHC NCG can.
11−#define SIZE_OF(a) max 1 (sizeOf (Proxy :: Proxy a))
12#define STORABLE_SIZE_OF(a) max 1 (sizeOf (undefined :: a))
11#define STORABLE_SIZE_OF(a) max 1 (sizeOf (undefined :: a))
14-- Move the pointer to ith element of specified type. Type is specified as the
13-- Move the pointer to ith element of specified type. Type is specified as the
@@ -27,9 +26,13 @@
27#define PTR_INVALID(ptr,end,a) ptr `plusPtr` STORABLE_SIZE_OF(a) > end
26#define PTR_INVALID(ptr,end,a) ptr `plusPtr` STORABLE_SIZE_OF(a) > end
29-------------------------------------------------------------------------------
28-------------------------------------------------------------------------------
30−-- Macros to access array indices
29+-- Macros to access array indices (using Unbox type class)
31-------------------------------------------------------------------------------
30-------------------------------------------------------------------------------
32+-- This macro was originally defined as a wrapper to sizeOf so that we can
33+-- avoid a sizeOf value of 0 and make it 1.
34+#define SIZE_OF(a) sizeOf (Proxy :: Proxy a)
33#define INDEX_NEXT(i,a) i + SIZE_OF(a)
36#define INDEX_NEXT(i,a) i + SIZE_OF(a)
34#define INDEX_PREV(i,a) i - SIZE_OF(a)
37#define INDEX_PREV(i,a) i - SIZE_OF(a)