comparison interps/cfunge/cfunge-src/src/global.h @ 996:859f9b4339e6

<Gregor> tar xf egobot.tar.xz
author HackBot
date Sun, 09 Dec 2012 19:30:08 +0000
parents
children
comparison
equal deleted inserted replaced
995:6883f5911eb7 996:859f9b4339e6
1 /* -*- mode: C; coding: utf-8; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*-
2 *
3 * cfunge - A standard-conforming Befunge93/98/109 interpreter in C.
4 * Copyright (C) 2008-2009 Arvid Norlander <anmaster AT tele2 DOT se>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at the proxy's option) any later version. Arvid Norlander is a
10 * proxy who can decide which future versions of the GNU General Public
11 * License can be used.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 /**
23 * @file
24 * Global defines. This file should be included everywhere.
25 */
26
27 #ifndef FUNGE_HAD_SRC_GLOBAL_H
28 #define FUNGE_HAD_SRC_GLOBAL_H
29
30 /**
31 * @defgroup compiler Compiler identification.
32 * Defines identifying the compiler.
33 *
34 * CFUNGE_COMP_GCC_COMPAT - GCC or claims to be GCC
35 * CFUNGE_COMP_ICC - Actually ICC
36 * CFUNGE_COMP_CLANG - Really clang.
37 * CFUNGE_COMP_GCC - In fact this is GCC. Or is someone pretending that
38 * we don't know how to identify correctly.
39 * CFUNGE_COMP_GCC3_COMPAT - Claims to be GCC 3.x or later.
40 * CFUNGE_COMP_GCC4_COMPAT - Claims to be GCC 4 or later.
41 * CFUNGE_COMP_GCC4_3_COMPAT - Claims to be GCC 4.3 or later.
42 * CFUNGE_COMP_GCC4_4_COMPAT - Claims to be GCC 4.4 or later.
43 */
44 /*@{*/
45 #ifdef __GNUC__
46 # define CFUNGE_COMP_GCC_COMPAT
47 # if defined(__INTEL_COMPILER)
48 # define CFUNGE_COMP_ICC
49 # elif defined(__clang__)
50 # define CFUNGE_COMP_CLANG
51 # else
52 # define CFUNGE_COMP_GCC
53 # endif
54 # if (__GNUC__ >= 3)
55 # define CFUNGE_COMP_GCC3_COMPAT
56 # endif
57 # if (__GNUC__ >= 4)
58 # define CFUNGE_COMP_GCC4_COMPAT
59 # endif
60 # if (defined(CFUNGE_COMP_GCC4_COMPAT) && (__GNUC_MINOR__ >= 3)) || (__GNUC__ >= 5)
61 # define CFUNGE_COMP_GCC4_3_COMPAT
62 # endif
63 # if (defined(CFUNGE_COMP_GCC4_COMPAT) && (__GNUC_MINOR__ >= 4)) || (__GNUC__ >= 5)
64 # define CFUNGE_COMP_GCC4_4_COMPAT
65 # endif
66 #endif
67 /*@}*/
68
69 /**
70 * @defgroup architecture Architecture identification.
71 * Defines identifying the compiler.
72 *
73 * CFUNGE_ARCH_X86 - 32-bit or 64-bit x86
74 * CFUNGE_ARCH_X86_32 - 32-bit x86
75 * CFUNGE_ARCH_X86_64 - 64-bit x86
76 */
77 /*@{*/
78 #ifdef __i386__
79 # define CFUNGE_ARCH_X86
80 # define CFUNGE_ARCH_X86_32
81 #endif
82 #ifdef __x86_64__
83 # define CFUNGE_ARCH_X86
84 # define CFUNGE_ARCH_X86_64
85 #endif
86 /*@}*/
87
88 /**
89 * @defgroup compat Compiler/system compatibility defines.
90 * Compatibility stuff to support systems lacking some functions of features.
91 */
92 /*@{*/
93 #ifdef CFUNGE_COMP_GCC_COMPAT
94 # define FUNGE_ATTR(x) __attribute__(x)
95 #else
96 /// Make non-GCC compilers happy.
97 # define FUNGE_ATTR(x) /* NO-OP */
98 #endif
99
100 #if defined(CFUNGE_COMP_GCC3_COMPAT) && !defined(CFUNGE_COMP_ICC)
101 /// Give GCC a hint about the most common outcome.
102 /// Please do not add this unless you have profiled.
103 # define FUNGE_EXPECT(expr, outcome) __builtin_expect((expr),(outcome))
104 #else
105 /// Give GCC a hint about the most common outcome.
106 /// Please do not add this unless you have profiled.
107 # define FUNGE_EXPECT(expr, outcome) (expr)
108 #endif /* __GNUC__ */
109
110 /// Hints about likely outcome. Do not add unless you have profiled.
111 #define FUNGE_LIKELY(expr) FUNGE_EXPECT(!!(expr), 1)
112 /// Hints about likely outcome. Do not add unless you have profiled.
113 #define FUNGE_UNLIKELY(expr) FUNGE_EXPECT(!!(expr), 0)
114
115 /*@}*/
116
117
118 /**
119 * @defgroup attributes Attribute specifications.
120 * Contains attribute specifications.
121 */
122 /*@{*/
123 #ifdef CFUNGE_COMP_GCC
124 # ifdef __i386__
125 /// Used to select fast calling convention on platforms that need it.
126 # define FUNGE_ATTR_FAST FUNGE_ATTR((regparm(3)))
127 # else
128 /// Used to select fast calling convention on platforms that need it.
129 # define FUNGE_ATTR_FAST /* NO-OP */
130 # endif
131 #else
132 /// Used to select fast calling convention on platforms that need it.
133 # define FUNGE_ATTR_FAST /* NO-OP */
134 #endif
135
136 #ifdef CFUNGE_COMP_GCC
137 # define FUNGE_ATTR_CONST FUNGE_ATTR((const))
138 # define FUNGE_ATTR_ALWAYS_INLINE FUNGE_ATTR((always_inline))
139 # define FUNGE_ATTR_MALLOC FUNGE_ATTR((malloc))
140 # define FUNGE_ATTR_NOINLINE FUNGE_ATTR((noinline))
141 # define FUNGE_ATTR_NONNULL FUNGE_ATTR((nonnull))
142 # define FUNGE_ATTR_NORET FUNGE_ATTR((noreturn))
143 # define FUNGE_ATTR_PURE FUNGE_ATTR((pure))
144 # define FUNGE_ATTR_UNUSED FUNGE_ATTR((unused))
145 # define FUNGE_ATTR_WARN_UNUSED FUNGE_ATTR((warn_unused_result))
146 # define FUNGE_ATTR_ALIGNED(m_n) FUNGE_ATTR((aligned(m_n)))
147 # define FUNGE_ATTR_FORMAT(m_type, m_fmtidx, m_chkid) \
148 FUNGE_ATTR((format(m_type, m_fmtidx, m_chkid)))
149 #else
150 # define FUNGE_ATTR_CONST /* NO-OP */
151 # define FUNGE_ATTR_ALWAYS_INLINE /* NO-OP */
152 # define FUNGE_ATTR_MALLOC /* NO-OP */
153 # define FUNGE_ATTR_NOINLINE /* NO-OP */
154 # define FUNGE_ATTR_NONNULL /* NO-OP */
155 # define FUNGE_ATTR_NORET /* NO-OP */
156 # define FUNGE_ATTR_PURE /* NO-OP */
157 # define FUNGE_ATTR_UNUSED /* NO-OP */
158 # define FUNGE_ATTR_WARN_UNUSED /* NO-OP */
159 # define FUNGE_ATTR_ALIGNED(m_n) /* NO-OP */
160 # define FUNGE_ATTR_FORMAT(m_type, m_fmtidx, m_chkid) /* NO-OP */
161 #endif
162
163 #if defined(CFUNGE_COMP_GCC) && defined(CFUNGE_COMP_GCC4_3_COMPAT)
164 # define FUNGE_ATTR_COLD FUNGE_ATTR((cold))
165 # define FUNGE_ATTR_HOT FUNGE_ATTR((hot))
166 #else
167 # define FUNGE_ATTR_COLD /* NO-OP */
168 # define FUNGE_ATTR_HOT /* NO-OP */
169 #endif
170
171 /*@}*/
172
173 // I so hate the C preprocessor...
174 #define FUNGE_CPP_STRINGIFY_INNER(m_arg) # m_arg
175 /**
176 * Stringifies argument, needed because the C preprocessor is so stupid.
177 */
178 #define FUNGE_CPP_STRINGIFY(m_arg) FUNGE_CPP_STRINGIFY_INNER(m_arg)
179
180 /* stdlib.h: For ABS() below, as well as malloc/calloc/free in support.h */
181 #include <stdlib.h>
182 #include "support.h"
183 /* stdint.h: For int32_t/int64_t needed for funge_cell below. */
184 #include <stdint.h>
185 /* inttypes.h: For INT64_MIN and such below. */
186 #include <inttypes.h>
187
188
189 /**
190 * @defgroup FUNGEDATA Funge data types
191 * The type/size of the data cells, and various related things
192 */
193 /*@{*/
194 #if defined(USE64)
195 /// The type of the data cells (64-bit version).
196 typedef int64_t funge_cell;
197 /// As funge_cell, but unsigned (64-bit version).
198 typedef uint64_t funge_unsigned_cell;
199 /// Generic printf code to use.
200 # define FUNGECELLPRI PRId64
201 /// Printf code for octal output.
202 # define FUNGECELLoctPRI PRIo64
203 /// Printf code for hexdecimal output.
204 # define FUNGECELLhexPRI PRIx64
205 /// Max value for funge_cell
206 # define FUNGECELL_MIN INT64_MIN
207 /// Min value for funge_cell
208 # define FUNGECELL_MAX INT64_MAX
209
210 /**
211 * Define the abs() function to use for the set data size.
212 * This one is 64-bit.
213 */
214 # define ABS(x) llabs(x)
215
216
217 #elif defined(USE32)
218 /// The type of the data cells (32-bit version).
219 typedef int32_t funge_cell;
220 /// As funge_cell, but unsigned (32-bit version).
221 typedef uint32_t funge_unsigned_cell;
222 /// Generic printf code to use.
223 # define FUNGECELLPRI PRId32
224 /// Printf code for octal output.
225 # define FUNGECELLoctPRI PRIo32
226 /// Printf code for hexdecimal output.
227 # define FUNGECELLhexPRI PRIx32
228 /// Max value for funge_cell
229 # define FUNGECELL_MIN INT32_MIN
230 /// Min value for funge_cell
231 # define FUNGECELL_MAX INT32_MAX
232
233 /**
234 * Define the abs() function to use for the set data size.
235 * This one is 32-bit.
236 */
237 # define ABS(x) abs(x)
238
239
240 #else
241 # error "Err, you actually got to select either 32-bit or 64-bit data type. If you used the normal build system this error should not happen."
242 #endif
243 /*@}*/
244
245
246 // This is done in other to make integration with IFFI easier for ais523.
247 #ifndef FUNGE_OLD_HANDPRINT
248 /// Funge-98 Handprint: CFUN
249 # define FUNGE_OLD_HANDPRINT 0x4346554e
250 #endif
251 #ifndef FUNGE_NEW_HANDPRINT
252 /// Funge-109 Handprint: An URL.
253 # define FUNGE_NEW_HANDPRINT "http://kuonet.org/~anmaster/cfunge"
254 #endif
255 #ifdef FUNGEHANDPRINT
256 # error "Please rename FUNGEHANDPRINT to FUNGE_OLD_HANDPRINT and add FUNGE_NEW_HANDPRINT!"
257 #endif
258 /// Version, for -V.
259 #define CFUNGE_APPVERSION "0.9.0"
260 /// For y instruction.
261 #define CFUNGE_VERSION_Y 90
262
263 /**
264 * For third party code.
265 * The format is 0xaabbccdd, where:
266 * - aa is major
267 * - bb is minor
268 * - cc is micro
269 * - dd is 0 for releases, and has a non-zero value for development versions
270 * after said release. Usually it will be 01, but it may be more if some
271 * major API breakage happened.
272 * This define was introduced between 0.3.3 and 0.3.4.
273 */
274 #define CFUNGE_VERSION 0x00090000
275
276 /// Since there may be no API changes between versions we also define this.
277 #define CFUNGE_API_VERSION 3
278
279 // Define if you use fuzz testing script.
280 //#define FUZZ_TESTING
281
282 #endif