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