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