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