FreeWRL/FreeX3D  3.0.0
duk_config.h
1 /*
2  * duk_config.h configuration header generated by genconfig.py.
3  *
4  * Git commit: external
5  * Git describe: external
6  * Git branch: external
7  *
8  * Supported platforms:
9  * - Mac OSX, iPhone, Darwin
10  * - Orbis
11  * - OpenBSD
12  * - Generic BSD
13  * - Atari ST TOS
14  * - AmigaOS
15  * - Windows
16  * - Flashplayer (Crossbridge)
17  * - QNX
18  * - TI-Nspire
19  * - Emscripten
20  * - Linux
21  * - Solaris
22  * - Generic POSIX
23  * - Cygwin
24  * - Generic UNIX
25  * - Generic fallback
26  *
27  * Supported architectures:
28  * - x86
29  * - x64
30  * - x32
31  * - ARM 32-bit
32  * - ARM 64-bit
33  * - MIPS 32-bit
34  * - MIPS 64-bit
35  * - PowerPC 32-bit
36  * - PowerPC 64-bit
37  * - SPARC 32-bit
38  * - SPARC 64-bit
39  * - SuperH
40  * - Motorola 68k
41  * - Emscripten
42  * - Generic
43  *
44  * Supported compilers:
45  * - Clang
46  * - GCC
47  * - MSVC
48  * - Emscripten
49  * - TinyC
50  * - VBCC
51  * - Bruce's C compiler
52  * - Generic
53  *
54  */
55 
56 #if !defined(DUK_CONFIG_H_INCLUDED)
57 #define DUK_CONFIG_H_INCLUDED
58 
59 /*
60  * Intermediate helper defines
61  */
62 
63 /* DLL build detection */
64 /* not configured for DLL build */
65 #undef DUK_F_DLL_BUILD
66 
67 /* Apple OSX, iOS */
68 #if defined(__APPLE__)
69 #define DUK_F_APPLE
70 #endif
71 
72 /* FreeBSD */
73 #if defined(__FreeBSD__) || defined(__FreeBSD)
74 #define DUK_F_FREEBSD
75 #endif
76 
77 /* Orbis (PS4) variant */
78 #if defined(DUK_F_FREEBSD) && defined(__ORBIS__)
79 #define DUK_F_ORBIS
80 #endif
81 
82 /* OpenBSD */
83 #if defined(__OpenBSD__) || defined(__OpenBSD)
84 #define DUK_F_OPENBSD
85 #endif
86 
87 /* NetBSD */
88 #if defined(__NetBSD__) || defined(__NetBSD)
89 #define DUK_F_NETBSD
90 #endif
91 
92 /* BSD variant */
93 #if defined(DUK_F_FREEBSD) || defined(DUK_F_NETBSD) || defined(DUK_F_OPENBSD) || \
94  defined(__bsdi__) || defined(__DragonFly__)
95 #define DUK_F_BSD
96 #endif
97 
98 /* Atari ST TOS. __TOS__ defined by PureC. No platform define in VBCC
99  * apparently, so to use with VBCC user must define __TOS__ manually.
100  */
101 #if defined(__TOS__)
102 #define DUK_F_TOS
103 #endif
104 
105 /* Motorola 68K. Not defined by VBCC, so user must define one of these
106  * manually when using VBCC.
107  */
108 #if defined(__m68k__) || defined(M68000) || defined(__MC68K__)
109 #define DUK_F_M68K
110 #endif
111 
112 /* AmigaOS. Neither AMIGA nor __amigaos__ is defined on VBCC, so user must
113  * define 'AMIGA' manually when using VBCC.
114  */
115 #if defined(AMIGA) || defined(__amigaos__)
116 #define DUK_F_AMIGAOS
117 #endif
118 
119 /* PowerPC */
120 #if defined(__powerpc) || defined(__powerpc__) || defined(__PPC__)
121 #define DUK_F_PPC
122 #if defined(__PPC64__) || defined(__LP64__) || defined(_LP64)
123 #define DUK_F_PPC64
124 #else
125 #define DUK_F_PPC32
126 #endif
127 #endif
128 
129 /* Windows, both 32-bit and 64-bit */
130 #if defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(WIN64) || \
131  defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__)
132 #define DUK_F_WINDOWS
133 #if defined(_WIN64) || defined(WIN64)
134 #define DUK_F_WIN64
135 #else
136 #define DUK_F_WIN32
137 #endif
138 #endif
139 
140 /* Flash player (e.g. Crossbridge) */
141 #if defined(__FLASHPLAYER__)
142 #define DUK_F_FLASHPLAYER
143 #endif
144 
145 /* QNX */
146 #if defined(__QNX__)
147 #define DUK_F_QNX
148 #endif
149 
150 /* TI-Nspire (using Ndless) */
151 #if defined(_TINSPIRE)
152 #define DUK_F_TINSPIRE
153 #endif
154 
155 /* Emscripten (provided explicitly by user), improve if possible */
156 #if defined(EMSCRIPTEN)
157 #define DUK_F_EMSCRIPTEN
158 #endif
159 
160 /* BCC (Bruce's C compiler): this is a "torture target" for compilation */
161 #if defined(__BCC__) || defined(__BCC_VERSION__)
162 #define DUK_F_BCC
163 #endif
164 
165 /* Linux */
166 #if defined(__linux) || defined(__linux__) || defined(linux)
167 #define DUK_F_LINUX
168 #endif
169 
170 /* illumos / Solaris */
171 #if defined(__sun) && defined(__SVR4)
172 #define DUK_F_SUN
173 #endif
174 
175 /* POSIX */
176 #if defined(__posix)
177 #define DUK_F_POSIX
178 #endif
179 
180 /* Cygwin */
181 #if defined(__CYGWIN__)
182 #define DUK_F_CYGWIN
183 #endif
184 
185 /* Generic Unix (includes Cygwin) */
186 #if defined(__unix) || defined(__unix__) || defined(unix) || \
187  defined(DUK_F_LINUX) || defined(DUK_F_BSD)
188 #define DUK_F_UNIX
189 #endif
190 
191 /* stdint.h not available */
192 #if defined(DUK_F_WINDOWS) && defined(_MSC_VER)
193 #if (_MSC_VER < 1700)
194 /* VS2012+ has stdint.h, < VS2012 does not (but it's available for download). */
195 #define DUK_F_NO_STDINT_H
196 #endif
197 #endif
198 #if !defined(DUK_F_NO_STDINT_H) && (defined(DUK_F_TOS) || defined(DUK_F_BCC))
199 #define DUK_F_NO_STDINT_H
200 #endif
201 
202 /* C++ */
203 #undef DUK_F_CPP
204 #if defined(__cplusplus)
205 #define DUK_F_CPP
206 #endif
207 
208 /* Intel x86 (32-bit), x64 (64-bit) or x32 (64-bit but 32-bit pointers),
209  * define only one of DUK_F_X86, DUK_F_X64, DUK_F_X32.
210  * https://sites.google.com/site/x32abi/
211  */
212 #if defined(__amd64__) || defined(__amd64) || \
213  defined(__x86_64__) || defined(__x86_64) || \
214  defined(_M_X64) || defined(_M_AMD64)
215 #if defined(__ILP32__) || defined(_ILP32)
216 #define DUK_F_X32
217 #else
218 #define DUK_F_X64
219 #endif
220 #elif defined(i386) || defined(__i386) || defined(__i386__) || \
221  defined(__i486__) || defined(__i586__) || defined(__i686__) || \
222  defined(__IA32__) || defined(_M_IX86) || defined(__X86__) || \
223  defined(_X86_) || defined(__THW_INTEL__) || defined(__I86__)
224 #if defined(__LP64__) || defined(_LP64)
225 /* This should not really happen, but would indicate x64. */
226 #define DUK_F_X64
227 #else
228 #define DUK_F_X86
229 #endif
230 #endif
231 
232 /* ARM */
233 #if defined(__arm__) || defined(__thumb__) || defined(_ARM) || defined(_M_ARM) || defined(__aarch64__)
234 #define DUK_F_ARM
235 #if defined(__LP64__) || defined(_LP64) || defined(__arm64) || defined(__arm64__) || defined(__aarch64__)
236 #define DUK_F_ARM64
237 #else
238 #define DUK_F_ARM32
239 #endif
240 #endif
241 
242 /* MIPS. Related defines: __MIPSEB__, __MIPSEL__, __mips_isa_rev, __LP64__ */
243 #if defined(__mips__) || defined(mips) || defined(_MIPS_ISA) || \
244  defined(_R3000) || defined(_R4000) || defined(_R5900) || \
245  defined(_MIPS_ISA_MIPS1) || defined(_MIPS_ISA_MIPS2) || \
246  defined(_MIPS_ISA_MIPS3) || defined(_MIPS_ISA_MIPS4) || \
247  defined(__mips) || defined(__MIPS__)
248 #define DUK_F_MIPS
249 #if defined(__LP64__) || defined(_LP64) || defined(__mips64) || \
250  defined(__mips64__) || defined(__mips_n64)
251 #define DUK_F_MIPS64
252 #else
253 #define DUK_F_MIPS32
254 #endif
255 #endif
256 
257 /* SPARC */
258 #if defined(sparc) || defined(__sparc) || defined(__sparc__)
259 #define DUK_F_SPARC
260 #if defined(__LP64__) || defined(_LP64)
261 #define DUK_F_SPARC64
262 #else
263 #define DUK_F_SPARC32
264 #endif
265 #endif
266 
267 /* SuperH */
268 #if defined(__sh__) || \
269  defined(__sh1__) || defined(__SH1__) || \
270  defined(__sh2__) || defined(__SH2__) || \
271  defined(__sh3__) || defined(__SH3__) || \
272  defined(__sh4__) || defined(__SH4__) || \
273  defined(__sh5__) || defined(__SH5__)
274 #define DUK_F_SUPERH
275 #endif
276 
277 /* Clang */
278 #if defined(__clang__)
279 #define DUK_F_CLANG
280 #endif
281 
282 /* C99 or above */
283 #undef DUK_F_C99
284 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
285 #define DUK_F_C99
286 #endif
287 
288 /* C++11 or above */
289 #undef DUK_F_CPP11
290 #if defined(__cplusplus) && (__cplusplus >= 201103L)
291 #define DUK_F_CPP11
292 #endif
293 
294 /* GCC. Clang also defines __GNUC__ so don't detect GCC if using Clang. */
295 #if defined(__GNUC__) && !defined(__clang__) && !defined(DUK_F_CLANG)
296 #define DUK_F_GCC
297 #if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
298 /* Convenience, e.g. gcc 4.5.1 == 40501; http://stackoverflow.com/questions/6031819/emulating-gccs-builtin-unreachable */
299 #define DUK_F_GCC_VERSION (__GNUC__ * 10000L + __GNUC_MINOR__ * 100L + __GNUC_PATCHLEVEL__)
300 #else
301 #error cannot figure out gcc version
302 #endif
303 #endif
304 
305 /* MinGW. Also GCC flags (DUK_F_GCC) are enabled now. */
306 #if defined(__MINGW32__) || defined(__MINGW64__)
307 #define DUK_F_MINGW
308 #endif
309 
310 /* MSVC */
311 #if defined(_MSC_VER)
312 /* MSVC preprocessor defines: http://msdn.microsoft.com/en-us/library/b0084kay.aspx
313  * _MSC_FULL_VER includes the build number, but it has at least two formats, see e.g.
314  * BOOST_MSVC_FULL_VER in http://www.boost.org/doc/libs/1_52_0/boost/config/compiler/visualc.hpp
315  */
316 #define DUK_F_MSVC
317 #if defined(_MSC_FULL_VER)
318 #if (_MSC_FULL_VER > 100000000)
319 #define DUK_F_MSVC_FULL_VER _MSC_FULL_VER
320 #else
321 #define DUK_F_MSCV_FULL_VER (_MSC_FULL_VER * 10)
322 #endif
323 #endif
324 #endif /* _MSC_VER */
325 
326 /* TinyC */
327 #if defined(__TINYC__)
328 /* http://bellard.org/tcc/tcc-doc.html#SEC9 */
329 #define DUK_F_TINYC
330 #endif
331 
332 /* VBCC */
333 #if defined(__VBCC__)
334 #define DUK_F_VBCC
335 #endif
336 
337 /*
338  * Platform autodetection
339  */
340 
341 /* Workaround for older C++ compilers before including <inttypes.h>,
342  * see e.g.: https://sourceware.org/bugzilla/show_bug.cgi?id=15366
343  */
344 #if defined(__cplusplus) && !defined(__STDC_LIMIT_MACROS)
345 #define __STDC_LIMIT_MACROS
346 #endif
347 #if defined(__cplusplus) && !defined(__STDC_CONSTANT_MACROS)
348 #define __STDC_CONSTANT_MACROS
349 #endif
350 
351 #if defined(DUK_F_APPLE)
352 /* --- Mac OSX, iPhone, Darwin --- */
353 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
354 #define DUK_USE_DATE_TZO_GMTIME_R
355 #define DUK_USE_DATE_PRS_STRPTIME
356 #define DUK_USE_DATE_FMT_STRFTIME
357 #include <TargetConditionals.h>
358 #include <architecture/byte_order.h>
359 #include <sys/param.h>
360 #include <sys/time.h>
361 #include <time.h>
362 
363 /* http://stackoverflow.com/questions/5919996/how-to-detect-reliably-mac-os-x-ios-linux-windows-in-c-preprocessor */
364 #if TARGET_IPHONE_SIMULATOR
365 #define DUK_USE_OS_STRING "iphone-sim"
366 #elif TARGET_OS_IPHONE
367 #define DUK_USE_OS_STRING "iphone"
368 #elif TARGET_OS_MAC
369 #define DUK_USE_OS_STRING "osx"
370 #else
371 #define DUK_USE_OS_STRING "osx-unknown"
372 #endif
373 
374 /* Use _setjmp() on Apple by default, see GH-55. */
375 #define DUK_JMPBUF_TYPE jmp_buf
376 #define DUK_SETJMP(jb) _setjmp((jb))
377 #define DUK_LONGJMP(jb) _longjmp((jb), 1)
378 #elif defined(DUK_F_ORBIS)
379 /* --- Orbis --- */
380 /* Orbis = PS4 */
381 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
382 #define DUK_USE_DATE_TZO_GMTIME_S
383 /* no parsing (not an error) */
384 #define DUK_USE_DATE_FMT_STRFTIME
385 #include <sys/types.h>
386 #include <machine/endian.h>
387 #include <sys/param.h>
388 #include <sys/time.h>
389 #include <time.h>
390 
391 #define DUK_USE_OS_STRING "orbis"
392 #elif defined(DUK_F_OPENBSD)
393 /* --- OpenBSD --- */
394 /* http://www.monkey.org/openbsd/archive/ports/0401/msg00089.html */
395 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
396 #define DUK_USE_DATE_TZO_GMTIME_R
397 #define DUK_USE_DATE_PRS_STRPTIME
398 #define DUK_USE_DATE_FMT_STRFTIME
399 #include <sys/types.h>
400 #include <sys/endian.h>
401 #include <sys/param.h>
402 #include <sys/time.h>
403 #include <time.h>
404 
405 #define DUK_USE_OS_STRING "openbsd"
406 #elif defined(DUK_F_BSD)
407 /* --- Generic BSD --- */
408 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
409 #define DUK_USE_DATE_TZO_GMTIME_R
410 #define DUK_USE_DATE_PRS_STRPTIME
411 #define DUK_USE_DATE_FMT_STRFTIME
412 #include <sys/types.h>
413 #include <sys/endian.h>
414 #include <sys/param.h>
415 #include <sys/time.h>
416 #include <time.h>
417 
418 #define DUK_USE_OS_STRING "bsd"
419 #elif defined(DUK_F_TOS)
420 /* --- Atari ST TOS --- */
421 #define DUK_USE_DATE_NOW_TIME
422 #define DUK_USE_DATE_TZO_GMTIME
423 /* no parsing (not an error) */
424 #define DUK_USE_DATE_FMT_STRFTIME
425 #include <time.h>
426 
427 #define DUK_USE_OS_STRING "tos"
428 
429 /* TOS on M68K is always big endian. */
430 #if !defined(DUK_USE_BYTEORDER) && defined(DUK_F_M68K)
431 #define DUK_USE_BYTEORDER 3
432 #endif
433 #elif defined(DUK_F_AMIGAOS)
434 /* --- AmigaOS --- */
435 #if defined(DUK_F_M68K)
436 /* AmigaOS on M68k */
437 #define DUK_USE_DATE_NOW_TIME
438 #define DUK_USE_DATE_TZO_GMTIME
439 /* no parsing (not an error) */
440 #define DUK_USE_DATE_FMT_STRFTIME
441 #include <time.h>
442 #elif defined(DUK_F_PPC)
443 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
444 #define DUK_USE_DATE_TZO_GMTIME_R
445 #define DUK_USE_DATE_PRS_STRPTIME
446 #define DUK_USE_DATE_FMT_STRFTIME
447 #include <time.h>
448 #if !defined(UINTPTR_MAX)
449 #define UINTPTR_MAX UINT_MAX
450 #endif
451 #else
452 #error AmigaOS but not M68K/PPC, not supported now
453 #endif
454 
455 #define DUK_USE_OS_STRING "amigaos"
456 
457 /* AmigaOS on M68K or PPC is always big endian. */
458 #if !defined(DUK_USE_BYTEORDER) && (defined(DUK_F_M68K) || defined(DUK_F_PPC))
459 #define DUK_USE_BYTEORDER 3
460 #endif
461 #elif defined(DUK_F_WINDOWS)
462 /* --- Windows --- */
463 /* Initial fix: disable secure CRT related warnings when compiling Duktape
464  * itself (must be defined before including Windows headers). Don't define
465  * for user code including duktape.h.
466  */
467 #if defined(DUK_COMPILING_DUKTAPE) && !defined(_CRT_SECURE_NO_WARNINGS)
468 #define _CRT_SECURE_NO_WARNINGS
469 #endif
470 
471 /* Windows 32-bit and 64-bit are currently the same. */
472 /* MSVC does not have sys/param.h */
473 #define DUK_USE_DATE_NOW_WINDOWS
474 #define DUK_USE_DATE_TZO_WINDOWS
475 /* Note: PRS and FMT are intentionally left undefined for now. This means
476  * there is no platform specific date parsing/formatting but there is still
477  * the ISO 8601 standard format.
478  */
479 #if defined(DUK_COMPILING_DUKTAPE)
480 /* Only include when compiling Duktape to avoid polluting application build
481  * with a lot of unnecessary defines.
482  */
483 #include <windows.h>
484 #endif
485 
486 #define DUK_USE_OS_STRING "windows"
487 
488 /* On Windows, assume we're little endian. Even Itanium which has a
489  * configurable endianness runs little endian in Windows.
490  */
491 #if !defined(DUK_USE_BYTEORDER)
492 #define DUK_USE_BYTEORDER 1
493 #endif
494 #elif defined(DUK_F_FLASHPLAYER)
495 /* --- Flashplayer (Crossbridge) --- */
496 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
497 #define DUK_USE_DATE_TZO_GMTIME_R
498 #define DUK_USE_DATE_PRS_STRPTIME
499 #define DUK_USE_DATE_FMT_STRFTIME
500 #include <endian.h>
501 #include <sys/param.h>
502 #include <sys/time.h>
503 #include <time.h>
504 
505 #define DUK_USE_OS_STRING "flashplayer"
506 
507 #if !defined(DUK_USE_BYTEORDER) && defined(DUK_F_FLASHPLAYER)
508 #define DUK_USE_BYTEORDER 1
509 #endif
510 #elif defined(DUK_F_QNX)
511 /* --- QNX --- */
512 #if defined(DUK_F_QNX) && defined(DUK_COMPILING_DUKTAPE)
513 /* See: /opt/qnx650/target/qnx6/usr/include/sys/platform.h */
514 #define _XOPEN_SOURCE 600
515 #define _POSIX_C_SOURCE 200112L
516 #endif
517 
518 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
519 #define DUK_USE_DATE_TZO_GMTIME_R
520 #define DUK_USE_DATE_PRS_STRPTIME
521 #define DUK_USE_DATE_FMT_STRFTIME
522 #include <sys/types.h>
523 #include <sys/param.h>
524 #include <sys/time.h>
525 #include <time.h>
526 
527 #define DUK_USE_OS_STRING "qnx"
528 #elif defined(DUK_F_TINSPIRE)
529 /* --- TI-Nspire --- */
530 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
531 #define DUK_USE_DATE_TZO_GMTIME_R
532 #define DUK_USE_DATE_PRS_STRPTIME
533 #define DUK_USE_DATE_FMT_STRFTIME
534 #include <sys/types.h>
535 #include <sys/param.h>
536 #include <sys/time.h>
537 #include <time.h>
538 
539 #define DUK_USE_OS_STRING "tinspire"
540 #elif defined(DUK_F_EMSCRIPTEN)
541 /* --- Emscripten --- */
542 #if defined(DUK_COMPILING_DUKTAPE)
543 #if !defined(_POSIX_C_SOURCE)
544 #define _POSIX_C_SOURCE 200809L
545 #endif
546 #if !defined(_GNU_SOURCE)
547 #define _GNU_SOURCE /* e.g. getdate_r */
548 #endif
549 #if !defined(_XOPEN_SOURCE)
550 #define _XOPEN_SOURCE /* e.g. strptime */
551 #endif
552 #endif /* DUK_COMPILING_DUKTAPE */
553 
554 #include <sys/types.h>
555 #if defined(DUK_F_BCC)
556 /* no endian.h */
557 #else
558 #include <endian.h>
559 #endif /* DUK_F_BCC */
560 #include <sys/param.h>
561 #include <sys/time.h>
562 #include <time.h>
563 #include <stdint.h>
564 
565 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
566 #define DUK_USE_DATE_TZO_GMTIME_R
567 #define DUK_USE_DATE_PRS_STRPTIME
568 #define DUK_USE_DATE_FMT_STRFTIME
569 
570 #define DUK_USE_OS_STRING "emscripten"
571 #elif defined(DUK_F_LINUX)
572 /* --- Linux --- */
573 #if defined(DUK_COMPILING_DUKTAPE)
574 #if !defined(_POSIX_C_SOURCE)
575 #define _POSIX_C_SOURCE 200809L
576 #endif
577 #if !defined(_GNU_SOURCE)
578 #define _GNU_SOURCE /* e.g. getdate_r */
579 #endif
580 #if !defined(_XOPEN_SOURCE)
581 #define _XOPEN_SOURCE /* e.g. strptime */
582 #endif
583 #endif /* DUK_COMPILING_DUKTAPE */
584 
585 #include <sys/types.h>
586 #if defined(DUK_F_BCC)
587 /* no endian.h or stdint.h */
588 #else
589 #include <endian.h>
590 #include <stdint.h>
591 #endif /* DUK_F_BCC */
592 #include <sys/param.h>
593 #include <sys/time.h>
594 #include <time.h>
595 
596 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
597 #define DUK_USE_DATE_TZO_GMTIME_R
598 #define DUK_USE_DATE_PRS_STRPTIME
599 #define DUK_USE_DATE_FMT_STRFTIME
600 
601 #define DUK_USE_OS_STRING "linux"
602 #elif defined(DUK_F_SUN)
603 /* --- Solaris --- */
604 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
605 #define DUK_USE_DATE_TZO_GMTIME_R
606 #define DUK_USE_DATE_PRS_STRPTIME
607 #define DUK_USE_DATE_FMT_STRFTIME
608 
609 #include <sys/types.h>
610 #include <ast/endian.h>
611 #include <sys/param.h>
612 #include <sys/time.h>
613 #include <time.h>
614 
615 #define DUK_USE_OS_STRING "solaris"
616 #elif defined(DUK_F_POSIX)
617 /* --- Generic POSIX --- */
618 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
619 #define DUK_USE_DATE_TZO_GMTIME_R
620 #define DUK_USE_DATE_PRS_STRPTIME
621 #define DUK_USE_DATE_FMT_STRFTIME
622 #include <sys/types.h>
623 #include <endian.h>
624 #include <sys/param.h>
625 #include <sys/time.h>
626 #include <time.h>
627 
628 #define DUK_USE_OS_STRING "posix"
629 #elif defined(DUK_F_CYGWIN)
630 /* --- Cygwin --- */
631 /* don't use strptime() for now */
632 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
633 #define DUK_USE_DATE_TZO_GMTIME_R
634 #define DUK_USE_DATE_FMT_STRFTIME
635 #include <sys/types.h>
636 #include <endian.h>
637 #include <sys/param.h>
638 #include <sys/time.h>
639 #include <time.h>
640 
641 #define DUK_JMPBUF_TYPE jmp_buf
642 #define DUK_SETJMP(jb) _setjmp((jb))
643 #define DUK_LONGJMP(jb) _longjmp((jb), 1)
644 
645 #define DUK_USE_OS_STRING "windows"
646 #elif defined(DUK_F_UNIX)
647 /* --- Generic UNIX --- */
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 <time.h>
653 #include <sys/time.h>
654 #define DUK_USE_OS_STRING "unknown"
655 #else
656 /* --- Generic fallback --- */
657 /* The most portable current time provider is time(), but it only has a
658  * one second resolution.
659  */
660 #define DUK_USE_DATE_NOW_TIME
661 
662 /* The most portable way to figure out local time offset is gmtime(),
663  * but it's not thread safe so use with caution.
664  */
665 #define DUK_USE_DATE_TZO_GMTIME
666 
667 /* Avoid custom date parsing and formatting for portability. */
668 #undef DUK_USE_DATE_PRS_STRPTIME
669 #undef DUK_USE_DATE_FMT_STRFTIME
670 
671 /* Rely on C89 headers only; time.h must be here. */
672 #include <time.h>
673 
674 #define DUK_USE_OS_STRING "unknown"
675 #endif /* autodetect platform */
676 
677 /* Shared includes: C89 */
678 #include <stdio.h>
679 #include <stdlib.h>
680 #include <string.h>
681 #include <stdarg.h> /* varargs */
682 #include <setjmp.h>
683 #include <stddef.h> /* e.g. ptrdiff_t */
684 #include <math.h>
685 #include <limits.h>
686 
687 /* date.h is omitted, and included per platform */
688 
689 /* Shared includes: stdint.h is C99 */
690 #if defined(DUK_F_NO_STDINT_H)
691 /* stdint.h not available */
692 #else
693 /* Technically C99 (C++11) but found in many systems. On some systems
694  * __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS must be defined before
695  * including stdint.h (see above).
696  */
697 #include <stdint.h>
698 #endif
699 
700 #if defined(DUK_F_CPP)
701 #include <exception> /* std::exception */
702 #endif
703 
704 /*
705  * Architecture autodetection
706  */
707 
708 #if defined(DUK_F_X86)
709 /* --- x86 --- */
710 #define DUK_USE_ARCH_STRING "x86"
711 #if !defined(DUK_USE_BYTEORDER)
712 #define DUK_USE_BYTEORDER 1
713 #endif
714 /* XXX: This is technically not guaranteed because it's possible to configure
715  * an x86 to require aligned accesses with Alignment Check (AC) flag.
716  */
717 #if !defined(DUK_USE_ALIGN_BY)
718 #define DUK_USE_ALIGN_BY 1
719 #endif
720 #define DUK_USE_PACKED_TVAL
721 #define DUK_F_PACKED_TVAL_PROVIDED
722 #elif defined(DUK_F_X64)
723 /* --- x64 --- */
724 #define DUK_USE_ARCH_STRING "x64"
725 #if !defined(DUK_USE_BYTEORDER)
726 #define DUK_USE_BYTEORDER 1
727 #endif
728 /* XXX: This is technically not guaranteed because it's possible to configure
729  * an x86 to require aligned accesses with Alignment Check (AC) flag.
730  */
731 #if !defined(DUK_USE_ALIGN_BY)
732 #define DUK_USE_ALIGN_BY 1
733 #endif
734 #undef DUK_USE_PACKED_TVAL
735 #define DUK_F_PACKED_TVAL_PROVIDED
736 #elif defined(DUK_F_X32)
737 /* --- x32 --- */
738 #define DUK_USE_ARCH_STRING "x32"
739 #if !defined(DUK_USE_BYTEORDER)
740 #define DUK_USE_BYTEORDER 1
741 #endif
742 /* XXX: This is technically not guaranteed because it's possible to configure
743  * an x86 to require aligned accesses with Alignment Check (AC) flag.
744  */
745 #if !defined(DUK_USE_ALIGN_BY)
746 #define DUK_USE_ALIGN_BY 1
747 #endif
748 #define DUK_USE_PACKED_TVAL
749 #define DUK_F_PACKED_TVAL_PROVIDED
750 #elif defined(DUK_F_ARM32)
751 /* --- ARM 32-bit --- */
752 #define DUK_USE_ARCH_STRING "arm32"
753 /* Byte order varies, so rely on autodetect. */
754 #if !defined(DUK_USE_ALIGN_BY)
755 #define DUK_USE_ALIGN_BY 4
756 #endif
757 #define DUK_USE_PACKED_TVAL
758 #define DUK_F_PACKED_TVAL_PROVIDED
759 #elif defined(DUK_F_ARM64)
760 /* --- ARM 64-bit --- */
761 #define DUK_USE_ARCH_STRING "arm64"
762 /* Byte order varies, so rely on autodetect. */
763 #if !defined(DUK_USE_ALIGN_BY)
764 #define DUK_USE_ALIGN_BY 8
765 #endif
766 #undef DUK_USE_PACKED_TVAL
767 #define DUK_F_PACKED_TVAL_PROVIDED
768 #elif defined(DUK_F_MIPS32)
769 /* --- MIPS 32-bit --- */
770 #define DUK_USE_ARCH_STRING "mips32"
771 /* MIPS byte order varies so rely on autodetection. */
772 /* Based on 'make checkalign' there are no alignment requirements on
773  * Linux MIPS except for doubles, which need align by 4. Alignment
774  * requirements vary based on target though.
775  */
776 #if !defined(DUK_USE_ALIGN_BY)
777 #define DUK_USE_ALIGN_BY 4
778 #endif
779 #define DUK_USE_PACKED_TVAL
780 #define DUK_F_PACKED_TVAL_PROVIDED
781 #elif defined(DUK_F_MIPS64)
782 /* --- MIPS 64-bit --- */
783 #define DUK_USE_ARCH_STRING "mips64"
784 /* MIPS byte order varies so rely on autodetection. */
785 /* Good default is a bit arbitrary because alignment requirements
786  * depend on target. See https://github.com/svaarala/duktape/issues/102.
787  */
788 #if !defined(DUK_USE_ALIGN_BY)
789 #define DUK_USE_ALIGN_BY 8
790 #endif
791 #undef DUK_USE_PACKED_TVAL
792 #define DUK_F_PACKED_TVAL_PROVIDED
793 #elif defined(DUK_F_PPC32)
794 /* --- PowerPC 32-bit --- */
795 #define DUK_USE_ARCH_STRING "ppc32"
796 #if !defined(DUK_USE_BYTEORDER)
797 #define DUK_USE_BYTEORDER 3
798 #endif
799 #if !defined(DUK_USE_ALIGN_BY)
800 #define DUK_USE_ALIGN_BY 8
801 #endif
802 #define DUK_USE_PACKED_TVAL
803 #define DUK_F_PACKED_TVAL_PROVIDED
804 #elif defined(DUK_F_PPC64)
805 /* --- PowerPC 64-bit --- */
806 #define DUK_USE_ARCH_STRING "ppc64"
807 #if !defined(DUK_USE_BYTEORDER)
808 #define DUK_USE_BYTEORDER 3
809 #endif
810 #if !defined(DUK_USE_ALIGN_BY)
811 #define DUK_USE_ALIGN_BY 8
812 #endif
813 #undef DUK_USE_PACKED_TVAL
814 #define DUK_F_PACKED_TVAL_PROVIDED
815 #elif defined(DUK_F_SPARC32)
816 /* --- SPARC 32-bit --- */
817 #define DUK_USE_ARCH_STRING "sparc32"
818 /* SPARC byte order varies so rely on autodetection. */
819 #if !defined(DUK_USE_ALIGN_BY)
820 #define DUK_USE_ALIGN_BY 8
821 #endif
822 #define DUK_USE_PACKED_TVAL
823 #define DUK_F_PACKED_TVAL_PROVIDED
824 #elif defined(DUK_F_SPARC64)
825 /* --- SPARC 64-bit --- */
826 #define DUK_USE_ARCH_STRING "sparc64"
827 /* SPARC byte order varies so rely on autodetection. */
828 #if !defined(DUK_USE_ALIGN_BY)
829 #define DUK_USE_ALIGN_BY 8
830 #endif
831 #undef DUK_USE_PACKED_TVAL
832 #define DUK_F_PACKED_TVAL_PROVIDED
833 #elif defined(DUK_F_SUPERH)
834 /* --- SuperH --- */
835 #define DUK_USE_ARCH_STRING "sh"
836 /* Byte order varies, rely on autodetection. */
837 /* Based on 'make checkalign' there are no alignment requirements on
838  * Linux SH4, but align by 4 is probably a good basic default.
839  */
840 #if !defined(DUK_USE_ALIGN_BY)
841 #define DUK_USE_ALIGN_BY 4
842 #endif
843 #define DUK_USE_PACKED_TVAL
844 #define DUK_F_PACKED_TVAL_PROVIDED
845 #elif defined(DUK_F_M68K)
846 /* --- Motorola 68k --- */
847 #define DUK_USE_ARCH_STRING "m68k"
848 #if !defined(DUK_USE_BYTEORDER)
849 #define DUK_USE_BYTEORDER 3
850 #endif
851 #if !defined(DUK_USE_ALIGN_BY)
852 #define DUK_USE_ALIGN_BY 8
853 #endif
854 #define DUK_USE_PACKED_TVAL
855 #define DUK_F_PACKED_TVAL_PROVIDED
856 #elif defined(DUK_F_EMSCRIPTEN)
857 /* --- Emscripten --- */
858 #define DUK_USE_ARCH_STRING "emscripten"
859 #if !defined(DUK_USE_BYTEORDER)
860 #define DUK_USE_BYTEORDER 1
861 #endif
862 #if !defined(DUK_USE_ALIGN_BY)
863 #define DUK_USE_ALIGN_BY 8
864 #endif
865 #undef DUK_USE_PACKED_TVAL
866 #define DUK_F_PACKED_TVAL_PROVIDED
867 #else
868 /* --- Generic --- */
869 /* These are necessary wild guesses. */
870 #define DUK_USE_ARCH_STRING "generic"
871 /* Rely on autodetection for byte order, alignment, and packed tval. */
872 #endif /* autodetect architecture */
873 
874 /*
875  * Compiler autodetection
876  */
877 
878 #if defined(DUK_F_CLANG)
879 /* --- Clang --- */
880 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
881 /* C99 / C++11 and above: rely on va_copy() which is required. */
882 #define DUK_VA_COPY(dest,src) va_copy(dest,src)
883 #else
884 /* Clang: assume we have __va_copy() in non-C99 mode. */
885 #define DUK_VA_COPY(dest,src) __va_copy(dest,src)
886 #endif
887 
888 #define DUK_NORETURN(decl) decl __attribute__((noreturn))
889 
890 #if defined(__clang__) && defined(__has_builtin)
891 #if __has_builtin(__builtin_unreachable)
892 #define DUK_UNREACHABLE() do { __builtin_unreachable(); } while (0)
893 #endif
894 #endif
895 
896 #define DUK_USE_BRANCH_HINTS
897 #define DUK_LIKELY(x) __builtin_expect((x), 1)
898 #define DUK_UNLIKELY(x) __builtin_expect((x), 0)
899 #if defined(__clang__) && defined(__has_builtin)
900 #if __has_builtin(__builtin_unpredictable)
901 #define DUK_UNPREDICTABLE(x) __builtin_unpredictable((x))
902 #endif
903 #endif
904 
905 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
906 #define DUK_NOINLINE __attribute__((noinline))
907 #define DUK_INLINE inline
908 #define DUK_ALWAYS_INLINE inline __attribute__((always_inline))
909 #endif
910 
911 #if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
912 /* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
913  * compiling Duktape or the application.
914  */
915 #if defined(DUK_COMPILING_DUKTAPE)
916 #define DUK_EXTERNAL_DECL extern __declspec(dllexport)
917 #define DUK_EXTERNAL __declspec(dllexport)
918 #else
919 #define DUK_EXTERNAL_DECL extern __declspec(dllimport)
920 #define DUK_EXTERNAL should_not_happen
921 #endif
922 #if defined(DUK_SINGLE_FILE)
923 #define DUK_INTERNAL_DECL static
924 #define DUK_INTERNAL static
925 #else
926 #define DUK_INTERNAL_DECL extern
927 #define DUK_INTERNAL /*empty*/
928 #endif
929 #define DUK_LOCAL_DECL static
930 #define DUK_LOCAL static
931 #else
932 #define DUK_EXTERNAL_DECL __attribute__ ((visibility("default"))) extern
933 #define DUK_EXTERNAL __attribute__ ((visibility("default")))
934 #if defined(DUK_SINGLE_FILE)
935 #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
936 /* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
937  * Clang. Based on documentation it should suffice to have the attribute
938  * in the declaration only, but in practice some warnings are generated unless
939  * the attribute is also applied to the definition.
940  */
941 #define DUK_INTERNAL_DECL static __attribute__ ((unused))
942 #define DUK_INTERNAL static __attribute__ ((unused))
943 #else
944 #define DUK_INTERNAL_DECL static
945 #define DUK_INTERNAL static
946 #endif
947 #else
948 #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
949 #define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
950 #define DUK_INTERNAL __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
951 #else
952 #define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) extern
953 #define DUK_INTERNAL __attribute__ ((visibility("hidden")))
954 #endif
955 #endif
956 #define DUK_LOCAL_DECL static
957 #define DUK_LOCAL static
958 #endif
959 
960 #if defined(DUK_F_CPP)
961 #define DUK_USE_COMPILER_STRING "clang"
962 #else
963 #define DUK_USE_COMPILER_STRING "clang"
964 #endif
965 
966 #undef DUK_USE_VARIADIC_MACROS
967 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
968 #define DUK_USE_VARIADIC_MACROS
969 #endif
970 
971 #define DUK_USE_UNION_INITIALIZERS
972 
973 #undef DUK_USE_FLEX_C99
974 #undef DUK_USE_FLEX_ZEROSIZE
975 #undef DUK_USE_FLEX_ONESIZE
976 #if defined(DUK_F_C99)
977 #define DUK_USE_FLEX_C99
978 #else
979 #define DUK_USE_FLEX_ZEROSIZE
980 #endif
981 
982 #undef DUK_USE_GCC_PRAGMAS
983 #define DUK_USE_PACK_CLANG_ATTR
984 #elif defined(DUK_F_GCC)
985 /* --- GCC --- */
986 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
987 /* C99 / C++11 and above: rely on va_copy() which is required. */
988 #define DUK_VA_COPY(dest,src) va_copy(dest,src)
989 #else
990 /* GCC: assume we have __va_copy() in non-C99 mode. */
991 #define DUK_VA_COPY(dest,src) __va_copy(dest,src)
992 #endif
993 
994 #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 20500L)
995 /* since gcc-2.5 */
996 #define DUK_NORETURN(decl) decl __attribute__((noreturn))
997 #endif
998 
999 #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40500L)
1000 /* since gcc-4.5 */
1001 #define DUK_UNREACHABLE() do { __builtin_unreachable(); } while (0)
1002 #endif
1003 
1004 #define DUK_USE_BRANCH_HINTS
1005 #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40500L)
1006 /* GCC: test not very accurate; enable only in relatively recent builds
1007  * because of bugs in gcc-4.4 (http://lists.debian.org/debian-gcc/2010/04/msg00000.html)
1008  */
1009 #define DUK_LIKELY(x) __builtin_expect((x), 1)
1010 #define DUK_UNLIKELY(x) __builtin_expect((x), 0)
1011 #endif
1012 /* XXX: equivalent of clang __builtin_unpredictable? */
1013 
1014 #if (defined(DUK_F_C99) || defined(DUK_F_CPP11)) && \
1015  defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 30101)
1016 #define DUK_NOINLINE __attribute__((noinline))
1017 #define DUK_INLINE inline
1018 #define DUK_ALWAYS_INLINE inline __attribute__((always_inline))
1019 #endif
1020 
1021 #if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
1022 /* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
1023  * compiling Duktape or the application.
1024  */
1025 #if defined(DUK_COMPILING_DUKTAPE)
1026 #define DUK_EXTERNAL_DECL extern __declspec(dllexport)
1027 #define DUK_EXTERNAL __declspec(dllexport)
1028 #else
1029 #define DUK_EXTERNAL_DECL extern __declspec(dllimport)
1030 #define DUK_EXTERNAL should_not_happen
1031 #endif
1032 #if defined(DUK_SINGLE_FILE)
1033 #define DUK_INTERNAL_DECL static
1034 #define DUK_INTERNAL static
1035 #else
1036 #define DUK_INTERNAL_DECL extern
1037 #define DUK_INTERNAL /*empty*/
1038 #endif
1039 #define DUK_LOCAL_DECL static
1040 #define DUK_LOCAL static
1041 #elif defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40000)
1042 #define DUK_EXTERNAL_DECL __attribute__ ((visibility("default"))) extern
1043 #define DUK_EXTERNAL __attribute__ ((visibility("default")))
1044 #if defined(DUK_SINGLE_FILE)
1045 #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
1046 /* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
1047  * Clang. Based on documentation it should suffice to have the attribute
1048  * in the declaration only, but in practice some warnings are generated unless
1049  * the attribute is also applied to the definition.
1050  */
1051 #define DUK_INTERNAL_DECL static __attribute__ ((unused))
1052 #define DUK_INTERNAL static __attribute__ ((unused))
1053 #else
1054 #define DUK_INTERNAL_DECL static
1055 #define DUK_INTERNAL static
1056 #endif
1057 #else
1058 #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
1059 #define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
1060 #define DUK_INTERNAL __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
1061 #else
1062 #define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) extern
1063 #define DUK_INTERNAL __attribute__ ((visibility("hidden")))
1064 #endif
1065 #endif
1066 #define DUK_LOCAL_DECL static
1067 #define DUK_LOCAL static
1068 #endif
1069 
1070 #if defined(DUK_F_MINGW)
1071 #if defined(DUK_F_CPP)
1072 #define DUK_USE_COMPILER_STRING "mingw++"
1073 #else
1074 #define DUK_USE_COMPILER_STRING "mingw"
1075 #endif
1076 #else
1077 #if defined(DUK_F_CPP)
1078 #define DUK_USE_COMPILER_STRING "g++"
1079 #else
1080 #define DUK_USE_COMPILER_STRING "gcc"
1081 #endif
1082 #endif
1083 
1084 #undef DUK_USE_VARIADIC_MACROS
1085 #if defined(DUK_F_C99) || (defined(DUK_F_CPP11) && defined(__GNUC__))
1086 #define DUK_USE_VARIADIC_MACROS
1087 #endif
1088 
1089 #define DUK_USE_UNION_INITIALIZERS
1090 
1091 #undef DUK_USE_FLEX_C99
1092 #undef DUK_USE_FLEX_ZEROSIZE
1093 #undef DUK_USE_FLEX_ONESIZE
1094 #if defined(DUK_F_C99)
1095 #define DUK_USE_FLEX_C99
1096 #else
1097 #define DUK_USE_FLEX_ZEROSIZE
1098 #endif
1099 
1100 #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40600)
1101 #define DUK_USE_GCC_PRAGMAS
1102 #else
1103 #undef DUK_USE_GCC_PRAGMAS
1104 #endif
1105 
1106 #define DUK_USE_PACK_GCC_ATTR
1107 #elif defined(DUK_F_MSVC)
1108 /* --- MSVC --- */
1109 /* http://msdn.microsoft.com/en-us/library/aa235362(VS.60).aspx */
1110 #define DUK_NORETURN(decl) __declspec(noreturn) decl
1111 
1112 /* XXX: DUK_UNREACHABLE for msvc? */
1113 
1114 #undef DUK_USE_BRANCH_HINTS
1115 
1116 /* XXX: DUK_LIKELY, DUK_UNLIKELY for msvc? */
1117 /* XXX: DUK_NOINLINE, DUK_INLINE, DUK_ALWAYS_INLINE for msvc? */
1118 
1119 #if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
1120 /* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
1121  * compiling Duktape or the application.
1122  */
1123 #if defined(DUK_COMPILING_DUKTAPE)
1124 #define DUK_EXTERNAL_DECL extern __declspec(dllexport)
1125 #define DUK_EXTERNAL __declspec(dllexport)
1126 #else
1127 #define DUK_EXTERNAL_DECL extern __declspec(dllimport)
1128 #define DUK_EXTERNAL should_not_happen
1129 #endif
1130 #if defined(DUK_SINGLE_FILE)
1131 #define DUK_INTERNAL_DECL static
1132 #define DUK_INTERNAL static
1133 #else
1134 #define DUK_INTERNAL_DECL extern
1135 #define DUK_INTERNAL /*empty*/
1136 #endif
1137 #define DUK_LOCAL_DECL static
1138 #define DUK_LOCAL static
1139 #endif
1140 
1141 #if defined(DUK_F_CPP)
1142 #define DUK_USE_COMPILER_STRING "msvc++"
1143 #else
1144 #define DUK_USE_COMPILER_STRING "msvc"
1145 #endif
1146 
1147 #undef DUK_USE_VARIADIC_MACROS
1148 #if defined(DUK_F_C99)
1149 #define DUK_USE_VARIADIC_MACROS
1150 #elif defined(_MSC_VER) && (_MSC_VER >= 1400)
1151 /* VS2005+ should have variadic macros even when they're not C99. */
1152 #define DUK_USE_VARIADIC_MACROS
1153 #endif
1154 
1155 #undef DUK_USE_UNION_INITIALIZERS
1156 #if defined(_MSC_VER) && (_MSC_VER >= 1800)
1157 /* VS2013+ supports union initializers but there's a bug involving union-inside-struct:
1158  * https://connect.microsoft.com/VisualStudio/feedback/details/805981
1159  * The bug was fixed (at least) in VS2015 so check for VS2015 for now:
1160  * https://blogs.msdn.microsoft.com/vcblog/2015/07/01/c-compiler-front-end-fixes-in-vs2015/
1161  * Manually tested using VS2013, CL reports 18.00.31101, so enable for VS2013 too.
1162  */
1163 #define DUK_USE_UNION_INITIALIZERS
1164 #endif
1165 
1166 #undef DUK_USE_FLEX_C99
1167 #undef DUK_USE_FLEX_ZEROSIZE
1168 #undef DUK_USE_FLEX_ONESIZE
1169 #if defined(DUK_F_C99)
1170 #define DUK_USE_FLEX_C99
1171 #else
1172 #define DUK_USE_FLEX_ZEROSIZE
1173 #endif
1174 
1175 #undef DUK_USE_GCC_PRAGMAS
1176 
1177 #define DUK_USE_PACK_MSVC_PRAGMA
1178 
1179 /* These have been tested from VS2008 onwards; may work in older VS versions
1180  * too but not enabled by default.
1181  */
1182 #if defined(_MSC_VER) && (_MSC_VER >= 1500)
1183 #define DUK_NOINLINE __declspec(noinline)
1184 #define DUK_INLINE __inline
1185 #define DUK_ALWAYS_INLINE __forceinline
1186 #endif
1187 
1188 #if defined(_MSC_VER) && (_MSC_VER >= 1900)
1189 #define DUK_SNPRINTF snprintf
1190 #define DUK_VSNPRINTF vsnprintf
1191 #else
1192 /* (v)snprintf() is missing before MSVC 2015. Note that _(v)snprintf() does
1193  * NOT NUL terminate on truncation, but Duktape code never assumes that.
1194  * http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
1195  */
1196 #define DUK_SNPRINTF _snprintf
1197 #define DUK_VSNPRINTF _vsnprintf
1198 #endif
1199 
1200 /* Avoid warning when doing DUK_UNREF(some_function). */
1201 #define DUK_UNREF(x) do { __pragma(warning(suppress:4100 4101 4550 4551)) (x); } while (0)
1202 #elif defined(DUK_F_EMSCRIPTEN)
1203 /* --- Emscripten --- */
1204 #define DUK_NORETURN(decl) decl __attribute__((noreturn))
1205 
1206 #if defined(__clang__) && defined(__has_builtin)
1207 #if __has_builtin(__builtin_unreachable)
1208 #define DUK_UNREACHABLE() do { __builtin_unreachable(); } while (0)
1209 #endif
1210 #endif
1211 
1212 #define DUK_USE_BRANCH_HINTS
1213 #define DUK_LIKELY(x) __builtin_expect((x), 1)
1214 #define DUK_UNLIKELY(x) __builtin_expect((x), 0)
1215 #if defined(__clang__) && defined(__has_builtin)
1216 #if __has_builtin(__builtin_unpredictable)
1217 #define DUK_UNPREDICTABLE(x) __builtin_unpredictable((x))
1218 #endif
1219 #endif
1220 
1221 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
1222 #define DUK_NOINLINE __attribute__((noinline))
1223 #define DUK_INLINE inline
1224 #define DUK_ALWAYS_INLINE inline __attribute__((always_inline))
1225 #endif
1226 
1227 #define DUK_EXTERNAL_DECL __attribute__ ((visibility("default"))) extern
1228 #define DUK_EXTERNAL __attribute__ ((visibility("default")))
1229 #if defined(DUK_SINGLE_FILE)
1230 #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
1231 /* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
1232  * Clang. Based on documentation it should suffice to have the attribute
1233  * in the declaration only, but in practice some warnings are generated unless
1234  * the attribute is also applied to the definition.
1235  */
1236 #define DUK_INTERNAL_DECL static __attribute__ ((unused))
1237 #define DUK_INTERNAL static __attribute__ ((unused))
1238 #else
1239 #define DUK_INTERNAL_DECL static
1240 #define DUK_INTERNAL static
1241 #endif
1242 #else
1243 #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
1244 #define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
1245 #define DUK_INTERNAL __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
1246 #else
1247 #define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) extern
1248 #define DUK_INTERNAL __attribute__ ((visibility("hidden")))
1249 #endif
1250 #endif
1251 #define DUK_LOCAL_DECL static
1252 #define DUK_LOCAL static
1253 
1254 #define DUK_USE_COMPILER_STRING "emscripten"
1255 
1256 #undef DUK_USE_VARIADIC_MACROS
1257 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
1258 #define DUK_USE_VARIADIC_MACROS
1259 #endif
1260 
1261 #define DUK_USE_UNION_INITIALIZERS
1262 
1263 #undef DUK_USE_FLEX_C99
1264 #undef DUK_USE_FLEX_ZEROSIZE
1265 #undef DUK_USE_FLEX_ONESIZE
1266 #if defined(DUK_F_C99)
1267 #define DUK_USE_FLEX_C99
1268 #else
1269 #define DUK_USE_FLEX_ZEROSIZE
1270 #endif
1271 
1272 #undef DUK_USE_GCC_PRAGMAS
1273 #define DUK_USE_PACK_CLANG_ATTR
1274 #elif defined(DUK_F_TINYC)
1275 /* --- TinyC --- */
1276 #undef DUK_USE_BRANCH_HINTS
1277 
1278 #if defined(DUK_F_CPP)
1279 #define DUK_USE_COMPILER_STRING "tinyc++"
1280 #else
1281 #define DUK_USE_COMPILER_STRING "tinyc"
1282 #endif
1283 
1284 /* http://bellard.org/tcc/tcc-doc.html#SEC7 */
1285 #define DUK_USE_VARIADIC_MACROS
1286 
1287 #define DUK_USE_UNION_INITIALIZERS
1288 
1289 /* Most portable, wastes space */
1290 #define DUK_USE_FLEX_ONESIZE
1291 
1292 /* Most portable, potentially wastes space */
1293 #define DUK_USE_PACK_DUMMY_MEMBER
1294 #elif defined(DUK_F_VBCC)
1295 /* --- VBCC --- */
1296 #undef DUK_USE_BRANCH_HINTS
1297 
1298 #if defined(DUK_F_CPP)
1299 #define DUK_USE_COMPILER_STRING "vbcc-c++"
1300 #else
1301 #define DUK_USE_COMPILER_STRING "vbcc"
1302 #endif
1303 
1304 #undef DUK_USE_VARIADIC_MACROS
1305 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
1306 #define DUK_USE_VARIADIC_MACROS
1307 #endif
1308 
1309 /* VBCC supports C99 so check only for C99 for union initializer support.
1310  * Designated union initializers would possibly work even without a C99 check.
1311  */
1312 #undef DUK_USE_UNION_INITIALIZERS
1313 #if defined(DUK_F_C99)
1314 #define DUK_USE_UNION_INITIALIZERS
1315 #endif
1316 
1317 #define DUK_USE_FLEX_ZEROSIZE
1318 #define DUK_USE_PACK_DUMMY_MEMBER
1319 #elif defined(DUK_F_BCC)
1320 /* --- Bruce's C compiler --- */
1321 #undef DUK_USE_BRANCH_HINTS
1322 
1323 #if defined(DUK_F_CPP)
1324 #define DUK_USE_COMPILER_STRING "bcc++"
1325 #else
1326 #define DUK_USE_COMPILER_STRING "bcc"
1327 #endif
1328 
1329 /* Most portable */
1330 #undef DUK_USE_VARIADIC_MACROS
1331 
1332 /* Most portable, wastes space */
1333 #undef DUK_USE_UNION_INITIALIZERS
1334 
1335 /* Most portable, wastes space */
1336 #define DUK_USE_FLEX_ONESIZE
1337 
1338 /* Most portable, potentially wastes space */
1339 #define DUK_USE_PACK_DUMMY_MEMBER
1340 
1341 /* BCC, assume we're on x86. */
1342 #if !defined(DUK_USE_BYTEORDER)
1343 #define DUK_USE_BYTEORDER 1
1344 #endif
1345 #else
1346 /* --- Generic --- */
1347 #undef DUK_USE_BRANCH_HINTS
1348 
1349 #if defined(DUK_F_CPP)
1350 #define DUK_USE_COMPILER_STRING "generic-c++"
1351 #else
1352 #define DUK_USE_COMPILER_STRING "generic"
1353 #endif
1354 
1355 #undef DUK_USE_VARIADIC_MACROS
1356 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
1357 #define DUK_USE_VARIADIC_MACROS
1358 #endif
1359 
1360 /* C++ doesn't have standard designated union initializers ({ .foo = 1 }). */
1361 #undef DUK_USE_UNION_INITIALIZERS
1362 #if defined(DUK_F_C99)
1363 #define DUK_USE_UNION_INITIALIZERS
1364 #endif
1365 
1366 /* Most portable, wastes space */
1367 #define DUK_USE_FLEX_ONESIZE
1368 
1369 /* Most portable, potentially wastes space */
1370 #define DUK_USE_PACK_DUMMY_MEMBER
1371 #endif /* autodetect compiler */
1372 
1373 /* uclibc */
1374 #if defined(__UCLIBC__)
1375 #define DUK_F_UCLIBC
1376 #endif
1377 
1378 /*
1379  * Wrapper typedefs and constants for integer types, also sanity check types.
1380  *
1381  * C99 typedefs are quite good but not always available, and we want to avoid
1382  * forcibly redefining the C99 typedefs. So, there are Duktape wrappers for
1383  * all C99 typedefs and Duktape code should only use these typedefs. Type
1384  * detection when C99 is not supported is best effort and may end up detecting
1385  * some types incorrectly.
1386  *
1387  * Pointer sizes are a portability problem: pointers to different types may
1388  * have a different size and function pointers are very difficult to manage
1389  * portably.
1390  *
1391  * http://en.wikipedia.org/wiki/C_data_types#Fixed-width_integer_types
1392  *
1393  * Note: there's an interesting corner case when trying to define minimum
1394  * signed integer value constants which leads to the current workaround of
1395  * defining e.g. -0x80000000 as (-0x7fffffffL - 1L). See doc/code-issues.txt
1396  * for a longer discussion.
1397  *
1398  * Note: avoid typecasts and computations in macro integer constants as they
1399  * can then no longer be used in macro relational expressions (such as
1400  * #if DUK_SIZE_MAX < 0xffffffffUL). There is internal code which relies on
1401  * being able to compare DUK_SIZE_MAX against a limit.
1402  */
1403 
1404 /* XXX: add feature options to force basic types from outside? */
1405 
1406 #if !defined(INT_MAX)
1407 #error INT_MAX not defined
1408 #endif
1409 
1410 /* Check that architecture is two's complement, standard C allows e.g.
1411  * INT_MIN to be -2**31+1 (instead of -2**31).
1412  */
1413 #if defined(INT_MAX) && defined(INT_MIN)
1414 #if INT_MAX != -(INT_MIN + 1)
1415 #error platform does not seem complement of two
1416 #endif
1417 #else
1418 #error cannot check complement of two
1419 #endif
1420 
1421 /* Pointer size determination based on __WORDSIZE or architecture when
1422  * that's not available.
1423  */
1424 #if defined(DUK_F_X86) || defined(DUK_F_X32) || \
1425  defined(DUK_F_M68K) || defined(DUK_F_PPC32) || \
1426  defined(DUK_F_BCC) || \
1427  (defined(__WORDSIZE) && (__WORDSIZE == 32))
1428 #define DUK_F_32BIT_PTRS
1429 #elif defined(DUK_F_X64) || \
1430  (defined(__WORDSIZE) && (__WORDSIZE == 64))
1431 #define DUK_F_64BIT_PTRS
1432 #else
1433 /* not sure, not needed with C99 anyway */
1434 #endif
1435 
1436 /* Intermediate define for 'have inttypes.h' */
1437 #undef DUK_F_HAVE_INTTYPES
1438 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
1439  !(defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC))
1440 /* vbcc + AmigaOS has C99 but no inttypes.h */
1441 #define DUK_F_HAVE_INTTYPES
1442 #elif defined(__cplusplus) && (__cplusplus >= 201103L)
1443 /* C++11 apparently ratified stdint.h */
1444 #define DUK_F_HAVE_INTTYPES
1445 #endif
1446 
1447 /* Basic integer typedefs and limits, preferably from inttypes.h, otherwise
1448  * through automatic detection.
1449  */
1450 #if defined(DUK_F_HAVE_INTTYPES)
1451 /* C99 or compatible */
1452 
1453 #define DUK_F_HAVE_64BIT
1454 #include <inttypes.h>
1455 
1456 typedef uint8_t duk_uint8_t;
1457 typedef int8_t duk_int8_t;
1458 typedef uint16_t duk_uint16_t;
1459 typedef int16_t duk_int16_t;
1460 typedef uint32_t duk_uint32_t;
1461 typedef int32_t duk_int32_t;
1462 typedef uint64_t duk_uint64_t;
1463 typedef int64_t duk_int64_t;
1464 typedef uint_least8_t duk_uint_least8_t;
1465 typedef int_least8_t duk_int_least8_t;
1466 typedef uint_least16_t duk_uint_least16_t;
1467 typedef int_least16_t duk_int_least16_t;
1468 typedef uint_least32_t duk_uint_least32_t;
1469 typedef int_least32_t duk_int_least32_t;
1470 typedef uint_least64_t duk_uint_least64_t;
1471 typedef int_least64_t duk_int_least64_t;
1472 typedef uint_fast8_t duk_uint_fast8_t;
1473 typedef int_fast8_t duk_int_fast8_t;
1474 typedef uint_fast16_t duk_uint_fast16_t;
1475 typedef int_fast16_t duk_int_fast16_t;
1476 typedef uint_fast32_t duk_uint_fast32_t;
1477 typedef int_fast32_t duk_int_fast32_t;
1478 typedef uint_fast64_t duk_uint_fast64_t;
1479 typedef int_fast64_t duk_int_fast64_t;
1480 typedef uintptr_t duk_uintptr_t;
1481 typedef intptr_t duk_intptr_t;
1482 typedef uintmax_t duk_uintmax_t;
1483 typedef intmax_t duk_intmax_t;
1484 
1485 #define DUK_UINT8_MIN 0
1486 #define DUK_UINT8_MAX UINT8_MAX
1487 #define DUK_INT8_MIN INT8_MIN
1488 #define DUK_INT8_MAX INT8_MAX
1489 #define DUK_UINT_LEAST8_MIN 0
1490 #define DUK_UINT_LEAST8_MAX UINT_LEAST8_MAX
1491 #define DUK_INT_LEAST8_MIN INT_LEAST8_MIN
1492 #define DUK_INT_LEAST8_MAX INT_LEAST8_MAX
1493 #define DUK_UINT_FAST8_MIN 0
1494 #define DUK_UINT_FAST8_MAX UINT_FAST8_MAX
1495 #define DUK_INT_FAST8_MIN INT_FAST8_MIN
1496 #define DUK_INT_FAST8_MAX INT_FAST8_MAX
1497 #define DUK_UINT16_MIN 0
1498 #define DUK_UINT16_MAX UINT16_MAX
1499 #define DUK_INT16_MIN INT16_MIN
1500 #define DUK_INT16_MAX INT16_MAX
1501 #define DUK_UINT_LEAST16_MIN 0
1502 #define DUK_UINT_LEAST16_MAX UINT_LEAST16_MAX
1503 #define DUK_INT_LEAST16_MIN INT_LEAST16_MIN
1504 #define DUK_INT_LEAST16_MAX INT_LEAST16_MAX
1505 #define DUK_UINT_FAST16_MIN 0
1506 #define DUK_UINT_FAST16_MAX UINT_FAST16_MAX
1507 #define DUK_INT_FAST16_MIN INT_FAST16_MIN
1508 #define DUK_INT_FAST16_MAX INT_FAST16_MAX
1509 #define DUK_UINT32_MIN 0
1510 #define DUK_UINT32_MAX UINT32_MAX
1511 #define DUK_INT32_MIN INT32_MIN
1512 #define DUK_INT32_MAX INT32_MAX
1513 #define DUK_UINT_LEAST32_MIN 0
1514 #define DUK_UINT_LEAST32_MAX UINT_LEAST32_MAX
1515 #define DUK_INT_LEAST32_MIN INT_LEAST32_MIN
1516 #define DUK_INT_LEAST32_MAX INT_LEAST32_MAX
1517 #define DUK_UINT_FAST32_MIN 0
1518 #define DUK_UINT_FAST32_MAX UINT_FAST32_MAX
1519 #define DUK_INT_FAST32_MIN INT_FAST32_MIN
1520 #define DUK_INT_FAST32_MAX INT_FAST32_MAX
1521 #define DUK_UINT64_MIN 0
1522 #define DUK_UINT64_MAX UINT64_MAX
1523 #define DUK_INT64_MIN INT64_MIN
1524 #define DUK_INT64_MAX INT64_MAX
1525 #define DUK_UINT_LEAST64_MIN 0
1526 #define DUK_UINT_LEAST64_MAX UINT_LEAST64_MAX
1527 #define DUK_INT_LEAST64_MIN INT_LEAST64_MIN
1528 #define DUK_INT_LEAST64_MAX INT_LEAST64_MAX
1529 #define DUK_UINT_FAST64_MIN 0
1530 #define DUK_UINT_FAST64_MAX UINT_FAST64_MAX
1531 #define DUK_INT_FAST64_MIN INT_FAST64_MIN
1532 #define DUK_INT_FAST64_MAX INT_FAST64_MAX
1533 
1534 #define DUK_UINTPTR_MIN 0
1535 #define DUK_UINTPTR_MAX UINTPTR_MAX
1536 #define DUK_INTPTR_MIN INTPTR_MIN
1537 #define DUK_INTPTR_MAX INTPTR_MAX
1538 
1539 #define DUK_UINTMAX_MIN 0
1540 #define DUK_UINTMAX_MAX UINTMAX_MAX
1541 #define DUK_INTMAX_MIN INTMAX_MIN
1542 #define DUK_INTMAX_MAX INTMAX_MAX
1543 
1544 #define DUK_SIZE_MIN 0
1545 #define DUK_SIZE_MAX SIZE_MAX
1546 #undef DUK_SIZE_MAX_COMPUTED
1547 
1548 #else /* C99 types */
1549 
1550 /* When C99 types are not available, we use heuristic detection to get
1551  * the basic 8, 16, 32, and (possibly) 64 bit types. The fast/least
1552  * types are then assumed to be exactly the same for now: these could
1553  * be improved per platform but C99 types are very often now available.
1554  * 64-bit types are not available on all platforms; this is OK at least
1555  * on 32-bit platforms.
1556  *
1557  * This detection code is necessarily a bit hacky and can provide typedefs
1558  * and defines that won't work correctly on some exotic platform.
1559  */
1560 
1561 #if (defined(CHAR_BIT) && (CHAR_BIT == 8)) || \
1562  (defined(UCHAR_MAX) && (UCHAR_MAX == 255))
1563 typedef unsigned char duk_uint8_t;
1564 typedef signed char duk_int8_t;
1565 #else
1566 #error cannot detect 8-bit type
1567 #endif
1568 
1569 #if defined(USHRT_MAX) && (USHRT_MAX == 65535UL)
1570 typedef unsigned short duk_uint16_t;
1571 typedef signed short duk_int16_t;
1572 #elif defined(UINT_MAX) && (UINT_MAX == 65535UL)
1573 /* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */
1574 typedef unsigned int duk_uint16_t;
1575 typedef signed int duk_int16_t;
1576 #else
1577 #error cannot detect 16-bit type
1578 #endif
1579 
1580 #if defined(UINT_MAX) && (UINT_MAX == 4294967295UL)
1581 typedef unsigned int duk_uint32_t;
1582 typedef signed int duk_int32_t;
1583 #elif defined(ULONG_MAX) && (ULONG_MAX == 4294967295UL)
1584 /* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */
1585 typedef unsigned long duk_uint32_t;
1586 typedef signed long duk_int32_t;
1587 #else
1588 #error cannot detect 32-bit type
1589 #endif
1590 
1591 /* 64-bit type detection is a bit tricky.
1592  *
1593  * ULLONG_MAX is a standard define. __LONG_LONG_MAX__ and __ULONG_LONG_MAX__
1594  * are used by at least GCC (even if system headers don't provide ULLONG_MAX).
1595  * Some GCC variants may provide __LONG_LONG_MAX__ but not __ULONG_LONG_MAX__.
1596  *
1597  * ULL / LL constants are rejected / warned about by some compilers, even if
1598  * the compiler has a 64-bit type and the compiler/system headers provide an
1599  * unsupported constant (ULL/LL)! Try to avoid using ULL / LL constants.
1600  * As a side effect we can only check that e.g. ULONG_MAX is larger than 32
1601  * bits but can't be sure it is exactly 64 bits. Self tests will catch such
1602  * cases.
1603  */
1604 #undef DUK_F_HAVE_64BIT
1605 #if !defined(DUK_F_HAVE_64BIT) && defined(ULONG_MAX)
1606 #if (ULONG_MAX > 4294967295UL)
1607 #define DUK_F_HAVE_64BIT
1608 typedef unsigned long duk_uint64_t;
1609 typedef signed long duk_int64_t;
1610 #endif
1611 #endif
1612 #if !defined(DUK_F_HAVE_64BIT) && defined(ULLONG_MAX)
1613 #if (ULLONG_MAX > 4294967295UL)
1614 #define DUK_F_HAVE_64BIT
1615 typedef unsigned long long duk_uint64_t;
1616 typedef signed long long duk_int64_t;
1617 #endif
1618 #endif
1619 #if !defined(DUK_F_HAVE_64BIT) && defined(__ULONG_LONG_MAX__)
1620 #if (__ULONG_LONG_MAX__ > 4294967295UL)
1621 #define DUK_F_HAVE_64BIT
1622 typedef unsigned long long duk_uint64_t;
1623 typedef signed long long duk_int64_t;
1624 #endif
1625 #endif
1626 #if !defined(DUK_F_HAVE_64BIT) && defined(__LONG_LONG_MAX__)
1627 #if (__LONG_LONG_MAX__ > 2147483647L)
1628 #define DUK_F_HAVE_64BIT
1629 typedef unsigned long long duk_uint64_t;
1630 typedef signed long long duk_int64_t;
1631 #endif
1632 #endif
1633 #if !defined(DUK_F_HAVE_64BIT) && \
1634  (defined(DUK_F_MINGW) || defined(DUK_F_MSVC))
1635 /* Both MinGW and MSVC have a 64-bit type. */
1636 #define DUK_F_HAVE_64BIT
1637 typedef unsigned long duk_uint64_t;
1638 typedef signed long duk_int64_t;
1639 #endif
1640 #if !defined(DUK_F_HAVE_64BIT)
1641 /* cannot detect 64-bit type, not always needed so don't error */
1642 #endif
1643 
1644 typedef duk_uint8_t duk_uint_least8_t;
1645 typedef duk_int8_t duk_int_least8_t;
1646 typedef duk_uint16_t duk_uint_least16_t;
1647 typedef duk_int16_t duk_int_least16_t;
1648 typedef duk_uint32_t duk_uint_least32_t;
1649 typedef duk_int32_t duk_int_least32_t;
1650 typedef duk_uint8_t duk_uint_fast8_t;
1651 typedef duk_int8_t duk_int_fast8_t;
1652 typedef duk_uint16_t duk_uint_fast16_t;
1653 typedef duk_int16_t duk_int_fast16_t;
1654 typedef duk_uint32_t duk_uint_fast32_t;
1655 typedef duk_int32_t duk_int_fast32_t;
1656 #if defined(DUK_F_HAVE_64BIT)
1657 typedef duk_uint64_t duk_uint_least64_t;
1658 typedef duk_int64_t duk_int_least64_t;
1659 typedef duk_uint64_t duk_uint_fast64_t;
1660 typedef duk_int64_t duk_int_fast64_t;
1661 #endif
1662 #if defined(DUK_F_HAVE_64BIT)
1663 typedef duk_uint64_t duk_uintmax_t;
1664 typedef duk_int64_t duk_intmax_t;
1665 #else
1666 typedef duk_uint32_t duk_uintmax_t;
1667 typedef duk_int32_t duk_intmax_t;
1668 #endif
1669 
1670 /* Note: the funny looking computations for signed minimum 16-bit, 32-bit, and
1671  * 64-bit values are intentional as the obvious forms (e.g. -0x80000000L) are
1672  * -not- portable. See code-issues.txt for a detailed discussion.
1673  */
1674 #define DUK_UINT8_MIN 0UL
1675 #define DUK_UINT8_MAX 0xffUL
1676 #define DUK_INT8_MIN (-0x80L)
1677 #define DUK_INT8_MAX 0x7fL
1678 #define DUK_UINT_LEAST8_MIN 0UL
1679 #define DUK_UINT_LEAST8_MAX 0xffUL
1680 #define DUK_INT_LEAST8_MIN (-0x80L)
1681 #define DUK_INT_LEAST8_MAX 0x7fL
1682 #define DUK_UINT_FAST8_MIN 0UL
1683 #define DUK_UINT_FAST8_MAX 0xffUL
1684 #define DUK_INT_FAST8_MIN (-0x80L)
1685 #define DUK_INT_FAST8_MAX 0x7fL
1686 #define DUK_UINT16_MIN 0UL
1687 #define DUK_UINT16_MAX 0xffffUL
1688 #define DUK_INT16_MIN (-0x7fffL - 1L)
1689 #define DUK_INT16_MAX 0x7fffL
1690 #define DUK_UINT_LEAST16_MIN 0UL
1691 #define DUK_UINT_LEAST16_MAX 0xffffUL
1692 #define DUK_INT_LEAST16_MIN (-0x7fffL - 1L)
1693 #define DUK_INT_LEAST16_MAX 0x7fffL
1694 #define DUK_UINT_FAST16_MIN 0UL
1695 #define DUK_UINT_FAST16_MAX 0xffffUL
1696 #define DUK_INT_FAST16_MIN (-0x7fffL - 1L)
1697 #define DUK_INT_FAST16_MAX 0x7fffL
1698 #define DUK_UINT32_MIN 0UL
1699 #define DUK_UINT32_MAX 0xffffffffUL
1700 #define DUK_INT32_MIN (-0x7fffffffL - 1L)
1701 #define DUK_INT32_MAX 0x7fffffffL
1702 #define DUK_UINT_LEAST32_MIN 0UL
1703 #define DUK_UINT_LEAST32_MAX 0xffffffffUL
1704 #define DUK_INT_LEAST32_MIN (-0x7fffffffL - 1L)
1705 #define DUK_INT_LEAST32_MAX 0x7fffffffL
1706 #define DUK_UINT_FAST32_MIN 0UL
1707 #define DUK_UINT_FAST32_MAX 0xffffffffUL
1708 #define DUK_INT_FAST32_MIN (-0x7fffffffL - 1L)
1709 #define DUK_INT_FAST32_MAX 0x7fffffffL
1710 
1711 /* 64-bit constants. Since LL / ULL constants are not always available,
1712  * use computed values. These values can't be used in preprocessor
1713  * comparisons; flag them as such.
1714  */
1715 #if defined(DUK_F_HAVE_64BIT)
1716 #define DUK_UINT64_MIN ((duk_uint64_t) 0)
1717 #define DUK_UINT64_MAX ((duk_uint64_t) -1)
1718 #define DUK_INT64_MIN ((duk_int64_t) (~(DUK_UINT64_MAX >> 1)))
1719 #define DUK_INT64_MAX ((duk_int64_t) (DUK_UINT64_MAX >> 1))
1720 #define DUK_UINT_LEAST64_MIN DUK_UINT64_MIN
1721 #define DUK_UINT_LEAST64_MAX DUK_UINT64_MAX
1722 #define DUK_INT_LEAST64_MIN DUK_INT64_MIN
1723 #define DUK_INT_LEAST64_MAX DUK_INT64_MAX
1724 #define DUK_UINT_FAST64_MIN DUK_UINT64_MIN
1725 #define DUK_UINT_FAST64_MAX DUK_UINT64_MAX
1726 #define DUK_INT_FAST64_MIN DUK_INT64_MIN
1727 #define DUK_INT_FAST64_MAX DUK_INT64_MAX
1728 #define DUK_UINT64_MIN_COMPUTED
1729 #define DUK_UINT64_MAX_COMPUTED
1730 #define DUK_INT64_MIN_COMPUTED
1731 #define DUK_INT64_MAX_COMPUTED
1732 #define DUK_UINT_LEAST64_MIN_COMPUTED
1733 #define DUK_UINT_LEAST64_MAX_COMPUTED
1734 #define DUK_INT_LEAST64_MIN_COMPUTED
1735 #define DUK_INT_LEAST64_MAX_COMPUTED
1736 #define DUK_UINT_FAST64_MIN_COMPUTED
1737 #define DUK_UINT_FAST64_MAX_COMPUTED
1738 #define DUK_INT_FAST64_MIN_COMPUTED
1739 #define DUK_INT_FAST64_MAX_COMPUTED
1740 #endif
1741 
1742 #if defined(DUK_F_HAVE_64BIT)
1743 #define DUK_UINTMAX_MIN DUK_UINT64_MIN
1744 #define DUK_UINTMAX_MAX DUK_UINT64_MAX
1745 #define DUK_INTMAX_MIN DUK_INT64_MIN
1746 #define DUK_INTMAX_MAX DUK_INT64_MAX
1747 #define DUK_UINTMAX_MIN_COMPUTED
1748 #define DUK_UINTMAX_MAX_COMPUTED
1749 #define DUK_INTMAX_MIN_COMPUTED
1750 #define DUK_INTMAX_MAX_COMPUTED
1751 #else
1752 #define DUK_UINTMAX_MIN 0UL
1753 #define DUK_UINTMAX_MAX 0xffffffffUL
1754 #define DUK_INTMAX_MIN (-0x7fffffffL - 1L)
1755 #define DUK_INTMAX_MAX 0x7fffffffL
1756 #endif
1757 
1758 /* This detection is not very reliable. */
1759 #if defined(DUK_F_32BIT_PTRS)
1760 typedef duk_int32_t duk_intptr_t;
1761 typedef duk_uint32_t duk_uintptr_t;
1762 #define DUK_UINTPTR_MIN DUK_UINT32_MIN
1763 #define DUK_UINTPTR_MAX DUK_UINT32_MAX
1764 #define DUK_INTPTR_MIN DUK_INT32_MIN
1765 #define DUK_INTPTR_MAX DUK_INT32_MAX
1766 #elif defined(DUK_F_64BIT_PTRS) && defined(DUK_F_HAVE_64BIT)
1767 typedef duk_int64_t duk_intptr_t;
1768 typedef duk_uint64_t duk_uintptr_t;
1769 #define DUK_UINTPTR_MIN DUK_UINT64_MIN
1770 #define DUK_UINTPTR_MAX DUK_UINT64_MAX
1771 #define DUK_INTPTR_MIN DUK_INT64_MIN
1772 #define DUK_INTPTR_MAX DUK_INT64_MAX
1773 #define DUK_UINTPTR_MIN_COMPUTED
1774 #define DUK_UINTPTR_MAX_COMPUTED
1775 #define DUK_INTPTR_MIN_COMPUTED
1776 #define DUK_INTPTR_MAX_COMPUTED
1777 #else
1778 #error cannot determine intptr type
1779 #endif
1780 
1781 /* SIZE_MAX may be missing so use an approximate value for it. */
1782 #undef DUK_SIZE_MAX_COMPUTED
1783 #if !defined(SIZE_MAX)
1784 #define DUK_SIZE_MAX_COMPUTED
1785 #define SIZE_MAX ((size_t) (-1))
1786 #endif
1787 #define DUK_SIZE_MIN 0
1788 #define DUK_SIZE_MAX SIZE_MAX
1789 
1790 #endif /* C99 types */
1791 
1792 /* A few types are assumed to always exist. */
1793 typedef size_t duk_size_t;
1794 typedef ptrdiff_t duk_ptrdiff_t;
1795 
1796 /* The best type for an "all around int" in Duktape internals is "at least
1797  * 32 bit signed integer" which is most convenient. Same for unsigned type.
1798  * Prefer 'int' when large enough, as it is almost always a convenient type.
1799  */
1800 #if defined(UINT_MAX) && (UINT_MAX >= 0xffffffffUL)
1801 typedef int duk_int_t;
1802 typedef unsigned int duk_uint_t;
1803 #define DUK_INT_MIN INT_MIN
1804 #define DUK_INT_MAX INT_MAX
1805 #define DUK_UINT_MIN 0
1806 #define DUK_UINT_MAX UINT_MAX
1807 #else
1808 typedef duk_int_fast32_t duk_int_t;
1809 typedef duk_uint_fast32_t duk_uint_t;
1810 #define DUK_INT_MIN DUK_INT_FAST32_MIN
1811 #define DUK_INT_MAX DUK_INT_FAST32_MAX
1812 #define DUK_UINT_MIN DUK_UINT_FAST32_MIN
1813 #define DUK_UINT_MAX DUK_UINT_FAST32_MAX
1814 #endif
1815 
1816 /* Same as 'duk_int_t' but guaranteed to be a 'fast' variant if this
1817  * distinction matters for the CPU. These types are used mainly in the
1818  * executor where it might really matter.
1819  */
1820 typedef duk_int_fast32_t duk_int_fast_t;
1821 typedef duk_uint_fast32_t duk_uint_fast_t;
1822 #define DUK_INT_FAST_MIN DUK_INT_FAST32_MIN
1823 #define DUK_INT_FAST_MAX DUK_INT_FAST32_MAX
1824 #define DUK_UINT_FAST_MIN DUK_UINT_FAST32_MIN
1825 #define DUK_UINT_FAST_MAX DUK_UINT_FAST32_MAX
1826 
1827 /* Small integers (16 bits or more) can fall back to the 'int' type, but
1828  * have a typedef so they are marked "small" explicitly.
1829  */
1830 typedef int duk_small_int_t;
1831 typedef unsigned int duk_small_uint_t;
1832 #define DUK_SMALL_INT_MIN INT_MIN
1833 #define DUK_SMALL_INT_MAX INT_MAX
1834 #define DUK_SMALL_UINT_MIN 0
1835 #define DUK_SMALL_UINT_MAX UINT_MAX
1836 
1837 /* Fast variants of small integers, again for really fast paths like the
1838  * executor.
1839  */
1840 typedef duk_int_fast16_t duk_small_int_fast_t;
1841 typedef duk_uint_fast16_t duk_small_uint_fast_t;
1842 #define DUK_SMALL_INT_FAST_MIN DUK_INT_FAST16_MIN
1843 #define DUK_SMALL_INT_FAST_MAX DUK_INT_FAST16_MAX
1844 #define DUK_SMALL_UINT_FAST_MIN DUK_UINT_FAST16_MIN
1845 #define DUK_SMALL_UINT_FAST_MAX DUK_UINT_FAST16_MAX
1846 
1847 /* Boolean values are represented with the platform 'int'. */
1848 typedef duk_small_int_t duk_bool_t;
1849 #define DUK_BOOL_MIN DUK_SMALL_INT_MIN
1850 #define DUK_BOOL_MAX DUK_SMALL_INT_MAX
1851 
1852 /* Index values must have at least 32-bit signed range. */
1853 typedef duk_int_t duk_idx_t;
1854 #define DUK_IDX_MIN DUK_INT_MIN
1855 #define DUK_IDX_MAX DUK_INT_MAX
1856 
1857 /* Unsigned index variant. */
1858 typedef duk_uint_t duk_uidx_t;
1859 #define DUK_UIDX_MIN DUK_UINT_MIN
1860 #define DUK_UIDX_MAX DUK_UINT_MAX
1861 
1862 /* Array index values, could be exact 32 bits.
1863  * Currently no need for signed duk_arridx_t.
1864  */
1865 typedef duk_uint_t duk_uarridx_t;
1866 #define DUK_UARRIDX_MIN DUK_UINT_MIN
1867 #define DUK_UARRIDX_MAX DUK_UINT_MAX
1868 
1869 /* Duktape/C function return value, platform int is enough for now to
1870  * represent 0, 1, or negative error code. Must be compatible with
1871  * assigning truth values (e.g. duk_ret_t rc = (foo == bar);).
1872  */
1873 typedef duk_small_int_t duk_ret_t;
1874 #define DUK_RET_MIN DUK_SMALL_INT_MIN
1875 #define DUK_RET_MAX DUK_SMALL_INT_MAX
1876 
1877 /* Error codes are represented with platform int. High bits are used
1878  * for flags and such, so 32 bits are needed.
1879  */
1880 typedef duk_int_t duk_errcode_t;
1881 #define DUK_ERRCODE_MIN DUK_INT_MIN
1882 #define DUK_ERRCODE_MAX DUK_INT_MAX
1883 
1884 /* Codepoint type. Must be 32 bits or more because it is used also for
1885  * internal codepoints. The type is signed because negative codepoints
1886  * are used as internal markers (e.g. to mark EOF or missing argument).
1887  * (X)UTF-8/CESU-8 encode/decode take and return an unsigned variant to
1888  * ensure duk_uint32_t casts back and forth nicely. Almost everything
1889  * else uses the signed one.
1890  */
1891 typedef duk_int_t duk_codepoint_t;
1892 typedef duk_uint_t duk_ucodepoint_t;
1893 #define DUK_CODEPOINT_MIN DUK_INT_MIN
1894 #define DUK_CODEPOINT_MAX DUK_INT_MAX
1895 #define DUK_UCODEPOINT_MIN DUK_UINT_MIN
1896 #define DUK_UCODEPOINT_MAX DUK_UINT_MAX
1897 
1898 /* IEEE float/double typedef. */
1899 typedef float duk_float_t;
1900 typedef double duk_double_t;
1901 
1902 /* We're generally assuming that we're working on a platform with a 32-bit
1903  * address space. If DUK_SIZE_MAX is a typecast value (which is necessary
1904  * if SIZE_MAX is missing), the check must be avoided because the
1905  * preprocessor can't do a comparison.
1906  */
1907 #if !defined(DUK_SIZE_MAX)
1908 #error DUK_SIZE_MAX is undefined, probably missing SIZE_MAX
1909 #elif !defined(DUK_SIZE_MAX_COMPUTED)
1910 #if DUK_SIZE_MAX < 0xffffffffUL
1911 /* On some systems SIZE_MAX can be smaller than max unsigned 32-bit value
1912  * which seems incorrect if size_t is (at least) an unsigned 32-bit type.
1913  * However, it doesn't seem useful to error out compilation if this is the
1914  * case.
1915  */
1916 #endif
1917 #endif
1918 
1919 /* Type for public API calls. */
1920 typedef struct duk_hthread duk_context;
1921 
1922 /* Check whether we should use 64-bit integers or not.
1923  *
1924  * Quite incomplete now. Use 64-bit types if detected (C99 or other detection)
1925  * unless they are known to be unreliable. For instance, 64-bit types are
1926  * available on VBCC but seem to misbehave.
1927  */
1928 #if defined(DUK_F_HAVE_64BIT) && !defined(DUK_F_VBCC)
1929 #define DUK_USE_64BIT_OPS
1930 #else
1931 #undef DUK_USE_64BIT_OPS
1932 #endif
1933 
1934 /*
1935  * Fill-ins for platform, architecture, and compiler
1936  */
1937 
1938 /* An abort()-like primitive is needed by the default fatal error handler. */
1939 #if !defined(DUK_ABORT)
1940 #define DUK_ABORT abort
1941 #endif
1942 
1943 #if !defined(DUK_SETJMP)
1944 #define DUK_JMPBUF_TYPE jmp_buf
1945 #define DUK_SETJMP(jb) setjmp((jb))
1946 #define DUK_LONGJMP(jb) longjmp((jb), 1)
1947 #endif
1948 
1949 #if 0
1950 /* sigsetjmp() alternative */
1951 #define DUK_JMPBUF_TYPE sigjmp_buf
1952 #define DUK_SETJMP(jb) sigsetjmp((jb))
1953 #define DUK_LONGJMP(jb) siglongjmp((jb), 1)
1954 #endif
1955 
1956 /* Special naming to avoid conflict with e.g. DUK_FREE() in duk_heap.h
1957  * (which is unfortunately named). May sometimes need replacement, e.g.
1958  * some compilers don't handle zero length or NULL correctly in realloc().
1959  */
1960 #if !defined(DUK_ANSI_MALLOC)
1961 #define DUK_ANSI_MALLOC malloc
1962 #endif
1963 #if !defined(DUK_ANSI_REALLOC)
1964 #define DUK_ANSI_REALLOC realloc
1965 #endif
1966 #if !defined(DUK_ANSI_CALLOC)
1967 #define DUK_ANSI_CALLOC calloc
1968 #endif
1969 #if !defined(DUK_ANSI_FREE)
1970 #define DUK_ANSI_FREE free
1971 #endif
1972 
1973 /* ANSI C (various versions) and some implementations require that the
1974  * pointer arguments to memset(), memcpy(), and memmove() be valid values
1975  * even when byte size is 0 (even a NULL pointer is considered invalid in
1976  * this context). Zero-size operations as such are allowed, as long as their
1977  * pointer arguments point to a valid memory area. The DUK_MEMSET(),
1978  * DUK_MEMCPY(), and DUK_MEMMOVE() macros require this same behavior, i.e.:
1979  * (1) pointers must be valid and non-NULL, (2) zero size must otherwise be
1980  * allowed. If these are not fulfilled, a macro wrapper is needed.
1981  *
1982  * http://stackoverflow.com/questions/5243012/is-it-guaranteed-to-be-safe-to-perform-memcpy0-0-0
1983  * http://lists.cs.uiuc.edu/pipermail/llvmdev/2007-October/011065.html
1984  *
1985  * Not sure what's the required behavior when a pointer points just past the
1986  * end of a buffer, which often happens in practice (e.g. zero size memmoves).
1987  * For example, if allocation size is 3, the following pointer would not
1988  * technically point to a valid memory byte:
1989  *
1990  * <-- alloc -->
1991  * | 0 | 1 | 2 | .....
1992  * ^-- p=3, points after last valid byte (2)
1993  */
1994 #if !defined(DUK_MEMCPY)
1995 #if defined(DUK_F_UCLIBC)
1996 /* Old uclibcs have a broken memcpy so use memmove instead (this is overly wide
1997  * now on purpose): http://lists.uclibc.org/pipermail/uclibc-cvs/2008-October/025511.html
1998  */
1999 #define DUK_MEMCPY memmove
2000 #else
2001 #define DUK_MEMCPY memcpy
2002 #endif
2003 #endif
2004 #if !defined(DUK_MEMMOVE)
2005 #define DUK_MEMMOVE memmove
2006 #endif
2007 #if !defined(DUK_MEMCMP)
2008 #define DUK_MEMCMP memcmp
2009 #endif
2010 #if !defined(DUK_MEMSET)
2011 #define DUK_MEMSET memset
2012 #endif
2013 #if !defined(DUK_STRLEN)
2014 #define DUK_STRLEN strlen
2015 #endif
2016 #if !defined(DUK_STRCMP)
2017 #define DUK_STRCMP strcmp
2018 #endif
2019 #if !defined(DUK_STRNCMP)
2020 #define DUK_STRNCMP strncmp
2021 #endif
2022 #if !defined(DUK_SPRINTF)
2023 #define DUK_SPRINTF sprintf
2024 #endif
2025 #if !defined(DUK_SNPRINTF)
2026 /* snprintf() is technically not part of C89 but usually available. */
2027 #define DUK_SNPRINTF snprintf
2028 #endif
2029 #if !defined(DUK_VSPRINTF)
2030 #define DUK_VSPRINTF vsprintf
2031 #endif
2032 #if !defined(DUK_VSNPRINTF)
2033 /* vsnprintf() is technically not part of C89 but usually available. */
2034 #define DUK_VSNPRINTF vsnprintf
2035 #endif
2036 #if !defined(DUK_SSCANF)
2037 #define DUK_SSCANF sscanf
2038 #endif
2039 #if !defined(DUK_VSSCANF)
2040 #define DUK_VSSCANF vsscanf
2041 #endif
2042 #if !defined(DUK_MEMZERO)
2043 #define DUK_MEMZERO(p,n) DUK_MEMSET((p), 0, (n))
2044 #endif
2045 
2046 #if !defined(DUK_DOUBLE_INFINITY)
2047 #undef DUK_USE_COMPUTED_INFINITY
2048 #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION < 40600)
2049 /* GCC older than 4.6: avoid overflow warnings related to using INFINITY */
2050 #define DUK_DOUBLE_INFINITY (__builtin_inf())
2051 #elif defined(INFINITY)
2052 #define DUK_DOUBLE_INFINITY ((double) INFINITY)
2053 #elif !defined(DUK_F_VBCC) && !defined(DUK_F_MSVC) && !defined(DUK_F_BCC)
2054 #define DUK_DOUBLE_INFINITY (1.0 / 0.0)
2055 #else
2056 /* In VBCC (1.0 / 0.0) results in a warning and 0.0 instead of infinity.
2057  * Use a computed infinity (initialized when a heap is created at the
2058  * latest).
2059  */
2060 #define DUK_USE_COMPUTED_INFINITY
2061 #define DUK_DOUBLE_INFINITY duk_computed_infinity
2062 #endif
2063 #endif
2064 
2065 #if !defined(DUK_DOUBLE_NAN)
2066 #undef DUK_USE_COMPUTED_NAN
2067 #if defined(NAN)
2068 #define DUK_DOUBLE_NAN NAN
2069 #elif !defined(DUK_F_VBCC) && !defined(DUK_F_MSVC) && !defined(DUK_F_BCC)
2070 #define DUK_DOUBLE_NAN (0.0 / 0.0)
2071 #else
2072 /* In VBCC (0.0 / 0.0) results in a warning and 0.0 instead of NaN.
2073  * In MSVC (VS2010 Express) (0.0 / 0.0) results in a compile error.
2074  * Use a computed NaN (initialized when a heap is created at the
2075  * latest).
2076  */
2077 #define DUK_USE_COMPUTED_NAN
2078 #define DUK_DOUBLE_NAN duk_computed_nan
2079 #endif
2080 #endif
2081 
2082 /* Many platforms are missing fpclassify() and friends, so use replacements
2083  * if necessary. The replacement constants (FP_NAN etc) can be anything but
2084  * match Linux constants now.
2085  */
2086 #undef DUK_USE_REPL_FPCLASSIFY
2087 #undef DUK_USE_REPL_SIGNBIT
2088 #undef DUK_USE_REPL_ISFINITE
2089 #undef DUK_USE_REPL_ISNAN
2090 #undef DUK_USE_REPL_ISINF
2091 
2092 /* Complex condition broken into separate parts. */
2093 #undef DUK_F_USE_REPL_ALL
2094 #if !(defined(FP_NAN) && defined(FP_INFINITE) && defined(FP_ZERO) && \
2095  defined(FP_SUBNORMAL) && defined(FP_NORMAL))
2096 /* Missing some obvious constants. */
2097 #define DUK_F_USE_REPL_ALL
2098 #elif defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC)
2099 /* VBCC is missing the built-ins even in C99 mode (perhaps a header issue). */
2100 #define DUK_F_USE_REPL_ALL
2101 #elif defined(DUK_F_AMIGAOS) && defined(DUK_F_M68K)
2102 /* AmigaOS + M68K seems to have math issues even when using GCC cross
2103  * compilation. Use replacements for all AmigaOS versions on M68K
2104  * regardless of compiler.
2105  */
2106 #define DUK_F_USE_REPL_ALL
2107 #elif defined(DUK_F_FREEBSD) && defined(DUK_F_CLANG)
2108 /* Placeholder fix for (detection is wider than necessary):
2109  * http://llvm.org/bugs/show_bug.cgi?id=17788
2110  */
2111 #define DUK_F_USE_REPL_ALL
2112 #elif defined(DUK_F_UCLIBC)
2113 /* At least some uclibc versions have broken floating point math. For
2114  * example, fpclassify() can incorrectly classify certain NaN formats.
2115  * To be safe, use replacements.
2116  */
2117 #define DUK_F_USE_REPL_ALL
2118 #endif
2119 
2120 #if defined(DUK_F_USE_REPL_ALL)
2121 #define DUK_USE_REPL_FPCLASSIFY
2122 #define DUK_USE_REPL_SIGNBIT
2123 #define DUK_USE_REPL_ISFINITE
2124 #define DUK_USE_REPL_ISNAN
2125 #define DUK_USE_REPL_ISINF
2126 #define DUK_FPCLASSIFY duk_repl_fpclassify
2127 #define DUK_SIGNBIT duk_repl_signbit
2128 #define DUK_ISFINITE duk_repl_isfinite
2129 #define DUK_ISNAN duk_repl_isnan
2130 #define DUK_ISINF duk_repl_isinf
2131 #define DUK_FP_NAN 0
2132 #define DUK_FP_INFINITE 1
2133 #define DUK_FP_ZERO 2
2134 #define DUK_FP_SUBNORMAL 3
2135 #define DUK_FP_NORMAL 4
2136 #else
2137 #define DUK_FPCLASSIFY fpclassify
2138 #define DUK_SIGNBIT signbit
2139 #define DUK_ISFINITE isfinite
2140 #define DUK_ISNAN isnan
2141 #define DUK_ISINF isinf
2142 #define DUK_FP_NAN FP_NAN
2143 #define DUK_FP_INFINITE FP_INFINITE
2144 #define DUK_FP_ZERO FP_ZERO
2145 #define DUK_FP_SUBNORMAL FP_SUBNORMAL
2146 #define DUK_FP_NORMAL FP_NORMAL
2147 #endif
2148 
2149 #if defined(DUK_F_USE_REPL_ALL)
2150 #undef DUK_F_USE_REPL_ALL
2151 #endif
2152 
2153 /* These functions don't currently need replacement but are wrapped for
2154  * completeness. Because these are used as function pointers, they need
2155  * to be defined as concrete C functions (not macros).
2156  */
2157 #if !defined(DUK_FABS)
2158 #define DUK_FABS fabs
2159 #endif
2160 #if !defined(DUK_FLOOR)
2161 #define DUK_FLOOR floor
2162 #endif
2163 #if !defined(DUK_CEIL)
2164 #define DUK_CEIL ceil
2165 #endif
2166 #if !defined(DUK_FMOD)
2167 #define DUK_FMOD fmod
2168 #endif
2169 #if !defined(DUK_POW)
2170 #define DUK_POW pow
2171 #endif
2172 #if !defined(DUK_ACOS)
2173 #define DUK_ACOS acos
2174 #endif
2175 #if !defined(DUK_ASIN)
2176 #define DUK_ASIN asin
2177 #endif
2178 #if !defined(DUK_ATAN)
2179 #define DUK_ATAN atan
2180 #endif
2181 #if !defined(DUK_ATAN2)
2182 #define DUK_ATAN2 atan2
2183 #endif
2184 #if !defined(DUK_SIN)
2185 #define DUK_SIN sin
2186 #endif
2187 #if !defined(DUK_COS)
2188 #define DUK_COS cos
2189 #endif
2190 #if !defined(DUK_TAN)
2191 #define DUK_TAN tan
2192 #endif
2193 #if !defined(DUK_EXP)
2194 #define DUK_EXP exp
2195 #endif
2196 #if !defined(DUK_LOG)
2197 #define DUK_LOG log
2198 #endif
2199 #if !defined(DUK_SQRT)
2200 #define DUK_SQRT sqrt
2201 #endif
2202 
2203 /* The functions below exist only in C99/C++11 or later and need a workaround
2204  * for platforms that don't include them. MSVC isn't detected as C99, but
2205  * these functions also exist in MSVC 2013 and later so include a clause for
2206  * that too.
2207  */
2208 #if defined(DUK_F_C99) || defined(DUK_F_CPP11) || (defined(_MSC_VER) && (_MSC_VER >= 1800))
2209 #if !defined(DUK_CBRT)
2210 #define DUK_CBRT cbrt
2211 #endif
2212 #if !defined(DUK_LOG2)
2213 #define DUK_LOG2 log2
2214 #endif
2215 #if !defined(DUK_LOG10)
2216 #define DUK_LOG10 log10
2217 #endif
2218 #if !defined(DUK_TRUNC)
2219 #define DUK_TRUNC trunc
2220 #endif
2221 #endif /* DUK_F_C99 */
2222 
2223 /* NetBSD 6.0 x86 (at least) has a few problems with pow() semantics,
2224  * see test-bug-netbsd-math-pow.js. MinGW has similar (but different)
2225  * issues, see test-bug-mingw-math-issues.js. Enable pow() workarounds
2226  * for these targets.
2227  */
2228 #undef DUK_USE_POW_WORKAROUNDS
2229 #if defined(DUK_F_NETBSD) || defined(DUK_F_MINGW)
2230 #define DUK_USE_POW_WORKAROUNDS
2231 #endif
2232 
2233 /* Similar workarounds for atan2() semantics issues. MinGW issues are
2234  * documented in test-bug-mingw-math-issues.js.
2235  */
2236 #undef DUK_USE_ATAN2_WORKAROUNDS
2237 #if defined(DUK_F_MINGW)
2238 #define DUK_USE_ATAN2_WORKAROUNDS
2239 #endif
2240 
2241 /* Rely as little as possible on compiler behavior for NaN comparison,
2242  * signed zero handling, etc. Currently never activated but may be needed
2243  * for broken compilers.
2244  */
2245 #undef DUK_USE_PARANOID_MATH
2246 
2247 /* There was a curious bug where test-bi-date-canceling.js would fail e.g.
2248  * on 64-bit Ubuntu, gcc-4.8.1, -m32, and no -std=c99. Some date computations
2249  * using doubles would be optimized which then broke some corner case tests.
2250  * The problem goes away by adding 'volatile' to the datetime computations.
2251  * Not sure what the actual triggering conditions are, but using this on
2252  * non-C99 systems solves the known issues and has relatively little cost
2253  * on other platforms.
2254  */
2255 #undef DUK_USE_PARANOID_DATE_COMPUTATION
2256 #if !defined(DUK_F_C99)
2257 #define DUK_USE_PARANOID_DATE_COMPUTATION
2258 #endif
2259 
2260 /*
2261  * Byte order and double memory layout detection
2262  *
2263  * Endianness detection is a major portability hassle because the macros
2264  * and headers are not standardized. There's even variance across UNIX
2265  * platforms. Even with "standard" headers, details like underscore count
2266  * varies between platforms, e.g. both __BYTE_ORDER and _BYTE_ORDER are used
2267  * (Crossbridge has a single underscore, for instance).
2268  *
2269  * The checks below are structured with this in mind: several approaches are
2270  * used, and at the end we check if any of them worked. This allows generic
2271  * approaches to be tried first, and platform/compiler specific hacks tried
2272  * last. As a last resort, the user can force a specific endianness, as it's
2273  * not likely that automatic detection will work on the most exotic platforms.
2274  *
2275  * Duktape supports little and big endian machines. There's also support
2276  * for a hybrid used by some ARM machines where integers are little endian
2277  * but IEEE double values use a mixed order (12345678 -> 43218765). This
2278  * byte order for doubles is referred to as "mixed endian".
2279  */
2280 
2281 /* GCC and Clang provide endianness defines as built-in predefines, with
2282  * leading and trailing double underscores (e.g. __BYTE_ORDER__). See
2283  * output of "make gccpredefs" and "make clangpredefs". Clang doesn't
2284  * seem to provide __FLOAT_WORD_ORDER__; assume not mixed endian for clang.
2285  * http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
2286  */
2287 #if !defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__)
2288 #if defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
2289 #if defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__)
2290 #define DUK_USE_BYTEORDER 1
2291 #elif defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)
2292 #define DUK_USE_BYTEORDER 2
2293 #elif !defined(__FLOAT_WORD_ORDER__)
2294 /* Float word order not known, assume not a hybrid. */
2295 #define DUK_USE_BYTEORDER 1
2296 #else
2297 /* Byte order is little endian but cannot determine IEEE double word order. */
2298 #endif /* float word order */
2299 #elif defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
2300 #if defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)
2301 #define DUK_USE_BYTEORDER 3
2302 #elif !defined(__FLOAT_WORD_ORDER__)
2303 /* Float word order not known, assume not a hybrid. */
2304 #define DUK_USE_BYTEORDER 3
2305 #else
2306 /* Byte order is big endian but cannot determine IEEE double word order. */
2307 #endif /* float word order */
2308 #else
2309 /* Cannot determine byte order; __ORDER_PDP_ENDIAN__ is related to 32-bit
2310  * integer ordering and is not relevant.
2311  */
2312 #endif /* integer byte order */
2313 #endif /* !defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__) */
2314 
2315 /* More or less standard endianness predefines provided by header files.
2316  * The ARM hybrid case is detected by assuming that __FLOAT_WORD_ORDER
2317  * will be big endian, see: http://lists.mysql.com/internals/443.
2318  * On some platforms some defines may be present with an empty value which
2319  * causes comparisons to fail: https://github.com/svaarala/duktape/issues/453.
2320  */
2321 #if !defined(DUK_USE_BYTEORDER)
2322 #if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && (__BYTE_ORDER == __LITTLE_ENDIAN) || \
2323  defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN) && (_BYTE_ORDER == _LITTLE_ENDIAN) || \
2324  defined(__LITTLE_ENDIAN__)
2325 #if defined(__FLOAT_WORD_ORDER) && defined(__LITTLE_ENDIAN) && (__FLOAT_WORD_ORDER == __LITTLE_ENDIAN) || \
2326  defined(_FLOAT_WORD_ORDER) && defined(_LITTLE_ENDIAN) && (_FLOAT_WORD_ORDER == _LITTLE_ENDIAN)
2327 #define DUK_USE_BYTEORDER 1
2328 #elif defined(__FLOAT_WORD_ORDER) && defined(__BIG_ENDIAN) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) || \
2329  defined(_FLOAT_WORD_ORDER) && defined(_BIG_ENDIAN) && (_FLOAT_WORD_ORDER == _BIG_ENDIAN)
2330 #define DUK_USE_BYTEORDER 2
2331 #elif !defined(__FLOAT_WORD_ORDER) && !defined(_FLOAT_WORD_ORDER)
2332 /* Float word order not known, assume not a hybrid. */
2333 #define DUK_USE_BYTEORDER 1
2334 #else
2335 /* Byte order is little endian but cannot determine IEEE double word order. */
2336 #endif /* float word order */
2337 #elif defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && (__BYTE_ORDER == __BIG_ENDIAN) || \
2338  defined(_BYTE_ORDER) && defined(_BIG_ENDIAN) && (_BYTE_ORDER == _BIG_ENDIAN) || \
2339  defined(__BIG_ENDIAN__)
2340 #if defined(__FLOAT_WORD_ORDER) && defined(__BIG_ENDIAN) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) || \
2341  defined(_FLOAT_WORD_ORDER) && defined(_BIG_ENDIAN) && (_FLOAT_WORD_ORDER == _BIG_ENDIAN)
2342 #define DUK_USE_BYTEORDER 3
2343 #elif !defined(__FLOAT_WORD_ORDER) && !defined(_FLOAT_WORD_ORDER)
2344 /* Float word order not known, assume not a hybrid. */
2345 #define DUK_USE_BYTEORDER 3
2346 #else
2347 /* Byte order is big endian but cannot determine IEEE double word order. */
2348 #endif /* float word order */
2349 #else
2350 /* Cannot determine byte order. */
2351 #endif /* integer byte order */
2352 #endif /* !defined(DUK_USE_BYTEORDER) */
2353 
2354 /* QNX gcc cross compiler seems to define e.g. __LITTLEENDIAN__ or __BIGENDIAN__:
2355  * $ /opt/qnx650/host/linux/x86/usr/bin/i486-pc-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
2356  * 67:#define __LITTLEENDIAN__ 1
2357  * $ /opt/qnx650/host/linux/x86/usr/bin/mips-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
2358  * 81:#define __BIGENDIAN__ 1
2359  * $ /opt/qnx650/host/linux/x86/usr/bin/arm-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
2360  * 70:#define __LITTLEENDIAN__ 1
2361  */
2362 #if !defined(DUK_USE_BYTEORDER)
2363 #if defined(__LITTLEENDIAN__)
2364 #define DUK_USE_BYTEORDER 1
2365 #elif defined(__BIGENDIAN__)
2366 #define DUK_USE_BYTEORDER 3
2367 #endif
2368 #endif
2369 
2370 /*
2371  * Alignment requirement and support for unaligned accesses
2372  *
2373  * Assume unaligned accesses are not supported unless specifically allowed
2374  * in the target platform. Some platforms may support unaligned accesses
2375  * but alignment to 4 or 8 may still be desirable.
2376  */
2377 
2378 /* If not provided, use safe default for alignment. */
2379 #if !defined(DUK_USE_ALIGN_BY)
2380 #define DUK_USE_ALIGN_BY 8
2381 #endif
2382 
2383 /* Compiler specific hackery needed to force struct size to match aligment,
2384  * see e.g. duk_hbuffer.h.
2385  *
2386  * http://stackoverflow.com/questions/11130109/c-struct-size-alignment
2387  * http://stackoverflow.com/questions/10951039/specifying-64-bit-alignment
2388  */
2389 #if !(defined(DUK_USE_PACK_MSVC_PRAGMA) || defined(DUK_USE_PACK_GCC_ATTR) || \
2390  defined(DUK_USE_PACK_CLANG_ATTR) || defined(DUK_USE_PACK_DUMMY_MEMBER))
2391 #define DUK_USE_PACK_DUMMY_MEMBER
2392 #endif
2393 
2394 #if !defined(DUK_VA_COPY)
2395 /* We need va_copy() which is defined in C99 / C++11, so an awkward
2396  * replacement is needed for pre-C99 / pre-C++11 environments. This
2397  * will quite likely need portability hacks for some non-C99
2398  * environments.
2399  */
2400 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
2401 /* C99 / C++11 and above: rely on va_copy() which is required.
2402  * Omit parenthesis on macro right side on purpose to minimize differences
2403  * to direct use.
2404  */
2405 #define DUK_VA_COPY(dest,src) va_copy(dest,src)
2406 #else
2407 /* Pre-C99: va_list type is implementation dependent. This replacement
2408  * assumes it is a plain value so that a simple assignment will work.
2409  * This is not the case on all platforms (it may be a single-array element,
2410  * for instance).
2411  */
2412 #define DUK_VA_COPY(dest,src) do { (dest) = (src); } while (0)
2413 #endif
2414 #endif
2415 
2416 #if !defined(DUK_MACRO_STRINGIFY)
2417 /* Macro hackery to convert e.g. __LINE__ to a string without formatting,
2418  * see: http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string
2419  */
2420 #define DUK_MACRO_STRINGIFY_HELPER(x) #x
2421 #define DUK_MACRO_STRINGIFY(x) DUK_MACRO_STRINGIFY_HELPER(x)
2422 #endif
2423 
2424 #if !defined(DUK_CAUSE_SEGFAULT)
2425 /* This can be used for testing; valgrind will then indicate the C call stack
2426  * leading to the call site.
2427  */
2428 #define DUK_CAUSE_SEGFAULT() do { *((volatile duk_uint32_t *) NULL) = (duk_uint32_t) 0xdeadbeefUL; } while (0)
2429 #endif
2430 #if !defined(DUK_UNREF)
2431 /* Macro for suppressing warnings for potentially unreferenced variables.
2432  * The variables can be actually unreferenced or unreferenced in some
2433  * specific cases only; for instance, if a variable is only debug printed,
2434  * it is unreferenced when debug printing is disabled.
2435  */
2436 #define DUK_UNREF(x) do { (void) (x); } while (0)
2437 #endif
2438 #if !defined(DUK_NORETURN)
2439 #define DUK_NORETURN(decl) decl
2440 #endif
2441 #if !defined(DUK_UNREACHABLE)
2442 /* Don't know how to declare unreachable point, so don't do it; this
2443  * may cause some spurious compilation warnings (e.g. "variable used
2444  * uninitialized").
2445  */
2446 #define DUK_UNREACHABLE() do { } while (0)
2447 #endif
2448 #if !defined(DUK_LOSE_CONST)
2449 /* Convert any input pointer into a "void *", losing a const qualifier.
2450  * This is not fully portable because casting through duk_uintptr_t may
2451  * not work on all architectures (e.g. those with long, segmented pointers).
2452  */
2453 #define DUK_LOSE_CONST(src) ((void *) (duk_uintptr_t) (src))
2454 #endif
2455 
2456 #if !defined(DUK_LIKELY)
2457 #define DUK_LIKELY(x) (x)
2458 #endif
2459 #if !defined(DUK_UNLIKELY)
2460 #define DUK_UNLIKELY(x) (x)
2461 #endif
2462 #if !defined(DUK_UNPREDICTABLE)
2463 #define DUK_UNPREDICTABLE(x) (x)
2464 #endif
2465 
2466 #if !defined(DUK_NOINLINE)
2467 #define DUK_NOINLINE /*nop*/
2468 #endif
2469 #if !defined(DUK_INLINE)
2470 #define DUK_INLINE /*nop*/
2471 #endif
2472 #if !defined(DUK_ALWAYS_INLINE)
2473 #define DUK_ALWAYS_INLINE /*nop*/
2474 #endif
2475 
2476 #if !defined(DUK_EXTERNAL_DECL)
2477 #define DUK_EXTERNAL_DECL extern
2478 #endif
2479 #if !defined(DUK_EXTERNAL)
2480 #define DUK_EXTERNAL /*empty*/
2481 #endif
2482 #if !defined(DUK_INTERNAL_DECL)
2483 #if defined(DUK_SINGLE_FILE)
2484 #define DUK_INTERNAL_DECL static
2485 #else
2486 #define DUK_INTERNAL_DECL extern
2487 #endif
2488 #endif
2489 #if !defined(DUK_INTERNAL)
2490 #if defined(DUK_SINGLE_FILE)
2491 #define DUK_INTERNAL static
2492 #else
2493 #define DUK_INTERNAL /*empty*/
2494 #endif
2495 #endif
2496 #if !defined(DUK_LOCAL_DECL)
2497 #define DUK_LOCAL_DECL static
2498 #endif
2499 #if !defined(DUK_LOCAL)
2500 #define DUK_LOCAL static
2501 #endif
2502 
2503 #if !defined(DUK_FILE_MACRO)
2504 #define DUK_FILE_MACRO __FILE__
2505 #endif
2506 #if !defined(DUK_LINE_MACRO)
2507 #define DUK_LINE_MACRO __LINE__
2508 #endif
2509 #if !defined(DUK_FUNC_MACRO)
2510 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
2511 #define DUK_FUNC_MACRO __func__
2512 #elif defined(__FUNCTION__)
2513 #define DUK_FUNC_MACRO __FUNCTION__
2514 #else
2515 #define DUK_FUNC_MACRO "unknown"
2516 #endif
2517 #endif
2518 
2519 #if !defined(DUK_BSWAP32)
2520 #define DUK_BSWAP32(x) \
2521  ((((duk_uint32_t) (x)) >> 24) | \
2522  ((((duk_uint32_t) (x)) >> 8) & 0xff00UL) | \
2523  ((((duk_uint32_t) (x)) << 8) & 0xff0000UL) | \
2524  (((duk_uint32_t) (x)) << 24))
2525 #endif
2526 #if !defined(DUK_BSWAP16)
2527 #define DUK_BSWAP16(x) \
2528  ((duk_uint16_t) (x) >> 8) | \
2529  ((duk_uint16_t) (x) << 8)
2530 #endif
2531 
2532 /* DUK_USE_VARIADIC_MACROS: required from compilers, so no fill-in. */
2533 /* DUK_USE_UNION_INITIALIZERS: required from compilers, so no fill-in. */
2534 
2535 #if !(defined(DUK_USE_FLEX_C99) || defined(DUK_USE_FLEX_ZEROSIZE) || defined(DUK_USE_FLEX_ONESIZE))
2536 #if defined(DUK_F_C99)
2537 #define DUK_USE_FLEX_C99
2538 #else
2539 #define DUK_USE_FLEX_ZEROSIZE /* Not standard but common enough */
2540 #endif
2541 #endif
2542 
2543 #if !(defined(DUK_USE_PACK_GCC_ATTR) || defined(DUK_USE_PACK_CLANG_ATTR) || \
2544  defined(DUK_USE_PACK_MSVC_PRAGMA) || defined(DUK_USE_PACK_DUMMY_MEMBER))
2545 #define DUK_USE_PACK_DUMMY_MEMBER
2546 #endif
2547 
2548 #if 0 /* not defined by default */
2549 #undef DUK_USE_GCC_PRAGMAS
2550 #endif
2551 
2552 /* Workaround for GH-323: avoid inlining control when compiling from
2553  * multiple sources, as it causes compiler portability trouble.
2554  */
2555 #if !defined(DUK_SINGLE_FILE)
2556 #undef DUK_NOINLINE
2557 #undef DUK_INLINE
2558 #undef DUK_ALWAYS_INLINE
2559 #define DUK_NOINLINE /*nop*/
2560 #define DUK_INLINE /*nop*/
2561 #define DUK_ALWAYS_INLINE /*nop*/
2562 #endif
2563 
2564 /*
2565  * Check whether or not a packed duk_tval representation is possible.
2566  * What's basically required is that pointers are 32-bit values
2567  * (sizeof(void *) == 4). Best effort check, not always accurate.
2568  * If guess goes wrong, crashes may result; self tests also verify
2569  * the guess.
2570  */
2571 
2572 /* Explicit marker needed; may be 'defined', 'undefined, 'or 'not provided'. */
2573 #if !defined(DUK_F_PACKED_TVAL_PROVIDED)
2574 #undef DUK_F_PACKED_TVAL_POSSIBLE
2575 
2576 /* Strict C99 case: DUK_UINTPTR_MAX (= UINTPTR_MAX) should be very reliable */
2577 #if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_UINTPTR_MAX)
2578 #if (DUK_UINTPTR_MAX <= 0xffffffffUL)
2579 #define DUK_F_PACKED_TVAL_POSSIBLE
2580 #endif
2581 #endif
2582 
2583 /* Non-C99 case, still relying on DUK_UINTPTR_MAX, as long as it is not a computed value */
2584 #if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_UINTPTR_MAX) && !defined(DUK_UINTPTR_MAX_COMPUTED)
2585 #if (DUK_UINTPTR_MAX <= 0xffffffffUL)
2586 #define DUK_F_PACKED_TVAL_POSSIBLE
2587 #endif
2588 #endif
2589 
2590 /* DUK_SIZE_MAX (= SIZE_MAX) is often reliable */
2591 #if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_SIZE_MAX) && !defined(DUK_SIZE_MAX_COMPUTED)
2592 #if (DUK_SIZE_MAX <= 0xffffffffUL)
2593 #define DUK_F_PACKED_TVAL_POSSIBLE
2594 #endif
2595 #endif
2596 
2597 #undef DUK_USE_PACKED_TVAL
2598 #if defined(DUK_F_PACKED_TVAL_POSSIBLE)
2599 #define DUK_USE_PACKED_TVAL
2600 #endif
2601 
2602 #undef DUK_F_PACKED_TVAL_POSSIBLE
2603 #endif /* DUK_F_PACKED_TVAL_PROVIDED */
2604 /* Object property allocation layout has implications for memory and code
2605  * footprint and generated code size/speed. The best layout also depends
2606  * on whether the platform has alignment requirements or benefits from
2607  * having mostly aligned accesses.
2608  */
2609 #undef DUK_USE_HOBJECT_LAYOUT_1
2610 #undef DUK_USE_HOBJECT_LAYOUT_2
2611 #undef DUK_USE_HOBJECT_LAYOUT_3
2612 #if (DUK_USE_ALIGN_BY == 1)
2613 /* On platforms without any alignment issues, layout 1 is preferable
2614  * because it compiles to slightly less code and provides direct access
2615  * to property keys.
2616  */
2617 #define DUK_USE_HOBJECT_LAYOUT_1
2618 #else
2619 /* On other platforms use layout 2, which requires some padding but
2620  * is a bit more natural than layout 3 in ordering the entries. Layout
2621  * 3 is currently not used.
2622  */
2623 #define DUK_USE_HOBJECT_LAYOUT_2
2624 #endif
2625 
2626 /* GCC/clang inaccurate math would break compliance and probably duk_tval,
2627  * so refuse to compile. Relax this if -ffast-math is tested to work.
2628  */
2629 #if defined(__FAST_MATH__)
2630 #error __FAST_MATH__ defined, refusing to compile
2631 #endif
2632 
2633 /*
2634  * Autogenerated defaults
2635  */
2636 
2637 #define DUK_USE_ARRAY_BUILTIN
2638 #define DUK_USE_ARRAY_FASTPATH
2639 #define DUK_USE_ARRAY_PROP_FASTPATH
2640 #undef DUK_USE_ASSERTIONS
2641 #define DUK_USE_AUGMENT_ERROR_CREATE
2642 #define DUK_USE_AUGMENT_ERROR_THROW
2643 #define DUK_USE_AVOID_PLATFORM_FUNCPTRS
2644 #define DUK_USE_BASE64_FASTPATH
2645 #define DUK_USE_BOOLEAN_BUILTIN
2646 #define DUK_USE_BUFFEROBJECT_SUPPORT
2647 #undef DUK_USE_BUFLEN16
2648 #define DUK_USE_BYTECODE_DUMP_SUPPORT
2649 #define DUK_USE_COMMONJS_MODULES
2650 #define DUK_USE_COMPILER_RECLIMIT 2500
2651 #define DUK_USE_COROUTINE_SUPPORT
2652 #undef DUK_USE_CPP_EXCEPTIONS
2653 #undef DUK_USE_DATAPTR16
2654 #undef DUK_USE_DATAPTR_DEC16
2655 #undef DUK_USE_DATAPTR_ENC16
2656 #define DUK_USE_DATE_BUILTIN
2657 #undef DUK_USE_DATE_FORMAT_STRING
2658 #undef DUK_USE_DATE_GET_LOCAL_TZOFFSET
2659 #undef DUK_USE_DATE_GET_NOW
2660 #undef DUK_USE_DATE_PARSE_STRING
2661 #undef DUK_USE_DATE_PRS_GETDATE
2662 #undef DUK_USE_DEBUG
2663 #undef DUK_USE_DEBUGGER_DUMPHEAP
2664 #undef DUK_USE_DEBUGGER_INSPECT
2665 #undef DUK_USE_DEBUGGER_PAUSE_UNCAUGHT
2666 #undef DUK_USE_DEBUGGER_SUPPORT
2667 #define DUK_USE_DEBUGGER_THROW_NOTIFY
2668 #undef DUK_USE_DEBUGGER_TRANSPORT_TORTURE
2669 #define DUK_USE_DEBUG_BUFSIZE 65536L
2670 #define DUK_USE_DEBUG_LEVEL 0
2671 #undef DUK_USE_DEBUG_WRITE
2672 #define DUK_USE_DOUBLE_LINKED_HEAP
2673 #define DUK_USE_DUKTAPE_BUILTIN
2674 #define DUK_USE_ENCODING_BUILTINS
2675 #define DUK_USE_ERRCREATE
2676 #define DUK_USE_ERRTHROW
2677 #define DUK_USE_ES6
2678 #define DUK_USE_ES6_OBJECT_PROTO_PROPERTY
2679 #define DUK_USE_ES6_OBJECT_SETPROTOTYPEOF
2680 #define DUK_USE_ES6_PROXY
2681 #define DUK_USE_ES6_REGEXP_SYNTAX
2682 #define DUK_USE_ES6_UNICODE_ESCAPE
2683 #define DUK_USE_ES7_EXP_OPERATOR
2684 #define DUK_USE_ESBC_LIMITS
2685 #define DUK_USE_ESBC_MAX_BYTES 2147418112L
2686 #define DUK_USE_ESBC_MAX_LINENUMBER 2147418112L
2687 #undef DUK_USE_EXEC_FUN_LOCAL
2688 #undef DUK_USE_EXEC_INDIRECT_BOUND_CHECK
2689 #undef DUK_USE_EXEC_PREFER_SIZE
2690 #define DUK_USE_EXEC_REGCONST_OPTIMIZE
2691 #undef DUK_USE_EXEC_TIMEOUT_CHECK
2692 #undef DUK_USE_EXPLICIT_NULL_INIT
2693 #undef DUK_USE_EXTSTR_FREE
2694 #undef DUK_USE_EXTSTR_INTERN_CHECK
2695 #undef DUK_USE_FASTINT
2696 #define DUK_USE_FAST_REFCOUNT_DEFAULT
2697 #undef DUK_USE_FATAL_HANDLER
2698 #define DUK_USE_FINALIZER_SUPPORT
2699 #undef DUK_USE_FUNCPTR16
2700 #undef DUK_USE_FUNCPTR_DEC16
2701 #undef DUK_USE_FUNCPTR_ENC16
2702 #define DUK_USE_FUNCTION_BUILTIN
2703 #define DUK_USE_FUNC_FILENAME_PROPERTY
2704 #define DUK_USE_FUNC_NAME_PROPERTY
2705 #undef DUK_USE_GC_TORTURE
2706 #undef DUK_USE_GET_RANDOM_DOUBLE
2707 #define DUK_USE_GLOBAL_BUILTIN
2708 #undef DUK_USE_HEAPPTR16
2709 #undef DUK_USE_HEAPPTR_DEC16
2710 #undef DUK_USE_HEAPPTR_ENC16
2711 #define DUK_USE_HEX_FASTPATH
2712 #define DUK_USE_HOBJECT_HASH_PART
2713 #define DUK_USE_HSTRING_ARRIDX
2714 #define DUK_USE_HSTRING_CLEN
2715 #undef DUK_USE_HSTRING_EXTDATA
2716 #define DUK_USE_IDCHAR_FASTPATH
2717 #undef DUK_USE_INTERRUPT_COUNTER
2718 #undef DUK_USE_INTERRUPT_DEBUG_FIXUP
2719 #define DUK_USE_JC
2720 #define DUK_USE_JSON_BUILTIN
2721 #define DUK_USE_JSON_DECNUMBER_FASTPATH
2722 #define DUK_USE_JSON_DECSTRING_FASTPATH
2723 #define DUK_USE_JSON_DEC_RECLIMIT 1000
2724 #define DUK_USE_JSON_EATWHITE_FASTPATH
2725 #define DUK_USE_JSON_ENC_RECLIMIT 1000
2726 #define DUK_USE_JSON_QUOTESTRING_FASTPATH
2727 #undef DUK_USE_JSON_STRINGIFY_FASTPATH
2728 #define DUK_USE_JSON_SUPPORT
2729 #define DUK_USE_JX
2730 #define DUK_USE_LEXER_SLIDING_WINDOW
2731 #undef DUK_USE_LIGHTFUNC_BUILTINS
2732 #undef DUK_USE_MARKANDSWEEP_FINALIZER_TORTURE
2733 #define DUK_USE_MARK_AND_SWEEP_RECLIMIT 256
2734 #define DUK_USE_MATH_BUILTIN
2735 #define DUK_USE_MS_STRINGTABLE_RESIZE
2736 #define DUK_USE_NATIVE_CALL_RECLIMIT 1000
2737 #define DUK_USE_NONSTD_ARRAY_CONCAT_TRAILER
2738 #define DUK_USE_NONSTD_ARRAY_MAP_TRAILER
2739 #define DUK_USE_NONSTD_ARRAY_SPLICE_DELCOUNT
2740 #undef DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
2741 #undef DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY
2742 #define DUK_USE_NONSTD_FUNC_STMT
2743 #define DUK_USE_NONSTD_GETTER_KEY_ARGUMENT
2744 #define DUK_USE_NONSTD_JSON_ESC_U2028_U2029
2745 #define DUK_USE_NONSTD_SETTER_KEY_ARGUMENT
2746 #define DUK_USE_NONSTD_STRING_FROMCHARCODE_32BIT
2747 #define DUK_USE_NUMBER_BUILTIN
2748 #define DUK_USE_OBJECT_BUILTIN
2749 #undef DUK_USE_OBJSIZES16
2750 #undef DUK_USE_PARANOID_ERRORS
2751 #define DUK_USE_PC2LINE
2752 #undef DUK_USE_PREFER_SIZE
2753 #define DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS
2754 #undef DUK_USE_REFCOUNT16
2755 #define DUK_USE_REFERENCE_COUNTING
2756 #define DUK_USE_REFLECT_BUILTIN
2757 #undef DUK_USE_REFZERO_FINALIZER_TORTURE
2758 #undef DUK_USE_REGEXP_CANON_WORKAROUND
2759 #define DUK_USE_REGEXP_COMPILER_RECLIMIT 10000
2760 #define DUK_USE_REGEXP_EXECUTOR_RECLIMIT 10000
2761 #define DUK_USE_REGEXP_SUPPORT
2762 #undef DUK_USE_ROM_GLOBAL_CLONE
2763 #undef DUK_USE_ROM_GLOBAL_INHERIT
2764 #undef DUK_USE_ROM_OBJECTS
2765 #define DUK_USE_ROM_PTRCOMP_FIRST 63488L
2766 #undef DUK_USE_ROM_STRINGS
2767 #define DUK_USE_SECTION_B
2768 #undef DUK_USE_SELF_TESTS
2769 #undef DUK_USE_SHUFFLE_TORTURE
2770 #define DUK_USE_SOURCE_NONBMP
2771 #undef DUK_USE_STRHASH16
2772 #undef DUK_USE_STRHASH_DENSE
2773 #define DUK_USE_STRHASH_SKIP_SHIFT 5
2774 #define DUK_USE_STRICT_DECL
2775 #undef DUK_USE_STRICT_UTF8_SOURCE
2776 #define DUK_USE_STRING_BUILTIN
2777 #undef DUK_USE_STRLEN16
2778 #undef DUK_USE_STRTAB_CHAIN
2779 #undef DUK_USE_STRTAB_CHAIN_SIZE
2780 #define DUK_USE_STRTAB_PROBE
2781 #undef DUK_USE_SYMBOL_BUILTIN
2782 #define DUK_USE_TAILCALL
2783 #define DUK_USE_TARGET_INFO "unknown"
2784 #define DUK_USE_TRACEBACKS
2785 #define DUK_USE_TRACEBACK_DEPTH 10
2786 #define DUK_USE_USER_DECLARE() /* no user declarations */
2787 #undef DUK_USE_VALSTACK_UNSAFE
2788 #define DUK_USE_VERBOSE_ERRORS
2789 #define DUK_USE_VERBOSE_EXECUTOR_ERRORS
2790 #define DUK_USE_VOLUNTARY_GC
2791 #define DUK_USE_ZERO_BUFFER_DATA
2792 
2793 /*
2794  * You may add overriding #define/#undef directives below for
2795  * customization. You of course cannot un-#include or un-typedef
2796  * anything; these require direct changes above.
2797  */
2798 
2799 /* __OVERRIDE_DEFINES__ */
2800 
2801 /*
2802  * Date provider selection
2803  *
2804  * User may define DUK_USE_DATE_GET_NOW() etc directly, in which case we'll
2805  * rely on an external provider. If this is not done, revert to previous
2806  * behavior and use Unix/Windows built-in provider.
2807  */
2808 
2809 #if defined(DUK_COMPILING_DUKTAPE)
2810 
2811 #if defined(DUK_USE_DATE_GET_NOW)
2812 /* External provider already defined. */
2813 #elif defined(DUK_USE_DATE_NOW_GETTIMEOFDAY)
2814 #define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_gettimeofday((ctx))
2815 #elif defined(DUK_USE_DATE_NOW_TIME)
2816 #define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_time((ctx))
2817 #elif defined(DUK_USE_DATE_NOW_WINDOWS)
2818 #define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_windows((ctx))
2819 #else
2820 #error no provider for DUK_USE_DATE_GET_NOW()
2821 #endif
2822 
2823 #if defined(DUK_USE_DATE_GET_LOCAL_TZOFFSET)
2824 /* External provider already defined. */
2825 #elif defined(DUK_USE_DATE_TZO_GMTIME_R) || defined(DUK_USE_DATE_TZO_GMTIME)
2826 #define DUK_USE_DATE_GET_LOCAL_TZOFFSET(d) duk_bi_date_get_local_tzoffset_gmtime((d))
2827 #elif defined(DUK_USE_DATE_TZO_WINDOWS)
2828 #define DUK_USE_DATE_GET_LOCAL_TZOFFSET(d) duk_bi_date_get_local_tzoffset_windows((d))
2829 #else
2830 #error no provider for DUK_USE_DATE_GET_LOCAL_TZOFFSET()
2831 #endif
2832 
2833 #if defined(DUK_USE_DATE_PARSE_STRING)
2834 /* External provider already defined. */
2835 #elif defined(DUK_USE_DATE_PRS_STRPTIME)
2836 #define DUK_USE_DATE_PARSE_STRING(ctx,str) duk_bi_date_parse_string_strptime((ctx), (str))
2837 #elif defined(DUK_USE_DATE_PRS_GETDATE)
2838 #define DUK_USE_DATE_PARSE_STRING(ctx,str) duk_bi_date_parse_string_getdate((ctx), (str))
2839 #else
2840 /* No provider for DUK_USE_DATE_PARSE_STRING(), fall back to ISO 8601 only. */
2841 #endif
2842 
2843 #if defined(DUK_USE_DATE_FORMAT_STRING)
2844 /* External provider already defined. */
2845 #elif defined(DUK_USE_DATE_FMT_STRFTIME)
2846 #define DUK_USE_DATE_FORMAT_STRING(ctx,parts,tzoffset,flags) \
2847  duk_bi_date_format_parts_strftime((ctx), (parts), (tzoffset), (flags))
2848 #else
2849 /* No provider for DUK_USE_DATE_FORMAT_STRING(), fall back to ISO 8601 only. */
2850 #endif
2851 
2852 #endif /* DUK_COMPILING_DUKTAPE */
2853 
2854 /*
2855  * Convert DUK_USE_BYTEORDER, from whatever source, into currently used
2856  * internal defines. If detection failed, #error out.
2857  */
2858 
2859 #if defined(DUK_USE_BYTEORDER)
2860 #if (DUK_USE_BYTEORDER == 1)
2861 #define DUK_USE_INTEGER_LE
2862 #define DUK_USE_DOUBLE_LE
2863 #elif (DUK_USE_BYTEORDER == 2)
2864 #define DUK_USE_INTEGER_LE /* integer endianness is little on purpose */
2865 #define DUK_USE_DOUBLE_ME
2866 #elif (DUK_USE_BYTEORDER == 3)
2867 #define DUK_USE_INTEGER_BE
2868 #define DUK_USE_DOUBLE_BE
2869 #else
2870 #error unsupported: byte order invalid
2871 #endif /* byte order */
2872 #else
2873 #error unsupported: byte order detection failed
2874 #endif /* defined(DUK_USE_BYTEORDER) */
2875 
2876 #endif /* DUK_CONFIG_H_INCLUDED */