1 /* -----------------------------------------------------------------------------
2 * $Id: StgTypes.h,v 1.15 2000/11/07 17:05:47 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).
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 and HsFFI.h in synch!
30 * NOTE: assumes #include "config.h"
32 * Works with or without _POSIX_SOURCE.
34 * ---------------------------------------------------------------------------*/
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.
46 typedef signed char StgInt8;
47 typedef unsigned char StgWord8;
49 typedef signed short StgInt16;
50 typedef unsigned short StgWord16;
53 #if SIZEOF_UNSIGNED_INT == 4
54 typedef signed int StgInt32;
55 typedef unsigned int StgWord32;
57 #error GHC untested on this architecture: sizeof(unsigned int) != 4
60 /* This #define controls whether we need to support long longs on a particular
63 * ToDo: find a proper home for (derived) configuration information like this.
65 #if HAVE_LONG_LONG && SIZEOF_VOID_P < 8
66 #define SUPPORT_LONG_LONGS
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;
80 #error GHC untested on this architecture: sizeof(void *) < 8 and no long longs.
84 * Define the standard word size we'll use on this machine: make it
85 * big enough to hold a pointer.
88 #if SIZEOF_VOID_P == 8
89 typedef StgInt64 StgInt;
90 typedef StgWord64 StgWord;
92 #if SIZEOF_VOID_P == 4
93 typedef StgInt32 StgInt;
94 typedef StgWord32 StgWord;
96 #error GHC untested on this architecture: sizeof(void *) != 4 or 8
100 typedef void* StgAddr;
103 * Other commonly-used STG datatypes.
106 typedef StgWord32 StgChar;
109 typedef float StgFloat;
110 typedef double StgDouble;
112 typedef void StgVoid;
114 typedef struct StgClosure_ StgClosure;
115 typedef StgClosure* StgClosurePtr;
116 typedef StgWord* StgPtr; /* pointer into closure */
117 typedef StgWord StgOffset; /* byte offset within closure */
119 typedef struct StgTSO_* StgTSOPtr;
121 typedef void* StgForeignPtr;
123 typedef StgInt StgStackOffset; /* offset in words! */
125 typedef StgWord* StgStackPtr;
127 typedef StgWord8 StgCode; /* close enough */
129 typedef StgPtr* StgArray; /* the goods of an Array# */
130 typedef char* StgByteArray; /* the goods of a ByteArray# */
132 typedef void* StgStablePtr;
135 Types for the generated C functions
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
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
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.
148 typedef void *(*(*StgFunPtr)(void))(void);
149 typedef StgFunPtr StgFun(void);
160 StgStackOffset offset; /* unused? */
165 #endif /* STGTYPES_H */