1 /* -----------------------------------------------------------------------------
2 * $Id: StgTypes.h,v 1.20 2003/11/12 17:27:05 sof Exp $
4 * (c) The GHC Team, 1998-2000
6 * Various C datatypes used in the run-time system. This is the
7 * lowest-level include file, after config.h and Derived.h.
9 * This module should define types *only*, all beginning with "Stg".
15 StgChar, StgFloat, StgDouble
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
23 StgBool, StgVoid, StgClosurePtr, StgPtr, StgOffset,
24 StgTSOPtr, StgForeignPtr, StgStackOffset, StgStackPtr,
25 StgCode, StgArray, StgByteArray, StgStablePtr, StgFunPtr,
28 * WARNING: Keep this file, MachDeps.h, and HsFFI.h in synch!
30 * NOTE: assumes #include "config.h"
32 * Works with or without _POSIX_SOURCE.
34 * ---------------------------------------------------------------------------*/
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.
48 typedef signed char StgInt8;
49 typedef unsigned char StgWord8;
51 typedef signed short StgInt16;
52 typedef unsigned short StgWord16;
55 #if SIZEOF_UNSIGNED_INT == 4
56 typedef signed int StgInt32;
57 typedef unsigned int StgWord32;
59 #error GHC untested on this architecture: sizeof(unsigned int) != 4
62 #ifdef SUPPORT_LONG_LONGS
63 /* assume long long is 64 bits */
65 typedef signed long long int StgInt64;
66 typedef unsigned long long int StgWord64;
68 typedef __int64 StgInt64;
69 typedef unsigned __int64 StgWord64;
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;
78 #error GHC untested on this architecture: sizeof(void *) < 8 and no long longs.
82 * Define the standard word size we'll use on this machine: make it
83 * big enough to hold a pointer.
86 #if SIZEOF_VOID_P == 8
87 typedef StgInt64 StgInt;
88 typedef StgWord64 StgWord;
89 typedef StgWord32 StgHalfWord;
91 #if SIZEOF_VOID_P == 4
92 typedef StgInt32 StgInt;
93 typedef StgWord32 StgWord;
94 typedef StgWord16 StgHalfWord;
96 #error GHC untested on this architecture: sizeof(void *) != 4 or 8
100 #define W_MASK (sizeof(W_)-1)
102 typedef void* StgAddr;
105 * Other commonly-used STG datatypes.
108 typedef StgWord32 StgChar;
111 typedef float StgFloat;
112 typedef double StgDouble;
114 typedef void StgVoid;
116 typedef struct StgClosure_ StgClosure;
117 typedef StgClosure* StgClosurePtr;
118 typedef StgWord* StgPtr; /* pointer into closure */
119 typedef StgWord StgOffset; /* byte offset within closure */
121 typedef struct StgTSO_* StgTSOPtr;
123 typedef void* StgForeignPtr;
125 typedef StgInt StgStackOffset; /* offset in words! */
127 typedef StgWord* StgStackPtr;
129 typedef StgWord8 StgCode; /* close enough */
131 typedef StgPtr* StgArray; /* the goods of an Array# */
132 typedef char* StgByteArray; /* the goods of a ByteArray# */
134 typedef void* StgStablePtr;
137 Types for the generated C functions
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
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
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.
150 typedef void *(*(*StgFunPtr)(void))(void);
151 typedef StgFunPtr StgFun(void);
162 StgStackOffset offset; /* unused? */
167 #endif /* STGTYPES_H */