1 /* -----------------------------------------------------------------------------
2 * $Id: StgTypes.h,v 1.10 2000/04/06 13:41:16 panne Exp $
4 * (c) The GHC Team, 1998-1999
6 * Various C datatypes used in the run-time system.
12 StgChar, StgFloat, StgDouble
14 ***** All the same size: *****
15 StgPtr Basic pointer type
16 StgWord Unit of heap allocation
17 StgInt Signed version of StgWord
18 StgAddr Generic address type
20 * WARNING: Keep this file and HsFFI.h in synch!
22 * ---------------------------------------------------------------------------*/
28 * First, platform-dependent definitions of size-specific integers.
29 * Assume for now that the int type is 32 bits.
30 * NOTE: Synch the following definitions with MachDeps.h!
31 * ToDo: move these into a platform-dependent file.
34 typedef signed char StgInt8;
35 typedef unsigned char StgWord8;
37 typedef signed short StgInt16;
38 typedef unsigned short StgWord16;
41 #if SIZEOF_UNSIGNED_INT == 4
42 typedef signed int StgInt32;
43 typedef unsigned int StgWord32;
45 #error GHC untested on this architecture: sizeof(unsigned int) != 4
48 /* This #define controls whether we need to support long longs on a particular
51 * ToDo: find a proper home for (derived) configuration information like this.
53 #if HAVE_LONG_LONG && SIZEOF_VOID_P < 8
54 #define SUPPORT_LONG_LONGS
57 #ifdef SUPPORT_LONG_LONGS
58 /* assume long long is 64 bits */
59 typedef unsigned long long int StgWord64;
60 typedef signed long long int StgInt64;
61 #elif SIZEOF_LONG == 8
62 typedef signed long StgInt64;
63 typedef unsigned long StgWord64;
65 #error GHC untested on this architecture: sizeof(void *) < 8 and no long longs.
70 * Define the standard word size we'll use on this machine: make it
71 * big enough to hold a pointer.
74 #if SIZEOF_VOID_P == 8
75 typedef StgInt64 StgInt;
76 typedef StgWord64 StgWord;
78 #if SIZEOF_VOID_P == 4
79 typedef StgInt32 StgInt;
80 typedef StgWord32 StgWord;
82 #error GHC untested on this architecture: sizeof(void *) != 4 or 8
86 typedef void* StgAddr;
89 * Other commonly-used STG datatypes.
92 typedef StgWord8 StgChar;
95 * If a double fits in an StgWord, don't bother using floats.
98 #if SIZEOF_DOUBLE == SIZEOF_VOID_P
99 typedef double StgFloat;
100 typedef double StgDouble;
101 #define FLOATS_AS_DOUBLES 1
103 typedef float StgFloat;
104 typedef double StgDouble;
107 typedef void StgVoid;
109 typedef struct StgClosure_* StgClosurePtr;
110 typedef StgWord* StgPtr; /* pointer into closure */
111 typedef StgWord StgOffset; /* byte offset within closure */
113 typedef struct StgTSO_* StgTSOPtr;
115 typedef void * StgForeignPtr;
117 typedef StgInt StgStackOffset; /* offset in words! */
119 typedef StgWord* StgStackPtr;
121 typedef StgWord8 StgCode; /* close enough */
122 typedef StgCode* StgCodePtr;
124 typedef StgPtr* StgArray; /* the goods of an Array# */
125 typedef char* StgByteArray; /* the goods of a ByteArray# */
127 typedef StgInt64 LI_;
128 typedef StgWord64 LW_;
130 /* Stable Pointers: A stable pointer is represented as an index into
131 * the stable pointer table in the low 24 bits with a weight in the
134 typedef StgWord StgStablePtr;
136 #define STABLEPTR_WEIGHT_MASK ((StgWord)0xff << ((sizeof(StgWord)-1) * BITS_PER_BYTE))
137 #define STABLEPTR_WEIGHT_SHIFT (BITS_IN(StgWord) - 8)
140 Types for the generated C functions
142 return a pointer to the next function to be called
143 use: Ptr to Fun that returns a Ptr to Fun which returns Ptr to void
145 Note: Neither StgFunPtr not StgFun is quite right (that is,
146 StgFunPtr != StgFun*). So, the functions we define all have type
147 StgFun but we always have to cast them to StgFunPtr when we assign
149 The only way round this would be to write a recursive type but
150 C only allows that if you're defining a struct or union.
153 typedef void *(*(*StgFunPtr)(void))(void);
154 typedef StgFunPtr StgFun(void);
164 StgStackOffset offset; /* unused? */
179 typedef const StgWord* D_;
180 typedef StgFunPtr F_;
181 typedef StgByteArray B_;
182 typedef StgClosurePtr L_;
185 * We often want to know the size of something in units of an
186 * StgWord... (rounded up, of course!)
189 #define sizeofW(t) ((sizeof(t)+sizeof(W_)-1)/sizeof(W_))
192 * It's nice to be able to grep for casts
195 #define stgCast(ty,e) ((ty)(e))
197 #endif /* STGTYPES_H */