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