2 * duk_config.h configuration header generated by genconfig.py.
4 * Git commit: cad34ae155acb0846545ca6bf2d29f9463b22bbb
9 * - Mac OSX, iPhone, Darwin
15 * - Flashplayer (Crossbridge)
26 * Supported architectures:
43 * Supported compilers:
50 * - Bruce's C compiler
55 #if !defined(DUK_CONFIG_H_INCLUDED)
56 #define DUK_CONFIG_H_INCLUDED
59 * Intermediate helper defines
62 /* DLL build detection */
63 #if defined(DUK_OPT_DLL_BUILD)
64 #define DUK_F_DLL_BUILD
65 #elif defined(DUK_OPT_NO_DLL_BUILD)
66 #undef DUK_F_DLL_BUILD
68 /* not configured for DLL build */
69 #undef DUK_F_DLL_BUILD
73 #if defined(__APPLE__)
78 #if defined(__OpenBSD__) || defined(__OpenBSD)
83 #if defined(__NetBSD__) || defined(__NetBSD)
88 #if defined(__FreeBSD__) || defined(__FreeBSD)
93 #if defined(DUK_F_FREEBSD) || defined(DUK_F_NETBSD) || defined(DUK_F_OPENBSD) || \
94 defined(__bsdi__) || defined(__DragonFly__)
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.
105 /* Motorola 68K. Not defined by VBCC, so user must define one of these
106 * manually when using VBCC.
108 #if defined(__m68k__) || defined(M68000) || defined(__MC68K__)
112 /* AmigaOS. Neither AMIGA nor __amigaos__ is defined on VBCC, so user must
113 * define 'AMIGA' manually when using VBCC.
115 #if defined(AMIGA) || defined(__amigaos__)
116 #define DUK_F_AMIGAOS
120 #if defined(__powerpc) || defined(__powerpc__) || defined(__PPC__)
122 #if defined(__PPC64__) || defined(__LP64__) || defined(_LP64)
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)
140 /* Flash player (e.g. Crossbridge) */
141 #if defined(__FLASHPLAYER__)
142 #define DUK_F_FLASHPLAYER
150 /* TI-Nspire (using Ndless) */
151 #if defined(_TINSPIRE)
152 #define DUK_F_TINSPIRE
155 /* Emscripten (provided explicitly by user), improve if possible */
156 #if defined(EMSCRIPTEN)
157 #define DUK_F_EMSCRIPTEN
160 /* BCC (Bruce's C compiler): this is a "torture target" for compilation */
161 #if defined(__BCC__) || defined(__BCC_VERSION__)
166 #if defined(__linux) || defined(__linux__) || defined(linux)
170 /* illumos / Solaris */
171 #if defined(__sun) && defined(__SVR4)
181 #if defined(__CYGWIN__)
185 /* Generic Unix (includes Cygwin) */
186 #if defined(__unix) || defined(__unix__) || defined(unix) || \
187 defined(DUK_F_LINUX) || defined(DUK_F_BSD)
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
198 #if !defined(DUK_F_NO_STDINT_H) && (defined(DUK_F_TOS) || defined(DUK_F_BCC))
199 #define DUK_F_NO_STDINT_H
204 #if defined(__cplusplus)
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/
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)
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. */
233 #if defined(__arm__) || defined(__thumb__) || defined(_ARM) || defined(_M_ARM)
235 #if defined(__LP64__) || defined(_LP64) || defined(__arm64) || defined(__arm64__)
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__)
249 #if defined(__LP64__) || defined(_LP64) || defined(__mips64) || \
250 defined(__mips64__) || defined(__mips_n64)
258 #if defined(sparc) || defined(__sparc) || defined(__sparc__)
260 #if defined(__LP64__) || defined(_LP64)
261 #define DUK_F_SPARC64
263 #define DUK_F_SPARC32
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__)
278 #if defined(__clang__)
284 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
290 #if defined(__cplusplus) && (__cplusplus >= 201103L)
294 /* GCC. Clang also defines __GNUC__ so don't detect GCC if using Clang. */
295 #if defined(__GNUC__) && !defined(__clang__) && !defined(DUK_F_CLANG)
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__)
301 #error cannot figure out gcc version
305 /* MinGW. Also GCC flags (DUK_F_GCC) are enabled now. */
306 #if defined(__MINGW32__) || defined(__MINGW64__)
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
317 #if defined(_MSC_FULL_VER)
318 #if (_MSC_FULL_VER > 100000000)
319 #define DUK_F_MSVC_FULL_VER _MSC_FULL_VER
321 #define DUK_F_MSCV_FULL_VER (_MSC_FULL_VER * 10)
324 #endif /* _MSC_VER */
327 #if defined(__TINYC__)
328 /* http://bellard.org/tcc/tcc-doc.html#SEC9 */
333 #if defined(__VBCC__)
338 #if defined(__MINT__)
343 * Platform autodetection
346 /* Workaround for older C++ compilers before including <inttypes.h>,
347 * see e.g.: https://sourceware.org/bugzilla/show_bug.cgi?id=15366
349 #if defined(__cplusplus) && !defined(__STDC_LIMIT_MACROS)
350 #define __STDC_LIMIT_MACROS
352 #if defined(__cplusplus) && !defined(__STDC_CONSTANT_MACROS)
353 #define __STDC_CONSTANT_MACROS
356 #if defined(DUK_F_APPLE)
357 /* --- Mac OSX, iPhone, Darwin --- */
358 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
359 #define DUK_USE_DATE_TZO_GMTIME_R
360 #define DUK_USE_DATE_PRS_STRPTIME
361 #define DUK_USE_DATE_FMT_STRFTIME
362 #include <TargetConditionals.h>
363 #include <architecture/byte_order.h>
364 #include <sys/param.h>
365 #include <sys/time.h>
368 /* http://stackoverflow.com/questions/5919996/how-to-detect-reliably-mac-os-x-ios-linux-windows-in-c-preprocessor */
369 #if TARGET_IPHONE_SIMULATOR
370 #define DUK_USE_OS_STRING "iphone-sim"
371 #elif TARGET_OS_IPHONE
372 #define DUK_USE_OS_STRING "iphone"
374 #define DUK_USE_OS_STRING "osx"
376 #define DUK_USE_OS_STRING "osx-unknown"
379 /* Use _setjmp() on Apple by default, see GH-55. */
380 #define DUK_JMPBUF_TYPE jmp_buf
381 #define DUK_SETJMP(jb) _setjmp((jb))
382 #define DUK_LONGJMP(jb) _longjmp((jb), 1)
383 #elif defined(DUK_F_OPENBSD)
384 /* --- OpenBSD --- */
385 /* http://www.monkey.org/openbsd/archive/ports/0401/msg00089.html */
386 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
387 #define DUK_USE_DATE_TZO_GMTIME_R
388 #define DUK_USE_DATE_PRS_STRPTIME
389 #define DUK_USE_DATE_FMT_STRFTIME
390 #include <sys/types.h>
391 #include <sys/endian.h>
392 #include <sys/param.h>
393 #include <sys/time.h>
396 #define DUK_USE_OS_STRING "openbsd"
397 #elif defined(DUK_F_BSD)
398 /* --- Generic BSD --- */
399 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
400 #define DUK_USE_DATE_TZO_GMTIME_R
401 #define DUK_USE_DATE_PRS_STRPTIME
402 #define DUK_USE_DATE_FMT_STRFTIME
403 #include <sys/types.h>
404 #include <sys/endian.h>
405 #include <sys/param.h>
406 #include <sys/time.h>
409 #define DUK_USE_OS_STRING "bsd"
410 #elif defined(DUK_F_TOS)
411 /* --- Atari ST TOS --- */
412 #define DUK_USE_DATE_NOW_TIME
413 #define DUK_USE_DATE_TZO_GMTIME
414 /* no parsing (not an error) */
415 #define DUK_USE_DATE_FMT_STRFTIME
418 #define DUK_USE_OS_STRING "tos"
420 /* TOS on M68K is always big endian. */
421 #if !defined(DUK_USE_BYTEORDER) && defined(DUK_F_M68K)
422 #define DUK_USE_BYTEORDER 3
424 #elif defined(DUK_F_AMIGAOS)
425 /* --- AmigaOS --- */
426 #if defined(DUK_F_M68K)
427 /* AmigaOS on M68k */
428 #define DUK_USE_DATE_NOW_TIME
429 #define DUK_USE_DATE_TZO_GMTIME
430 /* no parsing (not an error) */
431 #define DUK_USE_DATE_FMT_STRFTIME
433 #elif defined(DUK_F_PPC)
434 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
435 #define DUK_USE_DATE_TZO_GMTIME_R
436 #define DUK_USE_DATE_PRS_STRPTIME
437 #define DUK_USE_DATE_FMT_STRFTIME
440 #define UINTPTR_MAX UINT_MAX
443 #error AmigaOS but not M68K/PPC, not supported now
446 #define DUK_USE_OS_STRING "amigaos"
448 /* AmigaOS on M68K or PPC is always big endian. */
449 #if !defined(DUK_USE_BYTEORDER) && (defined(DUK_F_M68K) || defined(DUK_F_PPC))
450 #define DUK_USE_BYTEORDER 3
452 #elif defined(DUK_F_WINDOWS)
453 /* --- Windows --- */
454 /* Initial fix: disable secure CRT related warnings when compiling Duktape
455 * itself (must be defined before including Windows headers). Don't define
456 * for user code including duktape.h.
458 #if defined(DUK_COMPILING_DUKTAPE) && !defined(_CRT_SECURE_NO_WARNINGS)
459 #define _CRT_SECURE_NO_WARNINGS
462 /* Windows 32-bit and 64-bit are currently the same. */
463 /* MSVC does not have sys/param.h */
464 #define DUK_USE_DATE_NOW_WINDOWS
465 #define DUK_USE_DATE_TZO_WINDOWS
466 /* Note: PRS and FMT are intentionally left undefined for now. This means
467 * there is no platform specific date parsing/formatting but there is still
468 * the ISO 8601 standard format.
470 #if defined(DUK_COMPILING_DUKTAPE)
471 /* Only include when compiling Duktape to avoid polluting application build
472 * with a lot of unnecessary defines.
477 #define DUK_USE_OS_STRING "windows"
479 /* On Windows, assume we're little endian. Even Itanium which has a
480 * configurable endianness runs little endian in Windows.
482 #if !defined(DUK_USE_BYTEORDER)
483 #define DUK_USE_BYTEORDER 1
485 #elif defined(DUK_F_FLASHPLAYER)
486 /* --- Flashplayer (Crossbridge) --- */
487 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
488 #define DUK_USE_DATE_TZO_GMTIME_R
489 #define DUK_USE_DATE_PRS_STRPTIME
490 #define DUK_USE_DATE_FMT_STRFTIME
492 #include <sys/param.h>
493 #include <sys/time.h>
496 #define DUK_USE_OS_STRING "flashplayer"
498 #if !defined(DUK_USE_BYTEORDER) && defined(DUK_F_FLASHPLAYER)
499 #define DUK_USE_BYTEORDER 1
501 #elif defined(DUK_F_QNX)
503 #if defined(DUK_F_QNX) && defined(DUK_COMPILING_DUKTAPE)
504 /* See: /opt/qnx650/target/qnx6/usr/include/sys/platform.h */
505 #define _XOPEN_SOURCE 600
506 #define _POSIX_C_SOURCE 200112L
509 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
510 #define DUK_USE_DATE_TZO_GMTIME_R
511 #define DUK_USE_DATE_PRS_STRPTIME
512 #define DUK_USE_DATE_FMT_STRFTIME
513 #include <sys/types.h>
514 #include <sys/param.h>
515 #include <sys/time.h>
518 #define DUK_USE_OS_STRING "qnx"
519 #elif defined(DUK_F_TINSPIRE)
520 /* --- TI-Nspire --- */
521 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
522 #define DUK_USE_DATE_TZO_GMTIME_R
523 #define DUK_USE_DATE_PRS_STRPTIME
524 #define DUK_USE_DATE_FMT_STRFTIME
525 #include <sys/types.h>
526 #include <sys/param.h>
527 #include <sys/time.h>
530 #define DUK_USE_OS_STRING "tinspire"
531 #elif defined(DUK_F_EMSCRIPTEN)
532 /* --- Emscripten --- */
533 #if defined(DUK_COMPILING_DUKTAPE)
534 #ifndef _POSIX_C_SOURCE
535 #define _POSIX_C_SOURCE 200809L
538 #define _GNU_SOURCE /* e.g. getdate_r */
540 #ifndef _XOPEN_SOURCE
541 #define _XOPEN_SOURCE /* e.g. strptime */
543 #endif /* DUK_COMPILING_DUKTAPE */
545 #include <sys/types.h>
546 #if defined(DUK_F_BCC)
550 #endif /* DUK_F_BCC */
551 #include <sys/param.h>
552 #include <sys/time.h>
556 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
557 #define DUK_USE_DATE_TZO_GMTIME_R
558 #define DUK_USE_DATE_PRS_STRPTIME
559 #define DUK_USE_DATE_FMT_STRFTIME
561 #define DUK_USE_OS_STRING "emscripten"
562 #elif defined(DUK_F_LINUX)
564 #if defined(DUK_COMPILING_DUKTAPE)
565 #ifndef _POSIX_C_SOURCE
566 #define _POSIX_C_SOURCE 200809L
569 #define _GNU_SOURCE /* e.g. getdate_r */
571 #ifndef _XOPEN_SOURCE
572 #define _XOPEN_SOURCE /* e.g. strptime */
574 #endif /* DUK_COMPILING_DUKTAPE */
576 #include <sys/types.h>
577 #if defined(DUK_F_BCC)
578 /* no endian.h or stdint.h */
582 #endif /* DUK_F_BCC */
583 #include <sys/param.h>
584 #include <sys/time.h>
587 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
588 #define DUK_USE_DATE_TZO_GMTIME_R
589 #define DUK_USE_DATE_PRS_STRPTIME
590 #define DUK_USE_DATE_FMT_STRFTIME
592 #define DUK_USE_OS_STRING "linux"
593 #elif defined(DUK_F_SUN)
594 /* --- Solaris --- */
595 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
596 #define DUK_USE_DATE_TZO_GMTIME_R
597 #define DUK_USE_DATE_PRS_STRPTIME
598 #define DUK_USE_DATE_FMT_STRFTIME
600 #include <sys/types.h>
601 #include <ast/endian.h>
602 #include <sys/param.h>
603 #include <sys/time.h>
606 #define DUK_USE_OS_STRING "solaris"
607 #elif defined(DUK_F_POSIX)
608 /* --- Generic POSIX --- */
609 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
610 #define DUK_USE_DATE_TZO_GMTIME_R
611 #define DUK_USE_DATE_PRS_STRPTIME
612 #define DUK_USE_DATE_FMT_STRFTIME
613 #include <sys/types.h>
615 #include <sys/param.h>
616 #include <sys/time.h>
619 #define DUK_USE_OS_STRING "posix"
620 #elif defined(DUK_F_CYGWIN)
622 /* don't use strptime() for now */
623 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
624 #define DUK_USE_DATE_TZO_GMTIME_R
625 #define DUK_USE_DATE_FMT_STRFTIME
626 #include <sys/types.h>
628 #include <sys/param.h>
629 #include <sys/time.h>
632 #define DUK_JMPBUF_TYPE jmp_buf
633 #define DUK_SETJMP(jb) _setjmp((jb))
634 #define DUK_LONGJMP(jb) _longjmp((jb), 1)
636 #define DUK_USE_OS_STRING "windows"
637 #elif defined(DUK_F_UNIX)
638 /* --- Generic UNIX --- */
639 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
640 #define DUK_USE_DATE_TZO_GMTIME_R
641 #define DUK_USE_DATE_PRS_STRPTIME
642 #define DUK_USE_DATE_FMT_STRFTIME
644 #include <sys/time.h>
645 #define DUK_USE_OS_STRING "unknown"
647 /* --- Generic fallback --- */
648 /* The most portable current time provider is time(), but it only has a
649 * one second resolution.
651 #define DUK_USE_DATE_NOW_TIME
653 /* The most portable way to figure out local time offset is gmtime(),
654 * but it's not thread safe so use with caution.
656 #define DUK_USE_DATE_TZO_GMTIME
658 /* Avoid custom date parsing and formatting for portability. */
659 #undef DUK_USE_DATE_PRS_STRPTIME
660 #undef DUK_USE_DATE_FMT_STRFTIME
662 /* Rely on C89 headers only; time.h must be here. */
665 #define DUK_USE_OS_STRING "unknown"
666 #endif /* autodetect platform */
668 /* Shared includes: C89 */
672 #include <stdarg.h> /* varargs */
674 #include <stddef.h> /* e.g. ptrdiff_t */
678 /* date.h is omitted, and included per platform */
680 /* Shared includes: stdint.h is C99 */
681 #if defined(DUK_F_NO_STDINT_H)
682 /* stdint.h not available */
684 /* Technically C99 (C++11) but found in many systems. On some systems
685 * __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS must be defined before
686 * including stdint.h (see above).
691 #if defined(DUK_F_CPP)
692 #include <exception> /* std::exception */
696 * Architecture autodetection
699 #if defined(DUK_F_X86)
701 #define DUK_USE_ARCH_STRING "x86"
702 #if !defined(DUK_USE_BYTEORDER)
703 #define DUK_USE_BYTEORDER 1
705 /* XXX: This is technically not guaranteed because it's possible to configure
706 * an x86 to require aligned accesses with Alignment Check (AC) flag.
708 #if !defined(DUK_USE_ALIGN_BY)
709 #define DUK_USE_ALIGN_BY 1
711 #define DUK_USE_PACKED_TVAL
712 #define DUK_F_PACKED_TVAL_PROVIDED
713 #elif defined(DUK_F_X64)
715 #define DUK_USE_ARCH_STRING "x64"
716 #if !defined(DUK_USE_BYTEORDER)
717 #define DUK_USE_BYTEORDER 1
719 /* XXX: This is technically not guaranteed because it's possible to configure
720 * an x86 to require aligned accesses with Alignment Check (AC) flag.
722 #if !defined(DUK_USE_ALIGN_BY)
723 #define DUK_USE_ALIGN_BY 1
725 #undef DUK_USE_PACKED_TVAL
726 #define DUK_F_PACKED_TVAL_PROVIDED
727 #elif defined(DUK_F_X32)
729 #define DUK_USE_ARCH_STRING "x32"
730 #if !defined(DUK_USE_BYTEORDER)
731 #define DUK_USE_BYTEORDER 1
733 /* XXX: This is technically not guaranteed because it's possible to configure
734 * an x86 to require aligned accesses with Alignment Check (AC) flag.
736 #if !defined(DUK_USE_ALIGN_BY)
737 #define DUK_USE_ALIGN_BY 1
739 #define DUK_USE_PACKED_TVAL
740 #define DUK_F_PACKED_TVAL_PROVIDED
741 #elif defined(DUK_F_ARM32)
742 /* --- ARM 32-bit --- */
743 #define DUK_USE_ARCH_STRING "arm32"
744 /* Byte order varies, so rely on autodetect. */
745 #if !defined(DUK_USE_ALIGN_BY)
746 #define DUK_USE_ALIGN_BY 4
748 #define DUK_USE_PACKED_TVAL
749 #define DUK_F_PACKED_TVAL_PROVIDED
750 #elif defined(DUK_F_ARM64)
751 /* --- ARM 64-bit --- */
752 #define DUK_USE_ARCH_STRING "arm64"
753 /* Byte order varies, so rely on autodetect. */
754 #if !defined(DUK_USE_ALIGN_BY)
755 #define DUK_USE_ALIGN_BY 8
757 #undef DUK_USE_PACKED_TVAL
758 #define DUK_F_PACKED_TVAL_PROVIDED
759 #elif defined(DUK_F_MIPS32)
760 /* --- MIPS 32-bit --- */
761 #define DUK_USE_ARCH_STRING "mips32"
762 /* MIPS byte order varies so rely on autodetection. */
763 /* Based on 'make checkalign' there are no alignment requirements on
764 * Linux MIPS except for doubles, which need align by 4. Alignment
765 * requirements vary based on target though.
767 #if !defined(DUK_USE_ALIGN_BY)
768 #define DUK_USE_ALIGN_BY 4
770 #define DUK_USE_PACKED_TVAL
771 #define DUK_F_PACKED_TVAL_PROVIDED
772 #elif defined(DUK_F_MIPS64)
773 /* --- MIPS 64-bit --- */
774 #define DUK_USE_ARCH_STRING "mips64"
775 /* MIPS byte order varies so rely on autodetection. */
776 /* Good default is a bit arbitrary because alignment requirements
777 * depend on target. See https://github.com/svaarala/duktape/issues/102.
779 #if !defined(DUK_USE_ALIGN_BY)
780 #define DUK_USE_ALIGN_BY 8
782 #undef DUK_USE_PACKED_TVAL
783 #define DUK_F_PACKED_TVAL_PROVIDED
784 #elif defined(DUK_F_PPC32)
785 /* --- PowerPC 32-bit --- */
786 #define DUK_USE_ARCH_STRING "ppc32"
787 #if !defined(DUK_USE_BYTEORDER)
788 #define DUK_USE_BYTEORDER 3
790 #if !defined(DUK_USE_ALIGN_BY)
791 #define DUK_USE_ALIGN_BY 8
793 #define DUK_USE_PACKED_TVAL
794 #define DUK_F_PACKED_TVAL_PROVIDED
795 #elif defined(DUK_F_PPC64)
796 /* --- PowerPC 64-bit --- */
797 #define DUK_USE_ARCH_STRING "ppc64"
798 #if !defined(DUK_USE_BYTEORDER)
799 #define DUK_USE_BYTEORDER 3
801 #if !defined(DUK_USE_ALIGN_BY)
802 #define DUK_USE_ALIGN_BY 8
804 #undef DUK_USE_PACKED_TVAL
805 #define DUK_F_PACKED_TVAL_PROVIDED
806 #elif defined(DUK_F_SPARC32)
807 /* --- SPARC 32-bit --- */
808 #define DUK_USE_ARCH_STRING "sparc32"
809 /* SPARC byte order varies so rely on autodetection. */
810 #if !defined(DUK_USE_ALIGN_BY)
811 #define DUK_USE_ALIGN_BY 8
813 #define DUK_USE_PACKED_TVAL
814 #define DUK_F_PACKED_TVAL_PROVIDED
815 #elif defined(DUK_F_SPARC64)
816 /* --- SPARC 64-bit --- */
817 #define DUK_USE_ARCH_STRING "sparc64"
818 /* SPARC byte order varies so rely on autodetection. */
819 #if !defined(DUK_USE_ALIGN_BY)
820 #define DUK_USE_ALIGN_BY 8
822 #undef DUK_USE_PACKED_TVAL
823 #define DUK_F_PACKED_TVAL_PROVIDED
824 #elif defined(DUK_F_SUPERH)
826 #define DUK_USE_ARCH_STRING "sh"
827 /* Byte order varies, rely on autodetection. */
828 /* Based on 'make checkalign' there are no alignment requirements on
829 * Linux SH4, but align by 4 is probably a good basic default.
831 #if !defined(DUK_USE_ALIGN_BY)
832 #define DUK_USE_ALIGN_BY 4
834 #define DUK_USE_PACKED_TVAL
835 #define DUK_F_PACKED_TVAL_PROVIDED
836 #elif defined(DUK_F_M68K)
837 /* --- Motorola 68k --- */
838 #define DUK_USE_ARCH_STRING "m68k"
839 #if !defined(DUK_USE_BYTEORDER)
840 #define DUK_USE_BYTEORDER 3
842 #if !defined(DUK_USE_ALIGN_BY)
843 #define DUK_USE_ALIGN_BY 8
845 #define DUK_USE_PACKED_TVAL
846 #define DUK_F_PACKED_TVAL_PROVIDED
847 #elif defined(DUK_F_EMSCRIPTEN)
848 /* --- Emscripten --- */
849 #define DUK_USE_ARCH_STRING "emscripten"
850 #if !defined(DUK_USE_BYTEORDER)
851 #define DUK_USE_BYTEORDER 1
853 #if !defined(DUK_USE_ALIGN_BY)
854 #define DUK_USE_ALIGN_BY 8
856 #undef DUK_USE_PACKED_TVAL
857 #define DUK_F_PACKED_TVAL_PROVIDED
859 /* --- Generic --- */
860 /* These are necessary wild guesses. */
861 #define DUK_USE_ARCH_STRING "generic"
862 /* Rely on autodetection for byte order, alignment, and packed tval. */
863 #endif /* autodetect architecture */
866 * Compiler autodetection
869 #if defined(DUK_F_CLANG)
871 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
872 /* C99 / C++11 and above: rely on va_copy() which is required. */
873 #define DUK_VA_COPY(dest,src) va_copy(dest,src)
875 /* Clang: assume we have __va_copy() in non-C99 mode. */
876 #define DUK_VA_COPY(dest,src) __va_copy(dest,src)
879 #define DUK_NORETURN(decl) decl __attribute__((noreturn))
881 #if defined(__clang__) && defined(__has_builtin)
882 #if __has_builtin(__builtin_unreachable)
883 #define DUK_UNREACHABLE() do { __builtin_unreachable(); } while (0)
887 #define DUK_USE_BRANCH_HINTS
888 #define DUK_LIKELY(x) __builtin_expect((x), 1)
889 #define DUK_UNLIKELY(x) __builtin_expect((x), 0)
891 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
892 #define DUK_NOINLINE __attribute__((noinline))
893 #define DUK_INLINE inline
894 #define DUK_ALWAYS_INLINE inline __attribute__((always_inline))
897 #if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
898 /* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
899 * compiling Duktape or the application.
901 #if defined(DUK_COMPILING_DUKTAPE)
902 #define DUK_EXTERNAL_DECL extern __declspec(dllexport)
903 #define DUK_EXTERNAL __declspec(dllexport)
905 #define DUK_EXTERNAL_DECL extern __declspec(dllimport)
906 #define DUK_EXTERNAL should_not_happen
908 #if defined(DUK_SINGLE_FILE)
909 #define DUK_INTERNAL_DECL static
910 #define DUK_INTERNAL static
912 #define DUK_INTERNAL_DECL extern
913 #define DUK_INTERNAL /*empty*/
915 #define DUK_LOCAL_DECL static
916 #define DUK_LOCAL static
918 #define DUK_EXTERNAL_DECL __attribute__ ((visibility("default"))) extern
919 #define DUK_EXTERNAL __attribute__ ((visibility("default")))
920 #if defined(DUK_SINGLE_FILE)
921 #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
922 /* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
923 * Clang. Based on documentation it should suffice to have the attribute
924 * in the declaration only, but in practice some warnings are generated unless
925 * the attribute is also applied to the definition.
927 #define DUK_INTERNAL_DECL static __attribute__ ((unused))
928 #define DUK_INTERNAL static __attribute__ ((unused))
930 #define DUK_INTERNAL_DECL static
931 #define DUK_INTERNAL static
934 #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
935 #define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
936 #define DUK_INTERNAL __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
938 #define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) extern
939 #define DUK_INTERNAL __attribute__ ((visibility("hidden")))
942 #define DUK_LOCAL_DECL static
943 #define DUK_LOCAL static
946 #if defined(DUK_F_CPP)
947 #define DUK_USE_COMPILER_STRING "clang"
949 #define DUK_USE_COMPILER_STRING "clang"
952 #undef DUK_USE_VARIADIC_MACROS
953 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
954 #define DUK_USE_VARIADIC_MACROS
957 #define DUK_USE_UNION_INITIALIZERS
959 #undef DUK_USE_FLEX_C99
960 #undef DUK_USE_FLEX_ZEROSIZE
961 #undef DUK_USE_FLEX_ONESIZE
962 #if defined(DUK_F_C99)
963 #define DUK_USE_FLEX_C99
965 #define DUK_USE_FLEX_ZEROSIZE
968 #undef DUK_USE_GCC_PRAGMAS
969 #define DUK_USE_PACK_CLANG_ATTR
970 #elif defined(DUK_F_GCC)
972 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
973 /* C99 / C++11 and above: rely on va_copy() which is required. */
974 #define DUK_VA_COPY(dest,src) va_copy(dest,src)
976 /* GCC: assume we have __va_copy() in non-C99 mode. */
977 #define DUK_VA_COPY(dest,src) __va_copy(dest,src)
980 #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 20500L)
982 #define DUK_NORETURN(decl) decl __attribute__((noreturn))
985 #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40500L)
987 #define DUK_UNREACHABLE() do { __builtin_unreachable(); } while (0)
990 #define DUK_USE_BRANCH_HINTS
991 #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40500L)
992 /* GCC: test not very accurate; enable only in relatively recent builds
993 * because of bugs in gcc-4.4 (http://lists.debian.org/debian-gcc/2010/04/msg00000.html)
995 #define DUK_LIKELY(x) __builtin_expect((x), 1)
996 #define DUK_UNLIKELY(x) __builtin_expect((x), 0)
999 #if (defined(DUK_F_C99) || defined(DUK_F_CPP11)) && \
1000 defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 30101)
1001 #define DUK_NOINLINE __attribute__((noinline))
1002 #define DUK_INLINE inline
1003 #define DUK_ALWAYS_INLINE inline __attribute__((always_inline))
1006 #if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
1007 /* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
1008 * compiling Duktape or the application.
1010 #if defined(DUK_COMPILING_DUKTAPE)
1011 #define DUK_EXTERNAL_DECL extern __declspec(dllexport)
1012 #define DUK_EXTERNAL __declspec(dllexport)
1014 #define DUK_EXTERNAL_DECL extern __declspec(dllimport)
1015 #define DUK_EXTERNAL should_not_happen
1017 #if defined(DUK_SINGLE_FILE)
1018 #define DUK_INTERNAL_DECL static
1019 #define DUK_INTERNAL static
1021 #define DUK_INTERNAL_DECL extern
1022 #define DUK_INTERNAL /*empty*/
1024 #define DUK_LOCAL_DECL static
1025 #define DUK_LOCAL static
1026 #elif defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40000)
1027 #define DUK_EXTERNAL_DECL __attribute__ ((visibility("default"))) extern
1028 #define DUK_EXTERNAL __attribute__ ((visibility("default")))
1029 #if defined(DUK_SINGLE_FILE)
1030 #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
1031 /* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
1032 * Clang. Based on documentation it should suffice to have the attribute
1033 * in the declaration only, but in practice some warnings are generated unless
1034 * the attribute is also applied to the definition.
1036 #define DUK_INTERNAL_DECL static __attribute__ ((unused))
1037 #define DUK_INTERNAL static __attribute__ ((unused))
1039 #define DUK_INTERNAL_DECL static
1040 #define DUK_INTERNAL static
1043 #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
1044 #define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
1045 #define DUK_INTERNAL __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
1047 #define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) extern
1048 #define DUK_INTERNAL __attribute__ ((visibility("hidden")))
1051 #define DUK_LOCAL_DECL static
1052 #define DUK_LOCAL static
1055 #if defined(DUK_F_MINGW)
1056 #if defined(DUK_F_CPP)
1057 #define DUK_USE_COMPILER_STRING "mingw++"
1059 #define DUK_USE_COMPILER_STRING "mingw"
1062 #if defined(DUK_F_CPP)
1063 #define DUK_USE_COMPILER_STRING "g++"
1065 #define DUK_USE_COMPILER_STRING "gcc"
1069 #undef DUK_USE_VARIADIC_MACROS
1070 #if defined(DUK_F_C99) || (defined(DUK_F_CPP11) && defined(__GNUC__))
1071 #define DUK_USE_VARIADIC_MACROS
1074 #define DUK_USE_UNION_INITIALIZERS
1076 #undef DUK_USE_FLEX_C99
1077 #undef DUK_USE_FLEX_ZEROSIZE
1078 #undef DUK_USE_FLEX_ONESIZE
1079 #if defined(DUK_F_C99)
1080 #define DUK_USE_FLEX_C99
1082 #define DUK_USE_FLEX_ZEROSIZE
1085 #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40600)
1086 #define DUK_USE_GCC_PRAGMAS
1088 #undef DUK_USE_GCC_PRAGMAS
1091 #define DUK_USE_PACK_GCC_ATTR
1092 #elif defined(DUK_F_MSVC)
1094 /* http://msdn.microsoft.com/en-us/library/aa235362(VS.60).aspx */
1095 #define DUK_NORETURN(decl) __declspec(noreturn) decl
1097 /* XXX: DUK_UNREACHABLE for msvc? */
1099 #undef DUK_USE_BRANCH_HINTS
1101 /* XXX: DUK_LIKELY, DUK_UNLIKELY for msvc? */
1102 /* XXX: DUK_NOINLINE, DUK_INLINE, DUK_ALWAYS_INLINE for msvc? */
1104 #if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
1105 /* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
1106 * compiling Duktape or the application.
1108 #if defined(DUK_COMPILING_DUKTAPE)
1109 #define DUK_EXTERNAL_DECL extern __declspec(dllexport)
1110 #define DUK_EXTERNAL __declspec(dllexport)
1112 #define DUK_EXTERNAL_DECL extern __declspec(dllimport)
1113 #define DUK_EXTERNAL should_not_happen
1115 #if defined(DUK_SINGLE_FILE)
1116 #define DUK_INTERNAL_DECL static
1117 #define DUK_INTERNAL static
1119 #define DUK_INTERNAL_DECL extern
1120 #define DUK_INTERNAL /*empty*/
1122 #define DUK_LOCAL_DECL static
1123 #define DUK_LOCAL static
1126 #if defined(DUK_F_CPP)
1127 #define DUK_USE_COMPILER_STRING "msvc++"
1129 #define DUK_USE_COMPILER_STRING "msvc"
1132 #undef DUK_USE_VARIADIC_MACROS
1133 #if defined(DUK_F_C99)
1134 #define DUK_USE_VARIADIC_MACROS
1135 #elif defined(_MSC_VER) && (_MSC_VER >= 1400)
1136 /* VS2005+ should have variadic macros even when they're not C99. */
1137 #define DUK_USE_VARIADIC_MACROS
1140 #undef DUK_USE_UNION_INITIALIZERS
1141 #if defined(_MSC_VER) && (_MSC_VER >= 1800)
1142 /* VS2013+ supports union initializers but there's a bug involving union-inside-struct:
1143 * https://connect.microsoft.com/VisualStudio/feedback/details/805981
1144 * The bug was fixed (at least) in VS2015 so check for VS2015 for now:
1145 * https://blogs.msdn.microsoft.com/vcblog/2015/07/01/c-compiler-front-end-fixes-in-vs2015/
1146 * Manually tested using VS2013, CL reports 18.00.31101, so enable for VS2013 too.
1148 #define DUK_USE_UNION_INITIALIZERS
1151 #undef DUK_USE_FLEX_C99
1152 #undef DUK_USE_FLEX_ZEROSIZE
1153 #undef DUK_USE_FLEX_ONESIZE
1154 #if defined(DUK_F_C99)
1155 #define DUK_USE_FLEX_C99
1157 #define DUK_USE_FLEX_ZEROSIZE
1160 #undef DUK_USE_GCC_PRAGMAS
1162 #define DUK_USE_PACK_MSVC_PRAGMA
1164 /* These have been tested from VS2008 onwards; may work in older VS versions
1165 * too but not enabled by default.
1167 #if defined(_MSC_VER) && (_MSC_VER >= 1500)
1168 #define DUK_NOINLINE __declspec(noinline)
1169 #define DUK_INLINE __inline
1170 #define DUK_ALWAYS_INLINE __forceinline
1173 #if defined(_MSC_VER) && (_MSC_VER >= 1900)
1174 #define DUK_SNPRINTF snprintf
1175 #define DUK_VSNPRINTF vsnprintf
1177 /* (v)snprintf() is missing before MSVC 2015. Note that _(v)snprintf() does
1178 * NOT NUL terminate on truncation, but Duktape code never assumes that.
1179 * http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
1181 #define DUK_SNPRINTF _snprintf
1182 #define DUK_VSNPRINTF _vsnprintf
1184 #elif defined(DUK_F_EMSCRIPTEN)
1185 /* --- Emscripten --- */
1186 #define DUK_NORETURN(decl) decl __attribute__((noreturn))
1188 #if defined(__clang__) && defined(__has_builtin)
1189 #if __has_builtin(__builtin_unreachable)
1190 #define DUK_UNREACHABLE() do { __builtin_unreachable(); } while (0)
1194 #define DUK_USE_BRANCH_HINTS
1195 #define DUK_LIKELY(x) __builtin_expect((x), 1)
1196 #define DUK_UNLIKELY(x) __builtin_expect((x), 0)
1198 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
1199 #define DUK_NOINLINE __attribute__((noinline))
1200 #define DUK_INLINE inline
1201 #define DUK_ALWAYS_INLINE inline __attribute__((always_inline))
1204 #define DUK_EXTERNAL_DECL __attribute__ ((visibility("default"))) extern
1205 #define DUK_EXTERNAL __attribute__ ((visibility("default")))
1206 #if defined(DUK_SINGLE_FILE)
1207 #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
1208 /* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
1209 * Clang. Based on documentation it should suffice to have the attribute
1210 * in the declaration only, but in practice some warnings are generated unless
1211 * the attribute is also applied to the definition.
1213 #define DUK_INTERNAL_DECL static __attribute__ ((unused))
1214 #define DUK_INTERNAL static __attribute__ ((unused))
1216 #define DUK_INTERNAL_DECL static
1217 #define DUK_INTERNAL static
1220 #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
1221 #define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
1222 #define DUK_INTERNAL __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
1224 #define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) extern
1225 #define DUK_INTERNAL __attribute__ ((visibility("hidden")))
1228 #define DUK_LOCAL_DECL static
1229 #define DUK_LOCAL static
1231 #define DUK_USE_COMPILER_STRING "emscripten"
1233 #undef DUK_USE_VARIADIC_MACROS
1234 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
1235 #define DUK_USE_VARIADIC_MACROS
1238 #define DUK_USE_UNION_INITIALIZERS
1240 #undef DUK_USE_FLEX_C99
1241 #undef DUK_USE_FLEX_ZEROSIZE
1242 #undef DUK_USE_FLEX_ONESIZE
1243 #if defined(DUK_F_C99)
1244 #define DUK_USE_FLEX_C99
1246 #define DUK_USE_FLEX_ZEROSIZE
1249 #undef DUK_USE_GCC_PRAGMAS
1250 #define DUK_USE_PACK_CLANG_ATTR
1251 #elif defined(DUK_F_TINYC)
1253 #undef DUK_USE_BRANCH_HINTS
1255 #if defined(DUK_F_CPP)
1256 #define DUK_USE_COMPILER_STRING "tinyc++"
1258 #define DUK_USE_COMPILER_STRING "tinyc"
1261 /* http://bellard.org/tcc/tcc-doc.html#SEC7 */
1262 #define DUK_USE_VARIADIC_MACROS
1264 #define DUK_USE_UNION_INITIALIZERS
1266 /* Most portable, wastes space */
1267 #define DUK_USE_FLEX_ONESIZE
1269 /* Most portable, potentially wastes space */
1270 #define DUK_USE_PACK_DUMMY_MEMBER
1271 #elif defined(DUK_F_VBCC)
1273 #undef DUK_USE_BRANCH_HINTS
1275 #if defined(DUK_F_CPP)
1276 #define DUK_USE_COMPILER_STRING "vbcc-c++"
1278 #define DUK_USE_COMPILER_STRING "vbcc"
1281 #undef DUK_USE_VARIADIC_MACROS
1282 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
1283 #define DUK_USE_VARIADIC_MACROS
1286 /* VBCC supports C99 so check only for C99 for union initializer support.
1287 * Designated union initializers would possibly work even without a C99 check.
1289 #undef DUK_USE_UNION_INITIALIZERS
1290 #if defined(DUK_F_C99)
1291 #define DUK_USE_UNION_INITIALIZERS
1294 #define DUK_USE_FLEX_ZEROSIZE
1295 #define DUK_USE_PACK_DUMMY_MEMBER
1296 #elif defined(DUK_F_BCC)
1297 /* --- Bruce's C compiler --- */
1298 #undef DUK_USE_BRANCH_HINTS
1300 #if defined(DUK_F_CPP)
1301 #define DUK_USE_COMPILER_STRING "bcc++"
1303 #define DUK_USE_COMPILER_STRING "bcc"
1307 #undef DUK_USE_VARIADIC_MACROS
1309 /* Most portable, wastes space */
1310 #undef DUK_USE_UNION_INITIALIZERS
1312 /* Most portable, wastes space */
1313 #define DUK_USE_FLEX_ONESIZE
1315 /* Most portable, potentially wastes space */
1316 #define DUK_USE_PACK_DUMMY_MEMBER
1318 /* BCC, assume we're on x86. */
1319 #if !defined(DUK_USE_BYTEORDER)
1320 #define DUK_USE_BYTEORDER 1
1323 /* --- Generic --- */
1324 #undef DUK_USE_BRANCH_HINTS
1326 #if defined(DUK_F_CPP)
1327 #define DUK_USE_COMPILER_STRING "generic-c++"
1329 #define DUK_USE_COMPILER_STRING "generic"
1332 #undef DUK_USE_VARIADIC_MACROS
1333 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
1334 #define DUK_USE_VARIADIC_MACROS
1337 /* C++ doesn't have standard designated union initializers ({ .foo = 1 }). */
1338 #undef DUK_USE_UNION_INITIALIZERS
1339 #if defined(DUK_F_C99)
1340 #define DUK_USE_UNION_INITIALIZERS
1343 /* Most portable, wastes space */
1344 #define DUK_USE_FLEX_ONESIZE
1346 /* Most portable, potentially wastes space */
1347 #define DUK_USE_PACK_DUMMY_MEMBER
1348 #endif /* autodetect compiler */
1351 #if defined(__UCLIBC__)
1352 #define DUK_F_UCLIBC
1356 * Wrapper typedefs and constants for integer types, also sanity check types.
1358 * C99 typedefs are quite good but not always available, and we want to avoid
1359 * forcibly redefining the C99 typedefs. So, there are Duktape wrappers for
1360 * all C99 typedefs and Duktape code should only use these typedefs. Type
1361 * detection when C99 is not supported is best effort and may end up detecting
1362 * some types incorrectly.
1364 * Pointer sizes are a portability problem: pointers to different types may
1365 * have a different size and function pointers are very difficult to manage
1368 * http://en.wikipedia.org/wiki/C_data_types#Fixed-width_integer_types
1370 * Note: there's an interesting corner case when trying to define minimum
1371 * signed integer value constants which leads to the current workaround of
1372 * defining e.g. -0x80000000 as (-0x7fffffffL - 1L). See doc/code-issues.txt
1373 * for a longer discussion.
1375 * Note: avoid typecasts and computations in macro integer constants as they
1376 * can then no longer be used in macro relational expressions (such as
1377 * #if DUK_SIZE_MAX < 0xffffffffUL). There is internal code which relies on
1378 * being able to compare DUK_SIZE_MAX against a limit.
1381 /* XXX: add feature options to force basic types from outside? */
1383 #if !defined(INT_MAX)
1384 #error INT_MAX not defined
1387 /* Check that architecture is two's complement, standard C allows e.g.
1388 * INT_MIN to be -2**31+1 (instead of -2**31).
1390 #if defined(INT_MAX) && defined(INT_MIN)
1391 #if INT_MAX != -(INT_MIN + 1)
1392 #error platform does not seem complement of two
1395 #error cannot check complement of two
1398 /* Pointer size determination based on __WORDSIZE or architecture when
1399 * that's not available.
1401 #if defined(DUK_F_X86) || defined(DUK_F_X32) || \
1402 defined(DUK_F_M68K) || defined(DUK_F_PPC32) || \
1403 defined(DUK_F_BCC) || \
1404 (defined(__WORDSIZE) && (__WORDSIZE == 32))
1405 #define DUK_F_32BIT_PTRS
1406 #elif defined(DUK_F_X64) || \
1407 (defined(__WORDSIZE) && (__WORDSIZE == 64))
1408 #define DUK_F_64BIT_PTRS
1410 /* not sure, not needed with C99 anyway */
1413 /* Intermediate define for 'have inttypes.h' */
1414 #undef DUK_F_HAVE_INTTYPES
1415 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
1416 !(defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC))
1417 /* vbcc + AmigaOS has C99 but no inttypes.h */
1418 #define DUK_F_HAVE_INTTYPES
1419 #elif defined(__cplusplus) && (__cplusplus >= 201103L)
1420 /* C++11 apparently ratified stdint.h */
1421 #define DUK_F_HAVE_INTTYPES
1424 /* Basic integer typedefs and limits, preferably from inttypes.h, otherwise
1425 * through automatic detection.
1427 #if defined(DUK_F_HAVE_INTTYPES)
1428 /* C99 or compatible */
1430 #define DUK_F_HAVE_64BIT
1431 #include <inttypes.h>
1433 typedef uint8_t duk_uint8_t
;
1434 typedef int8_t duk_int8_t
;
1435 typedef uint16_t duk_uint16_t
;
1436 typedef int16_t duk_int16_t
;
1437 typedef uint32_t duk_uint32_t
;
1438 typedef int32_t duk_int32_t
;
1439 typedef uint64_t duk_uint64_t
;
1440 typedef int64_t duk_int64_t
;
1441 typedef uint_least8_t duk_uint_least8_t
;
1442 typedef int_least8_t duk_int_least8_t
;
1443 typedef uint_least16_t duk_uint_least16_t
;
1444 typedef int_least16_t duk_int_least16_t
;
1445 typedef uint_least32_t duk_uint_least32_t
;
1446 typedef int_least32_t duk_int_least32_t
;
1447 typedef uint_least64_t duk_uint_least64_t
;
1448 typedef int_least64_t duk_int_least64_t
;
1449 typedef uint_fast8_t duk_uint_fast8_t
;
1450 typedef int_fast8_t duk_int_fast8_t
;
1451 typedef uint_fast16_t duk_uint_fast16_t
;
1452 typedef int_fast16_t duk_int_fast16_t
;
1453 typedef uint_fast32_t duk_uint_fast32_t
;
1454 typedef int_fast32_t duk_int_fast32_t
;
1455 typedef uint_fast64_t duk_uint_fast64_t
;
1456 typedef int_fast64_t duk_int_fast64_t
;
1457 typedef uintptr_t duk_uintptr_t
;
1458 typedef intptr_t duk_intptr_t
;
1459 typedef uintmax_t duk_uintmax_t
;
1460 typedef intmax_t duk_intmax_t
;
1462 #define DUK_UINT8_MIN 0
1463 #define DUK_UINT8_MAX UINT8_MAX
1464 #define DUK_INT8_MIN INT8_MIN
1465 #define DUK_INT8_MAX INT8_MAX
1466 #define DUK_UINT_LEAST8_MIN 0
1467 #define DUK_UINT_LEAST8_MAX UINT_LEAST8_MAX
1468 #define DUK_INT_LEAST8_MIN INT_LEAST8_MIN
1469 #define DUK_INT_LEAST8_MAX INT_LEAST8_MAX
1470 #define DUK_UINT_FAST8_MIN 0
1471 #define DUK_UINT_FAST8_MAX UINT_FAST8_MAX
1472 #define DUK_INT_FAST8_MIN INT_FAST8_MIN
1473 #define DUK_INT_FAST8_MAX INT_FAST8_MAX
1474 #define DUK_UINT16_MIN 0
1475 #define DUK_UINT16_MAX UINT16_MAX
1476 #define DUK_INT16_MIN INT16_MIN
1477 #define DUK_INT16_MAX INT16_MAX
1478 #define DUK_UINT_LEAST16_MIN 0
1479 #define DUK_UINT_LEAST16_MAX UINT_LEAST16_MAX
1480 #define DUK_INT_LEAST16_MIN INT_LEAST16_MIN
1481 #define DUK_INT_LEAST16_MAX INT_LEAST16_MAX
1482 #define DUK_UINT_FAST16_MIN 0
1483 #define DUK_UINT_FAST16_MAX UINT_FAST16_MAX
1484 #define DUK_INT_FAST16_MIN INT_FAST16_MIN
1485 #define DUK_INT_FAST16_MAX INT_FAST16_MAX
1486 #define DUK_UINT32_MIN 0
1487 #define DUK_UINT32_MAX UINT32_MAX
1488 #define DUK_INT32_MIN INT32_MIN
1489 #define DUK_INT32_MAX INT32_MAX
1490 #define DUK_UINT_LEAST32_MIN 0
1491 #define DUK_UINT_LEAST32_MAX UINT_LEAST32_MAX
1492 #define DUK_INT_LEAST32_MIN INT_LEAST32_MIN
1493 #define DUK_INT_LEAST32_MAX INT_LEAST32_MAX
1494 #define DUK_UINT_FAST32_MIN 0
1495 #define DUK_UINT_FAST32_MAX UINT_FAST32_MAX
1496 #define DUK_INT_FAST32_MIN INT_FAST32_MIN
1497 #define DUK_INT_FAST32_MAX INT_FAST32_MAX
1498 #define DUK_UINT64_MIN 0
1499 #define DUK_UINT64_MAX UINT64_MAX
1500 #define DUK_INT64_MIN INT64_MIN
1501 #define DUK_INT64_MAX INT64_MAX
1502 #define DUK_UINT_LEAST64_MIN 0
1503 #define DUK_UINT_LEAST64_MAX UINT_LEAST64_MAX
1504 #define DUK_INT_LEAST64_MIN INT_LEAST64_MIN
1505 #define DUK_INT_LEAST64_MAX INT_LEAST64_MAX
1506 #define DUK_UINT_FAST64_MIN 0
1507 #define DUK_UINT_FAST64_MAX UINT_FAST64_MAX
1508 #define DUK_INT_FAST64_MIN INT_FAST64_MIN
1509 #define DUK_INT_FAST64_MAX INT_FAST64_MAX
1511 #define DUK_UINTPTR_MIN 0
1512 #define DUK_UINTPTR_MAX UINTPTR_MAX
1513 #define DUK_INTPTR_MIN INTPTR_MIN
1514 #define DUK_INTPTR_MAX INTPTR_MAX
1516 #define DUK_UINTMAX_MIN 0
1517 #define DUK_UINTMAX_MAX UINTMAX_MAX
1518 #define DUK_INTMAX_MIN INTMAX_MIN
1519 #define DUK_INTMAX_MAX INTMAX_MAX
1521 #define DUK_SIZE_MIN 0
1522 #define DUK_SIZE_MAX SIZE_MAX
1523 #undef DUK_SIZE_MAX_COMPUTED
1525 #else /* C99 types */
1527 /* When C99 types are not available, we use heuristic detection to get
1528 * the basic 8, 16, 32, and (possibly) 64 bit types. The fast/least
1529 * types are then assumed to be exactly the same for now: these could
1530 * be improved per platform but C99 types are very often now available.
1531 * 64-bit types are not available on all platforms; this is OK at least
1532 * on 32-bit platforms.
1534 * This detection code is necessarily a bit hacky and can provide typedefs
1535 * and defines that won't work correctly on some exotic platform.
1538 #if (defined(CHAR_BIT) && (CHAR_BIT == 8)) || \
1539 (defined(UCHAR_MAX) && (UCHAR_MAX == 255))
1540 typedef unsigned char duk_uint8_t
;
1541 typedef signed char duk_int8_t
;
1543 #error cannot detect 8-bit type
1546 #if defined(USHRT_MAX) && (USHRT_MAX == 65535UL)
1547 typedef unsigned short duk_uint16_t
;
1548 typedef signed short duk_int16_t
;
1549 #elif defined(UINT_MAX) && (UINT_MAX == 65535UL)
1550 /* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */
1551 typedef unsigned int duk_uint16_t
;
1552 typedef signed int duk_int16_t
;
1554 #error cannot detect 16-bit type
1557 #if defined(UINT_MAX) && (UINT_MAX == 4294967295UL)
1558 typedef unsigned int duk_uint32_t
;
1559 typedef signed int duk_int32_t
;
1560 #elif defined(ULONG_MAX) && (ULONG_MAX == 4294967295UL)
1561 /* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */
1562 typedef unsigned long duk_uint32_t
;
1563 typedef signed long duk_int32_t
;
1565 #error cannot detect 32-bit type
1568 /* 64-bit type detection is a bit tricky.
1570 * ULLONG_MAX is a standard define. __LONG_LONG_MAX__ and __ULONG_LONG_MAX__
1571 * are used by at least GCC (even if system headers don't provide ULLONG_MAX).
1572 * Some GCC variants may provide __LONG_LONG_MAX__ but not __ULONG_LONG_MAX__.
1574 * ULL / LL constants are rejected / warned about by some compilers, even if
1575 * the compiler has a 64-bit type and the compiler/system headers provide an
1576 * unsupported constant (ULL/LL)! Try to avoid using ULL / LL constants.
1577 * As a side effect we can only check that e.g. ULONG_MAX is larger than 32
1578 * bits but can't be sure it is exactly 64 bits. Self tests will catch such
1581 #undef DUK_F_HAVE_64BIT
1582 #if !defined(DUK_F_HAVE_64BIT) && defined(ULONG_MAX)
1583 #if (ULONG_MAX > 4294967295UL)
1584 #define DUK_F_HAVE_64BIT
1585 typedef unsigned long duk_uint64_t
;
1586 typedef signed long duk_int64_t
;
1589 #if !defined(DUK_F_HAVE_64BIT) && defined(ULLONG_MAX)
1590 #if (ULLONG_MAX > 4294967295UL)
1591 #define DUK_F_HAVE_64BIT
1592 typedef unsigned long long duk_uint64_t
;
1593 typedef signed long long duk_int64_t
;
1596 #if !defined(DUK_F_HAVE_64BIT) && defined(__ULONG_LONG_MAX__)
1597 #if (__ULONG_LONG_MAX__ > 4294967295UL)
1598 #define DUK_F_HAVE_64BIT
1599 typedef unsigned long long duk_uint64_t
;
1600 typedef signed long long duk_int64_t
;
1603 #if !defined(DUK_F_HAVE_64BIT) && defined(__LONG_LONG_MAX__)
1604 #if (__LONG_LONG_MAX__ > 2147483647L)
1605 #define DUK_F_HAVE_64BIT
1606 typedef unsigned long long duk_uint64_t
;
1607 typedef signed long long duk_int64_t
;
1610 #if !defined(DUK_F_HAVE_64BIT) && \
1611 (defined(DUK_F_MINGW) || defined(DUK_F_MSVC))
1612 /* Both MinGW and MSVC have a 64-bit type. */
1613 #define DUK_F_HAVE_64BIT
1614 typedef unsigned long duk_uint64_t
;
1615 typedef signed long duk_int64_t
;
1617 #if !defined(DUK_F_HAVE_64BIT)
1618 /* cannot detect 64-bit type, not always needed so don't error */
1621 typedef duk_uint8_t duk_uint_least8_t
;
1622 typedef duk_int8_t duk_int_least8_t
;
1623 typedef duk_uint16_t duk_uint_least16_t
;
1624 typedef duk_int16_t duk_int_least16_t
;
1625 typedef duk_uint32_t duk_uint_least32_t
;
1626 typedef duk_int32_t duk_int_least32_t
;
1627 typedef duk_uint8_t duk_uint_fast8_t
;
1628 typedef duk_int8_t duk_int_fast8_t
;
1629 typedef duk_uint16_t duk_uint_fast16_t
;
1630 typedef duk_int16_t duk_int_fast16_t
;
1631 typedef duk_uint32_t duk_uint_fast32_t
;
1632 typedef duk_int32_t duk_int_fast32_t
;
1633 #if defined(DUK_F_HAVE_64BIT)
1634 typedef duk_uint64_t duk_uint_least64_t
;
1635 typedef duk_int64_t duk_int_least64_t
;
1636 typedef duk_uint64_t duk_uint_fast64_t
;
1637 typedef duk_int64_t duk_int_fast64_t
;
1639 #if defined(DUK_F_HAVE_64BIT)
1640 typedef duk_uint64_t duk_uintmax_t
;
1641 typedef duk_int64_t duk_intmax_t
;
1643 typedef duk_uint32_t duk_uintmax_t
;
1644 typedef duk_int32_t duk_intmax_t
;
1647 /* Note: the funny looking computations for signed minimum 16-bit, 32-bit, and
1648 * 64-bit values are intentional as the obvious forms (e.g. -0x80000000L) are
1649 * -not- portable. See code-issues.txt for a detailed discussion.
1651 #define DUK_UINT8_MIN 0UL
1652 #define DUK_UINT8_MAX 0xffUL
1653 #define DUK_INT8_MIN (-0x80L)
1654 #define DUK_INT8_MAX 0x7fL
1655 #define DUK_UINT_LEAST8_MIN 0UL
1656 #define DUK_UINT_LEAST8_MAX 0xffUL
1657 #define DUK_INT_LEAST8_MIN (-0x80L)
1658 #define DUK_INT_LEAST8_MAX 0x7fL
1659 #define DUK_UINT_FAST8_MIN 0UL
1660 #define DUK_UINT_FAST8_MAX 0xffUL
1661 #define DUK_INT_FAST8_MIN (-0x80L)
1662 #define DUK_INT_FAST8_MAX 0x7fL
1663 #define DUK_UINT16_MIN 0UL
1664 #define DUK_UINT16_MAX 0xffffUL
1665 #define DUK_INT16_MIN (-0x7fffL - 1L)
1666 #define DUK_INT16_MAX 0x7fffL
1667 #define DUK_UINT_LEAST16_MIN 0UL
1668 #define DUK_UINT_LEAST16_MAX 0xffffUL
1669 #define DUK_INT_LEAST16_MIN (-0x7fffL - 1L)
1670 #define DUK_INT_LEAST16_MAX 0x7fffL
1671 #define DUK_UINT_FAST16_MIN 0UL
1672 #define DUK_UINT_FAST16_MAX 0xffffUL
1673 #define DUK_INT_FAST16_MIN (-0x7fffL - 1L)
1674 #define DUK_INT_FAST16_MAX 0x7fffL
1675 #define DUK_UINT32_MIN 0UL
1676 #define DUK_UINT32_MAX 0xffffffffUL
1677 #define DUK_INT32_MIN (-0x7fffffffL - 1L)
1678 #define DUK_INT32_MAX 0x7fffffffL
1679 #define DUK_UINT_LEAST32_MIN 0UL
1680 #define DUK_UINT_LEAST32_MAX 0xffffffffUL
1681 #define DUK_INT_LEAST32_MIN (-0x7fffffffL - 1L)
1682 #define DUK_INT_LEAST32_MAX 0x7fffffffL
1683 #define DUK_UINT_FAST32_MIN 0UL
1684 #define DUK_UINT_FAST32_MAX 0xffffffffUL
1685 #define DUK_INT_FAST32_MIN (-0x7fffffffL - 1L)
1686 #define DUK_INT_FAST32_MAX 0x7fffffffL
1688 /* 64-bit constants. Since LL / ULL constants are not always available,
1689 * use computed values. These values can't be used in preprocessor
1690 * comparisons; flag them as such.
1692 #if defined(DUK_F_HAVE_64BIT)
1693 #define DUK_UINT64_MIN ((duk_uint64_t) 0)
1694 #define DUK_UINT64_MAX ((duk_uint64_t) -1)
1695 #define DUK_INT64_MIN ((duk_int64_t) (~(DUK_UINT64_MAX >> 1)))
1696 #define DUK_INT64_MAX ((duk_int64_t) (DUK_UINT64_MAX >> 1))
1697 #define DUK_UINT_LEAST64_MIN DUK_UINT64_MIN
1698 #define DUK_UINT_LEAST64_MAX DUK_UINT64_MAX
1699 #define DUK_INT_LEAST64_MIN DUK_INT64_MIN
1700 #define DUK_INT_LEAST64_MAX DUK_INT64_MAX
1701 #define DUK_UINT_FAST64_MIN DUK_UINT64_MIN
1702 #define DUK_UINT_FAST64_MAX DUK_UINT64_MAX
1703 #define DUK_INT_FAST64_MIN DUK_INT64_MIN
1704 #define DUK_INT_FAST64_MAX DUK_INT64_MAX
1705 #define DUK_UINT64_MIN_COMPUTED
1706 #define DUK_UINT64_MAX_COMPUTED
1707 #define DUK_INT64_MIN_COMPUTED
1708 #define DUK_INT64_MAX_COMPUTED
1709 #define DUK_UINT_LEAST64_MIN_COMPUTED
1710 #define DUK_UINT_LEAST64_MAX_COMPUTED
1711 #define DUK_INT_LEAST64_MIN_COMPUTED
1712 #define DUK_INT_LEAST64_MAX_COMPUTED
1713 #define DUK_UINT_FAST64_MIN_COMPUTED
1714 #define DUK_UINT_FAST64_MAX_COMPUTED
1715 #define DUK_INT_FAST64_MIN_COMPUTED
1716 #define DUK_INT_FAST64_MAX_COMPUTED
1719 #if defined(DUK_F_HAVE_64BIT)
1720 #define DUK_UINTMAX_MIN DUK_UINT64_MIN
1721 #define DUK_UINTMAX_MAX DUK_UINT64_MAX
1722 #define DUK_INTMAX_MIN DUK_INT64_MIN
1723 #define DUK_INTMAX_MAX DUK_INT64_MAX
1724 #define DUK_UINTMAX_MIN_COMPUTED
1725 #define DUK_UINTMAX_MAX_COMPUTED
1726 #define DUK_INTMAX_MIN_COMPUTED
1727 #define DUK_INTMAX_MAX_COMPUTED
1729 #define DUK_UINTMAX_MIN 0UL
1730 #define DUK_UINTMAX_MAX 0xffffffffUL
1731 #define DUK_INTMAX_MIN (-0x7fffffffL - 1L)
1732 #define DUK_INTMAX_MAX 0x7fffffffL
1735 /* This detection is not very reliable. */
1736 #if defined(DUK_F_32BIT_PTRS)
1737 typedef duk_int32_t duk_intptr_t
;
1738 typedef duk_uint32_t duk_uintptr_t
;
1739 #define DUK_UINTPTR_MIN DUK_UINT32_MIN
1740 #define DUK_UINTPTR_MAX DUK_UINT32_MAX
1741 #define DUK_INTPTR_MIN DUK_INT32_MIN
1742 #define DUK_INTPTR_MAX DUK_INT32_MAX
1743 #elif defined(DUK_F_64BIT_PTRS) && defined(DUK_F_HAVE_64BIT)
1744 typedef duk_int64_t duk_intptr_t
;
1745 typedef duk_uint64_t duk_uintptr_t
;
1746 #define DUK_UINTPTR_MIN DUK_UINT64_MIN
1747 #define DUK_UINTPTR_MAX DUK_UINT64_MAX
1748 #define DUK_INTPTR_MIN DUK_INT64_MIN
1749 #define DUK_INTPTR_MAX DUK_INT64_MAX
1750 #define DUK_UINTPTR_MIN_COMPUTED
1751 #define DUK_UINTPTR_MAX_COMPUTED
1752 #define DUK_INTPTR_MIN_COMPUTED
1753 #define DUK_INTPTR_MAX_COMPUTED
1755 #error cannot determine intptr type
1758 /* SIZE_MAX may be missing so use an approximate value for it. */
1759 #undef DUK_SIZE_MAX_COMPUTED
1760 #if !defined(SIZE_MAX)
1761 #define DUK_SIZE_MAX_COMPUTED
1762 #define SIZE_MAX ((size_t) (-1))
1764 #define DUK_SIZE_MIN 0
1765 #define DUK_SIZE_MAX SIZE_MAX
1767 #endif /* C99 types */
1769 /* A few types are assumed to always exist. */
1770 typedef size_t duk_size_t
;
1771 typedef ptrdiff_t duk_ptrdiff_t
;
1773 /* The best type for an "all around int" in Duktape internals is "at least
1774 * 32 bit signed integer" which is most convenient. Same for unsigned type.
1775 * Prefer 'int' when large enough, as it is almost always a convenient type.
1777 #if defined(UINT_MAX) && (UINT_MAX >= 0xffffffffUL)
1778 typedef int duk_int_t
;
1779 typedef unsigned int duk_uint_t
;
1780 #define DUK_INT_MIN INT_MIN
1781 #define DUK_INT_MAX INT_MAX
1782 #define DUK_UINT_MIN 0
1783 #define DUK_UINT_MAX UINT_MAX
1785 typedef duk_int_fast32_t duk_int_t
;
1786 typedef duk_uint_fast32_t duk_uint_t
;
1787 #define DUK_INT_MIN DUK_INT_FAST32_MIN
1788 #define DUK_INT_MAX DUK_INT_FAST32_MAX
1789 #define DUK_UINT_MIN DUK_UINT_FAST32_MIN
1790 #define DUK_UINT_MAX DUK_UINT_FAST32_MAX
1793 /* Same as 'duk_int_t' but guaranteed to be a 'fast' variant if this
1794 * distinction matters for the CPU. These types are used mainly in the
1795 * executor where it might really matter.
1797 typedef duk_int_fast32_t duk_int_fast_t
;
1798 typedef duk_uint_fast32_t duk_uint_fast_t
;
1799 #define DUK_INT_FAST_MIN DUK_INT_FAST32_MIN
1800 #define DUK_INT_FAST_MAX DUK_INT_FAST32_MAX
1801 #define DUK_UINT_FAST_MIN DUK_UINT_FAST32_MIN
1802 #define DUK_UINT_FAST_MAX DUK_UINT_FAST32_MAX
1804 /* Small integers (16 bits or more) can fall back to the 'int' type, but
1805 * have a typedef so they are marked "small" explicitly.
1807 typedef int duk_small_int_t
;
1808 typedef unsigned int duk_small_uint_t
;
1809 #define DUK_SMALL_INT_MIN INT_MIN
1810 #define DUK_SMALL_INT_MAX INT_MAX
1811 #define DUK_SMALL_UINT_MIN 0
1812 #define DUK_SMALL_UINT_MAX UINT_MAX
1814 /* Fast variants of small integers, again for really fast paths like the
1817 typedef duk_int_fast16_t duk_small_int_fast_t
;
1818 typedef duk_uint_fast16_t duk_small_uint_fast_t
;
1819 #define DUK_SMALL_INT_FAST_MIN DUK_INT_FAST16_MIN
1820 #define DUK_SMALL_INT_FAST_MAX DUK_INT_FAST16_MAX
1821 #define DUK_SMALL_UINT_FAST_MIN DUK_UINT_FAST16_MIN
1822 #define DUK_SMALL_UINT_FAST_MAX DUK_UINT_FAST16_MAX
1824 /* Boolean values are represented with the platform 'int'. */
1825 typedef duk_small_int_t duk_bool_t
;
1826 #define DUK_BOOL_MIN DUK_SMALL_INT_MIN
1827 #define DUK_BOOL_MAX DUK_SMALL_INT_MAX
1829 /* Index values must have at least 32-bit signed range. */
1830 typedef duk_int_t duk_idx_t
;
1831 #define DUK_IDX_MIN DUK_INT_MIN
1832 #define DUK_IDX_MAX DUK_INT_MAX
1834 /* Unsigned index variant. */
1835 typedef duk_uint_t duk_uidx_t
;
1836 #define DUK_UIDX_MIN DUK_UINT_MIN
1837 #define DUK_UIDX_MAX DUK_UINT_MAX
1839 /* Array index values, could be exact 32 bits.
1840 * Currently no need for signed duk_arridx_t.
1842 typedef duk_uint_t duk_uarridx_t
;
1843 #define DUK_UARRIDX_MIN DUK_UINT_MIN
1844 #define DUK_UARRIDX_MAX DUK_UINT_MAX
1846 /* Duktape/C function return value, platform int is enough for now to
1847 * represent 0, 1, or negative error code. Must be compatible with
1848 * assigning truth values (e.g. duk_ret_t rc = (foo == bar);).
1850 typedef duk_small_int_t duk_ret_t
;
1851 #define DUK_RET_MIN DUK_SMALL_INT_MIN
1852 #define DUK_RET_MAX DUK_SMALL_INT_MAX
1854 /* Error codes are represented with platform int. High bits are used
1855 * for flags and such, so 32 bits are needed.
1857 typedef duk_int_t duk_errcode_t
;
1858 #define DUK_ERRCODE_MIN DUK_INT_MIN
1859 #define DUK_ERRCODE_MAX DUK_INT_MAX
1861 /* Codepoint type. Must be 32 bits or more because it is used also for
1862 * internal codepoints. The type is signed because negative codepoints
1863 * are used as internal markers (e.g. to mark EOF or missing argument).
1864 * (X)UTF-8/CESU-8 encode/decode take and return an unsigned variant to
1865 * ensure duk_uint32_t casts back and forth nicely. Almost everything
1866 * else uses the signed one.
1868 typedef duk_int_t duk_codepoint_t
;
1869 typedef duk_uint_t duk_ucodepoint_t
;
1870 #define DUK_CODEPOINT_MIN DUK_INT_MIN
1871 #define DUK_CODEPOINT_MAX DUK_INT_MAX
1872 #define DUK_UCODEPOINT_MIN DUK_UINT_MIN
1873 #define DUK_UCODEPOINT_MAX DUK_UINT_MAX
1875 /* IEEE float/double typedef. */
1876 typedef float duk_float_t
;
1877 typedef double duk_double_t
;
1879 /* We're generally assuming that we're working on a platform with a 32-bit
1880 * address space. If DUK_SIZE_MAX is a typecast value (which is necessary
1881 * if SIZE_MAX is missing), the check must be avoided because the
1882 * preprocessor can't do a comparison.
1884 #if !defined(DUK_SIZE_MAX)
1885 #error DUK_SIZE_MAX is undefined, probably missing SIZE_MAX
1886 #elif !defined(DUK_SIZE_MAX_COMPUTED)
1887 #if DUK_SIZE_MAX < 0xffffffffUL
1888 /* On some systems SIZE_MAX can be smaller than max unsigned 32-bit value
1889 * which seems incorrect if size_t is (at least) an unsigned 32-bit type.
1890 * However, it doesn't seem useful to error out compilation if this is the
1896 /* Type for public API calls. */
1897 typedef struct duk_hthread duk_context
;
1899 /* Check whether we should use 64-bit integers or not.
1901 * Quite incomplete now. Use 64-bit types if detected (C99 or other detection)
1902 * unless they are known to be unreliable. For instance, 64-bit types are
1903 * available on VBCC but seem to misbehave.
1905 #if defined(DUK_F_HAVE_64BIT) && !defined(DUK_F_VBCC)
1906 #define DUK_USE_64BIT_OPS
1908 #undef DUK_USE_64BIT_OPS
1912 * Fill-ins for platform, architecture, and compiler
1915 #if !defined(DUK_SETJMP)
1916 #define DUK_JMPBUF_TYPE jmp_buf
1917 #define DUK_SETJMP(jb) setjmp((jb))
1918 #define DUK_LONGJMP(jb) longjmp((jb), 1)
1922 /* sigsetjmp() alternative */
1923 #define DUK_JMPBUF_TYPE sigjmp_buf
1924 #define DUK_SETJMP(jb) sigsetjmp((jb))
1925 #define DUK_LONGJMP(jb) siglongjmp((jb), 1)
1928 typedef FILE duk_file
;
1929 #if !defined(DUK_STDIN)
1930 #define DUK_STDIN stdin
1932 #if !defined(DUK_STDOUT)
1933 #define DUK_STDOUT stdout
1935 #if !defined(DUK_STDERR)
1936 #define DUK_STDERR stderr
1939 /* Special naming to avoid conflict with e.g. DUK_FREE() in duk_heap.h
1940 * (which is unfortunately named). May sometimes need replacement, e.g.
1941 * some compilers don't handle zero length or NULL correctly in realloc().
1943 #if !defined(DUK_ANSI_MALLOC)
1944 #define DUK_ANSI_MALLOC malloc
1946 #if !defined(DUK_ANSI_REALLOC)
1947 #define DUK_ANSI_REALLOC realloc
1949 #if !defined(DUK_ANSI_CALLOC)
1950 #define DUK_ANSI_CALLOC calloc
1952 #if !defined(DUK_ANSI_FREE)
1953 #define DUK_ANSI_FREE free
1956 /* ANSI C (various versions) and some implementations require that the
1957 * pointer arguments to memset(), memcpy(), and memmove() be valid values
1958 * even when byte size is 0 (even a NULL pointer is considered invalid in
1959 * this context). Zero-size operations as such are allowed, as long as their
1960 * pointer arguments point to a valid memory area. The DUK_MEMSET(),
1961 * DUK_MEMCPY(), and DUK_MEMMOVE() macros require this same behavior, i.e.:
1962 * (1) pointers must be valid and non-NULL, (2) zero size must otherwise be
1963 * allowed. If these are not fulfilled, a macro wrapper is needed.
1965 * http://stackoverflow.com/questions/5243012/is-it-guaranteed-to-be-safe-to-perform-memcpy0-0-0
1966 * http://lists.cs.uiuc.edu/pipermail/llvmdev/2007-October/011065.html
1968 * Not sure what's the required behavior when a pointer points just past the
1969 * end of a buffer, which often happens in practice (e.g. zero size memmoves).
1970 * For example, if allocation size is 3, the following pointer would not
1971 * technically point to a valid memory byte:
1974 * | 0 | 1 | 2 | .....
1975 * ^-- p=3, points after last valid byte (2)
1977 #if !defined(DUK_MEMCPY)
1978 #if defined(DUK_F_UCLIBC)
1979 /* Old uclibcs have a broken memcpy so use memmove instead (this is overly wide
1980 * now on purpose): http://lists.uclibc.org/pipermail/uclibc-cvs/2008-October/025511.html
1982 #define DUK_MEMCPY memmove
1984 #define DUK_MEMCPY memcpy
1987 #if !defined(DUK_MEMMOVE)
1988 #define DUK_MEMMOVE memmove
1990 #if !defined(DUK_MEMCMP)
1991 #define DUK_MEMCMP memcmp
1993 #if !defined(DUK_MEMSET)
1994 #define DUK_MEMSET memset
1996 #if !defined(DUK_STRLEN)
1997 #define DUK_STRLEN strlen
1999 #if !defined(DUK_STRCMP)
2000 #define DUK_STRCMP strcmp
2002 #if !defined(DUK_STRNCMP)
2003 #define DUK_STRNCMP strncmp
2005 #if !defined(DUK_PRINTF)
2006 #define DUK_PRINTF printf
2008 #if !defined(DUK_FPRINTF)
2009 #define DUK_FPRINTF fprintf
2011 #if !defined(DUK_SPRINTF)
2012 #define DUK_SPRINTF sprintf
2014 #if !defined(DUK_SNPRINTF)
2015 /* snprintf() is technically not part of C89 but usually available. */
2016 #define DUK_SNPRINTF snprintf
2018 #if !defined(DUK_VSPRINTF)
2019 #define DUK_VSPRINTF vsprintf
2021 #if !defined(DUK_VSNPRINTF)
2022 /* vsnprintf() is technically not part of C89 but usually available. */
2023 #define DUK_VSNPRINTF vsnprintf
2025 #if !defined(DUK_SSCANF)
2026 #define DUK_SSCANF sscanf
2028 #if !defined(DUK_VSSCANF)
2029 #define DUK_VSSCANF vsscanf
2031 #if !defined(DUK_FOPEN)
2032 #define DUK_FOPEN fopen
2034 #if !defined(DUK_FCLOSE)
2035 #define DUK_FCLOSE fclose
2037 #if !defined(DUK_FREAD)
2038 #define DUK_FREAD fread
2040 #if !defined(DUK_FWRITE)
2041 #define DUK_FWRITE fwrite
2043 #if !defined(DUK_FSEEK)
2044 #define DUK_FSEEK fseek
2046 #if !defined(DUK_FTELL)
2047 #define DUK_FTELL ftell
2049 #if !defined(DUK_FFLUSH)
2050 #define DUK_FFLUSH fflush
2052 #if !defined(DUK_FPUTC)
2053 #define DUK_FPUTC fputc
2055 #if !defined(DUK_MEMZERO)
2056 #define DUK_MEMZERO(p,n) DUK_MEMSET((p), 0, (n))
2058 #if !defined(DUK_ABORT)
2059 #define DUK_ABORT abort
2061 #if !defined(DUK_EXIT)
2062 #define DUK_EXIT exit
2065 #if !defined(DUK_DOUBLE_2TO32)
2066 #define DUK_DOUBLE_2TO32 4294967296.0
2068 #if !defined(DUK_DOUBLE_2TO31)
2069 #define DUK_DOUBLE_2TO31 2147483648.0
2072 #if !defined(DUK_DOUBLE_INFINITY)
2073 #undef DUK_USE_COMPUTED_INFINITY
2074 #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION < 40600)
2075 /* GCC older than 4.6: avoid overflow warnings related to using INFINITY */
2076 #define DUK_DOUBLE_INFINITY (__builtin_inf())
2077 #elif defined(INFINITY)
2078 #define DUK_DOUBLE_INFINITY ((double) INFINITY)
2079 #elif !defined(DUK_F_VBCC) && !defined(DUK_F_MSVC) && !defined(DUK_F_BCC)
2080 #define DUK_DOUBLE_INFINITY (1.0 / 0.0)
2082 /* In VBCC (1.0 / 0.0) results in a warning and 0.0 instead of infinity.
2083 * Use a computed infinity (initialized when a heap is created at the
2086 #define DUK_USE_COMPUTED_INFINITY
2087 #define DUK_DOUBLE_INFINITY duk_computed_infinity
2091 #if !defined(DUK_DOUBLE_NAN)
2092 #undef DUK_USE_COMPUTED_NAN
2094 #define DUK_DOUBLE_NAN NAN
2095 #elif !defined(DUK_F_VBCC) && !defined(DUK_F_MSVC) && !defined(DUK_F_BCC)
2096 #define DUK_DOUBLE_NAN (0.0 / 0.0)
2098 /* In VBCC (0.0 / 0.0) results in a warning and 0.0 instead of NaN.
2099 * In MSVC (VS2010 Express) (0.0 / 0.0) results in a compile error.
2100 * Use a computed NaN (initialized when a heap is created at the
2103 #define DUK_USE_COMPUTED_NAN
2104 #define DUK_DOUBLE_NAN duk_computed_nan
2108 /* Many platforms are missing fpclassify() and friends, so use replacements
2109 * if necessary. The replacement constants (FP_NAN etc) can be anything but
2110 * match Linux constants now.
2112 #undef DUK_USE_REPL_FPCLASSIFY
2113 #undef DUK_USE_REPL_SIGNBIT
2114 #undef DUK_USE_REPL_ISFINITE
2115 #undef DUK_USE_REPL_ISNAN
2116 #undef DUK_USE_REPL_ISINF
2118 /* Complex condition broken into separate parts. */
2119 #undef DUK_F_USE_REPL_ALL
2120 #if !(defined(FP_NAN) && defined(FP_INFINITE) && defined(FP_ZERO) && \
2121 defined(FP_SUBNORMAL) && defined(FP_NORMAL))
2122 /* Missing some obvious constants. */
2123 #define DUK_F_USE_REPL_ALL
2124 #elif defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC)
2125 /* VBCC is missing the built-ins even in C99 mode (perhaps a header issue). */
2126 #define DUK_F_USE_REPL_ALL
2127 #elif defined(DUK_F_AMIGAOS) && defined(DUK_F_M68K)
2128 /* AmigaOS + M68K seems to have math issues even when using GCC cross
2129 * compilation. Use replacements for all AmigaOS versions on M68K
2130 * regardless of compiler.
2132 #define DUK_F_USE_REPL_ALL
2133 #elif defined(DUK_F_FREEBSD) && defined(DUK_F_CLANG)
2134 /* Placeholder fix for (detection is wider than necessary):
2135 * http://llvm.org/bugs/show_bug.cgi?id=17788
2137 #define DUK_F_USE_REPL_ALL
2138 #elif defined(DUK_F_UCLIBC)
2139 /* At least some uclibc versions have broken floating point math. For
2140 * example, fpclassify() can incorrectly classify certain NaN formats.
2141 * To be safe, use replacements.
2143 #define DUK_F_USE_REPL_ALL
2146 #if defined(DUK_F_USE_REPL_ALL)
2147 #define DUK_USE_REPL_FPCLASSIFY
2148 #define DUK_USE_REPL_SIGNBIT
2149 #define DUK_USE_REPL_ISFINITE
2150 #define DUK_USE_REPL_ISNAN
2151 #define DUK_USE_REPL_ISINF
2152 #define DUK_FPCLASSIFY duk_repl_fpclassify
2153 #define DUK_SIGNBIT duk_repl_signbit
2154 #define DUK_ISFINITE duk_repl_isfinite
2155 #define DUK_ISNAN duk_repl_isnan
2156 #define DUK_ISINF duk_repl_isinf
2157 #define DUK_FP_NAN 0
2158 #define DUK_FP_INFINITE 1
2159 #define DUK_FP_ZERO 2
2160 #define DUK_FP_SUBNORMAL 3
2161 #define DUK_FP_NORMAL 4
2163 #define DUK_FPCLASSIFY fpclassify
2164 #define DUK_SIGNBIT signbit
2165 #define DUK_ISFINITE isfinite
2166 #define DUK_ISNAN isnan
2167 #define DUK_ISINF isinf
2168 #define DUK_FP_NAN FP_NAN
2169 #define DUK_FP_INFINITE FP_INFINITE
2170 #define DUK_FP_ZERO FP_ZERO
2171 #define DUK_FP_SUBNORMAL FP_SUBNORMAL
2172 #define DUK_FP_NORMAL FP_NORMAL
2175 #if defined(DUK_F_USE_REPL_ALL)
2176 #undef DUK_F_USE_REPL_ALL
2179 /* Some math functions are C99 only. This is also an issue with some
2180 * embedded environments using uclibc where uclibc has been configured
2181 * not to provide some functions. For now, use replacements whenever
2184 #undef DUK_USE_MATH_FMIN
2185 #undef DUK_USE_MATH_FMAX
2186 #undef DUK_USE_MATH_ROUND
2187 #if defined(DUK_F_UCLIBC)
2188 /* uclibc may be missing these */
2189 #elif defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC)
2190 /* vbcc + AmigaOS may be missing these */
2191 #elif defined(DUK_F_MINT)
2192 /* mint clib is missing these */
2193 #elif !defined(DUK_F_C99) && !defined(DUK_F_CPP11)
2194 /* build is not C99 or C++11, play it safe */
2196 /* C99 or C++11, no known issues */
2197 #define DUK_USE_MATH_FMIN
2198 #define DUK_USE_MATH_FMAX
2199 #define DUK_USE_MATH_ROUND
2202 /* These functions don't currently need replacement but are wrapped for
2203 * completeness. Because these are used as function pointers, they need
2204 * to be defined as concrete C functions (not macros).
2206 #if !defined(DUK_FABS)
2207 #define DUK_FABS fabs
2209 #if !defined(DUK_FMIN)
2210 #define DUK_FMIN fmin
2212 #if !defined(DUK_FMAX)
2213 #define DUK_FMAX fmax
2215 #if !defined(DUK_FLOOR)
2216 #define DUK_FLOOR floor
2218 #if !defined(DUK_CEIL)
2219 #define DUK_CEIL ceil
2221 #if !defined(DUK_FMOD)
2222 #define DUK_FMOD fmod
2224 #if !defined(DUK_POW)
2227 #if !defined(DUK_ACOS)
2228 #define DUK_ACOS acos
2230 #if !defined(DUK_ASIN)
2231 #define DUK_ASIN asin
2233 #if !defined(DUK_ATAN)
2234 #define DUK_ATAN atan
2236 #if !defined(DUK_ATAN2)
2237 #define DUK_ATAN2 atan2
2239 #if !defined(DUK_SIN)
2242 #if !defined(DUK_COS)
2245 #if !defined(DUK_TAN)
2248 #if !defined(DUK_EXP)
2251 #if !defined(DUK_LOG)
2254 #if !defined(DUK_SQRT)
2255 #define DUK_SQRT sqrt
2258 /* NetBSD 6.0 x86 (at least) has a few problems with pow() semantics,
2259 * see test-bug-netbsd-math-pow.js. Use NetBSD specific workaround.
2260 * (This might be a wider problem; if so, generalize the define name.)
2262 #undef DUK_USE_POW_NETBSD_WORKAROUND
2263 #if defined(DUK_F_NETBSD)
2264 #define DUK_USE_POW_NETBSD_WORKAROUND
2267 /* Rely as little as possible on compiler behavior for NaN comparison,
2268 * signed zero handling, etc. Currently never activated but may be needed
2269 * for broken compilers.
2271 #undef DUK_USE_PARANOID_MATH
2273 /* There was a curious bug where test-bi-date-canceling.js would fail e.g.
2274 * on 64-bit Ubuntu, gcc-4.8.1, -m32, and no -std=c99. Some date computations
2275 * using doubles would be optimized which then broke some corner case tests.
2276 * The problem goes away by adding 'volatile' to the datetime computations.
2277 * Not sure what the actual triggering conditions are, but using this on
2278 * non-C99 systems solves the known issues and has relatively little cost
2279 * on other platforms.
2281 #undef DUK_USE_PARANOID_DATE_COMPUTATION
2282 #if !defined(DUK_F_C99)
2283 #define DUK_USE_PARANOID_DATE_COMPUTATION
2287 * Byte order and double memory layout detection
2289 * Endianness detection is a major portability hassle because the macros
2290 * and headers are not standardized. There's even variance across UNIX
2291 * platforms. Even with "standard" headers, details like underscore count
2292 * varies between platforms, e.g. both __BYTE_ORDER and _BYTE_ORDER are used
2293 * (Crossbridge has a single underscore, for instance).
2295 * The checks below are structured with this in mind: several approaches are
2296 * used, and at the end we check if any of them worked. This allows generic
2297 * approaches to be tried first, and platform/compiler specific hacks tried
2298 * last. As a last resort, the user can force a specific endianness, as it's
2299 * not likely that automatic detection will work on the most exotic platforms.
2301 * Duktape supports little and big endian machines. There's also support
2302 * for a hybrid used by some ARM machines where integers are little endian
2303 * but IEEE double values use a mixed order (12345678 -> 43218765). This
2304 * byte order for doubles is referred to as "mixed endian".
2307 /* For custom platforms allow user to define byteorder explicitly.
2308 * Since endianness headers are not standardized, this is a useful
2309 * workaround for custom platforms for which endianness detection
2310 * is not directly supported. Perhaps custom hardware is used and
2311 * user cannot submit upstream patches.
2313 #if defined(DUK_OPT_FORCE_BYTEORDER)
2314 #undef DUK_USE_BYTEORDER
2315 #if (DUK_OPT_FORCE_BYTEORDER == 1)
2316 #define DUK_USE_BYTEORDER 1
2317 #elif (DUK_OPT_FORCE_BYTEORDER == 2)
2318 #define DUK_USE_BYTEORDER 2
2319 #elif (DUK_OPT_FORCE_BYTEORDER == 3)
2320 #define DUK_USE_BYTEORDER 3
2322 #error invalid DUK_OPT_FORCE_BYTEORDER value
2324 #endif /* DUK_OPT_FORCE_BYTEORDER */
2326 /* GCC and Clang provide endianness defines as built-in predefines, with
2327 * leading and trailing double underscores (e.g. __BYTE_ORDER__). See
2328 * output of "make gccpredefs" and "make clangpredefs". Clang doesn't
2329 * seem to provide __FLOAT_WORD_ORDER__; assume not mixed endian for clang.
2330 * http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
2332 #if !defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__)
2333 #if defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
2334 #if defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__)
2335 #define DUK_USE_BYTEORDER 1
2336 #elif defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)
2337 #define DUK_USE_BYTEORDER 2
2338 #elif !defined(__FLOAT_WORD_ORDER__)
2339 /* Float word order not known, assume not a hybrid. */
2340 #define DUK_USE_BYTEORDER 1
2342 /* Byte order is little endian but cannot determine IEEE double word order. */
2343 #endif /* float word order */
2344 #elif defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
2345 #if defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)
2346 #define DUK_USE_BYTEORDER 3
2347 #elif !defined(__FLOAT_WORD_ORDER__)
2348 /* Float word order not known, assume not a hybrid. */
2349 #define DUK_USE_BYTEORDER 3
2351 /* Byte order is big endian but cannot determine IEEE double word order. */
2352 #endif /* float word order */
2354 /* Cannot determine byte order; __ORDER_PDP_ENDIAN__ is related to 32-bit
2355 * integer ordering and is not relevant.
2357 #endif /* integer byte order */
2358 #endif /* !defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__) */
2360 /* More or less standard endianness predefines provided by header files.
2361 * The ARM hybrid case is detected by assuming that __FLOAT_WORD_ORDER
2362 * will be big endian, see: http://lists.mysql.com/internals/443.
2363 * On some platforms some defines may be present with an empty value which
2364 * causes comparisons to fail: https://github.com/svaarala/duktape/issues/453.
2366 #if !defined(DUK_USE_BYTEORDER)
2367 #if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && (__BYTE_ORDER == __LITTLE_ENDIAN) || \
2368 defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN) && (_BYTE_ORDER == _LITTLE_ENDIAN) || \
2369 defined(__LITTLE_ENDIAN__)
2370 #if defined(__FLOAT_WORD_ORDER) && defined(__LITTLE_ENDIAN) && (__FLOAT_WORD_ORDER == __LITTLE_ENDIAN) || \
2371 defined(_FLOAT_WORD_ORDER) && defined(_LITTLE_ENDIAN) && (_FLOAT_WORD_ORDER == _LITTLE_ENDIAN)
2372 #define DUK_USE_BYTEORDER 1
2373 #elif defined(__FLOAT_WORD_ORDER) && defined(__BIG_ENDIAN) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) || \
2374 defined(_FLOAT_WORD_ORDER) && defined(_BIG_ENDIAN) && (_FLOAT_WORD_ORDER == _BIG_ENDIAN)
2375 #define DUK_USE_BYTEORDER 2
2376 #elif !defined(__FLOAT_WORD_ORDER) && !defined(_FLOAT_WORD_ORDER)
2377 /* Float word order not known, assume not a hybrid. */
2378 #define DUK_USE_BYTEORDER 1
2380 /* Byte order is little endian but cannot determine IEEE double word order. */
2381 #endif /* float word order */
2382 #elif defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && (__BYTE_ORDER == __BIG_ENDIAN) || \
2383 defined(_BYTE_ORDER) && defined(_BIG_ENDIAN) && (_BYTE_ORDER == _BIG_ENDIAN) || \
2384 defined(__BIG_ENDIAN__)
2385 #if defined(__FLOAT_WORD_ORDER) && defined(__BIG_ENDIAN) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) || \
2386 defined(_FLOAT_WORD_ORDER) && defined(_BIG_ENDIAN) && (_FLOAT_WORD_ORDER == _BIG_ENDIAN)
2387 #define DUK_USE_BYTEORDER 3
2388 #elif !defined(__FLOAT_WORD_ORDER) && !defined(_FLOAT_WORD_ORDER)
2389 /* Float word order not known, assume not a hybrid. */
2390 #define DUK_USE_BYTEORDER 3
2392 /* Byte order is big endian but cannot determine IEEE double word order. */
2393 #endif /* float word order */
2395 /* Cannot determine byte order. */
2396 #endif /* integer byte order */
2397 #endif /* !defined(DUK_USE_BYTEORDER) */
2399 /* QNX gcc cross compiler seems to define e.g. __LITTLEENDIAN__ or __BIGENDIAN__:
2400 * $ /opt/qnx650/host/linux/x86/usr/bin/i486-pc-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
2401 * 67:#define __LITTLEENDIAN__ 1
2402 * $ /opt/qnx650/host/linux/x86/usr/bin/mips-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
2403 * 81:#define __BIGENDIAN__ 1
2404 * $ /opt/qnx650/host/linux/x86/usr/bin/arm-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
2405 * 70:#define __LITTLEENDIAN__ 1
2407 #if !defined(DUK_USE_BYTEORDER)
2408 #if defined(__LITTLEENDIAN__)
2409 #define DUK_USE_BYTEORDER 1
2410 #elif defined(__BIGENDIAN__)
2411 #define DUK_USE_BYTEORDER 3
2416 * Alignment requirement and support for unaligned accesses
2418 * Assume unaligned accesses are not supported unless specifically allowed
2419 * in the target platform. Some platforms may support unaligned accesses
2420 * but alignment to 4 or 8 may still be desirable.
2423 /* If not provided, use safe default for alignment. */
2424 #if !defined(DUK_USE_ALIGN_BY)
2425 #define DUK_USE_ALIGN_BY 8
2428 /* User forced alignment to 4 or 8. */
2429 #if defined(DUK_OPT_FORCE_ALIGN)
2430 #undef DUK_USE_ALIGN_BY
2431 #if (DUK_OPT_FORCE_ALIGN == 4)
2432 #define DUK_USE_ALIGN_BY 4
2433 #elif (DUK_OPT_FORCE_ALIGN == 8)
2434 #define DUK_USE_ALIGN_BY 8
2436 #error invalid DUK_OPT_FORCE_ALIGN value
2440 /* Compiler specific hackery needed to force struct size to match aligment,
2441 * see e.g. duk_hbuffer.h.
2443 * http://stackoverflow.com/questions/11130109/c-struct-size-alignment
2444 * http://stackoverflow.com/questions/10951039/specifying-64-bit-alignment
2446 #if !(defined(DUK_USE_PACK_MSVC_PRAGMA) || defined(DUK_USE_PACK_GCC_ATTR) || \
2447 defined(DUK_USE_PACK_CLANG_ATTR) || defined(DUK_USE_PACK_DUMMY_MEMBER))
2448 #define DUK_USE_PACK_DUMMY_MEMBER
2451 #if !defined(DUK_VA_COPY)
2452 /* We need va_copy() which is defined in C99 / C++11, so an awkward
2453 * replacement is needed for pre-C99 / pre-C++11 environments. This
2454 * will quite likely need portability hacks for some non-C99
2457 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
2458 /* C99 / C++11 and above: rely on va_copy() which is required.
2459 * Omit parenthesis on macro right side on purpose to minimize differences
2462 #define DUK_VA_COPY(dest,src) va_copy(dest,src)
2464 /* Pre-C99: va_list type is implementation dependent. This replacement
2465 * assumes it is a plain value so that a simple assignment will work.
2466 * This is not the case on all platforms (it may be a single-array element,
2469 #define DUK_VA_COPY(dest,src) do { (dest) = (src); } while (0)
2473 #if !defined(DUK_MACRO_STRINGIFY)
2474 /* Macro hackery to convert e.g. __LINE__ to a string without formatting,
2475 * see: http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string
2477 #define DUK_MACRO_STRINGIFY_HELPER(x) #x
2478 #define DUK_MACRO_STRINGIFY(x) DUK_MACRO_STRINGIFY_HELPER(x)
2481 #if !defined(DUK_CAUSE_SEGFAULT)
2482 /* This is optionally used by panic handling to cause the program to segfault
2483 * (instead of e.g. abort()) on panic. Valgrind will then indicate the C
2484 * call stack leading to the panic.
2486 #define DUK_CAUSE_SEGFAULT() do { *((volatile duk_uint32_t *) NULL) = (duk_uint32_t) 0xdeadbeefUL; } while (0)
2488 #if !defined(DUK_UNREF)
2489 /* Macro for suppressing warnings for potentially unreferenced variables.
2490 * The variables can be actually unreferenced or unreferenced in some
2491 * specific cases only; for instance, if a variable is only debug printed,
2492 * it is unreferenced when debug printing is disabled.
2494 #define DUK_UNREF(x) do { (void) (x); } while (0)
2496 #if !defined(DUK_NORETURN)
2497 #define DUK_NORETURN(decl) decl
2499 #if !defined(DUK_UNREACHABLE)
2500 /* Don't know how to declare unreachable point, so don't do it; this
2501 * may cause some spurious compilation warnings (e.g. "variable used
2504 #define DUK_UNREACHABLE() do { } while (0)
2506 #if !defined(DUK_LOSE_CONST)
2507 /* Convert any input pointer into a "void *", losing a const qualifier.
2508 * This is not fully portable because casting through duk_uintptr_t may
2509 * not work on all architectures (e.g. those with long, segmented pointers).
2511 #define DUK_LOSE_CONST(src) ((void *) (duk_uintptr_t) (src))
2514 #if !defined(DUK_LIKELY)
2515 #define DUK_LIKELY(x) (x)
2517 #if !defined(DUK_UNLIKELY)
2518 #define DUK_UNLIKELY(x) (x)
2521 #if !defined(DUK_NOINLINE)
2522 #define DUK_NOINLINE /*nop*/
2524 #if !defined(DUK_INLINE)
2525 #define DUK_INLINE /*nop*/
2527 #if !defined(DUK_ALWAYS_INLINE)
2528 #define DUK_ALWAYS_INLINE /*nop*/
2531 #if !defined(DUK_EXTERNAL_DECL)
2532 #define DUK_EXTERNAL_DECL extern
2534 #if !defined(DUK_EXTERNAL)
2535 #define DUK_EXTERNAL /*empty*/
2537 #if !defined(DUK_INTERNAL_DECL)
2538 #if defined(DUK_SINGLE_FILE)
2539 #define DUK_INTERNAL_DECL static
2541 #define DUK_INTERNAL_DECL extern
2544 #if !defined(DUK_INTERNAL)
2545 #if defined(DUK_SINGLE_FILE)
2546 #define DUK_INTERNAL static
2548 #define DUK_INTERNAL /*empty*/
2551 #if !defined(DUK_LOCAL_DECL)
2552 #define DUK_LOCAL_DECL static
2554 #if !defined(DUK_LOCAL)
2555 #define DUK_LOCAL static
2558 #if !defined(DUK_FILE_MACRO)
2559 #define DUK_FILE_MACRO __FILE__
2561 #if !defined(DUK_LINE_MACRO)
2562 #define DUK_LINE_MACRO __LINE__
2564 #if !defined(DUK_FUNC_MACRO)
2565 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
2566 #define DUK_FUNC_MACRO __func__
2567 #elif defined(__FUNCTION__)
2568 #define DUK_FUNC_MACRO __FUNCTION__
2570 #define DUK_FUNC_MACRO "unknown"
2574 #if !defined(DUK_BSWAP32)
2575 #define DUK_BSWAP32(x) \
2576 ((((duk_uint32_t) (x)) >> 24) | \
2577 ((((duk_uint32_t) (x)) >> 8) & 0xff00UL) | \
2578 ((((duk_uint32_t) (x)) << 8) & 0xff0000UL) | \
2579 (((duk_uint32_t) (x)) << 24))
2581 #if !defined(DUK_BSWAP16)
2582 #define DUK_BSWAP16(x) \
2583 ((duk_uint16_t) (x) >> 8) | \
2584 ((duk_uint16_t) (x) << 8)
2587 /* DUK_USE_VARIADIC_MACROS: required from compilers, so no fill-in. */
2588 /* DUK_USE_UNION_INITIALIZERS: required from compilers, so no fill-in. */
2590 #if !(defined(DUK_USE_FLEX_C99) || defined(DUK_USE_FLEX_ZEROSIZE) || defined(DUK_USE_FLEX_ONESIZE))
2591 #if defined(DUK_F_C99)
2592 #define DUK_USE_FLEX_C99
2594 #define DUK_USE_FLEX_ZEROSIZE /* Not standard but common enough */
2598 #if !(defined(DUK_USE_PACK_GCC_ATTR) || defined(DUK_USE_PACK_CLANG_ATTR) || \
2599 defined(DUK_USE_PACK_MSVC_PRAGMA) || defined(DUK_USE_PACK_DUMMY_MEMBER))
2600 #define DUK_USE_PACK_DUMMY_MEMBER
2603 #if 0 /* not defined by default */
2604 #undef DUK_USE_GCC_PRAGMAS
2607 /* Workaround for GH-323: avoid inlining control when compiling from
2608 * multiple sources, as it causes compiler portability trouble.
2610 #if !defined(DUK_SINGLE_FILE)
2613 #undef DUK_ALWAYS_INLINE
2614 #define DUK_NOINLINE /*nop*/
2615 #define DUK_INLINE /*nop*/
2616 #define DUK_ALWAYS_INLINE /*nop*/
2620 * Check whether or not a packed duk_tval representation is possible.
2621 * What's basically required is that pointers are 32-bit values
2622 * (sizeof(void *) == 4). Best effort check, not always accurate.
2623 * If guess goes wrong, crashes may result; self tests also verify
2627 /* Explicit marker needed; may be 'defined', 'undefined, 'or 'not provided'. */
2628 #if !defined(DUK_F_PACKED_TVAL_PROVIDED)
2629 #undef DUK_F_PACKED_TVAL_POSSIBLE
2631 /* Strict C99 case: DUK_UINTPTR_MAX (= UINTPTR_MAX) should be very reliable */
2632 #if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_UINTPTR_MAX)
2633 #if (DUK_UINTPTR_MAX <= 0xffffffffUL)
2634 #define DUK_F_PACKED_TVAL_POSSIBLE
2638 /* Non-C99 case, still relying on DUK_UINTPTR_MAX, as long as it is not a computed value */
2639 #if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_UINTPTR_MAX) && !defined(DUK_UINTPTR_MAX_COMPUTED)
2640 #if (DUK_UINTPTR_MAX <= 0xffffffffUL)
2641 #define DUK_F_PACKED_TVAL_POSSIBLE
2645 /* DUK_SIZE_MAX (= SIZE_MAX) is often reliable */
2646 #if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_SIZE_MAX) && !defined(DUK_SIZE_MAX_COMPUTED)
2647 #if (DUK_SIZE_MAX <= 0xffffffffUL)
2648 #define DUK_F_PACKED_TVAL_POSSIBLE
2652 #undef DUK_USE_PACKED_TVAL
2653 #if defined(DUK_F_PACKED_TVAL_POSSIBLE)
2654 #define DUK_USE_PACKED_TVAL
2657 #undef DUK_F_PACKED_TVAL_POSSIBLE
2658 #endif /* DUK_F_PACKED_TVAL_PROVIDED */
2660 /* Feature option forcing. */
2661 #if defined(DUK_OPT_NO_PACKED_TVAL)
2662 #undef DUK_USE_PACKED_TVAL
2663 #elif defined(DUK_OPT_PACKED_TVAL)
2664 #undef DUK_USE_PACKED_TVAL
2665 #define DUK_USE_PACKED_TVAL
2667 /* Object property allocation layout has implications for memory and code
2668 * footprint and generated code size/speed. The best layout also depends
2669 * on whether the platform has alignment requirements or benefits from
2670 * having mostly aligned accesses.
2672 #undef DUK_USE_HOBJECT_LAYOUT_1
2673 #undef DUK_USE_HOBJECT_LAYOUT_2
2674 #undef DUK_USE_HOBJECT_LAYOUT_3
2675 #if (DUK_USE_ALIGN_BY == 1)
2676 /* On platforms without any alignment issues, layout 1 is preferable
2677 * because it compiles to slightly less code and provides direct access
2680 #define DUK_USE_HOBJECT_LAYOUT_1
2682 /* On other platforms use layout 2, which requires some padding but
2683 * is a bit more natural than layout 3 in ordering the entries. Layout
2684 * 3 is currently not used.
2686 #define DUK_USE_HOBJECT_LAYOUT_2
2689 /* GCC/clang inaccurate math would break compliance and probably duk_tval,
2690 * so refuse to compile. Relax this if -ffast-math is tested to work.
2692 #if defined(__FAST_MATH__)
2693 #error __FAST_MATH__ defined, refusing to compile
2697 * Feature option handling
2700 #if !defined(DUK_USE_ALIGN_BY)
2701 #if defined(DUK_OPT_FORCE_ALIGN)
2702 #define DUK_USE_ALIGN_BY DUK_OPT_FORCE_ALIGN
2704 #define DUK_USE_ALIGN_BY 8
2708 #if defined(DUK_OPT_ASSERTIONS)
2709 #define DUK_USE_ASSERTIONS
2710 #elif defined(DUK_OPT_NO_ASSERTIONS)
2711 #undef DUK_USE_ASSERTIONS
2713 #undef DUK_USE_ASSERTIONS
2716 #if defined(DUK_OPT_AUGMENT_ERRORS)
2717 #define DUK_USE_AUGMENT_ERROR_CREATE
2718 #elif defined(DUK_OPT_NO_AUGMENT_ERRORS)
2719 #undef DUK_USE_AUGMENT_ERROR_CREATE
2721 #define DUK_USE_AUGMENT_ERROR_CREATE
2724 #if defined(DUK_OPT_AUGMENT_ERRORS)
2725 #define DUK_USE_AUGMENT_ERROR_THROW
2726 #elif defined(DUK_OPT_NO_AUGMENT_ERRORS)
2727 #undef DUK_USE_AUGMENT_ERROR_THROW
2729 #define DUK_USE_AUGMENT_ERROR_THROW
2732 #if defined(DUK_OPT_BROWSER_LIKE)
2733 #define DUK_USE_BROWSER_LIKE
2734 #elif defined(DUK_OPT_NO_BROWSER_LIKE)
2735 #undef DUK_USE_BROWSER_LIKE
2737 #define DUK_USE_BROWSER_LIKE
2740 #if defined(DUK_OPT_BUFFEROBJECT_SUPPORT)
2741 #define DUK_USE_BUFFEROBJECT_SUPPORT
2742 #elif defined(DUK_OPT_NO_BUFFEROBJECT_SUPPORT)
2743 #undef DUK_USE_BUFFEROBJECT_SUPPORT
2745 #define DUK_USE_BUFFEROBJECT_SUPPORT
2748 #if defined(DUK_OPT_BUFLEN16)
2749 #define DUK_USE_BUFLEN16
2750 #elif defined(DUK_OPT_NO_BUFLEN16)
2751 #undef DUK_USE_BUFLEN16
2753 #undef DUK_USE_BUFLEN16
2756 #if defined(DUK_OPT_BYTECODE_DUMP_SUPPORT)
2757 #define DUK_USE_BYTECODE_DUMP_SUPPORT
2758 #elif defined(DUK_OPT_NO_BYTECODE_DUMP_SUPPORT)
2759 #undef DUK_USE_BYTECODE_DUMP_SUPPORT
2761 #define DUK_USE_BYTECODE_DUMP_SUPPORT
2764 #if defined(DUK_OPT_COMMONJS_MODULES)
2765 #define DUK_USE_COMMONJS_MODULES
2766 #elif defined(DUK_OPT_NO_COMMONJS_MODULES)
2767 #undef DUK_USE_COMMONJS_MODULES
2769 #define DUK_USE_COMMONJS_MODULES
2772 #if defined(DUK_OPT_CPP_EXCEPTIONS)
2773 #define DUK_USE_CPP_EXCEPTIONS
2774 #elif defined(DUK_OPT_NO_CPP_EXCEPTIONS)
2775 #undef DUK_USE_CPP_EXCEPTIONS
2777 #undef DUK_USE_CPP_EXCEPTIONS
2780 #if defined(DUK_OPT_DATAPTR16)
2781 #define DUK_USE_DATAPTR16
2782 #elif defined(DUK_OPT_NO_DATAPTR16)
2783 #undef DUK_USE_DATAPTR16
2785 #undef DUK_USE_DATAPTR16
2788 #if defined(DUK_OPT_DATAPTR_DEC16)
2789 #define DUK_USE_DATAPTR_DEC16(udata,ptr) DUK_OPT_DATAPTR_DEC16((udata),(ptr))
2791 #undef DUK_USE_DATAPTR_DEC16
2794 #if defined(DUK_OPT_DATAPTR_ENC16)
2795 #define DUK_USE_DATAPTR_ENC16(udata,ptr) DUK_OPT_DATAPTR_ENC16((udata),(ptr))
2797 #undef DUK_USE_DATAPTR_ENC16
2800 #if defined(DUK_OPT_DDDPRINT)
2801 #define DUK_USE_DDDPRINT
2802 #elif defined(DUK_OPT_NO_DDDPRINT)
2803 #undef DUK_USE_DDDPRINT
2805 #undef DUK_USE_DDDPRINT
2808 #if defined(DUK_OPT_DDPRINT)
2809 #define DUK_USE_DDPRINT
2810 #elif defined(DUK_OPT_NO_DDPRINT)
2811 #undef DUK_USE_DDPRINT
2813 #undef DUK_USE_DDPRINT
2816 #if defined(DUK_OPT_DEBUG)
2817 #define DUK_USE_DEBUG
2818 #elif defined(DUK_OPT_NO_DEBUG)
2819 #undef DUK_USE_DEBUG
2821 #undef DUK_USE_DEBUG
2824 #if defined(DUK_OPT_DEBUGGER_DUMPHEAP)
2825 #define DUK_USE_DEBUGGER_DUMPHEAP
2826 #elif defined(DUK_OPT_NO_DEBUGGER_DUMPHEAP)
2827 #undef DUK_USE_DEBUGGER_DUMPHEAP
2829 #undef DUK_USE_DEBUGGER_DUMPHEAP
2832 #if defined(DUK_OPT_DEBUGGER_FWD_LOGGING)
2833 #define DUK_USE_DEBUGGER_FWD_LOGGING
2834 #elif defined(DUK_OPT_NO_DEBUGGER_FWD_LOGGING)
2835 #undef DUK_USE_DEBUGGER_FWD_LOGGING
2837 #undef DUK_USE_DEBUGGER_FWD_LOGGING
2840 #if defined(DUK_OPT_DEBUGGER_FWD_PRINTALERT)
2841 #define DUK_USE_DEBUGGER_FWD_PRINTALERT
2842 #elif defined(DUK_OPT_NO_DEBUGGER_FWD_PRINTALERT)
2843 #undef DUK_USE_DEBUGGER_FWD_PRINTALERT
2845 #undef DUK_USE_DEBUGGER_FWD_PRINTALERT
2848 #if defined(DUK_OPT_DEBUGGER_INSPECT)
2849 #define DUK_USE_DEBUGGER_INSPECT
2850 #elif defined(DUK_OPT_NO_DEBUGGER_INSPECT)
2851 #undef DUK_USE_DEBUGGER_INSPECT
2853 #undef DUK_USE_DEBUGGER_INSPECT
2856 #if defined(DUK_OPT_DEBUGGER_PAUSE_UNCAUGHT)
2857 #define DUK_USE_DEBUGGER_PAUSE_UNCAUGHT
2858 #elif defined(DUK_OPT_NO_DEBUGGER_PAUSE_UNCAUGHT)
2859 #undef DUK_USE_DEBUGGER_PAUSE_UNCAUGHT
2861 #undef DUK_USE_DEBUGGER_PAUSE_UNCAUGHT
2864 #if defined(DUK_OPT_DEBUGGER_SUPPORT)
2865 #define DUK_USE_DEBUGGER_SUPPORT
2866 #elif defined(DUK_OPT_NO_DEBUGGER_SUPPORT)
2867 #undef DUK_USE_DEBUGGER_SUPPORT
2869 #undef DUK_USE_DEBUGGER_SUPPORT
2872 #if defined(DUK_OPT_DEBUGGER_THROW_NOTIFY)
2873 #define DUK_USE_DEBUGGER_THROW_NOTIFY
2874 #elif defined(DUK_OPT_NO_DEBUGGER_THROW_NOTIFY)
2875 #undef DUK_USE_DEBUGGER_THROW_NOTIFY
2877 #define DUK_USE_DEBUGGER_THROW_NOTIFY
2880 #if defined(DUK_OPT_DEBUGGER_TRANSPORT_TORTURE)
2881 #define DUK_USE_DEBUGGER_TRANSPORT_TORTURE
2882 #elif defined(DUK_OPT_NO_DEBUGGER_TRANSPORT_TORTURE)
2883 #undef DUK_USE_DEBUGGER_TRANSPORT_TORTURE
2885 #undef DUK_USE_DEBUGGER_TRANSPORT_TORTURE
2888 #if defined(DUK_OPT_DEBUG_BUFSIZE)
2889 #define DUK_USE_DEBUG_BUFSIZE DUK_OPT_DEBUG_BUFSIZE
2891 #define DUK_USE_DEBUG_BUFSIZE 65536L
2894 #if defined(DUK_OPT_REFERENCE_COUNTING)
2895 #define DUK_USE_DOUBLE_LINKED_HEAP
2896 #elif defined(DUK_OPT_NO_REFERENCE_COUNTING)
2897 #undef DUK_USE_DOUBLE_LINKED_HEAP
2899 #define DUK_USE_DOUBLE_LINKED_HEAP
2902 #if defined(DUK_OPT_DPRINT)
2903 #define DUK_USE_DPRINT
2904 #elif defined(DUK_OPT_NO_DPRINT)
2905 #undef DUK_USE_DPRINT
2907 #undef DUK_USE_DPRINT
2910 #if defined(DUK_OPT_DPRINT_COLORS)
2911 #define DUK_USE_DPRINT_COLORS
2912 #elif defined(DUK_OPT_NO_DPRINT_COLORS)
2913 #undef DUK_USE_DPRINT_COLORS
2915 #undef DUK_USE_DPRINT_COLORS
2918 #if defined(DUK_OPT_DPRINT_RDTSC)
2919 #define DUK_USE_DPRINT_RDTSC
2920 #elif defined(DUK_OPT_NO_DPRINT_RDTSC)
2921 #undef DUK_USE_DPRINT_RDTSC
2923 #undef DUK_USE_DPRINT_RDTSC
2926 #if defined(DUK_OPT_AUGMENT_ERRORS)
2927 #define DUK_USE_ERRCREATE
2928 #elif defined(DUK_OPT_NO_AUGMENT_ERRORS)
2929 #undef DUK_USE_ERRCREATE
2931 #define DUK_USE_ERRCREATE
2934 #if defined(DUK_OPT_AUGMENT_ERRORS)
2935 #define DUK_USE_ERRTHROW
2936 #elif defined(DUK_OPT_NO_AUGMENT_ERRORS)
2937 #undef DUK_USE_ERRTHROW
2939 #define DUK_USE_ERRTHROW
2942 #if defined(DUK_OPT_ES6_OBJECT_PROTO_PROPERTY)
2943 #define DUK_USE_ES6_OBJECT_PROTO_PROPERTY
2944 #elif defined(DUK_OPT_NO_ES6_OBJECT_PROTO_PROPERTY)
2945 #undef DUK_USE_ES6_OBJECT_PROTO_PROPERTY
2947 #define DUK_USE_ES6_OBJECT_PROTO_PROPERTY
2950 #if defined(DUK_OPT_ES6_OBJECT_SETPROTOTYPEOF)
2951 #define DUK_USE_ES6_OBJECT_SETPROTOTYPEOF
2952 #elif defined(DUK_OPT_NO_ES6_OBJECT_SETPROTOTYPEOF)
2953 #undef DUK_USE_ES6_OBJECT_SETPROTOTYPEOF
2955 #define DUK_USE_ES6_OBJECT_SETPROTOTYPEOF
2958 #if defined(DUK_OPT_ES6_PROXY)
2959 #define DUK_USE_ES6_PROXY
2960 #elif defined(DUK_OPT_NO_ES6_PROXY)
2961 #undef DUK_USE_ES6_PROXY
2963 #define DUK_USE_ES6_PROXY
2966 #if defined(DUK_OPT_ES6_REGEXP_BRACES)
2967 #define DUK_USE_ES6_REGEXP_BRACES
2968 #elif defined(DUK_OPT_NO_ES6_REGEXP_BRACES)
2969 #undef DUK_USE_ES6_REGEXP_BRACES
2971 #define DUK_USE_ES6_REGEXP_BRACES
2974 #undef DUK_USE_EXEC_INDIRECT_BOUND_CHECK
2975 #if defined(DUK_OPT_DEBUG) || defined(DUK_OPT_ASSERTIONS)
2976 /* Enabled with debug/assertions just so that any issues can be caught. */
2977 #define DUK_USE_EXEC_INDIRECT_BOUND_CHECK
2980 #undef DUK_USE_EXEC_TIMEOUT_CHECK
2981 #if defined(DUK_OPT_EXEC_TIMEOUT_CHECK)
2982 #define DUK_USE_EXEC_TIMEOUT_CHECK(udata) DUK_OPT_EXEC_TIMEOUT_CHECK((udata))
2985 #undef DUK_USE_EXTSTR_FREE
2986 #if defined(DUK_OPT_EXTERNAL_STRINGS) && defined(DUK_OPT_EXTSTR_FREE)
2987 #define DUK_USE_EXTSTR_FREE(udata,ptr) DUK_OPT_EXTSTR_FREE((udata), (ptr))
2990 #undef DUK_USE_EXTSTR_INTERN_CHECK
2991 #if defined(DUK_OPT_EXTERNAL_STRINGS) && defined(DUK_OPT_EXTSTR_INTERN_CHECK)
2992 #define DUK_USE_EXTSTR_INTERN_CHECK(udata,ptr,len) DUK_OPT_EXTSTR_INTERN_CHECK((udata), (ptr), (len))
2995 /* Support for 48-bit signed integer duk_tval with transparent semantics. */
2996 #undef DUK_USE_FASTINT
2997 #if defined(DUK_OPT_FASTINT)
2998 #if !defined(DUK_F_HAVE_64BIT)
2999 #error DUK_OPT_FASTINT requires 64-bit integer type support at the moment
3001 #define DUK_USE_FASTINT
3004 #if defined(DUK_OPT_FILE_IO)
3005 #define DUK_USE_FILE_IO
3006 #elif defined(DUK_OPT_NO_FILE_IO)
3007 #undef DUK_USE_FILE_IO
3009 #define DUK_USE_FILE_IO
3012 #if defined(DUK_OPT_FUNCPTR16)
3013 #define DUK_USE_FUNCPTR16
3014 #elif defined(DUK_OPT_NO_FUNCPTR16)
3015 #undef DUK_USE_FUNCPTR16
3017 #undef DUK_USE_FUNCPTR16
3020 #if defined(DUK_OPT_FUNCPTR_DEC16)
3021 #define DUK_USE_FUNCPTR_DEC16(udata,ptr) DUK_OPT_FUNCPTR_DEC16((udata),(ptr))
3023 #undef DUK_USE_FUNCPTR_DEC16
3026 #if defined(DUK_OPT_FUNCPTR_ENC16)
3027 #define DUK_USE_FUNCPTR_ENC16(udata,ptr) DUK_OPT_FUNCPTR_ENC16((udata),(ptr))
3029 #undef DUK_USE_FUNCPTR_ENC16
3032 #if defined(DUK_OPT_GC_TORTURE)
3033 #define DUK_USE_GC_TORTURE
3034 #elif defined(DUK_OPT_NO_GC_TORTURE)
3035 #undef DUK_USE_GC_TORTURE
3037 #undef DUK_USE_GC_TORTURE
3040 #if defined(DUK_OPT_HEAPPTR16)
3041 #define DUK_USE_HEAPPTR16
3042 #elif defined(DUK_OPT_NO_HEAPPTR16)
3043 #undef DUK_USE_HEAPPTR16
3045 #undef DUK_USE_HEAPPTR16
3048 #if defined(DUK_OPT_HEAPPTR_DEC16)
3049 #define DUK_USE_HEAPPTR_DEC16(udata,ptr) DUK_OPT_HEAPPTR_DEC16((udata),(ptr))
3051 #undef DUK_USE_HEAPPTR_DEC16
3054 #if defined(DUK_OPT_HEAPPTR_ENC16)
3055 #define DUK_USE_HEAPPTR_ENC16(udata,ptr) DUK_OPT_HEAPPTR_ENC16((udata),(ptr))
3057 #undef DUK_USE_HEAPPTR_ENC16
3060 /* For now, hash part is dropped if and only if 16-bit object fields are used. */
3061 #define DUK_USE_HOBJECT_HASH_PART
3062 #if defined(DUK_OPT_OBJSIZES16)
3063 #undef DUK_USE_HOBJECT_HASH_PART
3066 #if defined(DUK_OPT_HSTRING_CLEN)
3067 #define DUK_USE_HSTRING_CLEN
3068 #elif defined(DUK_OPT_NO_HSTRING_CLEN)
3069 #undef DUK_USE_HSTRING_CLEN
3071 #define DUK_USE_HSTRING_CLEN
3074 #if defined(DUK_OPT_EXTERNAL_STRINGS)
3075 #define DUK_USE_HSTRING_EXTDATA
3076 #elif defined(DUK_OPT_NO_EXTERNAL_STRINGS)
3077 #undef DUK_USE_HSTRING_EXTDATA
3079 #undef DUK_USE_HSTRING_EXTDATA
3082 #if defined(DUK_OPT_INTERRUPT_COUNTER)
3083 #define DUK_USE_INTERRUPT_COUNTER
3084 #elif defined(DUK_OPT_NO_INTERRUPT_COUNTER)
3085 #undef DUK_USE_INTERRUPT_COUNTER
3087 #undef DUK_USE_INTERRUPT_COUNTER
3090 #if defined(DUK_OPT_JC)
3092 #elif defined(DUK_OPT_NO_JC)
3098 #if defined(DUK_OPT_JSON_STRINGIFY_FASTPATH)
3099 #define DUK_USE_JSON_STRINGIFY_FASTPATH
3100 #elif defined(DUK_OPT_NO_JSON_STRINGIFY_FASTPATH)
3101 #undef DUK_USE_JSON_STRINGIFY_FASTPATH
3103 #undef DUK_USE_JSON_STRINGIFY_FASTPATH
3106 #if defined(DUK_OPT_JX)
3108 #elif defined(DUK_OPT_NO_JX)
3114 #if defined(DUK_OPT_LIGHTFUNC_BUILTINS)
3115 #define DUK_USE_LIGHTFUNC_BUILTINS
3116 #elif defined(DUK_OPT_NO_LIGHTFUNC_BUILTINS)
3117 #undef DUK_USE_LIGHTFUNC_BUILTINS
3119 #undef DUK_USE_LIGHTFUNC_BUILTINS
3122 #if defined(DUK_OPT_MARK_AND_SWEEP)
3123 #define DUK_USE_MARK_AND_SWEEP
3124 #elif defined(DUK_OPT_NO_MARK_AND_SWEEP)
3125 #undef DUK_USE_MARK_AND_SWEEP
3127 #define DUK_USE_MARK_AND_SWEEP
3130 #if defined(DUK_OPT_MS_STRINGTABLE_RESIZE)
3131 #define DUK_USE_MS_STRINGTABLE_RESIZE
3132 #elif defined(DUK_OPT_NO_MS_STRINGTABLE_RESIZE)
3133 #undef DUK_USE_MS_STRINGTABLE_RESIZE
3135 #define DUK_USE_MS_STRINGTABLE_RESIZE
3138 #if defined(DUK_OPT_NONSTD_ARRAY_CONCAT_TRAILER)
3139 #define DUK_USE_NONSTD_ARRAY_CONCAT_TRAILER
3140 #elif defined(DUK_OPT_NO_NONSTD_ARRAY_CONCAT_TRAILER)
3141 #undef DUK_USE_NONSTD_ARRAY_CONCAT_TRAILER
3143 #define DUK_USE_NONSTD_ARRAY_CONCAT_TRAILER
3146 #if defined(DUK_OPT_NONSTD_ARRAY_MAP_TRAILER)
3147 #define DUK_USE_NONSTD_ARRAY_MAP_TRAILER
3148 #elif defined(DUK_OPT_NO_NONSTD_ARRAY_MAP_TRAILER)
3149 #undef DUK_USE_NONSTD_ARRAY_MAP_TRAILER
3151 #define DUK_USE_NONSTD_ARRAY_MAP_TRAILER
3154 #if defined(DUK_OPT_NONSTD_ARRAY_SPLICE_DELCOUNT)
3155 #define DUK_USE_NONSTD_ARRAY_SPLICE_DELCOUNT
3156 #elif defined(DUK_OPT_NO_NONSTD_ARRAY_SPLICE_DELCOUNT)
3157 #undef DUK_USE_NONSTD_ARRAY_SPLICE_DELCOUNT
3159 #define DUK_USE_NONSTD_ARRAY_SPLICE_DELCOUNT
3162 #if defined(DUK_OPT_NONSTD_FUNC_CALLER_PROPERTY)
3163 #define DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
3164 #elif defined(DUK_OPT_NO_NONSTD_FUNC_CALLER_PROPERTY)
3165 #undef DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
3167 #undef DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
3170 #if defined(DUK_OPT_NONSTD_FUNC_SOURCE_PROPERTY)
3171 #define DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY
3172 #elif defined(DUK_OPT_NO_NONSTD_FUNC_SOURCE_PROPERTY)
3173 #undef DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY
3175 #undef DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY
3178 #if defined(DUK_OPT_NONSTD_FUNC_STMT)
3179 #define DUK_USE_NONSTD_FUNC_STMT
3180 #elif defined(DUK_OPT_NO_NONSTD_FUNC_STMT)
3181 #undef DUK_USE_NONSTD_FUNC_STMT
3183 #define DUK_USE_NONSTD_FUNC_STMT
3186 #if defined(DUK_OPT_NONSTD_ACCESSOR_KEY_ARGUMENT)
3187 #define DUK_USE_NONSTD_GETTER_KEY_ARGUMENT
3188 #elif defined(DUK_OPT_NO_NONSTD_ACCESSOR_KEY_ARGUMENT)
3189 #undef DUK_USE_NONSTD_GETTER_KEY_ARGUMENT
3191 #define DUK_USE_NONSTD_GETTER_KEY_ARGUMENT
3194 #if defined(DUK_OPT_NONSTD_JSON_ESC_U2028_U2029)
3195 #define DUK_USE_NONSTD_JSON_ESC_U2028_U2029
3196 #elif defined(DUK_OPT_NO_NONSTD_JSON_ESC_U2028_U2029)
3197 #undef DUK_USE_NONSTD_JSON_ESC_U2028_U2029
3199 #define DUK_USE_NONSTD_JSON_ESC_U2028_U2029
3202 #if defined(DUK_OPT_NONSTD_REGEXP_DOLLAR_ESCAPE)
3203 #define DUK_USE_NONSTD_REGEXP_DOLLAR_ESCAPE
3204 #elif defined(DUK_OPT_NO_NONSTD_REGEXP_DOLLAR_ESCAPE)
3205 #undef DUK_USE_NONSTD_REGEXP_DOLLAR_ESCAPE
3207 #define DUK_USE_NONSTD_REGEXP_DOLLAR_ESCAPE
3210 #if defined(DUK_OPT_NONSTD_ACCESSOR_KEY_ARGUMENT)
3211 #define DUK_USE_NONSTD_SETTER_KEY_ARGUMENT
3212 #elif defined(DUK_OPT_NO_NONSTD_ACCESSOR_KEY_ARGUMENT)
3213 #undef DUK_USE_NONSTD_SETTER_KEY_ARGUMENT
3215 #define DUK_USE_NONSTD_SETTER_KEY_ARGUMENT
3218 #if defined(DUK_OPT_NONSTD_STRING_FROMCHARCODE_32BIT)
3219 #define DUK_USE_NONSTD_STRING_FROMCHARCODE_32BIT
3220 #elif defined(DUK_OPT_NO_NONSTD_STRING_FROMCHARCODE_32BIT)
3221 #undef DUK_USE_NONSTD_STRING_FROMCHARCODE_32BIT
3223 #define DUK_USE_NONSTD_STRING_FROMCHARCODE_32BIT
3226 #if defined(DUK_OPT_OBJSIZES16)
3227 #define DUK_USE_OBJSIZES16
3228 #elif defined(DUK_OPT_NO_OBJSIZES16)
3229 #undef DUK_USE_OBJSIZES16
3231 #undef DUK_USE_OBJSIZES16
3234 #if defined(DUK_OPT_OCTAL_SUPPORT)
3235 #define DUK_USE_OCTAL_SUPPORT
3236 #elif defined(DUK_OPT_NO_OCTAL_SUPPORT)
3237 #undef DUK_USE_OCTAL_SUPPORT
3239 #define DUK_USE_OCTAL_SUPPORT
3242 #if defined(DUK_OPT_PACKED_TVAL)
3243 #define DUK_USE_PACKED_TVAL
3244 #elif defined(DUK_OPT_NO_PACKED_TVAL)
3245 #undef DUK_USE_PACKED_TVAL
3247 /* Already provided above */
3250 #undef DUK_USE_PANIC_ABORT
3251 #if !defined(DUK_OPT_SEGFAULT_ON_PANIC)
3252 #define DUK_USE_PANIC_ABORT
3255 #undef DUK_USE_PANIC_HANDLER
3256 #if defined(DUK_OPT_PANIC_HANDLER)
3257 #define DUK_USE_PANIC_HANDLER(code,msg) DUK_OPT_PANIC_HANDLER((code),(msg))
3260 #undef DUK_USE_PANIC_SEGFAULT
3261 #if defined(DUK_OPT_SEGFAULT_ON_PANIC)
3262 #define DUK_USE_PANIC_SEGFAULT
3265 #if defined(DUK_OPT_PARANOID_ERRORS)
3266 #define DUK_USE_PARANOID_ERRORS
3267 #elif defined(DUK_OPT_NO_PARANOID_ERRORS)
3268 #undef DUK_USE_PARANOID_ERRORS
3270 #undef DUK_USE_PARANOID_ERRORS
3273 #if defined(DUK_OPT_PC2LINE)
3274 #define DUK_USE_PC2LINE
3275 #elif defined(DUK_OPT_NO_PC2LINE)
3276 #undef DUK_USE_PC2LINE
3278 #define DUK_USE_PC2LINE
3281 #if defined(DUK_OPT_REFCOUNT16)
3282 #define DUK_USE_REFCOUNT16
3283 #elif defined(DUK_OPT_NO_REFCOUNT16)
3284 #undef DUK_USE_REFCOUNT16
3286 #undef DUK_USE_REFCOUNT16
3289 #if defined(DUK_OPT_REFERENCE_COUNTING)
3290 #define DUK_USE_REFERENCE_COUNTING
3291 #elif defined(DUK_OPT_NO_REFERENCE_COUNTING)
3292 #undef DUK_USE_REFERENCE_COUNTING
3294 #define DUK_USE_REFERENCE_COUNTING
3297 #if defined(DUK_OPT_REGEXP_CANON_WORKAROUND)
3298 #define DUK_USE_REGEXP_CANON_WORKAROUND
3299 #elif defined(DUK_OPT_NO_REGEXP_CANON_WORKAROUND)
3300 #undef DUK_USE_REGEXP_CANON_WORKAROUND
3302 #undef DUK_USE_REGEXP_CANON_WORKAROUND
3305 #if defined(DUK_OPT_REGEXP_SUPPORT)
3306 #define DUK_USE_REGEXP_SUPPORT
3307 #elif defined(DUK_OPT_NO_REGEXP_SUPPORT)
3308 #undef DUK_USE_REGEXP_SUPPORT
3310 #define DUK_USE_REGEXP_SUPPORT
3313 #if defined(DUK_OPT_ROM_GLOBAL_CLONE)
3314 #define DUK_USE_ROM_GLOBAL_CLONE
3315 #elif defined(DUK_OPT_NO_ROM_GLOBAL_CLONE)
3316 #undef DUK_USE_ROM_GLOBAL_CLONE
3318 #undef DUK_USE_ROM_GLOBAL_CLONE
3321 #if defined(DUK_OPT_ROM_GLOBAL_INHERIT)
3322 #define DUK_USE_ROM_GLOBAL_INHERIT
3323 #elif defined(DUK_OPT_NO_ROM_GLOBAL_INHERIT)
3324 #undef DUK_USE_ROM_GLOBAL_INHERIT
3326 #undef DUK_USE_ROM_GLOBAL_INHERIT
3329 #if defined(DUK_OPT_ROM_OBJECTS)
3330 #define DUK_USE_ROM_OBJECTS
3331 #elif defined(DUK_OPT_NO_ROM_OBJECTS)
3332 #undef DUK_USE_ROM_OBJECTS
3334 #undef DUK_USE_ROM_OBJECTS
3337 #if defined(DUK_OPT_ROM_STRINGS)
3338 #define DUK_USE_ROM_STRINGS
3339 #elif defined(DUK_OPT_NO_ROM_STRINGS)
3340 #undef DUK_USE_ROM_STRINGS
3342 #undef DUK_USE_ROM_STRINGS
3345 #if defined(DUK_OPT_SECTION_B)
3346 #define DUK_USE_SECTION_B
3347 #elif defined(DUK_OPT_NO_SECTION_B)
3348 #undef DUK_USE_SECTION_B
3350 #define DUK_USE_SECTION_B
3353 #if defined(DUK_OPT_SELF_TESTS)
3354 #define DUK_USE_SELF_TESTS
3355 #elif defined(DUK_OPT_NO_SELF_TESTS)
3356 #undef DUK_USE_SELF_TESTS
3358 #undef DUK_USE_SELF_TESTS
3361 #if defined(DUK_OPT_SHUFFLE_TORTURE)
3362 #define DUK_USE_SHUFFLE_TORTURE
3363 #elif defined(DUK_OPT_NO_SHUFFLE_TORTURE)
3364 #undef DUK_USE_SHUFFLE_TORTURE
3366 #undef DUK_USE_SHUFFLE_TORTURE
3369 #if defined(DUK_OPT_SOURCE_NONBMP)
3370 #define DUK_USE_SOURCE_NONBMP
3371 #elif defined(DUK_OPT_NO_SOURCE_NONBMP)
3372 #undef DUK_USE_SOURCE_NONBMP
3374 #define DUK_USE_SOURCE_NONBMP
3377 #if defined(DUK_OPT_STRHASH16)
3378 #define DUK_USE_STRHASH16
3379 #elif defined(DUK_OPT_NO_STRHASH16)
3380 #undef DUK_USE_STRHASH16
3382 #undef DUK_USE_STRHASH16
3385 #if defined(DUK_OPT_STRICT_DECL)
3386 #define DUK_USE_STRICT_DECL
3387 #elif defined(DUK_OPT_NO_STRICT_DECL)
3388 #undef DUK_USE_STRICT_DECL
3390 #define DUK_USE_STRICT_DECL
3393 #if defined(DUK_OPT_STRICT_UTF8_SOURCE)
3394 #define DUK_USE_STRICT_UTF8_SOURCE
3395 #elif defined(DUK_OPT_NO_STRICT_UTF8_SOURCE)
3396 #undef DUK_USE_STRICT_UTF8_SOURCE
3398 #undef DUK_USE_STRICT_UTF8_SOURCE
3401 #if defined(DUK_OPT_STRLEN16)
3402 #define DUK_USE_STRLEN16
3403 #elif defined(DUK_OPT_NO_STRLEN16)
3404 #undef DUK_USE_STRLEN16
3406 #undef DUK_USE_STRLEN16
3409 #undef DUK_USE_STRTAB_CHAIN
3410 #if defined(DUK_OPT_STRTAB_CHAIN) && defined(DUK_OPT_STRTAB_CHAIN_SIZE)
3411 #define DUK_USE_STRTAB_CHAIN
3414 #undef DUK_USE_STRTAB_CHAIN_SIZE
3415 #if defined(DUK_OPT_STRTAB_CHAIN) && defined(DUK_OPT_STRTAB_CHAIN_SIZE)
3416 /* Low memory algorithm: separate chaining using arrays, fixed size hash */
3417 #define DUK_USE_STRTAB_CHAIN_SIZE DUK_OPT_STRTAB_CHAIN_SIZE
3420 #undef DUK_USE_STRTAB_PROBE
3421 #if !(defined(DUK_OPT_STRTAB_CHAIN) && defined(DUK_OPT_STRTAB_CHAIN_SIZE))
3422 #define DUK_USE_STRTAB_PROBE
3425 #if defined(DUK_OPT_NONSTD_FUNC_CALLER_PROPERTY)
3426 #undef DUK_USE_TAILCALL
3428 #define DUK_USE_TAILCALL
3431 #if defined(DUK_OPT_TARGET_INFO)
3432 #define DUK_USE_TARGET_INFO DUK_OPT_TARGET_INFO
3434 #define DUK_USE_TARGET_INFO "unknown"
3437 #if defined(DUK_OPT_NO_AUGMENT_ERRORS)
3438 #undef DUK_USE_TRACEBACKS
3439 #elif defined(DUK_OPT_NO_TRACEBACKS)
3440 #undef DUK_USE_TRACEBACKS
3442 #define DUK_USE_TRACEBACKS
3445 #if defined(DUK_OPT_TRACEBACK_DEPTH)
3446 #define DUK_USE_TRACEBACK_DEPTH DUK_OPT_TRACEBACK_DEPTH
3448 #define DUK_USE_TRACEBACK_DEPTH 10
3451 #if defined(DUK_OPT_DECLARE)
3452 #define DUK_USE_USER_DECLARE() DUK_OPT_DECLARE
3454 #define DUK_USE_USER_DECLARE() /* no user declarations */
3457 /* User provided InitJS. */
3458 #undef DUK_USE_USER_INITJS
3459 #if defined(DUK_OPT_USER_INITJS)
3460 #define DUK_USE_USER_INITJS (DUK_OPT_USER_INITJS)
3463 #if defined(DUK_OPT_VERBOSE_ERRORS)
3464 #define DUK_USE_VERBOSE_ERRORS
3465 #elif defined(DUK_OPT_NO_VERBOSE_ERRORS)
3466 #undef DUK_USE_VERBOSE_ERRORS
3468 #define DUK_USE_VERBOSE_ERRORS
3471 #if defined(DUK_OPT_VOLUNTARY_GC)
3472 #define DUK_USE_VOLUNTARY_GC
3473 #elif defined(DUK_OPT_NO_VOLUNTARY_GC)
3474 #undef DUK_USE_VOLUNTARY_GC
3476 #define DUK_USE_VOLUNTARY_GC
3479 #if defined(DUK_OPT_ZERO_BUFFER_DATA)
3480 #define DUK_USE_ZERO_BUFFER_DATA
3481 #elif defined(DUK_OPT_NO_ZERO_BUFFER_DATA)
3482 #undef DUK_USE_ZERO_BUFFER_DATA
3484 #define DUK_USE_ZERO_BUFFER_DATA
3488 * Autogenerated defaults
3491 #define DUK_USE_AVOID_PLATFORM_FUNCPTRS
3492 #define DUK_USE_BASE64_FASTPATH
3493 #define DUK_USE_BUILTIN_INITJS
3494 #define DUK_USE_COMPILER_RECLIMIT 2500
3495 #undef DUK_USE_DATE_FORMAT_STRING
3496 #undef DUK_USE_DATE_GET_LOCAL_TZOFFSET
3497 #undef DUK_USE_DATE_GET_NOW
3498 #undef DUK_USE_DATE_PARSE_STRING
3499 #undef DUK_USE_DATE_PRS_GETDATE
3500 #define DUK_USE_ESBC_LIMITS
3501 #define DUK_USE_ESBC_MAX_BYTES 2147418112L
3502 #define DUK_USE_ESBC_MAX_LINENUMBER 2147418112L
3503 #undef DUK_USE_EXEC_FUN_LOCAL
3504 #undef DUK_USE_EXPLICIT_NULL_INIT
3505 #define DUK_USE_FAST_REFCOUNT_DEFAULT
3506 #define DUK_USE_HEX_FASTPATH
3507 #define DUK_USE_IDCHAR_FASTPATH
3508 #undef DUK_USE_INTERRUPT_DEBUG_FIXUP
3509 #define DUK_USE_JSON_DECNUMBER_FASTPATH
3510 #define DUK_USE_JSON_DECSTRING_FASTPATH
3511 #define DUK_USE_JSON_DEC_RECLIMIT 1000
3512 #define DUK_USE_JSON_EATWHITE_FASTPATH
3513 #define DUK_USE_JSON_ENC_RECLIMIT 1000
3514 #define DUK_USE_JSON_QUOTESTRING_FASTPATH
3515 #define DUK_USE_LEXER_SLIDING_WINDOW
3516 #undef DUK_USE_MARKANDSWEEP_FINALIZER_TORTURE
3517 #define DUK_USE_MARK_AND_SWEEP_RECLIMIT 256
3518 #define DUK_USE_MATH_BUILTIN
3519 #define DUK_USE_NATIVE_CALL_RECLIMIT 1000
3520 #undef DUK_USE_PANIC_EXIT
3521 #undef DUK_USE_PREFER_SIZE
3522 #define DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS
3523 #undef DUK_USE_REFZERO_FINALIZER_TORTURE
3524 #define DUK_USE_REGEXP_COMPILER_RECLIMIT 10000
3525 #define DUK_USE_REGEXP_EXECUTOR_RECLIMIT 10000
3526 #define DUK_USE_ROM_PTRCOMP_FIRST 63488L
3527 #undef DUK_USE_STRHASH_DENSE
3528 #define DUK_USE_STRHASH_SKIP_SHIFT 5
3529 #undef DUK_USE_VALSTACK_UNSAFE
3530 #define DUK_USE_VERBOSE_EXECUTOR_ERRORS
3533 * Alternative customization header
3535 * If you want to modify the final DUK_USE_xxx flags directly (without
3536 * using the available DUK_OPT_xxx flags), define DUK_OPT_HAVE_CUSTOM_H
3537 * and tweak the final flags there.
3540 #if defined(DUK_OPT_HAVE_CUSTOM_H)
3541 #include "duk_custom.h"
3545 * You may add overriding #define/#undef directives below for
3546 * customization. You of course cannot un-#include or un-typedef
3547 * anything; these require direct changes above.
3550 /* __OVERRIDE_DEFINES__ */
3553 * Date provider selection
3555 * User may define DUK_USE_DATE_GET_NOW() etc directly, in which case we'll
3556 * rely on an external provider. If this is not done, revert to previous
3557 * behavior and use Unix/Windows built-in provider.
3560 #if defined(DUK_COMPILING_DUKTAPE)
3562 #if defined(DUK_USE_DATE_GET_NOW)
3563 /* External provider already defined. */
3564 #elif defined(DUK_USE_DATE_NOW_GETTIMEOFDAY)
3565 #define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_gettimeofday((ctx))
3566 #elif defined(DUK_USE_DATE_NOW_TIME)
3567 #define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_time((ctx))
3568 #elif defined(DUK_USE_DATE_NOW_WINDOWS)
3569 #define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_windows((ctx))
3571 #error no provider for DUK_USE_DATE_GET_NOW()
3574 #if defined(DUK_USE_DATE_GET_LOCAL_TZOFFSET)
3575 /* External provider already defined. */
3576 #elif defined(DUK_USE_DATE_TZO_GMTIME_R) || defined(DUK_USE_DATE_TZO_GMTIME)
3577 #define DUK_USE_DATE_GET_LOCAL_TZOFFSET(d) duk_bi_date_get_local_tzoffset_gmtime((d))
3578 #elif defined(DUK_USE_DATE_TZO_WINDOWS)
3579 #define DUK_USE_DATE_GET_LOCAL_TZOFFSET(d) duk_bi_date_get_local_tzoffset_windows((d))
3581 #error no provider for DUK_USE_DATE_GET_LOCAL_TZOFFSET()
3584 #if defined(DUK_USE_DATE_PARSE_STRING)
3585 /* External provider already defined. */
3586 #elif defined(DUK_USE_DATE_PRS_STRPTIME)
3587 #define DUK_USE_DATE_PARSE_STRING(ctx,str) duk_bi_date_parse_string_strptime((ctx), (str))
3588 #elif defined(DUK_USE_DATE_PRS_GETDATE)
3589 #define DUK_USE_DATE_PARSE_STRING(ctx,str) duk_bi_date_parse_string_getdate((ctx), (str))
3591 /* No provider for DUK_USE_DATE_PARSE_STRING(), fall back to ISO 8601 only. */
3594 #if defined(DUK_USE_DATE_FORMAT_STRING)
3595 /* External provider already defined. */
3596 #elif defined(DUK_USE_DATE_FMT_STRFTIME)
3597 #define DUK_USE_DATE_FORMAT_STRING(ctx,parts,tzoffset,flags) \
3598 duk_bi_date_format_parts_strftime((ctx), (parts), (tzoffset), (flags))
3600 /* No provider for DUK_USE_DATE_FORMAT_STRING(), fall back to ISO 8601 only. */
3603 #endif /* DUK_COMPILING_DUKTAPE */
3606 * Checks for config option consistency (DUK_USE_xxx)
3609 #if defined(DUK_USE_32BIT_PTRS)
3610 #error unsupported config option used (option has been removed): DUK_USE_32BIT_PTRS
3612 #if defined(DUK_USE_ALIGN_4)
3613 #error unsupported config option used (option has been removed): DUK_USE_ALIGN_4
3615 #if defined(DUK_USE_ALIGN_8)
3616 #error unsupported config option used (option has been removed): DUK_USE_ALIGN_8
3618 #if defined(DUK_USE_BYTEORDER_FORCED)
3619 #error unsupported config option used (option has been removed): DUK_USE_BYTEORDER_FORCED
3621 #if defined(DUK_USE_DATAPTR_DEC16) && !defined(DUK_USE_DATAPTR16)
3622 #error config option DUK_USE_DATAPTR_DEC16 requires option DUK_USE_DATAPTR16 (which is missing)
3624 #if defined(DUK_USE_DATAPTR_ENC16) && !defined(DUK_USE_DATAPTR16)
3625 #error config option DUK_USE_DATAPTR_ENC16 requires option DUK_USE_DATAPTR16 (which is missing)
3627 #if defined(DUK_USE_DEBUGGER_SUPPORT) && !defined(DUK_USE_INTERRUPT_COUNTER)
3628 #error config option DUK_USE_DEBUGGER_SUPPORT requires option DUK_USE_INTERRUPT_COUNTER (which is missing)
3630 #if defined(DUK_USE_DEEP_C_STACK)
3631 #error unsupported config option used (option has been removed): DUK_USE_DEEP_C_STACK
3633 #if defined(DUK_USE_DOUBLE_BE)
3634 #error unsupported config option used (option has been removed): DUK_USE_DOUBLE_BE
3636 #if defined(DUK_USE_DOUBLE_BE) && defined(DUK_USE_DOUBLE_LE)
3637 #error config option DUK_USE_DOUBLE_BE conflicts with option DUK_USE_DOUBLE_LE (which is also defined)
3639 #if defined(DUK_USE_DOUBLE_BE) && defined(DUK_USE_DOUBLE_ME)
3640 #error config option DUK_USE_DOUBLE_BE conflicts with option DUK_USE_DOUBLE_ME (which is also defined)
3642 #if defined(DUK_USE_DOUBLE_LE)
3643 #error unsupported config option used (option has been removed): DUK_USE_DOUBLE_LE
3645 #if defined(DUK_USE_DOUBLE_LE) && defined(DUK_USE_DOUBLE_BE)
3646 #error config option DUK_USE_DOUBLE_LE conflicts with option DUK_USE_DOUBLE_BE (which is also defined)
3648 #if defined(DUK_USE_DOUBLE_LE) && defined(DUK_USE_DOUBLE_ME)
3649 #error config option DUK_USE_DOUBLE_LE conflicts with option DUK_USE_DOUBLE_ME (which is also defined)
3651 #if defined(DUK_USE_DOUBLE_ME)
3652 #error unsupported config option used (option has been removed): DUK_USE_DOUBLE_ME
3654 #if defined(DUK_USE_DOUBLE_ME) && defined(DUK_USE_DOUBLE_LE)
3655 #error config option DUK_USE_DOUBLE_ME conflicts with option DUK_USE_DOUBLE_LE (which is also defined)
3657 #if defined(DUK_USE_DOUBLE_ME) && defined(DUK_USE_DOUBLE_BE)
3658 #error config option DUK_USE_DOUBLE_ME conflicts with option DUK_USE_DOUBLE_BE (which is also defined)
3660 #if defined(DUK_USE_DPRINT) && !defined(DUK_USE_DEBUG)
3661 #error config option DUK_USE_DPRINT requires option DUK_USE_DEBUG (which is missing)
3663 #if defined(DUK_USE_ESBC_MAX_BYTES) && !defined(DUK_USE_ESBC_LIMITS)
3664 #error config option DUK_USE_ESBC_MAX_BYTES requires option DUK_USE_ESBC_LIMITS (which is missing)
3666 #if defined(DUK_USE_ESBC_MAX_LINENUMBER) && !defined(DUK_USE_ESBC_LIMITS)
3667 #error config option DUK_USE_ESBC_MAX_LINENUMBER requires option DUK_USE_ESBC_LIMITS (which is missing)
3669 #if defined(DUK_USE_EXEC_TIMEOUT_CHECK) && !defined(DUK_USE_INTERRUPT_COUNTER)
3670 #error config option DUK_USE_EXEC_TIMEOUT_CHECK requires option DUK_USE_INTERRUPT_COUNTER (which is missing)
3672 #if defined(DUK_USE_EXTSTR_FREE) && !defined(DUK_USE_HSTRING_EXTDATA)
3673 #error config option DUK_USE_EXTSTR_FREE requires option DUK_USE_HSTRING_EXTDATA (which is missing)
3675 #if defined(DUK_USE_EXTSTR_INTERN_CHECK) && !defined(DUK_USE_HSTRING_EXTDATA)
3676 #error config option DUK_USE_EXTSTR_INTERN_CHECK requires option DUK_USE_HSTRING_EXTDATA (which is missing)
3678 #if defined(DUK_USE_FULL_TVAL)
3679 #error unsupported config option used (option has been removed): DUK_USE_FULL_TVAL
3681 #if defined(DUK_USE_FUNCPTR_DEC16) && !defined(DUK_USE_FUNCPTR16)
3682 #error config option DUK_USE_FUNCPTR_DEC16 requires option DUK_USE_FUNCPTR16 (which is missing)
3684 #if defined(DUK_USE_FUNCPTR_ENC16) && !defined(DUK_USE_FUNCPTR16)
3685 #error config option DUK_USE_FUNCPTR_ENC16 requires option DUK_USE_FUNCPTR16 (which is missing)
3687 #if defined(DUK_USE_HASHBYTES_UNALIGNED_U32_ACCESS)
3688 #error unsupported config option used (option has been removed): DUK_USE_HASHBYTES_UNALIGNED_U32_ACCESS
3690 #if defined(DUK_USE_HEAPPTR16) && defined(DUK_USE_DEBUG)
3691 #error config option DUK_USE_HEAPPTR16 conflicts with option DUK_USE_DEBUG (which is also defined)
3693 #if defined(DUK_USE_HEAPPTR_DEC16) && !defined(DUK_USE_HEAPPTR16)
3694 #error config option DUK_USE_HEAPPTR_DEC16 requires option DUK_USE_HEAPPTR16 (which is missing)
3696 #if defined(DUK_USE_HEAPPTR_ENC16) && !defined(DUK_USE_HEAPPTR16)
3697 #error config option DUK_USE_HEAPPTR_ENC16 requires option DUK_USE_HEAPPTR16 (which is missing)
3699 #if defined(DUK_USE_INTEGER_BE)
3700 #error unsupported config option used (option has been removed): DUK_USE_INTEGER_BE
3702 #if defined(DUK_USE_INTEGER_BE) && defined(DUK_USE_INTEGER_LE)
3703 #error config option DUK_USE_INTEGER_BE conflicts with option DUK_USE_INTEGER_LE (which is also defined)
3705 #if defined(DUK_USE_INTEGER_BE) && defined(DUK_USE_INTEGER_ME)
3706 #error config option DUK_USE_INTEGER_BE conflicts with option DUK_USE_INTEGER_ME (which is also defined)
3708 #if defined(DUK_USE_INTEGER_LE)
3709 #error unsupported config option used (option has been removed): DUK_USE_INTEGER_LE
3711 #if defined(DUK_USE_INTEGER_LE) && defined(DUK_USE_INTEGER_BE)
3712 #error config option DUK_USE_INTEGER_LE conflicts with option DUK_USE_INTEGER_BE (which is also defined)
3714 #if defined(DUK_USE_INTEGER_LE) && defined(DUK_USE_INTEGER_ME)
3715 #error config option DUK_USE_INTEGER_LE conflicts with option DUK_USE_INTEGER_ME (which is also defined)
3717 #if defined(DUK_USE_INTEGER_ME)
3718 #error unsupported config option used (option has been removed): DUK_USE_INTEGER_ME
3720 #if defined(DUK_USE_INTEGER_ME) && defined(DUK_USE_INTEGER_LE)
3721 #error config option DUK_USE_INTEGER_ME conflicts with option DUK_USE_INTEGER_LE (which is also defined)
3723 #if defined(DUK_USE_INTEGER_ME) && defined(DUK_USE_INTEGER_BE)
3724 #error config option DUK_USE_INTEGER_ME conflicts with option DUK_USE_INTEGER_BE (which is also defined)
3726 #if defined(DUK_USE_NO_DOUBLE_ALIASING_SELFTEST)
3727 #error unsupported config option used (option has been removed): DUK_USE_NO_DOUBLE_ALIASING_SELFTEST
3729 #if defined(DUK_USE_PACKED_TVAL_POSSIBLE)
3730 #error unsupported config option used (option has been removed): DUK_USE_PACKED_TVAL_POSSIBLE
3732 #if defined(DUK_USE_RDTSC)
3733 #error unsupported config option used (option has been removed): DUK_USE_RDTSC
3735 #if defined(DUK_USE_ROM_GLOBAL_CLONE) && !defined(DUK_USE_ROM_STRINGS)
3736 #error config option DUK_USE_ROM_GLOBAL_CLONE requires option DUK_USE_ROM_STRINGS (which is missing)
3738 #if defined(DUK_USE_ROM_GLOBAL_CLONE) && !defined(DUK_USE_ROM_OBJECTS)
3739 #error config option DUK_USE_ROM_GLOBAL_CLONE requires option DUK_USE_ROM_OBJECTS (which is missing)
3741 #if defined(DUK_USE_ROM_GLOBAL_CLONE) && defined(DUK_USE_ROM_GLOBAL_INHERIT)
3742 #error config option DUK_USE_ROM_GLOBAL_CLONE conflicts with option DUK_USE_ROM_GLOBAL_INHERIT (which is also defined)
3744 #if defined(DUK_USE_ROM_GLOBAL_INHERIT) && !defined(DUK_USE_ROM_STRINGS)
3745 #error config option DUK_USE_ROM_GLOBAL_INHERIT requires option DUK_USE_ROM_STRINGS (which is missing)
3747 #if defined(DUK_USE_ROM_GLOBAL_INHERIT) && !defined(DUK_USE_ROM_OBJECTS)
3748 #error config option DUK_USE_ROM_GLOBAL_INHERIT requires option DUK_USE_ROM_OBJECTS (which is missing)
3750 #if defined(DUK_USE_ROM_GLOBAL_INHERIT) && defined(DUK_USE_ROM_GLOBAL_CLONE)
3751 #error config option DUK_USE_ROM_GLOBAL_INHERIT conflicts with option DUK_USE_ROM_GLOBAL_CLONE (which is also defined)
3753 #if defined(DUK_USE_ROM_OBJECTS) && !defined(DUK_USE_ROM_STRINGS)
3754 #error config option DUK_USE_ROM_OBJECTS requires option DUK_USE_ROM_STRINGS (which is missing)
3756 #if defined(DUK_USE_ROM_STRINGS) && !defined(DUK_USE_ROM_OBJECTS)
3757 #error config option DUK_USE_ROM_STRINGS requires option DUK_USE_ROM_OBJECTS (which is missing)
3759 #if defined(DUK_USE_SETJMP)
3760 #error unsupported config option used (option has been removed): DUK_USE_SETJMP
3762 #if defined(DUK_USE_SIGSETJMP)
3763 #error unsupported config option used (option has been removed): DUK_USE_SIGSETJMP
3765 #if defined(DUK_USE_STRTAB_CHAIN_SIZE) && !defined(DUK_USE_STRTAB_CHAIN)
3766 #error config option DUK_USE_STRTAB_CHAIN_SIZE requires option DUK_USE_STRTAB_CHAIN (which is missing)
3768 #if defined(DUK_USE_TAILCALL) && defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY)
3769 #error config option DUK_USE_TAILCALL conflicts with option DUK_USE_NONSTD_FUNC_CALLER_PROPERTY (which is also defined)
3771 #if defined(DUK_USE_UNALIGNED_ACCESSES_POSSIBLE)
3772 #error unsupported config option used (option has been removed): DUK_USE_UNALIGNED_ACCESSES_POSSIBLE
3774 #if defined(DUK_USE_UNDERSCORE_SETJMP)
3775 #error unsupported config option used (option has been removed): DUK_USE_UNDERSCORE_SETJMP
3778 #if defined(DUK_USE_CPP_EXCEPTIONS) && !defined(__cplusplus)
3779 #error DUK_USE_CPP_EXCEPTIONS enabled but not compiling with a C++ compiler
3783 * Convert DUK_USE_BYTEORDER, from whatever source, into currently used
3784 * internal defines. If detection failed, #error out.
3787 #if defined(DUK_USE_BYTEORDER)
3788 #if (DUK_USE_BYTEORDER == 1)
3789 #define DUK_USE_INTEGER_LE
3790 #define DUK_USE_DOUBLE_LE
3791 #elif (DUK_USE_BYTEORDER == 2)
3792 #define DUK_USE_INTEGER_LE /* integer endianness is little on purpose */
3793 #define DUK_USE_DOUBLE_ME
3794 #elif (DUK_USE_BYTEORDER == 3)
3795 #define DUK_USE_INTEGER_BE
3796 #define DUK_USE_DOUBLE_BE
3798 #error unsupported: byte order invalid
3799 #endif /* byte order */
3801 #error unsupported: byte order detection failed
3802 #endif /* defined(DUK_USE_BYTEORDER) */
3804 #endif /* DUK_CONFIG_H_INCLUDED */