[project @ 2002-12-05 23:49:43 by mthomas]
[ghc-hetmet.git] / ghc / includes / StgTypes.h
1 /* -----------------------------------------------------------------------------
2  * $Id: StgTypes.h,v 1.18 2001/10/03 13:57:42 simonmar 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 typedef signed long long int   StgInt64;
65 typedef unsigned long long int StgWord64;
66 #elif SIZEOF_LONG == 8
67 typedef signed   long          StgInt64;
68 typedef unsigned long          StgWord64;
69 #elif defined(__MSVC__)
70 typedef __int64                StgInt64;
71 typedef unsigned __int64       StgWord64;
72 #else
73 #error GHC untested on this architecture: sizeof(void *) < 8 and no long longs.
74 #endif
75
76 /*
77  * Define the standard word size we'll use on this machine: make it
78  * big enough to hold a pointer.
79  */
80
81 #if SIZEOF_VOID_P == 8
82 typedef StgInt64           StgInt;
83 typedef StgWord64          StgWord;
84 #else
85 #if SIZEOF_VOID_P == 4
86 typedef StgInt32           StgInt; 
87 typedef StgWord32          StgWord;
88 #else
89 #error GHC untested on this architecture: sizeof(void *) != 4 or 8
90 #endif
91 #endif
92
93 #define W_MASK  (sizeof(W_)-1)
94
95 typedef void*              StgAddr;
96
97 /*
98  * Other commonly-used STG datatypes.
99  */
100
101 typedef StgWord32          StgChar;
102 typedef int                StgBool;
103
104 typedef float              StgFloat;
105 typedef double             StgDouble;
106                            
107 typedef void               StgVoid;
108                            
109 typedef struct StgClosure_ StgClosure;
110 typedef StgClosure*        StgClosurePtr;
111 typedef StgWord*           StgPtr;           /* pointer into closure       */
112 typedef StgWord            StgOffset;        /* byte offset within closure */
113                            
114 typedef struct StgTSO_*    StgTSOPtr;
115
116 typedef void*              StgForeignPtr;
117
118 typedef StgInt             StgStackOffset;   /* offset in words! */
119
120 typedef StgWord*           StgStackPtr;
121
122 typedef StgWord8           StgCode;         /* close enough */
123
124 typedef StgPtr*            StgArray;        /* the goods of an Array# */
125 typedef char*              StgByteArray;    /* the goods of a ByteArray# */
126
127 typedef void*              StgStablePtr;
128
129 /*
130   Types for the generated C functions
131   take no arguments
132   return a pointer to the next function to be called
133   use: Ptr to Fun that returns a Ptr to Fun which returns Ptr to void
134
135   Note: Neither StgFunPtr not StgFun is quite right (that is, 
136   StgFunPtr != StgFun*).  So, the functions we define all have type
137   StgFun but we always have to cast them to StgFunPtr when we assign
138   them to something.
139   The only way round this would be to write a recursive type but
140   C only allows that if you're defining a struct or union.
141 */
142
143 typedef void  *(*(*StgFunPtr)(void))(void);
144 typedef StgFunPtr StgFun(void);
145
146 typedef union {
147     StgWord        w;
148     StgAddr        a;
149     StgChar        c;
150     StgInt8        i8;
151     StgFloat       f;
152     StgInt         i;
153     StgPtr         p;
154     StgClosurePtr  cl;
155     StgStackOffset offset;      /* unused? */
156     StgByteArray   b;
157     StgTSOPtr      t;
158 } StgUnion;
159
160 #endif /* STGTYPES_H */