1 /* -----------------------------------------------------------------------------
2 * $Id: StgTypes.h,v 1.4 1999/02/05 16:02:30 simonm 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
22 * ---------------------------------------------------------------------------*/
28 * First, platform-dependent definitions of size-specific integers.
29 * Assume for now that the int type is 32 bits.
30 * ToDo: move these into a platform-dependent file.
33 typedef signed char StgInt8;
34 typedef unsigned char StgNat8;
36 typedef signed short StgInt16;
37 typedef unsigned short StgNat16;
40 #if SIZEOF_UNSIGNED_INT == 4
41 typedef signed int StgInt32;
42 typedef unsigned int StgNat32;
44 #error GHC untested on this architecture: sizeof(unisgned int) != 4
47 /* This #define controls whether we need to support long longs on a particular
50 * ToDo: find a proper home for (derived) configuration information like this.
52 #if HAVE_LONG_LONG && SIZEOF_VOID_P < 8
53 #define SUPPORT_LONG_LONGS
56 #ifdef SUPPORT_LONG_LONGS
57 /* assume long long is 64 bits */
58 typedef unsigned long long int StgNat64;
59 typedef signed long long int StgInt64;
60 #elif SIZEOF_LONG == 8
61 typedef signed long StgInt64;
62 typedef unsigned long StgNat64;
64 #error GHC untested on this architecture: sizeof(void *) < 8 and no long longs.
69 * Define the standard word size we'll use on this machine: make it
70 * big enough to hold a pointer.
73 #if SIZEOF_VOID_P == 8
74 typedef StgInt64 StgInt;
75 typedef StgNat64 StgWord;
77 #if SIZEOF_VOID_P == 4
78 typedef StgInt32 StgInt;
79 typedef StgNat32 StgWord;
81 #error GHC untested on this architecture: sizeof(void *) != 4 or 8
85 typedef void* StgAddr;
88 * Other commonly-used STG datatypes.
91 typedef StgNat8 StgChar;
94 * If a double fits in an StgWord, don't bother using floats.
97 #if SIZEOF_DOUBLE == SIZEOF_VOID_P
98 typedef double StgFloat;
99 typedef double StgDouble;
100 #define FLOATS_AS_DOUBLES 1
102 typedef float StgFloat;
103 typedef double StgDouble;
106 typedef void StgVoid;
108 typedef struct StgClosure_* StgClosurePtr;
109 typedef StgWord* StgPtr; /* pointer into closure */
110 typedef StgWord StgOffset; /* byte offset within closure */
112 typedef struct StgTSO_* StgTSOPtr;
114 typedef void * StgForeignPtr;
116 typedef StgInt StgStackOffset; /* offset in words! */
118 typedef StgWord* StgStackPtr;
120 typedef StgNat8 StgCode; /* close enough */
121 typedef StgCode* StgCodePtr;
123 typedef StgPtr* StgArray; /* the goods of an Array# */
124 typedef char* StgByteArray; /* the goods of a ByteArray# */
126 typedef StgInt64 LI_;
127 typedef StgNat64 LW_;
129 /* Stable Pointers: A stable pointer is represented as an index into
130 * the stable pointer table in the low 24 bits with a weight in the
133 typedef StgWord StgStablePtr;
135 #define STABLEPTR_WEIGHT_MASK (0xff << ((sizeof(StgWord)-1) * BITS_PER_BYTE))
136 #define STABLEPTR_WEIGHT_SHIFT (BITS_IN(StgWord) - 8)
139 Types for the generated C functions
141 return a pointer to the next function to be called
142 use: Ptr to Fun that returns a Ptr to Fun which returns Ptr to void
144 Note: Neither StgFunPtr not StgFun is quite right (that is,
145 StgFunPtr != StgFun*). So, the functions we define all have type
146 StgFun but we always have to cast them to StgFunPtr when we assign
148 The only way round this would be to write a recursive type but
149 C only allows that if you're defining a struct or union.
152 typedef void *(*(*StgFunPtr)(void))(void);
153 typedef StgFunPtr StgFun(void);
163 StgStackOffset offset; /* unused? */
178 typedef const StgWord* D_;
179 typedef StgFunPtr F_;
180 typedef StgByteArray B_;
181 typedef StgClosurePtr L_;
184 * We often want to know the size of something in units of an
185 * StgWord... (rounded up, of course!)
188 #define sizeofW(t) ((sizeof(t)+sizeof(W_)-1)/sizeof(W_))
191 * It's nice to be able to grep for casts
194 #define stgCast(ty,e) ((ty)(e))