1 /* -----------------------------------------------------------------------------
2 * $Id: StgTypes.h,v 1.19 2002/12/11 15:36:39 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;
84 typedef StgWord32 StgHalfWord;
86 #if SIZEOF_VOID_P == 4
87 typedef StgInt32 StgInt;
88 typedef StgWord32 StgWord;
89 typedef StgWord16 StgHalfWord;
91 #error GHC untested on this architecture: sizeof(void *) != 4 or 8
95 #define W_MASK (sizeof(W_)-1)
97 typedef void* StgAddr;
100 * Other commonly-used STG datatypes.
103 typedef StgWord32 StgChar;
106 typedef float StgFloat;
107 typedef double StgDouble;
109 typedef void StgVoid;
111 typedef struct StgClosure_ StgClosure;
112 typedef StgClosure* StgClosurePtr;
113 typedef StgWord* StgPtr; /* pointer into closure */
114 typedef StgWord StgOffset; /* byte offset within closure */
116 typedef struct StgTSO_* StgTSOPtr;
118 typedef void* StgForeignPtr;
120 typedef StgInt StgStackOffset; /* offset in words! */
122 typedef StgWord* StgStackPtr;
124 typedef StgWord8 StgCode; /* close enough */
126 typedef StgPtr* StgArray; /* the goods of an Array# */
127 typedef char* StgByteArray; /* the goods of a ByteArray# */
129 typedef void* StgStablePtr;
132 Types for the generated C functions
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
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
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.
145 typedef void *(*(*StgFunPtr)(void))(void);
146 typedef StgFunPtr StgFun(void);
157 StgStackOffset offset; /* unused? */
162 #endif /* STGTYPES_H */