1 module duk_config;
2 /*
3  *  duk_config.h configuration header generated by genconfig.py.
4  *
5  *  Git commit: d7fdb67f18561a50e06bafd196c6b423af9ad6fe
6  *  Git describe: v2.3.0
7  *  Git branch: master
8  *
9  *  Supported platforms:
10  *      - Mac OSX, iPhone, Darwin
11  *      - Orbis
12  *      - OpenBSD
13  *      - Generic BSD
14  *      - Atari ST TOS
15  *      - AmigaOS
16  *      - Durango (XboxOne)
17  *      - Windows
18  *      - Flashplayer (Crossbridge)
19  *      - QNX
20  *      - TI-Nspire
21  *      - Emscripten
22  *      - Linux
23  *      - Solaris
24  *      - AIX
25  *      - HPUX
26  *      - Generic POSIX
27  *      - Cygwin
28  *      - Generic UNIX
29  *      - Generic fallback
30  *
31  *  Supported architectures:
32  *      - x86
33  *      - x64
34  *      - x32
35  *      - ARM 32-bit
36  *      - ARM 64-bit
37  *      - MIPS 32-bit
38  *      - MIPS 64-bit
39  *      - PowerPC 32-bit
40  *      - PowerPC 64-bit
41  *      - SPARC 32-bit
42  *      - SPARC 64-bit
43  *      - SuperH
44  *      - Motorola 68k
45  *      - Emscripten
46  *      - Generic
47  *
48  *  Supported compilers:
49  *      - Clang
50  *      - GCC
51  *      - MSVC
52  *      - Emscripten
53  *      - TinyC
54  *      - VBCC
55  *      - Bruce's C compiler
56  *      - Generic
57  *
58  */
59 
60 import core.stdc.config;
61 
62 import core.stdc.math;
63 import core.stdc.stdint;
64 import core.stdc.stdio;
65 import core.stdc.stdlib;
66 import core.stdc..string;
67 import core.sys.posix.setjmp;
68 import core.stdc.limits;
69 public import core.stdc.stdarg;
70 
71 extern (C):
72 
73 /*
74  *  Intermediate helper defines
75  */
76 
77 /* DLL build detection */
78 /* not configured for DLL build */
79 
80 /* Apple OSX, iOS */
81 
82 /* FreeBSD */
83 
84 /* Orbis (PS4) variant */
85 
86 /* OpenBSD */
87 
88 /* NetBSD */
89 
90 /* BSD variant */
91 
92 /* Atari ST TOS.  __TOS__ defined by PureC.  No platform define in VBCC
93  * apparently, so to use with VBCC user must define __TOS__ manually.
94   */
95 
96 /* Motorola 68K.  Not defined by VBCC, so user must define one of these
97  * manually when using VBCC.
98  */
99 
100 /* AmigaOS.  Neither AMIGA nor __amigaos__ is defined on VBCC, so user must
101  * define 'AMIGA' manually when using VBCC.
102  */
103 
104 /* PowerPC */
105 
106 /* Durango (Xbox One) */
107 
108 /* Windows, both 32-bit and 64-bit */
109 
110 /* Flash player (e.g. Crossbridge) */
111 
112 /* QNX */
113 
114 /* TI-Nspire (using Ndless) */
115 
116 /* Emscripten (provided explicitly by user), improve if possible */
117 
118 /* BCC (Bruce's C compiler): this is a "torture target" for compilation */
119 
120 /* Linux */
121 
122 /* illumos / Solaris */
123 
124 /* Defines _ILP32 / _LP64 required by DUK_F_X86/DUK_F_X64.  Platforms
125  * are processed before architectures, so this happens before the
126  * DUK_F_X86/DUK_F_X64 detection is emitted.
127  */
128 
129 /* AIX */
130 
131 /* defined(__xlc__) || defined(__IBMC__): works but too wide */
132 
133 /* HPUX */
134 
135 /* POSIX */
136 
137 /* Cygwin */
138 
139 /* Generic Unix (includes Cygwin) */
140 
141 /* Intel x86 (32-bit), x64 (64-bit) or x32 (64-bit but 32-bit pointers),
142  * define only one of DUK_F_X86, DUK_F_X64, DUK_F_X32.
143  * https://sites.google.com/site/x32abi/
144  *
145  * With DUK_F_OLD_SOLARIS the <sys/isa_defs.h> header must be included
146  * before this.
147  */
148 
149 /* This should not really happen, but would indicate x64. */
150 
151 /* ARM */
152 
153 /* MIPS.  Related defines: __MIPSEB__, __MIPSEL__, __mips_isa_rev, __LP64__ */
154 
155 /* SPARC */
156 
157 /* SuperH */
158 
159 /* Clang */
160 
161 /* C++ */
162 
163 /* C99 or above */
164 
165 /* C++11 or above */
166 
167 /* GCC.  Clang also defines __GNUC__ so don't detect GCC if using Clang. */
168 
169 /* Convenience, e.g. gcc 4.5.1 == 40501; http://stackoverflow.com/questions/6031819/emulating-gccs-builtin-unreachable */
170 
171 /* MinGW.  Also GCC flags (DUK_F_GCC) are enabled now. */
172 
173 /* MSVC */
174 
175 /* MSVC preprocessor defines: http://msdn.microsoft.com/en-us/library/b0084kay.aspx
176  * _MSC_FULL_VER includes the build number, but it has at least two formats, see e.g.
177  * BOOST_MSVC_FULL_VER in http://www.boost.org/doc/libs/1_52_0/boost/config/compiler/visualc.hpp
178  */
179 
180 /* _MSC_VER */
181 
182 /* TinyC */
183 
184 /* http://bellard.org/tcc/tcc-doc.html#SEC9 */
185 
186 /* VBCC */
187 
188 /* Atari Mint */
189 
190 /*
191  *  Platform autodetection
192  */
193 
194 /* Workaround for older C++ compilers before including <inttypes.h>,
195  * see e.g.: https://sourceware.org/bugzilla/show_bug.cgi?id=15366
196  */
197 
198 /* --- Mac OSX, iPhone, Darwin --- */
199 
200 /* http://stackoverflow.com/questions/5919996/how-to-detect-reliably-mac-os-x-ios-linux-windows-in-c-preprocessor */
201 
202 /* Use _setjmp() on Apple by default, see GH-55. */
203 
204 /* --- Orbis --- */
205 /* Orbis = PS4 */
206 
207 /* no parsing (not an error) */
208 
209 /* --- OpenBSD --- */
210 /* http://www.monkey.org/openbsd/archive/ports/0401/msg00089.html */
211 
212 /* --- Generic BSD --- */
213 
214 /* --- Atari ST TOS --- */
215 
216 /* no parsing (not an error) */
217 
218 /* TOS on M68K is always big endian. */
219 
220 /* --- AmigaOS --- */
221 
222 /* AmigaOS on M68k */
223 
224 /* no parsing (not an error) */
225 
226 /* AmigaOS on M68K or PPC is always big endian. */
227 
228 /* --- Durango (XboxOne) --- */
229 /* Durango = XboxOne
230  * Configuration is nearly identical to Windows, except for
231  * DUK_USE_DATE_TZO_WINDOWS.
232  */
233 
234 /* Initial fix: disable secure CRT related warnings when compiling Duktape
235  * itself (must be defined before including Windows headers).  Don't define
236  * for user code including duktape.h.
237  */
238 
239 /* MSVC does not have sys/param.h */
240 
241 /* Note: PRS and FMT are intentionally left undefined for now.  This means
242  * there is no platform specific date parsing/formatting but there is still
243  * the ISO 8601 standard format.
244  */
245 
246 /* Only include when compiling Duktape to avoid polluting application build
247  * with a lot of unnecessary defines.
248  */
249 
250 /* --- Windows --- */
251 /* Windows version can't obviously be determined at compile time,
252  * but _WIN32_WINNT indicates the minimum version targeted:
253  * - https://msdn.microsoft.com/en-us/library/6sehtctf.aspx
254  */
255 
256 /* Initial fix: disable secure CRT related warnings when compiling Duktape
257  * itself (must be defined before including Windows headers).  Don't define
258  * for user code including duktape.h.
259  */
260 
261 /* Windows 32-bit and 64-bit are currently the same. */
262 /* MSVC does not have sys/param.h */
263 
264 /* Only include when compiling Duktape to avoid polluting application build
265  * with a lot of unnecessary defines.
266  */
267 
268 /* GetSystemTimePreciseAsFileTime() available from Windows 8:
269  * https://msdn.microsoft.com/en-us/library/windows/desktop/hh706895(v=vs.85).aspx
270  */
271 
272 /* User forced provider. */
273 
274 /* Note: PRS and FMT are intentionally left undefined for now.  This means
275  * there is no platform specific date parsing/formatting but there is still
276  * the ISO 8601 standard format.
277  */
278 
279 /* QueryPerformanceCounter() may go backwards in Windows XP, so enable for
280  * Vista and later: https://msdn.microsoft.com/en-us/library/windows/desktop/dn553408(v=vs.85).aspx#qpc_support_in_windows_versions
281  */
282 
283 /* On Windows, assume we're little endian.  Even Itanium which has a
284  * configurable endianness runs little endian in Windows.
285  */
286 
287 /* --- Flashplayer (Crossbridge) --- */
288 
289 /* --- QNX --- */
290 
291 /* See: /opt/qnx650/target/qnx6/usr/include/sys/platform.h */
292 
293 /* --- TI-Nspire --- */
294 
295 /* e.g. strptime */
296 
297 /* --- Emscripten --- */
298 
299 /* e.g. getdate_r */
300 
301 /* e.g. strptime */
302 
303 /* DUK_COMPILING_DUKTAPE */
304 
305 /* no endian.h */
306 
307 /* DUK_F_BCC */
308 
309 /* --- Linux --- */
310 
311 /* e.g. getdate_r */
312 
313 /* e.g. strptime */
314 
315 /* DUK_COMPILING_DUKTAPE */
316 
317 /* no endian.h or stdint.h */
318 
319 /* DUK_F_BCC */
320 
321 /* XXX: safe condition? */
322 
323 enum DUK_USE_OS_STRING = "linux";
324 
325 /* --- Solaris --- */
326 
327 /* Old Solaris with no endian.h, stdint.h */
328 
329 /* DUK_F_OLD_SOLARIS */
330 
331 /* DUK_F_OLD_SOLARIS */
332 
333 /* --- AIX --- */
334 
335 /* --- HPUX --- */
336 
337 /* --- Generic POSIX --- */
338 
339 /* --- Cygwin --- */
340 /* don't use strptime() for now */
341 
342 /* --- Generic UNIX --- */
343 
344 /* --- Generic fallback --- */
345 /* The most portable current time provider is time(), but it only has a
346  * one second resolution.
347  */
348 
349 /* The most portable way to figure out local time offset is gmtime(),
350  * but it's not thread safe so use with caution.
351  */
352 
353 /* Avoid custom date parsing and formatting for portability. */
354 
355 /* Rely on C89 headers only; time.h must be here. */
356 
357 /* autodetect platform */
358 
359 /* Shared includes: C89 */
360 
361 /* varargs */
362 
363 /* e.g. ptrdiff_t */
364 
365 /* date.h is omitted, and included per platform */
366 
367 /* Shared includes: stdint.h is C99 */
368 
369 /* stdint.h not available */
370 
371 /* Technically C99 (C++11) but found in many systems.  On some systems
372  * __STDC_LIMIT_MACROS and __STDC_CONSTANT_MACROS must be defined before
373  * including stdint.h (see above).
374  */
375 
376 /* <exception> is only included if needed, based on DUK_USE_xxx flags. */
377 
378 /*
379  *  Architecture autodetection
380  */
381 
382 /* --- x86 --- */
383 
384 /* FreeBSD, -m32, and clang prior to 5.0 has union aliasing issues which
385  * break duk_tval copying.  Disable packed duk_tval automatically.
386  */
387 
388 /* --- x64 --- */
389 
390 /* --- x32 --- */
391 
392 /* --- ARM 32-bit --- */
393 
394 /* Byte order varies, so rely on autodetect. */
395 
396 /* --- ARM 64-bit --- */
397 
398 /* Byte order varies, so rely on autodetect. */
399 
400 /* --- MIPS 32-bit --- */
401 
402 /* MIPS byte order varies so rely on autodetection. */
403 
404 /* --- MIPS 64-bit --- */
405 
406 /* MIPS byte order varies so rely on autodetection. */
407 
408 /* --- PowerPC 32-bit --- */
409 
410 /* --- PowerPC 64-bit --- */
411 
412 /* --- SPARC 32-bit --- */
413 
414 /* SPARC byte order varies so rely on autodetection. */
415 
416 /* --- SPARC 64-bit --- */
417 
418 /* SPARC byte order varies so rely on autodetection. */
419 
420 /* --- SuperH --- */
421 
422 /* Byte order varies, rely on autodetection. */
423 
424 /* --- Motorola 68k --- */
425 
426 /* --- Emscripten --- */
427 
428 /* --- Generic --- */
429 /* These are necessary wild guesses. */
430 
431 /* Rely on autodetection for byte order, alignment, and packed tval. */
432 /* autodetect architecture */
433 
434 /*
435  *  Compiler autodetection
436  */
437 
438 /* --- Clang --- */
439 
440 /* C99 / C++11 and above: rely on va_copy() which is required. */
441 
442 /* Clang: assume we have __va_copy() in non-C99 mode. */
443 
444 /* DUK_HOT */
445 /* DUK_COLD */
446 
447 /* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
448  * compiling Duktape or the application.
449  */
450 
451 /*empty*/
452 
453 /* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
454  * Clang.  Based on documentation it should suffice to have the attribute
455  * in the declaration only, but in practice some warnings are generated unless
456  * the attribute is also applied to the definition.
457  */
458 
459 /* --- GCC --- */
460 
461 /* C99 / C++11 and above: rely on va_copy() which is required. */
462 
463 /* GCC: assume we have __va_copy() in non-C99 mode. */
464 
465 /* since gcc-2.5 */
466 
467 /* since gcc-4.5 */
468 
469 /* GCC: test not very accurate; enable only in relatively recent builds
470  * because of bugs in gcc-4.4 (http://lists.debian.org/debian-gcc/2010/04/msg00000.html)
471  */
472 
473 /* XXX: equivalent of clang __builtin_unpredictable? */
474 
475 /* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
476  * compiling Duktape or the application.
477  */
478 
479 /*empty*/
480 
481 /* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
482  * Clang.  Based on documentation it should suffice to have the attribute
483  * in the declaration only, but in practice some warnings are generated unless
484  * the attribute is also applied to the definition.
485  */
486 
487 /* --- MSVC --- */
488 /* http://msdn.microsoft.com/en-us/library/aa235362(VS.60).aspx */
489 
490 /* XXX: DUK_UNREACHABLE for msvc? */
491 
492 /* XXX: DUK_LIKELY, DUK_UNLIKELY for msvc? */
493 /* XXX: DUK_NOINLINE, DUK_INLINE, DUK_ALWAYS_INLINE for msvc? */
494 
495 /* MSVC dllexport/dllimport: appropriate __declspec depends on whether we're
496  * compiling Duktape or the application.
497  */
498 
499 /*empty*/
500 
501 /* VS2005+ should have variadic macros even when they're not C99. */
502 
503 /* VS2013+ supports union initializers but there's a bug involving union-inside-struct:
504  * https://connect.microsoft.com/VisualStudio/feedback/details/805981
505  * The bug was fixed (at least) in VS2015 so check for VS2015 for now:
506  * https://blogs.msdn.microsoft.com/vcblog/2015/07/01/c-compiler-front-end-fixes-in-vs2015/
507  * Manually tested using VS2013, CL reports 18.00.31101, so enable for VS2013 too.
508  */
509 
510 /* These have been tested from VS2008 onwards; may work in older VS versions
511  * too but not enabled by default.
512  */
513 
514 /* (v)snprintf() is missing before MSVC 2015.  Note that _(v)snprintf() does
515  * NOT NUL terminate on truncation, but Duktape code never assumes that.
516  * http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
517  */
518 
519 /* Avoid warning when doing DUK_UNREF(some_function). */
520 
521 /* Older versions of MSVC don't support the LL/ULL suffix. */
522 
523 /* --- Emscripten --- */
524 
525 /* Minimize warnings for unused internal functions with GCC >= 3.1.1 and
526  * Clang.  Based on documentation it should suffice to have the attribute
527  * in the declaration only, but in practice some warnings are generated unless
528  * the attribute is also applied to the definition.
529  */
530 
531 /* --- TinyC --- */
532 
533 /* http://bellard.org/tcc/tcc-doc.html#SEC7 */
534 
535 /* Most portable, wastes space */
536 
537 /* Most portable, potentially wastes space */
538 
539 /* --- VBCC --- */
540 
541 /* VBCC supports C99 so check only for C99 for union initializer support.
542  * Designated union initializers would possibly work even without a C99 check.
543  */
544 
545 /* --- Bruce's C compiler --- */
546 
547 /* Most portable */
548 
549 /* Most portable, wastes space */
550 
551 /* Most portable, wastes space */
552 
553 /* Most portable, potentially wastes space */
554 
555 /* BCC, assume we're on x86. */
556 
557 /* --- Generic --- */
558 
559 /* C++ doesn't have standard designated union initializers ({ .foo = 1 }). */
560 
561 /* Most portable, wastes space */
562 
563 /* Most portable, potentially wastes space */
564 
565 /* autodetect compiler */
566 
567 /* uclibc */
568 
569 /*
570  *  Wrapper typedefs and constants for integer types, also sanity check types.
571  *
572  *  C99 typedefs are quite good but not always available, and we want to avoid
573  *  forcibly redefining the C99 typedefs.  So, there are Duktape wrappers for
574  *  all C99 typedefs and Duktape code should only use these typedefs.  Type
575  *  detection when C99 is not supported is best effort and may end up detecting
576  *  some types incorrectly.
577  *
578  *  Pointer sizes are a portability problem: pointers to different types may
579  *  have a different size and function pointers are very difficult to manage
580  *  portably.
581  *
582  *  http://en.wikipedia.org/wiki/C_data_types#Fixed-width_integer_types
583  *
584  *  Note: there's an interesting corner case when trying to define minimum
585  *  signed integer value constants which leads to the current workaround of
586  *  defining e.g. -0x80000000 as (-0x7fffffffL - 1L).  See doc/code-issues.txt
587  *  for a longer discussion.
588  *
589  *  Note: avoid typecasts and computations in macro integer constants as they
590  *  can then no longer be used in macro relational expressions (such as
591  *  #if DUK_SIZE_MAX < 0xffffffffUL).  There is internal code which relies on
592  *  being able to compare DUK_SIZE_MAX against a limit.
593  */
594 
595 /* XXX: add feature options to force basic types from outside? */
596 
597 /* Check that architecture is two's complement, standard C allows e.g.
598  * INT_MIN to be -2**31+1 (instead of -2**31).
599  */
600 
601 /* Pointer size determination based on __WORDSIZE or architecture when
602  * that's not available.
603  */
604 
605 /* not sure, not needed with C99 anyway */
606 
607 /* Intermediate define for 'have inttypes.h' */
608 
609 /* vbcc + AmigaOS has C99 but no inttypes.h */
610 
611 /* C++11 apparently ratified stdint.h */
612 
613 /* Basic integer typedefs and limits, preferably from inttypes.h, otherwise
614  * through automatic detection.
615  */
616 
617 /* C99 or compatible */
618 
619 alias duk_uint8_t = ubyte;
620 alias duk_int8_t = byte;
621 alias duk_uint16_t = ushort;
622 alias duk_int16_t = short;
623 alias duk_uint32_t = uint;
624 alias duk_int32_t = int;
625 alias duk_uint64_t = c_ulong;
626 alias duk_int64_t = c_long;
627 alias duk_uint_least8_t = ubyte;
628 alias duk_int_least8_t = byte;
629 alias duk_uint_least16_t = ushort;
630 alias duk_int_least16_t = short;
631 alias duk_uint_least32_t = uint;
632 alias duk_int_least32_t = int;
633 alias duk_uint_least64_t = c_ulong;
634 alias duk_int_least64_t = c_long;
635 alias duk_uint_fast8_t = ubyte;
636 alias duk_int_fast8_t = byte;
637 alias duk_uint_fast16_t = c_ulong;
638 alias duk_int_fast16_t = c_long;
639 alias duk_uint_fast32_t = c_ulong;
640 alias duk_int_fast32_t = c_long;
641 alias duk_uint_fast64_t = c_ulong;
642 alias duk_int_fast64_t = c_long;
643 alias duk_uintptr_t = c_ulong;
644 alias duk_intptr_t = c_long;
645 alias duk_uintmax_t = c_ulong;
646 alias duk_intmax_t = c_long;
647 
648 /* C99 types */
649 
650 /* When C99 types are not available, we use heuristic detection to get
651  * the basic 8, 16, 32, and (possibly) 64 bit types.  The fast/least
652  * types are then assumed to be exactly the same for now: these could
653  * be improved per platform but C99 types are very often now available.
654  * 64-bit types are not available on all platforms; this is OK at least
655  * on 32-bit platforms.
656  *
657  * This detection code is necessarily a bit hacky and can provide typedefs
658  * and defines that won't work correctly on some exotic platform.
659  */
660 
661 /* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */
662 
663 /* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */
664 
665 /* 64-bit type detection is a bit tricky.
666  *
667  * ULLONG_MAX is a standard define.  __LONG_LONG_MAX__ and __ULONG_LONG_MAX__
668  * are used by at least GCC (even if system headers don't provide ULLONG_MAX).
669  * Some GCC variants may provide __LONG_LONG_MAX__ but not __ULONG_LONG_MAX__.
670  *
671  * ULL / LL constants are rejected / warned about by some compilers, even if
672  * the compiler has a 64-bit type and the compiler/system headers provide an
673  * unsupported constant (ULL/LL)!  Try to avoid using ULL / LL constants.
674  * As a side effect we can only check that e.g. ULONG_MAX is larger than 32
675  * bits but can't be sure it is exactly 64 bits.  Self tests will catch such
676  * cases.
677  */
678 
679 /* cannot detect 64-bit type, not always needed so don't error */
680 
681 /* Note: the funny looking computations for signed minimum 16-bit, 32-bit, and
682  * 64-bit values are intentional as the obvious forms (e.g. -0x80000000L) are
683  * -not- portable.  See code-issues.txt for a detailed discussion.
684  */
685 
686 /* 64-bit constants.  Since LL / ULL constants are not always available,
687  * use computed values.  These values can't be used in preprocessor
688  * comparisons; flag them as such.
689  */
690 
691 /* This detection is not very reliable. */
692 
693 /* SIZE_MAX may be missing so use an approximate value for it. */
694 
695 /* C99 types */
696 
697 /* A few types are assumed to always exist. */
698 alias duk_size_t = c_ulong;
699 alias duk_ptrdiff_t = c_long;
700 
701 /* The best type for an "all around int" in Duktape internals is "at least
702  * 32 bit signed integer" which is most convenient.  Same for unsigned type.
703  * Prefer 'int' when large enough, as it is almost always a convenient type.
704  */
705 
706 alias duk_int_t = int;
707 alias duk_uint_t = uint;
708 
709 /* Same as 'duk_int_t' but guaranteed to be a 'fast' variant if this
710  * distinction matters for the CPU.  These types are used mainly in the
711  * executor where it might really matter.
712  */
713 alias duk_int_fast_t = c_long;
714 alias duk_uint_fast_t = c_ulong;
715 
716 /* Small integers (16 bits or more) can fall back to the 'int' type, but
717  * have a typedef so they are marked "small" explicitly.
718  */
719 alias duk_small_int_t = int;
720 alias duk_small_uint_t = uint;
721 
722 /* Fast variants of small integers, again for really fast paths like the
723  * executor.
724  */
725 alias duk_small_int_fast_t = c_long;
726 alias duk_small_uint_fast_t = c_ulong;
727 
728 /* Boolean values are represented with the platform 'unsigned int'. */
729 alias duk_bool_t = uint;
730 
731 /* Index values must have at least 32-bit signed range. */
732 alias duk_idx_t = int;
733 
734 /* Unsigned index variant. */
735 alias duk_uidx_t = uint;
736 
737 /* Array index values, could be exact 32 bits.
738  * Currently no need for signed duk_arridx_t.
739  */
740 alias duk_uarridx_t = uint;
741 
742 /* Duktape/C function return value, platform int is enough for now to
743  * represent 0, 1, or negative error code.  Must be compatible with
744  * assigning truth values (e.g. duk_ret_t rc = (foo == bar);).
745  */
746 alias duk_ret_t = int;
747 
748 /* Error codes are represented with platform int.  High bits are used
749  * for flags and such, so 32 bits are needed.
750  */
751 alias duk_errcode_t = int;
752 
753 /* Codepoint type.  Must be 32 bits or more because it is used also for
754  * internal codepoints.  The type is signed because negative codepoints
755  * are used as internal markers (e.g. to mark EOF or missing argument).
756  * (X)UTF-8/CESU-8 encode/decode take and return an unsigned variant to
757  * ensure duk_uint32_t casts back and forth nicely.  Almost everything
758  * else uses the signed one.
759  */
760 alias duk_codepoint_t = int;
761 alias duk_ucodepoint_t = uint;
762 
763 /* IEEE float/double typedef. */
764 alias duk_float_t = float;
765 alias duk_double_t = double;
766 
767 /* We're generally assuming that we're working on a platform with a 32-bit
768  * address space.  If DUK_SIZE_MAX is a typecast value (which is necessary
769  * if SIZE_MAX is missing), the check must be avoided because the
770  * preprocessor can't do a comparison.
771  */
772 
773 /* On some systems SIZE_MAX can be smaller than max unsigned 32-bit value
774  * which seems incorrect if size_t is (at least) an unsigned 32-bit type.
775  * However, it doesn't seem useful to error out compilation if this is the
776  * case.
777  */
778 
779 /* Type used in public API declarations and user code.  Typedef maps to
780  * 'struct duk_hthread' like the 'duk_hthread' typedef which is used
781  * exclusively in internals.
782  */
783 struct duk_hthread;
784 alias duk_context = duk_hthread;
785 enum DUK_USE_ARCH_STRING = "x64";
786 enum DUK_USE_BYTEORDER = 1;
787 alias DUK_VA_COPY = va_copy;
788 
789 extern (D) auto DUK_LIKELY(T)(auto ref T x)
790 {
791     return __builtin_expect(x, 1);
792 }
793 
794 extern (D) auto DUK_UNLIKELY(T)(auto ref T x)
795 {
796     return __builtin_expect(x, 0);
797 }
798 
799 //alias DUK_UNPREDICTABLE = __builtin_unpredictable;
800 enum DUK_USE_COMPILER_STRING = "clang";
801 enum DUK_UINT8_MIN = 0;
802 enum DUK_UINT8_MAX = UINT8_MAX;
803 enum DUK_INT8_MIN = INT8_MIN;
804 enum DUK_INT8_MAX = INT8_MAX;
805 enum DUK_UINT_LEAST8_MIN = 0;
806 enum DUK_UINT_LEAST8_MAX = UINT_LEAST8_MAX;
807 enum DUK_INT_LEAST8_MIN = INT_LEAST8_MIN;
808 enum DUK_INT_LEAST8_MAX = INT_LEAST8_MAX;
809 enum DUK_UINT_FAST8_MIN = 0;
810 enum DUK_UINT_FAST8_MAX = UINT_FAST8_MAX;
811 enum DUK_INT_FAST8_MIN = INT_FAST8_MIN;
812 enum DUK_INT_FAST8_MAX = INT_FAST8_MAX;
813 enum DUK_UINT16_MIN = 0;
814 enum DUK_UINT16_MAX = UINT16_MAX;
815 enum DUK_INT16_MIN = INT16_MIN;
816 enum DUK_INT16_MAX = INT16_MAX;
817 enum DUK_UINT_LEAST16_MIN = 0;
818 enum DUK_UINT_LEAST16_MAX = UINT_LEAST16_MAX;
819 enum DUK_INT_LEAST16_MIN = INT_LEAST16_MIN;
820 enum DUK_INT_LEAST16_MAX = INT_LEAST16_MAX;
821 enum DUK_UINT_FAST16_MIN = 0;
822 enum DUK_UINT_FAST16_MAX = UINT_FAST16_MAX;
823 enum DUK_INT_FAST16_MIN = INT_FAST16_MIN;
824 enum DUK_INT_FAST16_MAX = INT_FAST16_MAX;
825 enum DUK_UINT32_MIN = 0;
826 enum DUK_UINT32_MAX = UINT32_MAX;
827 enum DUK_INT32_MIN = INT32_MIN;
828 enum DUK_INT32_MAX = INT32_MAX;
829 enum DUK_UINT_LEAST32_MIN = 0;
830 enum DUK_UINT_LEAST32_MAX = UINT_LEAST32_MAX;
831 enum DUK_INT_LEAST32_MIN = INT_LEAST32_MIN;
832 enum DUK_INT_LEAST32_MAX = INT_LEAST32_MAX;
833 enum DUK_UINT_FAST32_MIN = 0;
834 enum DUK_UINT_FAST32_MAX = UINT_FAST32_MAX;
835 enum DUK_INT_FAST32_MIN = INT_FAST32_MIN;
836 enum DUK_INT_FAST32_MAX = INT_FAST32_MAX;
837 enum DUK_UINT64_MIN = 0;
838 enum DUK_UINT64_MAX = UINT64_MAX;
839 enum DUK_INT64_MIN = INT64_MIN;
840 enum DUK_INT64_MAX = INT64_MAX;
841 enum DUK_UINT_LEAST64_MIN = 0;
842 enum DUK_UINT_LEAST64_MAX = UINT_LEAST64_MAX;
843 enum DUK_INT_LEAST64_MIN = INT_LEAST64_MIN;
844 enum DUK_INT_LEAST64_MAX = INT_LEAST64_MAX;
845 enum DUK_UINT_FAST64_MIN = 0;
846 enum DUK_UINT_FAST64_MAX = UINT_FAST64_MAX;
847 enum DUK_INT_FAST64_MIN = INT_FAST64_MIN;
848 enum DUK_INT_FAST64_MAX = INT_FAST64_MAX;
849 enum DUK_UINTPTR_MIN = 0;
850 enum DUK_UINTPTR_MAX = UINTPTR_MAX;
851 enum DUK_INTPTR_MIN = INTPTR_MIN;
852 enum DUK_INTPTR_MAX = INTPTR_MAX;
853 enum DUK_UINTMAX_MIN = 0;
854 enum DUK_UINTMAX_MAX = UINTMAX_MAX;
855 enum DUK_INTMAX_MIN = INTMAX_MIN;
856 enum DUK_INTMAX_MAX = INTMAX_MAX;
857 enum DUK_SIZE_MIN = 0;
858 enum DUK_SIZE_MAX = SIZE_MAX;
859 enum DUK_INT_MIN = INT_MIN;
860 enum DUK_INT_MAX = INT_MAX;
861 enum DUK_UINT_MIN = 0;
862 enum DUK_UINT_MAX = UINT_MAX;
863 enum DUK_INT_FAST_MIN = DUK_INT_FAST32_MIN;
864 enum DUK_INT_FAST_MAX = DUK_INT_FAST32_MAX;
865 enum DUK_UINT_FAST_MIN = DUK_UINT_FAST32_MIN;
866 enum DUK_UINT_FAST_MAX = DUK_UINT_FAST32_MAX;
867 enum DUK_SMALL_INT_MIN = INT_MIN;
868 enum DUK_SMALL_INT_MAX = INT_MAX;
869 enum DUK_SMALL_UINT_MIN = 0;
870 enum DUK_SMALL_UINT_MAX = UINT_MAX;
871 enum DUK_SMALL_INT_FAST_MIN = DUK_INT_FAST16_MIN;
872 enum DUK_SMALL_INT_FAST_MAX = DUK_INT_FAST16_MAX;
873 enum DUK_SMALL_UINT_FAST_MIN = DUK_UINT_FAST16_MIN;
874 enum DUK_SMALL_UINT_FAST_MAX = DUK_UINT_FAST16_MAX;
875 enum DUK_BOOL_MIN = DUK_SMALL_UINT_MIN;
876 enum DUK_BOOL_MAX = DUK_SMALL_UINT_MAX;
877 enum DUK_IDX_MIN = DUK_INT_MIN;
878 enum DUK_IDX_MAX = DUK_INT_MAX;
879 enum DUK_UIDX_MIN = DUK_UINT_MIN;
880 enum DUK_UIDX_MAX = DUK_UINT_MAX;
881 enum DUK_UARRIDX_MIN = DUK_UINT_MIN;
882 enum DUK_UARRIDX_MAX = DUK_UINT_MAX;
883 enum DUK_RET_MIN = DUK_SMALL_INT_MIN;
884 enum DUK_RET_MAX = DUK_SMALL_INT_MAX;
885 enum DUK_ERRCODE_MIN = DUK_INT_MIN;
886 enum DUK_ERRCODE_MAX = DUK_INT_MAX;
887 enum DUK_CODEPOINT_MIN = DUK_INT_MIN;
888 enum DUK_CODEPOINT_MAX = DUK_INT_MAX;
889 enum DUK_UCODEPOINT_MIN = DUK_UINT_MIN;
890 enum DUK_UCODEPOINT_MAX = DUK_UINT_MAX;
891 
892 /* Check whether we should use 64-bit integers or not.
893  *
894  * Quite incomplete now.  Use 64-bit types if detected (C99 or other detection)
895  * unless they are known to be unreliable.  For instance, 64-bit types are
896  * available on VBCC but seem to misbehave.
897  */
898 
899 /*
900  *  Fill-ins for platform, architecture, and compiler
901  */
902 
903 /* An abort()-like primitive is needed by the default fatal error handler. */
904 
905 alias DUK_ABORT = abort;
906 
907 version(Posix) {
908 
909 alias DUK_JMPBUF_TYPE = jmp_buf;
910 alias DUK_SETJMP = setjmp;
911 
912 }
913 
914 extern (D) auto DUK_LONGJMP(T)(auto ref T jb)
915 {
916     return longjmp(jb, 1);
917 }
918 
919 /* sigsetjmp() alternative */
920 
921 /* Special naming to avoid conflict with e.g. DUK_FREE() in duk_heap.h
922  * (which is unfortunately named).  May sometimes need replacement, e.g.
923  * some compilers don't handle zero length or NULL correctly in realloc().
924  */
925 
926 alias DUK_ANSI_MALLOC = malloc;
927 
928 alias DUK_ANSI_REALLOC = realloc;
929 
930 alias DUK_ANSI_CALLOC = calloc;
931 
932 alias DUK_ANSI_FREE = free;
933 
934 /* ANSI C (various versions) and some implementations require that the
935  * pointer arguments to memset(), memcpy(), and memmove() be valid values
936  * even when byte size is 0 (even a NULL pointer is considered invalid in
937  * this context).  Zero-size operations as such are allowed, as long as their
938  * pointer arguments point to a valid memory area.  The DUK_MEMSET(),
939  * DUK_MEMCPY(), and DUK_MEMMOVE() macros require this same behavior, i.e.:
940  * (1) pointers must be valid and non-NULL, (2) zero size must otherwise be
941  * allowed.  If these are not fulfilled, a macro wrapper is needed.
942  *
943  *   http://stackoverflow.com/questions/5243012/is-it-guaranteed-to-be-safe-to-perform-memcpy0-0-0
944  *   http://lists.cs.uiuc.edu/pipermail/llvmdev/2007-October/011065.html
945  *
946  * Not sure what's the required behavior when a pointer points just past the
947  * end of a buffer, which often happens in practice (e.g. zero size memmoves).
948  * For example, if allocation size is 3, the following pointer would not
949  * technically point to a valid memory byte:
950  *
951  *   <-- alloc -->
952  *   | 0 | 1 | 2 | .....
953  *                 ^-- p=3, points after last valid byte (2)
954  */
955 
956 /* Old uclibcs have a broken memcpy so use memmove instead (this is overly wide
957  * now on purpose): http://lists.uclibc.org/pipermail/uclibc-cvs/2008-October/025511.html
958  */
959 
960 alias DUK_MEMCPY = memcpy;
961 
962 alias DUK_MEMMOVE = memmove;
963 
964 alias DUK_MEMCMP = memcmp;
965 
966 alias DUK_MEMSET = memset;
967 
968 alias DUK_STRLEN = strlen;
969 
970 alias DUK_STRCMP = strcmp;
971 
972 alias DUK_STRNCMP = strncmp;
973 
974 alias DUK_SPRINTF = sprintf;
975 
976 /* snprintf() is technically not part of C89 but usually available. */
977 alias DUK_SNPRINTF = snprintf;
978 
979 alias DUK_VSPRINTF = vsprintf;
980 
981 /* vsnprintf() is technically not part of C89 but usually available. */
982 alias DUK_VSNPRINTF = vsnprintf;
983 
984 alias DUK_SSCANF = sscanf;
985 
986 alias DUK_VSSCANF = vsscanf;
987 
988 extern (D) auto DUK_MEMZERO(T0, T1)(auto ref T0 p, auto ref T1 n)
989 {
990     return DUK_MEMSET();
991 }
992 
993 /* GCC older than 4.6: avoid overflow warnings related to using INFINITY */
994 
995 enum DUK_DOUBLE_INFINITY = cast(double) INFINITY;
996 
997 /* In VBCC (1.0 / 0.0) results in a warning and 0.0 instead of infinity.
998  * Use a computed infinity (initialized when a heap is created at the
999  * latest).
1000  */
1001 
1002 enum DUK_DOUBLE_NAN = NAN;
1003 
1004 /* In VBCC (0.0 / 0.0) results in a warning and 0.0 instead of NaN.
1005  * In MSVC (VS2010 Express) (0.0 / 0.0) results in a compile error.
1006  * Use a computed NaN (initialized when a heap is created at the
1007  * latest).
1008  */
1009 
1010 /* Many platforms are missing fpclassify() and friends, so use replacements
1011  * if necessary.  The replacement constants (FP_NAN etc) can be anything but
1012  * match Linux constants now.
1013  */
1014 
1015 /* Complex condition broken into separate parts. */
1016 
1017 /* Missing some obvious constants. */
1018 
1019 /* VBCC is missing the built-ins even in C99 mode (perhaps a header issue). */
1020 
1021 /* AmigaOS + M68K seems to have math issues even when using GCC cross
1022  * compilation.  Use replacements for all AmigaOS versions on M68K
1023  * regardless of compiler.
1024  */
1025 
1026 /* Placeholder fix for (detection is wider than necessary):
1027  * http://llvm.org/bugs/show_bug.cgi?id=17788
1028  */
1029 
1030 /* At least some uclibc versions have broken floating point math.  For
1031  * example, fpclassify() can incorrectly classify certain NaN formats.
1032  * To be safe, use replacements.
1033  */
1034 
1035 /* Older versions may be missing isnan(), etc. */
1036 
1037 /* These functions don't currently need replacement but are wrapped for
1038  * completeness.  Because these are used as function pointers, they need
1039  * to be defined as concrete C functions (not macros).
1040  */
1041 
1042 alias DUK_FABS = fabs;
1043 
1044 alias DUK_FLOOR = floor;
1045 
1046 alias DUK_CEIL = ceil;
1047 
1048 alias DUK_FMOD = fmod;
1049 
1050 alias DUK_POW = pow;
1051 
1052 alias DUK_ACOS = acos;
1053 
1054 alias DUK_ASIN = asin;
1055 
1056 alias DUK_ATAN = atan;
1057 
1058 alias DUK_ATAN2 = atan2;
1059 
1060 alias DUK_SIN = sin;
1061 
1062 alias DUK_COS = cos;
1063 
1064 alias DUK_TAN = tan;
1065 
1066 alias DUK_EXP = exp;
1067 
1068 alias DUK_LOG = log;
1069 
1070 alias DUK_SQRT = sqrt;
1071 
1072 /* The functions below exist only in C99/C++11 or later and need a workaround
1073  * for platforms that don't include them.  MSVC isn't detected as C99, but
1074  * these functions also exist in MSVC 2013 and later so include a clause for
1075  * that too.  Android doesn't have log2; disable all of these for Android.
1076  */
1077 
1078 
1079 /* DUK_F_C99 etc */
1080 
1081 /* NetBSD 6.0 x86 (at least) has a few problems with pow() semantics,
1082  * see test-bug-netbsd-math-pow.js.  MinGW has similar (but different)
1083  * issues, see test-bug-mingw-math-issues.js.  Enable pow() workarounds
1084  * for these targets.
1085  */
1086 
1087 /* Similar workarounds for atan2() semantics issues.  MinGW issues are
1088  * documented in test-bug-mingw-math-issues.js.
1089  */
1090 
1091 /* Rely as little as possible on compiler behavior for NaN comparison,
1092  * signed zero handling, etc.  Currently never activated but may be needed
1093  * for broken compilers.
1094  */
1095 
1096 /* There was a curious bug where test-bi-date-canceling.js would fail e.g.
1097  * on 64-bit Ubuntu, gcc-4.8.1, -m32, and no -std=c99.  Some date computations
1098  * using doubles would be optimized which then broke some corner case tests.
1099  * The problem goes away by adding 'volatile' to the datetime computations.
1100  * Not sure what the actual triggering conditions are, but using this on
1101  * non-C99 systems solves the known issues and has relatively little cost
1102  * on other platforms.
1103  */
1104 
1105 /*
1106  *  Byte order and double memory layout detection
1107  *
1108  *  Endianness detection is a major portability hassle because the macros
1109  *  and headers are not standardized.  There's even variance across UNIX
1110  *  platforms.  Even with "standard" headers, details like underscore count
1111  *  varies between platforms, e.g. both __BYTE_ORDER and _BYTE_ORDER are used
1112  *  (Crossbridge has a single underscore, for instance).
1113  *
1114  *  The checks below are structured with this in mind: several approaches are
1115  *  used, and at the end we check if any of them worked.  This allows generic
1116  *  approaches to be tried first, and platform/compiler specific hacks tried
1117  *  last.  As a last resort, the user can force a specific endianness, as it's
1118  *  not likely that automatic detection will work on the most exotic platforms.
1119  *
1120  *  Duktape supports little and big endian machines.  There's also support
1121  *  for a hybrid used by some ARM machines where integers are little endian
1122  *  but IEEE double values use a mixed order (12345678 -> 43218765).  This
1123  *  byte order for doubles is referred to as "mixed endian".
1124  */
1125 
1126 /* GCC and Clang provide endianness defines as built-in predefines, with
1127  * leading and trailing double underscores (e.g. __BYTE_ORDER__).  See
1128  * output of "make gccpredefs" and "make clangpredefs".  Clang doesn't
1129  * seem to provide __FLOAT_WORD_ORDER__; assume not mixed endian for clang.
1130  * http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html
1131  */
1132 
1133 /* Float word order not known, assume not a hybrid. */
1134 
1135 /* Byte order is little endian but cannot determine IEEE double word order. */
1136 /* float word order */
1137 
1138 /* Float word order not known, assume not a hybrid. */
1139 
1140 /* Byte order is big endian but cannot determine IEEE double word order. */
1141 /* float word order */
1142 
1143 /* Cannot determine byte order; __ORDER_PDP_ENDIAN__ is related to 32-bit
1144  * integer ordering and is not relevant.
1145  */
1146 /* integer byte order */
1147 /* !defined(DUK_USE_BYTEORDER) && defined(__BYTE_ORDER__) */
1148 
1149 /* More or less standard endianness predefines provided by header files.
1150  * The ARM hybrid case is detected by assuming that __FLOAT_WORD_ORDER
1151  * will be big endian, see: http://lists.mysql.com/internals/443.
1152  * On some platforms some defines may be present with an empty value which
1153  * causes comparisons to fail: https://github.com/svaarala/duktape/issues/453.
1154  */
1155 
1156 /* Float word order not known, assume not a hybrid. */
1157 
1158 /* Byte order is little endian but cannot determine IEEE double word order. */
1159 /* float word order */
1160 
1161 /* Float word order not known, assume not a hybrid. */
1162 
1163 /* Byte order is big endian but cannot determine IEEE double word order. */
1164 /* float word order */
1165 
1166 /* Cannot determine byte order. */
1167 /* integer byte order */
1168 /* !defined(DUK_USE_BYTEORDER) */
1169 
1170 /* QNX gcc cross compiler seems to define e.g. __LITTLEENDIAN__ or __BIGENDIAN__:
1171  *  $ /opt/qnx650/host/linux/x86/usr/bin/i486-pc-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
1172  *  67:#define __LITTLEENDIAN__ 1
1173  *  $ /opt/qnx650/host/linux/x86/usr/bin/mips-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
1174  *  81:#define __BIGENDIAN__ 1
1175  *  $ /opt/qnx650/host/linux/x86/usr/bin/arm-unknown-nto-qnx6.5.0-gcc -dM -E - </dev/null | grep -ni endian
1176  *  70:#define __LITTLEENDIAN__ 1
1177  */
1178 
1179 /*
1180  *  Alignment requirement and support for unaligned accesses
1181  *
1182  *  Assume unaligned accesses are not supported unless specifically allowed
1183  *  in the target platform.  Some platforms may support unaligned accesses
1184  *  but alignment to 4 or 8 may still be desirable.  Note that unaligned
1185  *  accesses (and even pointers) relative to natural alignment (regardless
1186  *  of target alignment) are technically undefined behavior and thus
1187  *  compiler/architecture specific.
1188  */
1189 
1190 /* If not forced, use safe default for alignment. */
1191 
1192 enum DUK_USE_ALIGN_BY = 8;
1193 
1194 /* Compiler specific hackery needed to force struct size to match aligment,
1195  * see e.g. duk_hbuffer.h.
1196  *
1197  * http://stackoverflow.com/questions/11130109/c-struct-size-alignment
1198  * http://stackoverflow.com/questions/10951039/specifying-64-bit-alignment
1199  */
1200 
1201 /* We need va_copy() which is defined in C99 / C++11, so an awkward
1202  * replacement is needed for pre-C99 / pre-C++11 environments.  This
1203  * will quite likely need portability hacks for some non-C99
1204  * environments.
1205  */
1206 
1207 /* C99 / C++11 and above: rely on va_copy() which is required.
1208  * Omit parenthesis on macro right side on purpose to minimize differences
1209  * to direct use.
1210  */
1211 
1212 /* Pre-C99: va_list type is implementation dependent.  This replacement
1213  * assumes it is a plain value so that a simple assignment will work.
1214  * This is not the case on all platforms (it may be a single-array element,
1215  * for instance).
1216  */
1217 
1218 /* Macro hackery to convert e.g. __LINE__ to a string without formatting,
1219  * see: http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string
1220  */
1221 extern (D) string DUK_MACRO_STRINGIFY_HELPER(T)(auto ref T x)
1222 {
1223     import std.conv : to;
1224 
1225     return to!string(x);
1226 }
1227 
1228 alias DUK_MACRO_STRINGIFY = DUK_MACRO_STRINGIFY_HELPER;
1229 
1230 /* This can be used for testing; valgrind will then indicate the C call stack
1231  * leading to the call site.
1232  */
1233 
1234 /* Macro for suppressing warnings for potentially unreferenced variables.
1235  * The variables can be actually unreferenced or unreferenced in some
1236  * specific cases only; for instance, if a variable is only debug printed,
1237  * it is unreferenced when debug printing is disabled.  May cause warnings
1238  * for volatile arguments.
1239  */
1240 
1241 /* Fillin for DUK_NORETURN; DUK_WO_NORETURN() is used to insert dummy
1242  * dummy statements after noreturn calls to silence harmless compiler
1243  * warnings, e.g.:
1244  *
1245  *   DUK_ERROR_TYPE(thr, "aiee");
1246  *   DUK_WO_NORETURN(return 0;);
1247  *
1248  * Statements inside DUK_WO_NORETURN() must NEVER be actually reachable,
1249  * and they're only included to satisfy the compiler.
1250  */
1251 
1252 /* Don't know how to declare unreachable point, so don't do it; this
1253  * may cause some spurious compilation warnings (e.g. "variable used
1254  * uninitialized").
1255  */
1256 
1257 /* Convert any input pointer into a "void *", losing a const qualifier.
1258  * This is not fully portable because casting through duk_uintptr_t may
1259  * not work on all architectures (e.g. those with long, segmented pointers).
1260  */
1261 extern (D) auto DUK_LOSE_CONST(T)(auto ref T src)
1262 {
1263     return cast(void*) cast(duk_uintptr_t) src;
1264 }
1265 
1266 /*nop*/
1267 
1268 /*nop*/
1269 
1270 /*nop*/ /*nop*/ /*nop*/
1271 
1272 /*empty*/
1273 
1274 /*empty*/
1275 
1276 enum DUK_FILE_MACRO = __FILE__;
1277 
1278 enum DUK_LINE_MACRO = __LINE__;
1279 
1280 extern (D) auto DUK_BSWAP32(T)(auto ref T x)
1281 {
1282     return ((cast(duk_uint32_t) x) >> 24) | (((cast(duk_uint32_t) x) >> 8) & 0xff00UL) | (((cast(duk_uint32_t) x) << 8) & 0xff0000UL) | ((cast(duk_uint32_t) x) << 24);
1283 }
1284 
1285 extern (D) auto DUK_BSWAP16(T)(auto ref T x)
1286 {
1287     return (cast(duk_uint16_t) x >> 8) | (cast(duk_uint16_t) x << 8);
1288 }
1289 
1290 /* DUK_USE_VARIADIC_MACROS: required from compilers, so no fill-in. */
1291 /* DUK_USE_UNION_INITIALIZERS: required from compilers, so no fill-in. */
1292 
1293 /* Not standard but common enough */
1294 
1295 /* not defined by default */
1296 
1297 extern (D) string DUK_U64_CONSTANT(T)(auto ref T x)
1298 {
1299     import std.conv : to;
1300 
1301     return to!string(x) ~ "ULL";
1302 }
1303 
1304 extern (D) string DUK_I64_CONSTANT(T)(auto ref T x)
1305 {
1306     import std.conv : to;
1307 
1308     return to!string(x) ~ "LL";
1309 }
1310 
1311 /* Workaround for GH-323: avoid inlining control when compiling from
1312  * multiple sources, as it causes compiler portability trouble.
1313  */ /*nop*/ /*nop*/ /*nop*/
1314 
1315 /*
1316  *  Check whether or not a packed duk_tval representation is possible.
1317  *  What's basically required is that pointers are 32-bit values
1318  *  (sizeof(void *) == 4).  Best effort check, not always accurate.
1319  *  If guess goes wrong, crashes may result; self tests also verify
1320  *  the guess.
1321  */
1322 
1323 /* Explicit marker needed; may be 'defined', 'undefined, 'or 'not provided'. */
1324 
1325 /* Strict C99 case: DUK_UINTPTR_MAX (= UINTPTR_MAX) should be very reliable */
1326 
1327 /* Non-C99 case, still relying on DUK_UINTPTR_MAX, as long as it is not a computed value */
1328 
1329 /* DUK_SIZE_MAX (= SIZE_MAX) is often reliable */
1330 
1331 /* DUK_F_PACKED_TVAL_PROVIDED */
1332 /* Object property allocation layout has implications for memory and code
1333  * footprint and generated code size/speed.  The best layout also depends
1334  * on whether the platform has alignment requirements or benefits from
1335  * having mostly aligned accesses.
1336  */
1337 
1338 /* On platforms without any alignment issues, layout 1 is preferable
1339  * because it compiles to slightly less code and provides direct access
1340  * to property keys.
1341  */
1342 
1343 /* On other platforms use layout 2, which requires some padding but
1344  * is a bit more natural than layout 3 in ordering the entries.  Layout
1345  * 3 is currently not used.
1346  */
1347 
1348 /* GCC/clang inaccurate math would break compliance and probably duk_tval,
1349  * so refuse to compile.  Relax this if -ffast-math is tested to work.
1350  */
1351 
1352 /*
1353  *  Autogenerated defaults
1354  */
1355 
1356 enum DUK_USE_CALLSTACK_LIMIT = 10000;
1357 enum DUK_USE_COMPILER_RECLIMIT = 2500;
1358 
1359 enum DUK_USE_DEBUG_BUFSIZE = 65536L;
1360 enum DUK_USE_DEBUG_LEVEL = 0;
1361 
1362 enum DUK_USE_ESBC_MAX_BYTES = 2147418112L;
1363 enum DUK_USE_ESBC_MAX_LINENUMBER = 2147418112L;
1364 
1365 enum DUK_USE_FATAL_MAXLEN = 128;
1366 
1367 enum DUK_USE_HOBJECT_ARRAY_ABANDON_LIMIT = 2;
1368 enum DUK_USE_HOBJECT_ARRAY_FAST_RESIZE_LIMIT = 9;
1369 enum DUK_USE_HOBJECT_ARRAY_MINGROW_ADD = 16;
1370 enum DUK_USE_HOBJECT_ARRAY_MINGROW_DIVISOR = 8;
1371 enum DUK_USE_HOBJECT_ENTRY_MINGROW_ADD = 16;
1372 enum DUK_USE_HOBJECT_ENTRY_MINGROW_DIVISOR = 8;
1373 enum DUK_USE_HOBJECT_HASH_PROP_LIMIT = 8;
1374 
1375 enum DUK_USE_JSON_DEC_RECLIMIT = 1000;
1376 enum DUK_USE_JSON_ENC_RECLIMIT = 1000;
1377 
1378 enum DUK_USE_LITCACHE_SIZE = 256;
1379 enum DUK_USE_MARK_AND_SWEEP_RECLIMIT = 256;
1380 enum DUK_USE_NATIVE_CALL_RECLIMIT = 1000;
1381 
1382 enum DUK_USE_REGEXP_COMPILER_RECLIMIT = 10000;
1383 enum DUK_USE_REGEXP_EXECUTOR_RECLIMIT = 10000;
1384 
1385 enum DUK_USE_ROM_PTRCOMP_FIRST = 63488L;
1386 
1387 enum DUK_USE_STRHASH_SKIP_SHIFT = 5;
1388 
1389 enum DUK_USE_STRTAB_GROW_LIMIT = 17;
1390 enum DUK_USE_STRTAB_MAXSIZE = 268435456L;
1391 enum DUK_USE_STRTAB_MINSIZE = 1024;
1392 
1393 enum DUK_USE_STRTAB_RESIZE_CHECK_MASK = 255;
1394 enum DUK_USE_STRTAB_SHRINK_LIMIT = 6;
1395 
1396 enum DUK_USE_TARGET_INFO = "unknown";
1397 enum DUK_USE_TRACEBACK_DEPTH = 10; /* no user declarations */
1398 enum DUK_USE_VALSTACK_GROW_SHIFT = 2;
1399 enum DUK_USE_VALSTACK_LIMIT = 1000000L;
1400 enum DUK_USE_VALSTACK_SHRINK_CHECK_SHIFT = 2;
1401 enum DUK_USE_VALSTACK_SHRINK_SLACK_SHIFT = 4;
1402 
1403 /*
1404  *  You may add overriding #define/#undef directives below for
1405  *  customization.  You of course cannot un-#include or un-typedef
1406  *  anything; these require direct changes above.
1407  */
1408 
1409 /* __OVERRIDE_DEFINES__ */
1410 
1411 /*
1412  *  Conditional includes
1413  */
1414 
1415 /* std::exception */
1416 /* std::runtime_error */
1417 
1418 /*
1419  *  Date provider selection
1420  *
1421  *  User may define DUK_USE_DATE_GET_NOW() etc directly, in which case we'll
1422  *  rely on an external provider.  If this is not done, revert to previous
1423  *  behavior and use Unix/Windows built-in provider.
1424  */
1425 
1426 /* External provider already defined. */
1427 
1428 /* External provider already defined. */
1429 
1430 /* External provider already defined. */
1431 
1432 /* No provider for DUK_USE_DATE_PARSE_STRING(), fall back to ISO 8601 only. */
1433 
1434 /* External provider already defined. */
1435 
1436 /* No provider for DUK_USE_DATE_FORMAT_STRING(), fall back to ISO 8601 only. */
1437 
1438 /* External provider already defined. */
1439 
1440 /* No provider for DUK_USE_GET_MONOTONIC_TIME(), fall back to DUK_USE_DATE_GET_NOW(). */
1441 
1442 /* DUK_COMPILING_DUKTAPE */
1443 
1444 /*
1445  *  Checks for legacy feature options (DUK_OPT_xxx)
1446  */
1447 
1448 /*
1449  *  Checks for config option consistency (DUK_USE_xxx)
1450  */
1451 
1452 /*
1453  *  Convert DUK_USE_BYTEORDER, from whatever source, into currently used
1454  *  internal defines.  If detection failed, #error out.
1455  */
1456 
1457 /* integer endianness is little on purpose */
1458 
1459 /* byte order */
1460 
1461 /* defined(DUK_USE_BYTEORDER) */
1462 
1463 /* DUK_CONFIG_H_INCLUDED */