1 /*
2  *  duk_config.h configuration header generated by genconfig.py.
3  *
4  *  Git commit: external
5  *  Git describe: external
6  *  Git branch: external
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 #if !defined(DUK_USE_BYTEORDER)
968 #define DUK_USE_BYTEORDER 3
969 #endif
970 #undef DUK_USE_PACKED_TVAL
971 #define DUK_F_PACKED_TVAL_PROVIDED
972 #elif defined(DUK_F_SPARC32)
973 /* --- SPARC 32-bit --- */
974 #define DUK_USE_ARCH_STRING "sparc32"
975 /* SPARC byte order varies so rely on autodetection. */
976 #define DUK_USE_PACKED_TVAL
977 #define DUK_F_PACKED_TVAL_PROVIDED
978 #elif defined(DUK_F_SPARC64)
979 /* --- SPARC 64-bit --- */
980 #define DUK_USE_ARCH_STRING "sparc64"
981 /* SPARC byte order varies so rely on autodetection. */
982 #undef DUK_USE_PACKED_TVAL
983 #define DUK_F_PACKED_TVAL_PROVIDED
984 #elif defined(DUK_F_RISCV32)
985 /* --- RISC-V 32-bit --- */
986 #define DUK_USE_ARCH_STRING "riscv32"
987 #define DUK_USE_BYTEORDER 1
988 #define DUK_USE_PACKED_TVAL
989 #define DUK_F_PACKED_TVAL_PROVIDED
990 #elif defined(DUK_F_RISCV64)
991 /* --- RISC-V 64-bit --- */
992 #define DUK_USE_ARCH_STRING "riscv64"
993 #define DUK_USE_BYTEORDER 1
994 #undef DUK_USE_PACKED_TVAL
995 #define DUK_F_PACKED_TVAL_PROVIDED
996 #elif defined(DUK_F_SUPERH)
997 /* --- SuperH --- */
998 #define DUK_USE_ARCH_STRING "sh"
999 /* Byte order varies, rely on autodetection. */
1000 #define DUK_USE_PACKED_TVAL
1001 #define DUK_F_PACKED_TVAL_PROVIDED
1002 #elif defined(DUK_F_M68K)
1003 /* --- Motorola 68k --- */
1004 #define DUK_USE_ARCH_STRING "m68k"
1005 #if !defined(DUK_USE_BYTEORDER)
1006 #define DUK_USE_BYTEORDER 3
1007 #endif
1008 #define DUK_USE_PACKED_TVAL
1009 #define DUK_F_PACKED_TVAL_PROVIDED
1010 #elif defined(DUK_F_EMSCRIPTEN)
1011 /* --- Emscripten --- */
1012 #define DUK_USE_ARCH_STRING "emscripten"
1013 #if !defined(DUK_USE_BYTEORDER)
1014 #define DUK_USE_BYTEORDER 1
1015 #endif
1016 #undef DUK_USE_PACKED_TVAL
1017 #define DUK_F_PACKED_TVAL_PROVIDED
1018 #else
1019 /* --- Generic --- */
1020 /* These are necessary wild guesses. */
1021 #define DUK_USE_ARCH_STRING "generic"
1022 /* Rely on autodetection for byte order, alignment, and packed tval. */
1023 #endif  /* autodetect architecture */
1024 
1025 /*
1026  *  Compiler autodetection
1027  */
1028 
1029 #if defined(DUK_F_CLANG)
1030 /* --- Clang --- */
1031 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
1032 /* C99 / C++11 and above: rely on va_copy() which is required. */
1033 #define DUK_VA_COPY(dest,src) va_copy(dest,src)
1034 #else
1035 /* Clang: assume we have __va_copy() in non-C99 mode. */
1036 #define DUK_VA_COPY(dest,src) __va_copy(dest,src)
1037 #endif
1038 
1039 #define DUK_NORETURN(decl)  decl __attribute__((noreturn))
1040 
1041 #if defined(__clang__) && defined(__has_builtin)
1042 #if __has_builtin(__builtin_unreachable)
1043 #define DUK_UNREACHABLE()  do { __builtin_unreachable(); } while (0)
1044 #endif
1045 #endif
1046 
1047 #define DUK_USE_BRANCH_HINTS
1048 #define DUK_LIKELY(x)    __builtin_expect((x), 1)
1049 #define DUK_UNLIKELY(x)  __builtin_expect((x), 0)
1050 #if defined(__clang__) && defined(__has_builtin)
1051 #if __has_builtin(__builtin_unpredictable)
1052 #define DUK_UNPREDICTABLE(x)  __builtin_unpredictable((x))
1053 #endif
1054 #endif
1055 
1056 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
1057 #define DUK_NOINLINE        __attribute__((noinline))
1058 #define DUK_INLINE          inline
1059 #define DUK_ALWAYS_INLINE   inline __attribute__((always_inline))
1060 #endif
1061 
1062 /* DUK_HOT */
1063 /* DUK_COLD */
1064 
1065 #if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
1066 /* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
1067  * compiling Duktape or the application.
1068  */
1069 #if defined(DUK_COMPILING_DUKTAPE)
1070 #define DUK_EXTERNAL_DECL  extern __declspec(dllexport)
1071 #define DUK_EXTERNAL       __declspec(dllexport)
1072 #else
1073 #define DUK_EXTERNAL_DECL  extern __declspec(dllimport)
1074 #define DUK_EXTERNAL       should_not_happen
1075 #endif
1076 #if defined(DUK_SINGLE_FILE)
1077 #define DUK_INTERNAL_DECL  static
1078 #define DUK_INTERNAL       static
1079 #else
1080 #define DUK_INTERNAL_DECL  extern
1081 #define DUK_INTERNAL       /*empty*/
1082 #endif
1083 #define DUK_LOCAL_DECL     static
1084 #define DUK_LOCAL          static
1085 #else
1086 #define DUK_EXTERNAL_DECL  __attribute__ ((visibility("default"))) extern
1087 #define DUK_EXTERNAL       __attribute__ ((visibility("default")))
1088 #if defined(DUK_SINGLE_FILE)
1089 #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
1090 /* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
1091  * Clang.  Based on documentation it should suffice to have the attribute
1092  * in the declaration only, but in practice some warnings are generated unless
1093  * the attribute is also applied to the definition.
1094  */
1095 #define DUK_INTERNAL_DECL  static __attribute__ ((unused))
1096 #define DUK_INTERNAL       static __attribute__ ((unused))
1097 #else
1098 #define DUK_INTERNAL_DECL  static
1099 #define DUK_INTERNAL       static
1100 #endif
1101 #else
1102 #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
1103 #define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
1104 #define DUK_INTERNAL       __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
1105 #else
1106 #define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) extern
1107 #define DUK_INTERNAL       __attribute__ ((visibility("hidden")))
1108 #endif
1109 #endif
1110 #define DUK_LOCAL_DECL     static
1111 #define DUK_LOCAL          static
1112 #endif
1113 
1114 #if defined(DUK_F_CPP)
1115 #define DUK_USE_COMPILER_STRING "clang"
1116 #else
1117 #define DUK_USE_COMPILER_STRING "clang"
1118 #endif
1119 
1120 #undef DUK_USE_VARIADIC_MACROS
1121 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
1122 #define DUK_USE_VARIADIC_MACROS
1123 #endif
1124 
1125 #define DUK_USE_UNION_INITIALIZERS
1126 
1127 #undef DUK_USE_FLEX_C99
1128 #undef DUK_USE_FLEX_ZEROSIZE
1129 #undef DUK_USE_FLEX_ONESIZE
1130 #if defined(DUK_F_C99)
1131 #define DUK_USE_FLEX_C99
1132 #else
1133 #define DUK_USE_FLEX_ZEROSIZE
1134 #endif
1135 
1136 #define DUK_USE_CLANG_PRAGMAS
1137 #define DUK_USE_PACK_CLANG_ATTR
1138 
1139 #if defined(__clang__) && defined(__has_builtin)
1140 #if __has_builtin(__builtin_bswap64)
1141 #define DUK_BSWAP64(x) ((duk_uint64_t) __builtin_bswap64((duk_uint64_t) (x)))
1142 #endif
1143 #if __has_builtin(__builtin_bswap32)
1144 #define DUK_BSWAP32(x) ((duk_uint32_t) __builtin_bswap32((duk_uint32_t) (x)))
1145 #endif
1146 #if __has_builtin(__builtin_bswap16)
1147 #define DUK_BSWAP16(x) ((duk_uint16_t) __builtin_bswap16((duk_uint16_t) (x)))
1148 #endif
1149 #endif
1150 #elif defined(DUK_F_GCC)
1151 /* --- GCC --- */
1152 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
1153 /* C99 / C++11 and above: rely on va_copy() which is required. */
1154 #define DUK_VA_COPY(dest,src) va_copy(dest,src)
1155 #else
1156 /* GCC: assume we have __va_copy() in non-C99 mode. */
1157 #define DUK_VA_COPY(dest,src) __va_copy(dest,src)
1158 #endif
1159 
1160 #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 20500L) && (DUK_F_GCC_VERSION < 50000L)
1161 /* Since gcc-2.5.
1162  *
1163  * Disabled temporarily in GCC 5+ because of an unresolved noreturn-related
1164  * issue: https://github.com/svaarala/duktape/issues/2155.
1165  */
1166 #define DUK_NORETURN(decl)  decl __attribute__((noreturn))
1167 #endif
1168 
1169 #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40500L)
1170 /* Since gcc-4.5. */
1171 #define DUK_UNREACHABLE()  do { __builtin_unreachable(); } while (0)
1172 #endif
1173 
1174 #define DUK_USE_BRANCH_HINTS
1175 #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40500L)
1176 /* GCC: test not very accurate; enable only in relatively recent builds
1177  * because of bugs in gcc-4.4 (http://lists.debian.org/debian-gcc/2010/04/msg00000.html)
1178  */
1179 #define DUK_LIKELY(x)    __builtin_expect((x), 1)
1180 #define DUK_UNLIKELY(x)  __builtin_expect((x), 0)
1181 #endif
1182 /* XXX: equivalent of clang __builtin_unpredictable? */
1183 
1184 #if (defined(DUK_F_C99) || defined(DUK_F_CPP11)) && \
1185     defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 30101)
1186 #define DUK_NOINLINE        __attribute__((noinline))
1187 #define DUK_INLINE          inline
1188 #define DUK_ALWAYS_INLINE   inline __attribute__((always_inline))
1189 #endif
1190 
1191 #if (defined(DUK_F_C99) || defined(DUK_F_CPP11)) && \
1192     defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40300)
1193 #define DUK_HOT             __attribute__((hot))
1194 #define DUK_COLD            __attribute__((cold))
1195 #endif
1196 
1197 #if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
1198 /* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
1199  * compiling Duktape or the application.
1200  */
1201 #if defined(DUK_COMPILING_DUKTAPE)
1202 #define DUK_EXTERNAL_DECL  extern __declspec(dllexport)
1203 #define DUK_EXTERNAL       __declspec(dllexport)
1204 #else
1205 #define DUK_EXTERNAL_DECL  extern __declspec(dllimport)
1206 #define DUK_EXTERNAL       should_not_happen
1207 #endif
1208 #if defined(DUK_SINGLE_FILE)
1209 #define DUK_INTERNAL_DECL  static
1210 #define DUK_INTERNAL       static
1211 #else
1212 #define DUK_INTERNAL_DECL  extern
1213 #define DUK_INTERNAL       /*empty*/
1214 #endif
1215 #define DUK_LOCAL_DECL     static
1216 #define DUK_LOCAL          static
1217 #elif defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40000)
1218 #define DUK_EXTERNAL_DECL  __attribute__ ((visibility("default"))) extern
1219 #define DUK_EXTERNAL       __attribute__ ((visibility("default")))
1220 #if defined(DUK_SINGLE_FILE)
1221 #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
1222 /* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
1223  * Clang.  Based on documentation it should suffice to have the attribute
1224  * in the declaration only, but in practice some warnings are generated unless
1225  * the attribute is also applied to the definition.
1226  */
1227 #define DUK_INTERNAL_DECL  static __attribute__ ((unused))
1228 #define DUK_INTERNAL       static __attribute__ ((unused))
1229 #else
1230 #define DUK_INTERNAL_DECL  static
1231 #define DUK_INTERNAL       static
1232 #endif
1233 #else
1234 #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
1235 #define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
1236 #define DUK_INTERNAL       __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
1237 #else
1238 #define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) extern
1239 #define DUK_INTERNAL       __attribute__ ((visibility("hidden")))
1240 #endif
1241 #endif
1242 #define DUK_LOCAL_DECL     static
1243 #define DUK_LOCAL          static
1244 #endif
1245 
1246 #if defined(DUK_F_MINGW)
1247 #if defined(DUK_F_CPP)
1248 #define DUK_USE_COMPILER_STRING "mingw++"
1249 #else
1250 #define DUK_USE_COMPILER_STRING "mingw"
1251 #endif
1252 #else
1253 #if defined(DUK_F_CPP)
1254 #define DUK_USE_COMPILER_STRING "g++"
1255 #else
1256 #define DUK_USE_COMPILER_STRING "gcc"
1257 #endif
1258 #endif
1259 
1260 #undef DUK_USE_VARIADIC_MACROS
1261 #if defined(DUK_F_C99) || (defined(DUK_F_CPP11) && defined(__GNUC__))
1262 #define DUK_USE_VARIADIC_MACROS
1263 #endif
1264 
1265 #define DUK_USE_UNION_INITIALIZERS
1266 
1267 #undef DUK_USE_FLEX_C99
1268 #undef DUK_USE_FLEX_ZEROSIZE
1269 #undef DUK_USE_FLEX_ONESIZE
1270 #if defined(DUK_F_C99)
1271 #define DUK_USE_FLEX_C99
1272 #else
1273 #define DUK_USE_FLEX_ZEROSIZE
1274 #endif
1275 
1276 /* Since 4.6 one can '#pragma GCC diagnostic push/pop'. */
1277 #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40600)
1278 #define DUK_USE_GCC_PRAGMAS
1279 #else
1280 #undef DUK_USE_GCC_PRAGMAS
1281 #endif
1282 
1283 #define DUK_USE_PACK_GCC_ATTR
1284 
1285 /* Availability varies based on platform (between GCC 4.4 and 4.8), and there
1286  * are apparently some bugs in GCC 4.x.  Check for GCC 5.0 before enabling
1287  * these to be safe.
1288  */
1289 #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 50000L)
1290 #define DUK_BSWAP64(x) ((duk_uint64_t) __builtin_bswap64((duk_uint64_t) (x)))
1291 #define DUK_BSWAP32(x) ((duk_uint32_t) __builtin_bswap32((duk_uint32_t) (x)))
1292 #define DUK_BSWAP16(x) ((duk_uint16_t) __builtin_bswap16((duk_uint16_t) (x)))
1293 #endif
1294 #elif defined(DUK_F_MSVC)
1295 /* --- MSVC --- */
1296 /* http://msdn.microsoft.com/en-us/library/aa235362(VS.60).aspx */
1297 #define DUK_NORETURN(decl)  __declspec(noreturn) decl
1298 
1299 /* XXX: DUK_UNREACHABLE for msvc? */
1300 
1301 #undef DUK_USE_BRANCH_HINTS
1302 
1303 /* XXX: DUK_LIKELY, DUK_UNLIKELY for msvc? */
1304 /* XXX: DUK_NOINLINE, DUK_INLINE, DUK_ALWAYS_INLINE for msvc? */
1305 
1306 #if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
1307 /* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
1308  * compiling Duktape or the application.
1309  */
1310 #if defined(DUK_COMPILING_DUKTAPE)
1311 #define DUK_EXTERNAL_DECL  extern __declspec(dllexport)
1312 #define DUK_EXTERNAL       __declspec(dllexport)
1313 #else
1314 #define DUK_EXTERNAL_DECL  extern __declspec(dllimport)
1315 #define DUK_EXTERNAL       should_not_happen
1316 #endif
1317 #if defined(DUK_SINGLE_FILE)
1318 #define DUK_INTERNAL_DECL  static
1319 #define DUK_INTERNAL       static
1320 #else
1321 #define DUK_INTERNAL_DECL  extern
1322 #define DUK_INTERNAL       /*empty*/
1323 #endif
1324 #define DUK_LOCAL_DECL     static
1325 #define DUK_LOCAL          static
1326 #endif
1327 
1328 #if defined(DUK_F_CPP)
1329 #define DUK_USE_COMPILER_STRING "msvc++"
1330 #else
1331 #define DUK_USE_COMPILER_STRING "msvc"
1332 #endif
1333 
1334 #undef DUK_USE_VARIADIC_MACROS
1335 #if defined(DUK_F_C99)
1336 #define DUK_USE_VARIADIC_MACROS
1337 #elif defined(_MSC_VER) && (_MSC_VER >= 1400)
1338 /* VS2005+ should have variadic macros even when they're not C99. */
1339 #define DUK_USE_VARIADIC_MACROS
1340 #endif
1341 
1342 #undef DUK_USE_UNION_INITIALIZERS
1343 #if defined(_MSC_VER) && (_MSC_VER >= 1800)
1344 /* VS2013+ supports union initializers but there's a bug involving union-inside-struct:
1345  * https://connect.microsoft.com/VisualStudio/feedback/details/805981
1346  * The bug was fixed (at least) in VS2015 so check for VS2015 for now:
1347  * https://blogs.msdn.microsoft.com/vcblog/2015/07/01/c-compiler-front-end-fixes-in-vs2015/
1348  * Manually tested using VS2013, CL reports 18.00.31101, so enable for VS2013 too.
1349  */
1350 #define DUK_USE_UNION_INITIALIZERS
1351 #endif
1352 
1353 #undef DUK_USE_FLEX_C99
1354 #undef DUK_USE_FLEX_ZEROSIZE
1355 #undef DUK_USE_FLEX_ONESIZE
1356 #if defined(DUK_F_C99)
1357 #define DUK_USE_FLEX_C99
1358 #else
1359 #define DUK_USE_FLEX_ZEROSIZE
1360 #endif
1361 
1362 #undef DUK_USE_GCC_PRAGMAS
1363 
1364 #define DUK_USE_PACK_MSVC_PRAGMA
1365 
1366 /* These have been tested from VS2008 onwards; may work in older VS versions
1367  * too but not enabled by default.
1368  */
1369 #if defined(_MSC_VER) && (_MSC_VER >= 1500)
1370 #define DUK_NOINLINE        __declspec(noinline)
1371 #define DUK_INLINE          __inline
1372 #define DUK_ALWAYS_INLINE   __forceinline
1373 #endif
1374 
1375 #if defined(_MSC_VER) && (_MSC_VER >= 1900)
1376 #define DUK_SNPRINTF     snprintf
1377 #define DUK_VSNPRINTF    vsnprintf
1378 #else
1379 /* (v)snprintf() is missing before MSVC 2015.  Note that _(v)snprintf() does
1380  * NOT NUL terminate on truncation, but Duktape code never assumes that.
1381  * http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
1382  */
1383 #define DUK_SNPRINTF     _snprintf
1384 #define DUK_VSNPRINTF    _vsnprintf
1385 #endif
1386 
1387 /* Avoid warning when doing DUK_UNREF(some_function). */
1388 #if defined(_MSC_VER) && (_MSC_VER < 1500)
1389 #pragma warning(disable: 4100 4101 4550 4551)
1390 #define DUK_UNREF(x)
1391 #else
1392 #define DUK_UNREF(x)  do { __pragma(warning(suppress:4100 4101 4550 4551)) (x); } while (0)
1393 #endif
1394 
1395 /* Older versions of MSVC don't support the LL/ULL suffix. */
1396 #define DUK_U64_CONSTANT(x) x##ui64
1397 #define DUK_I64_CONSTANT(x) x##i64
1398 #elif defined(DUK_F_EMSCRIPTEN)
1399 /* --- Emscripten --- */
1400 #define DUK_NORETURN(decl)  decl __attribute__((noreturn))
1401 
1402 #if defined(__clang__) && defined(__has_builtin)
1403 #if __has_builtin(__builtin_unreachable)
1404 #define DUK_UNREACHABLE()  do { __builtin_unreachable(); } while (0)
1405 #endif
1406 #endif
1407 
1408 #define DUK_USE_BRANCH_HINTS
1409 #define DUK_LIKELY(x)    __builtin_expect((x), 1)
1410 #define DUK_UNLIKELY(x)  __builtin_expect((x), 0)
1411 #if defined(__clang__) && defined(__has_builtin)
1412 #if __has_builtin(__builtin_unpredictable)
1413 #define DUK_UNPREDICTABLE(x)  __builtin_unpredictable((x))
1414 #endif
1415 #endif
1416 
1417 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
1418 #define DUK_NOINLINE        __attribute__((noinline))
1419 #define DUK_INLINE          inline
1420 #define DUK_ALWAYS_INLINE   inline __attribute__((always_inline))
1421 #endif
1422 
1423 #define DUK_EXTERNAL_DECL  __attribute__ ((visibility("default"))) extern
1424 #define DUK_EXTERNAL       __attribute__ ((visibility("default")))
1425 #if defined(DUK_SINGLE_FILE)
1426 #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
1427 /* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
1428  * Clang.  Based on documentation it should suffice to have the attribute
1429  * in the declaration only, but in practice some warnings are generated unless
1430  * the attribute is also applied to the definition.
1431  */
1432 #define DUK_INTERNAL_DECL  static __attribute__ ((unused))
1433 #define DUK_INTERNAL       static __attribute__ ((unused))
1434 #else
1435 #define DUK_INTERNAL_DECL  static
1436 #define DUK_INTERNAL       static
1437 #endif
1438 #else
1439 #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
1440 #define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
1441 #define DUK_INTERNAL       __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
1442 #else
1443 #define DUK_INTERNAL_DECL  __attribute__ ((visibility("hidden"))) extern
1444 #define DUK_INTERNAL       __attribute__ ((visibility("hidden")))
1445 #endif
1446 #endif
1447 #define DUK_LOCAL_DECL     static
1448 #define DUK_LOCAL          static
1449 
1450 #define DUK_USE_COMPILER_STRING "emscripten"
1451 
1452 #undef DUK_USE_VARIADIC_MACROS
1453 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
1454 #define DUK_USE_VARIADIC_MACROS
1455 #endif
1456 
1457 #define DUK_USE_UNION_INITIALIZERS
1458 
1459 #undef DUK_USE_FLEX_C99
1460 #undef DUK_USE_FLEX_ZEROSIZE
1461 #undef DUK_USE_FLEX_ONESIZE
1462 #if defined(DUK_F_C99)
1463 #define DUK_USE_FLEX_C99
1464 #else
1465 #define DUK_USE_FLEX_ZEROSIZE
1466 #endif
1467 
1468 #undef DUK_USE_GCC_PRAGMAS
1469 #define DUK_USE_PACK_CLANG_ATTR
1470 #elif defined(DUK_F_TINYC)
1471 /* --- TinyC --- */
1472 #undef DUK_USE_BRANCH_HINTS
1473 
1474 #if defined(DUK_F_CPP)
1475 #define DUK_USE_COMPILER_STRING "tinyc++"
1476 #else
1477 #define DUK_USE_COMPILER_STRING "tinyc"
1478 #endif
1479 
1480 /* http://bellard.org/tcc/tcc-doc.html#SEC7 */
1481 #define DUK_USE_VARIADIC_MACROS
1482 
1483 #define DUK_USE_UNION_INITIALIZERS
1484 
1485 /* Most portable, wastes space */
1486 #define DUK_USE_FLEX_ONESIZE
1487 
1488 /* Most portable, potentially wastes space */
1489 #define DUK_USE_PACK_DUMMY_MEMBER
1490 #elif defined(DUK_F_VBCC)
1491 /* --- VBCC --- */
1492 #undef DUK_USE_BRANCH_HINTS
1493 
1494 #if defined(DUK_F_CPP)
1495 #define DUK_USE_COMPILER_STRING "vbcc-c++"
1496 #else
1497 #define DUK_USE_COMPILER_STRING "vbcc"
1498 #endif
1499 
1500 #undef DUK_USE_VARIADIC_MACROS
1501 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
1502 #define DUK_USE_VARIADIC_MACROS
1503 #endif
1504 
1505 /* VBCC supports C99 so check only for C99 for union initializer support.
1506  * Designated union initializers would possibly work even without a C99 check.
1507  */
1508 #undef DUK_USE_UNION_INITIALIZERS
1509 #if defined(DUK_F_C99)
1510 #define DUK_USE_UNION_INITIALIZERS
1511 #endif
1512 
1513 #define DUK_USE_FLEX_ZEROSIZE
1514 #define DUK_USE_PACK_DUMMY_MEMBER
1515 #elif defined(DUK_F_BCC)
1516 /* --- Bruce's C compiler --- */
1517 #undef DUK_USE_BRANCH_HINTS
1518 
1519 #if defined(DUK_F_CPP)
1520 #define DUK_USE_COMPILER_STRING "bcc++"
1521 #else
1522 #define DUK_USE_COMPILER_STRING "bcc"
1523 #endif
1524 
1525 /* Most portable */
1526 #undef DUK_USE_VARIADIC_MACROS
1527 
1528 /* Most portable, wastes space */
1529 #undef DUK_USE_UNION_INITIALIZERS
1530 
1531 /* Most portable, wastes space */
1532 #define DUK_USE_FLEX_ONESIZE
1533 
1534 /* Most portable, potentially wastes space */
1535 #define DUK_USE_PACK_DUMMY_MEMBER
1536 
1537 /* BCC, assume we're on x86. */
1538 #if !defined(DUK_USE_BYTEORDER)
1539 #define DUK_USE_BYTEORDER 1
1540 #endif
1541 #else
1542 /* --- Generic --- */
1543 #undef DUK_USE_BRANCH_HINTS
1544 
1545 #if defined(DUK_F_CPP)
1546 #define DUK_USE_COMPILER_STRING "generic-c++"
1547 #else
1548 #define DUK_USE_COMPILER_STRING "generic"
1549 #endif
1550 
1551 #undef DUK_USE_VARIADIC_MACROS
1552 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
1553 #define DUK_USE_VARIADIC_MACROS
1554 #endif
1555 
1556 /* C++ doesn't have standard designated union initializers ({ .foo = 1 }). */
1557 #undef DUK_USE_UNION_INITIALIZERS
1558 #if defined(DUK_F_C99)
1559 #define DUK_USE_UNION_INITIALIZERS
1560 #endif
1561 
1562 /* Most portable, wastes space */
1563 #define DUK_USE_FLEX_ONESIZE
1564 
1565 /* Most portable, potentially wastes space */
1566 #define DUK_USE_PACK_DUMMY_MEMBER
1567 #endif  /* autodetect compiler */
1568 
1569 /* uclibc */
1570 #if defined(__UCLIBC__)
1571 #define DUK_F_UCLIBC
1572 #endif
1573 
1574 /*
1575  *  Wrapper typedefs and constants for integer types, also sanity check types.
1576  *
1577  *  C99 typedefs are quite good but not always available, and we want to avoid
1578  *  forcibly redefining the C99 typedefs.  So, there are Duktape wrappers for
1579  *  all C99 typedefs and Duktape code should only use these typedefs.  Type
1580  *  detection when C99 is not supported is best effort and may end up detecting
1581  *  some types incorrectly.
1582  *
1583  *  Pointer sizes are a portability problem: pointers to different types may
1584  *  have a different size and function pointers are very difficult to manage
1585  *  portably.
1586  *
1587  *  http://en.wikipedia.org/wiki/C_data_types#Fixed-width_integer_types
1588  *
1589  *  Note: there's an interesting corner case when trying to define minimum
1590  *  signed integer value constants which leads to the current workaround of
1591  *  defining e.g. -0x80000000 as (-0x7fffffffL - 1L).  See doc/code-issues.txt
1592  *  for a longer discussion.
1593  *
1594  *  Note: avoid typecasts and computations in macro integer constants as they
1595  *  can then no longer be used in macro relational expressions (such as
1596  *  #if DUK_SIZE_MAX < 0xffffffffUL).  There is internal code which relies on
1597  *  being able to compare DUK_SIZE_MAX against a limit.
1598  */
1599 
1600 /* XXX: add feature options to force basic types from outside? */
1601 
1602 #if !defined(INT_MAX)
1603 #define INT_MAX 0x7FFFFFFF
1604 #endif
1605 
1606 /* Check that architecture is two's complement, standard C allows e.g.
1607  * INT_MIN to be -2**31+1 (instead of -2**31).
1608  */
1609 #if defined(INT_MAX) && defined(INT_MIN)
1610 #if INT_MAX != -(INT_MIN + 1)
1611 #error platform does not seem complement of two
1612 #endif
1613 #else
1614 #error cannot check complement of two
1615 #endif
1616 
1617 /* Pointer size determination based on __WORDSIZE or architecture when
1618  * that's not available.
1619  */
1620 #if defined(DUK_F_X86) || defined(DUK_F_X32) || \
1621     defined(DUK_F_M68K) || defined(DUK_F_PPC32) || \
1622     defined(DUK_F_BCC) || \
1623     (defined(__WORDSIZE) && (__WORDSIZE == 32)) || \
1624     ((defined(DUK_F_OLD_SOLARIS) || defined(DUK_F_AIX) || \
1625       defined(DUK_F_HPUX)) && defined(_ILP32)) || \
1626     defined(DUK_F_ARM32)
1627 #define DUK_F_32BIT_PTRS
1628 #elif defined(DUK_F_X64) || \
1629       (defined(__WORDSIZE) && (__WORDSIZE == 64)) || \
1630    ((defined(DUK_F_OLD_SOLARIS) || defined(DUK_F_AIX) || \
1631      defined(DUK_F_HPUX)) && defined(_LP64)) || \
1632     defined(DUK_F_ARM64)
1633 #define DUK_F_64BIT_PTRS
1634 #else
1635 /* not sure, not needed with C99 anyway */
1636 #endif
1637 
1638 /* Intermediate define for 'have inttypes.h' */
1639 #undef DUK_F_HAVE_INTTYPES
1640 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
1641     !(defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC))
1642 /* vbcc + AmigaOS has C99 but no inttypes.h */
1643 #define DUK_F_HAVE_INTTYPES
1644 #elif defined(__cplusplus) && (__cplusplus >= 201103L)
1645 /* C++11 apparently ratified stdint.h */
1646 #define DUK_F_HAVE_INTTYPES
1647 #endif
1648 
1649 /* Basic integer typedefs and limits, preferably from inttypes.h, otherwise
1650  * through automatic detection.
1651  */
1652 #if defined(DUK_F_HAVE_INTTYPES)
1653 /* C99 or compatible */
1654 
1655 #define DUK_F_HAVE_64BIT
1656 #include <inttypes.h>
1657 
1658 typedef uint8_t duk_uint8_t;
1659 typedef int8_t duk_int8_t;
1660 typedef uint16_t duk_uint16_t;
1661 typedef int16_t duk_int16_t;
1662 typedef uint32_t duk_uint32_t;
1663 typedef int32_t duk_int32_t;
1664 typedef uint64_t duk_uint64_t;
1665 typedef int64_t duk_int64_t;
1666 typedef uint_least8_t duk_uint_least8_t;
1667 typedef int_least8_t duk_int_least8_t;
1668 typedef uint_least16_t duk_uint_least16_t;
1669 typedef int_least16_t duk_int_least16_t;
1670 typedef uint_least32_t duk_uint_least32_t;
1671 typedef int_least32_t duk_int_least32_t;
1672 typedef uint_least64_t duk_uint_least64_t;
1673 typedef int_least64_t duk_int_least64_t;
1674 typedef uint_fast8_t duk_uint_fast8_t;
1675 typedef int_fast8_t duk_int_fast8_t;
1676 typedef uint_fast16_t duk_uint_fast16_t;
1677 typedef int_fast16_t duk_int_fast16_t;
1678 typedef uint_fast32_t duk_uint_fast32_t;
1679 typedef int_fast32_t duk_int_fast32_t;
1680 typedef uint_fast64_t duk_uint_fast64_t;
1681 typedef int_fast64_t duk_int_fast64_t;
1682 typedef uintptr_t duk_uintptr_t;
1683 typedef intptr_t duk_intptr_t;
1684 typedef uintmax_t duk_uintmax_t;
1685 typedef intmax_t duk_intmax_t;
1686 
1687 #define DUK_UINT8_MIN         0
1688 #define DUK_UINT8_MAX         UINT8_MAX
1689 #define DUK_INT8_MIN          INT8_MIN
1690 #define DUK_INT8_MAX          INT8_MAX
1691 #define DUK_UINT_LEAST8_MIN   0
1692 #define DUK_UINT_LEAST8_MAX   UINT_LEAST8_MAX
1693 #define DUK_INT_LEAST8_MIN    INT_LEAST8_MIN
1694 #define DUK_INT_LEAST8_MAX    INT_LEAST8_MAX
1695 #define DUK_UINT_FAST8_MIN    0
1696 #define DUK_UINT_FAST8_MAX    UINT_FAST8_MAX
1697 #define DUK_INT_FAST8_MIN     INT_FAST8_MIN
1698 #define DUK_INT_FAST8_MAX     INT_FAST8_MAX
1699 #define DUK_UINT16_MIN        0
1700 #define DUK_UINT16_MAX        UINT16_MAX
1701 #define DUK_INT16_MIN         INT16_MIN
1702 #define DUK_INT16_MAX         INT16_MAX
1703 #define DUK_UINT_LEAST16_MIN  0
1704 #define DUK_UINT_LEAST16_MAX  UINT_LEAST16_MAX
1705 #define DUK_INT_LEAST16_MIN   INT_LEAST16_MIN
1706 #define DUK_INT_LEAST16_MAX   INT_LEAST16_MAX
1707 #define DUK_UINT_FAST16_MIN   0
1708 #define DUK_UINT_FAST16_MAX   UINT_FAST16_MAX
1709 #define DUK_INT_FAST16_MIN    INT_FAST16_MIN
1710 #define DUK_INT_FAST16_MAX    INT_FAST16_MAX
1711 #define DUK_UINT32_MIN        0
1712 #define DUK_UINT32_MAX        UINT32_MAX
1713 #define DUK_INT32_MIN         INT32_MIN
1714 #define DUK_INT32_MAX         INT32_MAX
1715 #define DUK_UINT_LEAST32_MIN  0
1716 #define DUK_UINT_LEAST32_MAX  UINT_LEAST32_MAX
1717 #define DUK_INT_LEAST32_MIN   INT_LEAST32_MIN
1718 #define DUK_INT_LEAST32_MAX   INT_LEAST32_MAX
1719 #define DUK_UINT_FAST32_MIN   0
1720 #define DUK_UINT_FAST32_MAX   UINT_FAST32_MAX
1721 #define DUK_INT_FAST32_MIN    INT_FAST32_MIN
1722 #define DUK_INT_FAST32_MAX    INT_FAST32_MAX
1723 #define DUK_UINT64_MIN        0
1724 #define DUK_UINT64_MAX        UINT64_MAX
1725 #define DUK_INT64_MIN         INT64_MIN
1726 #define DUK_INT64_MAX         INT64_MAX
1727 #define DUK_UINT_LEAST64_MIN  0
1728 #define DUK_UINT_LEAST64_MAX  UINT_LEAST64_MAX
1729 #define DUK_INT_LEAST64_MIN   INT_LEAST64_MIN
1730 #define DUK_INT_LEAST64_MAX   INT_LEAST64_MAX
1731 #define DUK_UINT_FAST64_MIN   0
1732 #define DUK_UINT_FAST64_MAX   UINT_FAST64_MAX
1733 #define DUK_INT_FAST64_MIN    INT_FAST64_MIN
1734 #define DUK_INT_FAST64_MAX    INT_FAST64_MAX
1735 
1736 #define DUK_UINTPTR_MIN       0
1737 #define DUK_UINTPTR_MAX       UINTPTR_MAX
1738 #define DUK_INTPTR_MIN        INTPTR_MIN
1739 #define DUK_INTPTR_MAX        INTPTR_MAX
1740 
1741 #define DUK_UINTMAX_MIN       0
1742 #define DUK_UINTMAX_MAX       UINTMAX_MAX
1743 #define DUK_INTMAX_MIN        INTMAX_MIN
1744 #define DUK_INTMAX_MAX        INTMAX_MAX
1745 
1746 #define DUK_SIZE_MIN          0
1747 #define DUK_SIZE_MAX          SIZE_MAX
1748 #undef DUK_SIZE_MAX_COMPUTED
1749 
1750 #else  /* C99 types */
1751 
1752 /* When C99 types are not available, we use heuristic detection to get
1753  * the basic 8, 16, 32, and (possibly) 64 bit types.  The fast/least
1754  * types are then assumed to be exactly the same for now: these could
1755  * be improved per platform but C99 types are very often now available.
1756  * 64-bit types are not available on all platforms; this is OK at least
1757  * on 32-bit platforms.
1758  *
1759  * This detection code is necessarily a bit hacky and can provide typedefs
1760  * and defines that won't work correctly on some exotic platform.
1761  */
1762 
1763 #if (defined(CHAR_BIT) && (CHAR_BIT == 8)) || \
1764     (defined(UCHAR_MAX) && (UCHAR_MAX == 255))
1765 typedef unsigned char duk_uint8_t;
1766 typedef signed char duk_int8_t;
1767 #else
1768 #error cannot detect 8-bit type
1769 #endif
1770 
1771 #if defined(USHRT_MAX) && (USHRT_MAX == 65535UL)
1772 typedef unsigned short duk_uint16_t;
1773 typedef signed short duk_int16_t;
1774 #elif defined(UINT_MAX) && (UINT_MAX == 65535UL)
1775 /* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */
1776 typedef unsigned int duk_uint16_t;
1777 typedef signed int duk_int16_t;
1778 #else
1779 #error cannot detect 16-bit type
1780 #endif
1781 
1782 #if defined(UINT_MAX) && (UINT_MAX == 4294967295UL)
1783 typedef unsigned int duk_uint32_t;
1784 typedef signed int duk_int32_t;
1785 #elif defined(ULONG_MAX) && (ULONG_MAX == 4294967295UL)
1786 /* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */
1787 typedef unsigned long duk_uint32_t;
1788 typedef signed long duk_int32_t;
1789 #else
1790 #error cannot detect 32-bit type
1791 #endif
1792 
1793 /* 64-bit type detection is a bit tricky.
1794  *
1795  * ULLONG_MAX is a standard define.  __LONG_LONG_MAX__ and __ULONG_LONG_MAX__
1796  * are used by at least GCC (even if system headers don't provide ULLONG_MAX).
1797  * Some GCC variants may provide __LONG_LONG_MAX__ but not __ULONG_LONG_MAX__.
1798  *
1799  * ULL / LL constants are rejected / warned about by some compilers, even if
1800  * the compiler has a 64-bit type and the compiler/system headers provide an
1801  * unsupported constant (ULL/LL)!  Try to avoid using ULL / LL constants.
1802  * As a side effect we can only check that e.g. ULONG_MAX is larger than 32
1803  * bits but can't be sure it is exactly 64 bits.  Self tests will catch such
1804  * cases.
1805  */
1806 #undef DUK_F_HAVE_64BIT
1807 #if !defined(DUK_F_HAVE_64BIT) && defined(ULONG_MAX)
1808 #if (ULONG_MAX > 4294967295UL)
1809 #define DUK_F_HAVE_64BIT
1810 typedef unsigned long duk_uint64_t;
1811 typedef signed long duk_int64_t;
1812 #endif
1813 #endif
1814 #if !defined(DUK_F_HAVE_64BIT) && defined(ULLONG_MAX)
1815 #if (ULLONG_MAX > 4294967295UL)
1816 #define DUK_F_HAVE_64BIT
1817 typedef unsigned long long duk_uint64_t;
1818 typedef signed long long duk_int64_t;
1819 #endif
1820 #endif
1821 #if !defined(DUK_F_HAVE_64BIT) && defined(__ULONG_LONG_MAX__)
1822 #if (__ULONG_LONG_MAX__ > 4294967295UL)
1823 #define DUK_F_HAVE_64BIT
1824 typedef unsigned long long duk_uint64_t;
1825 typedef signed long long duk_int64_t;
1826 #endif
1827 #endif
1828 #if !defined(DUK_F_HAVE_64BIT) && defined(__LONG_LONG_MAX__)
1829 #if (__LONG_LONG_MAX__ > 2147483647L)
1830 #define DUK_F_HAVE_64BIT
1831 typedef unsigned long long duk_uint64_t;
1832 typedef signed long long duk_int64_t;
1833 #endif
1834 #endif
1835 #if !defined(DUK_F_HAVE_64BIT) && defined(DUK_F_MINGW)
1836 #define DUK_F_HAVE_64BIT
1837 typedef unsigned long duk_uint64_t;
1838 typedef signed long duk_int64_t;
1839 #endif
1840 #if !defined(DUK_F_HAVE_64BIT) && defined(DUK_F_MSVC)
1841 #define DUK_F_HAVE_64BIT
1842 typedef unsigned __int64 duk_uint64_t;
1843 typedef signed __int64 duk_int64_t;
1844 #endif
1845 #if !defined(DUK_F_HAVE_64BIT)
1846 /* cannot detect 64-bit type, not always needed so don't error */
1847 #endif
1848 
1849 typedef duk_uint8_t duk_uint_least8_t;
1850 typedef duk_int8_t duk_int_least8_t;
1851 typedef duk_uint16_t duk_uint_least16_t;
1852 typedef duk_int16_t duk_int_least16_t;
1853 typedef duk_uint32_t duk_uint_least32_t;
1854 typedef duk_int32_t duk_int_least32_t;
1855 typedef duk_uint8_t duk_uint_fast8_t;
1856 typedef duk_int8_t duk_int_fast8_t;
1857 typedef duk_uint16_t duk_uint_fast16_t;
1858 typedef duk_int16_t duk_int_fast16_t;
1859 typedef duk_uint32_t duk_uint_fast32_t;
1860 typedef duk_int32_t duk_int_fast32_t;
1861 #if defined(DUK_F_HAVE_64BIT)
1862 typedef duk_uint64_t duk_uint_least64_t;
1863 typedef duk_int64_t duk_int_least64_t;
1864 typedef duk_uint64_t duk_uint_fast64_t;
1865 typedef duk_int64_t duk_int_fast64_t;
1866 #endif
1867 #if defined(DUK_F_HAVE_64BIT)
1868 typedef duk_uint64_t duk_uintmax_t;
1869 typedef duk_int64_t duk_intmax_t;
1870 #else
1871 typedef duk_uint32_t duk_uintmax_t;
1872 typedef duk_int32_t duk_intmax_t;
1873 #endif
1874 
1875 /* Note: the funny looking computations for signed minimum 16-bit, 32-bit, and
1876  * 64-bit values are intentional as the obvious forms (e.g. -0x80000000L) are
1877  * -not- portable.  See code-issues.txt for a detailed discussion.
1878  */
1879 #define DUK_UINT8_MIN         0UL
1880 #define DUK_UINT8_MAX         0xffUL
1881 #define DUK_INT8_MIN          (-0x80L)
1882 #define DUK_INT8_MAX          0x7fL
1883 #define DUK_UINT_LEAST8_MIN   0UL
1884 #define DUK_UINT_LEAST8_MAX   0xffUL
1885 #define DUK_INT_LEAST8_MIN    (-0x80L)
1886 #define DUK_INT_LEAST8_MAX    0x7fL
1887 #define DUK_UINT_FAST8_MIN    0UL
1888 #define DUK_UINT_FAST8_MAX    0xffUL
1889 #define DUK_INT_FAST8_MIN     (-0x80L)
1890 #define DUK_INT_FAST8_MAX     0x7fL
1891 #define DUK_UINT16_MIN        0UL
1892 #define DUK_UINT16_MAX        0xffffUL
1893 #define DUK_INT16_MIN         (-0x7fffL - 1L)
1894 #define DUK_INT16_MAX         0x7fffL
1895 #define DUK_UINT_LEAST16_MIN  0UL
1896 #define DUK_UINT_LEAST16_MAX  0xffffUL
1897 #define DUK_INT_LEAST16_MIN   (-0x7fffL - 1L)
1898 #define DUK_INT_LEAST16_MAX   0x7fffL
1899 #define DUK_UINT_FAST16_MIN   0UL
1900 #define DUK_UINT_FAST16_MAX   0xffffUL
1901 #define DUK_INT_FAST16_MIN    (-0x7fffL - 1L)
1902 #define DUK_INT_FAST16_MAX    0x7fffL
1903 #define DUK_UINT32_MIN        0UL
1904 #define DUK_UINT32_MAX        0xffffffffUL
1905 #define DUK_INT32_MIN         (-0x7fffffffL - 1L)
1906 #define DUK_INT32_MAX         0x7fffffffL
1907 #define DUK_UINT_LEAST32_MIN  0UL
1908 #define DUK_UINT_LEAST32_MAX  0xffffffffUL
1909 #define DUK_INT_LEAST32_MIN   (-0x7fffffffL - 1L)
1910 #define DUK_INT_LEAST32_MAX   0x7fffffffL
1911 #define DUK_UINT_FAST32_MIN   0UL
1912 #define DUK_UINT_FAST32_MAX   0xffffffffUL
1913 #define DUK_INT_FAST32_MIN    (-0x7fffffffL - 1L)
1914 #define DUK_INT_FAST32_MAX    0x7fffffffL
1915 
1916 /* 64-bit constants.  Since LL / ULL constants are not always available,
1917  * use computed values.  These values can't be used in preprocessor
1918  * comparisons; flag them as such.
1919  */
1920 #if defined(DUK_F_HAVE_64BIT)
1921 #define DUK_UINT64_MIN        ((duk_uint64_t) 0)
1922 #define DUK_UINT64_MAX        ((duk_uint64_t) -1)
1923 #define DUK_INT64_MIN         ((duk_int64_t) (~(DUK_UINT64_MAX >> 1)))
1924 #define DUK_INT64_MAX         ((duk_int64_t) (DUK_UINT64_MAX >> 1))
1925 #define DUK_UINT_LEAST64_MIN  DUK_UINT64_MIN
1926 #define DUK_UINT_LEAST64_MAX  DUK_UINT64_MAX
1927 #define DUK_INT_LEAST64_MIN   DUK_INT64_MIN
1928 #define DUK_INT_LEAST64_MAX   DUK_INT64_MAX
1929 #define DUK_UINT_FAST64_MIN   DUK_UINT64_MIN
1930 #define DUK_UINT_FAST64_MAX   DUK_UINT64_MAX
1931 #define DUK_INT_FAST64_MIN    DUK_INT64_MIN
1932 #define DUK_INT_FAST64_MAX    DUK_INT64_MAX
1933 #define DUK_UINT64_MIN_COMPUTED
1934 #define DUK_UINT64_MAX_COMPUTED
1935 #define DUK_INT64_MIN_COMPUTED
1936 #define DUK_INT64_MAX_COMPUTED
1937 #define DUK_UINT_LEAST64_MIN_COMPUTED
1938 #define DUK_UINT_LEAST64_MAX_COMPUTED
1939 #define DUK_INT_LEAST64_MIN_COMPUTED
1940 #define DUK_INT_LEAST64_MAX_COMPUTED
1941 #define DUK_UINT_FAST64_MIN_COMPUTED
1942 #define DUK_UINT_FAST64_MAX_COMPUTED
1943 #define DUK_INT_FAST64_MIN_COMPUTED
1944 #define DUK_INT_FAST64_MAX_COMPUTED
1945 #endif
1946 
1947 #if defined(DUK_F_HAVE_64BIT)
1948 #define DUK_UINTMAX_MIN       DUK_UINT64_MIN
1949 #define DUK_UINTMAX_MAX       DUK_UINT64_MAX
1950 #define DUK_INTMAX_MIN        DUK_INT64_MIN
1951 #define DUK_INTMAX_MAX        DUK_INT64_MAX
1952 #define DUK_UINTMAX_MIN_COMPUTED
1953 #define DUK_UINTMAX_MAX_COMPUTED
1954 #define DUK_INTMAX_MIN_COMPUTED
1955 #define DUK_INTMAX_MAX_COMPUTED
1956 #else
1957 #define DUK_UINTMAX_MIN       0UL
1958 #define DUK_UINTMAX_MAX       0xffffffffUL
1959 #define DUK_INTMAX_MIN        (-0x7fffffffL - 1L)
1960 #define DUK_INTMAX_MAX        0x7fffffffL
1961 #endif
1962 
1963 /* This detection is not very reliable. */
1964 #if defined(DUK_F_32BIT_PTRS)
1965 typedef duk_int32_t duk_intptr_t;
1966 typedef duk_uint32_t duk_uintptr_t;
1967 #define DUK_UINTPTR_MIN       DUK_UINT32_MIN
1968 #define DUK_UINTPTR_MAX       DUK_UINT32_MAX
1969 #define DUK_INTPTR_MIN        DUK_INT32_MIN
1970 #define DUK_INTPTR_MAX        DUK_INT32_MAX
1971 #elif defined(DUK_F_64BIT_PTRS) && defined(DUK_F_HAVE_64BIT)
1972 typedef duk_int64_t duk_intptr_t;
1973 typedef duk_uint64_t duk_uintptr_t;
1974 #define DUK_UINTPTR_MIN       DUK_UINT64_MIN
1975 #define DUK_UINTPTR_MAX       DUK_UINT64_MAX
1976 #define DUK_INTPTR_MIN        DUK_INT64_MIN
1977 #define DUK_INTPTR_MAX        DUK_INT64_MAX
1978 #define DUK_UINTPTR_MIN_COMPUTED
1979 #define DUK_UINTPTR_MAX_COMPUTED
1980 #define DUK_INTPTR_MIN_COMPUTED
1981 #define DUK_INTPTR_MAX_COMPUTED
1982 #else
1983 #error cannot determine intptr type
1984 #endif
1985 
1986 /* SIZE_MAX may be missing so use an approximate value for it. */
1987 #undef DUK_SIZE_MAX_COMPUTED
1988 #if !defined(SIZE_MAX)
1989 #define DUK_SIZE_MAX_COMPUTED
1990 #define SIZE_MAX              ((size_t) (-1))
1991 #endif
1992 #define DUK_SIZE_MIN          0
1993 #define DUK_SIZE_MAX          SIZE_MAX
1994 
1995 #endif  /* C99 types */
1996 
1997 /* A few types are assumed to always exist. */
1998 typedef size_t duk_size_t;
1999 typedef ptrdiff_t duk_ptrdiff_t;
2000 
2001 /* The best type for an "all around int" in Duktape internals is "at least
2002  * 32 bit signed integer" which is most convenient.  Same for unsigned type.
2003  * Prefer 'int' when large enough, as it is almost always a convenient type.
2004  */
2005 #if defined(UINT_MAX) && (UINT_MAX >= 0xffffffffUL)
2006 typedef int duk_int_t;
2007 typedef unsigned int duk_uint_t;
2008 #define DUK_INT_MIN           INT_MIN
2009 #define DUK_INT_MAX           INT_MAX
2010 #define DUK_UINT_MIN          0
2011 #define DUK_UINT_MAX          UINT_MAX
2012 #else
2013 typedef duk_int_fast32_t duk_int_t;
2014 typedef duk_uint_fast32_t duk_uint_t;
2015 #define DUK_INT_MIN           DUK_INT_FAST32_MIN
2016 #define DUK_INT_MAX           DUK_INT_FAST32_MAX
2017 #define DUK_UINT_MIN          DUK_UINT_FAST32_MIN
2018 #define DUK_UINT_MAX          DUK_UINT_FAST32_MAX
2019 #endif
2020 
2021 /* Same as 'duk_int_t' but guaranteed to be a 'fast' variant if this
2022  * distinction matters for the CPU.  These types are used mainly in the
2023  * executor where it might really matter.
2024  */
2025 typedef duk_int_fast32_t duk_int_fast_t;
2026 typedef duk_uint_fast32_t duk_uint_fast_t;
2027 #define DUK_INT_FAST_MIN      DUK_INT_FAST32_MIN
2028 #define DUK_INT_FAST_MAX      DUK_INT_FAST32_MAX
2029 #define DUK_UINT_FAST_MIN     DUK_UINT_FAST32_MIN
2030 #define DUK_UINT_FAST_MAX     DUK_UINT_FAST32_MAX
2031 
2032 /* Small integers (16 bits or more) can fall back to the 'int' type, but
2033  * have a typedef so they are marked "small" explicitly.
2034  */
2035 typedef int duk_small_int_t;
2036 typedef unsigned int duk_small_uint_t;
2037 #define DUK_SMALL_INT_MIN     INT_MIN
2038 #define DUK_SMALL_INT_MAX     INT_MAX
2039 #define DUK_SMALL_UINT_MIN    0
2040 #define DUK_SMALL_UINT_MAX    UINT_MAX
2041 
2042 /* Fast variants of small integers, again for really fast paths like the
2043  * executor.
2044  */
2045 typedef duk_int_fast16_t duk_small_int_fast_t;
2046 typedef duk_uint_fast16_t duk_small_uint_fast_t;
2047 #define DUK_SMALL_INT_FAST_MIN    DUK_INT_FAST16_MIN
2048 #define DUK_SMALL_INT_FAST_MAX    DUK_INT_FAST16_MAX
2049 #define DUK_SMALL_UINT_FAST_MIN   DUK_UINT_FAST16_MIN
2050 #define DUK_SMALL_UINT_FAST_MAX   DUK_UINT_FAST16_MAX
2051 
2052 /* Boolean values are represented with the platform 'unsigned int'. */
2053 typedef duk_small_uint_t duk_bool_t;
2054 #define DUK_BOOL_MIN              DUK_SMALL_UINT_MIN
2055 #define DUK_BOOL_MAX              DUK_SMALL_UINT_MAX
2056 
2057 /* Index values must have at least 32-bit signed range. */
2058 typedef duk_int_t duk_idx_t;
2059 #define DUK_IDX_MIN               DUK_INT_MIN
2060 #define DUK_IDX_MAX               DUK_INT_MAX
2061 
2062 /* Unsigned index variant. */
2063 typedef duk_uint_t duk_uidx_t;
2064 #define DUK_UIDX_MIN              DUK_UINT_MIN
2065 #define DUK_UIDX_MAX              DUK_UINT_MAX
2066 
2067 /* Array index values, could be exact 32 bits.
2068  * Currently no need for signed duk_arridx_t.
2069  */
2070 typedef duk_uint_t duk_uarridx_t;
2071 #define DUK_UARRIDX_MIN           DUK_UINT_MIN
2072 #define DUK_UARRIDX_MAX           DUK_UINT_MAX
2073 
2074 /* Duktape/C function return value, platform int is enough for now to
2075  * represent 0, 1, or negative error code.  Must be compatible with
2076  * assigning truth values (e.g. duk_ret_t rc = (foo == bar);).
2077  */
2078 typedef duk_small_int_t duk_ret_t;
2079 #define DUK_RET_MIN               DUK_SMALL_INT_MIN
2080 #define DUK_RET_MAX               DUK_SMALL_INT_MAX
2081 
2082 /* Error codes are represented with platform int.  High bits are used
2083  * for flags and such, so 32 bits are needed.
2084  */
2085 typedef duk_int_t duk_errcode_t;
2086 #define DUK_ERRCODE_MIN           DUK_INT_MIN
2087 #define DUK_ERRCODE_MAX           DUK_INT_MAX
2088 
2089 /* Codepoint type.  Must be 32 bits or more because it is used also for
2090  * internal codepoints.  The type is signed because negative codepoints
2091  * are used as internal markers (e.g. to mark EOF or missing argument).
2092  * (X)UTF-8/CESU-8 encode/decode take and return an unsigned variant to
2093  * ensure duk_uint32_t casts back and forth nicely.  Almost everything
2094  * else uses the signed one.
2095  */
2096 typedef duk_int_t duk_codepoint_t;
2097 typedef duk_uint_t duk_ucodepoint_t;
2098 #define DUK_CODEPOINT_MIN         DUK_INT_MIN
2099 #define DUK_CODEPOINT_MAX         DUK_INT_MAX
2100 #define DUK_UCODEPOINT_MIN        DUK_UINT_MIN
2101 #define DUK_UCODEPOINT_MAX        DUK_UINT_MAX
2102 
2103 /* IEEE float/double typedef. */
2104 typedef float duk_float_t;
2105 typedef double duk_double_t;
2106 
2107 /* We're generally assuming that we're working on a platform with a 32-bit
2108  * address space.  If DUK_SIZE_MAX is a typecast value (which is necessary
2109  * if SIZE_MAX is missing), the check must be avoided because the
2110  * preprocessor can't do a comparison.
2111  */
2112 #if !defined(DUK_SIZE_MAX)
2113 #error DUK_SIZE_MAX is undefined, probably missing SIZE_MAX
2114 #elif !defined(DUK_SIZE_MAX_COMPUTED)
2115 #if DUK_SIZE_MAX < 0xffffffffUL
2116 /* On some systems SIZE_MAX can be smaller than max unsigned 32-bit value
2117  * which seems incorrect if size_t is (at least) an unsigned 32-bit type.
2118  * However, it doesn't seem useful to error out compilation if this is the
2119  * case.
2120  */
2121 #endif
2122 #endif
2123 
2124 /* Type used in public API declarations and user code.  Typedef maps to
2125  * 'struct duk_hthread' like the 'duk_hthread' typedef which is used
2126  * exclusively in internals.
2127  */
2128 typedef struct duk_hthread duk_context;
2129 
2130 /* Check whether we should use 64-bit integers or not.
2131  *
2132  * Quite incomplete now.  Use 64-bit types if detected (C99 or other detection)
2133  * unless they are known to be unreliable.  For instance, 64-bit types are
2134  * available on VBCC but seem to misbehave.
2135  */
2136 #if defined(DUK_F_HAVE_64BIT) && !defined(DUK_F_VBCC)
2137 #define DUK_USE_64BIT_OPS
2138 #else
2139 #undef DUK_USE_64BIT_OPS
2140 #endif
2141 
2142 /*
2143  *  Fill-ins for platform, architecture, and compiler
2144  */
2145 
2146 /* An abort()-like primitive is needed by the default fatal error handler. */
2147 #if !defined(DUK_ABORT)
2148 #define DUK_ABORT             abort
2149 #endif
2150 
2151 #if !defined(DUK_SETJMP)
2152 #define DUK_JMPBUF_TYPE       jmp_buf
2153 #define DUK_SETJMP(jb)        setjmp((jb))
2154 #define DUK_LONGJMP(jb)       longjmp((jb), 1)
2155 #endif
2156 
2157 #if 0
2158 /* sigsetjmp() alternative */
2159 #define DUK_JMPBUF_TYPE       sigjmp_buf
2160 #define DUK_SETJMP(jb)        sigsetjmp((jb))
2161 #define DUK_LONGJMP(jb)       siglongjmp((jb), 1)
2162 #endif
2163 
2164 /* Special naming to avoid conflict with e.g. DUK_FREE() in duk_heap.h
2165  * (which is unfortunately named).  May sometimes need replacement, e.g.
2166  * some compilers don't handle zero length or NULL correctly in realloc().
2167  */
2168 extern void *aos_realloc(void *ptr, unsigned int size);
2169 extern void *aos_malloc(unsigned int size);
2170 extern void aos_free(void *ptr);
2171 
2172 #if !defined(DUK_ANSI_MALLOC)
2173 #define DUK_ANSI_MALLOC      aos_malloc
2174 #endif
2175 
2176 #if !defined(DUK_ANSI_REALLOC)
2177 #define DUK_ANSI_REALLOC     aos_realloc
2178 #endif
2179 #if !defined(DUK_ANSI_CALLOC)
2180 // #define DUK_ANSI_CALLOC      duk_custom_calloc
2181 #endif
2182 #if !defined(DUK_ANSI_FREE)
2183 #define DUK_ANSI_FREE        aos_free
2184 #endif
2185 
2186 /* ANSI C (various versions) and some implementations require that the
2187  * pointer arguments to memset(), memcpy(), and memmove() be valid values
2188  * even when byte size is 0 (even a NULL pointer is considered invalid in
2189  * this context).  Zero-size operations as such are allowed, as long as their
2190  * pointer arguments point to a valid memory area.  The DUK_MEMSET(),
2191  * DUK_MEMCPY(), and DUK_MEMMOVE() macros require this same behavior, i.e.:
2192  * (1) pointers must be valid and non-NULL, (2) zero size must otherwise be
2193  * allowed.  If these are not fulfilled, a macro wrapper is needed.
2194  *
2195  *   http://stackoverflow.com/questions/5243012/is-it-guaranteed-to-be-safe-to-perform-memcpy0-0-0
2196  *   http://lists.cs.uiuc.edu/pipermail/llvmdev/2007-October/011065.html
2197  *
2198  * Not sure what's the required behavior when a pointer points just past the
2199  * end of a buffer, which often happens in practice (e.g. zero size memmoves).
2200  * For example, if allocation size is 3, the following pointer would not
2201  * technically point to a valid memory byte:
2202  *
2203  *   <-- alloc -->
2204  *   | 0 | 1 | 2 | .....
2205  *                 ^-- p=3, points after last valid byte (2)
2206  */
2207 #if !defined(DUK_MEMCPY)
2208 #if defined(DUK_F_UCLIBC)
2209 /* Old uclibcs have a broken memcpy so use memmove instead (this is overly wide
2210  * now on purpose): http://lists.uclibc.org/pipermail/uclibc-cvs/2008-October/025511.html
2211  */
2212 #define DUK_MEMCPY       memmove
2213 #else
2214 #define DUK_MEMCPY       memcpy
2215 #endif
2216 #endif
2217 #if !defined(DUK_MEMMOVE)
2218 #define DUK_MEMMOVE      memmove
2219 #endif
2220 #if !defined(DUK_MEMCMP)
2221 #define DUK_MEMCMP       memcmp
2222 #endif
2223 #if !defined(DUK_MEMSET)
2224 #define DUK_MEMSET       memset
2225 #endif
2226 #if !defined(DUK_STRLEN)
2227 #define DUK_STRLEN       strlen
2228 #endif
2229 #if !defined(DUK_STRCMP)
2230 #define DUK_STRCMP       strcmp
2231 #endif
2232 #if !defined(DUK_STRNCMP)
2233 #define DUK_STRNCMP      strncmp
2234 #endif
2235 #if !defined(DUK_SPRINTF)
2236 #define DUK_SPRINTF      sprintf
2237 #endif
2238 #if !defined(DUK_SNPRINTF)
2239 /* snprintf() is technically not part of C89 but usually available. */
2240 #define DUK_SNPRINTF     snprintf
2241 #endif
2242 #if !defined(DUK_VSPRINTF)
2243 #define DUK_VSPRINTF     vsprintf
2244 #endif
2245 #if !defined(DUK_VSNPRINTF)
2246 /* vsnprintf() is technically not part of C89 but usually available. */
2247 #define DUK_VSNPRINTF    vsnprintf
2248 #endif
2249 #if !defined(DUK_SSCANF)
2250 #define DUK_SSCANF       sscanf
2251 #endif
2252 #if !defined(DUK_VSSCANF)
2253 #define DUK_VSSCANF      vsscanf
2254 #endif
2255 #if !defined(DUK_MEMZERO)
2256 #define DUK_MEMZERO(p,n) DUK_MEMSET((p), 0, (n))
2257 #endif
2258 
2259 #if !defined(DUK_DOUBLE_INFINITY)
2260 #undef DUK_USE_COMPUTED_INFINITY
2261 #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION < 40600)
2262 /* GCC older than 4.6: avoid overflow warnings related to using INFINITY */
2263 #define DUK_DOUBLE_INFINITY  (__builtin_inf())
2264 #elif defined(INFINITY)
2265 #define DUK_DOUBLE_INFINITY  ((double) INFINITY)
2266 #elif !defined(DUK_F_VBCC) && !defined(DUK_F_MSVC) && !defined(DUK_F_BCC) && \
2267       !defined(DUK_F_OLD_SOLARIS) && !defined(DUK_F_AIX)
2268 #define DUK_DOUBLE_INFINITY  (1.0 / 0.0)
2269 #else
2270 /* In VBCC (1.0 / 0.0) results in a warning and 0.0 instead of infinity.
2271  * Use a computed infinity (initialized when a heap is created at the
2272  * latest).
2273  */
2274 #define DUK_USE_COMPUTED_INFINITY
2275 #define DUK_DOUBLE_INFINITY  duk_computed_infinity
2276 #endif
2277 #endif
2278 
2279 #if !defined(DUK_DOUBLE_NAN)
2280 #undef DUK_USE_COMPUTED_NAN
2281 #if defined(NAN)
2282 #define DUK_DOUBLE_NAN       NAN
2283 #elif !defined(DUK_F_VBCC) && !defined(DUK_F_MSVC) && !defined(DUK_F_BCC) && \
2284       !defined(DUK_F_OLD_SOLARIS) && !defined(DUK_F_AIX)
2285 #define DUK_DOUBLE_NAN       (0.0 / 0.0)
2286 #else
2287 /* In VBCC (0.0 / 0.0) results in a warning and 0.0 instead of NaN.
2288  * In MSVC (VS2010 Express) (0.0 / 0.0) results in a compile error.
2289  * Use a computed NaN (initialized when a heap is created at the
2290  * latest).
2291  */
2292 #define DUK_USE_COMPUTED_NAN
2293 #define DUK_DOUBLE_NAN       duk_computed_nan
2294 #endif
2295 #endif
2296 
2297 /* Many platforms are missing fpclassify() and friends, so use replacements
2298  * if necessary.  The replacement constants (FP_NAN etc) can be anything but
2299  * match Linux constants now.
2300  */
2301 #undef DUK_USE_REPL_FPCLASSIFY
2302 #undef DUK_USE_REPL_SIGNBIT
2303 #undef DUK_USE_REPL_ISFINITE
2304 #undef DUK_USE_REPL_ISNAN
2305 #undef DUK_USE_REPL_ISINF
2306 
2307 /* Complex condition broken into separate parts. */
2308 #undef DUK_F_USE_REPL_ALL
2309 #if !(defined(FP_NAN) && defined(FP_INFINITE) && defined(FP_ZERO) && \
2310       defined(FP_SUBNORMAL) && defined(FP_NORMAL))
2311 /* Missing some obvious constants. */
2312 #define DUK_F_USE_REPL_ALL
2313 #elif defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC)
2314 /* VBCC is missing the built-ins even in C99 mode (perhaps a header issue). */
2315 #define DUK_F_USE_REPL_ALL
2316 #elif defined(DUK_F_AMIGAOS) && defined(DUK_F_M68K)
2317 /* AmigaOS + M68K seems to have math issues even when using GCC cross
2318  * compilation.  Use replacements for all AmigaOS versions on M68K
2319  * regardless of compiler.
2320  */
2321 #define DUK_F_USE_REPL_ALL
2322 #elif defined(DUK_F_FREEBSD) && defined(DUK_F_CLANG)
2323 /* Placeholder fix for (detection is wider than necessary):
2324  * http://llvm.org/bugs/show_bug.cgi?id=17788
2325  */
2326 #define DUK_F_USE_REPL_ALL
2327 #elif defined(DUK_F_UCLIBC)
2328 /* At least some uclibc versions have broken floating point math.  For
2329  * example, fpclassify() can incorrectly classify certain NaN formats.
2330  * To be safe, use replacements.
2331  */
2332 #define DUK_F_USE_REPL_ALL
2333 #elif defined(DUK_F_AIX)
2334 /* Older versions may be missing isnan(), etc. */
2335 #define DUK_F_USE_REPL_ALL
2336 #endif
2337 
2338 #if defined(DUK_F_USE_REPL_ALL)
2339 #define DUK_USE_REPL_FPCLASSIFY
2340 #define DUK_USE_REPL_SIGNBIT
2341 #define DUK_USE_REPL_ISFINITE
2342 #define DUK_USE_REPL_ISNAN
2343 #define DUK_USE_REPL_ISINF
2344 #define DUK_FPCLASSIFY       duk_repl_fpclassify
2345 #define DUK_SIGNBIT          duk_repl_signbit
2346 #define DUK_ISFINITE         duk_repl_isfinite
2347 #define DUK_ISNAN            duk_repl_isnan
2348 #define DUK_ISINF            duk_repl_isinf
2349 #define DUK_FP_NAN           0
2350 #define DUK_FP_INFINITE      1
2351 #define DUK_FP_ZERO          2
2352 #define DUK_FP_SUBNORMAL     3
2353 #define DUK_FP_NORMAL        4
2354 #else
2355 #define DUK_FPCLASSIFY       fpclassify
2356 #define DUK_SIGNBIT          signbit
2357 #define DUK_ISFINITE         isfinite
2358 #define DUK_ISNAN            isnan
2359 #define DUK_ISINF            isinf
2360 #define DUK_FP_NAN           FP_NAN
2361 #define DUK_FP_INFINITE      FP_INFINITE
2362 #define DUK_FP_ZERO          FP_ZERO
2363 #define DUK_FP_SUBNORMAL     FP_SUBNORMAL
2364 #define DUK_FP_NORMAL        FP_NORMAL
2365 #endif
2366 
2367 #if defined(DUK_F_USE_REPL_ALL)
2368 #undef DUK_F_USE_REPL_ALL
2369 #endif
2370 
2371 /* These functions don't currently need replacement but are wrapped for
2372  * completeness.  Because these are used as function pointers, they need
2373  * to be defined as concrete C functions (not macros).
2374  */
2375 #if !defined(DUK_FABS)
2376 #define DUK_FABS             fabs
2377 #endif
2378 #if !defined(DUK_FLOOR)
2379 #define DUK_FLOOR            floor
2380 #endif
2381 #if !defined(DUK_CEIL)
2382 #define DUK_CEIL             ceil
2383 #endif
2384 #if !defined(DUK_FMOD)
2385 #define DUK_FMOD             fmod
2386 #endif
2387 #if !defined(DUK_POW)
2388 #define DUK_POW              pow
2389 #endif
2390 #if !defined(DUK_ACOS)
2391 #define DUK_ACOS             acos
2392 #endif
2393 #if !defined(DUK_ASIN)
2394 #define DUK_ASIN             asin
2395 #endif
2396 #if !defined(DUK_ATAN)
2397 #define DUK_ATAN             atan
2398 #endif
2399 #if !defined(DUK_ATAN2)
2400 #define DUK_ATAN2            atan2
2401 #endif
2402 #if !defined(DUK_SIN)
2403 #define DUK_SIN              sin
2404 #endif
2405 #if !defined(DUK_COS)
2406 #define DUK_COS              cos
2407 #endif
2408 #if !defined(DUK_TAN)
2409 #define DUK_TAN              tan
2410 #endif
2411 #if !defined(DUK_EXP)
2412 #define DUK_EXP              exp
2413 #endif
2414 #if !defined(DUK_LOG)
2415 #define DUK_LOG              log
2416 #endif
2417 #if !defined(DUK_SQRT)
2418 #define DUK_SQRT             sqrt
2419 #endif
2420 
2421 /* The functions below exist only in C99/C++11 or later and need a workaround
2422  * for platforms that don't include them.  MSVC isn't detected as C99, but
2423  * these functions also exist in MSVC 2013 and later so include a clause for
2424  * that too.  Android doesn't have log2; disable all of these for Android.
2425  */
2426 #if (defined(DUK_F_C99) || defined(DUK_F_CPP11) || (defined(_MSC_VER) && (_MSC_VER >= 1800))) && \
2427     !defined(DUK_F_ANDROID) && !defined(DUK_F_MINT)
2428 #if !defined(DUK_CBRT)
2429 #define DUK_CBRT             cbrt
2430 #endif
2431 #if !defined(DUK_LOG2)
2432 #define DUK_LOG2             log2
2433 #endif
2434 #if !defined(DUK_LOG10)
2435 #define DUK_LOG10            log10
2436 #endif
2437 #if !defined(DUK_TRUNC)
2438 #define DUK_TRUNC            trunc
2439 #endif
2440 #endif  /* DUK_F_C99 etc */
2441 
2442 /* NetBSD 6.0 x86 (at least) has a few problems with pow() semantics,
2443  * see test-bug-netbsd-math-pow.js.  MinGW has similar (but different)
2444  * issues, see test-bug-mingw-math-issues.js.  Enable pow() workarounds
2445  * for these targets.
2446  */
2447 #undef DUK_USE_POW_WORKAROUNDS
2448 #if defined(DUK_F_NETBSD) || defined(DUK_F_MINGW)
2449 #define DUK_USE_POW_WORKAROUNDS
2450 #endif
2451 
2452 /* Similar workarounds for atan2() semantics issues.  MinGW issues are
2453  * documented in test-bug-mingw-math-issues.js.
2454  */
2455 #undef DUK_USE_ATAN2_WORKAROUNDS
2456 #if defined(DUK_F_MINGW)
2457 #define DUK_USE_ATAN2_WORKAROUNDS
2458 #endif
2459 
2460 /* Rely as little as possible on compiler behavior for NaN comparison,
2461  * signed zero handling, etc.  Currently never activated but may be needed
2462  * for broken compilers.
2463  */
2464 #undef DUK_USE_PARANOID_MATH
2465 
2466 /* There was a curious bug where test-bi-date-canceling.js would fail e.g.
2467  * on 64-bit Ubuntu, gcc-4.8.1, -m32, and no -std=c99.  Some date computations
2468  * using doubles would be optimized which then broke some corner case tests.
2469  * The problem goes away by adding 'volatile' to the datetime computations.
2470  * Not sure what the actual triggering conditions are, but using this on
2471  * non-C99 systems solves the known issues and has relatively little cost
2472  * on other platforms.
2473  */
2474 #undef DUK_USE_PARANOID_DATE_COMPUTATION
2475 #if !defined(DUK_F_C99)
2476 #define DUK_USE_PARANOID_DATE_COMPUTATION
2477 #endif
2478 
2479 /*
2480  *  Byte order and double memory layout detection
2481  *
2482  *  Endianness detection is a major portability hassle because the macros
2483  *  and headers are not standardized.  There's even variance across UNIX
2484  *  platforms.  Even with "standard" headers, details like underscore count
2485  *  varies between platforms, e.g. both __BYTE_ORDER and _BYTE_ORDER are used
2486  *  (Crossbridge has a single underscore, for instance).
2487  *
2488  *  The checks below are structured with this in mind: several approaches are
2489  *  used, and at the end we check if any of them worked.  This allows generic
2490  *  approaches to be tried first, and platform/compiler specific hacks tried
2491  *  last.  As a last resort, the user can force a specific endianness, as it's
2492  *  not likely that automatic detection will work on the most exotic platforms.
2493  *
2494  *  Duktape supports little and big endian machines.  There's also support
2495  *  for a hybrid used by some ARM machines where integers are little endian
2496  *  but IEEE double values use a mixed order (12345678 -> 43218765).  This
2497  *  byte order for doubles is referred to as "mixed endian".
2498  */
2499 
2500 /* GCC and Clang provide endianness defines as built-in predefines, with
2501  * leading and trailing double underscores (e.g. __BYTE_ORDER__).  See
2502  * output of "make gccpredefs" and "make clangpredefs".  Clang doesn't
2503  * seem to provide __FLOAT_WORD_ORDER__; assume not mixed endian for clang.
2504  * http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
2505  */
2506 #if !defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__)
2507 #if defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
2508 #if defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__)
2509 #define DUK_USE_BYTEORDER 1
2510 #elif defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)
2511 #define DUK_USE_BYTEORDER 2
2512 #elif !defined(__FLOAT_WORD_ORDER__)
2513 /* Float word order not known, assume not a hybrid. */
2514 #define DUK_USE_BYTEORDER 1
2515 #else
2516 /* Byte order is little endian but cannot determine IEEE double word order. */
2517 #endif  /* float word order */
2518 #elif defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
2519 #if defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)
2520 #define DUK_USE_BYTEORDER 3
2521 #elif !defined(__FLOAT_WORD_ORDER__)
2522 /* Float word order not known, assume not a hybrid. */
2523 #define DUK_USE_BYTEORDER 3
2524 #else
2525 /* Byte order is big endian but cannot determine IEEE double word order. */
2526 #endif  /* float word order */
2527 #else
2528 /* Cannot determine byte order; __ORDER_PDP_ENDIAN__ is related to 32-bit
2529  * integer ordering and is not relevant.
2530  */
2531 #endif  /* integer byte order */
2532 #endif  /* !defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__) */
2533 
2534 /* More or less standard endianness predefines provided by header files.
2535  * The ARM hybrid case is detected by assuming that __FLOAT_WORD_ORDER
2536  * will be big endian, see: http://lists.mysql.com/internals/443.
2537  * On some platforms some defines may be present with an empty value which
2538  * causes comparisons to fail: https://github.com/svaarala/duktape/issues/453.
2539  */
2540 #if !defined(DUK_USE_BYTEORDER)
2541 #if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && (__BYTE_ORDER == __LITTLE_ENDIAN) || \
2542     defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN) && (_BYTE_ORDER == _LITTLE_ENDIAN) || \
2543     defined(__LITTLE_ENDIAN__)
2544 #if defined(__FLOAT_WORD_ORDER) && defined(__LITTLE_ENDIAN) && (__FLOAT_WORD_ORDER == __LITTLE_ENDIAN) || \
2545     defined(_FLOAT_WORD_ORDER) && defined(_LITTLE_ENDIAN) && (_FLOAT_WORD_ORDER == _LITTLE_ENDIAN)
2546 #define DUK_USE_BYTEORDER 1
2547 #elif defined(__FLOAT_WORD_ORDER) && defined(__BIG_ENDIAN) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) || \
2548       defined(_FLOAT_WORD_ORDER) && defined(_BIG_ENDIAN) && (_FLOAT_WORD_ORDER == _BIG_ENDIAN)
2549 #define DUK_USE_BYTEORDER 2
2550 #elif !defined(__FLOAT_WORD_ORDER) && !defined(_FLOAT_WORD_ORDER)
2551 /* Float word order not known, assume not a hybrid. */
2552 #define DUK_USE_BYTEORDER 1
2553 #else
2554 /* Byte order is little endian but cannot determine IEEE double word order. */
2555 #endif  /* float word order */
2556 #elif defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && (__BYTE_ORDER == __BIG_ENDIAN) || \
2557       defined(_BYTE_ORDER) && defined(_BIG_ENDIAN) && (_BYTE_ORDER == _BIG_ENDIAN) || \
2558       defined(__BIG_ENDIAN__)
2559 #if defined(__FLOAT_WORD_ORDER) && defined(__BIG_ENDIAN) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) || \
2560     defined(_FLOAT_WORD_ORDER) && defined(_BIG_ENDIAN) && (_FLOAT_WORD_ORDER == _BIG_ENDIAN)
2561 #define DUK_USE_BYTEORDER 3
2562 #elif !defined(__FLOAT_WORD_ORDER) && !defined(_FLOAT_WORD_ORDER)
2563 /* Float word order not known, assume not a hybrid. */
2564 #define DUK_USE_BYTEORDER 3
2565 #else
2566 /* Byte order is big endian but cannot determine IEEE double word order. */
2567 #endif  /* float word order */
2568 #else
2569 /* Cannot determine byte order. */
2570 #endif  /* integer byte order */
2571 #endif  /* !defined(DUK_USE_BYTEORDER) */
2572 
2573 /* QNX gcc cross compiler seems to define e.g. __LITTLEENDIAN__ or __BIGENDIAN__:
2574  *  $ /opt/qnx650/host/linux/x86/usr/bin/i486-pc-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
2575  *  67:#define __LITTLEENDIAN__ 1
2576  *  $ /opt/qnx650/host/linux/x86/usr/bin/mips-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
2577  *  81:#define __BIGENDIAN__ 1
2578  *  $ /opt/qnx650/host/linux/x86/usr/bin/arm-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
2579  *  70:#define __LITTLEENDIAN__ 1
2580  */
2581 #if !defined(DUK_USE_BYTEORDER)
2582 #if defined(__LITTLEENDIAN__)
2583 #define DUK_USE_BYTEORDER 1
2584 #elif defined(__BIGENDIAN__)
2585 #define DUK_USE_BYTEORDER 3
2586 #endif
2587 #endif
2588 
2589 /*
2590  *  Alignment requirement and support for unaligned accesses
2591  *
2592  *  Assume unaligned accesses are not supported unless specifically allowed
2593  *  in the target platform.  Some platforms may support unaligned accesses
2594  *  but alignment to 4 or 8 may still be desirable.  Note that unaligned
2595  *  accesses (and even pointers) relative to natural alignment (regardless
2596  *  of target alignment) are technically undefined behavior and thus
2597  *  compiler/architecture specific.
2598  */
2599 
2600 /* If not forced, use safe default for alignment. */
2601 #if !defined(DUK_USE_ALIGN_BY)
2602 #define DUK_USE_ALIGN_BY 8
2603 #endif
2604 
2605 /* Compiler specific hackery needed to force struct size to match alignment,
2606  * see e.g. duk_hbuffer.h.
2607  *
2608  * http://stackoverflow.com/questions/11130109/c-struct-size-alignment
2609  * http://stackoverflow.com/questions/10951039/specifying-64-bit-alignment
2610  */
2611 #if !(defined(DUK_USE_PACK_MSVC_PRAGMA) || defined(DUK_USE_PACK_GCC_ATTR) || \
2612       defined(DUK_USE_PACK_CLANG_ATTR) || defined(DUK_USE_PACK_DUMMY_MEMBER))
2613 #define DUK_USE_PACK_DUMMY_MEMBER
2614 #endif
2615 
2616 #if !defined(DUK_U64_CONSTANT)
2617 #define DUK_U64_CONSTANT(x) x##ULL
2618 #endif
2619 #if !defined(DUK_I64_CONSTANT)
2620 #define DUK_I64_CONSTANT(x) x##LL
2621 #endif
2622 
2623 #if !defined(DUK_VA_COPY)
2624 /* We need va_copy() which is defined in C99 / C++11, so an awkward
2625  * replacement is needed for pre-C99 / pre-C++11 environments.  This
2626  * will quite likely need portability hacks for some non-C99
2627  * environments.
2628  */
2629 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
2630 /* C99 / C++11 and above: rely on va_copy() which is required.
2631  * Omit parenthesis on macro right side on purpose to minimize differences
2632  * to direct use.
2633  */
2634 #define DUK_VA_COPY(dest,src) va_copy(dest,src)
2635 #else
2636 /* Pre-C99: va_list type is implementation dependent.  This replacement
2637  * assumes it is a plain value so that a simple assignment will work.
2638  * This is not the case on all platforms (it may be a single-array element,
2639  * for instance).
2640  */
2641 #define DUK_VA_COPY(dest,src) do { (dest) = (src); } while (0)
2642 #endif
2643 #endif
2644 
2645 #if !defined(DUK_MACRO_STRINGIFY)
2646 /* Macro hackery to convert e.g. __LINE__ to a string without formatting,
2647  * see: http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string
2648  */
2649 #define DUK_MACRO_STRINGIFY_HELPER(x)  #x
2650 #define DUK_MACRO_STRINGIFY(x)  DUK_MACRO_STRINGIFY_HELPER(x)
2651 #endif
2652 
2653 #if !defined(DUK_CAUSE_SEGFAULT)
2654 /* This can be used for testing; valgrind will then indicate the C call stack
2655  * leading to the call site.
2656  */
2657 #define DUK_CAUSE_SEGFAULT()  do { *((volatile duk_uint32_t *) NULL) = (duk_uint32_t) 0xdeadbeefUL; } while (0)
2658 #endif
2659 
2660 #if !defined(DUK_UNREF)
2661 /* Macro for suppressing warnings for potentially unreferenced variables.
2662  * The variables can be actually unreferenced or unreferenced in some
2663  * specific cases only; for instance, if a variable is only debug printed,
2664  * it is unreferenced when debug printing is disabled.  May cause warnings
2665  * for volatile arguments.
2666  */
2667 #define DUK_UNREF(x)  do { (void) (x); } while (0)
2668 #endif
2669 
2670 /* Fillin for DUK_NORETURN; DUK_WO_NORETURN() is used to insert dummy
2671  * dummy statements after noreturn calls to silence harmless compiler
2672  * warnings, e.g.:
2673  *
2674  *   DUK_ERROR_TYPE(thr, "aiee");
2675  *   DUK_WO_NORETURN(return 0;);
2676  *
2677  * Statements inside DUK_WO_NORETURN() must NEVER be actually reachable,
2678  * and they're only included to satisfy the compiler.
2679  */
2680 #if defined(DUK_NORETURN)
2681 #define DUK_WO_NORETURN(stmt) do { } while (0)
2682 #else
2683 #define DUK_NORETURN(decl)  decl
2684 #define DUK_WO_NORETURN(stmt) do { stmt } while (0)
2685 #endif
2686 
2687 #if defined(DUK_UNREACHABLE)
2688 #define DUK_WO_UNREACHABLE(stmt) do { } while (0)
2689 #else
2690 /* Don't know how to declare unreachable point, so don't do it; this
2691  * may cause some spurious compilation warnings (e.g. "variable used
2692  * uninitialized").
2693  */
2694 #define DUK_UNREACHABLE()  do { } while (0)
2695 #define DUK_WO_UNREACHABLE(stmt) do { stmt } while (0)
2696 #endif
2697 
2698 #if !defined(DUK_LOSE_CONST)
2699 /* Convert any input pointer into a "void *", losing a const qualifier.
2700  * This is not fully portable because casting through duk_uintptr_t may
2701  * not work on all architectures (e.g. those with long, segmented pointers).
2702  */
2703 #define DUK_LOSE_CONST(src) ((void *) (duk_uintptr_t) (src))
2704 #endif
2705 
2706 #if !defined(DUK_LIKELY)
2707 #define DUK_LIKELY(x)    (x)
2708 #endif
2709 #if !defined(DUK_UNLIKELY)
2710 #define DUK_UNLIKELY(x)  (x)
2711 #endif
2712 #if !defined(DUK_UNPREDICTABLE)
2713 #define DUK_UNPREDICTABLE(x)  (x)
2714 #endif
2715 
2716 #if !defined(DUK_NOINLINE)
2717 #define DUK_NOINLINE       /*nop*/
2718 #endif
2719 #if !defined(DUK_INLINE)
2720 #define DUK_INLINE         /*nop*/
2721 #endif
2722 #if !defined(DUK_ALWAYS_INLINE)
2723 #define DUK_ALWAYS_INLINE  /*nop*/
2724 #endif
2725 
2726 #if !defined(DUK_HOT)
2727 #define DUK_HOT            /*nop*/
2728 #endif
2729 #if !defined(DUK_COLD)
2730 #define DUK_COLD           /*nop*/
2731 #endif
2732 
2733 #if !defined(DUK_EXTERNAL_DECL)
2734 #define DUK_EXTERNAL_DECL  extern
2735 #endif
2736 #if !defined(DUK_EXTERNAL)
2737 #define DUK_EXTERNAL       /*empty*/
2738 #endif
2739 #if !defined(DUK_INTERNAL_DECL)
2740 #if defined(DUK_SINGLE_FILE)
2741 #define DUK_INTERNAL_DECL  static
2742 #else
2743 #define DUK_INTERNAL_DECL  extern
2744 #endif
2745 #endif
2746 #if !defined(DUK_INTERNAL)
2747 #if defined(DUK_SINGLE_FILE)
2748 #define DUK_INTERNAL       static
2749 #else
2750 #define DUK_INTERNAL       /*empty*/
2751 #endif
2752 #endif
2753 #if !defined(DUK_LOCAL_DECL)
2754 #define DUK_LOCAL_DECL     static
2755 #endif
2756 #if !defined(DUK_LOCAL)
2757 #define DUK_LOCAL          static
2758 #endif
2759 
2760 #if !defined(DUK_FILE_MACRO)
2761 #define DUK_FILE_MACRO  __FILE__
2762 #endif
2763 #if !defined(DUK_LINE_MACRO)
2764 #define DUK_LINE_MACRO  __LINE__
2765 #endif
2766 #if !defined(DUK_FUNC_MACRO)
2767 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
2768 #define DUK_FUNC_MACRO  __func__
2769 #elif defined(__FUNCTION__)
2770 #define DUK_FUNC_MACRO  __FUNCTION__
2771 #else
2772 #define DUK_FUNC_MACRO  "unknown"
2773 #endif
2774 #endif
2775 
2776 #if defined(DUK_F_HAVE_64BIT)
2777 #if !defined(DUK_BSWAP64)
2778 #define DUK_BSWAP64(x) \
2779 	((((duk_uint64_t) (x)) >> 56U) | \
2780 	 ((((duk_uint64_t) (x)) >> 40U) & DUK_U64_CONSTANT(0xff00)) | \
2781 	 ((((duk_uint64_t) (x)) >> 24U) & DUK_U64_CONSTANT(0xff0000)) | \
2782 	 ((((duk_uint64_t) (x)) >> 8U) & DUK_U64_CONSTANT(0xff000000)) | \
2783 	 ((((duk_uint64_t) (x)) << 8U) & DUK_U64_CONSTANT(0xff00000000)) | \
2784 	 ((((duk_uint64_t) (x)) << 24U) & DUK_U64_CONSTANT(0xff0000000000)) | \
2785 	 ((((duk_uint64_t) (x)) << 40U) & DUK_U64_CONSTANT(0xff000000000000)) | \
2786 	 (((duk_uint64_t) (x)) << 56U))
2787 #endif
2788 #endif
2789 #if !defined(DUK_BSWAP32)
2790 #define DUK_BSWAP32(x) \
2791 	((((duk_uint32_t) (x)) >> 24U) | \
2792 	 ((((duk_uint32_t) (x)) >> 8U) & 0xff00UL) | \
2793 	 ((((duk_uint32_t) (x)) << 8U) & 0xff0000UL) | \
2794 	 (((duk_uint32_t) (x)) << 24U))
2795 #endif
2796 #if !defined(DUK_BSWAP16)
2797 #define DUK_BSWAP16(x) \
2798 	((duk_uint16_t) (x) >> 8U) | \
2799 	((duk_uint16_t) (x) << 8U)
2800 #endif
2801 
2802 /* DUK_USE_VARIADIC_MACROS: required from compilers, so no fill-in. */
2803 /* DUK_USE_UNION_INITIALIZERS: required from compilers, so no fill-in. */
2804 
2805 #if !(defined(DUK_USE_FLEX_C99) || defined(DUK_USE_FLEX_ZEROSIZE) || defined(DUK_USE_FLEX_ONESIZE))
2806 #if defined(DUK_F_C99)
2807 #define DUK_USE_FLEX_C99
2808 #else
2809 #define DUK_USE_FLEX_ZEROSIZE  /* Not standard but common enough */
2810 #endif
2811 #endif
2812 
2813 #if !(defined(DUK_USE_PACK_GCC_ATTR) || defined(DUK_USE_PACK_CLANG_ATTR) || \
2814       defined(DUK_USE_PACK_MSVC_PRAGMA) || defined(DUK_USE_PACK_DUMMY_MEMBER))
2815 #define DUK_USE_PACK_DUMMY_MEMBER
2816 #endif
2817 
2818 #if 0  /* not defined by default */
2819 #undef DUK_USE_GCC_PRAGMAS
2820 #endif
2821 
2822 /* Workaround for GH-323: avoid inlining control when compiling from
2823  * multiple sources, as it causes compiler portability trouble.
2824  */
2825 #if !defined(DUK_SINGLE_FILE)
2826 #undef DUK_NOINLINE
2827 #undef DUK_INLINE
2828 #undef DUK_ALWAYS_INLINE
2829 #define DUK_NOINLINE       /*nop*/
2830 #define DUK_INLINE         /*nop*/
2831 #define DUK_ALWAYS_INLINE  /*nop*/
2832 #endif
2833 
2834 /*
2835  *  Check whether or not a packed duk_tval representation is possible.
2836  *  What's basically required is that pointers are 32-bit values
2837  *  (sizeof(void *) == 4).  Best effort check, not always accurate.
2838  *  If guess goes wrong, crashes may result; self tests also verify
2839  *  the guess.
2840  */
2841 
2842 /* Explicit marker needed; may be 'defined', 'undefined, 'or 'not provided'. */
2843 #if !defined(DUK_F_PACKED_TVAL_PROVIDED)
2844 #undef DUK_F_PACKED_TVAL_POSSIBLE
2845 
2846 /* Strict C99 case: DUK_UINTPTR_MAX (= UINTPTR_MAX) should be very reliable */
2847 #if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_UINTPTR_MAX)
2848 #if (DUK_UINTPTR_MAX <= 0xffffffffUL)
2849 #define DUK_F_PACKED_TVAL_POSSIBLE
2850 #endif
2851 #endif
2852 
2853 /* Non-C99 case, still relying on DUK_UINTPTR_MAX, as long as it is not a computed value */
2854 #if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_UINTPTR_MAX) && !defined(DUK_UINTPTR_MAX_COMPUTED)
2855 #if (DUK_UINTPTR_MAX <= 0xffffffffUL)
2856 #define DUK_F_PACKED_TVAL_POSSIBLE
2857 #endif
2858 #endif
2859 
2860 /* DUK_SIZE_MAX (= SIZE_MAX) is often reliable */
2861 #if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_SIZE_MAX) && !defined(DUK_SIZE_MAX_COMPUTED)
2862 #if (DUK_SIZE_MAX <= 0xffffffffUL)
2863 #define DUK_F_PACKED_TVAL_POSSIBLE
2864 #endif
2865 #endif
2866 
2867 #undef DUK_USE_PACKED_TVAL
2868 #if defined(DUK_F_PACKED_TVAL_POSSIBLE)
2869 #define DUK_USE_PACKED_TVAL
2870 #endif
2871 #undef DUK_F_PACKED_TVAL_POSSIBLE
2872 
2873 #endif  /* DUK_F_PACKED_TVAL_PROVIDED */
2874 /* Object property allocation layout has implications for memory and code
2875  * footprint and generated code size/speed.  The best layout also depends
2876  * on whether the platform has alignment requirements or benefits from
2877  * having mostly aligned accesses.
2878  */
2879 #undef DUK_USE_HOBJECT_LAYOUT_1
2880 #undef DUK_USE_HOBJECT_LAYOUT_2
2881 #undef DUK_USE_HOBJECT_LAYOUT_3
2882 #if (DUK_USE_ALIGN_BY == 1)
2883 /* On platforms without any alignment issues, layout 1 is preferable
2884  * because it compiles to slightly less code and provides direct access
2885  * to property keys.
2886  */
2887 #define DUK_USE_HOBJECT_LAYOUT_1
2888 #else
2889 /* On other platforms use layout 2, which requires some padding but
2890  * is a bit more natural than layout 3 in ordering the entries.  Layout
2891  * 3 is currently not used.
2892  */
2893 #define DUK_USE_HOBJECT_LAYOUT_2
2894 #endif
2895 
2896 /* GCC/clang inaccurate math would break compliance and probably duk_tval,
2897  * so refuse to compile.  Relax this if -ffast-math is tested to work.
2898  */
2899 #if defined(__FAST_MATH__)
2900 #error __FAST_MATH__ defined, refusing to compile
2901 #endif
2902 
2903 /*
2904  *  Forced options
2905  */
2906 
2907 #define DUK_USE_ALLOW_UNDEFINED_BEHAVIOR
2908 #undef DUK_USE_ARRAY_FASTPATH
2909 #undef DUK_USE_ARRAY_PROP_FASTPATH
2910 #undef DUK_USE_AUGMENT_ERROR_CREATE
2911 #undef DUK_USE_AUGMENT_ERROR_THROW
2912 #undef DUK_USE_BASE64_FASTPATH
2913 #undef DUK_USE_BASE64_SUPPORT
2914 #define DUK_USE_BUFFEROBJECT_SUPPORT
2915 #undef DUK_USE_BYTECODE_DUMP_SUPPORT
2916 #undef DUK_USE_CACHE_ACTIVATION
2917 #undef DUK_USE_CACHE_CATCHER
2918 #undef DUK_USE_CBOR_BUILTIN
2919 #undef DUK_USE_CBOR_SUPPORT
2920 #undef DUK_USE_COROUTINE_SUPPORT
2921 #undef DUK_USE_DEBUGGER_SUPPORT
2922 #define DUK_USE_DEBUG_BUFSIZE 2048
2923 #undef DUK_USE_ENCODING_BUILTINS
2924 #undef DUK_USE_ERRCREATE
2925 #undef DUK_USE_ERRTHROW
2926 #define DUK_USE_ES6
2927 #define DUK_USE_ES6_OBJECT_PROTO_PROPERTY
2928 #undef DUK_USE_ES6_PROXY
2929 #undef DUK_USE_ES6_UNICODE_ESCAPE
2930 #undef DUK_USE_ES7
2931 #undef DUK_USE_ES7_EXP_OPERATOR
2932 #undef DUK_USE_ES8
2933 #undef DUK_USE_ES9
2934 #define DUK_USE_EXEC_PREFER_SIZE
2935 #define DUK_USE_FASTINT
2936 #undef DUK_USE_FAST_REFCOUNT_DEFAULT
2937 #define DUK_USE_FATAL_MAXLEN 64
2938 #undef DUK_USE_FUNC_FILENAME_PROPERTY
2939 #define DUK_USE_FUNC_NAME_PROPERTY
2940 #undef DUK_USE_HEX_FASTPATH
2941 #undef DUK_USE_HEX_SUPPORT
2942 #define DUK_USE_HOBJECT_ARRAY_ABANDON_MINSIZE 32
2943 #define DUK_USE_HOBJECT_HASH_PROP_LIMIT 64
2944 #undef DUK_USE_HSTRING_ARRIDX
2945 #undef DUK_USE_HSTRING_LAZY_CLEN
2946 #undef DUK_USE_HTML_COMMENTS
2947 #undef DUK_USE_IDCHAR_FASTPATH
2948 #undef DUK_USE_JC
2949 #undef DUK_USE_JSON_DECNUMBER_FASTPATH
2950 #undef DUK_USE_JSON_DECSTRING_FASTPATH
2951 #undef DUK_USE_JSON_EATWHITE_FASTPATH
2952 #undef DUK_USE_JSON_QUOTESTRING_FASTPATH
2953 #undef DUK_USE_JSON_STRINGIFY_FASTPATH
2954 #define DUK_USE_JX
2955 #undef DUK_USE_LEXER_SLIDING_WINDOW
2956 #define DUK_USE_LIGHTFUNC_BUILTINS
2957 #undef DUK_USE_LITCACHE_SIZE
2958 #define DUK_USE_PARANOID_ERRORS
2959 #undef DUK_USE_PC2LINE
2960 #undef DUK_USE_PERFORMANCE_BUILTIN
2961 #define DUK_USE_PREFER_SIZE
2962 #undef DUK_USE_REFLECT_BUILTIN
2963 #undef DUK_USE_REGEXP_CANON_BITMAP
2964 #undef DUK_USE_REGEXP_CANON_WORKAROUND
2965 #undef DUK_USE_SHEBANG_COMMENTS
2966 #undef DUK_USE_SOURCE_NONBMP
2967 #define DUK_USE_STRTAB_GROW_LIMIT 65536L
2968 #define DUK_USE_STRTAB_MAXSIZE 128
2969 #define DUK_USE_STRTAB_MINSIZE 128
2970 #define DUK_USE_STRTAB_RESIZE_CHECK_MASK 255
2971 #define DUK_USE_STRTAB_SHRINK_LIMIT 0
2972 #define DUK_USE_SYMBOL_BUILTIN
2973 #undef DUK_USE_TRACEBACKS
2974 #undef DUK_USE_VALSTACK_GROW_SHIFT
2975 #undef DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT
2976 #undef DUK_USE_VALSTACK_SHRINK_SLACK_SHIFT
2977 #define DUK_USE_VALSTACK_UNSAFE
2978 #undef DUK_USE_VERBOSE_ERRORS
2979 #undef DUK_USE_VERBOSE_EXECUTOR_ERRORS
2980 
2981 /*
2982  *  Autogenerated defaults
2983  */
2984 
2985 #define DUK_USE_ARRAY_BUILTIN
2986 #undef DUK_USE_ASSERTIONS
2987 #define DUK_USE_AVOID_PLATFORM_FUNCPTRS
2988 #define DUK_USE_BOOLEAN_BUILTIN
2989 #undef DUK_USE_BUFLEN16
2990 #define DUK_USE_CALLSTACK_LIMIT 10000
2991 #define DUK_USE_COMPILER_RECLIMIT 2500
2992 #undef DUK_USE_CPP_EXCEPTIONS
2993 #undef DUK_USE_DATAPTR16
2994 #undef DUK_USE_DATAPTR_DEC16
2995 #undef DUK_USE_DATAPTR_ENC16
2996 #define DUK_USE_DATE_BUILTIN
2997 #undef DUK_USE_DATE_FORMAT_STRING
2998 #undef DUK_USE_DATE_GET_LOCAL_TZOFFSET
2999 #undef DUK_USE_DATE_GET_NOW
3000 #undef DUK_USE_DATE_PARSE_STRING
3001 #undef DUK_USE_DATE_PRS_GETDATE
3002 #undef DUK_USE_DEBUG
3003 #undef DUK_USE_DEBUGGER_DUMPHEAP
3004 #undef DUK_USE_DEBUGGER_INSPECT
3005 #undef DUK_USE_DEBUGGER_PAUSE_UNCAUGHT
3006 #define DUK_USE_DEBUGGER_THROW_NOTIFY
3007 #undef DUK_USE_DEBUGGER_TRANSPORT_TORTURE
3008 #define DUK_USE_DEBUG_LEVEL 0
3009 #undef DUK_USE_DEBUG_WRITE
3010 #define DUK_USE_DOUBLE_LINKED_HEAP
3011 #define DUK_USE_DUKTAPE_BUILTIN
3012 #define DUK_USE_ES6_OBJECT_SETPROTOTYPEOF
3013 #define DUK_USE_ES6_REGEXP_SYNTAX
3014 #define DUK_USE_ESBC_LIMITS
3015 #define DUK_USE_ESBC_MAX_BYTES 2147418112L
3016 #define DUK_USE_ESBC_MAX_LINENUMBER 2147418112L
3017 #undef DUK_USE_EXEC_FUN_LOCAL
3018 #undef DUK_USE_EXEC_INDIRECT_BOUND_CHECK
3019 #define DUK_USE_EXEC_REGCONST_OPTIMIZE
3020 #undef DUK_USE_EXEC_TIMEOUT_CHECK
3021 #undef DUK_USE_EXPLICIT_NULL_INIT
3022 #undef DUK_USE_EXTSTR_FREE
3023 #undef DUK_USE_EXTSTR_INTERN_CHECK
3024 #undef DUK_USE_FATAL_HANDLER
3025 #define DUK_USE_FINALIZER_SUPPORT
3026 #undef DUK_USE_FINALIZER_TORTURE
3027 #undef DUK_USE_FUNCPTR16
3028 #undef DUK_USE_FUNCPTR_DEC16
3029 #undef DUK_USE_FUNCPTR_ENC16
3030 #define DUK_USE_FUNCTION_BUILTIN
3031 #undef DUK_USE_GC_TORTURE
3032 #undef DUK_USE_GET_MONOTONIC_TIME
3033 #undef DUK_USE_GET_RANDOM_DOUBLE
3034 #define DUK_USE_GLOBAL_BINDING
3035 #define DUK_USE_GLOBAL_BUILTIN
3036 #undef DUK_USE_HEAPPTR16
3037 #undef DUK_USE_HEAPPTR_DEC16
3038 #undef DUK_USE_HEAPPTR_ENC16
3039 #define DUK_USE_HOBJECT_ARRAY_ABANDON_LIMIT 2
3040 #define DUK_USE_HOBJECT_ARRAY_FAST_RESIZE_LIMIT 9
3041 #define DUK_USE_HOBJECT_ARRAY_MINGROW_ADD 16
3042 #define DUK_USE_HOBJECT_ARRAY_MINGROW_DIVISOR 8
3043 #define DUK_USE_HOBJECT_ENTRY_MINGROW_ADD 16
3044 #define DUK_USE_HOBJECT_ENTRY_MINGROW_DIVISOR 8
3045 #define DUK_USE_HOBJECT_HASH_PART
3046 #define DUK_USE_HSTRING_CLEN
3047 #undef DUK_USE_HSTRING_EXTDATA
3048 #undef DUK_USE_INJECT_HEAP_ALLOC_ERROR
3049 #undef DUK_USE_INTERRUPT_COUNTER
3050 #undef DUK_USE_INTERRUPT_DEBUG_FIXUP
3051 #define DUK_USE_JSON_BUILTIN
3052 #define DUK_USE_JSON_DEC_RECLIMIT 1000
3053 #define DUK_USE_JSON_ENC_RECLIMIT 1000
3054 #define DUK_USE_JSON_SUPPORT
3055 #define DUK_USE_MARK_AND_SWEEP_RECLIMIT 256
3056 #define DUK_USE_MATH_BUILTIN
3057 #define DUK_USE_NATIVE_CALL_RECLIMIT 1000
3058 #undef DUK_USE_NATIVE_STACK_CHECK
3059 #define DUK_USE_NONSTD_ARRAY_SPLICE_DELCOUNT
3060 #undef DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
3061 #undef DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY
3062 #define DUK_USE_NONSTD_FUNC_STMT
3063 #define DUK_USE_NONSTD_GETTER_KEY_ARGUMENT
3064 #define DUK_USE_NONSTD_JSON_ESC_U2028_U2029
3065 #define DUK_USE_NONSTD_SETTER_KEY_ARGUMENT
3066 #define DUK_USE_NONSTD_STRING_FROMCHARCODE_32BIT
3067 #define DUK_USE_NUMBER_BUILTIN
3068 #define DUK_USE_OBJECT_BUILTIN
3069 #undef DUK_USE_OBJSIZES16
3070 #define DUK_USE_PROMISE_BUILTIN
3071 #define DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS
3072 #undef DUK_USE_REFCOUNT16
3073 #define DUK_USE_REFCOUNT32
3074 #define DUK_USE_REFERENCE_COUNTING
3075 #define DUK_USE_REGEXP_COMPILER_RECLIMIT 10000
3076 #define DUK_USE_REGEXP_EXECUTOR_RECLIMIT 10000
3077 #define DUK_USE_REGEXP_SUPPORT
3078 #undef DUK_USE_ROM_GLOBAL_CLONE
3079 #define DUK_USE_ROM_GLOBAL_INHERIT
3080 #define DUK_USE_ROM_OBJECTS
3081 #define DUK_USE_ROM_PTRCOMP_FIRST 63488L
3082 #define DUK_USE_ROM_STRINGS
3083 #define DUK_USE_SECTION_B
3084 #undef DUK_USE_SELF_TESTS
3085 #undef DUK_USE_SHUFFLE_TORTURE
3086 #undef DUK_USE_STRHASH16
3087 #undef DUK_USE_STRHASH_DENSE
3088 #define DUK_USE_STRHASH_SKIP_SHIFT 5
3089 #define DUK_USE_STRICT_DECL
3090 #undef DUK_USE_STRICT_UTF8_SOURCE
3091 #define DUK_USE_STRING_BUILTIN
3092 #undef DUK_USE_STRLEN16
3093 #undef DUK_USE_STRTAB_PTRCOMP
3094 #undef DUK_USE_STRTAB_TORTURE
3095 #define DUK_USE_TAILCALL
3096 #define DUK_USE_TARGET_INFO "amp"
3097 #define DUK_USE_TRACEBACK_DEPTH 10
3098 #define DUK_USE_VALSTACK_LIMIT 1000000L
3099 #define DUK_USE_VOLUNTARY_GC
3100 #define DUK_USE_ZERO_BUFFER_DATA
3101 
3102 #include "amp_config.h"
3103 #if !defined(AMP_LOWMEMORY_ENABLE)
3104 /* More feature */
3105 #define DUK_USE_LEXER_SLIDING_WINDOW
3106 #undef DUK_USE_PARANOID_ERRORS
3107 #define DUK_USE_REGEXP_CANON_BITMAP
3108 #define DUK_USE_BASE64_SUPPORT
3109 #define DUK_USE_BYTECODE_DUMP_SUPPORT
3110 /* Error reporting */
3111 #define DUK_USE_PC2LINE
3112 #define DUK_USE_AUGMENT_ERROR_CREATE
3113 #define DUK_USE_FUNC_FILENAME_PROPERTY
3114 #define DUK_USE_TRACEBACKS
3115 #define DUK_USE_VERBOSE_ERRORS
3116 #define DUK_USE_VERBOSE_EXECUTOR_ERRORS
3117 #endif
3118 
3119 
3120 /** custom defines */
3121 extern duk_double_t amp_date_get_now();
3122 /** get utc time */
3123 #define DUK_USE_DATE_GET_NOW(ctx) amp_date_get_now()
3124 /** beijing time offset */
3125 #define DUK_USE_DATE_GET_LOCAL_TZOFFSET(d)  28800
3126 
3127 /*
3128  *  You may add overriding #define/#undef directives below for
3129  *  customization.  You of course cannot un-#include or un-typedef
3130  *  anything; these require direct changes above.
3131  */
3132 
3133 /* __OVERRIDE_DEFINES__ */
3134 
3135 /*
3136  *  Conditional includes
3137  */
3138 
3139 #if defined(DUK_F_CPP) && defined(DUK_USE_CPP_EXCEPTIONS)
3140 #include <exception>  /* std::exception */
3141 #include <stdexcept>  /* std::runtime_error */
3142 #endif
3143 
3144 /*
3145  *  Date provider selection
3146  *
3147  *  User may define DUK_USE_DATE_GET_NOW() etc directly, in which case we'll
3148  *  rely on an external provider.  If this is not done, revert to previous
3149  *  behavior and use Unix/Windows built-in provider.
3150  */
3151 
3152 #if defined(DUK_COMPILING_DUKTAPE)
3153 
3154 #if defined(DUK_USE_DATE_GET_NOW)
3155 /* External provider already defined. */
3156 #elif defined(DUK_USE_DATE_NOW_GETTIMEOFDAY)
3157 #define DUK_USE_DATE_GET_NOW(ctx)            duk_bi_date_get_now_gettimeofday()
3158 #elif defined(DUK_USE_DATE_NOW_TIME)
3159 #define DUK_USE_DATE_GET_NOW(ctx)            duk_bi_date_get_now_time()
3160 #elif defined(DUK_USE_DATE_NOW_WINDOWS)
3161 #define DUK_USE_DATE_GET_NOW(ctx)            duk_bi_date_get_now_windows()
3162 #elif defined(DUK_USE_DATE_NOW_WINDOWS_SUBMS)
3163 #define DUK_USE_DATE_GET_NOW(ctx)            duk_bi_date_get_now_windows_subms()
3164 #else
3165 #error no provider for DUK_USE_DATE_GET_NOW()
3166 #endif
3167 
3168 #if defined(DUK_USE_DATE_GET_LOCAL_TZOFFSET)
3169 /* External provider already defined. */
3170 #elif defined(DUK_USE_DATE_TZO_GMTIME_R) || defined(DUK_USE_DATE_TZO_GMTIME_S) || defined(DUK_USE_DATE_TZO_GMTIME)
3171 #define DUK_USE_DATE_GET_LOCAL_TZOFFSET(d)   duk_bi_date_get_local_tzoffset_gmtime((d))
3172 #elif defined(DUK_USE_DATE_TZO_WINDOWS)
3173 #define DUK_USE_DATE_GET_LOCAL_TZOFFSET(d)   duk_bi_date_get_local_tzoffset_windows((d))
3174 #elif defined(DUK_USE_DATE_TZO_WINDOWS_NO_DST)
3175 #define DUK_USE_DATE_GET_LOCAL_TZOFFSET(d)   duk_bi_date_get_local_tzoffset_windows_no_dst((d))
3176 #else
3177 #error no provider for DUK_USE_DATE_GET_LOCAL_TZOFFSET()
3178 #endif
3179 
3180 #if defined(DUK_USE_DATE_PARSE_STRING)
3181 /* External provider already defined. */
3182 #elif defined(DUK_USE_DATE_PRS_STRPTIME)
3183 #define DUK_USE_DATE_PARSE_STRING(ctx,str)   duk_bi_date_parse_string_strptime((ctx), (str))
3184 #elif defined(DUK_USE_DATE_PRS_GETDATE)
3185 #define DUK_USE_DATE_PARSE_STRING(ctx,str)   duk_bi_date_parse_string_getdate((ctx), (str))
3186 #else
3187 /* No provider for DUK_USE_DATE_PARSE_STRING(), fall back to ISO 8601 only. */
3188 #endif
3189 
3190 #if defined(DUK_USE_DATE_FORMAT_STRING)
3191 /* External provider already defined. */
3192 #elif defined(DUK_USE_DATE_FMT_STRFTIME)
3193 #define DUK_USE_DATE_FORMAT_STRING(ctx,parts,tzoffset,flags) \
3194 	duk_bi_date_format_parts_strftime((ctx), (parts), (tzoffset), (flags))
3195 #else
3196 /* No provider for DUK_USE_DATE_FORMAT_STRING(), fall back to ISO 8601 only. */
3197 #endif
3198 
3199 #if defined(DUK_USE_GET_MONOTONIC_TIME)
3200 /* External provider already defined. */
3201 #elif defined(DUK_USE_GET_MONOTONIC_TIME_CLOCK_GETTIME)
3202 #define DUK_USE_GET_MONOTONIC_TIME(ctx)  duk_bi_date_get_monotonic_time_clock_gettime()
3203 #elif defined(DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC)
3204 #define DUK_USE_GET_MONOTONIC_TIME(ctx)  duk_bi_date_get_monotonic_time_windows_qpc()
3205 #else
3206 /* No provider for DUK_USE_GET_MONOTONIC_TIME(), fall back to DUK_USE_DATE_GET_NOW(). */
3207 #endif
3208 
3209 #endif  /* DUK_COMPILING_DUKTAPE */
3210 
3211 /*
3212  *  Convert DUK_USE_BYTEORDER, from whatever source, into currently used
3213  *  internal defines.  If detection failed, #error out.
3214  */
3215 
3216 #define DUK_USE_BYTEORDER 1
3217 
3218 #undef DUK_UNREACHABLE
3219 #define DUK_UNREACHABLE()  do { } while (0)
3220 
3221 // #define DUK_USE_DEBUG
3222 #undef DUK_USE_DEBUG_LEVEL
3223 #define DUK_USE_DEBUG_LEVEL 0
3224 
3225 // #define DUK_USE_SELF_TESTS
3226 
3227 extern void DUK_USE_DEBUG_WRITE(long arg_level, const char *arg_file, long arg_line, const char *arg_func, const char *arg_msg);
3228 #define DUK_USE_DEBUG_WRITE duk_debug_write_cb
3229 
3230 #define DUK_USE_VARIADIC_MACROS
3231 #if defined(DUK_USE_BYTEORDER)
3232 #if (DUK_USE_BYTEORDER == 1)
3233 #define DUK_USE_INTEGER_LE
3234 #define DUK_USE_DOUBLE_LE
3235 #elif (DUK_USE_BYTEORDER == 2)
3236 #define DUK_USE_INTEGER_LE  /* integer endianness is little on purpose */
3237 #define DUK_USE_DOUBLE_ME
3238 #elif (DUK_USE_BYTEORDER == 3)
3239 #define DUK_USE_INTEGER_BE
3240 #define DUK_USE_DOUBLE_BE
3241 #else
3242 #error unsupported: byte order invalid
3243 #endif  /* byte order */
3244 #else
3245 #error unsupported: byte order detection failed
3246 #endif  /* defined(DUK_USE_BYTEORDER) */
3247 
3248 #endif  /* DUK_CONFIG_H_INCLUDED */
3249