1 /* -----------------------------------------------------------------------------
2 * $Id: StgTypes.h,v 1.14 2000/11/07 13:30:40 simonmar Exp $
4 * (c) The GHC Team, 1998-2000
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 StgWord32 StgChar;
95 typedef float StgFloat;
96 typedef double StgDouble;
100 typedef struct StgClosure_* StgClosurePtr;
101 typedef StgWord* StgPtr; /* pointer into closure */
102 typedef StgWord StgOffset; /* byte offset within closure */
104 typedef struct StgTSO_* StgTSOPtr;
106 typedef void* StgForeignPtr;
108 typedef StgInt StgStackOffset; /* offset in words! */
110 typedef StgWord* StgStackPtr;
112 typedef StgWord8 StgCode; /* close enough */
113 typedef StgCode* StgCodePtr;
115 typedef StgPtr* StgArray; /* the goods of an Array# */
116 typedef char* StgByteArray; /* the goods of a ByteArray# */
118 typedef StgInt64 LI_;
119 typedef StgWord64 LW_;
121 /* Stable Pointers: A stable pointer is represented as an index into
122 * the stable pointer table in the low 24 bits with a weight in the
124 * SUP: StgStablePtr used to be a synonym for StgWord, but stable pointers
125 * are guaranteed to be void* on the C-side, so we have to do some occasional
126 * casting. Size is not a matter, because StgWord is always the same size as
129 typedef void* StgStablePtr;
131 #define STABLEPTR_WEIGHT_MASK ((StgWord)0xff << ((sizeof(StgWord)-1) * BITS_PER_BYTE))
132 #define STABLEPTR_WEIGHT_SHIFT (BITS_IN(StgWord) - 8)
135 Types for the generated C functions
137 return a pointer to the next function to be called
138 use: Ptr to Fun that returns a Ptr to Fun which returns Ptr to void
140 Note: Neither StgFunPtr not StgFun is quite right (that is,
141 StgFunPtr != StgFun*). So, the functions we define all have type
142 StgFun but we always have to cast them to StgFunPtr when we assign
144 The only way round this would be to write a recursive type but
145 C only allows that if you're defining a struct or union.
148 typedef void *(*(*StgFunPtr)(void))(void);
149 typedef StgFunPtr StgFun(void);
160 StgStackOffset offset; /* unused? */
175 typedef const StgWord* D_;
176 typedef StgFunPtr F_;
177 typedef StgByteArray B_;
178 typedef StgClosurePtr L_;
181 * We often want to know the size of something in units of an
182 * StgWord... (rounded up, of course!)
185 #define sizeofW(t) ((sizeof(t)+sizeof(W_)-1)/sizeof(W_))
188 * It's nice to be able to grep for casts
191 #define stgCast(ty,e) ((ty)(e))
193 #endif /* STGTYPES_H */