ba2adb4ceab68b4223cc5212f158509413f214c8
[ghc-hetmet.git] / ghc / 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_UNSIGNED_INT == 4
52 typedef signed   int             StgInt32;
53 typedef unsigned int             StgWord32;
54 #else
55 #error GHC untested on this architecture: sizeof(unsigned int) != 4
56 #endif
57
58 #ifdef SUPPORT_LONG_LONGS
59 /* assume long long is 64 bits */
60 # ifndef _MSC_VER
61 typedef signed long long int   StgInt64;
62 typedef unsigned long long int StgWord64;
63 # else
64 typedef __int64 StgInt64;
65 typedef unsigned __int64 StgWord64;
66 # endif
67 #elif SIZEOF_LONG == 8
68 typedef signed   long          StgInt64;
69 typedef unsigned long          StgWord64;
70 #elif defined(__MSVC__)
71 typedef __int64                StgInt64;
72 typedef unsigned __int64       StgWord64;
73 #else
74 #error GHC untested on this architecture: sizeof(void *) < 8 and no long longs.
75 #endif
76
77 /*
78  * Define the standard word size we'll use on this machine: make it
79  * big enough to hold a pointer.
80  */
81
82 #if SIZEOF_VOID_P == 8
83 typedef StgInt64           StgInt;
84 typedef StgWord64          StgWord;
85 typedef StgInt32           StgHalfInt;
86 typedef StgWord32          StgHalfWord;
87 #else
88 #if SIZEOF_VOID_P == 4
89 typedef StgInt32           StgInt; 
90 typedef StgWord32          StgWord;
91 typedef StgInt16           StgHalfInt;
92 typedef StgWord16          StgHalfWord;
93 #else
94 #error GHC untested on this architecture: sizeof(void *) != 4 or 8
95 #endif
96 #endif
97
98 #define W_MASK  (sizeof(W_)-1)
99
100 typedef void*              StgAddr;
101
102 /*
103  * Other commonly-used STG datatypes.
104  */
105
106 typedef StgWord32          StgChar;
107 typedef int                StgBool;
108
109 typedef float              StgFloat;
110 typedef double             StgDouble;
111                            
112 typedef void               StgVoid;
113                            
114 typedef struct StgClosure_ StgClosure;
115 typedef StgClosure*        StgClosurePtr;
116 typedef StgWord*           StgPtr;           /* pointer into closure       */
117 typedef StgWord            StgOffset;        /* byte offset within closure */
118                            
119 typedef struct StgTSO_*    StgTSOPtr;
120
121 typedef void*              StgForeignPtr;
122
123 typedef StgInt             StgStackOffset;   /* offset in words! */
124
125 typedef StgWord*           StgStackPtr;
126
127 typedef StgWord8           StgCode;         /* close enough */
128
129 typedef StgPtr*            StgArray;        /* the goods of an Array# */
130 typedef char*              StgByteArray;    /* the goods of a ByteArray# */
131
132 typedef void*              StgStablePtr;
133
134 /*
135   Types for the generated C functions
136   take no arguments
137   return a pointer to the next function to be called
138   use: Ptr to Fun that returns a Ptr to Fun which returns Ptr to void
139
140   Note: Neither StgFunPtr not StgFun is quite right (that is, 
141   StgFunPtr != StgFun*).  So, the functions we define all have type
142   StgFun but we always have to cast them to StgFunPtr when we assign
143   them to something.
144   The only way round this would be to write a recursive type but
145   C only allows that if you're defining a struct or union.
146 */
147
148 typedef void  *(*(*StgFunPtr)(void))(void);
149 typedef StgFunPtr StgFun(void);
150
151 #endif /* STGTYPES_H */