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