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