2 * duk_config.h configuration header generated by genconfig.py.
4 * Git commit: d7fdb67f18561a50e06bafd196c6b423af9ad6fe
9 * - Mac OSX, iPhone, Darwin
17 * - Flashplayer (Crossbridge)
30 * Supported architectures:
47 * Supported compilers:
54 * - Bruce's C compiler
59 #if !defined(DUK_CONFIG_H_INCLUDED)
60 #define DUK_CONFIG_H_INCLUDED
63 * Intermediate helper defines
66 /* DLL build detection */
67 /* not configured for DLL build */
68 #undef DUK_F_DLL_BUILD
71 #if defined(__APPLE__)
76 #if defined(__FreeBSD__) || defined(__FreeBSD)
80 /* Orbis (PS4) variant */
81 #if defined(DUK_F_FREEBSD) && defined(__ORBIS__)
86 #if defined(__OpenBSD__) || defined(__OpenBSD)
91 #if defined(__NetBSD__) || defined(__NetBSD)
96 #if defined(DUK_F_FREEBSD) || defined(DUK_F_NETBSD) || defined(DUK_F_OPENBSD) || \
97 defined(__bsdi__) || defined(__DragonFly__)
101 /* Atari ST TOS. __TOS__ defined by PureC. No platform define in VBCC
102 * apparently, so to use with VBCC user must define __TOS__ manually.
108 /* Motorola 68K. Not defined by VBCC, so user must define one of these
109 * manually when using VBCC.
111 #if defined(__m68k__) || defined(M68000) || defined(__MC68K__)
115 /* AmigaOS. Neither AMIGA nor __amigaos__ is defined on VBCC, so user must
116 * define 'AMIGA' manually when using VBCC.
118 #if defined(AMIGA) || defined(__amigaos__)
119 #define DUK_F_AMIGAOS
123 #if defined(__powerpc) || defined(__powerpc__) || defined(__PPC__)
125 #if defined(__PPC64__) || defined(__LP64__) || defined(_LP64)
132 /* Durango (Xbox One) */
133 #if defined(_DURANGO) || defined(_XBOX_ONE)
134 #define DUK_F_DURANGO
137 /* Windows, both 32-bit and 64-bit */
138 #if defined(_WIN32) || defined(WIN32) || defined(_WIN64) || defined(WIN64) || \
139 defined(__WIN32__) || defined(__TOS_WIN__) || defined(__WINDOWS__)
140 #define DUK_F_WINDOWS
141 #if defined(_WIN64) || defined(WIN64)
148 /* Flash player (e.g. Crossbridge) */
149 #if defined(__FLASHPLAYER__)
150 #define DUK_F_FLASHPLAYER
158 /* TI-Nspire (using Ndless) */
159 #if defined(_TINSPIRE)
160 #define DUK_F_TINSPIRE
163 /* Emscripten (provided explicitly by user), improve if possible */
164 #if defined(EMSCRIPTEN)
165 #define DUK_F_EMSCRIPTEN
168 /* BCC (Bruce's C compiler): this is a "torture target" for compilation */
169 #if defined(__BCC__) || defined(__BCC_VERSION__)
174 #if defined(__linux) || defined(__linux__) || defined(linux)
178 /* illumos / Solaris */
179 #if defined(__sun) && defined(__SVR4)
181 #if defined(__SUNPRO_C) && (__SUNPRO_C < 0x550)
182 #define DUK_F_OLD_SOLARIS
183 /* Defines _ILP32 / _LP64 required by DUK_F_X86/DUK_F_X64. Platforms
184 * are processed before architectures, so this happens before the
185 * DUK_F_X86/DUK_F_X64 detection is emitted.
187 #include <sys/isa_defs.h>
193 /* defined(__xlc__) || defined(__IBMC__): works but too wide */
201 #define DUK_F_HPUX_ITANIUM
211 #if defined(__CYGWIN__)
215 /* Generic Unix (includes Cygwin) */
216 #if defined(__unix) || defined(__unix__) || defined(unix) || \
217 defined(DUK_F_LINUX) || defined(DUK_F_BSD)
221 /* Intel x86 (32-bit), x64 (64-bit) or x32 (64-bit but 32-bit pointers),
222 * define only one of DUK_F_X86, DUK_F_X64, DUK_F_X32.
223 * https://sites.google.com/site/x32abi/
225 * With DUK_F_OLD_SOLARIS the <sys/isa_defs.h> header must be included
228 #if defined(__amd64__) || defined(__amd64) || \
229 defined(__x86_64__) || defined(__x86_64) || \
230 defined(_M_X64) || defined(_M_AMD64)
231 #if defined(__ILP32__) || defined(_ILP32)
236 #elif defined(i386) || defined(__i386) || defined(__i386__) || \
237 defined(__i486__) || defined(__i586__) || defined(__i686__) || \
238 defined(__IA32__) || defined(_M_IX86) || defined(__X86__) || \
239 defined(_X86_) || defined(__THW_INTEL__) || defined(__I86__)
240 #if defined(__LP64__) || defined(_LP64)
241 /* This should not really happen, but would indicate x64. */
249 #if defined(__arm__) || defined(__thumb__) || defined(_ARM) || defined(_M_ARM) || defined(__aarch64__)
251 #if defined(__LP64__) || defined(_LP64) || defined(__arm64) || defined(__arm64__) || defined(__aarch64__)
258 /* MIPS. Related defines: __MIPSEB__, __MIPSEL__, __mips_isa_rev, __LP64__ */
259 #if defined(__mips__) || defined(mips) || defined(_MIPS_ISA) || \
260 defined(_R3000) || defined(_R4000) || defined(_R5900) || \
261 defined(_MIPS_ISA_MIPS1) || defined(_MIPS_ISA_MIPS2) || \
262 defined(_MIPS_ISA_MIPS3) || defined(_MIPS_ISA_MIPS4) || \
263 defined(__mips) || defined(__MIPS__)
265 #if defined(__LP64__) || defined(_LP64) || defined(__mips64) || \
266 defined(__mips64__) || defined(__mips_n64)
274 #if defined(sparc) || defined(__sparc) || defined(__sparc__)
276 #if defined(__LP64__) || defined(_LP64)
277 #define DUK_F_SPARC64
279 #define DUK_F_SPARC32
284 #if defined(__sh__) || \
285 defined(__sh1__) || defined(__SH1__) || \
286 defined(__sh2__) || defined(__SH2__) || \
287 defined(__sh3__) || defined(__SH3__) || \
288 defined(__sh4__) || defined(__SH4__) || \
289 defined(__sh5__) || defined(__SH5__)
294 #if defined(__clang__)
300 #if defined(__cplusplus)
306 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
312 #if defined(__cplusplus) && (__cplusplus >= 201103L)
316 /* GCC. Clang also defines __GNUC__ so don't detect GCC if using Clang. */
317 #if defined(__GNUC__) && !defined(__clang__) && !defined(DUK_F_CLANG)
319 #if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__)
320 /* Convenience, e.g. gcc 4.5.1 == 40501; http://stackoverflow.com/questions/6031819/emulating-gccs-builtin-unreachable */
321 #define DUK_F_GCC_VERSION (__GNUC__ * 10000L + __GNUC_MINOR__ * 100L + __GNUC_PATCHLEVEL__)
323 #error cannot figure out gcc version
327 /* MinGW. Also GCC flags (DUK_F_GCC) are enabled now. */
328 #if defined(__MINGW32__) || defined(__MINGW64__)
333 #if defined(_MSC_VER)
334 /* MSVC preprocessor defines: http://msdn.microsoft.com/en-us/library/b0084kay.aspx
335 * _MSC_FULL_VER includes the build number, but it has at least two formats, see e.g.
336 * BOOST_MSVC_FULL_VER in http://www.boost.org/doc/libs/1_52_0/boost/config/compiler/visualc.hpp
339 #if defined(_MSC_FULL_VER)
340 #if (_MSC_FULL_VER > 100000000)
341 #define DUK_F_MSVC_FULL_VER _MSC_FULL_VER
343 #define DUK_F_MSCV_FULL_VER (_MSC_FULL_VER * 10)
346 #endif /* _MSC_VER */
349 #if defined(__TINYC__)
350 /* http://bellard.org/tcc/tcc-doc.html#SEC9 */
355 #if defined(__VBCC__)
359 #if defined(ANDROID) || defined(__ANDROID__)
360 #define DUK_F_ANDROID
364 #if defined(__MINT__)
369 * Platform autodetection
372 /* Workaround for older C++ compilers before including <inttypes.h>,
373 * see e.g.: https://sourceware.org/bugzilla/show_bug.cgi?id=15366
375 #if defined(__cplusplus) && !defined(__STDC_LIMIT_MACROS)
376 #define __STDC_LIMIT_MACROS
378 #if defined(__cplusplus) && !defined(__STDC_CONSTANT_MACROS)
379 #define __STDC_CONSTANT_MACROS
382 #if defined(DUK_F_APPLE)
383 /* --- Mac OSX, iPhone, Darwin --- */
384 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
385 #define DUK_USE_DATE_TZO_GMTIME_R
386 #define DUK_USE_DATE_PRS_STRPTIME
387 #define DUK_USE_DATE_FMT_STRFTIME
388 #include <TargetConditionals.h>
389 #include <architecture/byte_order.h>
390 #include <sys/param.h>
391 #include <sys/time.h>
394 /* http://stackoverflow.com/questions/5919996/how-to-detect-reliably-mac-os-x-ios-linux-windows-in-c-preprocessor */
395 #if TARGET_IPHONE_SIMULATOR
396 #define DUK_USE_OS_STRING "iphone-sim"
397 #elif TARGET_OS_IPHONE
398 #define DUK_USE_OS_STRING "iphone"
400 #define DUK_USE_OS_STRING "osx"
402 #define DUK_USE_OS_STRING "osx-unknown"
405 /* Use _setjmp() on Apple by default, see GH-55. */
406 #define DUK_JMPBUF_TYPE jmp_buf
407 #define DUK_SETJMP(jb) _setjmp((jb))
408 #define DUK_LONGJMP(jb) _longjmp((jb), 1)
409 #elif defined(DUK_F_ORBIS)
412 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
413 #define DUK_USE_DATE_TZO_GMTIME_S
414 /* no parsing (not an error) */
415 #define DUK_USE_DATE_FMT_STRFTIME
416 #include <sys/types.h>
417 #include <machine/endian.h>
418 #include <sys/param.h>
419 #include <sys/time.h>
422 #define DUK_USE_OS_STRING "orbis"
423 #elif defined(DUK_F_OPENBSD)
424 /* --- OpenBSD --- */
425 /* http://www.monkey.org/openbsd/archive/ports/0401/msg00089.html */
426 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
427 #define DUK_USE_DATE_TZO_GMTIME_R
428 #define DUK_USE_DATE_PRS_STRPTIME
429 #define DUK_USE_DATE_FMT_STRFTIME
430 #include <sys/types.h>
431 #include <sys/endian.h>
432 #include <sys/param.h>
433 #include <sys/time.h>
436 #define DUK_USE_OS_STRING "openbsd"
437 #elif defined(DUK_F_BSD)
438 /* --- Generic BSD --- */
439 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
440 #define DUK_USE_DATE_TZO_GMTIME_R
441 #define DUK_USE_DATE_PRS_STRPTIME
442 #define DUK_USE_DATE_FMT_STRFTIME
443 #include <sys/types.h>
444 #include <sys/endian.h>
445 #include <sys/param.h>
446 #include <sys/time.h>
449 #define DUK_USE_OS_STRING "bsd"
450 #elif defined(DUK_F_TOS)
451 /* --- Atari ST TOS --- */
452 #define DUK_USE_DATE_NOW_TIME
453 #define DUK_USE_DATE_TZO_GMTIME
454 /* no parsing (not an error) */
455 #define DUK_USE_DATE_FMT_STRFTIME
458 #define DUK_USE_OS_STRING "tos"
460 /* TOS on M68K is always big endian. */
461 #if !defined(DUK_USE_BYTEORDER) && defined(DUK_F_M68K)
462 #define DUK_USE_BYTEORDER 3
464 #elif defined(DUK_F_AMIGAOS)
465 /* --- AmigaOS --- */
466 #if defined(DUK_F_M68K)
467 /* AmigaOS on M68k */
468 #define DUK_USE_DATE_NOW_TIME
469 #define DUK_USE_DATE_TZO_GMTIME
470 /* no parsing (not an error) */
471 #define DUK_USE_DATE_FMT_STRFTIME
473 #elif defined(DUK_F_PPC)
474 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
475 #define DUK_USE_DATE_TZO_GMTIME_R
476 #define DUK_USE_DATE_PRS_STRPTIME
477 #define DUK_USE_DATE_FMT_STRFTIME
479 #if !defined(UINTPTR_MAX)
480 #define UINTPTR_MAX UINT_MAX
483 #error AmigaOS but not M68K/PPC, not supported now
486 #define DUK_USE_OS_STRING "amigaos"
488 /* AmigaOS on M68K or PPC is always big endian. */
489 #if !defined(DUK_USE_BYTEORDER) && (defined(DUK_F_M68K) || defined(DUK_F_PPC))
490 #define DUK_USE_BYTEORDER 3
492 #elif defined(DUK_F_DURANGO)
493 /* --- Durango (XboxOne) --- */
495 * Configuration is nearly identical to Windows, except for
496 * DUK_USE_DATE_TZO_WINDOWS.
499 /* Initial fix: disable secure CRT related warnings when compiling Duktape
500 * itself (must be defined before including Windows headers). Don't define
501 * for user code including duktape.h.
503 #if defined(DUK_COMPILING_DUKTAPE) && !defined(_CRT_SECURE_NO_WARNINGS)
504 #define _CRT_SECURE_NO_WARNINGS
507 /* MSVC does not have sys/param.h */
508 #define DUK_USE_DATE_NOW_WINDOWS
509 #define DUK_USE_DATE_TZO_WINDOWS_NO_DST
510 /* Note: PRS and FMT are intentionally left undefined for now. This means
511 * there is no platform specific date parsing/formatting but there is still
512 * the ISO 8601 standard format.
514 #if defined(DUK_COMPILING_DUKTAPE)
515 /* Only include when compiling Duktape to avoid polluting application build
516 * with a lot of unnecessary defines.
521 #define DUK_USE_OS_STRING "durango"
523 #if !defined(DUK_USE_BYTEORDER)
524 #define DUK_USE_BYTEORDER 1
526 #elif defined(DUK_F_WINDOWS)
527 /* --- Windows --- */
528 /* Windows version can't obviously be determined at compile time,
529 * but _WIN32_WINNT indicates the minimum version targeted:
530 * - https://msdn.microsoft.com/en-us/library/6sehtctf.aspx
533 /* Initial fix: disable secure CRT related warnings when compiling Duktape
534 * itself (must be defined before including Windows headers). Don't define
535 * for user code including duktape.h.
537 #if defined(DUK_COMPILING_DUKTAPE) && !defined(_CRT_SECURE_NO_WARNINGS)
538 #define _CRT_SECURE_NO_WARNINGS
541 /* Windows 32-bit and 64-bit are currently the same. */
542 /* MSVC does not have sys/param.h */
544 #if defined(DUK_COMPILING_DUKTAPE)
545 /* Only include when compiling Duktape to avoid polluting application build
546 * with a lot of unnecessary defines.
551 /* GetSystemTimePreciseAsFileTime() available from Windows 8:
552 * https://msdn.microsoft.com/en-us/library/windows/desktop/hh706895(v=vs.85).aspx
554 #if defined(DUK_USE_DATE_NOW_WINDOWS_SUBMS) || defined(DUK_USE_DATE_NOW_WINDOWS)
555 /* User forced provider. */
557 #if defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0602)
558 #define DUK_USE_DATE_NOW_WINDOWS_SUBMS
560 #define DUK_USE_DATE_NOW_WINDOWS
564 #define DUK_USE_DATE_TZO_WINDOWS
566 /* Note: PRS and FMT are intentionally left undefined for now. This means
567 * there is no platform specific date parsing/formatting but there is still
568 * the ISO 8601 standard format.
571 /* QueryPerformanceCounter() may go backwards in Windows XP, so enable for
572 * Vista and later: https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx#qpc_support_in_windows_versions
574 #if !defined(DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC) && \
575 defined(_WIN32_WINNT) && (_WIN32_WINNT >= 0x0600)
576 #define DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC
579 #define DUK_USE_OS_STRING "windows"
581 /* On Windows, assume we're little endian. Even Itanium which has a
582 * configurable endianness runs little endian in Windows.
584 #if !defined(DUK_USE_BYTEORDER)
585 #define DUK_USE_BYTEORDER 1
587 #elif defined(DUK_F_FLASHPLAYER)
588 /* --- Flashplayer (Crossbridge) --- */
589 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
590 #define DUK_USE_DATE_TZO_GMTIME_R
591 #define DUK_USE_DATE_PRS_STRPTIME
592 #define DUK_USE_DATE_FMT_STRFTIME
594 #include <sys/param.h>
595 #include <sys/time.h>
598 #define DUK_USE_OS_STRING "flashplayer"
600 #if !defined(DUK_USE_BYTEORDER) && defined(DUK_F_FLASHPLAYER)
601 #define DUK_USE_BYTEORDER 1
603 #elif defined(DUK_F_QNX)
605 #if defined(DUK_F_QNX) && defined(DUK_COMPILING_DUKTAPE)
606 /* See: /opt/qnx650/target/qnx6/usr/include/sys/platform.h */
607 #define _XOPEN_SOURCE 600
608 #define _POSIX_C_SOURCE 200112L
611 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
612 #define DUK_USE_DATE_TZO_GMTIME_R
613 #define DUK_USE_DATE_PRS_STRPTIME
614 #define DUK_USE_DATE_FMT_STRFTIME
615 #include <sys/types.h>
616 #include <sys/param.h>
617 #include <sys/time.h>
620 #define DUK_USE_OS_STRING "qnx"
621 #elif defined(DUK_F_TINSPIRE)
622 /* --- TI-Nspire --- */
623 #if defined(DUK_COMPILING_DUKTAPE) && !defined(_XOPEN_SOURCE)
624 #define _XOPEN_SOURCE /* e.g. strptime */
627 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
628 #define DUK_USE_DATE_TZO_GMTIME_R
629 #define DUK_USE_DATE_PRS_STRPTIME
630 #define DUK_USE_DATE_FMT_STRFTIME
631 #include <sys/types.h>
632 #include <sys/param.h>
633 #include <sys/time.h>
636 #define DUK_USE_OS_STRING "tinspire"
637 #elif defined(DUK_F_EMSCRIPTEN)
638 /* --- Emscripten --- */
639 #if defined(DUK_COMPILING_DUKTAPE)
640 #if !defined(_POSIX_C_SOURCE)
641 #define _POSIX_C_SOURCE 200809L
643 #if !defined(_GNU_SOURCE)
644 #define _GNU_SOURCE /* e.g. getdate_r */
646 #if !defined(_XOPEN_SOURCE)
647 #define _XOPEN_SOURCE /* e.g. strptime */
649 #endif /* DUK_COMPILING_DUKTAPE */
651 #include <sys/types.h>
652 #if defined(DUK_F_BCC)
656 #endif /* DUK_F_BCC */
657 #include <sys/param.h>
658 #include <sys/time.h>
662 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
663 #define DUK_USE_DATE_TZO_GMTIME_R
664 #define DUK_USE_DATE_PRS_STRPTIME
665 #define DUK_USE_DATE_FMT_STRFTIME
667 #define DUK_USE_OS_STRING "emscripten"
668 #elif defined(DUK_F_LINUX)
670 #if defined(DUK_COMPILING_DUKTAPE)
671 #if !defined(_POSIX_C_SOURCE)
672 #define _POSIX_C_SOURCE 200809L
674 #if !defined(_GNU_SOURCE)
675 #define _GNU_SOURCE /* e.g. getdate_r */
677 #if !defined(_XOPEN_SOURCE)
678 #define _XOPEN_SOURCE /* e.g. strptime */
680 #endif /* DUK_COMPILING_DUKTAPE */
682 #include <sys/types.h>
683 #if defined(DUK_F_BCC)
684 /* no endian.h or stdint.h */
688 #endif /* DUK_F_BCC */
689 #include <sys/param.h>
690 #include <sys/time.h>
693 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
694 #define DUK_USE_DATE_TZO_GMTIME_R
695 #define DUK_USE_DATE_PRS_STRPTIME
696 #define DUK_USE_DATE_FMT_STRFTIME
698 #if 0 /* XXX: safe condition? */
699 #define DUK_USE_GET_MONOTONIC_TIME_CLOCK_GETTIME
702 #define DUK_USE_OS_STRING "linux"
703 #elif defined(DUK_F_SUN)
704 /* --- Solaris --- */
705 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
706 #define DUK_USE_DATE_TZO_GMTIME_R
707 #define DUK_USE_DATE_PRS_STRPTIME
708 #define DUK_USE_DATE_FMT_STRFTIME
710 #include <sys/types.h>
711 #if defined(DUK_F_OLD_SOLARIS)
712 /* Old Solaris with no endian.h, stdint.h */
713 #define DUK_F_NO_STDINT_H
714 #if !defined(DUK_USE_BYTEORDER)
715 #define DUK_USE_BYTEORDER 3
717 #else /* DUK_F_OLD_SOLARIS */
718 #include <ast/endian.h>
719 #endif /* DUK_F_OLD_SOLARIS */
721 #include <sys/param.h>
722 #include <sys/time.h>
725 #define DUK_USE_OS_STRING "solaris"
726 #elif defined(DUK_F_AIX)
728 #if !defined(DUK_USE_BYTEORDER)
729 #define DUK_USE_BYTEORDER 3
731 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
732 #define DUK_USE_DATE_TZO_GMTIME_R
733 #define DUK_USE_DATE_PRS_STRPTIME
734 #define DUK_USE_DATE_FMT_STRFTIME
735 #include <sys/param.h>
736 #include <sys/time.h>
739 #define DUK_USE_OS_STRING "aix"
740 #elif defined(DUK_F_HPUX)
742 #define DUK_F_NO_STDINT_H
743 #if !defined(DUK_USE_BYTEORDER)
744 #define DUK_USE_BYTEORDER 3
746 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
747 #define DUK_USE_DATE_TZO_GMTIME_R
748 #define DUK_USE_DATE_PRS_STRPTIME
749 #define DUK_USE_DATE_FMT_STRFTIME
750 #include <sys/param.h>
751 #include <sys/time.h>
754 #define DUK_USE_OS_STRING "hpux"
755 #elif defined(DUK_F_POSIX)
756 /* --- Generic POSIX --- */
757 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
758 #define DUK_USE_DATE_TZO_GMTIME_R
759 #define DUK_USE_DATE_PRS_STRPTIME
760 #define DUK_USE_DATE_FMT_STRFTIME
761 #include <sys/types.h>
763 #include <sys/param.h>
764 #include <sys/time.h>
767 #define DUK_USE_OS_STRING "posix"
768 #elif defined(DUK_F_CYGWIN)
770 /* don't use strptime() for now */
771 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
772 #define DUK_USE_DATE_TZO_GMTIME_R
773 #define DUK_USE_DATE_FMT_STRFTIME
774 #include <sys/types.h>
776 #include <sys/param.h>
777 #include <sys/time.h>
780 #define DUK_JMPBUF_TYPE jmp_buf
781 #define DUK_SETJMP(jb) _setjmp((jb))
782 #define DUK_LONGJMP(jb) _longjmp((jb), 1)
784 #define DUK_USE_OS_STRING "windows"
785 #elif defined(DUK_F_UNIX)
786 /* --- Generic UNIX --- */
787 #define DUK_USE_DATE_NOW_GETTIMEOFDAY
788 #define DUK_USE_DATE_TZO_GMTIME_R
789 #define DUK_USE_DATE_PRS_STRPTIME
790 #define DUK_USE_DATE_FMT_STRFTIME
792 #include <sys/time.h>
793 #define DUK_USE_OS_STRING "unknown"
795 /* --- Generic fallback --- */
796 /* The most portable current time provider is time(), but it only has a
797 * one second resolution.
799 #define DUK_USE_DATE_NOW_TIME
801 /* The most portable way to figure out local time offset is gmtime(),
802 * but it's not thread safe so use with caution.
804 #define DUK_USE_DATE_TZO_GMTIME
806 /* Avoid custom date parsing and formatting for portability. */
807 #undef DUK_USE_DATE_PRS_STRPTIME
808 #undef DUK_USE_DATE_FMT_STRFTIME
810 /* Rely on C89 headers only; time.h must be here. */
813 #define DUK_USE_OS_STRING "unknown"
814 #endif /* autodetect platform */
816 /* Shared includes: C89 */
820 #include <stdarg.h> /* varargs */
822 #include <stddef.h> /* e.g. ptrdiff_t */
826 /* date.h is omitted, and included per platform */
828 /* Shared includes: stdint.h is C99 */
829 #if defined(DUK_F_NO_STDINT_H)
830 /* stdint.h not available */
832 /* Technically C99 (C++11) but found in many systems. On some systems
833 * __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS must be defined before
834 * including stdint.h (see above).
839 /* <exception> is only included if needed, based on DUK_USE_xxx flags. */
842 * Architecture autodetection
845 #if defined(DUK_F_X86)
847 #define DUK_USE_ARCH_STRING "x86"
848 #if !defined(DUK_USE_BYTEORDER)
849 #define DUK_USE_BYTEORDER 1
852 #define DUK_USE_PACKED_TVAL
854 /* FreeBSD, -m32, and clang prior to 5.0 has union aliasing issues which
855 * break duk_tval copying. Disable packed duk_tval automatically.
857 #if defined(DUK_F_FREEBSD) && defined(DUK_F_X86) && \
858 defined(__clang__) && defined(__clang_major__) && (__clang_major__ < 5)
859 #undef DUK_USE_PACKED_TVAL
861 #define DUK_F_PACKED_TVAL_PROVIDED
862 #elif defined(DUK_F_X64)
864 #define DUK_USE_ARCH_STRING "x64"
865 #if !defined(DUK_USE_BYTEORDER)
866 #define DUK_USE_BYTEORDER 1
868 #undef DUK_USE_PACKED_TVAL
869 #define DUK_F_PACKED_TVAL_PROVIDED
870 #elif defined(DUK_F_X32)
872 #define DUK_USE_ARCH_STRING "x32"
873 #if !defined(DUK_USE_BYTEORDER)
874 #define DUK_USE_BYTEORDER 1
876 #define DUK_USE_PACKED_TVAL
877 #define DUK_F_PACKED_TVAL_PROVIDED
878 #elif defined(DUK_F_ARM32)
879 /* --- ARM 32-bit --- */
880 #define DUK_USE_ARCH_STRING "arm32"
881 /* Byte order varies, so rely on autodetect. */
882 #define DUK_USE_PACKED_TVAL
883 #define DUK_F_PACKED_TVAL_PROVIDED
884 #elif defined(DUK_F_ARM64)
885 /* --- ARM 64-bit --- */
886 #define DUK_USE_ARCH_STRING "arm64"
887 /* Byte order varies, so rely on autodetect. */
888 #undef DUK_USE_PACKED_TVAL
889 #define DUK_F_PACKED_TVAL_PROVIDED
890 #elif defined(DUK_F_MIPS32)
891 /* --- MIPS 32-bit --- */
892 #define DUK_USE_ARCH_STRING "mips32"
893 /* MIPS byte order varies so rely on autodetection. */
894 #define DUK_USE_PACKED_TVAL
895 #define DUK_F_PACKED_TVAL_PROVIDED
896 #elif defined(DUK_F_MIPS64)
897 /* --- MIPS 64-bit --- */
898 #define DUK_USE_ARCH_STRING "mips64"
899 /* MIPS byte order varies so rely on autodetection. */
900 #undef DUK_USE_PACKED_TVAL
901 #define DUK_F_PACKED_TVAL_PROVIDED
902 #elif defined(DUK_F_PPC32)
903 /* --- PowerPC 32-bit --- */
904 #define DUK_USE_ARCH_STRING "ppc32"
905 #if !defined(DUK_USE_BYTEORDER)
906 #define DUK_USE_BYTEORDER 3
908 #define DUK_USE_PACKED_TVAL
909 #define DUK_F_PACKED_TVAL_PROVIDED
910 #elif defined(DUK_F_PPC64)
911 /* --- PowerPC 64-bit --- */
912 #define DUK_USE_ARCH_STRING "ppc64"
913 #if !defined(DUK_USE_BYTEORDER)
914 #define DUK_USE_BYTEORDER 3
916 #undef DUK_USE_PACKED_TVAL
917 #define DUK_F_PACKED_TVAL_PROVIDED
918 #elif defined(DUK_F_SPARC32)
919 /* --- SPARC 32-bit --- */
920 #define DUK_USE_ARCH_STRING "sparc32"
921 /* SPARC byte order varies so rely on autodetection. */
922 #define DUK_USE_PACKED_TVAL
923 #define DUK_F_PACKED_TVAL_PROVIDED
924 #elif defined(DUK_F_SPARC64)
925 /* --- SPARC 64-bit --- */
926 #define DUK_USE_ARCH_STRING "sparc64"
927 /* SPARC byte order varies so rely on autodetection. */
928 #undef DUK_USE_PACKED_TVAL
929 #define DUK_F_PACKED_TVAL_PROVIDED
930 #elif defined(DUK_F_SUPERH)
932 #define DUK_USE_ARCH_STRING "sh"
933 /* Byte order varies, rely on autodetection. */
934 #define DUK_USE_PACKED_TVAL
935 #define DUK_F_PACKED_TVAL_PROVIDED
936 #elif defined(DUK_F_M68K)
937 /* --- Motorola 68k --- */
938 #define DUK_USE_ARCH_STRING "m68k"
939 #if !defined(DUK_USE_BYTEORDER)
940 #define DUK_USE_BYTEORDER 3
942 #define DUK_USE_PACKED_TVAL
943 #define DUK_F_PACKED_TVAL_PROVIDED
944 #elif defined(DUK_F_EMSCRIPTEN)
945 /* --- Emscripten --- */
946 #define DUK_USE_ARCH_STRING "emscripten"
947 #if !defined(DUK_USE_BYTEORDER)
948 #define DUK_USE_BYTEORDER 1
950 #undef DUK_USE_PACKED_TVAL
951 #define DUK_F_PACKED_TVAL_PROVIDED
953 /* --- Generic --- */
954 /* These are necessary wild guesses. */
955 #define DUK_USE_ARCH_STRING "generic"
956 /* Rely on autodetection for byte order, alignment, and packed tval. */
957 #endif /* autodetect architecture */
960 * Compiler autodetection
963 #if defined(DUK_F_CLANG)
965 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
966 /* C99 / C++11 and above: rely on va_copy() which is required. */
967 #define DUK_VA_COPY(dest,src) va_copy(dest,src)
969 /* Clang: assume we have __va_copy() in non-C99 mode. */
970 #define DUK_VA_COPY(dest,src) __va_copy(dest,src)
973 #define DUK_NORETURN(decl) decl __attribute__((noreturn))
975 #if defined(__clang__) && defined(__has_builtin)
976 #if __has_builtin(__builtin_unreachable)
977 #define DUK_UNREACHABLE() do { __builtin_unreachable(); } while (0)
981 #define DUK_USE_BRANCH_HINTS
982 #define DUK_LIKELY(x) __builtin_expect((x), 1)
983 #define DUK_UNLIKELY(x) __builtin_expect((x), 0)
984 #if defined(__clang__) && defined(__has_builtin)
985 #if __has_builtin(__builtin_unpredictable)
986 #define DUK_UNPREDICTABLE(x) __builtin_unpredictable((x))
990 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
991 #define DUK_NOINLINE __attribute__((noinline))
992 #define DUK_INLINE inline
993 #define DUK_ALWAYS_INLINE inline __attribute__((always_inline))
999 #if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
1000 /* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
1001 * compiling Duktape or the application.
1003 #if defined(DUK_COMPILING_DUKTAPE)
1004 #define DUK_EXTERNAL_DECL extern __declspec(dllexport)
1005 #define DUK_EXTERNAL __declspec(dllexport)
1007 #define DUK_EXTERNAL_DECL extern __declspec(dllimport)
1008 #define DUK_EXTERNAL should_not_happen
1010 #if defined(DUK_SINGLE_FILE)
1011 #define DUK_INTERNAL_DECL static
1012 #define DUK_INTERNAL static
1014 #define DUK_INTERNAL_DECL extern
1015 #define DUK_INTERNAL /*empty*/
1017 #define DUK_LOCAL_DECL static
1018 #define DUK_LOCAL static
1020 #define DUK_EXTERNAL_DECL __attribute__ ((visibility("default"))) extern
1021 #define DUK_EXTERNAL __attribute__ ((visibility("default")))
1022 #if defined(DUK_SINGLE_FILE)
1023 #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
1024 /* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
1025 * Clang. Based on documentation it should suffice to have the attribute
1026 * in the declaration only, but in practice some warnings are generated unless
1027 * the attribute is also applied to the definition.
1029 #define DUK_INTERNAL_DECL static __attribute__ ((unused))
1030 #define DUK_INTERNAL static __attribute__ ((unused))
1032 #define DUK_INTERNAL_DECL static
1033 #define DUK_INTERNAL static
1036 #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
1037 #define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
1038 #define DUK_INTERNAL __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
1040 #define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) extern
1041 #define DUK_INTERNAL __attribute__ ((visibility("hidden")))
1044 #define DUK_LOCAL_DECL static
1045 #define DUK_LOCAL static
1048 #if defined(DUK_F_CPP)
1049 #define DUK_USE_COMPILER_STRING "clang"
1051 #define DUK_USE_COMPILER_STRING "clang"
1054 #undef DUK_USE_VARIADIC_MACROS
1055 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
1056 #define DUK_USE_VARIADIC_MACROS
1059 #define DUK_USE_UNION_INITIALIZERS
1061 #undef DUK_USE_FLEX_C99
1062 #undef DUK_USE_FLEX_ZEROSIZE
1063 #undef DUK_USE_FLEX_ONESIZE
1064 #if defined(DUK_F_C99)
1065 #define DUK_USE_FLEX_C99
1067 #define DUK_USE_FLEX_ZEROSIZE
1070 #undef DUK_USE_GCC_PRAGMAS
1071 #define DUK_USE_PACK_CLANG_ATTR
1072 #elif defined(DUK_F_GCC)
1074 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
1075 /* C99 / C++11 and above: rely on va_copy() which is required. */
1076 #define DUK_VA_COPY(dest,src) va_copy(dest,src)
1078 /* GCC: assume we have __va_copy() in non-C99 mode. */
1079 #define DUK_VA_COPY(dest,src) __va_copy(dest,src)
1082 #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 20500L)
1084 #define DUK_NORETURN(decl) decl __attribute__((noreturn))
1087 #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40500L)
1089 #define DUK_UNREACHABLE() do { __builtin_unreachable(); } while (0)
1092 #define DUK_USE_BRANCH_HINTS
1093 #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40500L)
1094 /* GCC: test not very accurate; enable only in relatively recent builds
1095 * because of bugs in gcc-4.4 (http://lists.debian.org/debian-gcc/2010/04/msg00000.html)
1097 #define DUK_LIKELY(x) __builtin_expect((x), 1)
1098 #define DUK_UNLIKELY(x) __builtin_expect((x), 0)
1100 /* XXX: equivalent of clang __builtin_unpredictable? */
1102 #if (defined(DUK_F_C99) || defined(DUK_F_CPP11)) && \
1103 defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 30101)
1104 #define DUK_NOINLINE __attribute__((noinline))
1105 #define DUK_INLINE inline
1106 #define DUK_ALWAYS_INLINE inline __attribute__((always_inline))
1109 #if (defined(DUK_F_C99) || defined(DUK_F_CPP11)) && \
1110 defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40300)
1111 #define DUK_HOT __attribute__((hot))
1112 #define DUK_COLD __attribute__((cold))
1115 #if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
1116 /* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
1117 * compiling Duktape or the application.
1119 #if defined(DUK_COMPILING_DUKTAPE)
1120 #define DUK_EXTERNAL_DECL extern __declspec(dllexport)
1121 #define DUK_EXTERNAL __declspec(dllexport)
1123 #define DUK_EXTERNAL_DECL extern __declspec(dllimport)
1124 #define DUK_EXTERNAL should_not_happen
1126 #if defined(DUK_SINGLE_FILE)
1127 #define DUK_INTERNAL_DECL static
1128 #define DUK_INTERNAL static
1130 #define DUK_INTERNAL_DECL extern
1131 #define DUK_INTERNAL /*empty*/
1133 #define DUK_LOCAL_DECL static
1134 #define DUK_LOCAL static
1135 #elif defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40000)
1136 #define DUK_EXTERNAL_DECL __attribute__ ((visibility("default"))) extern
1137 #define DUK_EXTERNAL __attribute__ ((visibility("default")))
1138 #if defined(DUK_SINGLE_FILE)
1139 #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
1140 /* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
1141 * Clang. Based on documentation it should suffice to have the attribute
1142 * in the declaration only, but in practice some warnings are generated unless
1143 * the attribute is also applied to the definition.
1145 #define DUK_INTERNAL_DECL static __attribute__ ((unused))
1146 #define DUK_INTERNAL static __attribute__ ((unused))
1148 #define DUK_INTERNAL_DECL static
1149 #define DUK_INTERNAL static
1152 #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
1153 #define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
1154 #define DUK_INTERNAL __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
1156 #define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) extern
1157 #define DUK_INTERNAL __attribute__ ((visibility("hidden")))
1160 #define DUK_LOCAL_DECL static
1161 #define DUK_LOCAL static
1164 #if defined(DUK_F_MINGW)
1165 #if defined(DUK_F_CPP)
1166 #define DUK_USE_COMPILER_STRING "mingw++"
1168 #define DUK_USE_COMPILER_STRING "mingw"
1171 #if defined(DUK_F_CPP)
1172 #define DUK_USE_COMPILER_STRING "g++"
1174 #define DUK_USE_COMPILER_STRING "gcc"
1178 #undef DUK_USE_VARIADIC_MACROS
1179 #if defined(DUK_F_C99) || (defined(DUK_F_CPP11) && defined(__GNUC__))
1180 #define DUK_USE_VARIADIC_MACROS
1183 #define DUK_USE_UNION_INITIALIZERS
1185 #undef DUK_USE_FLEX_C99
1186 #undef DUK_USE_FLEX_ZEROSIZE
1187 #undef DUK_USE_FLEX_ONESIZE
1188 #if defined(DUK_F_C99)
1189 #define DUK_USE_FLEX_C99
1191 #define DUK_USE_FLEX_ZEROSIZE
1194 #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION >= 40600)
1195 #define DUK_USE_GCC_PRAGMAS
1197 #undef DUK_USE_GCC_PRAGMAS
1200 #define DUK_USE_PACK_GCC_ATTR
1201 #elif defined(DUK_F_MSVC)
1203 /* http://msdn.microsoft.com/en-us/library/aa235362(VS.60).aspx */
1204 #define DUK_NORETURN(decl) __declspec(noreturn) decl
1206 /* XXX: DUK_UNREACHABLE for msvc? */
1208 #undef DUK_USE_BRANCH_HINTS
1210 /* XXX: DUK_LIKELY, DUK_UNLIKELY for msvc? */
1211 /* XXX: DUK_NOINLINE, DUK_INLINE, DUK_ALWAYS_INLINE for msvc? */
1213 #if defined(DUK_F_DLL_BUILD) && defined(DUK_F_WINDOWS)
1214 /* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
1215 * compiling Duktape or the application.
1217 #if defined(DUK_COMPILING_DUKTAPE)
1218 #define DUK_EXTERNAL_DECL extern __declspec(dllexport)
1219 #define DUK_EXTERNAL __declspec(dllexport)
1221 #define DUK_EXTERNAL_DECL extern __declspec(dllimport)
1222 #define DUK_EXTERNAL should_not_happen
1224 #if defined(DUK_SINGLE_FILE)
1225 #define DUK_INTERNAL_DECL static
1226 #define DUK_INTERNAL static
1228 #define DUK_INTERNAL_DECL extern
1229 #define DUK_INTERNAL /*empty*/
1231 #define DUK_LOCAL_DECL static
1232 #define DUK_LOCAL static
1235 #if defined(DUK_F_CPP)
1236 #define DUK_USE_COMPILER_STRING "msvc++"
1238 #define DUK_USE_COMPILER_STRING "msvc"
1241 #undef DUK_USE_VARIADIC_MACROS
1242 #if defined(DUK_F_C99)
1243 #define DUK_USE_VARIADIC_MACROS
1244 #elif defined(_MSC_VER) && (_MSC_VER >= 1400)
1245 /* VS2005+ should have variadic macros even when they're not C99. */
1246 #define DUK_USE_VARIADIC_MACROS
1249 #undef DUK_USE_UNION_INITIALIZERS
1250 #if defined(_MSC_VER) && (_MSC_VER >= 1800)
1251 /* VS2013+ supports union initializers but there's a bug involving union-inside-struct:
1252 * https://connect.microsoft.com/VisualStudio/feedback/details/805981
1253 * The bug was fixed (at least) in VS2015 so check for VS2015 for now:
1254 * https://blogs.msdn.microsoft.com/vcblog/2015/07/01/c-compiler-front-end-fixes-in-vs2015/
1255 * Manually tested using VS2013, CL reports 18.00.31101, so enable for VS2013 too.
1257 #define DUK_USE_UNION_INITIALIZERS
1260 #undef DUK_USE_FLEX_C99
1261 #undef DUK_USE_FLEX_ZEROSIZE
1262 #undef DUK_USE_FLEX_ONESIZE
1263 #if defined(DUK_F_C99)
1264 #define DUK_USE_FLEX_C99
1266 #define DUK_USE_FLEX_ZEROSIZE
1269 #undef DUK_USE_GCC_PRAGMAS
1271 #define DUK_USE_PACK_MSVC_PRAGMA
1273 /* These have been tested from VS2008 onwards; may work in older VS versions
1274 * too but not enabled by default.
1276 #if defined(_MSC_VER) && (_MSC_VER >= 1500)
1277 #define DUK_NOINLINE __declspec(noinline)
1278 #define DUK_INLINE __inline
1279 #define DUK_ALWAYS_INLINE __forceinline
1282 #if defined(_MSC_VER) && (_MSC_VER >= 1900)
1283 #define DUK_SNPRINTF snprintf
1284 #define DUK_VSNPRINTF vsnprintf
1286 /* (v)snprintf() is missing before MSVC 2015. Note that _(v)snprintf() does
1287 * NOT NUL terminate on truncation, but Duktape code never assumes that.
1288 * http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
1290 #define DUK_SNPRINTF _snprintf
1291 #define DUK_VSNPRINTF _vsnprintf
1294 /* Avoid warning when doing DUK_UNREF(some_function). */
1295 #if defined(_MSC_VER) && (_MSC_VER < 1500)
1296 #pragma warning(disable: 4100 4101 4550 4551)
1297 #define DUK_UNREF(x)
1299 #define DUK_UNREF(x) do { __pragma(warning(suppress:4100 4101 4550 4551)) (x); } while (0)
1302 /* Older versions of MSVC don't support the LL/ULL suffix. */
1303 #define DUK_U64_CONSTANT(x) x##ui64
1304 #define DUK_I64_CONSTANT(x) x##i64
1305 #elif defined(DUK_F_EMSCRIPTEN)
1306 /* --- Emscripten --- */
1307 #define DUK_NORETURN(decl) decl __attribute__((noreturn))
1309 #if defined(__clang__) && defined(__has_builtin)
1310 #if __has_builtin(__builtin_unreachable)
1311 #define DUK_UNREACHABLE() do { __builtin_unreachable(); } while (0)
1315 #define DUK_USE_BRANCH_HINTS
1316 #define DUK_LIKELY(x) __builtin_expect((x), 1)
1317 #define DUK_UNLIKELY(x) __builtin_expect((x), 0)
1318 #if defined(__clang__) && defined(__has_builtin)
1319 #if __has_builtin(__builtin_unpredictable)
1320 #define DUK_UNPREDICTABLE(x) __builtin_unpredictable((x))
1324 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
1325 #define DUK_NOINLINE __attribute__((noinline))
1326 #define DUK_INLINE inline
1327 #define DUK_ALWAYS_INLINE inline __attribute__((always_inline))
1330 #define DUK_EXTERNAL_DECL __attribute__ ((visibility("default"))) extern
1331 #define DUK_EXTERNAL __attribute__ ((visibility("default")))
1332 #if defined(DUK_SINGLE_FILE)
1333 #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
1334 /* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
1335 * Clang. Based on documentation it should suffice to have the attribute
1336 * in the declaration only, but in practice some warnings are generated unless
1337 * the attribute is also applied to the definition.
1339 #define DUK_INTERNAL_DECL static __attribute__ ((unused))
1340 #define DUK_INTERNAL static __attribute__ ((unused))
1342 #define DUK_INTERNAL_DECL static
1343 #define DUK_INTERNAL static
1346 #if (defined(DUK_F_GCC_VERSION) && DUK_F_GCC_VERSION >= 30101) || defined(DUK_F_CLANG)
1347 #define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) __attribute__ ((unused)) extern
1348 #define DUK_INTERNAL __attribute__ ((visibility("hidden"))) __attribute__ ((unused))
1350 #define DUK_INTERNAL_DECL __attribute__ ((visibility("hidden"))) extern
1351 #define DUK_INTERNAL __attribute__ ((visibility("hidden")))
1354 #define DUK_LOCAL_DECL static
1355 #define DUK_LOCAL static
1357 #define DUK_USE_COMPILER_STRING "emscripten"
1359 #undef DUK_USE_VARIADIC_MACROS
1360 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
1361 #define DUK_USE_VARIADIC_MACROS
1364 #define DUK_USE_UNION_INITIALIZERS
1366 #undef DUK_USE_FLEX_C99
1367 #undef DUK_USE_FLEX_ZEROSIZE
1368 #undef DUK_USE_FLEX_ONESIZE
1369 #if defined(DUK_F_C99)
1370 #define DUK_USE_FLEX_C99
1372 #define DUK_USE_FLEX_ZEROSIZE
1375 #undef DUK_USE_GCC_PRAGMAS
1376 #define DUK_USE_PACK_CLANG_ATTR
1377 #elif defined(DUK_F_TINYC)
1379 #undef DUK_USE_BRANCH_HINTS
1381 #if defined(DUK_F_CPP)
1382 #define DUK_USE_COMPILER_STRING "tinyc++"
1384 #define DUK_USE_COMPILER_STRING "tinyc"
1387 /* http://bellard.org/tcc/tcc-doc.html#SEC7 */
1388 #define DUK_USE_VARIADIC_MACROS
1390 #define DUK_USE_UNION_INITIALIZERS
1392 /* Most portable, wastes space */
1393 #define DUK_USE_FLEX_ONESIZE
1395 /* Most portable, potentially wastes space */
1396 #define DUK_USE_PACK_DUMMY_MEMBER
1397 #elif defined(DUK_F_VBCC)
1399 #undef DUK_USE_BRANCH_HINTS
1401 #if defined(DUK_F_CPP)
1402 #define DUK_USE_COMPILER_STRING "vbcc-c++"
1404 #define DUK_USE_COMPILER_STRING "vbcc"
1407 #undef DUK_USE_VARIADIC_MACROS
1408 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
1409 #define DUK_USE_VARIADIC_MACROS
1412 /* VBCC supports C99 so check only for C99 for union initializer support.
1413 * Designated union initializers would possibly work even without a C99 check.
1415 #undef DUK_USE_UNION_INITIALIZERS
1416 #if defined(DUK_F_C99)
1417 #define DUK_USE_UNION_INITIALIZERS
1420 #define DUK_USE_FLEX_ZEROSIZE
1421 #define DUK_USE_PACK_DUMMY_MEMBER
1422 #elif defined(DUK_F_BCC)
1423 /* --- Bruce's C compiler --- */
1424 #undef DUK_USE_BRANCH_HINTS
1426 #if defined(DUK_F_CPP)
1427 #define DUK_USE_COMPILER_STRING "bcc++"
1429 #define DUK_USE_COMPILER_STRING "bcc"
1433 #undef DUK_USE_VARIADIC_MACROS
1435 /* Most portable, wastes space */
1436 #undef DUK_USE_UNION_INITIALIZERS
1438 /* Most portable, wastes space */
1439 #define DUK_USE_FLEX_ONESIZE
1441 /* Most portable, potentially wastes space */
1442 #define DUK_USE_PACK_DUMMY_MEMBER
1444 /* BCC, assume we're on x86. */
1445 #if !defined(DUK_USE_BYTEORDER)
1446 #define DUK_USE_BYTEORDER 1
1449 /* --- Generic --- */
1450 #undef DUK_USE_BRANCH_HINTS
1452 #if defined(DUK_F_CPP)
1453 #define DUK_USE_COMPILER_STRING "generic-c++"
1455 #define DUK_USE_COMPILER_STRING "generic"
1458 #undef DUK_USE_VARIADIC_MACROS
1459 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
1460 #define DUK_USE_VARIADIC_MACROS
1463 /* C++ doesn't have standard designated union initializers ({ .foo = 1 }). */
1464 #undef DUK_USE_UNION_INITIALIZERS
1465 #if defined(DUK_F_C99)
1466 #define DUK_USE_UNION_INITIALIZERS
1469 /* Most portable, wastes space */
1470 #define DUK_USE_FLEX_ONESIZE
1472 /* Most portable, potentially wastes space */
1473 #define DUK_USE_PACK_DUMMY_MEMBER
1474 #endif /* autodetect compiler */
1477 #if defined(__UCLIBC__)
1478 #define DUK_F_UCLIBC
1482 * Wrapper typedefs and constants for integer types, also sanity check types.
1484 * C99 typedefs are quite good but not always available, and we want to avoid
1485 * forcibly redefining the C99 typedefs. So, there are Duktape wrappers for
1486 * all C99 typedefs and Duktape code should only use these typedefs. Type
1487 * detection when C99 is not supported is best effort and may end up detecting
1488 * some types incorrectly.
1490 * Pointer sizes are a portability problem: pointers to different types may
1491 * have a different size and function pointers are very difficult to manage
1494 * http://en.wikipedia.org/wiki/C_data_types#Fixed-width_integer_types
1496 * Note: there's an interesting corner case when trying to define minimum
1497 * signed integer value constants which leads to the current workaround of
1498 * defining e.g. -0x80000000 as (-0x7fffffffL - 1L). See doc/code-issues.txt
1499 * for a longer discussion.
1501 * Note: avoid typecasts and computations in macro integer constants as they
1502 * can then no longer be used in macro relational expressions (such as
1503 * #if DUK_SIZE_MAX < 0xffffffffUL). There is internal code which relies on
1504 * being able to compare DUK_SIZE_MAX against a limit.
1507 /* XXX: add feature options to force basic types from outside? */
1509 #if !defined(INT_MAX)
1510 #error INT_MAX not defined
1513 /* Check that architecture is two's complement, standard C allows e.g.
1514 * INT_MIN to be -2**31+1 (instead of -2**31).
1516 #if defined(INT_MAX) && defined(INT_MIN)
1517 #if INT_MAX != -(INT_MIN + 1)
1518 #error platform does not seem complement of two
1521 #error cannot check complement of two
1524 /* Pointer size determination based on __WORDSIZE or architecture when
1525 * that's not available.
1527 #if defined(DUK_F_X86) || defined(DUK_F_X32) || \
1528 defined(DUK_F_M68K) || defined(DUK_F_PPC32) || \
1529 defined(DUK_F_BCC) || \
1530 (defined(__WORDSIZE) && (__WORDSIZE == 32)) || \
1531 ((defined(DUK_F_OLD_SOLARIS) || defined(DUK_F_AIX) || \
1532 defined(DUK_F_HPUX)) && defined(_ILP32)) || \
1533 defined(DUK_F_ARM32)
1534 #define DUK_F_32BIT_PTRS
1535 #elif defined(DUK_F_X64) || \
1536 (defined(__WORDSIZE) && (__WORDSIZE == 64)) || \
1537 ((defined(DUK_F_OLD_SOLARIS) || defined(DUK_F_AIX) || \
1538 defined(DUK_F_HPUX)) && defined(_LP64)) || \
1539 defined(DUK_F_ARM64)
1540 #define DUK_F_64BIT_PTRS
1542 /* not sure, not needed with C99 anyway */
1545 /* Intermediate define for 'have inttypes.h' */
1546 #undef DUK_F_HAVE_INTTYPES
1547 #if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \
1548 !(defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC))
1549 /* vbcc + AmigaOS has C99 but no inttypes.h */
1550 #define DUK_F_HAVE_INTTYPES
1551 #elif defined(__cplusplus) && (__cplusplus >= 201103L)
1552 /* C++11 apparently ratified stdint.h */
1553 #define DUK_F_HAVE_INTTYPES
1556 /* Basic integer typedefs and limits, preferably from inttypes.h, otherwise
1557 * through automatic detection.
1559 #if defined(DUK_F_HAVE_INTTYPES)
1560 /* C99 or compatible */
1562 #define DUK_F_HAVE_64BIT
1563 #include <inttypes.h>
1565 typedef uint8_t duk_uint8_t;
1566 typedef int8_t duk_int8_t;
1567 typedef uint16_t duk_uint16_t;
1568 typedef int16_t duk_int16_t;
1569 typedef uint32_t duk_uint32_t;
1570 typedef int32_t duk_int32_t;
1571 typedef uint64_t duk_uint64_t;
1572 typedef int64_t duk_int64_t;
1573 typedef uint_least8_t duk_uint_least8_t;
1574 typedef int_least8_t duk_int_least8_t;
1575 typedef uint_least16_t duk_uint_least16_t;
1576 typedef int_least16_t duk_int_least16_t;
1577 typedef uint_least32_t duk_uint_least32_t;
1578 typedef int_least32_t duk_int_least32_t;
1579 typedef uint_least64_t duk_uint_least64_t;
1580 typedef int_least64_t duk_int_least64_t;
1581 typedef uint_fast8_t duk_uint_fast8_t;
1582 typedef int_fast8_t duk_int_fast8_t;
1583 typedef uint_fast16_t duk_uint_fast16_t;
1584 typedef int_fast16_t duk_int_fast16_t;
1585 typedef uint_fast32_t duk_uint_fast32_t;
1586 typedef int_fast32_t duk_int_fast32_t;
1587 typedef uint_fast64_t duk_uint_fast64_t;
1588 typedef int_fast64_t duk_int_fast64_t;
1589 typedef uintptr_t duk_uintptr_t;
1590 typedef intptr_t duk_intptr_t;
1591 typedef uintmax_t duk_uintmax_t;
1592 typedef intmax_t duk_intmax_t;
1594 #define DUK_UINT8_MIN 0
1595 #define DUK_UINT8_MAX UINT8_MAX
1596 #define DUK_INT8_MIN INT8_MIN
1597 #define DUK_INT8_MAX INT8_MAX
1598 #define DUK_UINT_LEAST8_MIN 0
1599 #define DUK_UINT_LEAST8_MAX UINT_LEAST8_MAX
1600 #define DUK_INT_LEAST8_MIN INT_LEAST8_MIN
1601 #define DUK_INT_LEAST8_MAX INT_LEAST8_MAX
1602 #define DUK_UINT_FAST8_MIN 0
1603 #define DUK_UINT_FAST8_MAX UINT_FAST8_MAX
1604 #define DUK_INT_FAST8_MIN INT_FAST8_MIN
1605 #define DUK_INT_FAST8_MAX INT_FAST8_MAX
1606 #define DUK_UINT16_MIN 0
1607 #define DUK_UINT16_MAX UINT16_MAX
1608 #define DUK_INT16_MIN INT16_MIN
1609 #define DUK_INT16_MAX INT16_MAX
1610 #define DUK_UINT_LEAST16_MIN 0
1611 #define DUK_UINT_LEAST16_MAX UINT_LEAST16_MAX
1612 #define DUK_INT_LEAST16_MIN INT_LEAST16_MIN
1613 #define DUK_INT_LEAST16_MAX INT_LEAST16_MAX
1614 #define DUK_UINT_FAST16_MIN 0
1615 #define DUK_UINT_FAST16_MAX UINT_FAST16_MAX
1616 #define DUK_INT_FAST16_MIN INT_FAST16_MIN
1617 #define DUK_INT_FAST16_MAX INT_FAST16_MAX
1618 #define DUK_UINT32_MIN 0
1619 #define DUK_UINT32_MAX UINT32_MAX
1620 #define DUK_INT32_MIN INT32_MIN
1621 #define DUK_INT32_MAX INT32_MAX
1622 #define DUK_UINT_LEAST32_MIN 0
1623 #define DUK_UINT_LEAST32_MAX UINT_LEAST32_MAX
1624 #define DUK_INT_LEAST32_MIN INT_LEAST32_MIN
1625 #define DUK_INT_LEAST32_MAX INT_LEAST32_MAX
1626 #define DUK_UINT_FAST32_MIN 0
1627 #define DUK_UINT_FAST32_MAX UINT_FAST32_MAX
1628 #define DUK_INT_FAST32_MIN INT_FAST32_MIN
1629 #define DUK_INT_FAST32_MAX INT_FAST32_MAX
1630 #define DUK_UINT64_MIN 0
1631 #define DUK_UINT64_MAX UINT64_MAX
1632 #define DUK_INT64_MIN INT64_MIN
1633 #define DUK_INT64_MAX INT64_MAX
1634 #define DUK_UINT_LEAST64_MIN 0
1635 #define DUK_UINT_LEAST64_MAX UINT_LEAST64_MAX
1636 #define DUK_INT_LEAST64_MIN INT_LEAST64_MIN
1637 #define DUK_INT_LEAST64_MAX INT_LEAST64_MAX
1638 #define DUK_UINT_FAST64_MIN 0
1639 #define DUK_UINT_FAST64_MAX UINT_FAST64_MAX
1640 #define DUK_INT_FAST64_MIN INT_FAST64_MIN
1641 #define DUK_INT_FAST64_MAX INT_FAST64_MAX
1643 #define DUK_UINTPTR_MIN 0
1644 #define DUK_UINTPTR_MAX UINTPTR_MAX
1645 #define DUK_INTPTR_MIN INTPTR_MIN
1646 #define DUK_INTPTR_MAX INTPTR_MAX
1648 #define DUK_UINTMAX_MIN 0
1649 #define DUK_UINTMAX_MAX UINTMAX_MAX
1650 #define DUK_INTMAX_MIN INTMAX_MIN
1651 #define DUK_INTMAX_MAX INTMAX_MAX
1653 #define DUK_SIZE_MIN 0
1654 #define DUK_SIZE_MAX SIZE_MAX
1655 #undef DUK_SIZE_MAX_COMPUTED
1657 #else /* C99 types */
1659 /* When C99 types are not available, we use heuristic detection to get
1660 * the basic 8, 16, 32, and (possibly) 64 bit types. The fast/least
1661 * types are then assumed to be exactly the same for now: these could
1662 * be improved per platform but C99 types are very often now available.
1663 * 64-bit types are not available on all platforms; this is OK at least
1664 * on 32-bit platforms.
1666 * This detection code is necessarily a bit hacky and can provide typedefs
1667 * and defines that won't work correctly on some exotic platform.
1670 #if (defined(CHAR_BIT) && (CHAR_BIT == 8)) || \
1671 (defined(UCHAR_MAX) && (UCHAR_MAX == 255))
1672 typedef unsigned char duk_uint8_t;
1673 typedef signed char duk_int8_t;
1675 #error cannot detect 8-bit type
1678 #if defined(USHRT_MAX) && (USHRT_MAX == 65535UL)
1679 typedef unsigned short duk_uint16_t;
1680 typedef signed short duk_int16_t;
1681 #elif defined(UINT_MAX) && (UINT_MAX == 65535UL)
1682 /* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */
1683 typedef unsigned int duk_uint16_t;
1684 typedef signed int duk_int16_t;
1686 #error cannot detect 16-bit type
1689 #if defined(UINT_MAX) && (UINT_MAX == 4294967295UL)
1690 typedef unsigned int duk_uint32_t;
1691 typedef signed int duk_int32_t;
1692 #elif defined(ULONG_MAX) && (ULONG_MAX == 4294967295UL)
1693 /* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */
1694 typedef unsigned long duk_uint32_t;
1695 typedef signed long duk_int32_t;
1697 #error cannot detect 32-bit type
1700 /* 64-bit type detection is a bit tricky.
1702 * ULLONG_MAX is a standard define. __LONG_LONG_MAX__ and __ULONG_LONG_MAX__
1703 * are used by at least GCC (even if system headers don't provide ULLONG_MAX).
1704 * Some GCC variants may provide __LONG_LONG_MAX__ but not __ULONG_LONG_MAX__.
1706 * ULL / LL constants are rejected / warned about by some compilers, even if
1707 * the compiler has a 64-bit type and the compiler/system headers provide an
1708 * unsupported constant (ULL/LL)! Try to avoid using ULL / LL constants.
1709 * As a side effect we can only check that e.g. ULONG_MAX is larger than 32
1710 * bits but can't be sure it is exactly 64 bits. Self tests will catch such
1713 #undef DUK_F_HAVE_64BIT
1714 #if !defined(DUK_F_HAVE_64BIT) && defined(ULONG_MAX)
1715 #if (ULONG_MAX > 4294967295UL)
1716 #define DUK_F_HAVE_64BIT
1717 typedef unsigned long duk_uint64_t;
1718 typedef signed long duk_int64_t;
1721 #if !defined(DUK_F_HAVE_64BIT) && defined(ULLONG_MAX)
1722 #if (ULLONG_MAX > 4294967295UL)
1723 #define DUK_F_HAVE_64BIT
1724 typedef unsigned long long duk_uint64_t;
1725 typedef signed long long duk_int64_t;
1728 #if !defined(DUK_F_HAVE_64BIT) && defined(__ULONG_LONG_MAX__)
1729 #if (__ULONG_LONG_MAX__ > 4294967295UL)
1730 #define DUK_F_HAVE_64BIT
1731 typedef unsigned long long duk_uint64_t;
1732 typedef signed long long duk_int64_t;
1735 #if !defined(DUK_F_HAVE_64BIT) && defined(__LONG_LONG_MAX__)
1736 #if (__LONG_LONG_MAX__ > 2147483647L)
1737 #define DUK_F_HAVE_64BIT
1738 typedef unsigned long long duk_uint64_t;
1739 typedef signed long long duk_int64_t;
1742 #if !defined(DUK_F_HAVE_64BIT) && defined(DUK_F_MINGW)
1743 #define DUK_F_HAVE_64BIT
1744 typedef unsigned long duk_uint64_t;
1745 typedef signed long duk_int64_t;
1747 #if !defined(DUK_F_HAVE_64BIT) && defined(DUK_F_MSVC)
1748 #define DUK_F_HAVE_64BIT
1749 typedef unsigned __int64 duk_uint64_t;
1750 typedef signed __int64 duk_int64_t;
1752 #if !defined(DUK_F_HAVE_64BIT)
1753 /* cannot detect 64-bit type, not always needed so don't error */
1756 typedef duk_uint8_t duk_uint_least8_t;
1757 typedef duk_int8_t duk_int_least8_t;
1758 typedef duk_uint16_t duk_uint_least16_t;
1759 typedef duk_int16_t duk_int_least16_t;
1760 typedef duk_uint32_t duk_uint_least32_t;
1761 typedef duk_int32_t duk_int_least32_t;
1762 typedef duk_uint8_t duk_uint_fast8_t;
1763 typedef duk_int8_t duk_int_fast8_t;
1764 typedef duk_uint16_t duk_uint_fast16_t;
1765 typedef duk_int16_t duk_int_fast16_t;
1766 typedef duk_uint32_t duk_uint_fast32_t;
1767 typedef duk_int32_t duk_int_fast32_t;
1768 #if defined(DUK_F_HAVE_64BIT)
1769 typedef duk_uint64_t duk_uint_least64_t;
1770 typedef duk_int64_t duk_int_least64_t;
1771 typedef duk_uint64_t duk_uint_fast64_t;
1772 typedef duk_int64_t duk_int_fast64_t;
1774 #if defined(DUK_F_HAVE_64BIT)
1775 typedef duk_uint64_t duk_uintmax_t;
1776 typedef duk_int64_t duk_intmax_t;
1778 typedef duk_uint32_t duk_uintmax_t;
1779 typedef duk_int32_t duk_intmax_t;
1782 /* Note: the funny looking computations for signed minimum 16-bit, 32-bit, and
1783 * 64-bit values are intentional as the obvious forms (e.g. -0x80000000L) are
1784 * -not- portable. See code-issues.txt for a detailed discussion.
1786 #define DUK_UINT8_MIN 0UL
1787 #define DUK_UINT8_MAX 0xffUL
1788 #define DUK_INT8_MIN (-0x80L)
1789 #define DUK_INT8_MAX 0x7fL
1790 #define DUK_UINT_LEAST8_MIN 0UL
1791 #define DUK_UINT_LEAST8_MAX 0xffUL
1792 #define DUK_INT_LEAST8_MIN (-0x80L)
1793 #define DUK_INT_LEAST8_MAX 0x7fL
1794 #define DUK_UINT_FAST8_MIN 0UL
1795 #define DUK_UINT_FAST8_MAX 0xffUL
1796 #define DUK_INT_FAST8_MIN (-0x80L)
1797 #define DUK_INT_FAST8_MAX 0x7fL
1798 #define DUK_UINT16_MIN 0UL
1799 #define DUK_UINT16_MAX 0xffffUL
1800 #define DUK_INT16_MIN (-0x7fffL - 1L)
1801 #define DUK_INT16_MAX 0x7fffL
1802 #define DUK_UINT_LEAST16_MIN 0UL
1803 #define DUK_UINT_LEAST16_MAX 0xffffUL
1804 #define DUK_INT_LEAST16_MIN (-0x7fffL - 1L)
1805 #define DUK_INT_LEAST16_MAX 0x7fffL
1806 #define DUK_UINT_FAST16_MIN 0UL
1807 #define DUK_UINT_FAST16_MAX 0xffffUL
1808 #define DUK_INT_FAST16_MIN (-0x7fffL - 1L)
1809 #define DUK_INT_FAST16_MAX 0x7fffL
1810 #define DUK_UINT32_MIN 0UL
1811 #define DUK_UINT32_MAX 0xffffffffUL
1812 #define DUK_INT32_MIN (-0x7fffffffL - 1L)
1813 #define DUK_INT32_MAX 0x7fffffffL
1814 #define DUK_UINT_LEAST32_MIN 0UL
1815 #define DUK_UINT_LEAST32_MAX 0xffffffffUL
1816 #define DUK_INT_LEAST32_MIN (-0x7fffffffL - 1L)
1817 #define DUK_INT_LEAST32_MAX 0x7fffffffL
1818 #define DUK_UINT_FAST32_MIN 0UL
1819 #define DUK_UINT_FAST32_MAX 0xffffffffUL
1820 #define DUK_INT_FAST32_MIN (-0x7fffffffL - 1L)
1821 #define DUK_INT_FAST32_MAX 0x7fffffffL
1823 /* 64-bit constants. Since LL / ULL constants are not always available,
1824 * use computed values. These values can't be used in preprocessor
1825 * comparisons; flag them as such.
1827 #if defined(DUK_F_HAVE_64BIT)
1828 #define DUK_UINT64_MIN ((duk_uint64_t) 0)
1829 #define DUK_UINT64_MAX ((duk_uint64_t) -1)
1830 #define DUK_INT64_MIN ((duk_int64_t) (~(DUK_UINT64_MAX >> 1)))
1831 #define DUK_INT64_MAX ((duk_int64_t) (DUK_UINT64_MAX >> 1))
1832 #define DUK_UINT_LEAST64_MIN DUK_UINT64_MIN
1833 #define DUK_UINT_LEAST64_MAX DUK_UINT64_MAX
1834 #define DUK_INT_LEAST64_MIN DUK_INT64_MIN
1835 #define DUK_INT_LEAST64_MAX DUK_INT64_MAX
1836 #define DUK_UINT_FAST64_MIN DUK_UINT64_MIN
1837 #define DUK_UINT_FAST64_MAX DUK_UINT64_MAX
1838 #define DUK_INT_FAST64_MIN DUK_INT64_MIN
1839 #define DUK_INT_FAST64_MAX DUK_INT64_MAX
1840 #define DUK_UINT64_MIN_COMPUTED
1841 #define DUK_UINT64_MAX_COMPUTED
1842 #define DUK_INT64_MIN_COMPUTED
1843 #define DUK_INT64_MAX_COMPUTED
1844 #define DUK_UINT_LEAST64_MIN_COMPUTED
1845 #define DUK_UINT_LEAST64_MAX_COMPUTED
1846 #define DUK_INT_LEAST64_MIN_COMPUTED
1847 #define DUK_INT_LEAST64_MAX_COMPUTED
1848 #define DUK_UINT_FAST64_MIN_COMPUTED
1849 #define DUK_UINT_FAST64_MAX_COMPUTED
1850 #define DUK_INT_FAST64_MIN_COMPUTED
1851 #define DUK_INT_FAST64_MAX_COMPUTED
1854 #if defined(DUK_F_HAVE_64BIT)
1855 #define DUK_UINTMAX_MIN DUK_UINT64_MIN
1856 #define DUK_UINTMAX_MAX DUK_UINT64_MAX
1857 #define DUK_INTMAX_MIN DUK_INT64_MIN
1858 #define DUK_INTMAX_MAX DUK_INT64_MAX
1859 #define DUK_UINTMAX_MIN_COMPUTED
1860 #define DUK_UINTMAX_MAX_COMPUTED
1861 #define DUK_INTMAX_MIN_COMPUTED
1862 #define DUK_INTMAX_MAX_COMPUTED
1864 #define DUK_UINTMAX_MIN 0UL
1865 #define DUK_UINTMAX_MAX 0xffffffffUL
1866 #define DUK_INTMAX_MIN (-0x7fffffffL - 1L)
1867 #define DUK_INTMAX_MAX 0x7fffffffL
1870 /* This detection is not very reliable. */
1871 #if defined(DUK_F_32BIT_PTRS)
1872 typedef duk_int32_t duk_intptr_t;
1873 typedef duk_uint32_t duk_uintptr_t;
1874 #define DUK_UINTPTR_MIN DUK_UINT32_MIN
1875 #define DUK_UINTPTR_MAX DUK_UINT32_MAX
1876 #define DUK_INTPTR_MIN DUK_INT32_MIN
1877 #define DUK_INTPTR_MAX DUK_INT32_MAX
1878 #elif defined(DUK_F_64BIT_PTRS) && defined(DUK_F_HAVE_64BIT)
1879 typedef duk_int64_t duk_intptr_t;
1880 typedef duk_uint64_t duk_uintptr_t;
1881 #define DUK_UINTPTR_MIN DUK_UINT64_MIN
1882 #define DUK_UINTPTR_MAX DUK_UINT64_MAX
1883 #define DUK_INTPTR_MIN DUK_INT64_MIN
1884 #define DUK_INTPTR_MAX DUK_INT64_MAX
1885 #define DUK_UINTPTR_MIN_COMPUTED
1886 #define DUK_UINTPTR_MAX_COMPUTED
1887 #define DUK_INTPTR_MIN_COMPUTED
1888 #define DUK_INTPTR_MAX_COMPUTED
1890 #error cannot determine intptr type
1893 /* SIZE_MAX may be missing so use an approximate value for it. */
1894 #undef DUK_SIZE_MAX_COMPUTED
1895 #if !defined(SIZE_MAX)
1896 #define DUK_SIZE_MAX_COMPUTED
1897 #define SIZE_MAX ((size_t) (-1))
1899 #define DUK_SIZE_MIN 0
1900 #define DUK_SIZE_MAX SIZE_MAX
1902 #endif /* C99 types */
1904 /* A few types are assumed to always exist. */
1905 typedef size_t duk_size_t;
1906 typedef ptrdiff_t duk_ptrdiff_t;
1908 /* The best type for an "all around int" in Duktape internals is "at least
1909 * 32 bit signed integer" which is most convenient. Same for unsigned type.
1910 * Prefer 'int' when large enough, as it is almost always a convenient type.
1912 #if defined(UINT_MAX) && (UINT_MAX >= 0xffffffffUL)
1913 typedef int duk_int_t;
1914 typedef unsigned int duk_uint_t;
1915 #define DUK_INT_MIN INT_MIN
1916 #define DUK_INT_MAX INT_MAX
1917 #define DUK_UINT_MIN 0
1918 #define DUK_UINT_MAX UINT_MAX
1920 typedef duk_int_fast32_t duk_int_t;
1921 typedef duk_uint_fast32_t duk_uint_t;
1922 #define DUK_INT_MIN DUK_INT_FAST32_MIN
1923 #define DUK_INT_MAX DUK_INT_FAST32_MAX
1924 #define DUK_UINT_MIN DUK_UINT_FAST32_MIN
1925 #define DUK_UINT_MAX DUK_UINT_FAST32_MAX
1928 /* Same as 'duk_int_t' but guaranteed to be a 'fast' variant if this
1929 * distinction matters for the CPU. These types are used mainly in the
1930 * executor where it might really matter.
1932 typedef duk_int_fast32_t duk_int_fast_t;
1933 typedef duk_uint_fast32_t duk_uint_fast_t;
1934 #define DUK_INT_FAST_MIN DUK_INT_FAST32_MIN
1935 #define DUK_INT_FAST_MAX DUK_INT_FAST32_MAX
1936 #define DUK_UINT_FAST_MIN DUK_UINT_FAST32_MIN
1937 #define DUK_UINT_FAST_MAX DUK_UINT_FAST32_MAX
1939 /* Small integers (16 bits or more) can fall back to the 'int' type, but
1940 * have a typedef so they are marked "small" explicitly.
1942 typedef int duk_small_int_t;
1943 typedef unsigned int duk_small_uint_t;
1944 #define DUK_SMALL_INT_MIN INT_MIN
1945 #define DUK_SMALL_INT_MAX INT_MAX
1946 #define DUK_SMALL_UINT_MIN 0
1947 #define DUK_SMALL_UINT_MAX UINT_MAX
1949 /* Fast variants of small integers, again for really fast paths like the
1952 typedef duk_int_fast16_t duk_small_int_fast_t;
1953 typedef duk_uint_fast16_t duk_small_uint_fast_t;
1954 #define DUK_SMALL_INT_FAST_MIN DUK_INT_FAST16_MIN
1955 #define DUK_SMALL_INT_FAST_MAX DUK_INT_FAST16_MAX
1956 #define DUK_SMALL_UINT_FAST_MIN DUK_UINT_FAST16_MIN
1957 #define DUK_SMALL_UINT_FAST_MAX DUK_UINT_FAST16_MAX
1959 /* Boolean values are represented with the platform 'unsigned int'. */
1960 typedef duk_small_uint_t duk_bool_t;
1961 #define DUK_BOOL_MIN DUK_SMALL_UINT_MIN
1962 #define DUK_BOOL_MAX DUK_SMALL_UINT_MAX
1964 /* Index values must have at least 32-bit signed range. */
1965 typedef duk_int_t duk_idx_t;
1966 #define DUK_IDX_MIN DUK_INT_MIN
1967 #define DUK_IDX_MAX DUK_INT_MAX
1969 /* Unsigned index variant. */
1970 typedef duk_uint_t duk_uidx_t;
1971 #define DUK_UIDX_MIN DUK_UINT_MIN
1972 #define DUK_UIDX_MAX DUK_UINT_MAX
1974 /* Array index values, could be exact 32 bits.
1975 * Currently no need for signed duk_arridx_t.
1977 typedef duk_uint_t duk_uarridx_t;
1978 #define DUK_UARRIDX_MIN DUK_UINT_MIN
1979 #define DUK_UARRIDX_MAX DUK_UINT_MAX
1981 /* Duktape/C function return value, platform int is enough for now to
1982 * represent 0, 1, or negative error code. Must be compatible with
1983 * assigning truth values (e.g. duk_ret_t rc = (foo == bar);).
1985 typedef duk_small_int_t duk_ret_t;
1986 #define DUK_RET_MIN DUK_SMALL_INT_MIN
1987 #define DUK_RET_MAX DUK_SMALL_INT_MAX
1989 /* Error codes are represented with platform int. High bits are used
1990 * for flags and such, so 32 bits are needed.
1992 typedef duk_int_t duk_errcode_t;
1993 #define DUK_ERRCODE_MIN DUK_INT_MIN
1994 #define DUK_ERRCODE_MAX DUK_INT_MAX
1996 /* Codepoint type. Must be 32 bits or more because it is used also for
1997 * internal codepoints. The type is signed because negative codepoints
1998 * are used as internal markers (e.g. to mark EOF or missing argument).
1999 * (X)UTF-8/CESU-8 encode/decode take and return an unsigned variant to
2000 * ensure duk_uint32_t casts back and forth nicely. Almost everything
2001 * else uses the signed one.
2003 typedef duk_int_t duk_codepoint_t;
2004 typedef duk_uint_t duk_ucodepoint_t;
2005 #define DUK_CODEPOINT_MIN DUK_INT_MIN
2006 #define DUK_CODEPOINT_MAX DUK_INT_MAX
2007 #define DUK_UCODEPOINT_MIN DUK_UINT_MIN
2008 #define DUK_UCODEPOINT_MAX DUK_UINT_MAX
2010 /* IEEE float/double typedef. */
2011 typedef float duk_float_t;
2012 typedef double duk_double_t;
2014 /* We're generally assuming that we're working on a platform with a 32-bit
2015 * address space. If DUK_SIZE_MAX is a typecast value (which is necessary
2016 * if SIZE_MAX is missing), the check must be avoided because the
2017 * preprocessor can't do a comparison.
2019 #if !defined(DUK_SIZE_MAX)
2020 #error DUK_SIZE_MAX is undefined, probably missing SIZE_MAX
2021 #elif !defined(DUK_SIZE_MAX_COMPUTED)
2022 #if DUK_SIZE_MAX < 0xffffffffUL
2023 /* On some systems SIZE_MAX can be smaller than max unsigned 32-bit value
2024 * which seems incorrect if size_t is (at least) an unsigned 32-bit type.
2025 * However, it doesn't seem useful to error out compilation if this is the
2031 /* Type used in public API declarations and user code. Typedef maps to
2032 * 'struct duk_hthread' like the 'duk_hthread' typedef which is used
2033 * exclusively in internals.
2035 typedef struct duk_hthread duk_context;
2037 /* Check whether we should use 64-bit integers or not.
2039 * Quite incomplete now. Use 64-bit types if detected (C99 or other detection)
2040 * unless they are known to be unreliable. For instance, 64-bit types are
2041 * available on VBCC but seem to misbehave.
2043 #if defined(DUK_F_HAVE_64BIT) && !defined(DUK_F_VBCC)
2044 #define DUK_USE_64BIT_OPS
2046 #undef DUK_USE_64BIT_OPS
2050 * Fill-ins for platform, architecture, and compiler
2053 /* An abort()-like primitive is needed by the default fatal error handler. */
2054 #if !defined(DUK_ABORT)
2055 #define DUK_ABORT abort
2058 #if !defined(DUK_SETJMP)
2059 #define DUK_JMPBUF_TYPE jmp_buf
2060 #define DUK_SETJMP(jb) setjmp((jb))
2061 #define DUK_LONGJMP(jb) longjmp((jb), 1)
2065 /* sigsetjmp() alternative */
2066 #define DUK_JMPBUF_TYPE sigjmp_buf
2067 #define DUK_SETJMP(jb) sigsetjmp((jb))
2068 #define DUK_LONGJMP(jb) siglongjmp((jb), 1)
2071 /* Special naming to avoid conflict with e.g. DUK_FREE() in duk_heap.h
2072 * (which is unfortunately named). May sometimes need replacement, e.g.
2073 * some compilers don't handle zero length or NULL correctly in realloc().
2075 #if !defined(DUK_ANSI_MALLOC)
2076 #define DUK_ANSI_MALLOC malloc
2078 #if !defined(DUK_ANSI_REALLOC)
2079 #define DUK_ANSI_REALLOC realloc
2081 #if !defined(DUK_ANSI_CALLOC)
2082 #define DUK_ANSI_CALLOC calloc
2084 #if !defined(DUK_ANSI_FREE)
2085 #define DUK_ANSI_FREE free
2088 /* ANSI C (various versions) and some implementations require that the
2089 * pointer arguments to memset(), memcpy(), and memmove() be valid values
2090 * even when byte size is 0 (even a NULL pointer is considered invalid in
2091 * this context). Zero-size operations as such are allowed, as long as their
2092 * pointer arguments point to a valid memory area. The DUK_MEMSET(),
2093 * DUK_MEMCPY(), and DUK_MEMMOVE() macros require this same behavior, i.e.:
2094 * (1) pointers must be valid and non-NULL, (2) zero size must otherwise be
2095 * allowed. If these are not fulfilled, a macro wrapper is needed.
2097 * http://stackoverflow.com/questions/5243012/is-it-guaranteed-to-be-safe-to-perform-memcpy0-0-0
2098 * http://lists.cs.uiuc.edu/pipermail/llvmdev/2007-October/011065.html
2100 * Not sure what's the required behavior when a pointer points just past the
2101 * end of a buffer, which often happens in practice (e.g. zero size memmoves).
2102 * For example, if allocation size is 3, the following pointer would not
2103 * technically point to a valid memory byte:
2106 * | 0 | 1 | 2 | .....
2107 * ^-- p=3, points after last valid byte (2)
2109 #if !defined(DUK_MEMCPY)
2110 #if defined(DUK_F_UCLIBC)
2111 /* Old uclibcs have a broken memcpy so use memmove instead (this is overly wide
2112 * now on purpose): http://lists.uclibc.org/pipermail/uclibc-cvs/2008-October/025511.html
2114 #define DUK_MEMCPY memmove
2116 #define DUK_MEMCPY memcpy
2119 #if !defined(DUK_MEMMOVE)
2120 #define DUK_MEMMOVE memmove
2122 #if !defined(DUK_MEMCMP)
2123 #define DUK_MEMCMP memcmp
2125 #if !defined(DUK_MEMSET)
2126 #define DUK_MEMSET memset
2128 #if !defined(DUK_STRLEN)
2129 #define DUK_STRLEN strlen
2131 #if !defined(DUK_STRCMP)
2132 #define DUK_STRCMP strcmp
2134 #if !defined(DUK_STRNCMP)
2135 #define DUK_STRNCMP strncmp
2137 #if !defined(DUK_SPRINTF)
2138 #define DUK_SPRINTF sprintf
2140 #if !defined(DUK_SNPRINTF)
2141 /* snprintf() is technically not part of C89 but usually available. */
2142 #define DUK_SNPRINTF snprintf
2144 #if !defined(DUK_VSPRINTF)
2145 #define DUK_VSPRINTF vsprintf
2147 #if !defined(DUK_VSNPRINTF)
2148 /* vsnprintf() is technically not part of C89 but usually available. */
2149 #define DUK_VSNPRINTF vsnprintf
2151 #if !defined(DUK_SSCANF)
2152 #define DUK_SSCANF sscanf
2154 #if !defined(DUK_VSSCANF)
2155 #define DUK_VSSCANF vsscanf
2157 #if !defined(DUK_MEMZERO)
2158 #define DUK_MEMZERO(p,n) DUK_MEMSET((p), 0, (n))
2161 #if !defined(DUK_DOUBLE_INFINITY)
2162 #undef DUK_USE_COMPUTED_INFINITY
2163 #if defined(DUK_F_GCC_VERSION) && (DUK_F_GCC_VERSION < 40600)
2164 /* GCC older than 4.6: avoid overflow warnings related to using INFINITY */
2165 #define DUK_DOUBLE_INFINITY (__builtin_inf())
2166 #elif defined(INFINITY)
2167 #define DUK_DOUBLE_INFINITY ((double) INFINITY)
2168 #elif !defined(DUK_F_VBCC) && !defined(DUK_F_MSVC) && !defined(DUK_F_BCC) && \
2169 !defined(DUK_F_OLD_SOLARIS) && !defined(DUK_F_AIX)
2170 #define DUK_DOUBLE_INFINITY (1.0 / 0.0)
2172 /* In VBCC (1.0 / 0.0) results in a warning and 0.0 instead of infinity.
2173 * Use a computed infinity (initialized when a heap is created at the
2176 #define DUK_USE_COMPUTED_INFINITY
2177 #define DUK_DOUBLE_INFINITY duk_computed_infinity
2181 #if !defined(DUK_DOUBLE_NAN)
2182 #undef DUK_USE_COMPUTED_NAN
2184 #define DUK_DOUBLE_NAN NAN
2185 #elif !defined(DUK_F_VBCC) && !defined(DUK_F_MSVC) && !defined(DUK_F_BCC) && \
2186 !defined(DUK_F_OLD_SOLARIS) && !defined(DUK_F_AIX)
2187 #define DUK_DOUBLE_NAN (0.0 / 0.0)
2189 /* In VBCC (0.0 / 0.0) results in a warning and 0.0 instead of NaN.
2190 * In MSVC (VS2010 Express) (0.0 / 0.0) results in a compile error.
2191 * Use a computed NaN (initialized when a heap is created at the
2194 #define DUK_USE_COMPUTED_NAN
2195 #define DUK_DOUBLE_NAN duk_computed_nan
2199 /* Many platforms are missing fpclassify() and friends, so use replacements
2200 * if necessary. The replacement constants (FP_NAN etc) can be anything but
2201 * match Linux constants now.
2203 #undef DUK_USE_REPL_FPCLASSIFY
2204 #undef DUK_USE_REPL_SIGNBIT
2205 #undef DUK_USE_REPL_ISFINITE
2206 #undef DUK_USE_REPL_ISNAN
2207 #undef DUK_USE_REPL_ISINF
2209 /* Complex condition broken into separate parts. */
2210 #undef DUK_F_USE_REPL_ALL
2211 #if !(defined(FP_NAN) && defined(FP_INFINITE) && defined(FP_ZERO) && \
2212 defined(FP_SUBNORMAL) && defined(FP_NORMAL))
2213 /* Missing some obvious constants. */
2214 #define DUK_F_USE_REPL_ALL
2215 #elif defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC)
2216 /* VBCC is missing the built-ins even in C99 mode (perhaps a header issue). */
2217 #define DUK_F_USE_REPL_ALL
2218 #elif defined(DUK_F_AMIGAOS) && defined(DUK_F_M68K)
2219 /* AmigaOS + M68K seems to have math issues even when using GCC cross
2220 * compilation. Use replacements for all AmigaOS versions on M68K
2221 * regardless of compiler.
2223 #define DUK_F_USE_REPL_ALL
2224 #elif defined(DUK_F_FREEBSD) && defined(DUK_F_CLANG)
2225 /* Placeholder fix for (detection is wider than necessary):
2226 * http://llvm.org/bugs/show_bug.cgi?id=17788
2228 #define DUK_F_USE_REPL_ALL
2229 #elif defined(DUK_F_UCLIBC)
2230 /* At least some uclibc versions have broken floating point math. For
2231 * example, fpclassify() can incorrectly classify certain NaN formats.
2232 * To be safe, use replacements.
2234 #define DUK_F_USE_REPL_ALL
2235 #elif defined(DUK_F_AIX)
2236 /* Older versions may be missing isnan(), etc. */
2237 #define DUK_F_USE_REPL_ALL
2240 #if defined(DUK_F_USE_REPL_ALL)
2241 #define DUK_USE_REPL_FPCLASSIFY
2242 #define DUK_USE_REPL_SIGNBIT
2243 #define DUK_USE_REPL_ISFINITE
2244 #define DUK_USE_REPL_ISNAN
2245 #define DUK_USE_REPL_ISINF
2246 #define DUK_FPCLASSIFY duk_repl_fpclassify
2247 #define DUK_SIGNBIT duk_repl_signbit
2248 #define DUK_ISFINITE duk_repl_isfinite
2249 #define DUK_ISNAN duk_repl_isnan
2250 #define DUK_ISINF duk_repl_isinf
2251 #define DUK_FP_NAN 0
2252 #define DUK_FP_INFINITE 1
2253 #define DUK_FP_ZERO 2
2254 #define DUK_FP_SUBNORMAL 3
2255 #define DUK_FP_NORMAL 4
2257 #define DUK_FPCLASSIFY fpclassify
2258 #define DUK_SIGNBIT signbit
2259 #define DUK_ISFINITE isfinite
2260 #define DUK_ISNAN isnan
2261 #define DUK_ISINF isinf
2262 #define DUK_FP_NAN FP_NAN
2263 #define DUK_FP_INFINITE FP_INFINITE
2264 #define DUK_FP_ZERO FP_ZERO
2265 #define DUK_FP_SUBNORMAL FP_SUBNORMAL
2266 #define DUK_FP_NORMAL FP_NORMAL
2269 #if defined(DUK_F_USE_REPL_ALL)
2270 #undef DUK_F_USE_REPL_ALL
2273 /* These functions don't currently need replacement but are wrapped for
2274 * completeness. Because these are used as function pointers, they need
2275 * to be defined as concrete C functions (not macros).
2277 #if !defined(DUK_FABS)
2278 #define DUK_FABS fabs
2280 #if !defined(DUK_FLOOR)
2281 #define DUK_FLOOR floor
2283 #if !defined(DUK_CEIL)
2284 #define DUK_CEIL ceil
2286 #if !defined(DUK_FMOD)
2287 #define DUK_FMOD fmod
2289 #if !defined(DUK_POW)
2292 #if !defined(DUK_ACOS)
2293 #define DUK_ACOS acos
2295 #if !defined(DUK_ASIN)
2296 #define DUK_ASIN asin
2298 #if !defined(DUK_ATAN)
2299 #define DUK_ATAN atan
2301 #if !defined(DUK_ATAN2)
2302 #define DUK_ATAN2 atan2
2304 #if !defined(DUK_SIN)
2307 #if !defined(DUK_COS)
2310 #if !defined(DUK_TAN)
2313 #if !defined(DUK_EXP)
2316 #if !defined(DUK_LOG)
2319 #if !defined(DUK_SQRT)
2320 #define DUK_SQRT sqrt
2323 /* The functions below exist only in C99/C++11 or later and need a workaround
2324 * for platforms that don't include them. MSVC isn't detected as C99, but
2325 * these functions also exist in MSVC 2013 and later so include a clause for
2326 * that too. Android doesn't have log2; disable all of these for Android.
2328 #if (defined(DUK_F_C99) || defined(DUK_F_CPP11) || (defined(_MSC_VER) && (_MSC_VER >= 1800))) && \
2329 !defined(DUK_F_ANDROID) && !defined(DUK_F_MINT)
2330 #if !defined(DUK_CBRT)
2331 #define DUK_CBRT cbrt
2333 #if !defined(DUK_LOG2)
2334 #define DUK_LOG2 log2
2336 #if !defined(DUK_LOG10)
2337 #define DUK_LOG10 log10
2339 #if !defined(DUK_TRUNC)
2340 #define DUK_TRUNC trunc
2342 #endif /* DUK_F_C99 etc */
2344 /* NetBSD 6.0 x86 (at least) has a few problems with pow() semantics,
2345 * see test-bug-netbsd-math-pow.js. MinGW has similar (but different)
2346 * issues, see test-bug-mingw-math-issues.js. Enable pow() workarounds
2347 * for these targets.
2349 #undef DUK_USE_POW_WORKAROUNDS
2350 #if defined(DUK_F_NETBSD) || defined(DUK_F_MINGW)
2351 #define DUK_USE_POW_WORKAROUNDS
2354 /* Similar workarounds for atan2() semantics issues. MinGW issues are
2355 * documented in test-bug-mingw-math-issues.js.
2357 #undef DUK_USE_ATAN2_WORKAROUNDS
2358 #if defined(DUK_F_MINGW)
2359 #define DUK_USE_ATAN2_WORKAROUNDS
2362 /* Rely as little as possible on compiler behavior for NaN comparison,
2363 * signed zero handling, etc. Currently never activated but may be needed
2364 * for broken compilers.
2366 #undef DUK_USE_PARANOID_MATH
2368 /* There was a curious bug where test-bi-date-canceling.js would fail e.g.
2369 * on 64-bit Ubuntu, gcc-4.8.1, -m32, and no -std=c99. Some date computations
2370 * using doubles would be optimized which then broke some corner case tests.
2371 * The problem goes away by adding 'volatile' to the datetime computations.
2372 * Not sure what the actual triggering conditions are, but using this on
2373 * non-C99 systems solves the known issues and has relatively little cost
2374 * on other platforms.
2376 #undef DUK_USE_PARANOID_DATE_COMPUTATION
2377 #if !defined(DUK_F_C99)
2378 #define DUK_USE_PARANOID_DATE_COMPUTATION
2382 * Byte order and double memory layout detection
2384 * Endianness detection is a major portability hassle because the macros
2385 * and headers are not standardized. There's even variance across UNIX
2386 * platforms. Even with "standard" headers, details like underscore count
2387 * varies between platforms, e.g. both __BYTE_ORDER and _BYTE_ORDER are used
2388 * (Crossbridge has a single underscore, for instance).
2390 * The checks below are structured with this in mind: several approaches are
2391 * used, and at the end we check if any of them worked. This allows generic
2392 * approaches to be tried first, and platform/compiler specific hacks tried
2393 * last. As a last resort, the user can force a specific endianness, as it's
2394 * not likely that automatic detection will work on the most exotic platforms.
2396 * Duktape supports little and big endian machines. There's also support
2397 * for a hybrid used by some ARM machines where integers are little endian
2398 * but IEEE double values use a mixed order (12345678 -> 43218765). This
2399 * byte order for doubles is referred to as "mixed endian".
2402 /* GCC and Clang provide endianness defines as built-in predefines, with
2403 * leading and trailing double underscores (e.g. __BYTE_ORDER__). See
2404 * output of "make gccpredefs" and "make clangpredefs". Clang doesn't
2405 * seem to provide __FLOAT_WORD_ORDER__; assume not mixed endian for clang.
2406 * http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
2408 #if !defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__)
2409 #if defined(__ORDER_LITTLE_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
2410 #if defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_LITTLE_ENDIAN__)
2411 #define DUK_USE_BYTEORDER 1
2412 #elif defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)
2413 #define DUK_USE_BYTEORDER 2
2414 #elif !defined(__FLOAT_WORD_ORDER__)
2415 /* Float word order not known, assume not a hybrid. */
2416 #define DUK_USE_BYTEORDER 1
2418 /* Byte order is little endian but cannot determine IEEE double word order. */
2419 #endif /* float word order */
2420 #elif defined(__ORDER_BIG_ENDIAN__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
2421 #if defined(__FLOAT_WORD_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && (__FLOAT_WORD_ORDER__ == __ORDER_BIG_ENDIAN__)
2422 #define DUK_USE_BYTEORDER 3
2423 #elif !defined(__FLOAT_WORD_ORDER__)
2424 /* Float word order not known, assume not a hybrid. */
2425 #define DUK_USE_BYTEORDER 3
2427 /* Byte order is big endian but cannot determine IEEE double word order. */
2428 #endif /* float word order */
2430 /* Cannot determine byte order; __ORDER_PDP_ENDIAN__ is related to 32-bit
2431 * integer ordering and is not relevant.
2433 #endif /* integer byte order */
2434 #endif /* !defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__) */
2436 /* More or less standard endianness predefines provided by header files.
2437 * The ARM hybrid case is detected by assuming that __FLOAT_WORD_ORDER
2438 * will be big endian, see: http://lists.mysql.com/internals/443.
2439 * On some platforms some defines may be present with an empty value which
2440 * causes comparisons to fail: https://github.com/svaarala/duktape/issues/453.
2442 #if !defined(DUK_USE_BYTEORDER)
2443 #if defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && (__BYTE_ORDER == __LITTLE_ENDIAN) || \
2444 defined(_BYTE_ORDER) && defined(_LITTLE_ENDIAN) && (_BYTE_ORDER == _LITTLE_ENDIAN) || \
2445 defined(__LITTLE_ENDIAN__)
2446 #if defined(__FLOAT_WORD_ORDER) && defined(__LITTLE_ENDIAN) && (__FLOAT_WORD_ORDER == __LITTLE_ENDIAN) || \
2447 defined(_FLOAT_WORD_ORDER) && defined(_LITTLE_ENDIAN) && (_FLOAT_WORD_ORDER == _LITTLE_ENDIAN)
2448 #define DUK_USE_BYTEORDER 1
2449 #elif defined(__FLOAT_WORD_ORDER) && defined(__BIG_ENDIAN) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) || \
2450 defined(_FLOAT_WORD_ORDER) && defined(_BIG_ENDIAN) && (_FLOAT_WORD_ORDER == _BIG_ENDIAN)
2451 #define DUK_USE_BYTEORDER 2
2452 #elif !defined(__FLOAT_WORD_ORDER) && !defined(_FLOAT_WORD_ORDER)
2453 /* Float word order not known, assume not a hybrid. */
2454 #define DUK_USE_BYTEORDER 1
2456 /* Byte order is little endian but cannot determine IEEE double word order. */
2457 #endif /* float word order */
2458 #elif defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && (__BYTE_ORDER == __BIG_ENDIAN) || \
2459 defined(_BYTE_ORDER) && defined(_BIG_ENDIAN) && (_BYTE_ORDER == _BIG_ENDIAN) || \
2460 defined(__BIG_ENDIAN__)
2461 #if defined(__FLOAT_WORD_ORDER) && defined(__BIG_ENDIAN) && (__FLOAT_WORD_ORDER == __BIG_ENDIAN) || \
2462 defined(_FLOAT_WORD_ORDER) && defined(_BIG_ENDIAN) && (_FLOAT_WORD_ORDER == _BIG_ENDIAN)
2463 #define DUK_USE_BYTEORDER 3
2464 #elif !defined(__FLOAT_WORD_ORDER) && !defined(_FLOAT_WORD_ORDER)
2465 /* Float word order not known, assume not a hybrid. */
2466 #define DUK_USE_BYTEORDER 3
2468 /* Byte order is big endian but cannot determine IEEE double word order. */
2469 #endif /* float word order */
2471 /* Cannot determine byte order. */
2472 #endif /* integer byte order */
2473 #endif /* !defined(DUK_USE_BYTEORDER) */
2475 /* QNX gcc cross compiler seems to define e.g. __LITTLEENDIAN__ or __BIGENDIAN__:
2476 * $ /opt/qnx650/host/linux/x86/usr/bin/i486-pc-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
2477 * 67:#define __LITTLEENDIAN__ 1
2478 * $ /opt/qnx650/host/linux/x86/usr/bin/mips-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
2479 * 81:#define __BIGENDIAN__ 1
2480 * $ /opt/qnx650/host/linux/x86/usr/bin/arm-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
2481 * 70:#define __LITTLEENDIAN__ 1
2483 #if !defined(DUK_USE_BYTEORDER)
2484 #if defined(__LITTLEENDIAN__)
2485 #define DUK_USE_BYTEORDER 1
2486 #elif defined(__BIGENDIAN__)
2487 #define DUK_USE_BYTEORDER 3
2492 * Alignment requirement and support for unaligned accesses
2494 * Assume unaligned accesses are not supported unless specifically allowed
2495 * in the target platform. Some platforms may support unaligned accesses
2496 * but alignment to 4 or 8 may still be desirable. Note that unaligned
2497 * accesses (and even pointers) relative to natural alignment (regardless
2498 * of target alignment) are technically undefined behavior and thus
2499 * compiler/architecture specific.
2502 /* If not forced, use safe default for alignment. */
2503 #if !defined(DUK_USE_ALIGN_BY)
2504 #define DUK_USE_ALIGN_BY 8
2507 /* Compiler specific hackery needed to force struct size to match aligment,
2508 * see e.g. duk_hbuffer.h.
2510 * http://stackoverflow.com/questions/11130109/c-struct-size-alignment
2511 * http://stackoverflow.com/questions/10951039/specifying-64-bit-alignment
2513 #if !(defined(DUK_USE_PACK_MSVC_PRAGMA) || defined(DUK_USE_PACK_GCC_ATTR) || \
2514 defined(DUK_USE_PACK_CLANG_ATTR) || defined(DUK_USE_PACK_DUMMY_MEMBER))
2515 #define DUK_USE_PACK_DUMMY_MEMBER
2518 #if !defined(DUK_VA_COPY)
2519 /* We need va_copy() which is defined in C99 / C++11, so an awkward
2520 * replacement is needed for pre-C99 / pre-C++11 environments. This
2521 * will quite likely need portability hacks for some non-C99
2524 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
2525 /* C99 / C++11 and above: rely on va_copy() which is required.
2526 * Omit parenthesis on macro right side on purpose to minimize differences
2529 #define DUK_VA_COPY(dest,src) va_copy(dest,src)
2531 /* Pre-C99: va_list type is implementation dependent. This replacement
2532 * assumes it is a plain value so that a simple assignment will work.
2533 * This is not the case on all platforms (it may be a single-array element,
2536 #define DUK_VA_COPY(dest,src) do { (dest) = (src); } while (0)
2540 #if !defined(DUK_MACRO_STRINGIFY)
2541 /* Macro hackery to convert e.g. __LINE__ to a string without formatting,
2542 * see: http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string
2544 #define DUK_MACRO_STRINGIFY_HELPER(x) #x
2545 #define DUK_MACRO_STRINGIFY(x) DUK_MACRO_STRINGIFY_HELPER(x)
2548 #if !defined(DUK_CAUSE_SEGFAULT)
2549 /* This can be used for testing; valgrind will then indicate the C call stack
2550 * leading to the call site.
2552 #define DUK_CAUSE_SEGFAULT() do { *((volatile duk_uint32_t *) NULL) = (duk_uint32_t) 0xdeadbeefUL; } while (0)
2555 #if !defined(DUK_UNREF)
2556 /* Macro for suppressing warnings for potentially unreferenced variables.
2557 * The variables can be actually unreferenced or unreferenced in some
2558 * specific cases only; for instance, if a variable is only debug printed,
2559 * it is unreferenced when debug printing is disabled. May cause warnings
2560 * for volatile arguments.
2562 #define DUK_UNREF(x) do { (void) (x); } while (0)
2565 /* Fillin for DUK_NORETURN; DUK_WO_NORETURN() is used to insert dummy
2566 * dummy statements after noreturn calls to silence harmless compiler
2569 * DUK_ERROR_TYPE(thr, "aiee");
2570 * DUK_WO_NORETURN(return 0;);
2572 * Statements inside DUK_WO_NORETURN() must NEVER be actually reachable,
2573 * and they're only included to satisfy the compiler.
2575 #if defined(DUK_NORETURN)
2576 #define DUK_WO_NORETURN(stmt) do { } while (0)
2578 #define DUK_NORETURN(decl) decl
2579 #define DUK_WO_NORETURN(stmt) do { stmt } while (0)
2582 #if !defined(DUK_UNREACHABLE)
2583 /* Don't know how to declare unreachable point, so don't do it; this
2584 * may cause some spurious compilation warnings (e.g. "variable used
2587 #define DUK_UNREACHABLE() do { } while (0)
2590 #if !defined(DUK_LOSE_CONST)
2591 /* Convert any input pointer into a "void *", losing a const qualifier.
2592 * This is not fully portable because casting through duk_uintptr_t may
2593 * not work on all architectures (e.g. those with long, segmented pointers).
2595 #define DUK_LOSE_CONST(src) ((void *) (duk_uintptr_t) (src))
2598 #if !defined(DUK_LIKELY)
2599 #define DUK_LIKELY(x) (x)
2601 #if !defined(DUK_UNLIKELY)
2602 #define DUK_UNLIKELY(x) (x)
2604 #if !defined(DUK_UNPREDICTABLE)
2605 #define DUK_UNPREDICTABLE(x) (x)
2608 #if !defined(DUK_NOINLINE)
2609 #define DUK_NOINLINE /*nop*/
2611 #if !defined(DUK_INLINE)
2612 #define DUK_INLINE /*nop*/
2614 #if !defined(DUK_ALWAYS_INLINE)
2615 #define DUK_ALWAYS_INLINE /*nop*/
2618 #if !defined(DUK_HOT)
2619 #define DUK_HOT /*nop*/
2621 #if !defined(DUK_COLD)
2622 #define DUK_COLD /*nop*/
2625 #if !defined(DUK_EXTERNAL_DECL)
2626 #define DUK_EXTERNAL_DECL extern
2628 #if !defined(DUK_EXTERNAL)
2629 #define DUK_EXTERNAL /*empty*/
2631 #if !defined(DUK_INTERNAL_DECL)
2632 #if defined(DUK_SINGLE_FILE)
2633 #define DUK_INTERNAL_DECL static
2635 #define DUK_INTERNAL_DECL extern
2638 #if !defined(DUK_INTERNAL)
2639 #if defined(DUK_SINGLE_FILE)
2640 #define DUK_INTERNAL static
2642 #define DUK_INTERNAL /*empty*/
2645 #if !defined(DUK_LOCAL_DECL)
2646 #define DUK_LOCAL_DECL static
2648 #if !defined(DUK_LOCAL)
2649 #define DUK_LOCAL static
2652 #if !defined(DUK_FILE_MACRO)
2653 #define DUK_FILE_MACRO __FILE__
2655 #if !defined(DUK_LINE_MACRO)
2656 #define DUK_LINE_MACRO __LINE__
2658 #if !defined(DUK_FUNC_MACRO)
2659 #if defined(DUK_F_C99) || defined(DUK_F_CPP11)
2660 #define DUK_FUNC_MACRO __func__
2661 #elif defined(__FUNCTION__)
2662 #define DUK_FUNC_MACRO __FUNCTION__
2664 #define DUK_FUNC_MACRO "unknown"
2668 #if !defined(DUK_BSWAP32)
2669 #define DUK_BSWAP32(x) \
2670 ((((duk_uint32_t) (x)) >> 24) | \
2671 ((((duk_uint32_t) (x)) >> 8) & 0xff00UL) | \
2672 ((((duk_uint32_t) (x)) << 8) & 0xff0000UL) | \
2673 (((duk_uint32_t) (x)) << 24))
2675 #if !defined(DUK_BSWAP16)
2676 #define DUK_BSWAP16(x) \
2677 ((duk_uint16_t) (x) >> 8) | \
2678 ((duk_uint16_t) (x) << 8)
2681 /* DUK_USE_VARIADIC_MACROS: required from compilers, so no fill-in. */
2682 /* DUK_USE_UNION_INITIALIZERS: required from compilers, so no fill-in. */
2684 #if !(defined(DUK_USE_FLEX_C99) || defined(DUK_USE_FLEX_ZEROSIZE) || defined(DUK_USE_FLEX_ONESIZE))
2685 #if defined(DUK_F_C99)
2686 #define DUK_USE_FLEX_C99
2688 #define DUK_USE_FLEX_ZEROSIZE /* Not standard but common enough */
2692 #if !(defined(DUK_USE_PACK_GCC_ATTR) || defined(DUK_USE_PACK_CLANG_ATTR) || \
2693 defined(DUK_USE_PACK_MSVC_PRAGMA) || defined(DUK_USE_PACK_DUMMY_MEMBER))
2694 #define DUK_USE_PACK_DUMMY_MEMBER
2697 #if 0 /* not defined by default */
2698 #undef DUK_USE_GCC_PRAGMAS
2701 #if !defined(DUK_U64_CONSTANT)
2702 #define DUK_U64_CONSTANT(x) x##ULL
2704 #if !defined(DUK_I64_CONSTANT)
2705 #define DUK_I64_CONSTANT(x) x##LL
2708 /* Workaround for GH-323: avoid inlining control when compiling from
2709 * multiple sources, as it causes compiler portability trouble.
2711 #if !defined(DUK_SINGLE_FILE)
2714 #undef DUK_ALWAYS_INLINE
2715 #define DUK_NOINLINE /*nop*/
2716 #define DUK_INLINE /*nop*/
2717 #define DUK_ALWAYS_INLINE /*nop*/
2721 * Check whether or not a packed duk_tval representation is possible.
2722 * What's basically required is that pointers are 32-bit values
2723 * (sizeof(void *) == 4). Best effort check, not always accurate.
2724 * If guess goes wrong, crashes may result; self tests also verify
2728 /* Explicit marker needed; may be 'defined', 'undefined, 'or 'not provided'. */
2729 #if !defined(DUK_F_PACKED_TVAL_PROVIDED)
2730 #undef DUK_F_PACKED_TVAL_POSSIBLE
2732 /* Strict C99 case: DUK_UINTPTR_MAX (= UINTPTR_MAX) should be very reliable */
2733 #if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_UINTPTR_MAX)
2734 #if (DUK_UINTPTR_MAX <= 0xffffffffUL)
2735 #define DUK_F_PACKED_TVAL_POSSIBLE
2739 /* Non-C99 case, still relying on DUK_UINTPTR_MAX, as long as it is not a computed value */
2740 #if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_UINTPTR_MAX) && !defined(DUK_UINTPTR_MAX_COMPUTED)
2741 #if (DUK_UINTPTR_MAX <= 0xffffffffUL)
2742 #define DUK_F_PACKED_TVAL_POSSIBLE
2746 /* DUK_SIZE_MAX (= SIZE_MAX) is often reliable */
2747 #if !defined(DUK_F_PACKED_TVAL_POSSIBLE) && defined(DUK_SIZE_MAX) && !defined(DUK_SIZE_MAX_COMPUTED)
2748 #if (DUK_SIZE_MAX <= 0xffffffffUL)
2749 #define DUK_F_PACKED_TVAL_POSSIBLE
2753 #undef DUK_USE_PACKED_TVAL
2754 #if defined(DUK_F_PACKED_TVAL_POSSIBLE)
2755 #define DUK_USE_PACKED_TVAL
2757 #undef DUK_F_PACKED_TVAL_POSSIBLE
2759 #endif /* DUK_F_PACKED_TVAL_PROVIDED */
2760 /* Object property allocation layout has implications for memory and code
2761 * footprint and generated code size/speed. The best layout also depends
2762 * on whether the platform has alignment requirements or benefits from
2763 * having mostly aligned accesses.
2765 #undef DUK_USE_HOBJECT_LAYOUT_1
2766 #undef DUK_USE_HOBJECT_LAYOUT_2
2767 #undef DUK_USE_HOBJECT_LAYOUT_3
2768 #if (DUK_USE_ALIGN_BY == 1)
2769 /* On platforms without any alignment issues, layout 1 is preferable
2770 * because it compiles to slightly less code and provides direct access
2773 #define DUK_USE_HOBJECT_LAYOUT_1
2775 /* On other platforms use layout 2, which requires some padding but
2776 * is a bit more natural than layout 3 in ordering the entries. Layout
2777 * 3 is currently not used.
2779 #define DUK_USE_HOBJECT_LAYOUT_2
2782 /* GCC/clang inaccurate math would break compliance and probably duk_tval,
2783 * so refuse to compile. Relax this if -ffast-math is tested to work.
2785 #if defined(__FAST_MATH__)
2786 #error __FAST_MATH__ defined, refusing to compile
2790 * Autogenerated defaults
2793 #undef DUK_USE_ALLOW_UNDEFINED_BEHAVIOR
2794 #define DUK_USE_ARRAY_BUILTIN
2795 #define DUK_USE_ARRAY_FASTPATH
2796 #define DUK_USE_ARRAY_PROP_FASTPATH
2797 #undef DUK_USE_ASSERTIONS
2798 #define DUK_USE_AUGMENT_ERROR_CREATE
2799 #define DUK_USE_AUGMENT_ERROR_THROW
2800 #define DUK_USE_AVOID_PLATFORM_FUNCPTRS
2801 #define DUK_USE_BASE64_FASTPATH
2802 #define DUK_USE_BASE64_SUPPORT
2803 #define DUK_USE_BOOLEAN_BUILTIN
2804 #define DUK_USE_BUFFEROBJECT_SUPPORT
2805 #undef DUK_USE_BUFLEN16
2806 #define DUK_USE_BYTECODE_DUMP_SUPPORT
2807 #define DUK_USE_CACHE_ACTIVATION
2808 #define DUK_USE_CACHE_CATCHER
2809 #define DUK_USE_CALLSTACK_LIMIT 10000
2810 #define DUK_USE_COMMONJS_MODULES
2811 #define DUK_USE_COMPILER_RECLIMIT 2500
2812 #define DUK_USE_COROUTINE_SUPPORT
2813 #undef DUK_USE_CPP_EXCEPTIONS
2814 #undef DUK_USE_DATAPTR16
2815 #undef DUK_USE_DATAPTR_DEC16
2816 #undef DUK_USE_DATAPTR_ENC16
2817 #define DUK_USE_DATE_BUILTIN
2818 #undef DUK_USE_DATE_FORMAT_STRING
2819 #undef DUK_USE_DATE_GET_LOCAL_TZOFFSET
2820 #undef DUK_USE_DATE_GET_NOW
2821 #undef DUK_USE_DATE_PARSE_STRING
2822 #undef DUK_USE_DATE_PRS_GETDATE
2823 #undef DUK_USE_DEBUG
2824 #undef DUK_USE_DEBUGGER_DUMPHEAP
2825 #undef DUK_USE_DEBUGGER_INSPECT
2826 #undef DUK_USE_DEBUGGER_PAUSE_UNCAUGHT
2827 #undef DUK_USE_DEBUGGER_SUPPORT
2828 #define DUK_USE_DEBUGGER_THROW_NOTIFY
2829 #undef DUK_USE_DEBUGGER_TRANSPORT_TORTURE
2830 #define DUK_USE_DEBUG_BUFSIZE 65536L
2831 #define DUK_USE_DEBUG_LEVEL 0
2832 #undef DUK_USE_DEBUG_WRITE
2833 #define DUK_USE_DOUBLE_LINKED_HEAP
2834 #define DUK_USE_DUKTAPE_BUILTIN
2835 #define DUK_USE_ENCODING_BUILTINS
2836 #define DUK_USE_ERRCREATE
2837 #define DUK_USE_ERRTHROW
2839 #define DUK_USE_ES6_OBJECT_PROTO_PROPERTY
2840 #define DUK_USE_ES6_OBJECT_SETPROTOTYPEOF
2841 #define DUK_USE_ES6_PROXY
2842 #define DUK_USE_ES6_REGEXP_SYNTAX
2843 #define DUK_USE_ES6_UNICODE_ESCAPE
2845 #define DUK_USE_ES7_EXP_OPERATOR
2848 #define DUK_USE_ESBC_LIMITS
2849 #define DUK_USE_ESBC_MAX_BYTES 2147418112L
2850 #define DUK_USE_ESBC_MAX_LINENUMBER 2147418112L
2851 #undef DUK_USE_EXEC_FUN_LOCAL
2852 #undef DUK_USE_EXEC_INDIRECT_BOUND_CHECK
2853 #undef DUK_USE_EXEC_PREFER_SIZE
2854 #define DUK_USE_EXEC_REGCONST_OPTIMIZE
2855 #undef DUK_USE_EXEC_TIMEOUT_CHECK
2856 #undef DUK_USE_EXPLICIT_NULL_INIT
2857 #undef DUK_USE_EXTSTR_FREE
2858 #undef DUK_USE_EXTSTR_INTERN_CHECK
2859 #undef DUK_USE_FASTINT
2860 #define DUK_USE_FAST_REFCOUNT_DEFAULT
2861 #undef DUK_USE_FATAL_HANDLER
2862 #define DUK_USE_FATAL_MAXLEN 128
2863 #define DUK_USE_FINALIZER_SUPPORT
2864 #undef DUK_USE_FINALIZER_TORTURE
2865 #undef DUK_USE_FUNCPTR16
2866 #undef DUK_USE_FUNCPTR_DEC16
2867 #undef DUK_USE_FUNCPTR_ENC16
2868 #define DUK_USE_FUNCTION_BUILTIN
2869 #define DUK_USE_FUNC_FILENAME_PROPERTY
2870 #define DUK_USE_FUNC_NAME_PROPERTY
2871 #undef DUK_USE_GC_TORTURE
2872 #undef DUK_USE_GET_MONOTONIC_TIME
2873 #undef DUK_USE_GET_RANDOM_DOUBLE
2874 #undef DUK_USE_GLOBAL_BINDING
2875 #define DUK_USE_GLOBAL_BUILTIN
2876 #undef DUK_USE_HEAPPTR16
2877 #undef DUK_USE_HEAPPTR_DEC16
2878 #undef DUK_USE_HEAPPTR_ENC16
2879 #define DUK_USE_HEX_FASTPATH
2880 #define DUK_USE_HEX_SUPPORT
2881 #define DUK_USE_HOBJECT_ARRAY_ABANDON_LIMIT 2
2882 #define DUK_USE_HOBJECT_ARRAY_FAST_RESIZE_LIMIT 9
2883 #define DUK_USE_HOBJECT_ARRAY_MINGROW_ADD 16
2884 #define DUK_USE_HOBJECT_ARRAY_MINGROW_DIVISOR 8
2885 #define DUK_USE_HOBJECT_ENTRY_MINGROW_ADD 16
2886 #define DUK_USE_HOBJECT_ENTRY_MINGROW_DIVISOR 8
2887 #define DUK_USE_HOBJECT_HASH_PART
2888 #define DUK_USE_HOBJECT_HASH_PROP_LIMIT 8
2889 #define DUK_USE_HSTRING_ARRIDX
2890 #define DUK_USE_HSTRING_CLEN
2891 #undef DUK_USE_HSTRING_EXTDATA
2892 #define DUK_USE_HSTRING_LAZY_CLEN
2893 #define DUK_USE_HTML_COMMENTS
2894 #define DUK_USE_IDCHAR_FASTPATH
2895 #undef DUK_USE_INJECT_HEAP_ALLOC_ERROR
2896 #undef DUK_USE_INTERRUPT_COUNTER
2897 #undef DUK_USE_INTERRUPT_DEBUG_FIXUP
2899 #define DUK_USE_JSON_BUILTIN
2900 #define DUK_USE_JSON_DECNUMBER_FASTPATH
2901 #define DUK_USE_JSON_DECSTRING_FASTPATH
2902 #define DUK_USE_JSON_DEC_RECLIMIT 1000
2903 #define DUK_USE_JSON_EATWHITE_FASTPATH
2904 #define DUK_USE_JSON_ENC_RECLIMIT 1000
2905 #define DUK_USE_JSON_QUOTESTRING_FASTPATH
2906 #undef DUK_USE_JSON_STRINGIFY_FASTPATH
2907 #define DUK_USE_JSON_SUPPORT
2909 #define DUK_USE_LEXER_SLIDING_WINDOW
2910 #undef DUK_USE_LIGHTFUNC_BUILTINS
2911 #define DUK_USE_LITCACHE_SIZE 256
2912 #define DUK_USE_MARK_AND_SWEEP_RECLIMIT 256
2913 #define DUK_USE_MATH_BUILTIN
2914 #define DUK_USE_NATIVE_CALL_RECLIMIT 1000
2915 #define DUK_USE_NONSTD_ARRAY_SPLICE_DELCOUNT
2916 #undef DUK_USE_NONSTD_FUNC_CALLER_PROPERTY
2917 #undef DUK_USE_NONSTD_FUNC_SOURCE_PROPERTY
2918 #define DUK_USE_NONSTD_FUNC_STMT
2919 #define DUK_USE_NONSTD_GETTER_KEY_ARGUMENT
2920 #define DUK_USE_NONSTD_JSON_ESC_U2028_U2029
2921 #define DUK_USE_NONSTD_SETTER_KEY_ARGUMENT
2922 #define DUK_USE_NONSTD_STRING_FROMCHARCODE_32BIT
2923 #define DUK_USE_NUMBER_BUILTIN
2924 #define DUK_USE_OBJECT_BUILTIN
2925 #undef DUK_USE_OBJSIZES16
2926 #undef DUK_USE_PARANOID_ERRORS
2927 #define DUK_USE_PC2LINE
2928 #define DUK_USE_PERFORMANCE_BUILTIN
2929 #undef DUK_USE_PREFER_SIZE
2930 #undef DUK_USE_PROMISE_BUILTIN
2931 #define DUK_USE_PROVIDE_DEFAULT_ALLOC_FUNCTIONS
2932 #undef DUK_USE_REFCOUNT16
2933 #define DUK_USE_REFCOUNT32
2934 #define DUK_USE_REFERENCE_COUNTING
2935 #define DUK_USE_REFLECT_BUILTIN
2936 #define DUK_USE_REGEXP_CANON_BITMAP
2937 #undef DUK_USE_REGEXP_CANON_WORKAROUND
2938 #define DUK_USE_REGEXP_COMPILER_RECLIMIT 10000
2939 #define DUK_USE_REGEXP_EXECUTOR_RECLIMIT 10000
2940 #define DUK_USE_REGEXP_SUPPORT
2941 #undef DUK_USE_ROM_GLOBAL_CLONE
2942 #undef DUK_USE_ROM_GLOBAL_INHERIT
2943 #undef DUK_USE_ROM_OBJECTS
2944 #define DUK_USE_ROM_PTRCOMP_FIRST 63488L
2945 #undef DUK_USE_ROM_STRINGS
2946 #define DUK_USE_SECTION_B
2947 #undef DUK_USE_SELF_TESTS
2948 #define DUK_USE_SHEBANG_COMMENTS
2949 #undef DUK_USE_SHUFFLE_TORTURE
2950 #define DUK_USE_SOURCE_NONBMP
2951 #undef DUK_USE_STRHASH16
2952 #undef DUK_USE_STRHASH_DENSE
2953 #define DUK_USE_STRHASH_SKIP_SHIFT 5
2954 #define DUK_USE_STRICT_DECL
2955 #undef DUK_USE_STRICT_UTF8_SOURCE
2956 #define DUK_USE_STRING_BUILTIN
2957 #undef DUK_USE_STRLEN16
2958 #define DUK_USE_STRTAB_GROW_LIMIT 17
2959 #define DUK_USE_STRTAB_MAXSIZE 268435456L
2960 #define DUK_USE_STRTAB_MINSIZE 1024
2961 #undef DUK_USE_STRTAB_PTRCOMP
2962 #define DUK_USE_STRTAB_RESIZE_CHECK_MASK 255
2963 #define DUK_USE_STRTAB_SHRINK_LIMIT 6
2964 #undef DUK_USE_STRTAB_TORTURE
2965 #undef DUK_USE_SYMBOL_BUILTIN
2966 #define DUK_USE_TAILCALL
2967 #define DUK_USE_TARGET_INFO "unknown"
2968 #define DUK_USE_TRACEBACKS
2969 #define DUK_USE_TRACEBACK_DEPTH 10
2970 #define DUK_USE_USER_DECLARE() /* no user declarations */
2971 #define DUK_USE_VALSTACK_GROW_SHIFT 2
2972 #define DUK_USE_VALSTACK_LIMIT 1000000L
2973 #define DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT 2
2974 #define DUK_USE_VALSTACK_SHRINK_SLACK_SHIFT 4
2975 #undef DUK_USE_VALSTACK_UNSAFE
2976 #define DUK_USE_VERBOSE_ERRORS
2977 #define DUK_USE_VERBOSE_EXECUTOR_ERRORS
2978 #define DUK_USE_VOLUNTARY_GC
2979 #define DUK_USE_ZERO_BUFFER_DATA
2982 * You may add overriding #define/#undef directives below for
2983 * customization. You of course cannot un-#include or un-typedef
2984 * anything; these require direct changes above.
2987 /* __OVERRIDE_DEFINES__ */
2990 * Conditional includes
2993 #if defined(DUK_F_CPP) && defined(DUK_USE_CPP_EXCEPTIONS)
2994 #include <exception> /* std::exception */
2995 #include <stdexcept> /* std::runtime_error */
2999 * Date provider selection
3001 * User may define DUK_USE_DATE_GET_NOW() etc directly, in which case we'll
3002 * rely on an external provider. If this is not done, revert to previous
3003 * behavior and use Unix/Windows built-in provider.
3006 #if defined(DUK_COMPILING_DUKTAPE)
3008 #if defined(DUK_USE_DATE_GET_NOW)
3009 /* External provider already defined. */
3010 #elif defined(DUK_USE_DATE_NOW_GETTIMEOFDAY)
3011 #define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_gettimeofday()
3012 #elif defined(DUK_USE_DATE_NOW_TIME)
3013 #define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_time()
3014 #elif defined(DUK_USE_DATE_NOW_WINDOWS)
3015 #define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_windows()
3016 #elif defined(DUK_USE_DATE_NOW_WINDOWS_SUBMS)
3017 #define DUK_USE_DATE_GET_NOW(ctx) duk_bi_date_get_now_windows_subms()
3019 #error no provider for DUK_USE_DATE_GET_NOW()
3022 #if defined(DUK_USE_DATE_GET_LOCAL_TZOFFSET)
3023 /* External provider already defined. */
3024 #elif defined(DUK_USE_DATE_TZO_GMTIME_R) || defined(DUK_USE_DATE_TZO_GMTIME_S) || defined(DUK_USE_DATE_TZO_GMTIME)
3025 #define DUK_USE_DATE_GET_LOCAL_TZOFFSET(d) duk_bi_date_get_local_tzoffset_gmtime((d))
3026 #elif defined(DUK_USE_DATE_TZO_WINDOWS)
3027 #define DUK_USE_DATE_GET_LOCAL_TZOFFSET(d) duk_bi_date_get_local_tzoffset_windows((d))
3028 #elif defined(DUK_USE_DATE_TZO_WINDOWS_NO_DST)
3029 #define DUK_USE_DATE_GET_LOCAL_TZOFFSET(d) duk_bi_date_get_local_tzoffset_windows_no_dst((d))
3031 #error no provider for DUK_USE_DATE_GET_LOCAL_TZOFFSET()
3034 #if defined(DUK_USE_DATE_PARSE_STRING)
3035 /* External provider already defined. */
3036 #elif defined(DUK_USE_DATE_PRS_STRPTIME)
3037 #define DUK_USE_DATE_PARSE_STRING(ctx,str) duk_bi_date_parse_string_strptime((ctx), (str))
3038 #elif defined(DUK_USE_DATE_PRS_GETDATE)
3039 #define DUK_USE_DATE_PARSE_STRING(ctx,str) duk_bi_date_parse_string_getdate((ctx), (str))
3041 /* No provider for DUK_USE_DATE_PARSE_STRING(), fall back to ISO 8601 only. */
3044 #if defined(DUK_USE_DATE_FORMAT_STRING)
3045 /* External provider already defined. */
3046 #elif defined(DUK_USE_DATE_FMT_STRFTIME)
3047 #define DUK_USE_DATE_FORMAT_STRING(ctx,parts,tzoffset,flags) \
3048 duk_bi_date_format_parts_strftime((ctx), (parts), (tzoffset), (flags))
3050 /* No provider for DUK_USE_DATE_FORMAT_STRING(), fall back to ISO 8601 only. */
3053 #if defined(DUK_USE_GET_MONOTONIC_TIME)
3054 /* External provider already defined. */
3055 #elif defined(DUK_USE_GET_MONOTONIC_TIME_CLOCK_GETTIME)
3056 #define DUK_USE_GET_MONOTONIC_TIME(ctx) duk_bi_date_get_monotonic_time_clock_gettime()
3057 #elif defined(DUK_USE_GET_MONOTONIC_TIME_WINDOWS_QPC)
3058 #define DUK_USE_GET_MONOTONIC_TIME(ctx) duk_bi_date_get_monotonic_time_windows_qpc()
3060 /* No provider for DUK_USE_GET_MONOTONIC_TIME(), fall back to DUK_USE_DATE_GET_NOW(). */
3063 #endif /* DUK_COMPILING_DUKTAPE */
3066 * Checks for legacy feature options (DUK_OPT_xxx)
3069 #if defined(DUK_OPT_ASSERTIONS)
3070 #error unsupported legacy feature option DUK_OPT_ASSERTIONS used
3072 #if defined(DUK_OPT_BUFFEROBJECT_SUPPORT)
3073 #error unsupported legacy feature option DUK_OPT_BUFFEROBJECT_SUPPORT used
3075 #if defined(DUK_OPT_BUFLEN16)
3076 #error unsupported legacy feature option DUK_OPT_BUFLEN16 used
3078 #if defined(DUK_OPT_DATAPTR16)
3079 #error unsupported legacy feature option DUK_OPT_DATAPTR16 used
3081 #if defined(DUK_OPT_DATAPTR_DEC16)
3082 #error unsupported legacy feature option DUK_OPT_DATAPTR_DEC16 used
3084 #if defined(DUK_OPT_DATAPTR_ENC16)
3085 #error unsupported legacy feature option DUK_OPT_DATAPTR_ENC16 used
3087 #if defined(DUK_OPT_DDDPRINT)
3088 #error unsupported legacy feature option DUK_OPT_DDDPRINT used
3090 #if defined(DUK_OPT_DDPRINT)
3091 #error unsupported legacy feature option DUK_OPT_DDPRINT used
3093 #if defined(DUK_OPT_DEBUG)
3094 #error unsupported legacy feature option DUK_OPT_DEBUG used
3096 #if defined(DUK_OPT_DEBUGGER_DUMPHEAP)
3097 #error unsupported legacy feature option DUK_OPT_DEBUGGER_DUMPHEAP used
3099 #if defined(DUK_OPT_DEBUGGER_FWD_LOGGING)
3100 #error unsupported legacy feature option DUK_OPT_DEBUGGER_FWD_LOGGING used
3102 #if defined(DUK_OPT_DEBUGGER_FWD_PRINTALERT)
3103 #error unsupported legacy feature option DUK_OPT_DEBUGGER_FWD_PRINTALERT used
3105 #if defined(DUK_OPT_DEBUGGER_SUPPORT)
3106 #error unsupported legacy feature option DUK_OPT_DEBUGGER_SUPPORT used
3108 #if defined(DUK_OPT_DEBUGGER_TRANSPORT_TORTURE)
3109 #error unsupported legacy feature option DUK_OPT_DEBUGGER_TRANSPORT_TORTURE used
3111 #if defined(DUK_OPT_DEBUG_BUFSIZE)
3112 #error unsupported legacy feature option DUK_OPT_DEBUG_BUFSIZE used
3114 #if defined(DUK_OPT_DECLARE)
3115 #error unsupported legacy feature option DUK_OPT_DECLARE used
3117 #if defined(DUK_OPT_DEEP_C_STACK)
3118 #error unsupported legacy feature option DUK_OPT_DEEP_C_STACK used
3120 #if defined(DUK_OPT_DLL_BUILD)
3121 #error unsupported legacy feature option DUK_OPT_DLL_BUILD used
3123 #if defined(DUK_OPT_DPRINT)
3124 #error unsupported legacy feature option DUK_OPT_DPRINT used
3126 #if defined(DUK_OPT_DPRINT_COLORS)
3127 #error unsupported legacy feature option DUK_OPT_DPRINT_COLORS used
3129 #if defined(DUK_OPT_DPRINT_RDTSC)
3130 #error unsupported legacy feature option DUK_OPT_DPRINT_RDTSC used
3132 #if defined(DUK_OPT_EXEC_TIMEOUT_CHECK)
3133 #error unsupported legacy feature option DUK_OPT_EXEC_TIMEOUT_CHECK used
3135 #if defined(DUK_OPT_EXTERNAL_STRINGS)
3136 #error unsupported legacy feature option DUK_OPT_EXTERNAL_STRINGS used
3138 #if defined(DUK_OPT_EXTSTR_FREE)
3139 #error unsupported legacy feature option DUK_OPT_EXTSTR_FREE used
3141 #if defined(DUK_OPT_EXTSTR_INTERN_CHECK)
3142 #error unsupported legacy feature option DUK_OPT_EXTSTR_INTERN_CHECK used
3144 #if defined(DUK_OPT_FASTINT)
3145 #error unsupported legacy feature option DUK_OPT_FASTINT used
3147 #if defined(DUK_OPT_FORCE_ALIGN)
3148 #error unsupported legacy feature option DUK_OPT_FORCE_ALIGN used
3150 #if defined(DUK_OPT_FORCE_BYTEORDER)
3151 #error unsupported legacy feature option DUK_OPT_FORCE_BYTEORDER used
3153 #if defined(DUK_OPT_FUNCPTR16)
3154 #error unsupported legacy feature option DUK_OPT_FUNCPTR16 used
3156 #if defined(DUK_OPT_FUNCPTR_DEC16)
3157 #error unsupported legacy feature option DUK_OPT_FUNCPTR_DEC16 used
3159 #if defined(DUK_OPT_FUNCPTR_ENC16)
3160 #error unsupported legacy feature option DUK_OPT_FUNCPTR_ENC16 used
3162 #if defined(DUK_OPT_FUNC_NONSTD_CALLER_PROPERTY)
3163 #error unsupported legacy feature option DUK_OPT_FUNC_NONSTD_CALLER_PROPERTY used
3165 #if defined(DUK_OPT_FUNC_NONSTD_SOURCE_PROPERTY)
3166 #error unsupported legacy feature option DUK_OPT_FUNC_NONSTD_SOURCE_PROPERTY used
3168 #if defined(DUK_OPT_GC_TORTURE)
3169 #error unsupported legacy feature option DUK_OPT_GC_TORTURE used
3171 #if defined(DUK_OPT_HAVE_CUSTOM_H)
3172 #error unsupported legacy feature option DUK_OPT_HAVE_CUSTOM_H used
3174 #if defined(DUK_OPT_HEAPPTR16)
3175 #error unsupported legacy feature option DUK_OPT_HEAPPTR16 used
3177 #if defined(DUK_OPT_HEAPPTR_DEC16)
3178 #error unsupported legacy feature option DUK_OPT_HEAPPTR_DEC16 used
3180 #if defined(DUK_OPT_HEAPPTR_ENC16)
3181 #error unsupported legacy feature option DUK_OPT_HEAPPTR_ENC16 used
3183 #if defined(DUK_OPT_INTERRUPT_COUNTER)
3184 #error unsupported legacy feature option DUK_OPT_INTERRUPT_COUNTER used
3186 #if defined(DUK_OPT_JSON_STRINGIFY_FASTPATH)
3187 #error unsupported legacy feature option DUK_OPT_JSON_STRINGIFY_FASTPATH used
3189 #if defined(DUK_OPT_LIGHTFUNC_BUILTINS)
3190 #error unsupported legacy feature option DUK_OPT_LIGHTFUNC_BUILTINS used
3192 #if defined(DUK_OPT_NONSTD_FUNC_CALLER_PROPERTY)
3193 #error unsupported legacy feature option DUK_OPT_NONSTD_FUNC_CALLER_PROPERTY used
3195 #if defined(DUK_OPT_NONSTD_FUNC_SOURCE_PROPERTY)
3196 #error unsupported legacy feature option DUK_OPT_NONSTD_FUNC_SOURCE_PROPERTY used
3198 #if defined(DUK_OPT_NO_ARRAY_SPLICE_NONSTD_DELCOUNT)
3199 #error unsupported legacy feature option DUK_OPT_NO_ARRAY_SPLICE_NONSTD_DELCOUNT used
3201 #if defined(DUK_OPT_NO_AUGMENT_ERRORS)
3202 #error unsupported legacy feature option DUK_OPT_NO_AUGMENT_ERRORS used
3204 #if defined(DUK_OPT_NO_BROWSER_LIKE)
3205 #error unsupported legacy feature option DUK_OPT_NO_BROWSER_LIKE used
3207 #if defined(DUK_OPT_NO_BUFFEROBJECT_SUPPORT)
3208 #error unsupported legacy feature option DUK_OPT_NO_BUFFEROBJECT_SUPPORT used
3210 #if defined(DUK_OPT_NO_BYTECODE_DUMP_SUPPORT)
3211 #error unsupported legacy feature option DUK_OPT_NO_BYTECODE_DUMP_SUPPORT used
3213 #if defined(DUK_OPT_NO_COMMONJS_MODULES)
3214 #error unsupported legacy feature option DUK_OPT_NO_COMMONJS_MODULES used
3216 #if defined(DUK_OPT_NO_ES6_OBJECT_PROTO_PROPERTY)
3217 #error unsupported legacy feature option DUK_OPT_NO_ES6_OBJECT_PROTO_PROPERTY used
3219 #if defined(DUK_OPT_NO_ES6_OBJECT_SETPROTOTYPEOF)
3220 #error unsupported legacy feature option DUK_OPT_NO_ES6_OBJECT_SETPROTOTYPEOF used
3222 #if defined(DUK_OPT_NO_ES6_PROXY)
3223 #error unsupported legacy feature option DUK_OPT_NO_ES6_PROXY used
3225 #if defined(DUK_OPT_NO_FILE_IO)
3226 #error unsupported legacy feature option DUK_OPT_NO_FILE_IO used
3228 #if defined(DUK_OPT_NO_FUNC_STMT)
3229 #error unsupported legacy feature option DUK_OPT_NO_FUNC_STMT used
3231 #if defined(DUK_OPT_NO_JC)
3232 #error unsupported legacy feature option DUK_OPT_NO_JC used
3234 #if defined(DUK_OPT_NO_JSONC)
3235 #error unsupported legacy feature option DUK_OPT_NO_JSONC used
3237 #if defined(DUK_OPT_NO_JSONX)
3238 #error unsupported legacy feature option DUK_OPT_NO_JSONX used
3240 #if defined(DUK_OPT_NO_JX)
3241 #error unsupported legacy feature option DUK_OPT_NO_JX used
3243 #if defined(DUK_OPT_NO_MARK_AND_SWEEP)
3244 #error unsupported legacy feature option DUK_OPT_NO_MARK_AND_SWEEP used
3246 #if defined(DUK_OPT_NO_MS_STRINGTABLE_RESIZE)
3247 #error unsupported legacy feature option DUK_OPT_NO_MS_STRINGTABLE_RESIZE used
3249 #if defined(DUK_OPT_NO_NONSTD_ACCESSOR_KEY_ARGUMENT)
3250 #error unsupported legacy feature option DUK_OPT_NO_NONSTD_ACCESSOR_KEY_ARGUMENT used
3252 #if defined(DUK_OPT_NO_NONSTD_ARRAY_CONCAT_TRAILER)
3253 #error unsupported legacy feature option DUK_OPT_NO_NONSTD_ARRAY_CONCAT_TRAILER used
3255 #if defined(DUK_OPT_NO_NONSTD_ARRAY_MAP_TRAILER)
3256 #error unsupported legacy feature option DUK_OPT_NO_NONSTD_ARRAY_MAP_TRAILER used
3258 #if defined(DUK_OPT_NO_NONSTD_ARRAY_SPLICE_DELCOUNT)
3259 #error unsupported legacy feature option DUK_OPT_NO_NONSTD_ARRAY_SPLICE_DELCOUNT used
3261 #if defined(DUK_OPT_NO_NONSTD_FUNC_STMT)
3262 #error unsupported legacy feature option DUK_OPT_NO_NONSTD_FUNC_STMT used
3264 #if defined(DUK_OPT_NO_NONSTD_JSON_ESC_U2028_U2029)
3265 #error unsupported legacy feature option DUK_OPT_NO_NONSTD_JSON_ESC_U2028_U2029 used
3267 #if defined(DUK_OPT_NO_NONSTD_STRING_FROMCHARCODE_32BIT)
3268 #error unsupported legacy feature option DUK_OPT_NO_NONSTD_STRING_FROMCHARCODE_32BIT used
3270 #if defined(DUK_OPT_NO_OBJECT_ES6_PROTO_PROPERTY)
3271 #error unsupported legacy feature option DUK_OPT_NO_OBJECT_ES6_PROTO_PROPERTY used
3273 #if defined(DUK_OPT_NO_OBJECT_ES6_SETPROTOTYPEOF)
3274 #error unsupported legacy feature option DUK_OPT_NO_OBJECT_ES6_SETPROTOTYPEOF used
3276 #if defined(DUK_OPT_NO_OCTAL_SUPPORT)
3277 #error unsupported legacy feature option DUK_OPT_NO_OCTAL_SUPPORT used
3279 #if defined(DUK_OPT_NO_PACKED_TVAL)
3280 #error unsupported legacy feature option DUK_OPT_NO_PACKED_TVAL used
3282 #if defined(DUK_OPT_NO_PC2LINE)
3283 #error unsupported legacy feature option DUK_OPT_NO_PC2LINE used
3285 #if defined(DUK_OPT_NO_REFERENCE_COUNTING)
3286 #error unsupported legacy feature option DUK_OPT_NO_REFERENCE_COUNTING used
3288 #if defined(DUK_OPT_NO_REGEXP_SUPPORT)
3289 #error unsupported legacy feature option DUK_OPT_NO_REGEXP_SUPPORT used
3291 #if defined(DUK_OPT_NO_SECTION_B)
3292 #error unsupported legacy feature option DUK_OPT_NO_SECTION_B used
3294 #if defined(DUK_OPT_NO_SOURCE_NONBMP)
3295 #error unsupported legacy feature option DUK_OPT_NO_SOURCE_NONBMP used
3297 #if defined(DUK_OPT_NO_STRICT_DECL)
3298 #error unsupported legacy feature option DUK_OPT_NO_STRICT_DECL used
3300 #if defined(DUK_OPT_NO_TRACEBACKS)
3301 #error unsupported legacy feature option DUK_OPT_NO_TRACEBACKS used
3303 #if defined(DUK_OPT_NO_VERBOSE_ERRORS)
3304 #error unsupported legacy feature option DUK_OPT_NO_VERBOSE_ERRORS used
3306 #if defined(DUK_OPT_NO_VOLUNTARY_GC)
3307 #error unsupported legacy feature option DUK_OPT_NO_VOLUNTARY_GC used
3309 #if defined(DUK_OPT_NO_ZERO_BUFFER_DATA)
3310 #error unsupported legacy feature option DUK_OPT_NO_ZERO_BUFFER_DATA used
3312 #if defined(DUK_OPT_OBJSIZES16)
3313 #error unsupported legacy feature option DUK_OPT_OBJSIZES16 used
3315 #if defined(DUK_OPT_PANIC_HANDLER)
3316 #error unsupported legacy feature option DUK_OPT_PANIC_HANDLER used
3318 #if defined(DUK_OPT_REFCOUNT16)
3319 #error unsupported legacy feature option DUK_OPT_REFCOUNT16 used
3321 #if defined(DUK_OPT_SEGFAULT_ON_PANIC)
3322 #error unsupported legacy feature option DUK_OPT_SEGFAULT_ON_PANIC used
3324 #if defined(DUK_OPT_SELF_TESTS)
3325 #error unsupported legacy feature option DUK_OPT_SELF_TESTS used
3327 #if defined(DUK_OPT_SETJMP)
3328 #error unsupported legacy feature option DUK_OPT_SETJMP used
3330 #if defined(DUK_OPT_SHUFFLE_TORTURE)
3331 #error unsupported legacy feature option DUK_OPT_SHUFFLE_TORTURE used
3333 #if defined(DUK_OPT_SIGSETJMP)
3334 #error unsupported legacy feature option DUK_OPT_SIGSETJMP used
3336 #if defined(DUK_OPT_STRHASH16)
3337 #error unsupported legacy feature option DUK_OPT_STRHASH16 used
3339 #if defined(DUK_OPT_STRICT_UTF8_SOURCE)
3340 #error unsupported legacy feature option DUK_OPT_STRICT_UTF8_SOURCE used
3342 #if defined(DUK_OPT_STRLEN16)
3343 #error unsupported legacy feature option DUK_OPT_STRLEN16 used
3345 #if defined(DUK_OPT_STRTAB_CHAIN)
3346 #error unsupported legacy feature option DUK_OPT_STRTAB_CHAIN used
3348 #if defined(DUK_OPT_STRTAB_CHAIN_SIZE)
3349 #error unsupported legacy feature option DUK_OPT_STRTAB_CHAIN_SIZE used
3351 #if defined(DUK_OPT_TARGET_INFO)
3352 #error unsupported legacy feature option DUK_OPT_TARGET_INFO used
3354 #if defined(DUK_OPT_TRACEBACK_DEPTH)
3355 #error unsupported legacy feature option DUK_OPT_TRACEBACK_DEPTH used
3357 #if defined(DUK_OPT_UNDERSCORE_SETJMP)
3358 #error unsupported legacy feature option DUK_OPT_UNDERSCORE_SETJMP used
3360 #if defined(DUK_OPT_USER_INITJS)
3361 #error unsupported legacy feature option DUK_OPT_USER_INITJS used
3365 * Checks for config option consistency (DUK_USE_xxx)
3368 #if defined(DUK_USE_32BIT_PTRS)
3369 #error unsupported config option used (option has been removed): DUK_USE_32BIT_PTRS
3371 #if defined(DUK_USE_ALIGN_4)
3372 #error unsupported config option used (option has been removed): DUK_USE_ALIGN_4
3374 #if defined(DUK_USE_ALIGN_8)
3375 #error unsupported config option used (option has been removed): DUK_USE_ALIGN_8
3377 #if defined(DUK_USE_BROWSER_LIKE)
3378 #error unsupported config option used (option has been removed): DUK_USE_BROWSER_LIKE
3380 #if defined(DUK_USE_BUILTIN_INITJS)
3381 #error unsupported config option used (option has been removed): DUK_USE_BUILTIN_INITJS
3383 #if defined(DUK_USE_BYTEORDER_FORCED)
3384 #error unsupported config option used (option has been removed): DUK_USE_BYTEORDER_FORCED
3386 #if defined(DUK_USE_DATAPTR_DEC16) && !defined(DUK_USE_DATAPTR16)
3387 #error config option DUK_USE_DATAPTR_DEC16 requires option DUK_USE_DATAPTR16 (which is missing)
3389 #if defined(DUK_USE_DATAPTR_ENC16) && !defined(DUK_USE_DATAPTR16)
3390 #error config option DUK_USE_DATAPTR_ENC16 requires option DUK_USE_DATAPTR16 (which is missing)
3392 #if defined(DUK_USE_DDDPRINT)
3393 #error unsupported config option used (option has been removed): DUK_USE_DDDPRINT
3395 #if defined(DUK_USE_DDPRINT)
3396 #error unsupported config option used (option has been removed): DUK_USE_DDPRINT
3398 #if defined(DUK_USE_DEBUGGER_FWD_LOGGING)
3399 #error unsupported config option used (option has been removed): DUK_USE_DEBUGGER_FWD_LOGGING
3401 #if defined(DUK_USE_DEBUGGER_FWD_PRINTALERT)
3402 #error unsupported config option used (option has been removed): DUK_USE_DEBUGGER_FWD_PRINTALERT
3404 #if defined(DUK_USE_DEBUGGER_SUPPORT) && !defined(DUK_USE_INTERRUPT_COUNTER)
3405 #error config option DUK_USE_DEBUGGER_SUPPORT requires option DUK_USE_INTERRUPT_COUNTER (which is missing)
3407 #if defined(DUK_USE_DEEP_C_STACK)
3408 #error unsupported config option used (option has been removed): DUK_USE_DEEP_C_STACK
3410 #if defined(DUK_USE_DOUBLE_BE)
3411 #error unsupported config option used (option has been removed): DUK_USE_DOUBLE_BE
3413 #if defined(DUK_USE_DOUBLE_BE) && defined(DUK_USE_DOUBLE_LE)
3414 #error config option DUK_USE_DOUBLE_BE conflicts with option DUK_USE_DOUBLE_LE (which is also defined)
3416 #if defined(DUK_USE_DOUBLE_BE) && defined(DUK_USE_DOUBLE_ME)
3417 #error config option DUK_USE_DOUBLE_BE conflicts with option DUK_USE_DOUBLE_ME (which is also defined)
3419 #if defined(DUK_USE_DOUBLE_LE)
3420 #error unsupported config option used (option has been removed): DUK_USE_DOUBLE_LE
3422 #if defined(DUK_USE_DOUBLE_LE) && defined(DUK_USE_DOUBLE_BE)
3423 #error config option DUK_USE_DOUBLE_LE conflicts with option DUK_USE_DOUBLE_BE (which is also defined)
3425 #if defined(DUK_USE_DOUBLE_LE) && defined(DUK_USE_DOUBLE_ME)
3426 #error config option DUK_USE_DOUBLE_LE conflicts with option DUK_USE_DOUBLE_ME (which is also defined)
3428 #if defined(DUK_USE_DOUBLE_ME)
3429 #error unsupported config option used (option has been removed): DUK_USE_DOUBLE_ME
3431 #if defined(DUK_USE_DOUBLE_ME) && defined(DUK_USE_DOUBLE_LE)
3432 #error config option DUK_USE_DOUBLE_ME conflicts with option DUK_USE_DOUBLE_LE (which is also defined)
3434 #if defined(DUK_USE_DOUBLE_ME) && defined(DUK_USE_DOUBLE_BE)
3435 #error config option DUK_USE_DOUBLE_ME conflicts with option DUK_USE_DOUBLE_BE (which is also defined)
3437 #if defined(DUK_USE_DPRINT)
3438 #error unsupported config option used (option has been removed): DUK_USE_DPRINT
3440 #if defined(DUK_USE_DPRINT) && !defined(DUK_USE_DEBUG)
3441 #error config option DUK_USE_DPRINT requires option DUK_USE_DEBUG (which is missing)
3443 #if defined(DUK_USE_DPRINT_COLORS)
3444 #error unsupported config option used (option has been removed): DUK_USE_DPRINT_COLORS
3446 #if defined(DUK_USE_DPRINT_RDTSC)
3447 #error unsupported config option used (option has been removed): DUK_USE_DPRINT_RDTSC
3449 #if defined(DUK_USE_ES6_REGEXP_BRACES)
3450 #error unsupported config option used (option has been removed): DUK_USE_ES6_REGEXP_BRACES
3452 #if defined(DUK_USE_ESBC_MAX_BYTES) && !defined(DUK_USE_ESBC_LIMITS)
3453 #error config option DUK_USE_ESBC_MAX_BYTES requires option DUK_USE_ESBC_LIMITS (which is missing)
3455 #if defined(DUK_USE_ESBC_MAX_LINENUMBER) && !defined(DUK_USE_ESBC_LIMITS)
3456 #error config option DUK_USE_ESBC_MAX_LINENUMBER requires option DUK_USE_ESBC_LIMITS (which is missing)
3458 #if defined(DUK_USE_EXEC_TIMEOUT_CHECK) && !defined(DUK_USE_INTERRUPT_COUNTER)
3459 #error config option DUK_USE_EXEC_TIMEOUT_CHECK requires option DUK_USE_INTERRUPT_COUNTER (which is missing)
3461 #if defined(DUK_USE_EXTSTR_FREE) && !defined(DUK_USE_HSTRING_EXTDATA)
3462 #error config option DUK_USE_EXTSTR_FREE requires option DUK_USE_HSTRING_EXTDATA (which is missing)
3464 #if defined(DUK_USE_EXTSTR_INTERN_CHECK) && !defined(DUK_USE_HSTRING_EXTDATA)
3465 #error config option DUK_USE_EXTSTR_INTERN_CHECK requires option DUK_USE_HSTRING_EXTDATA (which is missing)
3467 #if defined(DUK_USE_FASTINT) && !defined(DUK_USE_64BIT_OPS)
3468 #error config option DUK_USE_FASTINT requires option DUK_USE_64BIT_OPS (which is missing)
3470 #if defined(DUK_USE_FILE_IO)
3471 #error unsupported config option used (option has been removed): DUK_USE_FILE_IO
3473 #if defined(DUK_USE_FULL_TVAL)
3474 #error unsupported config option used (option has been removed): DUK_USE_FULL_TVAL
3476 #if defined(DUK_USE_FUNCPTR_DEC16) && !defined(DUK_USE_FUNCPTR16)
3477 #error config option DUK_USE_FUNCPTR_DEC16 requires option DUK_USE_FUNCPTR16 (which is missing)
3479 #if defined(DUK_USE_FUNCPTR_ENC16) && !defined(DUK_USE_FUNCPTR16)
3480 #error config option DUK_USE_FUNCPTR_ENC16 requires option DUK_USE_FUNCPTR16 (which is missing)
3482 #if defined(DUK_USE_HASHBYTES_UNALIGNED_U32_ACCESS)
3483 #error unsupported config option used (option has been removed): DUK_USE_HASHBYTES_UNALIGNED_U32_ACCESS
3485 #if defined(DUK_USE_HEAPPTR16) && defined(DUK_USE_DEBUG)
3486 #error config option DUK_USE_HEAPPTR16 conflicts with option DUK_USE_DEBUG (which is also defined)
3488 #if defined(DUK_USE_HEAPPTR_DEC16) && !defined(DUK_USE_HEAPPTR16)
3489 #error config option DUK_USE_HEAPPTR_DEC16 requires option DUK_USE_HEAPPTR16 (which is missing)
3491 #if defined(DUK_USE_HEAPPTR_ENC16) && !defined(DUK_USE_HEAPPTR16)
3492 #error config option DUK_USE_HEAPPTR_ENC16 requires option DUK_USE_HEAPPTR16 (which is missing)
3494 #if defined(DUK_USE_INTEGER_BE)
3495 #error unsupported config option used (option has been removed): DUK_USE_INTEGER_BE
3497 #if defined(DUK_USE_INTEGER_BE) && defined(DUK_USE_INTEGER_LE)
3498 #error config option DUK_USE_INTEGER_BE conflicts with option DUK_USE_INTEGER_LE (which is also defined)
3500 #if defined(DUK_USE_INTEGER_BE) && defined(DUK_USE_INTEGER_ME)
3501 #error config option DUK_USE_INTEGER_BE conflicts with option DUK_USE_INTEGER_ME (which is also defined)
3503 #if defined(DUK_USE_INTEGER_LE)
3504 #error unsupported config option used (option has been removed): DUK_USE_INTEGER_LE
3506 #if defined(DUK_USE_INTEGER_LE) && defined(DUK_USE_INTEGER_BE)
3507 #error config option DUK_USE_INTEGER_LE conflicts with option DUK_USE_INTEGER_BE (which is also defined)
3509 #if defined(DUK_USE_INTEGER_LE) && defined(DUK_USE_INTEGER_ME)
3510 #error config option DUK_USE_INTEGER_LE conflicts with option DUK_USE_INTEGER_ME (which is also defined)
3512 #if defined(DUK_USE_INTEGER_ME)
3513 #error unsupported config option used (option has been removed): DUK_USE_INTEGER_ME
3515 #if defined(DUK_USE_INTEGER_ME) && defined(DUK_USE_INTEGER_LE)
3516 #error config option DUK_USE_INTEGER_ME conflicts with option DUK_USE_INTEGER_LE (which is also defined)
3518 #if defined(DUK_USE_INTEGER_ME) && defined(DUK_USE_INTEGER_BE)
3519 #error config option DUK_USE_INTEGER_ME conflicts with option DUK_USE_INTEGER_BE (which is also defined)
3521 #if defined(DUK_USE_MARKANDSWEEP_FINALIZER_TORTURE)
3522 #error unsupported config option used (option has been removed): DUK_USE_MARKANDSWEEP_FINALIZER_TORTURE
3524 #if defined(DUK_USE_MARK_AND_SWEEP)
3525 #error unsupported config option used (option has been removed): DUK_USE_MARK_AND_SWEEP
3527 #if defined(DUK_USE_MATH_FMAX)
3528 #error unsupported config option used (option has been removed): DUK_USE_MATH_FMAX
3530 #if defined(DUK_USE_MATH_FMIN)
3531 #error unsupported config option used (option has been removed): DUK_USE_MATH_FMIN
3533 #if defined(DUK_USE_MATH_ROUND)
3534 #error unsupported config option used (option has been removed): DUK_USE_MATH_ROUND
3536 #if defined(DUK_USE_MS_STRINGTABLE_RESIZE)
3537 #error unsupported config option used (option has been removed): DUK_USE_MS_STRINGTABLE_RESIZE
3539 #if defined(DUK_USE_NONSTD_ARRAY_CONCAT_TRAILER)
3540 #error unsupported config option used (option has been removed): DUK_USE_NONSTD_ARRAY_CONCAT_TRAILER
3542 #if defined(DUK_USE_NONSTD_ARRAY_MAP_TRAILER)
3543 #error unsupported config option used (option has been removed): DUK_USE_NONSTD_ARRAY_MAP_TRAILER
3545 #if defined(DUK_USE_NONSTD_REGEXP_DOLLAR_ESCAPE)
3546 #error unsupported config option used (option has been removed): DUK_USE_NONSTD_REGEXP_DOLLAR_ESCAPE
3548 #if defined(DUK_USE_NO_DOUBLE_ALIASING_SELFTEST)
3549 #error unsupported config option used (option has been removed): DUK_USE_NO_DOUBLE_ALIASING_SELFTEST
3551 #if defined(DUK_USE_OCTAL_SUPPORT)
3552 #error unsupported config option used (option has been removed): DUK_USE_OCTAL_SUPPORT
3554 #if defined(DUK_USE_PACKED_TVAL_POSSIBLE)
3555 #error unsupported config option used (option has been removed): DUK_USE_PACKED_TVAL_POSSIBLE
3557 #if defined(DUK_USE_PANIC_ABORT)
3558 #error unsupported config option used (option has been removed): DUK_USE_PANIC_ABORT
3560 #if defined(DUK_USE_PANIC_EXIT)
3561 #error unsupported config option used (option has been removed): DUK_USE_PANIC_EXIT
3563 #if defined(DUK_USE_PANIC_HANDLER)
3564 #error unsupported config option used (option has been removed): DUK_USE_PANIC_HANDLER
3566 #if defined(DUK_USE_PANIC_SEGFAULT)
3567 #error unsupported config option used (option has been removed): DUK_USE_PANIC_SEGFAULT
3569 #if defined(DUK_USE_POW_NETBSD_WORKAROUND)
3570 #error unsupported config option used (option has been removed): DUK_USE_POW_NETBSD_WORKAROUND
3572 #if defined(DUK_USE_RDTSC)
3573 #error unsupported config option used (option has been removed): DUK_USE_RDTSC
3575 #if defined(DUK_USE_REFZERO_FINALIZER_TORTURE)
3576 #error unsupported config option used (option has been removed): DUK_USE_REFZERO_FINALIZER_TORTURE
3578 #if defined(DUK_USE_ROM_GLOBAL_CLONE) && !defined(DUK_USE_ROM_STRINGS)
3579 #error config option DUK_USE_ROM_GLOBAL_CLONE requires option DUK_USE_ROM_STRINGS (which is missing)
3581 #if defined(DUK_USE_ROM_GLOBAL_CLONE) && !defined(DUK_USE_ROM_OBJECTS)
3582 #error config option DUK_USE_ROM_GLOBAL_CLONE requires option DUK_USE_ROM_OBJECTS (which is missing)
3584 #if defined(DUK_USE_ROM_GLOBAL_CLONE) && defined(DUK_USE_ROM_GLOBAL_INHERIT)
3585 #error config option DUK_USE_ROM_GLOBAL_CLONE conflicts with option DUK_USE_ROM_GLOBAL_INHERIT (which is also defined)
3587 #if defined(DUK_USE_ROM_GLOBAL_INHERIT) && !defined(DUK_USE_ROM_STRINGS)
3588 #error config option DUK_USE_ROM_GLOBAL_INHERIT requires option DUK_USE_ROM_STRINGS (which is missing)
3590 #if defined(DUK_USE_ROM_GLOBAL_INHERIT) && !defined(DUK_USE_ROM_OBJECTS)
3591 #error config option DUK_USE_ROM_GLOBAL_INHERIT requires option DUK_USE_ROM_OBJECTS (which is missing)
3593 #if defined(DUK_USE_ROM_GLOBAL_INHERIT) && defined(DUK_USE_ROM_GLOBAL_CLONE)
3594 #error config option DUK_USE_ROM_GLOBAL_INHERIT conflicts with option DUK_USE_ROM_GLOBAL_CLONE (which is also defined)
3596 #if defined(DUK_USE_ROM_OBJECTS) && !defined(DUK_USE_ROM_STRINGS)
3597 #error config option DUK_USE_ROM_OBJECTS requires option DUK_USE_ROM_STRINGS (which is missing)
3599 #if defined(DUK_USE_ROM_STRINGS) && !defined(DUK_USE_ROM_OBJECTS)
3600 #error config option DUK_USE_ROM_STRINGS requires option DUK_USE_ROM_OBJECTS (which is missing)
3602 #if defined(DUK_USE_SETJMP)
3603 #error unsupported config option used (option has been removed): DUK_USE_SETJMP
3605 #if defined(DUK_USE_SIGSETJMP)
3606 #error unsupported config option used (option has been removed): DUK_USE_SIGSETJMP
3608 #if defined(DUK_USE_STRTAB_CHAIN)
3609 #error unsupported config option used (option has been removed): DUK_USE_STRTAB_CHAIN
3611 #if defined(DUK_USE_STRTAB_CHAIN_SIZE)
3612 #error unsupported config option used (option has been removed): DUK_USE_STRTAB_CHAIN_SIZE
3614 #if defined(DUK_USE_STRTAB_CHAIN_SIZE) && !defined(DUK_USE_STRTAB_CHAIN)
3615 #error config option DUK_USE_STRTAB_CHAIN_SIZE requires option DUK_USE_STRTAB_CHAIN (which is missing)
3617 #if defined(DUK_USE_STRTAB_PROBE)
3618 #error unsupported config option used (option has been removed): DUK_USE_STRTAB_PROBE
3620 #if defined(DUK_USE_STRTAB_PTRCOMP) && !defined(DUK_USE_HEAPPTR16)
3621 #error config option DUK_USE_STRTAB_PTRCOMP requires option DUK_USE_HEAPPTR16 (which is missing)
3623 #if defined(DUK_USE_TAILCALL) && defined(DUK_USE_NONSTD_FUNC_CALLER_PROPERTY)
3624 #error config option DUK_USE_TAILCALL conflicts with option DUK_USE_NONSTD_FUNC_CALLER_PROPERTY (which is also defined)
3626 #if defined(DUK_USE_UNALIGNED_ACCESSES_POSSIBLE)
3627 #error unsupported config option used (option has been removed): DUK_USE_UNALIGNED_ACCESSES_POSSIBLE
3629 #if defined(DUK_USE_UNDERSCORE_SETJMP)
3630 #error unsupported config option used (option has been removed): DUK_USE_UNDERSCORE_SETJMP
3632 #if defined(DUK_USE_USER_INITJS)
3633 #error unsupported config option used (option has been removed): DUK_USE_USER_INITJS
3636 #if defined(DUK_USE_CPP_EXCEPTIONS) && !defined(__cplusplus)
3637 #error DUK_USE_CPP_EXCEPTIONS enabled but not compiling with a C++ compiler
3641 * Convert DUK_USE_BYTEORDER, from whatever source, into currently used
3642 * internal defines. If detection failed, #error out.
3645 #if defined(DUK_USE_BYTEORDER)
3646 #if (DUK_USE_BYTEORDER == 1)
3647 #define DUK_USE_INTEGER_LE
3648 #define DUK_USE_DOUBLE_LE
3649 #elif (DUK_USE_BYTEORDER == 2)
3650 #define DUK_USE_INTEGER_LE /* integer endianness is little on purpose */
3651 #define DUK_USE_DOUBLE_ME
3652 #elif (DUK_USE_BYTEORDER == 3)
3653 #define DUK_USE_INTEGER_BE
3654 #define DUK_USE_DOUBLE_BE
3656 #error unsupported: byte order invalid
3657 #endif /* byte order */
3659 #error unsupported: byte order detection failed
3660 #endif /* defined(DUK_USE_BYTEORDER) */
3662 #endif /* DUK_CONFIG_H_INCLUDED */