]> git.proxmox.com Git - ceph.git/blame - ceph/src/civetweb/src/third_party/duktape-1.8.0/src-noline/duk_config.h
import 12.2.13 release
[ceph.git] / ceph / src / civetweb / src / third_party / duktape-1.8.0 / src-noline / duk_config.h
CommitLineData
7c673cae 1/*
37b3c998 2 * duk_config.h configuration header generated by genconfig.py.
7c673cae 3 *
37b3c998
TL
4 * Git commit: 0a70d7e4c5227c84e3fed5209828973117d02849
5 * Git describe: v1.8.0
6 * Git branch: v1.8-maintenance
7c673cae 7 *
37b3c998
TL
8 * Supported platforms:
9 * - Mac OSX, iPhone, Darwin
10 * - OpenBSD
11 * - Generic BSD
12 * - Atari ST TOS
13 * - AmigaOS
14 * - Windows
15 * - Flashplayer (Crossbridge)
16 * - QNX
17 * - TI-Nspire
18 * - Emscripten
19 * - Linux
20 * - Solaris
21 * - Generic POSIX
22 * - Cygwin
23 * - Generic UNIX
24 * - Generic fallback
7c673cae 25 *
37b3c998
TL
26 * Supported architectures:
27 * - x86
28 * - x64
29 * - x32
30 * - ARM 32-bit
31 * - ARM 64-bit
32 * - MIPS 32-bit
33 * - MIPS 64-bit
34 * - PowerPC 32-bit
35 * - PowerPC 64-bit
36 * - SPARC 32-bit
37 * - SPARC 64-bit
38 * - SuperH
39 * - Motorola 68k
40 * - Emscripten
41 * - Generic
7c673cae 42 *
37b3c998
TL
43 * Supported compilers:
44 * - Clang
45 * - GCC
46 * - MSVC
47 * - Emscripten
48 * - TinyC
49 * - VBCC
50 * - Bruce's C compiler
51 * - Generic
7c673cae 52 *
7c673cae
FG
53 */
54
37b3c998 55#if !defined(DUK_CONFIG_H_INCLUDED)
7c673cae
FG
56#define DUK_CONFIG_H_INCLUDED
57
58/*
37b3c998 59 * Intermediate helper defines
7c673cae
FG
60 */
61
37b3c998
TL
62/* DLL build detection */
63#if defined(DUK_OPT_DLL_BUILD)
64#define DUK_F_DLL_BUILD
65#elif defined(DUK_OPT_NO_DLL_BUILD)
66#undef DUK_F_DLL_BUILD
7c673cae 67#else
37b3c998
TL
68/* not configured for DLL build */
69#undef DUK_F_DLL_BUILD
7c673cae
FG
70#endif
71
37b3c998
TL
72/* Apple OSX, iOS */
73#if defined(__APPLE__)
74#define DUK_F_APPLE
7c673cae
FG
75#endif
76
37b3c998
TL
77/* OpenBSD */
78#if defined(__OpenBSD__) || defined(__OpenBSD)
79#define DUK_F_OPENBSD
7c673cae
FG
80#endif
81
37b3c998
TL
82/* NetBSD */
83#if defined(__NetBSD__) || defined(__NetBSD)
84#define DUK_F_NETBSD
7c673cae
FG
85#endif
86
37b3c998
TL
87/* FreeBSD */
88#if defined(__FreeBSD__) || defined(__FreeBSD)
89#define DUK_F_FREEBSD
7c673cae
FG
90#endif
91
37b3c998
TL
92/* BSD variant */
93#if defined(DUK_F_FREEBSD) || defined(DUK_F_NETBSD) || defined(DUK_F_OPENBSD) || \
94 defined(__bsdi__) || defined(__DragonFly__)
95#define DUK_F_BSD
7c673cae
FG
96#endif
97
37b3c998
TL
98/* Atari ST TOS. __TOS__ defined by PureC. No platform define in VBCC
99 * apparently, so to use with VBCC user must define __TOS__ manually.
100 */
101#if defined(__TOS__)
102#define DUK_F_TOS
7c673cae
FG
103#endif
104
105/* Motorola 68K. Not defined by VBCC, so user must define one of these
106 * manually when using VBCC.
107 */
108#if defined(__m68k__) || defined(M68000) || defined(__MC68K__)
109#define DUK_F_M68K
110#endif
111
37b3c998
TL
112/* AmigaOS. Neither AMIGA nor __amigaos__ is defined on VBCC, so user must
113 * define 'AMIGA' manually when using VBCC.
114 */
115#if defined(AMIGA) || defined(__amigaos__)
116#define DUK_F_AMIGAOS
117#endif
118
7c673cae
FG
119/* PowerPC */
120#if defined(__powerpc) || defined(__powerpc__) || defined(__PPC__)
121#define DUK_F_PPC
37b3c998 122#if defined(__PPC64__) || defined(__LP64__) || defined(_LP64)
7c673cae
FG
123#define DUK_F_PPC64
124#else
125#define DUK_F_PPC32
126#endif
127#endif
128
37b3c998
TL
129/* Windows, both 32-bit and 64-bit */
130#if defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(WIN64) || \
131 defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__)
132#define DUK_F_WINDOWS
133#if defined(_WIN64) || defined(WIN64)
134#define DUK_F_WIN64
135#else
136#define DUK_F_WIN32
137#endif
138#endif
139
140/* Flash player (e.g. Crossbridge) */
141#if defined(__FLASHPLAYER__)
142#define DUK_F_FLASHPLAYER
143#endif
144
145/* QNX */
146#if defined(__QNX__)
147#define DUK_F_QNX
148#endif
149
150/* TI-Nspire (using Ndless) */
151#if defined(_TINSPIRE)
152#define DUK_F_TINSPIRE
153#endif
154
155/* Emscripten (provided explicitly by user), improve if possible */
156#if defined(EMSCRIPTEN)
157#define DUK_F_EMSCRIPTEN
158#endif
159
160/* BCC (Bruce's C compiler): this is a "torture target" for compilation */
161#if defined(__BCC__) || defined(__BCC_VERSION__)
162#define DUK_F_BCC
163#endif
164
7c673cae
FG
165/* Linux */
166#if defined(__linux) || defined(__linux__) || defined(linux)
167#define DUK_F_LINUX
168#endif
169
37b3c998
TL
170/* illumos / Solaris */
171#if defined(__sun) && defined(__SVR4)
172#define DUK_F_SUN
7c673cae
FG
173#endif
174
37b3c998
TL
175/* POSIX */
176#if defined(__posix)
177#define DUK_F_POSIX
7c673cae
FG
178#endif
179
37b3c998
TL
180/* Cygwin */
181#if defined(__CYGWIN__)
182#define DUK_F_CYGWIN
7c673cae
FG
183#endif
184
185/* Generic Unix (includes Cygwin) */
186#if defined(__unix) || defined(__unix__) || defined(unix) || \
187 defined(DUK_F_LINUX) || defined(DUK_F_BSD)
188#define DUK_F_UNIX
189#endif
190
37b3c998
TL
191/* stdint.h not available */
192#if defined(DUK_F_WINDOWS) && defined(_MSC_VER)
193#if (_MSC_VER < 1700)
194/* VS2012+ has stdint.h, < VS2012 does not (but it's available for download). */
195#define DUK_F_NO_STDINT_H
196#endif
197#endif
198#if !defined(DUK_F_NO_STDINT_H) && (defined(DUK_F_TOS) || defined(DUK_F_BCC))
199#define DUK_F_NO_STDINT_H
7c673cae
FG
200#endif
201
37b3c998
TL
202/* C++ */
203#undef DUK_F_CPP
204#if defined(__cplusplus)
205#define DUK_F_CPP
7c673cae
FG
206#endif
207
37b3c998
TL
208/* Intel x86 (32-bit), x64 (64-bit) or x32 (64-bit but 32-bit pointers),
209 * define only one of DUK_F_X86, DUK_F_X64, DUK_F_X32.
210 * https://sites.google.com/site/x32abi/
211 */
212#if defined(__amd64__) || defined(__amd64) || \
213 defined(__x86_64__) || defined(__x86_64) || \
214 defined(_M_X64) || defined(_M_AMD64)
215#if defined(__ILP32__) || defined(_ILP32)
216#define DUK_F_X32
217#else
218#define DUK_F_X64
219#endif
220#elif defined(i386) || defined(__i386) || defined(__i386__) || \
221 defined(__i486__) || defined(__i586__) || defined(__i686__) || \
222 defined(__IA32__) || defined(_M_IX86) || defined(__X86__) || \
223 defined(_X86_) || defined(__THW_INTEL__) || defined(__I86__)
224#if defined(__LP64__) || defined(_LP64)
225/* This should not really happen, but would indicate x64. */
226#define DUK_F_X64
227#else
228#define DUK_F_X86
229#endif
7c673cae
FG
230#endif
231
37b3c998
TL
232/* ARM */
233#if defined(__arm__) || defined(__thumb__) || defined(_ARM) || defined(_M_ARM)
234#define DUK_F_ARM
235#if defined(__LP64__) || defined(_LP64) || defined(__arm64) || defined(__arm64__)
236#define DUK_F_ARM64
237#else
238#define DUK_F_ARM32
239#endif
7c673cae
FG
240#endif
241
37b3c998
TL
242/* MIPS. Related defines: __MIPSEB__, __MIPSEL__, __mips_isa_rev, __LP64__ */
243#if defined(__mips__) || defined(mips) || defined(_MIPS_ISA) || \
244 defined(_R3000) || defined(_R4000) || defined(_R5900) || \
245 defined(_MIPS_ISA_MIPS1) || defined(_MIPS_ISA_MIPS2) || \
246 defined(_MIPS_ISA_MIPS3) || defined(_MIPS_ISA_MIPS4) || \
247 defined(__mips) || defined(__MIPS__)
248#define DUK_F_MIPS
249#if defined(__LP64__) || defined(_LP64) || defined(__mips64) || \
250 defined(__mips64__) || defined(__mips_n64)
251#define DUK_F_MIPS64
252#else
253#define DUK_F_MIPS32
254#endif
7c673cae
FG
255#endif
256
37b3c998
TL
257/* SPARC */
258#if defined(sparc) || defined(__sparc) || defined(__sparc__)
259#define DUK_F_SPARC
260#if defined(__LP64__) || defined(_LP64)
261#define DUK_F_SPARC64
262#else
263#define DUK_F_SPARC32
264#endif
7c673cae
FG
265#endif
266
37b3c998
TL
267/* SuperH */
268#if defined(__sh__) || \
269 defined(__sh1__) || defined(__SH1__) || \
270 defined(__sh2__) || defined(__SH2__) || \
271 defined(__sh3__) || defined(__SH3__) || \
272 defined(__sh4__) || defined(__SH4__) || \
273 defined(__sh5__) || defined(__SH5__)
274#define DUK_F_SUPERH
7c673cae
FG
275#endif
276
37b3c998
TL
277/* Clang */
278#if defined(__clang__)
279#define DUK_F_CLANG
7c673cae
FG
280#endif
281
37b3c998
TL
282/* C99 or above */
283#undef DUK_F_C99
284#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
285#define DUK_F_C99
286#endif
287
288/* C++11 or above */
289#undef DUK_F_CPP11
290#if defined(__cplusplus) && (__cplusplus >= 201103L)
291#define DUK_F_CPP11
7c673cae
FG
292#endif
293
37b3c998
TL
294/* GCC. Clang also defines __GNUC__ so don't detect GCC if using Clang. */
295#if defined(__GNUC__) && !defined(__clang__) && !defined(DUK_F_CLANG)
7c673cae
FG
296#define DUK_F_GCC
297#if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
298/* Convenience, e.g. gcc 4.5.1 == 40501; http://stackoverflow.com/questions/6031819/emulating-gccs-builtin-unreachable */
299#define DUK_F_GCC_VERSION (__GNUC__ * 10000L + __GNUC_MINOR__ * 100L + __GNUC_PATCHLEVEL__)
300#else
301#error cannot figure out gcc version
302#endif
303#endif
304
37b3c998
TL
305/* MinGW. Also GCC flags (DUK_F_GCC) are enabled now. */
306#if defined(__MINGW32__) || defined(__MINGW64__)
307#define DUK_F_MINGW
7c673cae
FG
308#endif
309
310/* MSVC */
311#if defined(_MSC_VER)
312/* MSVC preprocessor defines: http://msdn.microsoft.com/en-us/library/b0084kay.aspx
313 * _MSC_FULL_VER includes the build number, but it has at least two formats, see e.g.
314 * BOOST_MSVC_FULL_VER in http://www.boost.org/doc/libs/1_52_0/boost/config/compiler/visualc.hpp
315 */
316#define DUK_F_MSVC
317#if defined(_MSC_FULL_VER)
318#if (_MSC_FULL_VER > 100000000)
319#define DUK_F_MSVC_FULL_VER _MSC_FULL_VER
320#else
321#define DUK_F_MSCV_FULL_VER (_MSC_FULL_VER * 10)
322#endif
323#endif
324#endif /* _MSC_VER */
325
37b3c998
TL
326/* TinyC */
327#if defined(__TINYC__)
328/* http://bellard.org/tcc/tcc-doc.html#SEC9 */
329#define DUK_F_TINYC
7c673cae
FG
330#endif
331
37b3c998 332/* VBCC */
7c673cae
FG
333#if defined(__VBCC__)
334#define DUK_F_VBCC
335#endif
336
37b3c998
TL
337/* Atari Mint */
338#if defined(__MINT__)
339#define DUK_F_MINT
340#endif
341
7c673cae 342/*
37b3c998 343 * Platform autodetection
7c673cae
FG
344 */
345
37b3c998
TL
346/* Workaround for older C++ compilers before including <inttypes.h>,
347 * see e.g.: https://sourceware.org/bugzilla/show_bug.cgi?id=15366
7c673cae 348 */
37b3c998
TL
349#if defined(__cplusplus) && !defined(__STDC_LIMIT_MACROS)
350#define __STDC_LIMIT_MACROS
7c673cae 351#endif
37b3c998
TL
352#if defined(__cplusplus) && !defined(__STDC_CONSTANT_MACROS)
353#define __STDC_CONSTANT_MACROS
7c673cae
FG
354#endif
355
37b3c998
TL
356#if defined(DUK_F_APPLE)
357/* --- Mac OSX, iPhone, Darwin --- */
7c673cae
FG
358#define DUK_USE_DATE_NOW_GETTIMEOFDAY
359#define DUK_USE_DATE_TZO_GMTIME_R
360#define DUK_USE_DATE_PRS_STRPTIME
361#define DUK_USE_DATE_FMT_STRFTIME
362#include <TargetConditionals.h>
363#include <architecture/byte_order.h>
7c673cae
FG
364#include <sys/param.h>
365#include <sys/time.h>
366#include <time.h>
37b3c998
TL
367
368/* http://stackoverflow.com/questions/5919996/how-to-detect-reliably-mac-os-x-ios-linux-windows-in-c-preprocessor */
369#if TARGET_IPHONE_SIMULATOR
370#define DUK_USE_OS_STRING "iphone-sim"
371#elif TARGET_OS_IPHONE
372#define DUK_USE_OS_STRING "iphone"
373#elif TARGET_OS_MAC
374#define DUK_USE_OS_STRING "osx"
375#else
376#define DUK_USE_OS_STRING "osx-unknown"
377#endif
378
379/* Use _setjmp() on Apple by default, see GH-55. */
380#define DUK_JMPBUF_TYPE jmp_buf
381#define DUK_SETJMP(jb) _setjmp((jb))
382#define DUK_LONGJMP(jb) _longjmp((jb), 1)
7c673cae 383#elif defined(DUK_F_OPENBSD)
37b3c998 384/* --- OpenBSD --- */
7c673cae
FG
385/* http://www.monkey.org/openbsd/archive/ports/0401/msg00089.html */
386#define DUK_USE_DATE_NOW_GETTIMEOFDAY
387#define DUK_USE_DATE_TZO_GMTIME_R
388#define DUK_USE_DATE_PRS_STRPTIME
389#define DUK_USE_DATE_FMT_STRFTIME
390#include <sys/types.h>
391#include <sys/endian.h>
7c673cae
FG
392#include <sys/param.h>
393#include <sys/time.h>
394#include <time.h>
37b3c998
TL
395
396#define DUK_USE_OS_STRING "openbsd"
7c673cae 397#elif defined(DUK_F_BSD)
37b3c998 398/* --- Generic BSD --- */
7c673cae
FG
399#define DUK_USE_DATE_NOW_GETTIMEOFDAY
400#define DUK_USE_DATE_TZO_GMTIME_R
401#define DUK_USE_DATE_PRS_STRPTIME
402#define DUK_USE_DATE_FMT_STRFTIME
403#include <sys/types.h>
404#include <sys/endian.h>
7c673cae
FG
405#include <sys/param.h>
406#include <sys/time.h>
407#include <time.h>
37b3c998
TL
408
409#define DUK_USE_OS_STRING "bsd"
7c673cae 410#elif defined(DUK_F_TOS)
37b3c998 411/* --- Atari ST TOS --- */
7c673cae
FG
412#define DUK_USE_DATE_NOW_TIME
413#define DUK_USE_DATE_TZO_GMTIME
414/* no parsing (not an error) */
415#define DUK_USE_DATE_FMT_STRFTIME
7c673cae 416#include <time.h>
37b3c998
TL
417
418#define DUK_USE_OS_STRING "tos"
419
420/* TOS on M68K is always big endian. */
421#if !defined(DUK_USE_BYTEORDER) && defined(DUK_F_M68K)
422#define DUK_USE_BYTEORDER 3
423#endif
7c673cae 424#elif defined(DUK_F_AMIGAOS)
37b3c998 425/* --- AmigaOS --- */
7c673cae
FG
426#if defined(DUK_F_M68K)
427/* AmigaOS on M68k */
428#define DUK_USE_DATE_NOW_TIME
429#define DUK_USE_DATE_TZO_GMTIME
430/* no parsing (not an error) */
431#define DUK_USE_DATE_FMT_STRFTIME
7c673cae
FG
432#include <time.h>
433#elif defined(DUK_F_PPC)
434#define DUK_USE_DATE_NOW_GETTIMEOFDAY
435#define DUK_USE_DATE_TZO_GMTIME_R
436#define DUK_USE_DATE_PRS_STRPTIME
437#define DUK_USE_DATE_FMT_STRFTIME
7c673cae
FG
438#include <time.h>
439#ifndef UINTPTR_MAX
440#define UINTPTR_MAX UINT_MAX
441#endif
442#else
443#error AmigaOS but not M68K/PPC, not supported now
444#endif
37b3c998
TL
445
446#define DUK_USE_OS_STRING "amigaos"
447
448/* AmigaOS on M68K or PPC is always big endian. */
449#if !defined(DUK_USE_BYTEORDER) && (defined(DUK_F_M68K) || defined(DUK_F_PPC))
450#define DUK_USE_BYTEORDER 3
451#endif
7c673cae 452#elif defined(DUK_F_WINDOWS)
37b3c998
TL
453/* --- Windows --- */
454/* Initial fix: disable secure CRT related warnings when compiling Duktape
455 * itself (must be defined before including Windows headers). Don't define
456 * for user code including duktape.h.
457 */
458#if defined(DUK_COMPILING_DUKTAPE) && !defined(_CRT_SECURE_NO_WARNINGS)
459#define _CRT_SECURE_NO_WARNINGS
460#endif
461
7c673cae
FG
462/* Windows 32-bit and 64-bit are currently the same. */
463/* MSVC does not have sys/param.h */
464#define DUK_USE_DATE_NOW_WINDOWS
465#define DUK_USE_DATE_TZO_WINDOWS
466/* Note: PRS and FMT are intentionally left undefined for now. This means
467 * there is no platform specific date parsing/formatting but there is still
468 * the ISO 8601 standard format.
469 */
470#if defined(DUK_COMPILING_DUKTAPE)
37b3c998
TL
471/* Only include when compiling Duktape to avoid polluting application build
472 * with a lot of unnecessary defines.
473 */
7c673cae
FG
474#include <windows.h>
475#endif
37b3c998
TL
476
477#define DUK_USE_OS_STRING "windows"
478
479/* On Windows, assume we're little endian. Even Itanium which has a
480 * configurable endianness runs little endian in Windows.
481 */
482#if !defined(DUK_USE_BYTEORDER)
483#define DUK_USE_BYTEORDER 1
484#endif
7c673cae 485#elif defined(DUK_F_FLASHPLAYER)
37b3c998 486/* --- Flashplayer (Crossbridge) --- */
7c673cae
FG
487#define DUK_USE_DATE_NOW_GETTIMEOFDAY
488#define DUK_USE_DATE_TZO_GMTIME_R
489#define DUK_USE_DATE_PRS_STRPTIME
490#define DUK_USE_DATE_FMT_STRFTIME
491#include <endian.h>
7c673cae
FG
492#include <sys/param.h>
493#include <sys/time.h>
494#include <time.h>
37b3c998
TL
495
496#define DUK_USE_OS_STRING "flashplayer"
497
498#if !defined(DUK_USE_BYTEORDER) && defined(DUK_F_FLASHPLAYER)
499#define DUK_USE_BYTEORDER 1
500#endif
7c673cae 501#elif defined(DUK_F_QNX)
37b3c998
TL
502/* --- QNX --- */
503#if defined(DUK_F_QNX) && defined(DUK_COMPILING_DUKTAPE)
504/* See: /opt/qnx650/target/qnx6/usr/include/sys/platform.h */
505#define _XOPEN_SOURCE 600
506#define _POSIX_C_SOURCE 200112L
507#endif
508
7c673cae
FG
509#define DUK_USE_DATE_NOW_GETTIMEOFDAY
510#define DUK_USE_DATE_TZO_GMTIME_R
511#define DUK_USE_DATE_PRS_STRPTIME
512#define DUK_USE_DATE_FMT_STRFTIME
513#include <sys/types.h>
7c673cae
FG
514#include <sys/param.h>
515#include <sys/time.h>
516#include <time.h>
37b3c998
TL
517
518#define DUK_USE_OS_STRING "qnx"
7c673cae 519#elif defined(DUK_F_TINSPIRE)
37b3c998 520/* --- TI-Nspire --- */
7c673cae
FG
521#define DUK_USE_DATE_NOW_GETTIMEOFDAY
522#define DUK_USE_DATE_TZO_GMTIME_R
523#define DUK_USE_DATE_PRS_STRPTIME
524#define DUK_USE_DATE_FMT_STRFTIME
525#include <sys/types.h>
7c673cae
FG
526#include <sys/param.h>
527#include <sys/time.h>
528#include <time.h>
37b3c998
TL
529
530#define DUK_USE_OS_STRING "tinspire"
531#elif defined(DUK_F_EMSCRIPTEN)
532/* --- Emscripten --- */
533#if defined(DUK_COMPILING_DUKTAPE)
534#ifndef _POSIX_C_SOURCE
535#define _POSIX_C_SOURCE 200809L
536#endif
537#ifndef _GNU_SOURCE
538#define _GNU_SOURCE /* e.g. getdate_r */
539#endif
540#ifndef _XOPEN_SOURCE
541#define _XOPEN_SOURCE /* e.g. strptime */
542#endif
543#endif /* DUK_COMPILING_DUKTAPE */
544
545#include <sys/types.h>
546#if defined(DUK_F_BCC)
547/* no endian.h */
548#else
549#include <endian.h>
550#endif /* DUK_F_BCC */
551#include <sys/param.h>
552#include <sys/time.h>
553#include <time.h>
554#include <stdint.h>
555
7c673cae
FG
556#define DUK_USE_DATE_NOW_GETTIMEOFDAY
557#define DUK_USE_DATE_TZO_GMTIME_R
558#define DUK_USE_DATE_PRS_STRPTIME
559#define DUK_USE_DATE_FMT_STRFTIME
37b3c998
TL
560
561#define DUK_USE_OS_STRING "emscripten"
562#elif defined(DUK_F_LINUX)
563/* --- Linux --- */
564#if defined(DUK_COMPILING_DUKTAPE)
565#ifndef _POSIX_C_SOURCE
566#define _POSIX_C_SOURCE 200809L
567#endif
568#ifndef _GNU_SOURCE
569#define _GNU_SOURCE /* e.g. getdate_r */
570#endif
571#ifndef _XOPEN_SOURCE
572#define _XOPEN_SOURCE /* e.g. strptime */
573#endif
574#endif /* DUK_COMPILING_DUKTAPE */
575
7c673cae
FG
576#include <sys/types.h>
577#if defined(DUK_F_BCC)
37b3c998 578/* no endian.h or stdint.h */
7c673cae
FG
579#else
580#include <endian.h>
37b3c998 581#include <stdint.h>
7c673cae 582#endif /* DUK_F_BCC */
7c673cae
FG
583#include <sys/param.h>
584#include <sys/time.h>
585#include <time.h>
37b3c998
TL
586
587#define DUK_USE_DATE_NOW_GETTIMEOFDAY
588#define DUK_USE_DATE_TZO_GMTIME_R
589#define DUK_USE_DATE_PRS_STRPTIME
590#define DUK_USE_DATE_FMT_STRFTIME
591
592#define DUK_USE_OS_STRING "linux"
593#elif defined(DUK_F_SUN)
594/* --- Solaris --- */
7c673cae
FG
595#define DUK_USE_DATE_NOW_GETTIMEOFDAY
596#define DUK_USE_DATE_TZO_GMTIME_R
597#define DUK_USE_DATE_PRS_STRPTIME
598#define DUK_USE_DATE_FMT_STRFTIME
37b3c998 599
7c673cae 600#include <sys/types.h>
37b3c998 601#include <ast/endian.h>
7c673cae
FG
602#include <sys/param.h>
603#include <sys/time.h>
604#include <time.h>
37b3c998
TL
605
606#define DUK_USE_OS_STRING "solaris"
607#elif defined(DUK_F_POSIX)
608/* --- Generic POSIX --- */
7c673cae
FG
609#define DUK_USE_DATE_NOW_GETTIMEOFDAY
610#define DUK_USE_DATE_TZO_GMTIME_R
37b3c998 611#define DUK_USE_DATE_PRS_STRPTIME
7c673cae
FG
612#define DUK_USE_DATE_FMT_STRFTIME
613#include <sys/types.h>
614#include <endian.h>
7c673cae
FG
615#include <sys/param.h>
616#include <sys/time.h>
617#include <time.h>
37b3c998
TL
618
619#define DUK_USE_OS_STRING "posix"
620#elif defined(DUK_F_CYGWIN)
621/* --- Cygwin --- */
622/* don't use strptime() for now */
7c673cae
FG
623#define DUK_USE_DATE_NOW_GETTIMEOFDAY
624#define DUK_USE_DATE_TZO_GMTIME_R
7c673cae
FG
625#define DUK_USE_DATE_FMT_STRFTIME
626#include <sys/types.h>
7c673cae 627#include <endian.h>
7c673cae
FG
628#include <sys/param.h>
629#include <sys/time.h>
630#include <time.h>
7c673cae 631
37b3c998
TL
632#define DUK_JMPBUF_TYPE jmp_buf
633#define DUK_SETJMP(jb) _setjmp((jb))
634#define DUK_LONGJMP(jb) _longjmp((jb), 1)
635
636#define DUK_USE_OS_STRING "windows"
637#elif defined(DUK_F_UNIX)
638/* --- Generic UNIX --- */
639#define DUK_USE_DATE_NOW_GETTIMEOFDAY
640#define DUK_USE_DATE_TZO_GMTIME_R
641#define DUK_USE_DATE_PRS_STRPTIME
642#define DUK_USE_DATE_FMT_STRFTIME
643#include <time.h>
644#include <sys/time.h>
645#define DUK_USE_OS_STRING "unknown"
646#else
647/* --- Generic fallback --- */
648/* The most portable current time provider is time(), but it only has a
649 * one second resolution.
650 */
651#define DUK_USE_DATE_NOW_TIME
652
653/* The most portable way to figure out local time offset is gmtime(),
654 * but it's not thread safe so use with caution.
655 */
656#define DUK_USE_DATE_TZO_GMTIME
657
658/* Avoid custom date parsing and formatting for portability. */
659#undef DUK_USE_DATE_PRS_STRPTIME
660#undef DUK_USE_DATE_FMT_STRFTIME
661
662/* Rely on C89 headers only; time.h must be here. */
663#include <time.h>
664
665#define DUK_USE_OS_STRING "unknown"
666#endif /* autodetect platform */
667
668/* Shared includes: C89 */
7c673cae
FG
669#include <stdio.h>
670#include <stdlib.h>
671#include <string.h>
672#include <stdarg.h> /* varargs */
673#include <setjmp.h>
674#include <stddef.h> /* e.g. ptrdiff_t */
37b3c998
TL
675#include <math.h>
676#include <limits.h>
677
678/* date.h is omitted, and included per platform */
679
680/* Shared includes: stdint.h is C99 */
7c673cae
FG
681#if defined(DUK_F_NO_STDINT_H)
682/* stdint.h not available */
683#else
37b3c998
TL
684/* Technically C99 (C++11) but found in many systems. On some systems
685 * __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS must be defined before
686 * including stdint.h (see above).
7c673cae
FG
687 */
688#include <stdint.h>
689#endif
7c673cae 690
37b3c998
TL
691#if defined(DUK_F_CPP)
692#include <exception> /* std::exception */
7c673cae
FG
693#endif
694
695/*
37b3c998 696 * Architecture autodetection
7c673cae
FG
697 */
698
37b3c998
TL
699#if defined(DUK_F_X86)
700/* --- x86 --- */
701#define DUK_USE_ARCH_STRING "x86"
702#if !defined(DUK_USE_BYTEORDER)
703#define DUK_USE_BYTEORDER 1
7c673cae 704#endif
37b3c998
TL
705/* XXX: This is technically not guaranteed because it's possible to configure
706 * an x86 to require aligned accesses with Alignment Check (AC) flag.
7c673cae 707 */
37b3c998
TL
708#if !defined(DUK_USE_ALIGN_BY)
709#define DUK_USE_ALIGN_BY 1
7c673cae 710#endif
37b3c998
TL
711#define DUK_USE_PACKED_TVAL
712#define DUK_F_PACKED_TVAL_PROVIDED
713#elif defined(DUK_F_X64)
714/* --- x64 --- */
715#define DUK_USE_ARCH_STRING "x64"
716#if !defined(DUK_USE_BYTEORDER)
717#define DUK_USE_BYTEORDER 1
718#endif
719/* XXX: This is technically not guaranteed because it's possible to configure
720 * an x86 to require aligned accesses with Alignment Check (AC) flag.
7c673cae 721 */
37b3c998
TL
722#if !defined(DUK_USE_ALIGN_BY)
723#define DUK_USE_ALIGN_BY 1
7c673cae 724#endif
37b3c998
TL
725#undef DUK_USE_PACKED_TVAL
726#define DUK_F_PACKED_TVAL_PROVIDED
727#elif defined(DUK_F_X32)
728/* --- x32 --- */
729#define DUK_USE_ARCH_STRING "x32"
730#if !defined(DUK_USE_BYTEORDER)
731#define DUK_USE_BYTEORDER 1
7c673cae 732#endif
37b3c998
TL
733/* XXX: This is technically not guaranteed because it's possible to configure
734 * an x86 to require aligned accesses with Alignment Check (AC) flag.
7c673cae 735 */
37b3c998
TL
736#if !defined(DUK_USE_ALIGN_BY)
737#define DUK_USE_ALIGN_BY 1
738#endif
739#define DUK_USE_PACKED_TVAL
740#define DUK_F_PACKED_TVAL_PROVIDED
741#elif defined(DUK_F_ARM32)
742/* --- ARM 32-bit --- */
743#define DUK_USE_ARCH_STRING "arm32"
744/* Byte order varies, so rely on autodetect. */
745#if !defined(DUK_USE_ALIGN_BY)
746#define DUK_USE_ALIGN_BY 4
747#endif
748#define DUK_USE_PACKED_TVAL
749#define DUK_F_PACKED_TVAL_PROVIDED
750#elif defined(DUK_F_ARM64)
751/* --- ARM 64-bit --- */
752#define DUK_USE_ARCH_STRING "arm64"
753/* Byte order varies, so rely on autodetect. */
754#if !defined(DUK_USE_ALIGN_BY)
755#define DUK_USE_ALIGN_BY 8
756#endif
757#undef DUK_USE_PACKED_TVAL
758#define DUK_F_PACKED_TVAL_PROVIDED
759#elif defined(DUK_F_MIPS32)
760/* --- MIPS 32-bit --- */
761#define DUK_USE_ARCH_STRING "mips32"
762/* MIPS byte order varies so rely on autodetection. */
763/* Based on 'make checkalign' there are no alignment requirements on
764 * Linux MIPS except for doubles, which need align by 4. Alignment
765 * requirements vary based on target though.
766 */
767#if !defined(DUK_USE_ALIGN_BY)
768#define DUK_USE_ALIGN_BY 4
769#endif
770#define DUK_USE_PACKED_TVAL
771#define DUK_F_PACKED_TVAL_PROVIDED
772#elif defined(DUK_F_MIPS64)
773/* --- MIPS 64-bit --- */
774#define DUK_USE_ARCH_STRING "mips64"
775/* MIPS byte order varies so rely on autodetection. */
776/* Good default is a bit arbitrary because alignment requirements
777 * depend on target. See https://github.com/svaarala/duktape/issues/102.
778 */
779#if !defined(DUK_USE_ALIGN_BY)
780#define DUK_USE_ALIGN_BY 8
781#endif
782#undef DUK_USE_PACKED_TVAL
783#define DUK_F_PACKED_TVAL_PROVIDED
784#elif defined(DUK_F_PPC32)
785/* --- PowerPC 32-bit --- */
786#define DUK_USE_ARCH_STRING "ppc32"
787#if !defined(DUK_USE_BYTEORDER)
788#define DUK_USE_BYTEORDER 3
789#endif
790#if !defined(DUK_USE_ALIGN_BY)
791#define DUK_USE_ALIGN_BY 8
792#endif
793#define DUK_USE_PACKED_TVAL
794#define DUK_F_PACKED_TVAL_PROVIDED
795#elif defined(DUK_F_PPC64)
796/* --- PowerPC 64-bit --- */
797#define DUK_USE_ARCH_STRING "ppc64"
798#if !defined(DUK_USE_BYTEORDER)
799#define DUK_USE_BYTEORDER 3
800#endif
801#if !defined(DUK_USE_ALIGN_BY)
802#define DUK_USE_ALIGN_BY 8
803#endif
804#undef DUK_USE_PACKED_TVAL
805#define DUK_F_PACKED_TVAL_PROVIDED
806#elif defined(DUK_F_SPARC32)
807/* --- SPARC 32-bit --- */
808#define DUK_USE_ARCH_STRING "sparc32"
809/* SPARC byte order varies so rely on autodetection. */
810#if !defined(DUK_USE_ALIGN_BY)
811#define DUK_USE_ALIGN_BY 8
812#endif
813#define DUK_USE_PACKED_TVAL
814#define DUK_F_PACKED_TVAL_PROVIDED
815#elif defined(DUK_F_SPARC64)
816/* --- SPARC 64-bit --- */
817#define DUK_USE_ARCH_STRING "sparc64"
818/* SPARC byte order varies so rely on autodetection. */
819#if !defined(DUK_USE_ALIGN_BY)
820#define DUK_USE_ALIGN_BY 8
821#endif
822#undef DUK_USE_PACKED_TVAL
823#define DUK_F_PACKED_TVAL_PROVIDED
824#elif defined(DUK_F_SUPERH)
825/* --- SuperH --- */
826#define DUK_USE_ARCH_STRING "sh"
827/* Byte order varies, rely on autodetection. */
828/* Based on 'make checkalign' there are no alignment requirements on
829 * Linux SH4, but align by 4 is probably a good basic default.
830 */
831#if !defined(DUK_USE_ALIGN_BY)
832#define DUK_USE_ALIGN_BY 4
833#endif
834#define DUK_USE_PACKED_TVAL
835#define DUK_F_PACKED_TVAL_PROVIDED
836#elif defined(DUK_F_M68K)
837/* --- Motorola 68k --- */
838#define DUK_USE_ARCH_STRING "m68k"
839#if !defined(DUK_USE_BYTEORDER)
840#define DUK_USE_BYTEORDER 3
841#endif
842#if !defined(DUK_USE_ALIGN_BY)
843#define DUK_USE_ALIGN_BY 8
844#endif
845#define DUK_USE_PACKED_TVAL
846#define DUK_F_PACKED_TVAL_PROVIDED
847#elif defined(DUK_F_EMSCRIPTEN)
848/* --- Emscripten --- */
849#define DUK_USE_ARCH_STRING "emscripten"
850#if !defined(DUK_USE_BYTEORDER)
851#define DUK_USE_BYTEORDER 1
852#endif
853#if !defined(DUK_USE_ALIGN_BY)
854#define DUK_USE_ALIGN_BY 8
855#endif
856#undef DUK_USE_PACKED_TVAL
857#define DUK_F_PACKED_TVAL_PROVIDED
858#else
859/* --- Generic --- */
860/* These are necessary wild guesses. */
861#define DUK_USE_ARCH_STRING "generic"
862/* Rely on autodetection for byte order, alignment, and packed tval. */
863#endif /* autodetect architecture */
864
865/*
866 * Compiler autodetection
867 */
868
869#if defined(DUK_F_CLANG)
870/* --- Clang --- */
871#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
872/* C99 / C++11 and above: rely on va_copy() which is required. */
873#define DUK_VA_COPY(dest,src) va_copy(dest,src)
874#else
875/* Clang: assume we have __va_copy() in non-C99 mode. */
876#define DUK_VA_COPY(dest,src) __va_copy(dest,src)
877#endif
878
879#define DUK_NORETURN(decl) decl __attribute__((noreturn))
880
881#if defined(__clang__) && defined(__has_builtin)
882#if __has_builtin(__builtin_unreachable)
883#define DUK_UNREACHABLE() do { __builtin_unreachable(); } while (0)
884#endif
885#endif
886
887#define DUK_USE_BRANCH_HINTS
888#define DUK_LIKELY(x) __builtin_expect((x), 1)
889#define DUK_UNLIKELY(x) __builtin_expect((x), 0)
890
891#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
892#define DUK_NOINLINE __attribute__((noinline))
893#define DUK_INLINE inline
894#define DUK_ALWAYS_INLINE inline __attribute__((always_inline))
895#endif
896
897#if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
898/* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
899 * compiling Duktape or the application.
900 */
901#if defined(DUK_COMPILING_DUKTAPE)
902#define DUK_EXTERNAL_DECL extern __declspec(dllexport)
903#define DUK_EXTERNAL __declspec(dllexport)
904#else
905#define DUK_EXTERNAL_DECL extern __declspec(dllimport)
906#define DUK_EXTERNAL should_not_happen
907#endif
908#if defined(DUK_SINGLE_FILE)
909#define DUK_INTERNAL_DECL static
910#define DUK_INTERNAL static
911#else
912#define DUK_INTERNAL_DECL extern
913#define DUK_INTERNAL /*empty*/
914#endif
915#define DUK_LOCAL_DECL static
916#define DUK_LOCAL static
917#else
918#define DUK_EXTERNAL_DECL __attribute__ ((visibility("default"))) extern
919#define DUK_EXTERNAL __attribute__ ((visibility("default")))
920#if defined(DUK_SINGLE_FILE)
921#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
922/* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
923 * Clang. Based on documentation it should suffice to have the attribute
924 * in the declaration only, but in practice some warnings are generated unless
925 * the attribute is also applied to the definition.
926 */
927#define DUK_INTERNAL_DECL static __attribute__ ((unused))
928#define DUK_INTERNAL static __attribute__ ((unused))
929#else
930#define DUK_INTERNAL_DECL static
931#define DUK_INTERNAL static
932#endif
933#else
934#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
935#define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
936#define DUK_INTERNAL __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
937#else
938#define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) extern
939#define DUK_INTERNAL __attribute__ ((visibility("hidden")))
940#endif
941#endif
942#define DUK_LOCAL_DECL static
943#define DUK_LOCAL static
944#endif
945
946#if defined(DUK_F_CPP)
947#define DUK_USE_COMPILER_STRING "clang"
948#else
949#define DUK_USE_COMPILER_STRING "clang"
950#endif
951
952#undef DUK_USE_VARIADIC_MACROS
953#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
954#define DUK_USE_VARIADIC_MACROS
955#endif
956
957#define DUK_USE_UNION_INITIALIZERS
958
959#undef DUK_USE_FLEX_C99
960#undef DUK_USE_FLEX_ZEROSIZE
961#undef DUK_USE_FLEX_ONESIZE
962#if defined(DUK_F_C99)
963#define DUK_USE_FLEX_C99
964#else
965#define DUK_USE_FLEX_ZEROSIZE
966#endif
967
968#undef DUK_USE_GCC_PRAGMAS
969#define DUK_USE_PACK_CLANG_ATTR
970#elif defined(DUK_F_GCC)
971/* --- GCC --- */
972#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
973/* C99 / C++11 and above: rely on va_copy() which is required. */
974#define DUK_VA_COPY(dest,src) va_copy(dest,src)
975#else
976/* GCC: assume we have __va_copy() in non-C99 mode. */
977#define DUK_VA_COPY(dest,src) __va_copy(dest,src)
978#endif
979
980#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 20500L)
981/* since gcc-2.5 */
982#define DUK_NORETURN(decl) decl __attribute__((noreturn))
983#endif
984
985#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40500L)
986/* since gcc-4.5 */
987#define DUK_UNREACHABLE() do { __builtin_unreachable(); } while (0)
988#endif
989
990#define DUK_USE_BRANCH_HINTS
991#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40500L)
992/* GCC: test not very accurate; enable only in relatively recent builds
993 * because of bugs in gcc-4.4 (http://lists.debian.org/debian-gcc/2010/04/msg00000.html)
994 */
995#define DUK_LIKELY(x) __builtin_expect((x), 1)
996#define DUK_UNLIKELY(x) __builtin_expect((x), 0)
997#endif
998
999#if (defined(DUK_F_C99) || defined(DUK_F_CPP11)) && \
1000 defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 30101)
1001#define DUK_NOINLINE __attribute__((noinline))
1002#define DUK_INLINE inline
1003#define DUK_ALWAYS_INLINE inline __attribute__((always_inline))
1004#endif
1005
1006#if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
1007/* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
1008 * compiling Duktape or the application.
1009 */
1010#if defined(DUK_COMPILING_DUKTAPE)
1011#define DUK_EXTERNAL_DECL extern __declspec(dllexport)
1012#define DUK_EXTERNAL __declspec(dllexport)
1013#else
1014#define DUK_EXTERNAL_DECL extern __declspec(dllimport)
1015#define DUK_EXTERNAL should_not_happen
1016#endif
1017#if defined(DUK_SINGLE_FILE)
1018#define DUK_INTERNAL_DECL static
1019#define DUK_INTERNAL static
1020#else
1021#define DUK_INTERNAL_DECL extern
1022#define DUK_INTERNAL /*empty*/
1023#endif
1024#define DUK_LOCAL_DECL static
1025#define DUK_LOCAL static
1026#elif defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40000)
1027#define DUK_EXTERNAL_DECL __attribute__ ((visibility("default"))) extern
1028#define DUK_EXTERNAL __attribute__ ((visibility("default")))
1029#if defined(DUK_SINGLE_FILE)
1030#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
1031/* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
1032 * Clang. Based on documentation it should suffice to have the attribute
1033 * in the declaration only, but in practice some warnings are generated unless
1034 * the attribute is also applied to the definition.
1035 */
1036#define DUK_INTERNAL_DECL static __attribute__ ((unused))
1037#define DUK_INTERNAL static __attribute__ ((unused))
1038#else
1039#define DUK_INTERNAL_DECL static
1040#define DUK_INTERNAL static
1041#endif
1042#else
1043#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
1044#define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
1045#define DUK_INTERNAL __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
1046#else
1047#define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) extern
1048#define DUK_INTERNAL __attribute__ ((visibility("hidden")))
1049#endif
1050#endif
1051#define DUK_LOCAL_DECL static
1052#define DUK_LOCAL static
1053#endif
1054
1055#if defined(DUK_F_MINGW)
1056#if defined(DUK_F_CPP)
1057#define DUK_USE_COMPILER_STRING "mingw++"
1058#else
1059#define DUK_USE_COMPILER_STRING "mingw"
1060#endif
1061#else
1062#if defined(DUK_F_CPP)
1063#define DUK_USE_COMPILER_STRING "g++"
1064#else
1065#define DUK_USE_COMPILER_STRING "gcc"
1066#endif
1067#endif
1068
1069#undef DUK_USE_VARIADIC_MACROS
1070#if defined(DUK_F_C99) || (defined(DUK_F_CPP11) && defined(__GNUC__))
1071#define DUK_USE_VARIADIC_MACROS
1072#endif
1073
1074#define DUK_USE_UNION_INITIALIZERS
1075
1076#undef DUK_USE_FLEX_C99
1077#undef DUK_USE_FLEX_ZEROSIZE
1078#undef DUK_USE_FLEX_ONESIZE
1079#if defined(DUK_F_C99)
1080#define DUK_USE_FLEX_C99
1081#else
1082#define DUK_USE_FLEX_ZEROSIZE
1083#endif
1084
1085#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40600)
1086#define DUK_USE_GCC_PRAGMAS
1087#else
1088#undef DUK_USE_GCC_PRAGMAS
1089#endif
1090
1091#define DUK_USE_PACK_GCC_ATTR
1092#elif defined(DUK_F_MSVC)
1093/* --- MSVC --- */
1094/* http://msdn.microsoft.com/en-us/library/aa235362(VS.60).aspx */
1095#define DUK_NORETURN(decl) __declspec(noreturn) decl
1096
1097/* XXX: DUK_UNREACHABLE for msvc? */
1098
1099#undef DUK_USE_BRANCH_HINTS
1100
1101/* XXX: DUK_LIKELY, DUK_UNLIKELY for msvc? */
1102/* XXX: DUK_NOINLINE, DUK_INLINE, DUK_ALWAYS_INLINE for msvc? */
1103
1104#if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
1105/* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
1106 * compiling Duktape or the application.
1107 */
1108#if defined(DUK_COMPILING_DUKTAPE)
1109#define DUK_EXTERNAL_DECL extern __declspec(dllexport)
1110#define DUK_EXTERNAL __declspec(dllexport)
1111#else
1112#define DUK_EXTERNAL_DECL extern __declspec(dllimport)
1113#define DUK_EXTERNAL should_not_happen
1114#endif
1115#if defined(DUK_SINGLE_FILE)
1116#define DUK_INTERNAL_DECL static
1117#define DUK_INTERNAL static
1118#else
1119#define DUK_INTERNAL_DECL extern
1120#define DUK_INTERNAL /*empty*/
1121#endif
1122#define DUK_LOCAL_DECL static
1123#define DUK_LOCAL static
1124#endif
1125
1126#if defined(DUK_F_CPP)
1127#define DUK_USE_COMPILER_STRING "msvc++"
1128#else
1129#define DUK_USE_COMPILER_STRING "msvc"
1130#endif
1131
1132#undef DUK_USE_VARIADIC_MACROS
1133#if defined(DUK_F_C99)
1134#define DUK_USE_VARIADIC_MACROS
1135#elif defined(_MSC_VER) && (_MSC_VER >= 1400)
1136/* VS2005+ should have variadic macros even when they're not C99. */
1137#define DUK_USE_VARIADIC_MACROS
1138#endif
1139
1140#undef DUK_USE_UNION_INITIALIZERS
1141#if defined(_MSC_VER) && (_MSC_VER >= 1800)
1142/* VS2013+ supports union initializers but there's a bug involving union-inside-struct:
1143 * https://connect.microsoft.com/VisualStudio/feedback/details/805981
1144 * The bug was fixed (at least) in VS2015 so check for VS2015 for now:
1145 * https://blogs.msdn.microsoft.com/vcblog/2015/07/01/c-compiler-front-end-fixes-in-vs2015/
1146 * Manually tested using VS2013, CL reports 18.00.31101, so enable for VS2013 too.
1147 */
1148#define DUK_USE_UNION_INITIALIZERS
1149#endif
1150
1151#undef DUK_USE_FLEX_C99
1152#undef DUK_USE_FLEX_ZEROSIZE
1153#undef DUK_USE_FLEX_ONESIZE
1154#if defined(DUK_F_C99)
1155#define DUK_USE_FLEX_C99
1156#else
1157#define DUK_USE_FLEX_ZEROSIZE
1158#endif
1159
1160#undef DUK_USE_GCC_PRAGMAS
1161
1162#define DUK_USE_PACK_MSVC_PRAGMA
1163
1164/* These have been tested from VS2008 onwards; may work in older VS versions
1165 * too but not enabled by default.
1166 */
1167#if defined(_MSC_VER) && (_MSC_VER >= 1500)
1168#define DUK_NOINLINE __declspec(noinline)
1169#define DUK_INLINE __inline
1170#define DUK_ALWAYS_INLINE __forceinline
1171#endif
1172
1173#if defined(_MSC_VER) && (_MSC_VER >= 1900)
1174#define DUK_SNPRINTF snprintf
1175#define DUK_VSNPRINTF vsnprintf
1176#else
1177/* (v)snprintf() is missing before MSVC 2015. Note that _(v)snprintf() does
1178 * NOT NUL terminate on truncation, but Duktape code never assumes that.
1179 * http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
1180 */
1181#define DUK_SNPRINTF _snprintf
1182#define DUK_VSNPRINTF _vsnprintf
1183#endif
1184#elif defined(DUK_F_EMSCRIPTEN)
1185/* --- Emscripten --- */
1186#define DUK_NORETURN(decl) decl __attribute__((noreturn))
1187
1188#if defined(__clang__) && defined(__has_builtin)
1189#if __has_builtin(__builtin_unreachable)
1190#define DUK_UNREACHABLE() do { __builtin_unreachable(); } while (0)
1191#endif
1192#endif
1193
1194#define DUK_USE_BRANCH_HINTS
1195#define DUK_LIKELY(x) __builtin_expect((x), 1)
1196#define DUK_UNLIKELY(x) __builtin_expect((x), 0)
1197
1198#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
1199#define DUK_NOINLINE __attribute__((noinline))
1200#define DUK_INLINE inline
1201#define DUK_ALWAYS_INLINE inline __attribute__((always_inline))
1202#endif
1203
1204#define DUK_EXTERNAL_DECL __attribute__ ((visibility("default"))) extern
1205#define DUK_EXTERNAL __attribute__ ((visibility("default")))
1206#if defined(DUK_SINGLE_FILE)
1207#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
1208/* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
1209 * Clang. Based on documentation it should suffice to have the attribute
1210 * in the declaration only, but in practice some warnings are generated unless
1211 * the attribute is also applied to the definition.
1212 */
1213#define DUK_INTERNAL_DECL static __attribute__ ((unused))
1214#define DUK_INTERNAL static __attribute__ ((unused))
1215#else
1216#define DUK_INTERNAL_DECL static
1217#define DUK_INTERNAL static
1218#endif
1219#else
1220#if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
1221#define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
1222#define DUK_INTERNAL __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
1223#else
1224#define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) extern
1225#define DUK_INTERNAL __attribute__ ((visibility("hidden")))
1226#endif
1227#endif
1228#define DUK_LOCAL_DECL static
1229#define DUK_LOCAL static
1230
1231#define DUK_USE_COMPILER_STRING "emscripten"
1232
1233#undef DUK_USE_VARIADIC_MACROS
1234#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
1235#define DUK_USE_VARIADIC_MACROS
1236#endif
1237
1238#define DUK_USE_UNION_INITIALIZERS
1239
1240#undef DUK_USE_FLEX_C99
1241#undef DUK_USE_FLEX_ZEROSIZE
1242#undef DUK_USE_FLEX_ONESIZE
1243#if defined(DUK_F_C99)
1244#define DUK_USE_FLEX_C99
1245#else
1246#define DUK_USE_FLEX_ZEROSIZE
1247#endif
1248
1249#undef DUK_USE_GCC_PRAGMAS
1250#define DUK_USE_PACK_CLANG_ATTR
1251#elif defined(DUK_F_TINYC)
1252/* --- TinyC --- */
1253#undef DUK_USE_BRANCH_HINTS
1254
1255#if defined(DUK_F_CPP)
1256#define DUK_USE_COMPILER_STRING "tinyc++"
1257#else
1258#define DUK_USE_COMPILER_STRING "tinyc"
1259#endif
1260
1261/* http://bellard.org/tcc/tcc-doc.html#SEC7 */
1262#define DUK_USE_VARIADIC_MACROS
1263
1264#define DUK_USE_UNION_INITIALIZERS
1265
1266/* Most portable, wastes space */
1267#define DUK_USE_FLEX_ONESIZE
1268
1269/* Most portable, potentially wastes space */
1270#define DUK_USE_PACK_DUMMY_MEMBER
1271#elif defined(DUK_F_VBCC)
1272/* --- VBCC --- */
1273#undef DUK_USE_BRANCH_HINTS
1274
1275#if defined(DUK_F_CPP)
1276#define DUK_USE_COMPILER_STRING "vbcc-c++"
1277#else
1278#define DUK_USE_COMPILER_STRING "vbcc"
1279#endif
1280
1281#undef DUK_USE_VARIADIC_MACROS
1282#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
1283#define DUK_USE_VARIADIC_MACROS
1284#endif
1285
1286/* VBCC supports C99 so check only for C99 for union initializer support.
1287 * Designated union initializers would possibly work even without a C99 check.
1288 */
1289#undef DUK_USE_UNION_INITIALIZERS
1290#if defined(DUK_F_C99)
1291#define DUK_USE_UNION_INITIALIZERS
1292#endif
1293
1294#define DUK_USE_FLEX_ZEROSIZE
1295#define DUK_USE_PACK_DUMMY_MEMBER
1296#elif defined(DUK_F_BCC)
1297/* --- Bruce's C compiler --- */
1298#undef DUK_USE_BRANCH_HINTS
1299
1300#if defined(DUK_F_CPP)
1301#define DUK_USE_COMPILER_STRING "bcc++"
1302#else
1303#define DUK_USE_COMPILER_STRING "bcc"
1304#endif
1305
1306/* Most portable */
1307#undef DUK_USE_VARIADIC_MACROS
1308
1309/* Most portable, wastes space */
1310#undef DUK_USE_UNION_INITIALIZERS
1311
1312/* Most portable, wastes space */
1313#define DUK_USE_FLEX_ONESIZE
1314
1315/* Most portable, potentially wastes space */
1316#define DUK_USE_PACK_DUMMY_MEMBER
1317
1318/* BCC, assume we're on x86. */
1319#if !defined(DUK_USE_BYTEORDER)
1320#define DUK_USE_BYTEORDER 1
1321#endif
1322#else
1323/* --- Generic --- */
1324#undef DUK_USE_BRANCH_HINTS
1325
1326#if defined(DUK_F_CPP)
1327#define DUK_USE_COMPILER_STRING "generic-c++"
1328#else
1329#define DUK_USE_COMPILER_STRING "generic"
1330#endif
1331
1332#undef DUK_USE_VARIADIC_MACROS
1333#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
1334#define DUK_USE_VARIADIC_MACROS
1335#endif
1336
1337/* C++ doesn't have standard designated union initializers ({ .foo = 1 }). */
1338#undef DUK_USE_UNION_INITIALIZERS
1339#if defined(DUK_F_C99)
1340#define DUK_USE_UNION_INITIALIZERS
1341#endif
1342
1343/* Most portable, wastes space */
1344#define DUK_USE_FLEX_ONESIZE
1345
1346/* Most portable, potentially wastes space */
1347#define DUK_USE_PACK_DUMMY_MEMBER
1348#endif /* autodetect compiler */
1349
1350/* uclibc */
1351#if defined(__UCLIBC__)
1352#define DUK_F_UCLIBC
1353#endif
1354
1355/*
1356 * Wrapper typedefs and constants for integer types, also sanity check types.
1357 *
1358 * C99 typedefs are quite good but not always available, and we want to avoid
1359 * forcibly redefining the C99 typedefs. So, there are Duktape wrappers for
1360 * all C99 typedefs and Duktape code should only use these typedefs. Type
1361 * detection when C99 is not supported is best effort and may end up detecting
1362 * some types incorrectly.
1363 *
1364 * Pointer sizes are a portability problem: pointers to different types may
1365 * have a different size and function pointers are very difficult to manage
1366 * portably.
1367 *
1368 * http://en.wikipedia.org/wiki/C_data_types#Fixed-width_integer_types
1369 *
1370 * Note: there's an interesting corner case when trying to define minimum
1371 * signed integer value constants which leads to the current workaround of
1372 * defining e.g. -0x80000000 as (-0x7fffffffL - 1L). See doc/code-issues.txt
1373 * for a longer discussion.
1374 *
1375 * Note: avoid typecasts and computations in macro integer constants as they
1376 * can then no longer be used in macro relational expressions (such as
1377 * #if DUK_SIZE_MAX < 0xffffffffUL). There is internal code which relies on
1378 * being able to compare DUK_SIZE_MAX against a limit.
1379 */
1380
1381/* XXX: add feature options to force basic types from outside? */
1382
1383#if !defined(INT_MAX)
1384#error INT_MAX not defined
1385#endif
1386
1387/* Check that architecture is two's complement, standard C allows e.g.
1388 * INT_MIN to be -2**31+1 (instead of -2**31).
1389 */
1390#if defined(INT_MAX) && defined(INT_MIN)
1391#if INT_MAX != -(INT_MIN + 1)
1392#error platform does not seem complement of two
1393#endif
1394#else
1395#error cannot check complement of two
1396#endif
1397
1398/* Pointer size determination based on __WORDSIZE or architecture when
1399 * that's not available.
1400 */
1401#if defined(DUK_F_X86) || defined(DUK_F_X32) || \
1402 defined(DUK_F_M68K) || defined(DUK_F_PPC32) || \
1403 defined(DUK_F_BCC) || \
1404 (defined(__WORDSIZE) && (__WORDSIZE == 32))
1405#define DUK_F_32BIT_PTRS
1406#elif defined(DUK_F_X64) || \
1407 (defined(__WORDSIZE) && (__WORDSIZE == 64))
1408#define DUK_F_64BIT_PTRS
7c673cae
FG
1409#else
1410/* not sure, not needed with C99 anyway */
1411#endif
1412
1413/* Intermediate define for 'have inttypes.h' */
1414#undef DUK_F_HAVE_INTTYPES
1415#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
1416 !(defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC))
1417/* vbcc + AmigaOS has C99 but no inttypes.h */
1418#define DUK_F_HAVE_INTTYPES
1419#elif defined(__cplusplus) && (__cplusplus >= 201103L)
1420/* C++11 apparently ratified stdint.h */
1421#define DUK_F_HAVE_INTTYPES
1422#endif
1423
1424/* Basic integer typedefs and limits, preferably from inttypes.h, otherwise
1425 * through automatic detection.
1426 */
1427#if defined(DUK_F_HAVE_INTTYPES)
1428/* C99 or compatible */
1429
1430#define DUK_F_HAVE_64BIT
1431#include <inttypes.h>
1432
1433typedef uint8_t duk_uint8_t;
1434typedef int8_t duk_int8_t;
1435typedef uint16_t duk_uint16_t;
1436typedef int16_t duk_int16_t;
1437typedef uint32_t duk_uint32_t;
1438typedef int32_t duk_int32_t;
1439typedef uint64_t duk_uint64_t;
1440typedef int64_t duk_int64_t;
1441typedef uint_least8_t duk_uint_least8_t;
1442typedef int_least8_t duk_int_least8_t;
1443typedef uint_least16_t duk_uint_least16_t;
1444typedef int_least16_t duk_int_least16_t;
1445typedef uint_least32_t duk_uint_least32_t;
1446typedef int_least32_t duk_int_least32_t;
1447typedef uint_least64_t duk_uint_least64_t;
1448typedef int_least64_t duk_int_least64_t;
1449typedef uint_fast8_t duk_uint_fast8_t;
1450typedef int_fast8_t duk_int_fast8_t;
1451typedef uint_fast16_t duk_uint_fast16_t;
1452typedef int_fast16_t duk_int_fast16_t;
1453typedef uint_fast32_t duk_uint_fast32_t;
1454typedef int_fast32_t duk_int_fast32_t;
1455typedef uint_fast64_t duk_uint_fast64_t;
1456typedef int_fast64_t duk_int_fast64_t;
1457typedef uintptr_t duk_uintptr_t;
1458typedef intptr_t duk_intptr_t;
1459typedef uintmax_t duk_uintmax_t;
1460typedef intmax_t duk_intmax_t;
1461
1462#define DUK_UINT8_MIN 0
1463#define DUK_UINT8_MAX UINT8_MAX
1464#define DUK_INT8_MIN INT8_MIN
1465#define DUK_INT8_MAX INT8_MAX
1466#define DUK_UINT_LEAST8_MIN 0
1467#define DUK_UINT_LEAST8_MAX UINT_LEAST8_MAX
1468#define DUK_INT_LEAST8_MIN INT_LEAST8_MIN
1469#define DUK_INT_LEAST8_MAX INT_LEAST8_MAX
1470#define DUK_UINT_FAST8_MIN 0
1471#define DUK_UINT_FAST8_MAX UINT_FAST8_MAX
1472#define DUK_INT_FAST8_MIN INT_FAST8_MIN
1473#define DUK_INT_FAST8_MAX INT_FAST8_MAX
1474#define DUK_UINT16_MIN 0
1475#define DUK_UINT16_MAX UINT16_MAX
1476#define DUK_INT16_MIN INT16_MIN
1477#define DUK_INT16_MAX INT16_MAX
1478#define DUK_UINT_LEAST16_MIN 0
1479#define DUK_UINT_LEAST16_MAX UINT_LEAST16_MAX
1480#define DUK_INT_LEAST16_MIN INT_LEAST16_MIN
1481#define DUK_INT_LEAST16_MAX INT_LEAST16_MAX
1482#define DUK_UINT_FAST16_MIN 0
1483#define DUK_UINT_FAST16_MAX UINT_FAST16_MAX
1484#define DUK_INT_FAST16_MIN INT_FAST16_MIN
1485#define DUK_INT_FAST16_MAX INT_FAST16_MAX
1486#define DUK_UINT32_MIN 0
1487#define DUK_UINT32_MAX UINT32_MAX
1488#define DUK_INT32_MIN INT32_MIN
1489#define DUK_INT32_MAX INT32_MAX
1490#define DUK_UINT_LEAST32_MIN 0
1491#define DUK_UINT_LEAST32_MAX UINT_LEAST32_MAX
1492#define DUK_INT_LEAST32_MIN INT_LEAST32_MIN
1493#define DUK_INT_LEAST32_MAX INT_LEAST32_MAX
1494#define DUK_UINT_FAST32_MIN 0
1495#define DUK_UINT_FAST32_MAX UINT_FAST32_MAX
1496#define DUK_INT_FAST32_MIN INT_FAST32_MIN
1497#define DUK_INT_FAST32_MAX INT_FAST32_MAX
1498#define DUK_UINT64_MIN 0
1499#define DUK_UINT64_MAX UINT64_MAX
1500#define DUK_INT64_MIN INT64_MIN
1501#define DUK_INT64_MAX INT64_MAX
1502#define DUK_UINT_LEAST64_MIN 0
1503#define DUK_UINT_LEAST64_MAX UINT_LEAST64_MAX
1504#define DUK_INT_LEAST64_MIN INT_LEAST64_MIN
1505#define DUK_INT_LEAST64_MAX INT_LEAST64_MAX
1506#define DUK_UINT_FAST64_MIN 0
1507#define DUK_UINT_FAST64_MAX UINT_FAST64_MAX
1508#define DUK_INT_FAST64_MIN INT_FAST64_MIN
1509#define DUK_INT_FAST64_MAX INT_FAST64_MAX
1510
1511#define DUK_UINTPTR_MIN 0
1512#define DUK_UINTPTR_MAX UINTPTR_MAX
1513#define DUK_INTPTR_MIN INTPTR_MIN
1514#define DUK_INTPTR_MAX INTPTR_MAX
1515
1516#define DUK_UINTMAX_MIN 0
1517#define DUK_UINTMAX_MAX UINTMAX_MAX
1518#define DUK_INTMAX_MIN INTMAX_MIN
1519#define DUK_INTMAX_MAX INTMAX_MAX
1520
1521#define DUK_SIZE_MIN 0
1522#define DUK_SIZE_MAX SIZE_MAX
1523#undef DUK_SIZE_MAX_COMPUTED
1524
1525#else /* C99 types */
1526
1527/* When C99 types are not available, we use heuristic detection to get
1528 * the basic 8, 16, 32, and (possibly) 64 bit types. The fast/least
1529 * types are then assumed to be exactly the same for now: these could
1530 * be improved per platform but C99 types are very often now available.
1531 * 64-bit types are not available on all platforms; this is OK at least
1532 * on 32-bit platforms.
1533 *
1534 * This detection code is necessarily a bit hacky and can provide typedefs
1535 * and defines that won't work correctly on some exotic platform.
1536 */
1537
1538#if (defined(CHAR_BIT) && (CHAR_BIT == 8)) || \
1539 (defined(UCHAR_MAX) && (UCHAR_MAX == 255))
1540typedef unsigned char duk_uint8_t;
1541typedef signed char duk_int8_t;
1542#else
1543#error cannot detect 8-bit type
1544#endif
1545
1546#if defined(USHRT_MAX) && (USHRT_MAX == 65535UL)
1547typedef unsigned short duk_uint16_t;
1548typedef signed short duk_int16_t;
1549#elif defined(UINT_MAX) && (UINT_MAX == 65535UL)
1550/* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */
1551typedef unsigned int duk_uint16_t;
1552typedef signed int duk_int16_t;
1553#else
1554#error cannot detect 16-bit type
1555#endif
1556
1557#if defined(UINT_MAX) && (UINT_MAX == 4294967295UL)
1558typedef unsigned int duk_uint32_t;
1559typedef signed int duk_int32_t;
1560#elif defined(ULONG_MAX) && (ULONG_MAX == 4294967295UL)
1561/* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */
1562typedef unsigned long duk_uint32_t;
1563typedef signed long duk_int32_t;
1564#else
1565#error cannot detect 32-bit type
1566#endif
1567
1568/* 64-bit type detection is a bit tricky.
1569 *
1570 * ULLONG_MAX is a standard define. __LONG_LONG_MAX__ and __ULONG_LONG_MAX__
1571 * are used by at least GCC (even if system headers don't provide ULLONG_MAX).
1572 * Some GCC variants may provide __LONG_LONG_MAX__ but not __ULONG_LONG_MAX__.
1573 *
1574 * ULL / LL constants are rejected / warned about by some compilers, even if
1575 * the compiler has a 64-bit type and the compiler/system headers provide an
1576 * unsupported constant (ULL/LL)! Try to avoid using ULL / LL constants.
1577 * As a side effect we can only check that e.g. ULONG_MAX is larger than 32
1578 * bits but can't be sure it is exactly 64 bits. Self tests will catch such
1579 * cases.
1580 */
1581#undef DUK_F_HAVE_64BIT
1582#if !defined(DUK_F_HAVE_64BIT) && defined(ULONG_MAX)
1583#if (ULONG_MAX > 4294967295UL)
1584#define DUK_F_HAVE_64BIT
1585typedef unsigned long duk_uint64_t;
1586typedef signed long duk_int64_t;
1587#endif
1588#endif
1589#if !defined(DUK_F_HAVE_64BIT) && defined(ULLONG_MAX)
1590#if (ULLONG_MAX > 4294967295UL)
1591#define DUK_F_HAVE_64BIT
1592typedef unsigned long long duk_uint64_t;
1593typedef signed long long duk_int64_t;
1594#endif
1595#endif
1596#if !defined(DUK_F_HAVE_64BIT) && defined(__ULONG_LONG_MAX__)
1597#if (__ULONG_LONG_MAX__ > 4294967295UL)
1598#define DUK_F_HAVE_64BIT
1599typedef unsigned long long duk_uint64_t;
1600typedef signed long long duk_int64_t;
1601#endif
1602#endif
1603#if !defined(DUK_F_HAVE_64BIT) && defined(__LONG_LONG_MAX__)
1604#if (__LONG_LONG_MAX__ > 2147483647L)
1605#define DUK_F_HAVE_64BIT
1606typedef unsigned long long duk_uint64_t;
1607typedef signed long long duk_int64_t;
1608#endif
1609#endif
1610#if !defined(DUK_F_HAVE_64BIT) && \
1611 (defined(DUK_F_MINGW) || defined(DUK_F_MSVC))
1612/* Both MinGW and MSVC have a 64-bit type. */
1613#define DUK_F_HAVE_64BIT
1614typedef unsigned long duk_uint64_t;
1615typedef signed long duk_int64_t;
1616#endif
1617#if !defined(DUK_F_HAVE_64BIT)
1618/* cannot detect 64-bit type, not always needed so don't error */
1619#endif
1620
1621typedef duk_uint8_t duk_uint_least8_t;
1622typedef duk_int8_t duk_int_least8_t;
1623typedef duk_uint16_t duk_uint_least16_t;
1624typedef duk_int16_t duk_int_least16_t;
1625typedef duk_uint32_t duk_uint_least32_t;
1626typedef duk_int32_t duk_int_least32_t;
1627typedef duk_uint8_t duk_uint_fast8_t;
1628typedef duk_int8_t duk_int_fast8_t;
1629typedef duk_uint16_t duk_uint_fast16_t;
1630typedef duk_int16_t duk_int_fast16_t;
1631typedef duk_uint32_t duk_uint_fast32_t;
1632typedef duk_int32_t duk_int_fast32_t;
1633#if defined(DUK_F_HAVE_64BIT)
1634typedef duk_uint64_t duk_uint_least64_t;
1635typedef duk_int64_t duk_int_least64_t;
1636typedef duk_uint64_t duk_uint_fast64_t;
1637typedef duk_int64_t duk_int_fast64_t;
1638#endif
1639#if defined(DUK_F_HAVE_64BIT)
1640typedef duk_uint64_t duk_uintmax_t;
1641typedef duk_int64_t duk_intmax_t;
1642#else
1643typedef duk_uint32_t duk_uintmax_t;
1644typedef duk_int32_t duk_intmax_t;
1645#endif
1646
1647/* Note: the funny looking computations for signed minimum 16-bit, 32-bit, and
1648 * 64-bit values are intentional as the obvious forms (e.g. -0x80000000L) are
1649 * -not- portable. See code-issues.txt for a detailed discussion.
1650 */
1651#define DUK_UINT8_MIN 0UL
1652#define DUK_UINT8_MAX 0xffUL
1653#define DUK_INT8_MIN (-0x80L)
1654#define DUK_INT8_MAX 0x7fL
1655#define DUK_UINT_LEAST8_MIN 0UL
1656#define DUK_UINT_LEAST8_MAX 0xffUL
1657#define DUK_INT_LEAST8_MIN (-0x80L)
1658#define DUK_INT_LEAST8_MAX 0x7fL
1659#define DUK_UINT_FAST8_MIN 0UL
1660#define DUK_UINT_FAST8_MAX 0xffUL
1661#define DUK_INT_FAST8_MIN (-0x80L)
1662#define DUK_INT_FAST8_MAX 0x7fL
1663#define DUK_UINT16_MIN 0UL
1664#define DUK_UINT16_MAX 0xffffUL
1665#define DUK_INT16_MIN (-0x7fffL - 1L)
1666#define DUK_INT16_MAX 0x7fffL
1667#define DUK_UINT_LEAST16_MIN 0UL
1668#define DUK_UINT_LEAST16_MAX 0xffffUL
1669#define DUK_INT_LEAST16_MIN (-0x7fffL - 1L)
1670#define DUK_INT_LEAST16_MAX 0x7fffL
1671#define DUK_UINT_FAST16_MIN 0UL
1672#define DUK_UINT_FAST16_MAX 0xffffUL
1673#define DUK_INT_FAST16_MIN (-0x7fffL - 1L)
1674#define DUK_INT_FAST16_MAX 0x7fffL
1675#define DUK_UINT32_MIN 0UL
1676#define DUK_UINT32_MAX 0xffffffffUL
1677#define DUK_INT32_MIN (-0x7fffffffL - 1L)
1678#define DUK_INT32_MAX 0x7fffffffL
1679#define DUK_UINT_LEAST32_MIN 0UL
1680#define DUK_UINT_LEAST32_MAX 0xffffffffUL
1681#define DUK_INT_LEAST32_MIN (-0x7fffffffL - 1L)
1682#define DUK_INT_LEAST32_MAX 0x7fffffffL
1683#define DUK_UINT_FAST32_MIN 0UL
1684#define DUK_UINT_FAST32_MAX 0xffffffffUL
1685#define DUK_INT_FAST32_MIN (-0x7fffffffL - 1L)
1686#define DUK_INT_FAST32_MAX 0x7fffffffL
1687
1688/* 64-bit constants. Since LL / ULL constants are not always available,
1689 * use computed values. These values can't be used in preprocessor
1690 * comparisons; flag them as such.
1691 */
1692#if defined(DUK_F_HAVE_64BIT)
1693#define DUK_UINT64_MIN ((duk_uint64_t) 0)
1694#define DUK_UINT64_MAX ((duk_uint64_t) -1)
1695#define DUK_INT64_MIN ((duk_int64_t) (~(DUK_UINT64_MAX >> 1)))
1696#define DUK_INT64_MAX ((duk_int64_t) (DUK_UINT64_MAX >> 1))
1697#define DUK_UINT_LEAST64_MIN DUK_UINT64_MIN
1698#define DUK_UINT_LEAST64_MAX DUK_UINT64_MAX
1699#define DUK_INT_LEAST64_MIN DUK_INT64_MIN
1700#define DUK_INT_LEAST64_MAX DUK_INT64_MAX
1701#define DUK_UINT_FAST64_MIN DUK_UINT64_MIN
1702#define DUK_UINT_FAST64_MAX DUK_UINT64_MAX
1703#define DUK_INT_FAST64_MIN DUK_INT64_MIN
1704#define DUK_INT_FAST64_MAX DUK_INT64_MAX
1705#define DUK_UINT64_MIN_COMPUTED
1706#define DUK_UINT64_MAX_COMPUTED
1707#define DUK_INT64_MIN_COMPUTED
1708#define DUK_INT64_MAX_COMPUTED
1709#define DUK_UINT_LEAST64_MIN_COMPUTED
1710#define DUK_UINT_LEAST64_MAX_COMPUTED
1711#define DUK_INT_LEAST64_MIN_COMPUTED
1712#define DUK_INT_LEAST64_MAX_COMPUTED
1713#define DUK_UINT_FAST64_MIN_COMPUTED
1714#define DUK_UINT_FAST64_MAX_COMPUTED
1715#define DUK_INT_FAST64_MIN_COMPUTED
1716#define DUK_INT_FAST64_MAX_COMPUTED
1717#endif
1718
1719#if defined(DUK_F_HAVE_64BIT)
1720#define DUK_UINTMAX_MIN DUK_UINT64_MIN
1721#define DUK_UINTMAX_MAX DUK_UINT64_MAX
1722#define DUK_INTMAX_MIN DUK_INT64_MIN
1723#define DUK_INTMAX_MAX DUK_INT64_MAX
1724#define DUK_UINTMAX_MIN_COMPUTED
1725#define DUK_UINTMAX_MAX_COMPUTED
1726#define DUK_INTMAX_MIN_COMPUTED
1727#define DUK_INTMAX_MAX_COMPUTED
1728#else
1729#define DUK_UINTMAX_MIN 0UL
1730#define DUK_UINTMAX_MAX 0xffffffffUL
1731#define DUK_INTMAX_MIN (-0x7fffffffL - 1L)
1732#define DUK_INTMAX_MAX 0x7fffffffL
1733#endif
1734
1735/* This detection is not very reliable. */
1736#if defined(DUK_F_32BIT_PTRS)
1737typedef duk_int32_t duk_intptr_t;
1738typedef duk_uint32_t duk_uintptr_t;
1739#define DUK_UINTPTR_MIN DUK_UINT32_MIN
1740#define DUK_UINTPTR_MAX DUK_UINT32_MAX
1741#define DUK_INTPTR_MIN DUK_INT32_MIN
1742#define DUK_INTPTR_MAX DUK_INT32_MAX
1743#elif defined(DUK_F_64BIT_PTRS) && defined(DUK_F_HAVE_64BIT)
1744typedef duk_int64_t duk_intptr_t;
1745typedef duk_uint64_t duk_uintptr_t;
1746#define DUK_UINTPTR_MIN DUK_UINT64_MIN
1747#define DUK_UINTPTR_MAX DUK_UINT64_MAX
1748#define DUK_INTPTR_MIN DUK_INT64_MIN
1749#define DUK_INTPTR_MAX DUK_INT64_MAX
1750#define DUK_UINTPTR_MIN_COMPUTED
1751#define DUK_UINTPTR_MAX_COMPUTED
1752#define DUK_INTPTR_MIN_COMPUTED
1753#define DUK_INTPTR_MAX_COMPUTED
1754#else
1755#error cannot determine intptr type
1756#endif
1757
1758/* SIZE_MAX may be missing so use an approximate value for it. */
1759#undef DUK_SIZE_MAX_COMPUTED
1760#if !defined(SIZE_MAX)
1761#define DUK_SIZE_MAX_COMPUTED
1762#define SIZE_MAX ((size_t) (-1))
1763#endif
1764#define DUK_SIZE_MIN 0
1765#define DUK_SIZE_MAX SIZE_MAX
1766
1767#endif /* C99 types */
1768
1769/* A few types are assumed to always exist. */
1770typedef size_t duk_size_t;
1771typedef ptrdiff_t duk_ptrdiff_t;
1772
1773/* The best type for an "all around int" in Duktape internals is "at least
1774 * 32 bit signed integer" which is most convenient. Same for unsigned type.
1775 * Prefer 'int' when large enough, as it is almost always a convenient type.
1776 */
1777#if defined(UINT_MAX) && (UINT_MAX >= 0xffffffffUL)
1778typedef int duk_int_t;
1779typedef unsigned int duk_uint_t;
1780#define DUK_INT_MIN INT_MIN
37b3c998
TL
1781#define DUK_INT_MAX INT_MAX
1782#define DUK_UINT_MIN 0
1783#define DUK_UINT_MAX UINT_MAX
7c673cae 1784#else
37b3c998
TL
1785typedef duk_int_fast32_t duk_int_t;
1786typedef duk_uint_fast32_t duk_uint_t;
1787#define DUK_INT_MIN DUK_INT_FAST32_MIN
1788#define DUK_INT_MAX DUK_INT_FAST32_MAX
1789#define DUK_UINT_MIN DUK_UINT_FAST32_MIN
1790#define DUK_UINT_MAX DUK_UINT_FAST32_MAX
7c673cae 1791#endif
7c673cae 1792
37b3c998
TL
1793/* Same as 'duk_int_t' but guaranteed to be a 'fast' variant if this
1794 * distinction matters for the CPU. These types are used mainly in the
1795 * executor where it might really matter.
7c673cae 1796 */
37b3c998
TL
1797typedef duk_int_fast32_t duk_int_fast_t;
1798typedef duk_uint_fast32_t duk_uint_fast_t;
1799#define DUK_INT_FAST_MIN DUK_INT_FAST32_MIN
1800#define DUK_INT_FAST_MAX DUK_INT_FAST32_MAX
1801#define DUK_UINT_FAST_MIN DUK_UINT_FAST32_MIN
1802#define DUK_UINT_FAST_MAX DUK_UINT_FAST32_MAX
7c673cae 1803
37b3c998
TL
1804/* Small integers (16 bits or more) can fall back to the 'int' type, but
1805 * have a typedef so they are marked "small" explicitly.
7c673cae 1806 */
37b3c998
TL
1807typedef int duk_small_int_t;
1808typedef unsigned int duk_small_uint_t;
1809#define DUK_SMALL_INT_MIN INT_MIN
1810#define DUK_SMALL_INT_MAX INT_MAX
1811#define DUK_SMALL_UINT_MIN 0
1812#define DUK_SMALL_UINT_MAX UINT_MAX
1813
1814/* Fast variants of small integers, again for really fast paths like the
1815 * executor.
7c673cae 1816 */
37b3c998
TL
1817typedef duk_int_fast16_t duk_small_int_fast_t;
1818typedef duk_uint_fast16_t duk_small_uint_fast_t;
1819#define DUK_SMALL_INT_FAST_MIN DUK_INT_FAST16_MIN
1820#define DUK_SMALL_INT_FAST_MAX DUK_INT_FAST16_MAX
1821#define DUK_SMALL_UINT_FAST_MIN DUK_UINT_FAST16_MIN
1822#define DUK_SMALL_UINT_FAST_MAX DUK_UINT_FAST16_MAX
7c673cae 1823
37b3c998
TL
1824/* Boolean values are represented with the platform 'int'. */
1825typedef duk_small_int_t duk_bool_t;
1826#define DUK_BOOL_MIN DUK_SMALL_INT_MIN
1827#define DUK_BOOL_MAX DUK_SMALL_INT_MAX
7c673cae 1828
37b3c998
TL
1829/* Index values must have at least 32-bit signed range. */
1830typedef duk_int_t duk_idx_t;
1831#define DUK_IDX_MIN DUK_INT_MIN
1832#define DUK_IDX_MAX DUK_INT_MAX
7c673cae 1833
37b3c998
TL
1834/* Unsigned index variant. */
1835typedef duk_uint_t duk_uidx_t;
1836#define DUK_UIDX_MIN DUK_UINT_MIN
1837#define DUK_UIDX_MAX DUK_UINT_MAX
1838
1839/* Array index values, could be exact 32 bits.
1840 * Currently no need for signed duk_arridx_t.
7c673cae 1841 */
37b3c998
TL
1842typedef duk_uint_t duk_uarridx_t;
1843#define DUK_UARRIDX_MIN DUK_UINT_MIN
1844#define DUK_UARRIDX_MAX DUK_UINT_MAX
1845
1846/* Duktape/C function return value, platform int is enough for now to
1847 * represent 0, 1, or negative error code. Must be compatible with
1848 * assigning truth values (e.g. duk_ret_t rc = (foo == bar);).
7c673cae 1849 */
37b3c998
TL
1850typedef duk_small_int_t duk_ret_t;
1851#define DUK_RET_MIN DUK_SMALL_INT_MIN
1852#define DUK_RET_MAX DUK_SMALL_INT_MAX
7c673cae 1853
37b3c998
TL
1854/* Error codes are represented with platform int. High bits are used
1855 * for flags and such, so 32 bits are needed.
7c673cae 1856 */
37b3c998
TL
1857typedef duk_int_t duk_errcode_t;
1858#define DUK_ERRCODE_MIN DUK_INT_MIN
1859#define DUK_ERRCODE_MAX DUK_INT_MAX
7c673cae 1860
37b3c998
TL
1861/* Codepoint type. Must be 32 bits or more because it is used also for
1862 * internal codepoints. The type is signed because negative codepoints
1863 * are used as internal markers (e.g. to mark EOF or missing argument).
1864 * (X)UTF-8/CESU-8 encode/decode take and return an unsigned variant to
1865 * ensure duk_uint32_t casts back and forth nicely. Almost everything
1866 * else uses the signed one.
1867 */
1868typedef duk_int_t duk_codepoint_t;
1869typedef duk_uint_t duk_ucodepoint_t;
1870#define DUK_CODEPOINT_MIN DUK_INT_MIN
1871#define DUK_CODEPOINT_MAX DUK_INT_MAX
1872#define DUK_UCODEPOINT_MIN DUK_UINT_MIN
1873#define DUK_UCODEPOINT_MAX DUK_UINT_MAX
1874
1875/* IEEE float/double typedef. */
1876typedef float duk_float_t;
1877typedef double duk_double_t;
1878
1879/* We're generally assuming that we're working on a platform with a 32-bit
1880 * address space. If DUK_SIZE_MAX is a typecast value (which is necessary
1881 * if SIZE_MAX is missing), the check must be avoided because the
1882 * preprocessor can't do a comparison.
1883 */
1884#if !defined(DUK_SIZE_MAX)
1885#error DUK_SIZE_MAX is undefined, probably missing SIZE_MAX
1886#elif !defined(DUK_SIZE_MAX_COMPUTED)
1887#if DUK_SIZE_MAX < 0xffffffffUL
1888/* On some systems SIZE_MAX can be smaller than max unsigned 32-bit value
1889 * which seems incorrect if size_t is (at least) an unsigned 32-bit type.
1890 * However, it doesn't seem useful to error out compilation if this is the
1891 * case.
7c673cae 1892 */
7c673cae
FG
1893#endif
1894#endif
1895
37b3c998
TL
1896/* Type for public API calls. */
1897typedef struct duk_hthread duk_context;
7c673cae 1898
37b3c998
TL
1899/* Check whether we should use 64-bit integers or not.
1900 *
1901 * Quite incomplete now. Use 64-bit types if detected (C99 or other detection)
1902 * unless they are known to be unreliable. For instance, 64-bit types are
1903 * available on VBCC but seem to misbehave.
7c673cae 1904 */
37b3c998
TL
1905#if defined(DUK_F_HAVE_64BIT) && !defined(DUK_F_VBCC)
1906#define DUK_USE_64BIT_OPS
7c673cae 1907#else
37b3c998
TL
1908#undef DUK_USE_64BIT_OPS
1909#endif
7c673cae
FG
1910
1911/*
37b3c998 1912 * Fill-ins for platform, architecture, and compiler
7c673cae
FG
1913 */
1914
37b3c998
TL
1915#if !defined(DUK_SETJMP)
1916#define DUK_JMPBUF_TYPE jmp_buf
1917#define DUK_SETJMP(jb) setjmp((jb))
1918#define DUK_LONGJMP(jb) longjmp((jb), 1)
7c673cae 1919#endif
37b3c998
TL
1920
1921#if 0
1922/* sigsetjmp() alternative */
1923#define DUK_JMPBUF_TYPE sigjmp_buf
1924#define DUK_SETJMP(jb) sigsetjmp((jb))
1925#define DUK_LONGJMP(jb) siglongjmp((jb), 1)
7c673cae
FG
1926#endif
1927
37b3c998
TL
1928typedef FILE duk_file;
1929#if !defined(DUK_STDIN)
1930#define DUK_STDIN stdin
1931#endif
1932#if !defined(DUK_STDOUT)
1933#define DUK_STDOUT stdout
7c673cae 1934#endif
37b3c998
TL
1935#if !defined(DUK_STDERR)
1936#define DUK_STDERR stderr
7c673cae
FG
1937#endif
1938
37b3c998
TL
1939/* Special naming to avoid conflict with e.g. DUK_FREE() in duk_heap.h
1940 * (which is unfortunately named). May sometimes need replacement, e.g.
1941 * some compilers don't handle zero length or NULL correctly in realloc().
1942 */
1943#if !defined(DUK_ANSI_MALLOC)
1944#define DUK_ANSI_MALLOC malloc
7c673cae 1945#endif
37b3c998
TL
1946#if !defined(DUK_ANSI_REALLOC)
1947#define DUK_ANSI_REALLOC realloc
7c673cae 1948#endif
37b3c998
TL
1949#if !defined(DUK_ANSI_CALLOC)
1950#define DUK_ANSI_CALLOC calloc
7c673cae 1951#endif
37b3c998
TL
1952#if !defined(DUK_ANSI_FREE)
1953#define DUK_ANSI_FREE free
7c673cae
FG
1954#endif
1955
37b3c998
TL
1956/* ANSI C (various versions) and some implementations require that the
1957 * pointer arguments to memset(), memcpy(), and memmove() be valid values
1958 * even when byte size is 0 (even a NULL pointer is considered invalid in
1959 * this context). Zero-size operations as such are allowed, as long as their
1960 * pointer arguments point to a valid memory area. The DUK_MEMSET(),
1961 * DUK_MEMCPY(), and DUK_MEMMOVE() macros require this same behavior, i.e.:
1962 * (1) pointers must be valid and non-NULL, (2) zero size must otherwise be
1963 * allowed. If these are not fulfilled, a macro wrapper is needed.
1964 *
1965 * http://stackoverflow.com/questions/5243012/is-it-guaranteed-to-be-safe-to-perform-memcpy0-0-0
1966 * http://lists.cs.uiuc.edu/pipermail/llvmdev/2007-October/011065.html
1967 *
1968 * Not sure what's the required behavior when a pointer points just past the
1969 * end of a buffer, which often happens in practice (e.g. zero size memmoves).
1970 * For example, if allocation size is 3, the following pointer would not
1971 * technically point to a valid memory byte:
1972 *
1973 * <-- alloc -->
1974 * | 0 | 1 | 2 | .....
1975 * ^-- p=3, points after last valid byte (2)
7c673cae 1976 */
37b3c998
TL
1977#if !defined(DUK_MEMCPY)
1978#if defined(DUK_F_UCLIBC)
1979/* Old uclibcs have a broken memcpy so use memmove instead (this is overly wide
1980 * now on purpose): http://lists.uclibc.org/pipermail/uclibc-cvs/2008-October/025511.html
7c673cae 1981 */
37b3c998
TL
1982#define DUK_MEMCPY memmove
1983#else
1984#define DUK_MEMCPY memcpy
7c673cae 1985#endif
37b3c998
TL
1986#endif
1987#if !defined(DUK_MEMMOVE)
1988#define DUK_MEMMOVE memmove
1989#endif
1990#if !defined(DUK_MEMCMP)
1991#define DUK_MEMCMP memcmp
1992#endif
1993#if !defined(DUK_MEMSET)
1994#define DUK_MEMSET memset
1995#endif
1996#if !defined(DUK_STRLEN)
1997#define DUK_STRLEN strlen
1998#endif
1999#if !defined(DUK_STRCMP)
2000#define DUK_STRCMP strcmp
2001#endif
2002#if !defined(DUK_STRNCMP)
2003#define DUK_STRNCMP strncmp
2004#endif
2005#if !defined(DUK_PRINTF)
2006#define DUK_PRINTF printf
2007#endif
2008#if !defined(DUK_FPRINTF)
2009#define DUK_FPRINTF fprintf
2010#endif
2011#if !defined(DUK_SPRINTF)
2012#define DUK_SPRINTF sprintf
2013#endif
2014#if !defined(DUK_SNPRINTF)
2015/* snprintf() is technically not part of C89 but usually available. */
2016#define DUK_SNPRINTF snprintf
2017#endif
2018#if !defined(DUK_VSPRINTF)
2019#define DUK_VSPRINTF vsprintf
2020#endif
2021#if !defined(DUK_VSNPRINTF)
2022/* vsnprintf() is technically not part of C89 but usually available. */
2023#define DUK_VSNPRINTF vsnprintf
2024#endif
2025#if !defined(DUK_SSCANF)
2026#define DUK_SSCANF sscanf
2027#endif
2028#if !defined(DUK_VSSCANF)
2029#define DUK_VSSCANF vsscanf
2030#endif
2031#if !defined(DUK_FOPEN)
2032#define DUK_FOPEN fopen
2033#endif
2034#if !defined(DUK_FCLOSE)
2035#define DUK_FCLOSE fclose
2036#endif
2037#if !defined(DUK_FREAD)
2038#define DUK_FREAD fread
2039#endif
2040#if !defined(DUK_FWRITE)
2041#define DUK_FWRITE fwrite
2042#endif
2043#if !defined(DUK_FSEEK)
2044#define DUK_FSEEK fseek
2045#endif
2046#if !defined(DUK_FTELL)
2047#define DUK_FTELL ftell
2048#endif
2049#if !defined(DUK_FFLUSH)
2050#define DUK_FFLUSH fflush
2051#endif
2052#if !defined(DUK_FPUTC)
2053#define DUK_FPUTC fputc
2054#endif
2055#if !defined(DUK_MEMZERO)
2056#define DUK_MEMZERO(p,n) DUK_MEMSET((p), 0, (n))
2057#endif
2058#if !defined(DUK_ABORT)
2059#define DUK_ABORT abort
2060#endif
2061#if !defined(DUK_EXIT)
2062#define DUK_EXIT exit
7c673cae
FG
2063#endif
2064
37b3c998 2065#if !defined(DUK_DOUBLE_2TO32)
7c673cae 2066#define DUK_DOUBLE_2TO32 4294967296.0
37b3c998
TL
2067#endif
2068#if !defined(DUK_DOUBLE_2TO31)
7c673cae 2069#define DUK_DOUBLE_2TO31 2147483648.0
37b3c998 2070#endif
7c673cae 2071
37b3c998 2072#if !defined(DUK_DOUBLE_INFINITY)
7c673cae
FG
2073#undef DUK_USE_COMPUTED_INFINITY
2074#if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION < 40600)
2075/* GCC older than 4.6: avoid overflow warnings related to using INFINITY */
2076#define DUK_DOUBLE_INFINITY (__builtin_inf())
2077#elif defined(INFINITY)
2078#define DUK_DOUBLE_INFINITY ((double) INFINITY)
2079#elif !defined(DUK_F_VBCC) && !defined(DUK_F_MSVC) && !defined(DUK_F_BCC)
2080#define DUK_DOUBLE_INFINITY (1.0 / 0.0)
2081#else
2082/* In VBCC (1.0 / 0.0) results in a warning and 0.0 instead of infinity.
2083 * Use a computed infinity (initialized when a heap is created at the
2084 * latest).
2085 */
7c673cae
FG
2086#define DUK_USE_COMPUTED_INFINITY
2087#define DUK_DOUBLE_INFINITY duk_computed_infinity
2088#endif
37b3c998 2089#endif
7c673cae 2090
37b3c998 2091#if !defined(DUK_DOUBLE_NAN)
7c673cae
FG
2092#undef DUK_USE_COMPUTED_NAN
2093#if defined(NAN)
2094#define DUK_DOUBLE_NAN NAN
2095#elif !defined(DUK_F_VBCC) && !defined(DUK_F_MSVC) && !defined(DUK_F_BCC)
2096#define DUK_DOUBLE_NAN (0.0 / 0.0)
2097#else
2098/* In VBCC (0.0 / 0.0) results in a warning and 0.0 instead of NaN.
2099 * In MSVC (VS2010 Express) (0.0 / 0.0) results in a compile error.
2100 * Use a computed NaN (initialized when a heap is created at the
2101 * latest).
2102 */
7c673cae
FG
2103#define DUK_USE_COMPUTED_NAN
2104#define DUK_DOUBLE_NAN duk_computed_nan
2105#endif
37b3c998 2106#endif
7c673cae
FG
2107
2108/* Many platforms are missing fpclassify() and friends, so use replacements
2109 * if necessary. The replacement constants (FP_NAN etc) can be anything but
2110 * match Linux constants now.
2111 */
2112#undef DUK_USE_REPL_FPCLASSIFY
2113#undef DUK_USE_REPL_SIGNBIT
2114#undef DUK_USE_REPL_ISFINITE
2115#undef DUK_USE_REPL_ISNAN
2116#undef DUK_USE_REPL_ISINF
2117
2118/* Complex condition broken into separate parts. */
2119#undef DUK_F_USE_REPL_ALL
2120#if !(defined(FP_NAN) && defined(FP_INFINITE) && defined(FP_ZERO) && \
2121 defined(FP_SUBNORMAL) && defined(FP_NORMAL))
2122/* Missing some obvious constants. */
2123#define DUK_F_USE_REPL_ALL
2124#elif defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC)
37b3c998
TL
2125/* VBCC is missing the built-ins even in C99 mode (perhaps a header issue). */
2126#define DUK_F_USE_REPL_ALL
2127#elif defined(DUK_F_AMIGAOS) && defined(DUK_F_M68K)
2128/* AmigaOS + M68K seems to have math issues even when using GCC cross
2129 * compilation. Use replacements for all AmigaOS versions on M68K
2130 * regardless of compiler.
2131 */
7c673cae
FG
2132#define DUK_F_USE_REPL_ALL
2133#elif defined(DUK_F_FREEBSD) && defined(DUK_F_CLANG)
2134/* Placeholder fix for (detection is wider than necessary):
2135 * http://llvm.org/bugs/show_bug.cgi?id=17788
2136 */
2137#define DUK_F_USE_REPL_ALL
2138#elif defined(DUK_F_UCLIBC)
2139/* At least some uclibc versions have broken floating point math. For
2140 * example, fpclassify() can incorrectly classify certain NaN formats.
2141 * To be safe, use replacements.
2142 */
2143#define DUK_F_USE_REPL_ALL
2144#endif
2145
2146#if defined(DUK_F_USE_REPL_ALL)
2147#define DUK_USE_REPL_FPCLASSIFY
2148#define DUK_USE_REPL_SIGNBIT
2149#define DUK_USE_REPL_ISFINITE
2150#define DUK_USE_REPL_ISNAN
2151#define DUK_USE_REPL_ISINF
2152#define DUK_FPCLASSIFY duk_repl_fpclassify
2153#define DUK_SIGNBIT duk_repl_signbit
2154#define DUK_ISFINITE duk_repl_isfinite
2155#define DUK_ISNAN duk_repl_isnan
2156#define DUK_ISINF duk_repl_isinf
2157#define DUK_FP_NAN 0
2158#define DUK_FP_INFINITE 1
2159#define DUK_FP_ZERO 2
2160#define DUK_FP_SUBNORMAL 3
2161#define DUK_FP_NORMAL 4
2162#else
2163#define DUK_FPCLASSIFY fpclassify
2164#define DUK_SIGNBIT signbit
2165#define DUK_ISFINITE isfinite
2166#define DUK_ISNAN isnan
2167#define DUK_ISINF isinf
2168#define DUK_FP_NAN FP_NAN
2169#define DUK_FP_INFINITE FP_INFINITE
2170#define DUK_FP_ZERO FP_ZERO
2171#define DUK_FP_SUBNORMAL FP_SUBNORMAL
2172#define DUK_FP_NORMAL FP_NORMAL
2173#endif
2174
2175#if defined(DUK_F_USE_REPL_ALL)
2176#undef DUK_F_USE_REPL_ALL
2177#endif
2178
2179/* Some math functions are C99 only. This is also an issue with some
2180 * embedded environments using uclibc where uclibc has been configured
2181 * not to provide some functions. For now, use replacements whenever
2182 * using uclibc.
2183 */
2184#undef DUK_USE_MATH_FMIN
2185#undef DUK_USE_MATH_FMAX
2186#undef DUK_USE_MATH_ROUND
2187#if defined(DUK_F_UCLIBC)
2188/* uclibc may be missing these */
2189#elif defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC)
2190/* vbcc + AmigaOS may be missing these */
37b3c998
TL
2191#elif defined(DUK_F_MINT)
2192/* mint clib is missing these */
7c673cae
FG
2193#elif !defined(DUK_F_C99) && !defined(DUK_F_CPP11)
2194/* build is not C99 or C++11, play it safe */
2195#else
2196/* C99 or C++11, no known issues */
2197#define DUK_USE_MATH_FMIN
2198#define DUK_USE_MATH_FMAX
2199#define DUK_USE_MATH_ROUND
2200#endif
2201
2202/* These functions don't currently need replacement but are wrapped for
2203 * completeness. Because these are used as function pointers, they need
2204 * to be defined as concrete C functions (not macros).
2205 */
37b3c998 2206#if !defined(DUK_FABS)
7c673cae 2207#define DUK_FABS fabs
37b3c998
TL
2208#endif
2209#if !defined(DUK_FMIN)
7c673cae 2210#define DUK_FMIN fmin
37b3c998
TL
2211#endif
2212#if !defined(DUK_FMAX)
7c673cae 2213#define DUK_FMAX fmax
37b3c998
TL
2214#endif
2215#if !defined(DUK_FLOOR)
7c673cae 2216#define DUK_FLOOR floor
37b3c998
TL
2217#endif
2218#if !defined(DUK_CEIL)
7c673cae 2219#define DUK_CEIL ceil
37b3c998
TL
2220#endif
2221#if !defined(DUK_FMOD)
7c673cae 2222#define DUK_FMOD fmod
37b3c998
TL
2223#endif
2224#if !defined(DUK_POW)
7c673cae 2225#define DUK_POW pow
37b3c998
TL
2226#endif
2227#if !defined(DUK_ACOS)
7c673cae 2228#define DUK_ACOS acos
37b3c998
TL
2229#endif
2230#if !defined(DUK_ASIN)
7c673cae 2231#define DUK_ASIN asin
37b3c998
TL
2232#endif
2233#if !defined(DUK_ATAN)
7c673cae 2234#define DUK_ATAN atan
37b3c998
TL
2235#endif
2236#if !defined(DUK_ATAN2)
7c673cae 2237#define DUK_ATAN2 atan2
37b3c998
TL
2238#endif
2239#if !defined(DUK_SIN)
7c673cae 2240#define DUK_SIN sin
37b3c998
TL
2241#endif
2242#if !defined(DUK_COS)
7c673cae 2243#define DUK_COS cos
37b3c998
TL
2244#endif
2245#if !defined(DUK_TAN)
7c673cae 2246#define DUK_TAN tan
37b3c998
TL
2247#endif
2248#if !defined(DUK_EXP)
7c673cae 2249#define DUK_EXP exp
37b3c998
TL
2250#endif
2251#if !defined(DUK_LOG)
7c673cae 2252#define DUK_LOG log
37b3c998
TL
2253#endif
2254#if !defined(DUK_SQRT)
7c673cae 2255#define DUK_SQRT sqrt
37b3c998 2256#endif
7c673cae
FG
2257
2258/* NetBSD 6.0 x86 (at least) has a few problems with pow() semantics,
2259 * see test-bug-netbsd-math-pow.js. Use NetBSD specific workaround.
2260 * (This might be a wider problem; if so, generalize the define name.)
2261 */
2262#undef DUK_USE_POW_NETBSD_WORKAROUND
2263#if defined(DUK_F_NETBSD)
2264#define DUK_USE_POW_NETBSD_WORKAROUND
2265#endif
2266
2267/* Rely as little as possible on compiler behavior for NaN comparison,
2268 * signed zero handling, etc. Currently never activated but may be needed
2269 * for broken compilers.
2270 */
2271#undef DUK_USE_PARANOID_MATH
2272
2273/* There was a curious bug where test-bi-date-canceling.js would fail e.g.
2274 * on 64-bit Ubuntu, gcc-4.8.1, -m32, and no -std=c99. Some date computations
2275 * using doubles would be optimized which then broke some corner case tests.
2276 * The problem goes away by adding 'volatile' to the datetime computations.
2277 * Not sure what the actual triggering conditions are, but using this on
2278 * non-C99 systems solves the known issues and has relatively little cost
37b3c998 2279 * on other platforms.
7c673cae
FG
2280 */
2281#undef DUK_USE_PARANOID_DATE_COMPUTATION
2282#if !defined(DUK_F_C99)
2283#define DUK_USE_PARANOID_DATE_COMPUTATION
2284#endif
2285
2286/*
37b3c998 2287 * Byte order and double memory layout detection
7c673cae 2288 *
37b3c998
TL
2289 * Endianness detection is a major portability hassle because the macros
2290 * and headers are not standardized. There's even variance across UNIX
2291 * platforms. Even with "standard" headers, details like underscore count
2292 * varies between platforms, e.g. both __BYTE_ORDER and _BYTE_ORDER are used
2293 * (Crossbridge has a single underscore, for instance).
7c673cae 2294 *
37b3c998
TL
2295 * The checks below are structured with this in mind: several approaches are
2296 * used, and at the end we check if any of them worked. This allows generic
2297 * approaches to be tried first, and platform/compiler specific hacks tried
2298 * last. As a last resort, the user can force a specific endianness, as it's
2299 * not likely that automatic detection will work on the most exotic platforms.
7c673cae 2300 *
37b3c998
TL
2301 * Duktape supports little and big endian machines. There's also support
2302 * for a hybrid used by some ARM machines where integers are little endian
2303 * but IEEE double values use a mixed order (12345678 -> 43218765). This
2304 * byte order for doubles is referred to as "mixed endian".
7c673cae 2305 */
7c673cae 2306
37b3c998
TL
2307/* For custom platforms allow user to define byteorder explicitly.
2308 * Since endianness headers are not standardized, this is a useful
2309 * workaround for custom platforms for which endianness detection
2310 * is not directly supported. Perhaps custom hardware is used and
2311 * user cannot submit upstream patches.
7c673cae 2312 */
37b3c998
TL
2313#if defined(DUK_OPT_FORCE_BYTEORDER)
2314#undef DUK_USE_BYTEORDER
2315#if (DUK_OPT_FORCE_BYTEORDER == 1)
2316#define DUK_USE_BYTEORDER 1
2317#elif (DUK_OPT_FORCE_BYTEORDER == 2)
2318#define DUK_USE_BYTEORDER 2
2319#elif (DUK_OPT_FORCE_BYTEORDER == 3)
2320#define DUK_USE_BYTEORDER 3
7c673cae 2321#else
37b3c998 2322#error invalid DUK_OPT_FORCE_BYTEORDER value
7c673cae 2323#endif
37b3c998 2324#endif /* DUK_OPT_FORCE_BYTEORDER */
7c673cae 2325
37b3c998
TL
2326/* GCC and Clang provide endianness defines as built-in predefines, with
2327 * leading and trailing double underscores (e.g. __BYTE_ORDER__). See
2328 * output of "make gccpredefs" and "make clangpredefs". Clang doesn't
2329 * seem to provide __FLOAT_WORD_ORDER__; assume not mixed endian for clang.
2330 * http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
2331 */
2332#if !defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__)
2333#if defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
2334#if defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__)
2335#define DUK_USE_BYTEORDER 1
2336#elif defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)
2337#define DUK_USE_BYTEORDER 2
2338#elif !defined(__FLOAT_WORD_ORDER__)
2339/* Float word order not known, assume not a hybrid. */
2340#define DUK_USE_BYTEORDER 1
2341#else
2342/* Byte order is little endian but cannot determine IEEE double word order. */
2343#endif /* float word order */
2344#elif defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
2345#if defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)
2346#define DUK_USE_BYTEORDER 3
2347#elif !defined(__FLOAT_WORD_ORDER__)
2348/* Float word order not known, assume not a hybrid. */
2349#define DUK_USE_BYTEORDER 3
2350#else
2351/* Byte order is big endian but cannot determine IEEE double word order. */
2352#endif /* float word order */
2353#else
2354/* Cannot determine byte order; __ORDER_PDP_ENDIAN__ is related to 32-bit
2355 * integer ordering and is not relevant.
2356 */
2357#endif /* integer byte order */
2358#endif /* !defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__) */
7c673cae 2359
37b3c998
TL
2360/* More or less standard endianness predefines provided by header files.
2361 * The ARM hybrid case is detected by assuming that __FLOAT_WORD_ORDER
2362 * will be big endian, see: http://lists.mysql.com/internals/443.
2363 * On some platforms some defines may be present with an empty value which
2364 * causes comparisons to fail: https://github.com/svaarala/duktape/issues/453.
7c673cae 2365 */
37b3c998
TL
2366#if !defined(DUK_USE_BYTEORDER)
2367#if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && (__BYTE_ORDER == __LITTLE_ENDIAN) || \
2368 defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN) && (_BYTE_ORDER == _LITTLE_ENDIAN) || \
2369 defined(__LITTLE_ENDIAN__)
2370#if defined(__FLOAT_WORD_ORDER) && defined(__LITTLE_ENDIAN) && (__FLOAT_WORD_ORDER == __LITTLE_ENDIAN) || \
2371 defined(_FLOAT_WORD_ORDER) && defined(_LITTLE_ENDIAN) && (_FLOAT_WORD_ORDER == _LITTLE_ENDIAN)
2372#define DUK_USE_BYTEORDER 1
2373#elif defined(__FLOAT_WORD_ORDER) && defined(__BIG_ENDIAN) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) || \
2374 defined(_FLOAT_WORD_ORDER) && defined(_BIG_ENDIAN) && (_FLOAT_WORD_ORDER == _BIG_ENDIAN)
2375#define DUK_USE_BYTEORDER 2
2376#elif !defined(__FLOAT_WORD_ORDER) && !defined(_FLOAT_WORD_ORDER)
2377/* Float word order not known, assume not a hybrid. */
2378#define DUK_USE_BYTEORDER 1
7c673cae 2379#else
37b3c998
TL
2380/* Byte order is little endian but cannot determine IEEE double word order. */
2381#endif /* float word order */
2382#elif defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && (__BYTE_ORDER == __BIG_ENDIAN) || \
2383 defined(_BYTE_ORDER) && defined(_BIG_ENDIAN) && (_BYTE_ORDER == _BIG_ENDIAN) || \
2384 defined(__BIG_ENDIAN__)
2385#if defined(__FLOAT_WORD_ORDER) && defined(__BIG_ENDIAN) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) || \
2386 defined(_FLOAT_WORD_ORDER) && defined(_BIG_ENDIAN) && (_FLOAT_WORD_ORDER == _BIG_ENDIAN)
2387#define DUK_USE_BYTEORDER 3
2388#elif !defined(__FLOAT_WORD_ORDER) && !defined(_FLOAT_WORD_ORDER)
2389/* Float word order not known, assume not a hybrid. */
2390#define DUK_USE_BYTEORDER 3
2391#else
2392/* Byte order is big endian but cannot determine IEEE double word order. */
2393#endif /* float word order */
2394#else
2395/* Cannot determine byte order. */
2396#endif /* integer byte order */
2397#endif /* !defined(DUK_USE_BYTEORDER) */
2398
2399/* QNX gcc cross compiler seems to define e.g. __LITTLEENDIAN__ or __BIGENDIAN__:
2400 * $ /opt/qnx650/host/linux/x86/usr/bin/i486-pc-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
2401 * 67:#define __LITTLEENDIAN__ 1
2402 * $ /opt/qnx650/host/linux/x86/usr/bin/mips-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
2403 * 81:#define __BIGENDIAN__ 1
2404 * $ /opt/qnx650/host/linux/x86/usr/bin/arm-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
2405 * 70:#define __LITTLEENDIAN__ 1
2406 */
2407#if !defined(DUK_USE_BYTEORDER)
2408#if defined(__LITTLEENDIAN__)
2409#define DUK_USE_BYTEORDER 1
2410#elif defined(__BIGENDIAN__)
2411#define DUK_USE_BYTEORDER 3
2412#endif
7c673cae
FG
2413#endif
2414
37b3c998
TL
2415/*
2416 * Alignment requirement and support for unaligned accesses
2417 *
2418 * Assume unaligned accesses are not supported unless specifically allowed
2419 * in the target platform. Some platforms may support unaligned accesses
2420 * but alignment to 4 or 8 may still be desirable.
2421 */
7c673cae 2422
37b3c998
TL
2423/* If not provided, use safe default for alignment. */
2424#if !defined(DUK_USE_ALIGN_BY)
2425#define DUK_USE_ALIGN_BY 8
7c673cae 2426#endif
7c673cae 2427
37b3c998
TL
2428/* User forced alignment to 4 or 8. */
2429#if defined(DUK_OPT_FORCE_ALIGN)
2430#undef DUK_USE_ALIGN_BY
2431#if (DUK_OPT_FORCE_ALIGN == 4)
2432#define DUK_USE_ALIGN_BY 4
2433#elif (DUK_OPT_FORCE_ALIGN == 8)
2434#define DUK_USE_ALIGN_BY 8
2435#else
2436#error invalid DUK_OPT_FORCE_ALIGN value
2437#endif
2438#endif
7c673cae 2439
37b3c998
TL
2440/* Compiler specific hackery needed to force struct size to match aligment,
2441 * see e.g. duk_hbuffer.h.
2442 *
2443 * http://stackoverflow.com/questions/11130109/c-struct-size-alignment
2444 * http://stackoverflow.com/questions/10951039/specifying-64-bit-alignment
7c673cae 2445 */
37b3c998
TL
2446#if !(defined(DUK_USE_PACK_MSVC_PRAGMA) || defined(DUK_USE_PACK_GCC_ATTR) || \
2447 defined(DUK_USE_PACK_CLANG_ATTR) || defined(DUK_USE_PACK_DUMMY_MEMBER))
2448#define DUK_USE_PACK_DUMMY_MEMBER
2449#endif
7c673cae 2450
37b3c998
TL
2451#if !defined(DUK_VA_COPY)
2452/* We need va_copy() which is defined in C99 / C++11, so an awkward
2453 * replacement is needed for pre-C99 / pre-C++11 environments. This
2454 * will quite likely need portability hacks for some non-C99
2455 * environments.
2456 */
7c673cae
FG
2457#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
2458/* C99 / C++11 and above: rely on va_copy() which is required.
2459 * Omit parenthesis on macro right side on purpose to minimize differences
2460 * to direct use.
2461 */
2462#define DUK_VA_COPY(dest,src) va_copy(dest,src)
7c673cae
FG
2463#else
2464/* Pre-C99: va_list type is implementation dependent. This replacement
2465 * assumes it is a plain value so that a simple assignment will work.
2466 * This is not the case on all platforms (it may be a single-array element,
2467 * for instance).
2468 */
2469#define DUK_VA_COPY(dest,src) do { (dest) = (src); } while (0)
2470#endif
37b3c998 2471#endif
7c673cae 2472
37b3c998
TL
2473#if !defined(DUK_MACRO_STRINGIFY)
2474/* Macro hackery to convert e.g. __LINE__ to a string without formatting,
2475 * see: http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string
7c673cae 2476 */
37b3c998
TL
2477#define DUK_MACRO_STRINGIFY_HELPER(x) #x
2478#define DUK_MACRO_STRINGIFY(x) DUK_MACRO_STRINGIFY_HELPER(x)
2479#endif
7c673cae 2480
37b3c998
TL
2481#if !defined(DUK_CAUSE_SEGFAULT)
2482/* This is optionally used by panic handling to cause the program to segfault
2483 * (instead of e.g. abort()) on panic. Valgrind will then indicate the C
2484 * call stack leading to the panic.
7c673cae 2485 */
37b3c998 2486#define DUK_CAUSE_SEGFAULT() do { *((volatile duk_uint32_t *) NULL) = (duk_uint32_t) 0xdeadbeefUL; } while (0)
7c673cae 2487#endif
37b3c998
TL
2488#if !defined(DUK_UNREF)
2489/* Macro for suppressing warnings for potentially unreferenced variables.
2490 * The variables can be actually unreferenced or unreferenced in some
2491 * specific cases only; for instance, if a variable is only debug printed,
2492 * it is unreferenced when debug printing is disabled.
7c673cae 2493 */
37b3c998 2494#define DUK_UNREF(x) do { (void) (x); } while (0)
7c673cae 2495#endif
37b3c998
TL
2496#if !defined(DUK_NORETURN)
2497#define DUK_NORETURN(decl) decl
7c673cae 2498#endif
7c673cae 2499#if !defined(DUK_UNREACHABLE)
37b3c998
TL
2500/* Don't know how to declare unreachable point, so don't do it; this
2501 * may cause some spurious compilation warnings (e.g. "variable used
2502 * uninitialized").
2503 */
2504#define DUK_UNREACHABLE() do { } while (0)
7c673cae 2505#endif
37b3c998
TL
2506#if !defined(DUK_LOSE_CONST)
2507/* Convert any input pointer into a "void *", losing a const qualifier.
2508 * This is not fully portable because casting through duk_uintptr_t may
2509 * not work on all architectures (e.g. those with long, segmented pointers).
7c673cae 2510 */
37b3c998 2511#define DUK_LOSE_CONST(src) ((void *) (duk_uintptr_t) (src))
7c673cae 2512#endif
7c673cae
FG
2513
2514#if !defined(DUK_LIKELY)
2515#define DUK_LIKELY(x) (x)
2516#endif
2517#if !defined(DUK_UNLIKELY)
2518#define DUK_UNLIKELY(x) (x)
2519#endif
2520
7c673cae
FG
2521#if !defined(DUK_NOINLINE)
2522#define DUK_NOINLINE /*nop*/
7c673cae 2523#endif
37b3c998 2524#if !defined(DUK_INLINE)
7c673cae 2525#define DUK_INLINE /*nop*/
37b3c998
TL
2526#endif
2527#if !defined(DUK_ALWAYS_INLINE)
7c673cae
FG
2528#define DUK_ALWAYS_INLINE /*nop*/
2529#endif
2530
37b3c998
TL
2531#if !defined(DUK_EXTERNAL_DECL)
2532#define DUK_EXTERNAL_DECL extern
7c673cae 2533#endif
37b3c998
TL
2534#if !defined(DUK_EXTERNAL)
2535#define DUK_EXTERNAL /*empty*/
7c673cae 2536#endif
37b3c998 2537#if !defined(DUK_INTERNAL_DECL)
7c673cae
FG
2538#if defined(DUK_SINGLE_FILE)
2539#define DUK_INTERNAL_DECL static
7c673cae 2540#else
37b3c998 2541#define DUK_INTERNAL_DECL extern
7c673cae 2542#endif
7c673cae 2543#endif
37b3c998 2544#if !defined(DUK_INTERNAL)
7c673cae 2545#if defined(DUK_SINGLE_FILE)
7c673cae
FG
2546#define DUK_INTERNAL static
2547#else
7c673cae
FG
2548#define DUK_INTERNAL /*empty*/
2549#endif
2550#endif
37b3c998 2551#if !defined(DUK_LOCAL_DECL)
7c673cae 2552#define DUK_LOCAL_DECL static
37b3c998
TL
2553#endif
2554#if !defined(DUK_LOCAL)
7c673cae 2555#define DUK_LOCAL static
37b3c998 2556#endif
7c673cae 2557
37b3c998 2558#if !defined(DUK_FILE_MACRO)
7c673cae 2559#define DUK_FILE_MACRO __FILE__
37b3c998
TL
2560#endif
2561#if !defined(DUK_LINE_MACRO)
7c673cae 2562#define DUK_LINE_MACRO __LINE__
37b3c998
TL
2563#endif
2564#if !defined(DUK_FUNC_MACRO)
2565#if defined(DUK_F_C99) || defined(DUK_F_CPP11)
7c673cae 2566#define DUK_FUNC_MACRO __func__
37b3c998
TL
2567#elif defined(__FUNCTION__)
2568#define DUK_FUNC_MACRO __FUNCTION__
7c673cae
FG
2569#else
2570#define DUK_FUNC_MACRO "unknown"
2571#endif
37b3c998 2572#endif
7c673cae 2573
37b3c998 2574#if !defined(DUK_BSWAP32)
7c673cae
FG
2575#define DUK_BSWAP32(x) \
2576 ((((duk_uint32_t) (x)) >> 24) | \
2577 ((((duk_uint32_t) (x)) >> 8) & 0xff00UL) | \
2578 ((((duk_uint32_t) (x)) << 8) & 0xff0000UL) | \
2579 (((duk_uint32_t) (x)) << 24))
37b3c998
TL
2580#endif
2581#if !defined(DUK_BSWAP16)
7c673cae
FG
2582#define DUK_BSWAP16(x) \
2583 ((duk_uint16_t) (x) >> 8) | \
2584 ((duk_uint16_t) (x) << 8)
37b3c998 2585#endif
7c673cae 2586
37b3c998
TL
2587/* DUK_USE_VARIADIC_MACROS: required from compilers, so no fill-in. */
2588/* DUK_USE_UNION_INITIALIZERS: required from compilers, so no fill-in. */
7c673cae 2589
37b3c998
TL
2590#if !(defined(DUK_USE_FLEX_C99) || defined(DUK_USE_FLEX_ZEROSIZE) || defined(DUK_USE_FLEX_ONESIZE))
2591#if defined(DUK_F_C99)
2592#define DUK_USE_FLEX_C99
7c673cae 2593#else
37b3c998
TL
2594#define DUK_USE_FLEX_ZEROSIZE /* Not standard but common enough */
2595#endif
7c673cae
FG
2596#endif
2597
37b3c998
TL
2598#if !(defined(DUK_USE_PACK_GCC_ATTR) || defined(DUK_USE_PACK_CLANG_ATTR) || \
2599 defined(DUK_USE_PACK_MSVC_PRAGMA) || defined(DUK_USE_PACK_DUMMY_MEMBER))
2600#define DUK_USE_PACK_DUMMY_MEMBER
2601#endif
7c673cae 2602
37b3c998
TL
2603#if 0 /* not defined by default */
2604#undef DUK_USE_GCC_PRAGMAS
7c673cae 2605#endif
37b3c998
TL
2606
2607/* Workaround for GH-323: avoid inlining control when compiling from
2608 * multiple sources, as it causes compiler portability trouble.
2609 */
2610#if !defined(DUK_SINGLE_FILE)
2611#undef DUK_NOINLINE
2612#undef DUK_INLINE
2613#undef DUK_ALWAYS_INLINE
2614#define DUK_NOINLINE /*nop*/
2615#define DUK_INLINE /*nop*/
2616#define DUK_ALWAYS_INLINE /*nop*/
7c673cae
FG
2617#endif
2618
2619/*
37b3c998
TL
2620 * Check whether or not a packed duk_tval representation is possible.
2621 * What's basically required is that pointers are 32-bit values
2622 * (sizeof(void *) == 4). Best effort check, not always accurate.
2623 * If guess goes wrong, crashes may result; self tests also verify
2624 * the guess.
7c673cae
FG
2625 */
2626
37b3c998
TL
2627/* Explicit marker needed; may be 'defined', 'undefined, 'or 'not provided'. */
2628#if !defined(DUK_F_PACKED_TVAL_PROVIDED)
2629#undef DUK_F_PACKED_TVAL_POSSIBLE
2630
2631/* Strict C99 case: DUK_UINTPTR_MAX (= UINTPTR_MAX) should be very reliable */
2632#if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_UINTPTR_MAX)
2633#if (DUK_UINTPTR_MAX <= 0xffffffffUL)
2634#define DUK_F_PACKED_TVAL_POSSIBLE
7c673cae 2635#endif
7c673cae
FG
2636#endif
2637
37b3c998
TL
2638/* Non-C99 case, still relying on DUK_UINTPTR_MAX, as long as it is not a computed value */
2639#if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_UINTPTR_MAX) && !defined(DUK_UINTPTR_MAX_COMPUTED)
2640#if (DUK_UINTPTR_MAX <= 0xffffffffUL)
2641#define DUK_F_PACKED_TVAL_POSSIBLE
2642#endif
2643#endif
7c673cae 2644
37b3c998
TL
2645/* DUK_SIZE_MAX (= SIZE_MAX) is often reliable */
2646#if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_SIZE_MAX) && !defined(DUK_SIZE_MAX_COMPUTED)
2647#if (DUK_SIZE_MAX <= 0xffffffffUL)
2648#define DUK_F_PACKED_TVAL_POSSIBLE
2649#endif
7c673cae
FG
2650#endif
2651
37b3c998
TL
2652#undef DUK_USE_PACKED_TVAL
2653#if defined(DUK_F_PACKED_TVAL_POSSIBLE)
2654#define DUK_USE_PACKED_TVAL
2655#endif
7c673cae 2656
37b3c998
TL
2657#undef DUK_F_PACKED_TVAL_POSSIBLE
2658#endif /* DUK_F_PACKED_TVAL_PROVIDED */
7c673cae 2659
37b3c998
TL
2660/* Feature option forcing. */
2661#if defined(DUK_OPT_NO_PACKED_TVAL)
2662#undef DUK_USE_PACKED_TVAL
2663#elif defined(DUK_OPT_PACKED_TVAL)
2664#undef DUK_USE_PACKED_TVAL
2665#define DUK_USE_PACKED_TVAL
7c673cae 2666#endif
37b3c998
TL
2667/* Object property allocation layout has implications for memory and code
2668 * footprint and generated code size/speed. The best layout also depends
2669 * on whether the platform has alignment requirements or benefits from
2670 * having mostly aligned accesses.
2671 */
2672#undef DUK_USE_HOBJECT_LAYOUT_1
2673#undef DUK_USE_HOBJECT_LAYOUT_2
2674#undef DUK_USE_HOBJECT_LAYOUT_3
2675#if (DUK_USE_ALIGN_BY == 1)
2676/* On platforms without any alignment issues, layout 1 is preferable
2677 * because it compiles to slightly less code and provides direct access
2678 * to property keys.
2679 */
2680#define DUK_USE_HOBJECT_LAYOUT_1
7c673cae 2681#else
37b3c998
TL
2682/* On other platforms use layout 2, which requires some padding but
2683 * is a bit more natural than layout 3 in ordering the entries. Layout
2684 * 3 is currently not used.
7c673cae 2685 */
37b3c998
TL
2686#define DUK_USE_HOBJECT_LAYOUT_2
2687#endif
7c673cae 2688
37b3c998
TL
2689/* GCC/clang inaccurate math would break compliance and probably duk_tval,
2690 * so refuse to compile. Relax this if -ffast-math is tested to work.
7c673cae 2691 */
37b3c998
TL
2692#if defined(__FAST_MATH__)
2693#error __FAST_MATH__ defined, refusing to compile
2694#endif
7c673cae 2695
37b3c998
TL
2696/*
2697 * Feature option handling
7c673cae 2698 */
7c673cae 2699
37b3c998
TL
2700#if !defined(DUK_USE_ALIGN_BY)
2701#if defined(DUK_OPT_FORCE_ALIGN)
2702#define DUK_USE_ALIGN_BY DUK_OPT_FORCE_ALIGN
2703#else
2704#define DUK_USE_ALIGN_BY 8
2705#endif
2706#endif
7c673cae 2707
37b3c998
TL
2708#if defined(DUK_OPT_ASSERTIONS)
2709#define DUK_USE_ASSERTIONS
2710#elif defined(DUK_OPT_NO_ASSERTIONS)
2711#undef DUK_USE_ASSERTIONS
2712#else
2713#undef DUK_USE_ASSERTIONS
2714#endif
7c673cae 2715
37b3c998
TL
2716#if defined(DUK_OPT_AUGMENT_ERRORS)
2717#define DUK_USE_AUGMENT_ERROR_CREATE
2718#elif defined(DUK_OPT_NO_AUGMENT_ERRORS)
2719#undef DUK_USE_AUGMENT_ERROR_CREATE
2720#else
2721#define DUK_USE_AUGMENT_ERROR_CREATE
7c673cae
FG
2722#endif
2723
37b3c998
TL
2724#if defined(DUK_OPT_AUGMENT_ERRORS)
2725#define DUK_USE_AUGMENT_ERROR_THROW
2726#elif defined(DUK_OPT_NO_AUGMENT_ERRORS)
2727#undef DUK_USE_AUGMENT_ERROR_THROW
2728#else
2729#define DUK_USE_AUGMENT_ERROR_THROW
2730#endif
7c673cae 2731
37b3c998
TL
2732#if defined(DUK_OPT_BROWSER_LIKE)
2733#define DUK_USE_BROWSER_LIKE
2734#elif defined(DUK_OPT_NO_BROWSER_LIKE)
2735#undef DUK_USE_BROWSER_LIKE
2736#else
2737#define DUK_USE_BROWSER_LIKE
2738#endif
7c673cae 2739
37b3c998
TL
2740#if defined(DUK_OPT_BUFFEROBJECT_SUPPORT)
2741#define DUK_USE_BUFFEROBJECT_SUPPORT
2742#elif defined(DUK_OPT_NO_BUFFEROBJECT_SUPPORT)
2743#undef DUK_USE_BUFFEROBJECT_SUPPORT
2744#else
2745#define DUK_USE_BUFFEROBJECT_SUPPORT
7c673cae
FG
2746#endif
2747
37b3c998
TL
2748#if defined(DUK_OPT_BUFLEN16)
2749#define DUK_USE_BUFLEN16
2750#elif defined(DUK_OPT_NO_BUFLEN16)
2751#undef DUK_USE_BUFLEN16
2752#else
2753#undef DUK_USE_BUFLEN16
7c673cae 2754#endif
37b3c998
TL
2755
2756#if defined(DUK_OPT_BYTECODE_DUMP_SUPPORT)
2757#define DUK_USE_BYTECODE_DUMP_SUPPORT
2758#elif defined(DUK_OPT_NO_BYTECODE_DUMP_SUPPORT)
2759#undef DUK_USE_BYTECODE_DUMP_SUPPORT
2760#else
2761#define DUK_USE_BYTECODE_DUMP_SUPPORT
7c673cae
FG
2762#endif
2763
37b3c998
TL
2764#if defined(DUK_OPT_COMMONJS_MODULES)
2765#define DUK_USE_COMMONJS_MODULES
2766#elif defined(DUK_OPT_NO_COMMONJS_MODULES)
2767#undef DUK_USE_COMMONJS_MODULES
2768#else
2769#define DUK_USE_COMMONJS_MODULES
2770#endif
7c673cae 2771
37b3c998
TL
2772#if defined(DUK_OPT_CPP_EXCEPTIONS)
2773#define DUK_USE_CPP_EXCEPTIONS
2774#elif defined(DUK_OPT_NO_CPP_EXCEPTIONS)
2775#undef DUK_USE_CPP_EXCEPTIONS
2776#else
2777#undef DUK_USE_CPP_EXCEPTIONS
2778#endif
7c673cae 2779
37b3c998
TL
2780#if defined(DUK_OPT_DATAPTR16)
2781#define DUK_USE_DATAPTR16
2782#elif defined(DUK_OPT_NO_DATAPTR16)
2783#undef DUK_USE_DATAPTR16
2784#else
2785#undef DUK_USE_DATAPTR16
7c673cae
FG
2786#endif
2787
37b3c998
TL
2788#if defined(DUK_OPT_DATAPTR_DEC16)
2789#define DUK_USE_DATAPTR_DEC16(udata,ptr) DUK_OPT_DATAPTR_DEC16((udata),(ptr))
2790#else
2791#undef DUK_USE_DATAPTR_DEC16
7c673cae
FG
2792#endif
2793
37b3c998
TL
2794#if defined(DUK_OPT_DATAPTR_ENC16)
2795#define DUK_USE_DATAPTR_ENC16(udata,ptr) DUK_OPT_DATAPTR_ENC16((udata),(ptr))
2796#else
2797#undef DUK_USE_DATAPTR_ENC16
7c673cae 2798#endif
37b3c998
TL
2799
2800#if defined(DUK_OPT_DDDPRINT)
2801#define DUK_USE_DDDPRINT
2802#elif defined(DUK_OPT_NO_DDDPRINT)
2803#undef DUK_USE_DDDPRINT
2804#else
2805#undef DUK_USE_DDDPRINT
7c673cae
FG
2806#endif
2807
37b3c998
TL
2808#if defined(DUK_OPT_DDPRINT)
2809#define DUK_USE_DDPRINT
2810#elif defined(DUK_OPT_NO_DDPRINT)
2811#undef DUK_USE_DDPRINT
2812#else
2813#undef DUK_USE_DDPRINT
7c673cae
FG
2814#endif
2815
37b3c998
TL
2816#if defined(DUK_OPT_DEBUG)
2817#define DUK_USE_DEBUG
2818#elif defined(DUK_OPT_NO_DEBUG)
2819#undef DUK_USE_DEBUG
2820#else
2821#undef DUK_USE_DEBUG
7c673cae
FG
2822#endif
2823
37b3c998
TL
2824#if defined(DUK_OPT_DEBUGGER_DUMPHEAP)
2825#define DUK_USE_DEBUGGER_DUMPHEAP
2826#elif defined(DUK_OPT_NO_DEBUGGER_DUMPHEAP)
2827#undef DUK_USE_DEBUGGER_DUMPHEAP
2828#else
2829#undef DUK_USE_DEBUGGER_DUMPHEAP
7c673cae
FG
2830#endif
2831
37b3c998
TL
2832#if defined(DUK_OPT_DEBUGGER_FWD_LOGGING)
2833#define DUK_USE_DEBUGGER_FWD_LOGGING
2834#elif defined(DUK_OPT_NO_DEBUGGER_FWD_LOGGING)
2835#undef DUK_USE_DEBUGGER_FWD_LOGGING
2836#else
2837#undef DUK_USE_DEBUGGER_FWD_LOGGING
2838#endif
7c673cae 2839
37b3c998
TL
2840#if defined(DUK_OPT_DEBUGGER_FWD_PRINTALERT)
2841#define DUK_USE_DEBUGGER_FWD_PRINTALERT
2842#elif defined(DUK_OPT_NO_DEBUGGER_FWD_PRINTALERT)
2843#undef DUK_USE_DEBUGGER_FWD_PRINTALERT
7c673cae 2844#else
37b3c998 2845#undef DUK_USE_DEBUGGER_FWD_PRINTALERT
7c673cae
FG
2846#endif
2847
37b3c998
TL
2848#if defined(DUK_OPT_DEBUGGER_INSPECT)
2849#define DUK_USE_DEBUGGER_INSPECT
2850#elif defined(DUK_OPT_NO_DEBUGGER_INSPECT)
2851#undef DUK_USE_DEBUGGER_INSPECT
2852#else
2853#undef DUK_USE_DEBUGGER_INSPECT
2854#endif
7c673cae 2855
37b3c998
TL
2856#if defined(DUK_OPT_DEBUGGER_PAUSE_UNCAUGHT)
2857#define DUK_USE_DEBUGGER_PAUSE_UNCAUGHT
2858#elif defined(DUK_OPT_NO_DEBUGGER_PAUSE_UNCAUGHT)
2859#undef DUK_USE_DEBUGGER_PAUSE_UNCAUGHT
2860#else
2861#undef DUK_USE_DEBUGGER_PAUSE_UNCAUGHT
2862#endif
7c673cae 2863
37b3c998
TL
2864#if defined(DUK_OPT_DEBUGGER_SUPPORT)
2865#define DUK_USE_DEBUGGER_SUPPORT
2866#elif defined(DUK_OPT_NO_DEBUGGER_SUPPORT)
2867#undef DUK_USE_DEBUGGER_SUPPORT
2868#else
2869#undef DUK_USE_DEBUGGER_SUPPORT
2870#endif
7c673cae 2871
37b3c998
TL
2872#if defined(DUK_OPT_DEBUGGER_THROW_NOTIFY)
2873#define DUK_USE_DEBUGGER_THROW_NOTIFY
2874#elif defined(DUK_OPT_NO_DEBUGGER_THROW_NOTIFY)
2875#undef DUK_USE_DEBUGGER_THROW_NOTIFY
2876#else
2877#define DUK_USE_DEBUGGER_THROW_NOTIFY
7c673cae
FG
2878#endif
2879
37b3c998
TL
2880#if defined(DUK_OPT_DEBUGGER_TRANSPORT_TORTURE)
2881#define DUK_USE_DEBUGGER_TRANSPORT_TORTURE
2882#elif defined(DUK_OPT_NO_DEBUGGER_TRANSPORT_TORTURE)
2883#undef DUK_USE_DEBUGGER_TRANSPORT_TORTURE
2884#else
2885#undef DUK_USE_DEBUGGER_TRANSPORT_TORTURE
7c673cae
FG
2886#endif
2887
37b3c998
TL
2888#if defined(DUK_OPT_DEBUG_BUFSIZE)
2889#define DUK_USE_DEBUG_BUFSIZE DUK_OPT_DEBUG_BUFSIZE
7c673cae 2890#else
37b3c998 2891#define DUK_USE_DEBUG_BUFSIZE 65536L
7c673cae 2892#endif
37b3c998
TL
2893
2894#if defined(DUK_OPT_REFERENCE_COUNTING)
2895#define DUK_USE_DOUBLE_LINKED_HEAP
2896#elif defined(DUK_OPT_NO_REFERENCE_COUNTING)
2897#undef DUK_USE_DOUBLE_LINKED_HEAP
2898#else
2899#define DUK_USE_DOUBLE_LINKED_HEAP
7c673cae
FG
2900#endif
2901
37b3c998
TL
2902#if defined(DUK_OPT_DPRINT)
2903#define DUK_USE_DPRINT
2904#elif defined(DUK_OPT_NO_DPRINT)
2905#undef DUK_USE_DPRINT
2906#else
2907#undef DUK_USE_DPRINT
2908#endif
7c673cae 2909
37b3c998
TL
2910#if defined(DUK_OPT_DPRINT_COLORS)
2911#define DUK_USE_DPRINT_COLORS
2912#elif defined(DUK_OPT_NO_DPRINT_COLORS)
2913#undef DUK_USE_DPRINT_COLORS
2914#else
2915#undef DUK_USE_DPRINT_COLORS
2916#endif
7c673cae 2917
37b3c998
TL
2918#if defined(DUK_OPT_DPRINT_RDTSC)
2919#define DUK_USE_DPRINT_RDTSC
2920#elif defined(DUK_OPT_NO_DPRINT_RDTSC)
2921#undef DUK_USE_DPRINT_RDTSC
2922#else
2923#undef DUK_USE_DPRINT_RDTSC
7c673cae
FG
2924#endif
2925
37b3c998
TL
2926#if defined(DUK_OPT_AUGMENT_ERRORS)
2927#define DUK_USE_ERRCREATE
2928#elif defined(DUK_OPT_NO_AUGMENT_ERRORS)
2929#undef DUK_USE_ERRCREATE
2930#else
2931#define DUK_USE_ERRCREATE
7c673cae
FG
2932#endif
2933
37b3c998
TL
2934#if defined(DUK_OPT_AUGMENT_ERRORS)
2935#define DUK_USE_ERRTHROW
2936#elif defined(DUK_OPT_NO_AUGMENT_ERRORS)
2937#undef DUK_USE_ERRTHROW
2938#else
2939#define DUK_USE_ERRTHROW
7c673cae
FG
2940#endif
2941
37b3c998
TL
2942#if defined(DUK_OPT_ES6_OBJECT_PROTO_PROPERTY)
2943#define DUK_USE_ES6_OBJECT_PROTO_PROPERTY
2944#elif defined(DUK_OPT_NO_ES6_OBJECT_PROTO_PROPERTY)
2945#undef DUK_USE_ES6_OBJECT_PROTO_PROPERTY
2946#else
2947#define DUK_USE_ES6_OBJECT_PROTO_PROPERTY
7c673cae
FG
2948#endif
2949
37b3c998
TL
2950#if defined(DUK_OPT_ES6_OBJECT_SETPROTOTYPEOF)
2951#define DUK_USE_ES6_OBJECT_SETPROTOTYPEOF
2952#elif defined(DUK_OPT_NO_ES6_OBJECT_SETPROTOTYPEOF)
2953#undef DUK_USE_ES6_OBJECT_SETPROTOTYPEOF
2954#else
2955#define DUK_USE_ES6_OBJECT_SETPROTOTYPEOF
7c673cae
FG
2956#endif
2957
37b3c998
TL
2958#if defined(DUK_OPT_ES6_PROXY)
2959#define DUK_USE_ES6_PROXY
2960#elif defined(DUK_OPT_NO_ES6_PROXY)
2961#undef DUK_USE_ES6_PROXY
2962#else
2963#define DUK_USE_ES6_PROXY
7c673cae
FG
2964#endif
2965
37b3c998
TL
2966#if defined(DUK_OPT_ES6_REGEXP_BRACES)
2967#define DUK_USE_ES6_REGEXP_BRACES
2968#elif defined(DUK_OPT_NO_ES6_REGEXP_BRACES)
2969#undef DUK_USE_ES6_REGEXP_BRACES
2970#else
2971#define DUK_USE_ES6_REGEXP_BRACES
7c673cae
FG
2972#endif
2973
7c673cae
FG
2974#undef DUK_USE_EXEC_INDIRECT_BOUND_CHECK
2975#if defined(DUK_OPT_DEBUG) || defined(DUK_OPT_ASSERTIONS)
2976/* Enabled with debug/assertions just so that any issues can be caught. */
2977#define DUK_USE_EXEC_INDIRECT_BOUND_CHECK
2978#endif
2979
37b3c998
TL
2980#undef DUK_USE_EXEC_TIMEOUT_CHECK
2981#if defined(DUK_OPT_EXEC_TIMEOUT_CHECK)
2982#define DUK_USE_EXEC_TIMEOUT_CHECK(udata) DUK_OPT_EXEC_TIMEOUT_CHECK((udata))
2983#endif
7c673cae 2984
37b3c998
TL
2985#undef DUK_USE_EXTSTR_FREE
2986#if defined(DUK_OPT_EXTERNAL_STRINGS) && defined(DUK_OPT_EXTSTR_FREE)
2987#define DUK_USE_EXTSTR_FREE(udata,ptr) DUK_OPT_EXTSTR_FREE((udata), (ptr))
2988#endif
7c673cae 2989
37b3c998
TL
2990#undef DUK_USE_EXTSTR_INTERN_CHECK
2991#if defined(DUK_OPT_EXTERNAL_STRINGS) && defined(DUK_OPT_EXTSTR_INTERN_CHECK)
2992#define DUK_USE_EXTSTR_INTERN_CHECK(udata,ptr,len) DUK_OPT_EXTSTR_INTERN_CHECK((udata), (ptr), (len))
7c673cae
FG
2993#endif
2994
37b3c998
TL
2995/* Support for 48-bit signed integer duk_tval with transparent semantics. */
2996#undef DUK_USE_FASTINT
2997#if defined(DUK_OPT_FASTINT)
2998#if !defined(DUK_F_HAVE_64BIT)
2999#error DUK_OPT_FASTINT requires 64-bit integer type support at the moment
7c673cae 3000#endif
37b3c998 3001#define DUK_USE_FASTINT
7c673cae 3002#endif
37b3c998
TL
3003
3004#if defined(DUK_OPT_FILE_IO)
3005#define DUK_USE_FILE_IO
3006#elif defined(DUK_OPT_NO_FILE_IO)
3007#undef DUK_USE_FILE_IO
3008#else
3009#define DUK_USE_FILE_IO
7c673cae
FG
3010#endif
3011
37b3c998
TL
3012#if defined(DUK_OPT_FUNCPTR16)
3013#define DUK_USE_FUNCPTR16
3014#elif defined(DUK_OPT_NO_FUNCPTR16)
3015#undef DUK_USE_FUNCPTR16
3016#else
3017#undef DUK_USE_FUNCPTR16
7c673cae
FG
3018#endif
3019
37b3c998
TL
3020#if defined(DUK_OPT_FUNCPTR_DEC16)
3021#define DUK_USE_FUNCPTR_DEC16(udata,ptr) DUK_OPT_FUNCPTR_DEC16((udata),(ptr))
7c673cae 3022#else
37b3c998 3023#undef DUK_USE_FUNCPTR_DEC16
7c673cae
FG
3024#endif
3025
37b3c998
TL
3026#if defined(DUK_OPT_FUNCPTR_ENC16)
3027#define DUK_USE_FUNCPTR_ENC16(udata,ptr) DUK_OPT_FUNCPTR_ENC16((udata),(ptr))
3028#else
3029#undef DUK_USE_FUNCPTR_ENC16
3030#endif
3031
3032#if defined(DUK_OPT_GC_TORTURE)
3033#define DUK_USE_GC_TORTURE
3034#elif defined(DUK_OPT_NO_GC_TORTURE)
3035#undef DUK_USE_GC_TORTURE
3036#else
3037#undef DUK_USE_GC_TORTURE
7c673cae
FG
3038#endif
3039
37b3c998
TL
3040#if defined(DUK_OPT_HEAPPTR16)
3041#define DUK_USE_HEAPPTR16
3042#elif defined(DUK_OPT_NO_HEAPPTR16)
3043#undef DUK_USE_HEAPPTR16
7c673cae 3044#else
37b3c998 3045#undef DUK_USE_HEAPPTR16
7c673cae
FG
3046#endif
3047
37b3c998
TL
3048#if defined(DUK_OPT_HEAPPTR_DEC16)
3049#define DUK_USE_HEAPPTR_DEC16(udata,ptr) DUK_OPT_HEAPPTR_DEC16((udata),(ptr))
3050#else
3051#undef DUK_USE_HEAPPTR_DEC16
3052#endif
7c673cae 3053
37b3c998
TL
3054#if defined(DUK_OPT_HEAPPTR_ENC16)
3055#define DUK_USE_HEAPPTR_ENC16(udata,ptr) DUK_OPT_HEAPPTR_ENC16((udata),(ptr))
7c673cae 3056#else
37b3c998 3057#undef DUK_USE_HEAPPTR_ENC16
7c673cae
FG
3058#endif
3059
37b3c998
TL
3060/* For now, hash part is dropped if and only if 16-bit object fields are used. */
3061#define DUK_USE_HOBJECT_HASH_PART
3062#if defined(DUK_OPT_OBJSIZES16)
3063#undef DUK_USE_HOBJECT_HASH_PART
7c673cae
FG
3064#endif
3065
37b3c998
TL
3066#if defined(DUK_OPT_HSTRING_CLEN)
3067#define DUK_USE_HSTRING_CLEN
3068#elif defined(DUK_OPT_NO_HSTRING_CLEN)
3069#undef DUK_USE_HSTRING_CLEN
3070#else
3071#define DUK_USE_HSTRING_CLEN
7c673cae
FG
3072#endif
3073
37b3c998
TL
3074#if defined(DUK_OPT_EXTERNAL_STRINGS)
3075#define DUK_USE_HSTRING_EXTDATA
3076#elif defined(DUK_OPT_NO_EXTERNAL_STRINGS)
3077#undef DUK_USE_HSTRING_EXTDATA
3078#else
3079#undef DUK_USE_HSTRING_EXTDATA
7c673cae
FG
3080#endif
3081
37b3c998
TL
3082#if defined(DUK_OPT_INTERRUPT_COUNTER)
3083#define DUK_USE_INTERRUPT_COUNTER
3084#elif defined(DUK_OPT_NO_INTERRUPT_COUNTER)
3085#undef DUK_USE_INTERRUPT_COUNTER
3086#else
3087#undef DUK_USE_INTERRUPT_COUNTER
7c673cae
FG
3088#endif
3089
37b3c998
TL
3090#if defined(DUK_OPT_JC)
3091#define DUK_USE_JC
3092#elif defined(DUK_OPT_NO_JC)
3093#undef DUK_USE_JC
3094#else
3095#define DUK_USE_JC
7c673cae
FG
3096#endif
3097
37b3c998
TL
3098#if defined(DUK_OPT_JSON_STRINGIFY_FASTPATH)
3099#define DUK_USE_JSON_STRINGIFY_FASTPATH
3100#elif defined(DUK_OPT_NO_JSON_STRINGIFY_FASTPATH)
3101#undef DUK_USE_JSON_STRINGIFY_FASTPATH
3102#else
3103#undef DUK_USE_JSON_STRINGIFY_FASTPATH
7c673cae
FG
3104#endif
3105
37b3c998
TL
3106#if defined(DUK_OPT_JX)
3107#define DUK_USE_JX
3108#elif defined(DUK_OPT_NO_JX)
3109#undef DUK_USE_JX
3110#else
3111#define DUK_USE_JX
7c673cae
FG
3112#endif
3113
37b3c998
TL
3114#if defined(DUK_OPT_LIGHTFUNC_BUILTINS)
3115#define DUK_USE_LIGHTFUNC_BUILTINS
3116#elif defined(DUK_OPT_NO_LIGHTFUNC_BUILTINS)
3117#undef DUK_USE_LIGHTFUNC_BUILTINS
3118#else
3119#undef DUK_USE_LIGHTFUNC_BUILTINS
3120#endif
7c673cae 3121
37b3c998
TL
3122#if defined(DUK_OPT_MARK_AND_SWEEP)
3123#define DUK_USE_MARK_AND_SWEEP
3124#elif defined(DUK_OPT_NO_MARK_AND_SWEEP)
3125#undef DUK_USE_MARK_AND_SWEEP
3126#else
3127#define DUK_USE_MARK_AND_SWEEP
7c673cae
FG
3128#endif
3129
37b3c998
TL
3130#if defined(DUK_OPT_MS_STRINGTABLE_RESIZE)
3131#define DUK_USE_MS_STRINGTABLE_RESIZE
3132#elif defined(DUK_OPT_NO_MS_STRINGTABLE_RESIZE)
3133#undef DUK_USE_MS_STRINGTABLE_RESIZE
3134#else
3135#define DUK_USE_MS_STRINGTABLE_RESIZE
7c673cae
FG
3136#endif
3137
37b3c998 3138#if defined(DUK_OPT_NONSTD_ARRAY_CONCAT_TRAILER)
7c673cae 3139#define DUK_USE_NONSTD_ARRAY_CONCAT_TRAILER
37b3c998 3140#elif defined(DUK_OPT_NO_NONSTD_ARRAY_CONCAT_TRAILER)
7c673cae 3141#undef DUK_USE_NONSTD_ARRAY_CONCAT_TRAILER
37b3c998
TL
3142#else
3143#define DUK_USE_NONSTD_ARRAY_CONCAT_TRAILER
7c673cae
FG
3144#endif
3145
37b3c998 3146#if defined(DUK_OPT_NONSTD_ARRAY_MAP_TRAILER)
7c673cae 3147#define DUK_USE_NONSTD_ARRAY_MAP_TRAILER
37b3c998 3148#elif defined(DUK_OPT_NO_NONSTD_ARRAY_MAP_TRAILER)
7c673cae 3149#undef DUK_USE_NONSTD_ARRAY_MAP_TRAILER
37b3c998
TL
3150#else
3151#define DUK_USE_NONSTD_ARRAY_MAP_TRAILER
7c673cae
FG
3152#endif
3153
37b3c998
TL
3154#if defined(DUK_OPT_NONSTD_ARRAY_SPLICE_DELCOUNT)
3155#define DUK_USE_NONSTD_ARRAY_SPLICE_DELCOUNT
3156#elif defined(DUK_OPT_NO_NONSTD_ARRAY_SPLICE_DELCOUNT)
3157#undef DUK_USE_NONSTD_ARRAY_SPLICE_DELCOUNT
3158#else
3159#define DUK_USE_NONSTD_ARRAY_SPLICE_DELCOUNT
7c673cae
FG
3160#endif
3161
37b3c998
TL
3162#if defined(DUK_OPT_NONSTD_FUNC_CALLER_PROPERTY)
3163#define DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
3164#elif defined(DUK_OPT_NO_NONSTD_FUNC_CALLER_PROPERTY)
3165#undef DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
3166#else
3167#undef DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
7c673cae
FG
3168#endif
3169
7c673cae
FG
3170#if defined(DUK_OPT_NONSTD_FUNC_SOURCE_PROPERTY)
3171#define DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY
37b3c998
TL
3172#elif defined(DUK_OPT_NO_NONSTD_FUNC_SOURCE_PROPERTY)
3173#undef DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY
3174#else
3175#undef DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY
7c673cae
FG
3176#endif
3177
37b3c998
TL
3178#if defined(DUK_OPT_NONSTD_FUNC_STMT)
3179#define DUK_USE_NONSTD_FUNC_STMT
3180#elif defined(DUK_OPT_NO_NONSTD_FUNC_STMT)
3181#undef DUK_USE_NONSTD_FUNC_STMT
3182#else
3183#define DUK_USE_NONSTD_FUNC_STMT
7c673cae
FG
3184#endif
3185
37b3c998 3186#if defined(DUK_OPT_NONSTD_ACCESSOR_KEY_ARGUMENT)
7c673cae 3187#define DUK_USE_NONSTD_GETTER_KEY_ARGUMENT
37b3c998 3188#elif defined(DUK_OPT_NO_NONSTD_ACCESSOR_KEY_ARGUMENT)
7c673cae 3189#undef DUK_USE_NONSTD_GETTER_KEY_ARGUMENT
37b3c998
TL
3190#else
3191#define DUK_USE_NONSTD_GETTER_KEY_ARGUMENT
7c673cae
FG
3192#endif
3193
37b3c998 3194#if defined(DUK_OPT_NONSTD_JSON_ESC_U2028_U2029)
7c673cae 3195#define DUK_USE_NONSTD_JSON_ESC_U2028_U2029
37b3c998 3196#elif defined(DUK_OPT_NO_NONSTD_JSON_ESC_U2028_U2029)
7c673cae 3197#undef DUK_USE_NONSTD_JSON_ESC_U2028_U2029
37b3c998
TL
3198#else
3199#define DUK_USE_NONSTD_JSON_ESC_U2028_U2029
7c673cae
FG
3200#endif
3201
37b3c998
TL
3202#if defined(DUK_OPT_NONSTD_REGEXP_DOLLAR_ESCAPE)
3203#define DUK_USE_NONSTD_REGEXP_DOLLAR_ESCAPE
3204#elif defined(DUK_OPT_NO_NONSTD_REGEXP_DOLLAR_ESCAPE)
3205#undef DUK_USE_NONSTD_REGEXP_DOLLAR_ESCAPE
3206#else
3207#define DUK_USE_NONSTD_REGEXP_DOLLAR_ESCAPE
7c673cae
FG
3208#endif
3209
37b3c998
TL
3210#if defined(DUK_OPT_NONSTD_ACCESSOR_KEY_ARGUMENT)
3211#define DUK_USE_NONSTD_SETTER_KEY_ARGUMENT
3212#elif defined(DUK_OPT_NO_NONSTD_ACCESSOR_KEY_ARGUMENT)
3213#undef DUK_USE_NONSTD_SETTER_KEY_ARGUMENT
3214#else
3215#define DUK_USE_NONSTD_SETTER_KEY_ARGUMENT
7c673cae
FG
3216#endif
3217
37b3c998
TL
3218#if defined(DUK_OPT_NONSTD_STRING_FROMCHARCODE_32BIT)
3219#define DUK_USE_NONSTD_STRING_FROMCHARCODE_32BIT
3220#elif defined(DUK_OPT_NO_NONSTD_STRING_FROMCHARCODE_32BIT)
3221#undef DUK_USE_NONSTD_STRING_FROMCHARCODE_32BIT
3222#else
3223#define DUK_USE_NONSTD_STRING_FROMCHARCODE_32BIT
7c673cae
FG
3224#endif
3225
37b3c998
TL
3226#if defined(DUK_OPT_OBJSIZES16)
3227#define DUK_USE_OBJSIZES16
3228#elif defined(DUK_OPT_NO_OBJSIZES16)
3229#undef DUK_USE_OBJSIZES16
3230#else
3231#undef DUK_USE_OBJSIZES16
7c673cae
FG
3232#endif
3233
37b3c998
TL
3234#if defined(DUK_OPT_OCTAL_SUPPORT)
3235#define DUK_USE_OCTAL_SUPPORT
3236#elif defined(DUK_OPT_NO_OCTAL_SUPPORT)
3237#undef DUK_USE_OCTAL_SUPPORT
3238#else
3239#define DUK_USE_OCTAL_SUPPORT
7c673cae
FG
3240#endif
3241
37b3c998
TL
3242#if defined(DUK_OPT_PACKED_TVAL)
3243#define DUK_USE_PACKED_TVAL
3244#elif defined(DUK_OPT_NO_PACKED_TVAL)
3245#undef DUK_USE_PACKED_TVAL
3246#else
3247/* Already provided above */
7c673cae
FG
3248#endif
3249
37b3c998
TL
3250#undef DUK_USE_PANIC_ABORT
3251#if !defined(DUK_OPT_SEGFAULT_ON_PANIC)
3252#define DUK_USE_PANIC_ABORT
3253#endif
7c673cae
FG
3254
3255#undef DUK_USE_PANIC_HANDLER
3256#if defined(DUK_OPT_PANIC_HANDLER)
3257#define DUK_USE_PANIC_HANDLER(code,msg) DUK_OPT_PANIC_HANDLER((code),(msg))
3258#endif
3259
7c673cae 3260#undef DUK_USE_PANIC_SEGFAULT
7c673cae
FG
3261#if defined(DUK_OPT_SEGFAULT_ON_PANIC)
3262#define DUK_USE_PANIC_SEGFAULT
7c673cae
FG
3263#endif
3264
37b3c998
TL
3265#if defined(DUK_OPT_PARANOID_ERRORS)
3266#define DUK_USE_PARANOID_ERRORS
3267#elif defined(DUK_OPT_NO_PARANOID_ERRORS)
3268#undef DUK_USE_PARANOID_ERRORS
3269#else
3270#undef DUK_USE_PARANOID_ERRORS
7c673cae
FG
3271#endif
3272
37b3c998
TL
3273#if defined(DUK_OPT_PC2LINE)
3274#define DUK_USE_PC2LINE
3275#elif defined(DUK_OPT_NO_PC2LINE)
3276#undef DUK_USE_PC2LINE
3277#else
3278#define DUK_USE_PC2LINE
7c673cae
FG
3279#endif
3280
37b3c998
TL
3281#if defined(DUK_OPT_REFCOUNT16)
3282#define DUK_USE_REFCOUNT16
3283#elif defined(DUK_OPT_NO_REFCOUNT16)
3284#undef DUK_USE_REFCOUNT16
3285#else
3286#undef DUK_USE_REFCOUNT16
7c673cae
FG
3287#endif
3288
37b3c998
TL
3289#if defined(DUK_OPT_REFERENCE_COUNTING)
3290#define DUK_USE_REFERENCE_COUNTING
3291#elif defined(DUK_OPT_NO_REFERENCE_COUNTING)
3292#undef DUK_USE_REFERENCE_COUNTING
3293#else
3294#define DUK_USE_REFERENCE_COUNTING
7c673cae
FG
3295#endif
3296
37b3c998
TL
3297#if defined(DUK_OPT_REGEXP_CANON_WORKAROUND)
3298#define DUK_USE_REGEXP_CANON_WORKAROUND
3299#elif defined(DUK_OPT_NO_REGEXP_CANON_WORKAROUND)
3300#undef DUK_USE_REGEXP_CANON_WORKAROUND
3301#else
3302#undef DUK_USE_REGEXP_CANON_WORKAROUND
7c673cae
FG
3303#endif
3304
37b3c998
TL
3305#if defined(DUK_OPT_REGEXP_SUPPORT)
3306#define DUK_USE_REGEXP_SUPPORT
3307#elif defined(DUK_OPT_NO_REGEXP_SUPPORT)
3308#undef DUK_USE_REGEXP_SUPPORT
3309#else
3310#define DUK_USE_REGEXP_SUPPORT
7c673cae
FG
3311#endif
3312
37b3c998
TL
3313#if defined(DUK_OPT_ROM_GLOBAL_CLONE)
3314#define DUK_USE_ROM_GLOBAL_CLONE
3315#elif defined(DUK_OPT_NO_ROM_GLOBAL_CLONE)
3316#undef DUK_USE_ROM_GLOBAL_CLONE
3317#else
3318#undef DUK_USE_ROM_GLOBAL_CLONE
7c673cae
FG
3319#endif
3320
37b3c998
TL
3321#if defined(DUK_OPT_ROM_GLOBAL_INHERIT)
3322#define DUK_USE_ROM_GLOBAL_INHERIT
3323#elif defined(DUK_OPT_NO_ROM_GLOBAL_INHERIT)
3324#undef DUK_USE_ROM_GLOBAL_INHERIT
3325#else
3326#undef DUK_USE_ROM_GLOBAL_INHERIT
7c673cae
FG
3327#endif
3328
37b3c998
TL
3329#if defined(DUK_OPT_ROM_OBJECTS)
3330#define DUK_USE_ROM_OBJECTS
3331#elif defined(DUK_OPT_NO_ROM_OBJECTS)
3332#undef DUK_USE_ROM_OBJECTS
3333#else
3334#undef DUK_USE_ROM_OBJECTS
7c673cae
FG
3335#endif
3336
37b3c998
TL
3337#if defined(DUK_OPT_ROM_STRINGS)
3338#define DUK_USE_ROM_STRINGS
3339#elif defined(DUK_OPT_NO_ROM_STRINGS)
3340#undef DUK_USE_ROM_STRINGS
3341#else
3342#undef DUK_USE_ROM_STRINGS
3343#endif
7c673cae 3344
37b3c998
TL
3345#if defined(DUK_OPT_SECTION_B)
3346#define DUK_USE_SECTION_B
3347#elif defined(DUK_OPT_NO_SECTION_B)
3348#undef DUK_USE_SECTION_B
3349#else
3350#define DUK_USE_SECTION_B
7c673cae
FG
3351#endif
3352
37b3c998
TL
3353#if defined(DUK_OPT_SELF_TESTS)
3354#define DUK_USE_SELF_TESTS
3355#elif defined(DUK_OPT_NO_SELF_TESTS)
3356#undef DUK_USE_SELF_TESTS
3357#else
3358#undef DUK_USE_SELF_TESTS
7c673cae
FG
3359#endif
3360
37b3c998
TL
3361#if defined(DUK_OPT_SHUFFLE_TORTURE)
3362#define DUK_USE_SHUFFLE_TORTURE
3363#elif defined(DUK_OPT_NO_SHUFFLE_TORTURE)
3364#undef DUK_USE_SHUFFLE_TORTURE
3365#else
3366#undef DUK_USE_SHUFFLE_TORTURE
7c673cae
FG
3367#endif
3368
37b3c998
TL
3369#if defined(DUK_OPT_SOURCE_NONBMP)
3370#define DUK_USE_SOURCE_NONBMP
3371#elif defined(DUK_OPT_NO_SOURCE_NONBMP)
3372#undef DUK_USE_SOURCE_NONBMP
3373#else
3374#define DUK_USE_SOURCE_NONBMP
7c673cae
FG
3375#endif
3376
7c673cae
FG
3377#if defined(DUK_OPT_STRHASH16)
3378#define DUK_USE_STRHASH16
37b3c998
TL
3379#elif defined(DUK_OPT_NO_STRHASH16)
3380#undef DUK_USE_STRHASH16
3381#else
3382#undef DUK_USE_STRHASH16
7c673cae
FG
3383#endif
3384
37b3c998
TL
3385#if defined(DUK_OPT_STRICT_DECL)
3386#define DUK_USE_STRICT_DECL
3387#elif defined(DUK_OPT_NO_STRICT_DECL)
3388#undef DUK_USE_STRICT_DECL
3389#else
3390#define DUK_USE_STRICT_DECL
7c673cae
FG
3391#endif
3392
37b3c998
TL
3393#if defined(DUK_OPT_STRICT_UTF8_SOURCE)
3394#define DUK_USE_STRICT_UTF8_SOURCE
3395#elif defined(DUK_OPT_NO_STRICT_UTF8_SOURCE)
3396#undef DUK_USE_STRICT_UTF8_SOURCE
3397#else
3398#undef DUK_USE_STRICT_UTF8_SOURCE
7c673cae
FG
3399#endif
3400
37b3c998
TL
3401#if defined(DUK_OPT_STRLEN16)
3402#define DUK_USE_STRLEN16
3403#elif defined(DUK_OPT_NO_STRLEN16)
3404#undef DUK_USE_STRLEN16
3405#else
3406#undef DUK_USE_STRLEN16
7c673cae
FG
3407#endif
3408
37b3c998
TL
3409#undef DUK_USE_STRTAB_CHAIN
3410#if defined(DUK_OPT_STRTAB_CHAIN) && defined(DUK_OPT_STRTAB_CHAIN_SIZE)
3411#define DUK_USE_STRTAB_CHAIN
7c673cae
FG
3412#endif
3413
37b3c998
TL
3414#undef DUK_USE_STRTAB_CHAIN_SIZE
3415#if defined(DUK_OPT_STRTAB_CHAIN) && defined(DUK_OPT_STRTAB_CHAIN_SIZE)
3416/* Low memory algorithm: separate chaining using arrays, fixed size hash */
3417#define DUK_USE_STRTAB_CHAIN_SIZE DUK_OPT_STRTAB_CHAIN_SIZE
7c673cae
FG
3418#endif
3419
37b3c998
TL
3420#undef DUK_USE_STRTAB_PROBE
3421#if !(defined(DUK_OPT_STRTAB_CHAIN) && defined(DUK_OPT_STRTAB_CHAIN_SIZE))
3422#define DUK_USE_STRTAB_PROBE
7c673cae
FG
3423#endif
3424
37b3c998
TL
3425#if defined(DUK_OPT_NONSTD_FUNC_CALLER_PROPERTY)
3426#undef DUK_USE_TAILCALL
3427#else
3428#define DUK_USE_TAILCALL
7c673cae 3429#endif
37b3c998
TL
3430
3431#if defined(DUK_OPT_TARGET_INFO)
3432#define DUK_USE_TARGET_INFO DUK_OPT_TARGET_INFO
3433#else
3434#define DUK_USE_TARGET_INFO "unknown"
7c673cae 3435#endif
37b3c998
TL
3436
3437#if defined(DUK_OPT_NO_AUGMENT_ERRORS)
3438#undef DUK_USE_TRACEBACKS
3439#elif defined(DUK_OPT_NO_TRACEBACKS)
3440#undef DUK_USE_TRACEBACKS
3441#else
3442#define DUK_USE_TRACEBACKS
7c673cae
FG
3443#endif
3444
37b3c998
TL
3445#if defined(DUK_OPT_TRACEBACK_DEPTH)
3446#define DUK_USE_TRACEBACK_DEPTH DUK_OPT_TRACEBACK_DEPTH
3447#else
3448#define DUK_USE_TRACEBACK_DEPTH 10
3449#endif
7c673cae 3450
37b3c998
TL
3451#if defined(DUK_OPT_DECLARE)
3452#define DUK_USE_USER_DECLARE() DUK_OPT_DECLARE
7c673cae 3453#else
37b3c998 3454#define DUK_USE_USER_DECLARE() /* no user declarations */
7c673cae
FG
3455#endif
3456
37b3c998
TL
3457/* User provided InitJS. */
3458#undef DUK_USE_USER_INITJS
3459#if defined(DUK_OPT_USER_INITJS)
3460#define DUK_USE_USER_INITJS (DUK_OPT_USER_INITJS)
3461#endif
7c673cae 3462
37b3c998
TL
3463#if defined(DUK_OPT_VERBOSE_ERRORS)
3464#define DUK_USE_VERBOSE_ERRORS
3465#elif defined(DUK_OPT_NO_VERBOSE_ERRORS)
3466#undef DUK_USE_VERBOSE_ERRORS
7c673cae 3467#else
37b3c998 3468#define DUK_USE_VERBOSE_ERRORS
7c673cae
FG
3469#endif
3470
37b3c998
TL
3471#if defined(DUK_OPT_VOLUNTARY_GC)
3472#define DUK_USE_VOLUNTARY_GC
3473#elif defined(DUK_OPT_NO_VOLUNTARY_GC)
3474#undef DUK_USE_VOLUNTARY_GC
3475#else
3476#define DUK_USE_VOLUNTARY_GC
3477#endif
7c673cae 3478
37b3c998
TL
3479#if defined(DUK_OPT_ZERO_BUFFER_DATA)
3480#define DUK_USE_ZERO_BUFFER_DATA
3481#elif defined(DUK_OPT_NO_ZERO_BUFFER_DATA)
3482#undef DUK_USE_ZERO_BUFFER_DATA
7c673cae 3483#else
37b3c998 3484#define DUK_USE_ZERO_BUFFER_DATA
7c673cae
FG
3485#endif
3486
3487/*
3488 * Autogenerated defaults
3489 */
3490
37b3c998
TL
3491#define DUK_USE_AVOID_PLATFORM_FUNCPTRS
3492#define DUK_USE_BASE64_FASTPATH
3493#define DUK_USE_BUILTIN_INITJS
7c673cae
FG
3494#define DUK_USE_COMPILER_RECLIMIT 2500
3495#undef DUK_USE_DATE_FORMAT_STRING
3496#undef DUK_USE_DATE_GET_LOCAL_TZOFFSET
3497#undef DUK_USE_DATE_GET_NOW
3498#undef DUK_USE_DATE_PARSE_STRING
3499#undef DUK_USE_DATE_PRS_GETDATE
37b3c998
TL
3500#define DUK_USE_ESBC_LIMITS
3501#define DUK_USE_ESBC_MAX_BYTES 2147418112L
3502#define DUK_USE_ESBC_MAX_LINENUMBER 2147418112L
3503#undef DUK_USE_EXEC_FUN_LOCAL
3504#undef DUK_USE_EXPLICIT_NULL_INIT
3505#define DUK_USE_FAST_REFCOUNT_DEFAULT
3506#define DUK_USE_HEX_FASTPATH
3507#define DUK_USE_IDCHAR_FASTPATH
3508#undef DUK_USE_INTERRUPT_DEBUG_FIXUP
7c673cae
FG
3509#define DUK_USE_JSON_DECNUMBER_FASTPATH
3510#define DUK_USE_JSON_DECSTRING_FASTPATH
3511#define DUK_USE_JSON_DEC_RECLIMIT 1000
3512#define DUK_USE_JSON_EATWHITE_FASTPATH
3513#define DUK_USE_JSON_ENC_RECLIMIT 1000
3514#define DUK_USE_JSON_QUOTESTRING_FASTPATH
37b3c998 3515#define DUK_USE_LEXER_SLIDING_WINDOW
7c673cae
FG
3516#undef DUK_USE_MARKANDSWEEP_FINALIZER_TORTURE
3517#define DUK_USE_MARK_AND_SWEEP_RECLIMIT 256
37b3c998 3518#define DUK_USE_MATH_BUILTIN
7c673cae 3519#define DUK_USE_NATIVE_CALL_RECLIMIT 1000
37b3c998
TL
3520#undef DUK_USE_PANIC_EXIT
3521#undef DUK_USE_PREFER_SIZE
3522#define DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS
7c673cae
FG
3523#undef DUK_USE_REFZERO_FINALIZER_TORTURE
3524#define DUK_USE_REGEXP_COMPILER_RECLIMIT 10000
3525#define DUK_USE_REGEXP_EXECUTOR_RECLIMIT 10000
37b3c998
TL
3526#define DUK_USE_ROM_PTRCOMP_FIRST 63488L
3527#undef DUK_USE_STRHASH_DENSE
3528#define DUK_USE_STRHASH_SKIP_SHIFT 5
3529#undef DUK_USE_VALSTACK_UNSAFE
3530#define DUK_USE_VERBOSE_EXECUTOR_ERRORS
7c673cae
FG
3531
3532/*
3533 * Alternative customization header
3534 *
3535 * If you want to modify the final DUK_USE_xxx flags directly (without
3536 * using the available DUK_OPT_xxx flags), define DUK_OPT_HAVE_CUSTOM_H
3537 * and tweak the final flags there.
3538 */
3539
3540#if defined(DUK_OPT_HAVE_CUSTOM_H)
3541#include "duk_custom.h"
3542#endif
3543
3544/*
3545 * You may add overriding #define/#undef directives below for
3546 * customization. You of course cannot un-#include or un-typedef
3547 * anything; these require direct changes above.
3548 */
3549
3550/* __OVERRIDE_DEFINES__ */
3551
3552/*
3553 * Date provider selection
3554 *
3555 * User may define DUK_USE_DATE_GET_NOW() etc directly, in which case we'll
3556 * rely on an external provider. If this is not done, revert to previous
3557 * behavior and use Unix/Windows built-in provider.
3558 */
3559
3560#if defined(DUK_COMPILING_DUKTAPE)
3561
3562#if defined(DUK_USE_DATE_GET_NOW)
3563/* External provider already defined. */
3564#elif defined(DUK_USE_DATE_NOW_GETTIMEOFDAY)
7c673cae
FG
3565#define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_gettimeofday((ctx))
3566#elif defined(DUK_USE_DATE_NOW_TIME)
7c673cae
FG
3567#define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_time((ctx))
3568#elif defined(DUK_USE_DATE_NOW_WINDOWS)
7c673cae
FG
3569#define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_windows((ctx))
3570#else
3571#error no provider for DUK_USE_DATE_GET_NOW()
3572#endif
3573
3574#if defined(DUK_USE_DATE_GET_LOCAL_TZOFFSET)
3575/* External provider already defined. */
3576#elif defined(DUK_USE_DATE_TZO_GMTIME_R) || defined(DUK_USE_DATE_TZO_GMTIME)
7c673cae
FG
3577#define DUK_USE_DATE_GET_LOCAL_TZOFFSET(d) duk_bi_date_get_local_tzoffset_gmtime((d))
3578#elif defined(DUK_USE_DATE_TZO_WINDOWS)
7c673cae
FG
3579#define DUK_USE_DATE_GET_LOCAL_TZOFFSET(d) duk_bi_date_get_local_tzoffset_windows((d))
3580#else
3581#error no provider for DUK_USE_DATE_GET_LOCAL_TZOFFSET()
3582#endif
3583
3584#if defined(DUK_USE_DATE_PARSE_STRING)
3585/* External provider already defined. */
3586#elif defined(DUK_USE_DATE_PRS_STRPTIME)
7c673cae
FG
3587#define DUK_USE_DATE_PARSE_STRING(ctx,str) duk_bi_date_parse_string_strptime((ctx), (str))
3588#elif defined(DUK_USE_DATE_PRS_GETDATE)
7c673cae
FG
3589#define DUK_USE_DATE_PARSE_STRING(ctx,str) duk_bi_date_parse_string_getdate((ctx), (str))
3590#else
3591/* No provider for DUK_USE_DATE_PARSE_STRING(), fall back to ISO 8601 only. */
3592#endif
3593
3594#if defined(DUK_USE_DATE_FORMAT_STRING)
3595/* External provider already defined. */
3596#elif defined(DUK_USE_DATE_FMT_STRFTIME)
7c673cae
FG
3597#define DUK_USE_DATE_FORMAT_STRING(ctx,parts,tzoffset,flags) \
3598 duk_bi_date_format_parts_strftime((ctx), (parts), (tzoffset), (flags))
3599#else
3600/* No provider for DUK_USE_DATE_FORMAT_STRING(), fall back to ISO 8601 only. */
3601#endif
3602
3603#endif /* DUK_COMPILING_DUKTAPE */
3604
3605/*
37b3c998 3606 * Checks for config option consistency (DUK_USE_xxx)
7c673cae
FG
3607 */
3608
37b3c998
TL
3609#if defined(DUK_USE_32BIT_PTRS)
3610#error unsupported config option used (option has been removed): DUK_USE_32BIT_PTRS
7c673cae 3611#endif
37b3c998
TL
3612#if defined(DUK_USE_ALIGN_4)
3613#error unsupported config option used (option has been removed): DUK_USE_ALIGN_4
7c673cae 3614#endif
37b3c998
TL
3615#if defined(DUK_USE_ALIGN_8)
3616#error unsupported config option used (option has been removed): DUK_USE_ALIGN_8
7c673cae 3617#endif
37b3c998
TL
3618#if defined(DUK_USE_BYTEORDER_FORCED)
3619#error unsupported config option used (option has been removed): DUK_USE_BYTEORDER_FORCED
7c673cae 3620#endif
37b3c998
TL
3621#if defined(DUK_USE_DATAPTR_DEC16) && !defined(DUK_USE_DATAPTR16)
3622#error config option DUK_USE_DATAPTR_DEC16 requires option DUK_USE_DATAPTR16 (which is missing)
7c673cae 3623#endif
37b3c998
TL
3624#if defined(DUK_USE_DATAPTR_ENC16) && !defined(DUK_USE_DATAPTR16)
3625#error config option DUK_USE_DATAPTR_ENC16 requires option DUK_USE_DATAPTR16 (which is missing)
7c673cae 3626#endif
37b3c998
TL
3627#if defined(DUK_USE_DEBUGGER_SUPPORT) && !defined(DUK_USE_INTERRUPT_COUNTER)
3628#error config option DUK_USE_DEBUGGER_SUPPORT requires option DUK_USE_INTERRUPT_COUNTER (which is missing)
7c673cae 3629#endif
37b3c998
TL
3630#if defined(DUK_USE_DEEP_C_STACK)
3631#error unsupported config option used (option has been removed): DUK_USE_DEEP_C_STACK
3632#endif
3633#if defined(DUK_USE_DOUBLE_BE)
3634#error unsupported config option used (option has been removed): DUK_USE_DOUBLE_BE
3635#endif
3636#if defined(DUK_USE_DOUBLE_BE) && defined(DUK_USE_DOUBLE_LE)
3637#error config option DUK_USE_DOUBLE_BE conflicts with option DUK_USE_DOUBLE_LE (which is also defined)
3638#endif
3639#if defined(DUK_USE_DOUBLE_BE) && defined(DUK_USE_DOUBLE_ME)
3640#error config option DUK_USE_DOUBLE_BE conflicts with option DUK_USE_DOUBLE_ME (which is also defined)
3641#endif
3642#if defined(DUK_USE_DOUBLE_LE)
3643#error unsupported config option used (option has been removed): DUK_USE_DOUBLE_LE
3644#endif
3645#if defined(DUK_USE_DOUBLE_LE) && defined(DUK_USE_DOUBLE_BE)
3646#error config option DUK_USE_DOUBLE_LE conflicts with option DUK_USE_DOUBLE_BE (which is also defined)
3647#endif
3648#if defined(DUK_USE_DOUBLE_LE) && defined(DUK_USE_DOUBLE_ME)
3649#error config option DUK_USE_DOUBLE_LE conflicts with option DUK_USE_DOUBLE_ME (which is also defined)
3650#endif
3651#if defined(DUK_USE_DOUBLE_ME)
3652#error unsupported config option used (option has been removed): DUK_USE_DOUBLE_ME
3653#endif
3654#if defined(DUK_USE_DOUBLE_ME) && defined(DUK_USE_DOUBLE_LE)
3655#error config option DUK_USE_DOUBLE_ME conflicts with option DUK_USE_DOUBLE_LE (which is also defined)
3656#endif
3657#if defined(DUK_USE_DOUBLE_ME) && defined(DUK_USE_DOUBLE_BE)
3658#error config option DUK_USE_DOUBLE_ME conflicts with option DUK_USE_DOUBLE_BE (which is also defined)
7c673cae 3659#endif
7c673cae 3660#if defined(DUK_USE_DPRINT) && !defined(DUK_USE_DEBUG)
37b3c998 3661#error config option DUK_USE_DPRINT requires option DUK_USE_DEBUG (which is missing)
7c673cae 3662#endif
37b3c998
TL
3663#if defined(DUK_USE_ESBC_MAX_BYTES) && !defined(DUK_USE_ESBC_LIMITS)
3664#error config option DUK_USE_ESBC_MAX_BYTES requires option DUK_USE_ESBC_LIMITS (which is missing)
7c673cae 3665#endif
37b3c998
TL
3666#if defined(DUK_USE_ESBC_MAX_LINENUMBER) && !defined(DUK_USE_ESBC_LIMITS)
3667#error config option DUK_USE_ESBC_MAX_LINENUMBER requires option DUK_USE_ESBC_LIMITS (which is missing)
3668#endif
3669#if defined(DUK_USE_EXEC_TIMEOUT_CHECK) && !defined(DUK_USE_INTERRUPT_COUNTER)
3670#error config option DUK_USE_EXEC_TIMEOUT_CHECK requires option DUK_USE_INTERRUPT_COUNTER (which is missing)
3671#endif
3672#if defined(DUK_USE_EXTSTR_FREE) && !defined(DUK_USE_HSTRING_EXTDATA)
3673#error config option DUK_USE_EXTSTR_FREE requires option DUK_USE_HSTRING_EXTDATA (which is missing)
3674#endif
3675#if defined(DUK_USE_EXTSTR_INTERN_CHECK) && !defined(DUK_USE_HSTRING_EXTDATA)
3676#error config option DUK_USE_EXTSTR_INTERN_CHECK requires option DUK_USE_HSTRING_EXTDATA (which is missing)
3677#endif
3678#if defined(DUK_USE_FULL_TVAL)
3679#error unsupported config option used (option has been removed): DUK_USE_FULL_TVAL
3680#endif
3681#if defined(DUK_USE_FUNCPTR_DEC16) && !defined(DUK_USE_FUNCPTR16)
3682#error config option DUK_USE_FUNCPTR_DEC16 requires option DUK_USE_FUNCPTR16 (which is missing)
3683#endif
3684#if defined(DUK_USE_FUNCPTR_ENC16) && !defined(DUK_USE_FUNCPTR16)
3685#error config option DUK_USE_FUNCPTR_ENC16 requires option DUK_USE_FUNCPTR16 (which is missing)
3686#endif
3687#if defined(DUK_USE_HASHBYTES_UNALIGNED_U32_ACCESS)
3688#error unsupported config option used (option has been removed): DUK_USE_HASHBYTES_UNALIGNED_U32_ACCESS
7c673cae 3689#endif
7c673cae 3690#if defined(DUK_USE_HEAPPTR16) && defined(DUK_USE_DEBUG)
37b3c998 3691#error config option DUK_USE_HEAPPTR16 conflicts with option DUK_USE_DEBUG (which is also defined)
7c673cae 3692#endif
37b3c998
TL
3693#if defined(DUK_USE_HEAPPTR_DEC16) && !defined(DUK_USE_HEAPPTR16)
3694#error config option DUK_USE_HEAPPTR_DEC16 requires option DUK_USE_HEAPPTR16 (which is missing)
7c673cae 3695#endif
37b3c998
TL
3696#if defined(DUK_USE_HEAPPTR_ENC16) && !defined(DUK_USE_HEAPPTR16)
3697#error config option DUK_USE_HEAPPTR_ENC16 requires option DUK_USE_HEAPPTR16 (which is missing)
7c673cae 3698#endif
37b3c998
TL
3699#if defined(DUK_USE_INTEGER_BE)
3700#error unsupported config option used (option has been removed): DUK_USE_INTEGER_BE
7c673cae 3701#endif
37b3c998
TL
3702#if defined(DUK_USE_INTEGER_BE) && defined(DUK_USE_INTEGER_LE)
3703#error config option DUK_USE_INTEGER_BE conflicts with option DUK_USE_INTEGER_LE (which is also defined)
3704#endif
3705#if defined(DUK_USE_INTEGER_BE) && defined(DUK_USE_INTEGER_ME)
3706#error config option DUK_USE_INTEGER_BE conflicts with option DUK_USE_INTEGER_ME (which is also defined)
3707#endif
3708#if defined(DUK_USE_INTEGER_LE)
3709#error unsupported config option used (option has been removed): DUK_USE_INTEGER_LE
3710#endif
3711#if defined(DUK_USE_INTEGER_LE) && defined(DUK_USE_INTEGER_BE)
3712#error config option DUK_USE_INTEGER_LE conflicts with option DUK_USE_INTEGER_BE (which is also defined)
3713#endif
3714#if defined(DUK_USE_INTEGER_LE) && defined(DUK_USE_INTEGER_ME)
3715#error config option DUK_USE_INTEGER_LE conflicts with option DUK_USE_INTEGER_ME (which is also defined)
3716#endif
3717#if defined(DUK_USE_INTEGER_ME)
3718#error unsupported config option used (option has been removed): DUK_USE_INTEGER_ME
3719#endif
3720#if defined(DUK_USE_INTEGER_ME) && defined(DUK_USE_INTEGER_LE)
3721#error config option DUK_USE_INTEGER_ME conflicts with option DUK_USE_INTEGER_LE (which is also defined)
3722#endif
3723#if defined(DUK_USE_INTEGER_ME) && defined(DUK_USE_INTEGER_BE)
3724#error config option DUK_USE_INTEGER_ME conflicts with option DUK_USE_INTEGER_BE (which is also defined)
3725#endif
3726#if defined(DUK_USE_NO_DOUBLE_ALIASING_SELFTEST)
3727#error unsupported config option used (option has been removed): DUK_USE_NO_DOUBLE_ALIASING_SELFTEST
3728#endif
3729#if defined(DUK_USE_PACKED_TVAL_POSSIBLE)
3730#error unsupported config option used (option has been removed): DUK_USE_PACKED_TVAL_POSSIBLE
3731#endif
3732#if defined(DUK_USE_RDTSC)
3733#error unsupported config option used (option has been removed): DUK_USE_RDTSC
3734#endif
3735#if defined(DUK_USE_ROM_GLOBAL_CLONE) && !defined(DUK_USE_ROM_STRINGS)
3736#error config option DUK_USE_ROM_GLOBAL_CLONE requires option DUK_USE_ROM_STRINGS (which is missing)
3737#endif
3738#if defined(DUK_USE_ROM_GLOBAL_CLONE) && !defined(DUK_USE_ROM_OBJECTS)
3739#error config option DUK_USE_ROM_GLOBAL_CLONE requires option DUK_USE_ROM_OBJECTS (which is missing)
3740#endif
3741#if defined(DUK_USE_ROM_GLOBAL_CLONE) && defined(DUK_USE_ROM_GLOBAL_INHERIT)
3742#error config option DUK_USE_ROM_GLOBAL_CLONE conflicts with option DUK_USE_ROM_GLOBAL_INHERIT (which is also defined)
3743#endif
3744#if defined(DUK_USE_ROM_GLOBAL_INHERIT) && !defined(DUK_USE_ROM_STRINGS)
3745#error config option DUK_USE_ROM_GLOBAL_INHERIT requires option DUK_USE_ROM_STRINGS (which is missing)
3746#endif
3747#if defined(DUK_USE_ROM_GLOBAL_INHERIT) && !defined(DUK_USE_ROM_OBJECTS)
3748#error config option DUK_USE_ROM_GLOBAL_INHERIT requires option DUK_USE_ROM_OBJECTS (which is missing)
3749#endif
3750#if defined(DUK_USE_ROM_GLOBAL_INHERIT) && defined(DUK_USE_ROM_GLOBAL_CLONE)
3751#error config option DUK_USE_ROM_GLOBAL_INHERIT conflicts with option DUK_USE_ROM_GLOBAL_CLONE (which is also defined)
3752#endif
3753#if defined(DUK_USE_ROM_OBJECTS) && !defined(DUK_USE_ROM_STRINGS)
3754#error config option DUK_USE_ROM_OBJECTS requires option DUK_USE_ROM_STRINGS (which is missing)
3755#endif
3756#if defined(DUK_USE_ROM_STRINGS) && !defined(DUK_USE_ROM_OBJECTS)
3757#error config option DUK_USE_ROM_STRINGS requires option DUK_USE_ROM_OBJECTS (which is missing)
3758#endif
3759#if defined(DUK_USE_SETJMP)
3760#error unsupported config option used (option has been removed): DUK_USE_SETJMP
3761#endif
3762#if defined(DUK_USE_SIGSETJMP)
3763#error unsupported config option used (option has been removed): DUK_USE_SIGSETJMP
3764#endif
3765#if defined(DUK_USE_STRTAB_CHAIN_SIZE) && !defined(DUK_USE_STRTAB_CHAIN)
3766#error config option DUK_USE_STRTAB_CHAIN_SIZE requires option DUK_USE_STRTAB_CHAIN (which is missing)
3767#endif
3768#if defined(DUK_USE_TAILCALL) && defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY)
3769#error config option DUK_USE_TAILCALL conflicts with option DUK_USE_NONSTD_FUNC_CALLER_PROPERTY (which is also defined)
3770#endif
3771#if defined(DUK_USE_UNALIGNED_ACCESSES_POSSIBLE)
3772#error unsupported config option used (option has been removed): DUK_USE_UNALIGNED_ACCESSES_POSSIBLE
3773#endif
3774#if defined(DUK_USE_UNDERSCORE_SETJMP)
3775#error unsupported config option used (option has been removed): DUK_USE_UNDERSCORE_SETJMP
7c673cae
FG
3776#endif
3777
37b3c998
TL
3778#if defined(DUK_USE_CPP_EXCEPTIONS) && !defined(__cplusplus)
3779#error DUK_USE_CPP_EXCEPTIONS enabled but not compiling with a C++ compiler
7c673cae
FG
3780#endif
3781
3782/*
37b3c998
TL
3783 * Convert DUK_USE_BYTEORDER, from whatever source, into currently used
3784 * internal defines. If detection failed, #error out.
7c673cae
FG
3785 */
3786
37b3c998
TL
3787#if defined(DUK_USE_BYTEORDER)
3788#if (DUK_USE_BYTEORDER == 1)
3789#define DUK_USE_INTEGER_LE
3790#define DUK_USE_DOUBLE_LE
3791#elif (DUK_USE_BYTEORDER == 2)
3792#define DUK_USE_INTEGER_LE /* integer endianness is little on purpose */
3793#define DUK_USE_DOUBLE_ME
3794#elif (DUK_USE_BYTEORDER == 3)
3795#define DUK_USE_INTEGER_BE
3796#define DUK_USE_DOUBLE_BE
3797#else
3798#error unsupported: byte order invalid
3799#endif /* byte order */
3800#else
3801#error unsupported: byte order detection failed
3802#endif /* defined(DUK_USE_BYTEORDER) */
7c673cae
FG
3803
3804#endif /* DUK_CONFIG_H_INCLUDED */