c0675215573e9bc43be67da87aefa42fd566f732
[ghc-hetmet.git] / ghc / includes / StgTypes.h
1 /* -----------------------------------------------------------------------------
2  * $Id: StgTypes.h,v 1.3 1999/01/26 11:12:58 simonm Exp $
3  *
4  * Various C datatypes used in the run-time system.
5
6  * Specifically:
7
8         StgInt8, 16, 32, 64
9         StgNat8, 16, 32, 64
10         StgChar, StgFloat, StgDouble
11
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
17         
18
19  *
20  * ---------------------------------------------------------------------------*/
21
22 #ifndef STGTYPES_H
23 #define STGTYPES_H
24
25 /*
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.
29  */
30
31 typedef signed   char            StgInt8;
32 typedef unsigned char            StgNat8;
33
34 typedef signed   short           StgInt16;
35 typedef unsigned short           StgNat16;
36
37
38 #if SIZEOF_UNSIGNED_INT == 4
39 typedef signed   int             StgInt32;
40 typedef unsigned int             StgNat32;
41 #else
42 #error GHC untested on this architecture: sizeof(unisgned int) != 4
43 #endif
44
45 /* This #define controls whether we need to support long longs on a particular
46  * platform. 
47  *
48  * ToDo: find a proper home for (derived) configuration information like this.
49  */
50 #if HAVE_LONG_LONG && SIZEOF_VOID_P < 8
51 #define SUPPORT_LONG_LONGS
52 #endif
53
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;
61 #else
62 #error GHC untested on this architecture: sizeof(void *) < 8 and no long longs.
63 #endif
64
65
66 /*
67  * Define the standard word size we'll use on this machine: make it
68  * big enough to hold a pointer.
69  */
70
71 #if SIZEOF_VOID_P == 8
72 typedef StgInt64           StgInt;
73 typedef StgNat64           StgWord;
74 #else
75 #if SIZEOF_VOID_P == 4
76 typedef StgInt32           StgInt; 
77 typedef StgNat32           StgWord;
78 #else
79 #error GHC untested on this architecture: sizeof(void *) != 4 or 8
80 #endif
81 #endif
82
83 typedef void*              StgAddr;
84
85 /*
86  * Other commonly-used STG datatypes.
87  */
88
89 typedef StgNat8            StgChar;
90
91 /*
92  * If a double fits in an StgWord, don't bother using floats.
93  */
94
95 #if SIZEOF_DOUBLE == SIZEOF_VOID_P
96 typedef double             StgFloat;
97 typedef double             StgDouble;
98 #define FLOATS_AS_DOUBLES  1
99 #else
100 typedef float              StgFloat;
101 typedef double             StgDouble;
102 #endif
103                            
104 typedef void               StgVoid;
105                            
106 typedef struct StgClosure_* StgClosurePtr;
107 typedef StgWord*           StgPtr;           /* pointer into closure       */
108 typedef StgWord            StgOffset;        /* byte offset within closure */
109                            
110 typedef struct StgTSO_*    StgTSOPtr;
111
112 typedef void *             StgForeignPtr;
113
114 typedef StgInt             StgStackOffset;   /* offset in words! */
115
116 typedef StgWord*           StgStackPtr;
117
118 typedef StgNat8            StgCode;         /* close enough */
119 typedef StgCode*           StgCodePtr;  
120
121 typedef StgPtr*            StgArray;        /* the goods of an Array# */
122 typedef char*              StgByteArray;    /* the goods of a ByteArray# */
123
124 typedef StgInt64               LI_;
125 typedef StgNat64               LW_;
126
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
129  * upper 8 bits.
130  */
131 typedef StgWord            StgStablePtr;
132
133 #define STABLEPTR_WEIGHT_MASK   (0xff << ((sizeof(StgWord)-1) * BITS_PER_BYTE))
134 #define STABLEPTR_WEIGHT_SHIFT  (BITS_IN(StgWord) - 8)
135
136 /*
137   Types for the generated C functions
138   take no arguments
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
141
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
145   them to something.
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.
148 */
149
150 typedef void  *(*(*StgFunPtr)(void))(void);
151 typedef StgFunPtr StgFun(void);
152
153 typedef union {
154     StgWord        w;
155     StgAddr        a;
156     StgChar        c;
157     StgFloat       f;
158     StgInt         i;
159     StgPtr         p;
160     StgClosurePtr  cl;
161     StgStackOffset offset;      /* unused? */
162     StgByteArray   b;
163     StgTSOPtr      t;
164 } StgUnion;
165
166 /*
167  * Shorthand forms
168  */
169
170 typedef StgChar         C_;
171 typedef StgWord         W_;
172 typedef StgWord*        P_;
173 typedef P_*             PP_;
174 typedef StgInt          I_;
175 typedef StgAddr         A_;
176 typedef const StgWord*  D_;
177 typedef StgFunPtr       F_;
178 typedef StgByteArray    B_;
179 typedef StgClosurePtr   L_;
180
181 /*
182  * We often want to know the size of something in units of an
183  * StgWord... (rounded up, of course!)
184  */
185
186 #define sizeofW(t) ((sizeof(t)+sizeof(W_)-1)/sizeof(W_))
187
188 /* 
189  * It's nice to be able to grep for casts
190  */
191
192 #define stgCast(ty,e) ((ty)(e))
193
194 #endif STGTYPES_H
195