Merge non-moving garbage collector
[ghc.git] / includes / stg / Types.h
1 /* -----------------------------------------------------------------------------
2 *
3 * (c) The GHC Team, 1998-2004
4 *
5 * Various C datatypes used in the run-time system. This is the
6 * lowest-level include file, after ghcconfig.h and RtsConfig.h.
7 *
8 * Do not #include this file directly: #include "Rts.h" instead.
9 *
10 * To understand the structure of the RTS headers, see the wiki:
11 * https://gitlab.haskell.org/ghc/ghc/wikis/commentary/source-tree/includes
12 *
13 * NOTE: assumes #include "ghcconfig.h"
14 *
15 * Works with or without _POSIX_SOURCE.
16 *
17 * WARNING: Keep this file, MachDeps.h, and HsFFI.h in synch!
18 *
19 * ---------------------------------------------------------------------------*/
20
21 #pragma once
22
23 #if defined(mingw32_HOST_OS)
24 # if defined(__USE_MINGW_ANSI_STDIO)
25 # if __USE_MINGW_ANSI_STDIO != 1
26 # warning "Mismatch between __USE_MINGW_ANSI_STDIO definitions. \
27 If using Rts.h make sure it is the first header included."
28 # endif
29 # else
30 /* Inform mingw we want the ISO rather than Windows printf format specifiers. */
31 # define __USE_MINGW_ANSI_STDIO 1
32 #endif
33 #endif
34
35 /* ISO C 99 says:
36 * "C++ implementations should define these macros only when
37 * __STDC_LIMIT_MACROS is defined before <stdint.h> is included."
38 *
39 * So we need to define it for now to compile with C++ compilers.
40 * However, C++11 does not require it anymore so we can remove this once we
41 * upgrade to requiring C++11 or newer.
42 */
43 #define __STDC_LIMIT_MACROS
44 #include <inttypes.h>
45
46
47 /*
48 * This module should define types *only*, all beginning with "Stg".
49 *
50 * Specifically:
51
52 StgInt8, 16, 32, 64
53 StgWord8, 16, 32, 64
54 StgChar, StgFloat, StgDouble
55
56 ***** All the same size (i.e. sizeof(void *)): *****
57 StgPtr Basic pointer type
58 StgWord Unit of heap allocation
59 StgInt Signed version of StgWord
60 StgAddr Generic address type
61
62 StgBool, StgVoid, StgPtr, StgOffset,
63 StgCode, StgStablePtr, StgFunPtr,
64 StgUnion.
65 */
66
67 /*
68 * First, platform-dependent definitions of size-specific integers.
69 */
70
71 typedef int8_t StgInt8;
72 typedef uint8_t StgWord8;
73
74 #define STG_INT8_MIN INT8_MIN
75 #define STG_INT8_MAX INT8_MAX
76 #define STG_WORD8_MAX UINT8_MAX
77
78 #define FMT_Word8 PRIu8
79
80 typedef int16_t StgInt16;
81 typedef uint16_t StgWord16;
82
83 #define STG_INT16_MIN INT16_MIN
84 #define STG_INT16_MAX INT16_MAX
85 #define STG_WORD16_MAX UINT16_MAX
86
87 #define FMT_Word16 PRIu16
88
89 typedef int32_t StgInt32;
90 typedef uint32_t StgWord32;
91
92 #define STG_INT32_MIN INT32_MIN
93 #define STG_INT32_MAX INT32_MAX
94 #define STG_WORD32_MAX UINT32_MAX
95
96 #define FMT_Word32 PRIu32
97 #define FMT_HexWord32 PRIx32
98 #define FMT_Int32 PRId32
99
100 typedef int64_t StgInt64;
101 typedef uint64_t StgWord64;
102
103 #define STG_INT64_MIN INT64_MIN
104 #define STG_INT64_MAX INT64_MAX
105 #define STG_WORD64_MAX UINT64_MAX
106
107 #define FMT_Word64 PRIu64
108 #define FMT_HexWord64 PRIx64
109 #define FMT_Int64 PRId64
110
111 typedef struct { StgWord64 h; StgWord64 l; } StgWord128;
112
113 typedef struct { StgWord128 h; StgWord128 l; } StgWord256;
114
115 typedef struct { StgWord256 h; StgWord256 l; } StgWord512;
116
117 /*
118 * Stg{Int,Word} are defined such that they have the exact same size as a
119 * void pointer.
120 */
121
122 #if SIZEOF_VOID_P == 8
123 typedef int64_t StgInt;
124 typedef uint64_t StgWord;
125
126 typedef int32_t StgHalfInt;
127 typedef uint32_t StgHalfWord;
128
129 #define STG_INT_MIN INT64_MIN
130 #define STG_INT_MAX INT64_MAX
131 #define STG_WORD_MAX UINT64_MAX
132
133 #define FMT_Word FMT_Word64
134 #define FMT_HexWord FMT_HexWord64
135 #define FMT_Int FMT_Int64
136
137 #define strToStgWord strtoull
138
139 #elif SIZEOF_VOID_P == 4
140 typedef int32_t StgInt;
141 typedef uint32_t StgWord;
142
143 typedef int16_t StgHalfInt;
144 typedef uint16_t StgHalfWord;
145
146 #define STG_INT_MIN INT32_MIN
147 #define STG_INT_MAX INT32_MAX
148 #define STG_WORD_MAX UINT32_MAX
149
150 #define FMT_Word FMT_Word32
151 #define FMT_HexWord FMT_HexWord32
152 #define FMT_Int FMT_Int32
153
154 #define strToStgWord strtoul
155
156 #else
157 #error GHC untested on this architecture: sizeof(void *) != 4 or 8
158 #endif
159
160 #define W_MASK (sizeof(W_)-1)
161
162 /*
163 * Other commonly-used STG datatypes.
164 */
165
166 typedef void* StgAddr;
167 typedef StgWord32 StgChar;
168 typedef int StgBool;
169 typedef float StgFloat;
170 typedef double StgDouble;
171 typedef StgWord* StgPtr; /* heap or stack pointer */
172 typedef StgWord volatile* StgVolatilePtr; /* pointer to volatile word */
173 typedef StgWord StgOffset; /* byte offset within closure */
174 typedef StgWord8 StgCode; /* close enough */
175 typedef void* StgStablePtr;
176 typedef StgWord8* StgByteArray;
177
178 /*
179 Types for generated C functions when compiling via C.
180
181 The C functions take no arguments, and return a pointer to the next
182 function to be called use: Ptr to Fun that returns a Ptr to Fun
183 which returns Ptr to void
184
185 Note: Neither StgFunPtr not StgFun is quite right (that is,
186 StgFunPtr != StgFun*). So, the functions we define all have type
187 StgFun but we always have to cast them to StgFunPtr when we assign
188 them to something.
189 The only way round this would be to write a recursive type but
190 C only allows that if you're defining a struct or union.
191 */
192
193 typedef void *(*(*StgFunPtr)(void))(void);
194 typedef StgFunPtr StgFun(void);
195
196 // Forward declarations for the unregisterised backend, which
197 // only depends upon Stg.h and not the entirety of Rts.h, which
198 // is where these are defined.
199 struct StgClosure_;
200 struct StgThunk_;
201 struct Capability_;