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