1 /* -----------------------------------------------------------------------------
2 * $Id: StgTypes.h,v 1.2 1998/12/02 13:21:41 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 StgWord StgStablePtr;
113 typedef void * StgForeignPtr;
115 typedef StgInt StgStackOffset; /* offset in words! */
117 typedef StgWord* StgStackPtr;
119 typedef StgNat8 StgCode; /* close enough */
120 typedef StgCode* StgCodePtr;
122 typedef StgPtr* StgArray; /* the goods of an Array# */
123 typedef char* StgByteArray; /* the goods of a ByteArray# */
125 typedef StgInt64 LI_;
126 typedef StgNat64 LW_;
129 Types for the generated C functions
131 return a pointer to the next function to be called
132 use: Ptr to Fun that returns a Ptr to Fun which returns Ptr to void
134 Note: Neither StgFunPtr not StgFun is quite right (that is,
135 StgFunPtr != StgFun*). So, the functions we define all have type
136 StgFun but we always have to cast them to StgFunPtr when we assign
138 The only way round this would be to write a recursive type but
139 C only allows that if you're defining a struct or union.
142 typedef void *(*(*StgFunPtr)(void))(void);
143 typedef StgFunPtr StgFun(void);
153 StgStackOffset offset; /* unused? */
168 typedef const StgWord* D_;
169 typedef StgFunPtr F_;
170 typedef StgByteArray B_;
171 typedef StgClosurePtr L_;
174 * We often want to know the size of something in units of an
175 * StgWord... (rounded up, of course!)
178 #define sizeofW(t) ((sizeof(t)+sizeof(W_)-1)/sizeof(W_))
181 * It's nice to be able to grep for casts
184 #define stgCast(ty,e) ((ty)(e))