[project @ 2000-11-07 17:05:47 by simonmar]
[ghc-hetmet.git] / ghc / includes / StgTypes.h
1 /* -----------------------------------------------------------------------------
2  * $Id: StgTypes.h,v 1.15 2000/11/07 17:05:47 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).
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 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 /*
40  * First, platform-dependent definitions of size-specific integers.
41  * Assume for now that the int type is 32 bits.
42  * NOTE: Synch the following definitions with MachDeps.h!
43  * ToDo: move these into a platform-dependent file.
44  */
45
46 typedef signed   char            StgInt8;
47 typedef unsigned char            StgWord8;
48
49 typedef signed   short           StgInt16;
50 typedef unsigned short           StgWord16;
51
52
53 #if SIZEOF_UNSIGNED_INT == 4
54 typedef signed   int             StgInt32;
55 typedef unsigned int             StgWord32;
56 #else
57 #error GHC untested on this architecture: sizeof(unsigned int) != 4
58 #endif
59
60 /* This #define controls whether we need to support long longs on a particular
61  * platform. 
62  *
63  * ToDo: find a proper home for (derived) configuration information like this.
64  */
65 #if HAVE_LONG_LONG && SIZEOF_VOID_P < 8
66 #define SUPPORT_LONG_LONGS
67 #endif
68
69 #ifdef SUPPORT_LONG_LONGS
70 /* assume long long is 64 bits */
71 typedef signed long long int   StgInt64;
72 typedef unsigned long long int StgWord64;
73 #elif SIZEOF_LONG == 8
74 typedef signed   long          StgInt64;
75 typedef unsigned long          StgWord64;
76 #elif defined(__MSVC__)
77 typedef __int64                StgInt64;
78 typedef unsigned __int64       StgWord64;
79 #else
80 #error GHC untested on this architecture: sizeof(void *) < 8 and no long longs.
81 #endif
82
83 /*
84  * Define the standard word size we'll use on this machine: make it
85  * big enough to hold a pointer.
86  */
87
88 #if SIZEOF_VOID_P == 8
89 typedef StgInt64           StgInt;
90 typedef StgWord64          StgWord;
91 #else
92 #if SIZEOF_VOID_P == 4
93 typedef StgInt32           StgInt; 
94 typedef StgWord32          StgWord;
95 #else
96 #error GHC untested on this architecture: sizeof(void *) != 4 or 8
97 #endif
98 #endif
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 typedef union {
152     StgWord        w;
153     StgAddr        a;
154     StgChar        c;
155     StgInt8        i8;
156     StgFloat       f;
157     StgInt         i;
158     StgPtr         p;
159     StgClosurePtr  cl;
160     StgStackOffset offset;      /* unused? */
161     StgByteArray   b;
162     StgTSOPtr      t;
163 } StgUnion;
164
165 #endif /* STGTYPES_H */