[project @ 1998-12-02 13:17:09 by simonm]
[ghc-hetmet.git] / ghc / includes / StgTypes.h
1 /* -----------------------------------------------------------------------------
2  * $Id: StgTypes.h,v 1.2 1998/12/02 13:21:41 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 StgWord            StgStablePtr;
113 typedef void *             StgForeignPtr;
114
115 typedef StgInt             StgStackOffset;   /* offset in words! */
116
117 typedef StgWord*           StgStackPtr;
118
119 typedef StgNat8            StgCode;         /* close enough */
120 typedef StgCode*           StgCodePtr;  
121
122 typedef StgPtr*            StgArray;        /* the goods of an Array# */
123 typedef char*              StgByteArray;    /* the goods of a ByteArray# */
124
125 typedef StgInt64               LI_;
126 typedef StgNat64               LW_;
127
128 /*
129   Types for the generated C functions
130   take no arguments
131   return a pointer to the next function to be called
132   use: Ptr to Fun that returns a Ptr to Fun which returns Ptr to void
133
134   Note: Neither StgFunPtr not StgFun is quite right (that is, 
135   StgFunPtr != StgFun*).  So, the functions we define all have type
136   StgFun but we always have to cast them to StgFunPtr when we assign
137   them to something.
138   The only way round this would be to write a recursive type but
139   C only allows that if you're defining a struct or union.
140 */
141
142 typedef void  *(*(*StgFunPtr)(void))(void);
143 typedef StgFunPtr StgFun(void);
144
145 typedef union {
146     StgWord        w;
147     StgAddr        a;
148     StgChar        c;
149     StgFloat       f;
150     StgInt         i;
151     StgPtr         p;
152     StgClosurePtr  cl;
153     StgStackOffset offset;      /* unused? */
154     StgByteArray   b;
155     StgTSOPtr      t;
156 } StgUnion;
157
158 /*
159  * Shorthand forms
160  */
161
162 typedef StgChar         C_;
163 typedef StgWord         W_;
164 typedef StgWord*        P_;
165 typedef P_*             PP_;
166 typedef StgInt          I_;
167 typedef StgAddr         A_;
168 typedef const StgWord*  D_;
169 typedef StgFunPtr       F_;
170 typedef StgByteArray    B_;
171 typedef StgClosurePtr   L_;
172
173 /*
174  * We often want to know the size of something in units of an
175  * StgWord... (rounded up, of course!)
176  */
177
178 #define sizeofW(t) ((sizeof(t)+sizeof(W_)-1)/sizeof(W_))
179
180 /* 
181  * It's nice to be able to grep for casts
182  */
183
184 #define stgCast(ty,e) ((ty)(e))
185
186 #endif STGTYPES_H
187