Adding TcGadt.lhs
[ghc-hetmet.git] / includes / StgTypes.h
1 /* -----------------------------------------------------------------------------
2  *
3  * (c) The GHC Team, 1998-2004
4  *
5  * Various C datatypes used in the run-time system.  This is the
6  * lowest-level include file, after ghcconfig.h and RtsConfig.h.
7  *
8  * This module should define types *only*, all beginning with "Stg".
9  *
10  * Specifically:
11
12         StgInt8,  16, 32, 64
13         StgWord8, 16, 32, 64
14         StgChar, StgFloat, StgDouble
15
16         ***** All the same size (i.e. sizeof(void *)): *****
17         StgPtr                  Basic pointer type
18         StgWord                 Unit of heap allocation
19         StgInt                  Signed version of StgWord
20         StgAddr                 Generic address type
21         
22         StgBool, StgVoid, StgClosurePtr, StgPtr, StgOffset, 
23         StgTSOPtr, StgForeignPtr, StgStackOffset, StgStackPtr,
24         StgCode, StgArray, StgByteArray, StgStablePtr, StgFunPtr,
25         StgUnion.
26
27  * WARNING: Keep this file, MachDeps.h, and HsFFI.h in synch!
28  *
29  * NOTE: assumes #include "ghcconfig.h"
30  * 
31  * Works with or without _POSIX_SOURCE.
32  *
33  * ---------------------------------------------------------------------------*/
34
35 #ifndef STGTYPES_H
36 #define STGTYPES_H
37
38 /*
39  * First, platform-dependent definitions of size-specific integers.
40  * Assume for now that the int type is 32 bits.
41  * NOTE: Synch the following definitions with MachDeps.h!
42  * ToDo: move these into a platform-dependent file.
43  */
44
45 typedef signed   char            StgInt8;
46 typedef unsigned char            StgWord8;
47
48 typedef signed   short           StgInt16;
49 typedef unsigned short           StgWord16;
50
51 #if SIZEOF_LONG == 4
52 typedef signed   long            StgInt32;
53 typedef unsigned long            StgWord32;
54 #elif SIZEOF_INT == 4
55 typedef signed   int             StgInt32;
56 typedef unsigned int             StgWord32;
57 #else
58 #error GHC untested on this architecture: sizeof(int) != 4
59 #endif
60
61 #ifdef SUPPORT_LONG_LONGS
62 /* assume long long is 64 bits */
63 # ifndef _MSC_VER
64 typedef signed long long int   StgInt64;
65 typedef unsigned long long int StgWord64;
66 # else
67 typedef __int64 StgInt64;
68 typedef unsigned __int64 StgWord64;
69 # endif
70 #elif SIZEOF_LONG == 8
71 typedef signed   long          StgInt64;
72 typedef unsigned long          StgWord64;
73 #elif defined(__MSVC__)
74 typedef __int64                StgInt64;
75 typedef unsigned __int64       StgWord64;
76 #else
77 #error GHC untested on this architecture: sizeof(void *) < 8 and no long longs.
78 #endif
79
80 /*
81  * Define the standard word size we'll use on this machine: make it
82  * big enough to hold a pointer.
83  *
84  * It's useful if StgInt/StgWord are always the same as long, so that
85  * we can use a consistent printf format specifier without warnings on
86  * any platform.  Fortunately this works at the moement; if it breaks
87  * in the future we'll have to start using macros for format
88  * specifiers (c.f. FMT_StgWord64 in Rts.h).
89  */
90
91 #if SIZEOF_VOID_P == 8
92 typedef StgInt64           StgInt;
93 typedef StgWord64          StgWord;
94 typedef StgInt32           StgHalfInt;
95 typedef StgWord32          StgHalfWord;
96 #else
97 #if SIZEOF_VOID_P == 4
98 typedef StgInt32           StgInt; 
99 typedef StgWord32          StgWord;
100 typedef StgInt16           StgHalfInt;
101 typedef StgWord16          StgHalfWord;
102 #else
103 #error GHC untested on this architecture: sizeof(void *) != 4 or 8
104 #endif
105 #endif
106
107 #define W_MASK  (sizeof(W_)-1)
108
109 typedef void*              StgAddr;
110
111 /*
112  * Other commonly-used STG datatypes.
113  */
114
115 typedef StgWord32          StgChar;
116 typedef int                StgBool;
117
118 typedef float              StgFloat;
119 typedef double             StgDouble;
120                            
121 typedef void               StgVoid;
122                            
123 typedef struct StgClosure_ StgClosure;
124 typedef StgClosure*        StgClosurePtr;
125 typedef StgWord*           StgPtr;           /* pointer into closure       */
126 typedef StgWord volatile*  StgVolatilePtr;   /* pointer to volatile word   */
127 typedef StgWord            StgOffset;        /* byte offset within closure */
128                            
129 typedef struct StgTSO_*    StgTSOPtr;
130
131 typedef void*              StgForeignPtr;
132
133 typedef StgInt             StgStackOffset;   /* offset in words! */
134
135 typedef StgWord*           StgStackPtr;
136
137 typedef StgWord8           StgCode;         /* close enough */
138
139 typedef StgPtr*            StgArray;        /* the goods of an Array# */
140 typedef char*              StgByteArray;    /* the goods of a ByteArray# */
141
142 typedef void*              StgStablePtr;
143
144 /*
145   Types for the generated C functions
146   take no arguments
147   return a pointer to the next function to be called
148   use: Ptr to Fun that returns a Ptr to Fun which returns Ptr to void
149
150   Note: Neither StgFunPtr not StgFun is quite right (that is, 
151   StgFunPtr != StgFun*).  So, the functions we define all have type
152   StgFun but we always have to cast them to StgFunPtr when we assign
153   them to something.
154   The only way round this would be to write a recursive type but
155   C only allows that if you're defining a struct or union.
156 */
157
158 typedef void  *(*(*StgFunPtr)(void))(void);
159 typedef StgFunPtr StgFun(void);
160
161 #endif /* STGTYPES_H */