1 /* -----------------------------------------------------------------------------
2 * $Id: StgTypes.h,v 1.3 1999/01/26 11:12:58 simonm Exp $
4 * Various C datatypes used in the run-time system.
10 StgChar, StgFloat, StgDouble
12 ***** All the same size: *****
13 StgPtr Basic pointer type
14 StgWord Unit of heap allocation
15 StgInt Signed version of StgWord
16 StgAddr Generic address type
20 * ---------------------------------------------------------------------------*/
26 * First, platform-dependent definitions of size-specific integers.
27 * Assume for now that the int type is 32 bits.
28 * ToDo: move these into a platform-dependent file.
31 typedef signed char StgInt8;
32 typedef unsigned char StgNat8;
34 typedef signed short StgInt16;
35 typedef unsigned short StgNat16;
38 #if SIZEOF_UNSIGNED_INT == 4
39 typedef signed int StgInt32;
40 typedef unsigned int StgNat32;
42 #error GHC untested on this architecture: sizeof(unisgned int) != 4
45 /* This #define controls whether we need to support long longs on a particular
48 * ToDo: find a proper home for (derived) configuration information like this.
50 #if HAVE_LONG_LONG && SIZEOF_VOID_P < 8
51 #define SUPPORT_LONG_LONGS
54 #ifdef SUPPORT_LONG_LONGS
55 /* assume long long is 64 bits */
56 typedef unsigned long long int StgNat64;
57 typedef signed long long int StgInt64;
58 #elif SIZEOF_LONG == 8
59 typedef signed long StgInt64;
60 typedef unsigned long StgNat64;
62 #error GHC untested on this architecture: sizeof(void *) < 8 and no long longs.
67 * Define the standard word size we'll use on this machine: make it
68 * big enough to hold a pointer.
71 #if SIZEOF_VOID_P == 8
72 typedef StgInt64 StgInt;
73 typedef StgNat64 StgWord;
75 #if SIZEOF_VOID_P == 4
76 typedef StgInt32 StgInt;
77 typedef StgNat32 StgWord;
79 #error GHC untested on this architecture: sizeof(void *) != 4 or 8
83 typedef void* StgAddr;
86 * Other commonly-used STG datatypes.
89 typedef StgNat8 StgChar;
92 * If a double fits in an StgWord, don't bother using floats.
95 #if SIZEOF_DOUBLE == SIZEOF_VOID_P
96 typedef double StgFloat;
97 typedef double StgDouble;
98 #define FLOATS_AS_DOUBLES 1
100 typedef float StgFloat;
101 typedef double StgDouble;
104 typedef void StgVoid;
106 typedef struct StgClosure_* StgClosurePtr;
107 typedef StgWord* StgPtr; /* pointer into closure */
108 typedef StgWord StgOffset; /* byte offset within closure */
110 typedef struct StgTSO_* StgTSOPtr;
112 typedef void * StgForeignPtr;
114 typedef StgInt StgStackOffset; /* offset in words! */
116 typedef StgWord* StgStackPtr;
118 typedef StgNat8 StgCode; /* close enough */
119 typedef StgCode* StgCodePtr;
121 typedef StgPtr* StgArray; /* the goods of an Array# */
122 typedef char* StgByteArray; /* the goods of a ByteArray# */
124 typedef StgInt64 LI_;
125 typedef StgNat64 LW_;
127 /* Stable Pointers: A stable pointer is represented as an index into
128 * the stable pointer table in the low 24 bits with a weight in the
131 typedef StgWord StgStablePtr;
133 #define STABLEPTR_WEIGHT_MASK (0xff << ((sizeof(StgWord)-1) * BITS_PER_BYTE))
134 #define STABLEPTR_WEIGHT_SHIFT (BITS_IN(StgWord) - 8)
137 Types for the generated C functions
139 return a pointer to the next function to be called
140 use: Ptr to Fun that returns a Ptr to Fun which returns Ptr to void
142 Note: Neither StgFunPtr not StgFun is quite right (that is,
143 StgFunPtr != StgFun*). So, the functions we define all have type
144 StgFun but we always have to cast them to StgFunPtr when we assign
146 The only way round this would be to write a recursive type but
147 C only allows that if you're defining a struct or union.
150 typedef void *(*(*StgFunPtr)(void))(void);
151 typedef StgFunPtr StgFun(void);
161 StgStackOffset offset; /* unused? */
176 typedef const StgWord* D_;
177 typedef StgFunPtr F_;
178 typedef StgByteArray B_;
179 typedef StgClosurePtr L_;
182 * We often want to know the size of something in units of an
183 * StgWord... (rounded up, of course!)
186 #define sizeofW(t) ((sizeof(t)+sizeof(W_)-1)/sizeof(W_))
189 * It's nice to be able to grep for casts
192 #define stgCast(ty,e) ((ty)(e))