[project @ 2003-08-05 14:01:34 by simonpj]
[ghc-hetmet.git] / ghc / includes / StgTypes.h
1 /* -----------------------------------------------------------------------------
2  * $Id: StgTypes.h,v 1.19 2002/12/11 15:36:39 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 typedef StgWord32          StgHalfWord;
85 #else
86 #if SIZEOF_VOID_P == 4
87 typedef StgInt32           StgInt; 
88 typedef StgWord32          StgWord;
89 typedef StgWord16          StgHalfWord;
90 #else
91 #error GHC untested on this architecture: sizeof(void *) != 4 or 8
92 #endif
93 #endif
94
95 #define W_MASK  (sizeof(W_)-1)
96
97 typedef void*              StgAddr;
98
99 /*
100  * Other commonly-used STG datatypes.
101  */
102
103 typedef StgWord32          StgChar;
104 typedef int                StgBool;
105
106 typedef float              StgFloat;
107 typedef double             StgDouble;
108                            
109 typedef void               StgVoid;
110                            
111 typedef struct StgClosure_ StgClosure;
112 typedef StgClosure*        StgClosurePtr;
113 typedef StgWord*           StgPtr;           /* pointer into closure       */
114 typedef StgWord            StgOffset;        /* byte offset within closure */
115                            
116 typedef struct StgTSO_*    StgTSOPtr;
117
118 typedef void*              StgForeignPtr;
119
120 typedef StgInt             StgStackOffset;   /* offset in words! */
121
122 typedef StgWord*           StgStackPtr;
123
124 typedef StgWord8           StgCode;         /* close enough */
125
126 typedef StgPtr*            StgArray;        /* the goods of an Array# */
127 typedef char*              StgByteArray;    /* the goods of a ByteArray# */
128
129 typedef void*              StgStablePtr;
130
131 /*
132   Types for the generated C functions
133   take no arguments
134   return a pointer to the next function to be called
135   use: Ptr to Fun that returns a Ptr to Fun which returns Ptr to void
136
137   Note: Neither StgFunPtr not StgFun is quite right (that is, 
138   StgFunPtr != StgFun*).  So, the functions we define all have type
139   StgFun but we always have to cast them to StgFunPtr when we assign
140   them to something.
141   The only way round this would be to write a recursive type but
142   C only allows that if you're defining a struct or union.
143 */
144
145 typedef void  *(*(*StgFunPtr)(void))(void);
146 typedef StgFunPtr StgFun(void);
147
148 typedef union {
149     StgWord        w;
150     StgAddr        a;
151     StgChar        c;
152     StgInt8        i8;
153     StgFloat       f;
154     StgInt         i;
155     StgPtr         p;
156     StgClosurePtr  cl;
157     StgStackOffset offset;      /* unused? */
158     StgByteArray   b;
159     StgTSOPtr      t;
160 } StgUnion;
161
162 #endif /* STGTYPES_H */