1 /* -----------------------------------------------------------------------------
2 * $Id: StgTypes.h,v 1.18 2001/10/03 13:57:42 simonmar 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 */
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;
73 #error GHC untested on this architecture: sizeof(void *) < 8 and no long longs.
77 * Define the standard word size we'll use on this machine: make it
78 * big enough to hold a pointer.
81 #if SIZEOF_VOID_P == 8
82 typedef StgInt64 StgInt;
83 typedef StgWord64 StgWord;
85 #if SIZEOF_VOID_P == 4
86 typedef StgInt32 StgInt;
87 typedef StgWord32 StgWord;
89 #error GHC untested on this architecture: sizeof(void *) != 4 or 8
93 #define W_MASK (sizeof(W_)-1)
95 typedef void* StgAddr;
98 * Other commonly-used STG datatypes.
101 typedef StgWord32 StgChar;
104 typedef float StgFloat;
105 typedef double StgDouble;
107 typedef void StgVoid;
109 typedef struct StgClosure_ StgClosure;
110 typedef StgClosure* StgClosurePtr;
111 typedef StgWord* StgPtr; /* pointer into closure */
112 typedef StgWord StgOffset; /* byte offset within closure */
114 typedef struct StgTSO_* StgTSOPtr;
116 typedef void* StgForeignPtr;
118 typedef StgInt StgStackOffset; /* offset in words! */
120 typedef StgWord* StgStackPtr;
122 typedef StgWord8 StgCode; /* close enough */
124 typedef StgPtr* StgArray; /* the goods of an Array# */
125 typedef char* StgByteArray; /* the goods of a ByteArray# */
127 typedef void* StgStablePtr;
130 Types for the generated C functions
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
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
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.
143 typedef void *(*(*StgFunPtr)(void))(void);
144 typedef StgFunPtr StgFun(void);
155 StgStackOffset offset; /* unused? */
160 #endif /* STGTYPES_H */