1 /* -----------------------------------------------------------------------------
3 * (c) The GHC Team, 1998-2004
5 * Various C datatypes used in the run-time system. This is the
6 * lowest-level include file, after ghcconfig.h and RtsConfig.h.
8 * This module should define types *only*, all beginning with "Stg".
14 StgChar, StgFloat, StgDouble
16 ***** All the same size (i.e. sizeof(void *)): *****
17 StgPtr Basic pointer type
18 StgWord Unit of heap allocation
19 StgInt Signed version of StgWord
20 StgAddr Generic address type
22 StgBool, StgVoid, StgPtr, StgOffset,
23 StgCode, StgStablePtr, StgFunPtr,
26 * WARNING: Keep this file, MachDeps.h, and HsFFI.h in synch!
28 * NOTE: assumes #include "ghcconfig.h"
30 * Works with or without _POSIX_SOURCE.
32 * ---------------------------------------------------------------------------*/
38 * First, platform-dependent definitions of size-specific integers.
39 * Assume for now that the int type is 32 bits.
40 * NOTE: Synch the following definitions with MachDeps.h!
41 * ToDo: move these into a platform-dependent file.
44 typedef signed char StgInt8;
45 typedef unsigned char StgWord8;
47 typedef signed short StgInt16;
48 typedef unsigned short StgWord16;
51 typedef signed long StgInt32;
52 typedef unsigned long StgWord32;
54 typedef signed int StgInt32;
55 typedef unsigned int StgWord32;
57 #error GHC untested on this architecture: sizeof(int) != 4
61 typedef signed long StgInt64;
62 typedef unsigned long StgWord64;
63 #elif defined(__MSVC__)
64 typedef __int64 StgInt64;
65 typedef unsigned __int64 StgWord64;
66 #elif SIZEOF_LONG_LONG == 8
67 typedef signed long long int StgInt64;
68 typedef unsigned long long int StgWord64;
70 #error cannot find a way to define StgInt64
74 * Define the standard word size we'll use on this machine: make it
75 * big enough to hold a pointer.
77 * It's useful if StgInt/StgWord are always the same as long, so that
78 * we can use a consistent printf format specifier without warnings on
79 * any platform. Fortunately this works at the moement; if it breaks
80 * in the future we'll have to start using macros for format
81 * specifiers (c.f. FMT_StgWord64 in Rts.h).
84 #if SIZEOF_VOID_P == 8
85 typedef StgInt64 StgInt;
86 typedef StgWord64 StgWord;
87 typedef StgInt32 StgHalfInt;
88 typedef StgWord32 StgHalfWord;
90 #if SIZEOF_VOID_P == 4
91 typedef StgInt32 StgInt;
92 typedef StgWord32 StgWord;
93 typedef StgInt16 StgHalfInt;
94 typedef StgWord16 StgHalfWord;
96 #error GHC untested on this architecture: sizeof(void *) != 4 or 8
100 #define W_MASK (sizeof(W_)-1)
103 * Other commonly-used STG datatypes.
106 typedef void* StgAddr;
107 typedef StgWord32 StgChar;
109 typedef float StgFloat;
110 typedef double StgDouble;
111 typedef StgWord* StgPtr; /* heap or stack pointer */
112 typedef StgWord volatile* StgVolatilePtr; /* pointer to volatile word */
113 typedef StgWord StgOffset; /* byte offset within closure */
114 typedef StgWord8 StgCode; /* close enough */
115 typedef void* StgStablePtr;
116 typedef StgWord8* StgByteArray;
119 Types for the generated C functions
121 return a pointer to the next function to be called
122 use: Ptr to Fun that returns a Ptr to Fun which returns Ptr to void
124 Note: Neither StgFunPtr not StgFun is quite right (that is,
125 StgFunPtr != StgFun*). So, the functions we define all have type
126 StgFun but we always have to cast them to StgFunPtr when we assign
128 The only way round this would be to write a recursive type but
129 C only allows that if you're defining a struct or union.
132 typedef void *(*(*StgFunPtr)(void))(void);
133 typedef StgFunPtr StgFun(void);
135 #endif /* STGTYPES_H */