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