mirror of https://github.com/svaarala/duktape.git
Sami Vaarala
8 years ago
1 changed files with 0 additions and 541 deletions
@ -1,541 +0,0 @@ |
|||||
/*
|
|
||||
* Wrapper typedefs and constants for integer types, also sanity check types. |
|
||||
* |
|
||||
* C99 typedefs are quite good but not always available, and we want to avoid |
|
||||
* forcibly redefining the C99 typedefs. So, there are Duktape wrappers for |
|
||||
* all C99 typedefs and Duktape code should only use these typedefs. Type |
|
||||
* detection when C99 is not supported is best effort and may end up detecting |
|
||||
* some types incorrectly. |
|
||||
* |
|
||||
* Pointer sizes are a portability problem: pointers to different types may |
|
||||
* have a different size and function pointers are very difficult to manage |
|
||||
* portably. |
|
||||
* |
|
||||
* http://en.wikipedia.org/wiki/C_data_types#Fixed-width_integer_types
|
|
||||
* |
|
||||
* Note: there's an interesting corner case when trying to define minimum |
|
||||
* signed integer value constants which leads to the current workaround of |
|
||||
* defining e.g. -0x80000000 as (-0x7fffffffL - 1L). See doc/code-issues.txt |
|
||||
* for a longer discussion. |
|
||||
* |
|
||||
* Note: avoid typecasts and computations in macro integer constants as they |
|
||||
* can then no longer be used in macro relational expressions (such as |
|
||||
* #if DUK_SIZE_MAX < 0xffffffffUL). There is internal code which relies on |
|
||||
* being able to compare DUK_SIZE_MAX against a limit. |
|
||||
*/ |
|
||||
|
|
||||
/* XXX: add feature options to force basic types from outside? */ |
|
||||
|
|
||||
#if !defined(INT_MAX) |
|
||||
#error INT_MAX not defined |
|
||||
#endif |
|
||||
|
|
||||
/* Check that architecture is two's complement, standard C allows e.g.
|
|
||||
* INT_MIN to be -2**31+1 (instead of -2**31). |
|
||||
*/ |
|
||||
#if defined(INT_MAX) && defined(INT_MIN) |
|
||||
#if INT_MAX != -(INT_MIN + 1) |
|
||||
#error platform does not seem complement of two |
|
||||
#endif |
|
||||
#else |
|
||||
#error cannot check complement of two |
|
||||
#endif |
|
||||
|
|
||||
/* Pointer size determination based on architecture.
|
|
||||
* XXX: unsure about BCC correctness. |
|
||||
*/ |
|
||||
#if defined(DUK_F_X86) || defined(DUK_F_X32) || \ |
|
||||
defined(DUK_F_BCC) || \ |
|
||||
(defined(__WORDSIZE) && (__WORDSIZE == 32)) |
|
||||
#define DUK_F_32BIT_PTRS |
|
||||
#elif defined(DUK_F_X64) || \ |
|
||||
(defined(__WORDSIZE) && (__WORDSIZE == 64)) |
|
||||
#define DUK_F_64BIT_PTRS |
|
||||
#else |
|
||||
/* not sure, not needed with C99 anyway */ |
|
||||
#endif |
|
||||
|
|
||||
/* Intermediate define for 'have inttypes.h' */ |
|
||||
#undef DUK_F_HAVE_INTTYPES |
|
||||
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \ |
|
||||
!(defined(DUK_F_AMIGAOS) && defined(DUK_F_VBCC)) |
|
||||
/* vbcc + AmigaOS has C99 but no inttypes.h */ |
|
||||
#define DUK_F_HAVE_INTTYPES |
|
||||
#elif defined(__cplusplus) && (__cplusplus >= 201103L) |
|
||||
/* C++11 apparently ratified stdint.h */ |
|
||||
#define DUK_F_HAVE_INTTYPES |
|
||||
#endif |
|
||||
|
|
||||
/* Basic integer typedefs and limits, preferably from inttypes.h, otherwise
|
|
||||
* through automatic detection. |
|
||||
*/ |
|
||||
#if defined(DUK_F_HAVE_INTTYPES) |
|
||||
/* C99 or compatible */ |
|
||||
|
|
||||
#define DUK_F_HAVE_64BIT |
|
||||
#include <inttypes.h> |
|
||||
|
|
||||
typedef uint8_t duk_uint8_t; |
|
||||
typedef int8_t duk_int8_t; |
|
||||
typedef uint16_t duk_uint16_t; |
|
||||
typedef int16_t duk_int16_t; |
|
||||
typedef uint32_t duk_uint32_t; |
|
||||
typedef int32_t duk_int32_t; |
|
||||
typedef uint64_t duk_uint64_t; |
|
||||
typedef int64_t duk_int64_t; |
|
||||
typedef uint_least8_t duk_uint_least8_t; |
|
||||
typedef int_least8_t duk_int_least8_t; |
|
||||
typedef uint_least16_t duk_uint_least16_t; |
|
||||
typedef int_least16_t duk_int_least16_t; |
|
||||
typedef uint_least32_t duk_uint_least32_t; |
|
||||
typedef int_least32_t duk_int_least32_t; |
|
||||
typedef uint_least64_t duk_uint_least64_t; |
|
||||
typedef int_least64_t duk_int_least64_t; |
|
||||
typedef uint_fast8_t duk_uint_fast8_t; |
|
||||
typedef int_fast8_t duk_int_fast8_t; |
|
||||
typedef uint_fast16_t duk_uint_fast16_t; |
|
||||
typedef int_fast16_t duk_int_fast16_t; |
|
||||
typedef uint_fast32_t duk_uint_fast32_t; |
|
||||
typedef int_fast32_t duk_int_fast32_t; |
|
||||
typedef uint_fast64_t duk_uint_fast64_t; |
|
||||
typedef int_fast64_t duk_int_fast64_t; |
|
||||
typedef uintptr_t duk_uintptr_t; |
|
||||
typedef intptr_t duk_intptr_t; |
|
||||
typedef uintmax_t duk_uintmax_t; |
|
||||
typedef intmax_t duk_intmax_t; |
|
||||
|
|
||||
#define DUK_UINT8_MIN 0 |
|
||||
#define DUK_UINT8_MAX UINT8_MAX |
|
||||
#define DUK_INT8_MIN INT8_MIN |
|
||||
#define DUK_INT8_MAX INT8_MAX |
|
||||
#define DUK_UINT_LEAST8_MIN 0 |
|
||||
#define DUK_UINT_LEAST8_MAX UINT_LEAST8_MAX |
|
||||
#define DUK_INT_LEAST8_MIN INT_LEAST8_MIN |
|
||||
#define DUK_INT_LEAST8_MAX INT_LEAST8_MAX |
|
||||
#define DUK_UINT_FAST8_MIN 0 |
|
||||
#define DUK_UINT_FAST8_MAX UINT_FAST8_MAX |
|
||||
#define DUK_INT_FAST8_MIN INT_FAST8_MIN |
|
||||
#define DUK_INT_FAST8_MAX INT_FAST8_MAX |
|
||||
#define DUK_UINT16_MIN 0 |
|
||||
#define DUK_UINT16_MAX UINT16_MAX |
|
||||
#define DUK_INT16_MIN INT16_MIN |
|
||||
#define DUK_INT16_MAX INT16_MAX |
|
||||
#define DUK_UINT_LEAST16_MIN 0 |
|
||||
#define DUK_UINT_LEAST16_MAX UINT_LEAST16_MAX |
|
||||
#define DUK_INT_LEAST16_MIN INT_LEAST16_MIN |
|
||||
#define DUK_INT_LEAST16_MAX INT_LEAST16_MAX |
|
||||
#define DUK_UINT_FAST16_MIN 0 |
|
||||
#define DUK_UINT_FAST16_MAX UINT_FAST16_MAX |
|
||||
#define DUK_INT_FAST16_MIN INT_FAST16_MIN |
|
||||
#define DUK_INT_FAST16_MAX INT_FAST16_MAX |
|
||||
#define DUK_UINT32_MIN 0 |
|
||||
#define DUK_UINT32_MAX UINT32_MAX |
|
||||
#define DUK_INT32_MIN INT32_MIN |
|
||||
#define DUK_INT32_MAX INT32_MAX |
|
||||
#define DUK_UINT_LEAST32_MIN 0 |
|
||||
#define DUK_UINT_LEAST32_MAX UINT_LEAST32_MAX |
|
||||
#define DUK_INT_LEAST32_MIN INT_LEAST32_MIN |
|
||||
#define DUK_INT_LEAST32_MAX INT_LEAST32_MAX |
|
||||
#define DUK_UINT_FAST32_MIN 0 |
|
||||
#define DUK_UINT_FAST32_MAX UINT_FAST32_MAX |
|
||||
#define DUK_INT_FAST32_MIN INT_FAST32_MIN |
|
||||
#define DUK_INT_FAST32_MAX INT_FAST32_MAX |
|
||||
#define DUK_UINT64_MIN 0 |
|
||||
#define DUK_UINT64_MAX UINT64_MAX |
|
||||
#define DUK_INT64_MIN INT64_MIN |
|
||||
#define DUK_INT64_MAX INT64_MAX |
|
||||
#define DUK_UINT_LEAST64_MIN 0 |
|
||||
#define DUK_UINT_LEAST64_MAX UINT_LEAST64_MAX |
|
||||
#define DUK_INT_LEAST64_MIN INT_LEAST64_MIN |
|
||||
#define DUK_INT_LEAST64_MAX INT_LEAST64_MAX |
|
||||
#define DUK_UINT_FAST64_MIN 0 |
|
||||
#define DUK_UINT_FAST64_MAX UINT_FAST64_MAX |
|
||||
#define DUK_INT_FAST64_MIN INT_FAST64_MIN |
|
||||
#define DUK_INT_FAST64_MAX INT_FAST64_MAX |
|
||||
|
|
||||
#define DUK_UINTPTR_MIN 0 |
|
||||
#define DUK_UINTPTR_MAX UINTPTR_MAX |
|
||||
#define DUK_INTPTR_MIN INTPTR_MIN |
|
||||
#define DUK_INTPTR_MAX INTPTR_MAX |
|
||||
|
|
||||
#define DUK_UINTMAX_MIN 0 |
|
||||
#define DUK_UINTMAX_MAX UINTMAX_MAX |
|
||||
#define DUK_INTMAX_MIN INTMAX_MIN |
|
||||
#define DUK_INTMAX_MAX INTMAX_MAX |
|
||||
|
|
||||
#define DUK_SIZE_MIN 0 |
|
||||
#define DUK_SIZE_MAX SIZE_MAX |
|
||||
|
|
||||
#else /* C99 types */ |
|
||||
|
|
||||
/* When C99 types are not available, we use heuristic detection to get
|
|
||||
* the basic 8, 16, 32, and (possibly) 64 bit types. The fast/least |
|
||||
* types are then assumed to be exactly the same for now: these could |
|
||||
* be improved per platform but C99 types are very often now available. |
|
||||
* 64-bit types are not available on all platforms; this is OK at least |
|
||||
* on 32-bit platforms. |
|
||||
* |
|
||||
* This detection code is necessarily a bit hacky and can provide typedefs |
|
||||
* and defines that won't work correctly on some exotic platform. |
|
||||
*/ |
|
||||
|
|
||||
#if (defined(CHAR_BIT) && (CHAR_BIT == 8)) || \ |
|
||||
(defined(UCHAR_MAX) && (UCHAR_MAX == 255)) |
|
||||
typedef unsigned char duk_uint8_t; |
|
||||
typedef signed char duk_int8_t; |
|
||||
#else |
|
||||
#error cannot detect 8-bit type |
|
||||
#endif |
|
||||
|
|
||||
#if defined(USHRT_MAX) && (USHRT_MAX == 65535UL) |
|
||||
typedef unsigned short duk_uint16_t; |
|
||||
typedef signed short duk_int16_t; |
|
||||
#elif defined(UINT_MAX) && (UINT_MAX == 65535UL) |
|
||||
/* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */ |
|
||||
typedef unsigned int duk_uint16_t; |
|
||||
typedef signed int duk_int16_t; |
|
||||
#else |
|
||||
#error cannot detect 16-bit type |
|
||||
#endif |
|
||||
|
|
||||
#if defined(UINT_MAX) && (UINT_MAX == 4294967295UL) |
|
||||
typedef unsigned int duk_uint32_t; |
|
||||
typedef signed int duk_int32_t; |
|
||||
#elif defined(ULONG_MAX) && (ULONG_MAX == 4294967295UL) |
|
||||
/* On some platforms int is 16-bit but long is 32-bit (e.g. PureC) */ |
|
||||
typedef unsigned long duk_uint32_t; |
|
||||
typedef signed long duk_int32_t; |
|
||||
#else |
|
||||
#error cannot detect 32-bit type |
|
||||
#endif |
|
||||
|
|
||||
/* 64-bit type detection is a bit tricky.
|
|
||||
* |
|
||||
* ULLONG_MAX is a standard define. __LONG_LONG_MAX__ and __ULONG_LONG_MAX__ |
|
||||
* are used by at least GCC (even if system headers don't provide ULLONG_MAX). |
|
||||
* Some GCC variants may provide __LONG_LONG_MAX__ but not __ULONG_LONG_MAX__. |
|
||||
* |
|
||||
* ULL / LL constants are rejected / warned about by some compilers, even if |
|
||||
* the compiler has a 64-bit type and the compiler/system headers provide an |
|
||||
* unsupported constant (ULL/LL)! Try to avoid using ULL / LL constants. |
|
||||
* As a side effect we can only check that e.g. ULONG_MAX is larger than 32 |
|
||||
* bits but can't be sure it is exactly 64 bits. Self tests will catch such |
|
||||
* cases. |
|
||||
*/ |
|
||||
#undef DUK_F_HAVE_64BIT |
|
||||
#if !defined(DUK_F_HAVE_64BIT) && defined(ULONG_MAX) |
|
||||
#if (ULONG_MAX > 4294967295UL) |
|
||||
#define DUK_F_HAVE_64BIT |
|
||||
typedef unsigned long duk_uint64_t; |
|
||||
typedef signed long duk_int64_t; |
|
||||
#endif |
|
||||
#endif |
|
||||
#if !defined(DUK_F_HAVE_64BIT) && defined(ULLONG_MAX) |
|
||||
#if (ULLONG_MAX > 4294967295UL) |
|
||||
#define DUK_F_HAVE_64BIT |
|
||||
typedef unsigned long long duk_uint64_t; |
|
||||
typedef signed long long duk_int64_t; |
|
||||
#endif |
|
||||
#endif |
|
||||
#if !defined(DUK_F_HAVE_64BIT) && defined(__ULONG_LONG_MAX__) |
|
||||
#if (__ULONG_LONG_MAX__ > 4294967295UL) |
|
||||
#define DUK_F_HAVE_64BIT |
|
||||
typedef unsigned long long duk_uint64_t; |
|
||||
typedef signed long long duk_int64_t; |
|
||||
#endif |
|
||||
#endif |
|
||||
#if !defined(DUK_F_HAVE_64BIT) && defined(__LONG_LONG_MAX__) |
|
||||
#if (__LONG_LONG_MAX__ > 2147483647L) |
|
||||
#define DUK_F_HAVE_64BIT |
|
||||
typedef unsigned long long duk_uint64_t; |
|
||||
typedef signed long long duk_int64_t; |
|
||||
#endif |
|
||||
#endif |
|
||||
#if !defined(DUK_F_HAVE_64BIT) && \ |
|
||||
(defined(DUK_F_MINGW) || defined(DUK_F_MSVC)) |
|
||||
/* Both MinGW and MSVC have a 64-bit type. */ |
|
||||
#define DUK_F_HAVE_64BIT |
|
||||
typedef unsigned long duk_uint64_t; |
|
||||
typedef signed long duk_int64_t; |
|
||||
#endif |
|
||||
#if !defined(DUK_F_HAVE_64BIT) |
|
||||
/* cannot detect 64-bit type, not always needed so don't error */ |
|
||||
#endif |
|
||||
|
|
||||
typedef duk_uint8_t duk_uint_least8_t; |
|
||||
typedef duk_int8_t duk_int_least8_t; |
|
||||
typedef duk_uint16_t duk_uint_least16_t; |
|
||||
typedef duk_int16_t duk_int_least16_t; |
|
||||
typedef duk_uint32_t duk_uint_least32_t; |
|
||||
typedef duk_int32_t duk_int_least32_t; |
|
||||
typedef duk_uint8_t duk_uint_fast8_t; |
|
||||
typedef duk_int8_t duk_int_fast8_t; |
|
||||
typedef duk_uint16_t duk_uint_fast16_t; |
|
||||
typedef duk_int16_t duk_int_fast16_t; |
|
||||
typedef duk_uint32_t duk_uint_fast32_t; |
|
||||
typedef duk_int32_t duk_int_fast32_t; |
|
||||
#if defined(DUK_F_HAVE_64BIT) |
|
||||
typedef duk_uint64_t duk_uint_least64_t; |
|
||||
typedef duk_int64_t duk_int_least64_t; |
|
||||
typedef duk_uint64_t duk_uint_fast64_t; |
|
||||
typedef duk_int64_t duk_int_fast64_t; |
|
||||
#endif |
|
||||
#if defined(DUK_F_HAVE_64BIT) |
|
||||
typedef duk_uint64_t duk_uintmax_t; |
|
||||
typedef duk_int64_t duk_intmax_t; |
|
||||
#else |
|
||||
typedef duk_uint32_t duk_uintmax_t; |
|
||||
typedef duk_int32_t duk_intmax_t; |
|
||||
#endif |
|
||||
|
|
||||
/* Note: the funny looking computations for signed minimum 16-bit, 32-bit, and
|
|
||||
* 64-bit values are intentional as the obvious forms (e.g. -0x80000000L) are |
|
||||
* -not- portable. See code-issues.txt for a detailed discussion. |
|
||||
*/ |
|
||||
#define DUK_UINT8_MIN 0UL |
|
||||
#define DUK_UINT8_MAX 0xffUL |
|
||||
#define DUK_INT8_MIN (-0x80L) |
|
||||
#define DUK_INT8_MAX 0x7fL |
|
||||
#define DUK_UINT_LEAST8_MIN 0UL |
|
||||
#define DUK_UINT_LEAST8_MAX 0xffUL |
|
||||
#define DUK_INT_LEAST8_MIN (-0x80L) |
|
||||
#define DUK_INT_LEAST8_MAX 0x7fL |
|
||||
#define DUK_UINT_FAST8_MIN 0UL |
|
||||
#define DUK_UINT_FAST8_MAX 0xffUL |
|
||||
#define DUK_INT_FAST8_MIN (-0x80L) |
|
||||
#define DUK_INT_FAST8_MAX 0x7fL |
|
||||
#define DUK_UINT16_MIN 0UL |
|
||||
#define DUK_UINT16_MAX 0xffffUL |
|
||||
#define DUK_INT16_MIN (-0x7fffL - 1L) |
|
||||
#define DUK_INT16_MAX 0x7fffL |
|
||||
#define DUK_UINT_LEAST16_MIN 0UL |
|
||||
#define DUK_UINT_LEAST16_MAX 0xffffUL |
|
||||
#define DUK_INT_LEAST16_MIN (-0x7fffL - 1L) |
|
||||
#define DUK_INT_LEAST16_MAX 0x7fffL |
|
||||
#define DUK_UINT_FAST16_MIN 0UL |
|
||||
#define DUK_UINT_FAST16_MAX 0xffffUL |
|
||||
#define DUK_INT_FAST16_MIN (-0x7fffL - 1L) |
|
||||
#define DUK_INT_FAST16_MAX 0x7fffL |
|
||||
#define DUK_UINT32_MIN 0UL |
|
||||
#define DUK_UINT32_MAX 0xffffffffUL |
|
||||
#define DUK_INT32_MIN (-0x7fffffffL - 1L) |
|
||||
#define DUK_INT32_MAX 0x7fffffffL |
|
||||
#define DUK_UINT_LEAST32_MIN 0UL |
|
||||
#define DUK_UINT_LEAST32_MAX 0xffffffffUL |
|
||||
#define DUK_INT_LEAST32_MIN (-0x7fffffffL - 1L) |
|
||||
#define DUK_INT_LEAST32_MAX 0x7fffffffL |
|
||||
#define DUK_UINT_FAST32_MIN 0UL |
|
||||
#define DUK_UINT_FAST32_MAX 0xffffffffUL |
|
||||
#define DUK_INT_FAST32_MIN (-0x7fffffffL - 1L) |
|
||||
#define DUK_INT_FAST32_MAX 0x7fffffffL |
|
||||
|
|
||||
/* 64-bit constants. Since LL / ULL constants are not always available,
|
|
||||
* use computed values. These values can't be used in preprocessor |
|
||||
* comparisons; flag them as such. |
|
||||
*/ |
|
||||
#if defined(DUK_F_HAVE_64BIT) |
|
||||
#define DUK_UINT64_MIN ((duk_uint64_t) 0) |
|
||||
#define DUK_UINT64_MAX ((duk_uint64_t) -1) |
|
||||
#define DUK_INT64_MIN ((duk_int64_t) (~(DUK_UINT64_MAX >> 1))) |
|
||||
#define DUK_INT64_MAX ((duk_int64_t) (DUK_UINT64_MAX >> 1)) |
|
||||
#define DUK_UINT_LEAST64_MIN DUK_UINT64_MIN |
|
||||
#define DUK_UINT_LEAST64_MAX DUK_UINT64_MAX |
|
||||
#define DUK_INT_LEAST64_MIN DUK_INT64_MIN |
|
||||
#define DUK_INT_LEAST64_MAX DUK_INT64_MAX |
|
||||
#define DUK_UINT_FAST64_MIN DUK_UINT64_MIN |
|
||||
#define DUK_UINT_FAST64_MAX DUK_UINT64_MAX |
|
||||
#define DUK_INT_FAST64_MIN DUK_INT64_MIN |
|
||||
#define DUK_INT_FAST64_MAX DUK_INT64_MAX |
|
||||
#define DUK_UINT64_MIN_COMPUTED |
|
||||
#define DUK_UINT64_MAX_COMPUTED |
|
||||
#define DUK_INT64_MIN_COMPUTED |
|
||||
#define DUK_INT64_MAX_COMPUTED |
|
||||
#define DUK_UINT_LEAST64_MIN_COMPUTED |
|
||||
#define DUK_UINT_LEAST64_MAX_COMPUTED |
|
||||
#define DUK_INT_LEAST64_MIN_COMPUTED |
|
||||
#define DUK_INT_LEAST64_MAX_COMPUTED |
|
||||
#define DUK_UINT_FAST64_MIN_COMPUTED |
|
||||
#define DUK_UINT_FAST64_MAX_COMPUTED |
|
||||
#define DUK_INT_FAST64_MIN_COMPUTED |
|
||||
#define DUK_INT_FAST64_MAX_COMPUTED |
|
||||
#endif |
|
||||
|
|
||||
#if defined(DUK_F_HAVE_64BIT) |
|
||||
#define DUK_UINTMAX_MIN DUK_UINT64_MIN |
|
||||
#define DUK_UINTMAX_MAX DUK_UINT64_MAX |
|
||||
#define DUK_INTMAX_MIN DUK_INT64_MIN |
|
||||
#define DUK_INTMAX_MAX DUK_INT64_MAX |
|
||||
#define DUK_UINTMAX_MIN_COMPUTED |
|
||||
#define DUK_UINTMAX_MAX_COMPUTED |
|
||||
#define DUK_INTMAX_MIN_COMPUTED |
|
||||
#define DUK_INTMAX_MAX_COMPUTED |
|
||||
#else |
|
||||
#define DUK_UINTMAX_MIN 0UL |
|
||||
#define DUK_UINTMAX_MAX 0xffffffffUL |
|
||||
#define DUK_INTMAX_MIN (-0x7fffffffL - 1L) |
|
||||
#define DUK_INTMAX_MAX 0x7fffffffL |
|
||||
#endif |
|
||||
|
|
||||
/* This detection is not very reliable. */ |
|
||||
#if defined(DUK_F_32BIT_PTRS) |
|
||||
typedef duk_int32_t duk_intptr_t; |
|
||||
typedef duk_uint32_t duk_uintptr_t; |
|
||||
#define DUK_UINTPTR_MIN DUK_UINT32_MIN |
|
||||
#define DUK_UINTPTR_MAX DUK_UINT32_MAX |
|
||||
#define DUK_INTPTR_MIN DUK_INT32_MIN |
|
||||
#define DUK_INTPTR_MAX DUK_INT32_MAX |
|
||||
#elif defined(DUK_F_64BIT_PTRS) && defined(DUK_F_HAVE_64BIT) |
|
||||
typedef duk_int64_t duk_intptr_t; |
|
||||
typedef duk_uint64_t duk_uintptr_t; |
|
||||
#define DUK_UINTPTR_MIN DUK_UINT64_MIN |
|
||||
#define DUK_UINTPTR_MAX DUK_UINT64_MAX |
|
||||
#define DUK_INTPTR_MIN DUK_INT64_MIN |
|
||||
#define DUK_INTPTR_MAX DUK_INT64_MAX |
|
||||
#define DUK_UINTPTR_MIN_COMPUTED |
|
||||
#define DUK_UINTPTR_MAX_COMPUTED |
|
||||
#define DUK_INTPTR_MIN_COMPUTED |
|
||||
#define DUK_INTPTR_MAX_COMPUTED |
|
||||
#else |
|
||||
#error cannot determine intptr type |
|
||||
#endif |
|
||||
|
|
||||
/* SIZE_MAX may be missing so use an approximate value for it. */ |
|
||||
#undef DUK_SIZE_MAX_COMPUTED |
|
||||
#if !defined(SIZE_MAX) |
|
||||
#define DUK_SIZE_MAX_COMPUTED |
|
||||
#define SIZE_MAX ((size_t) (-1)) |
|
||||
#endif |
|
||||
#define DUK_SIZE_MIN 0 |
|
||||
#define DUK_SIZE_MAX SIZE_MAX |
|
||||
|
|
||||
#endif /* C99 types */ |
|
||||
|
|
||||
/* A few types are assumed to always exist. */ |
|
||||
typedef size_t duk_size_t; |
|
||||
typedef ptrdiff_t duk_ptrdiff_t; |
|
||||
|
|
||||
/* The best type for an "all around int" in Duktape internals is "at least
|
|
||||
* 32 bit signed integer" which is most convenient. Same for unsigned type. |
|
||||
* Prefer 'int' when large enough, as it is almost always a convenient type. |
|
||||
*/ |
|
||||
#if defined(UINT_MAX) && (UINT_MAX >= 0xffffffffUL) |
|
||||
typedef int duk_int_t; |
|
||||
typedef unsigned int duk_uint_t; |
|
||||
#define DUK_INT_MIN INT_MIN |
|
||||
#define DUK_INT_MAX INT_MAX |
|
||||
#define DUK_UINT_MIN 0 |
|
||||
#define DUK_UINT_MAX UINT_MAX |
|
||||
#else |
|
||||
typedef duk_int_fast32_t duk_int_t; |
|
||||
typedef duk_uint_fast32_t duk_uint_t; |
|
||||
#define DUK_INT_MIN DUK_INT_FAST32_MIN |
|
||||
#define DUK_INT_MAX DUK_INT_FAST32_MAX |
|
||||
#define DUK_UINT_MIN DUK_UINT_FAST32_MIN |
|
||||
#define DUK_UINT_MAX DUK_UINT_FAST32_MAX |
|
||||
#endif |
|
||||
|
|
||||
/* Same as 'duk_int_t' but guaranteed to be a 'fast' variant if this
|
|
||||
* distinction matters for the CPU. These types are used mainly in the |
|
||||
* executor where it might really matter. |
|
||||
*/ |
|
||||
typedef duk_int_fast32_t duk_int_fast_t; |
|
||||
typedef duk_uint_fast32_t duk_uint_fast_t; |
|
||||
#define DUK_INT_FAST_MIN DUK_INT_FAST32_MIN |
|
||||
#define DUK_INT_FAST_MAX DUK_INT_FAST32_MAX |
|
||||
#define DUK_UINT_FAST_MIN DUK_UINT_FAST32_MIN |
|
||||
#define DUK_UINT_FAST_MAX DUK_UINT_FAST32_MAX |
|
||||
|
|
||||
/* Small integers (16 bits or more) can fall back to the 'int' type, but
|
|
||||
* have a typedef so they are marked "small" explicitly. |
|
||||
*/ |
|
||||
typedef int duk_small_int_t; |
|
||||
typedef unsigned int duk_small_uint_t; |
|
||||
#define DUK_SMALL_INT_MIN INT_MIN |
|
||||
#define DUK_SMALL_INT_MAX INT_MAX |
|
||||
#define DUK_SMALL_UINT_MIN 0 |
|
||||
#define DUK_SMALL_UINT_MAX UINT_MAX |
|
||||
|
|
||||
/* Fast variants of small integers, again for really fast paths like the
|
|
||||
* executor. |
|
||||
*/ |
|
||||
typedef duk_int_fast16_t duk_small_int_fast_t; |
|
||||
typedef duk_uint_fast16_t duk_small_uint_fast_t; |
|
||||
#define DUK_SMALL_INT_FAST_MIN DUK_INT_FAST16_MIN |
|
||||
#define DUK_SMALL_INT_FAST_MAX DUK_INT_FAST16_MAX |
|
||||
#define DUK_SMALL_UINT_FAST_MIN DUK_UINT_FAST16_MIN |
|
||||
#define DUK_SMALL_UINT_FAST_MAX DUK_UINT_FAST16_MAX |
|
||||
|
|
||||
/* Boolean values are represented with the platform 'int'. */ |
|
||||
typedef duk_small_int_t duk_bool_t; |
|
||||
#define DUK_BOOL_MIN DUK_SMALL_INT_MIN |
|
||||
#define DUK_BOOL_MAX DUK_SMALL_INT_MAX |
|
||||
|
|
||||
/* Index values must have at least 32-bit signed range. */ |
|
||||
typedef duk_int_t duk_idx_t; |
|
||||
#define DUK_IDX_MIN DUK_INT_MIN |
|
||||
#define DUK_IDX_MAX DUK_INT_MAX |
|
||||
|
|
||||
/* Unsigned index variant. */ |
|
||||
typedef duk_uint_t duk_uidx_t; |
|
||||
#define DUK_UIDX_MIN DUK_UINT_MIN |
|
||||
#define DUK_UIDX_MAX DUK_UINT_MAX |
|
||||
|
|
||||
/* Array index values, could be exact 32 bits.
|
|
||||
* Currently no need for signed duk_arridx_t. |
|
||||
*/ |
|
||||
typedef duk_uint_t duk_uarridx_t; |
|
||||
#define DUK_UARRIDX_MIN DUK_UINT_MIN |
|
||||
#define DUK_UARRIDX_MAX DUK_UINT_MAX |
|
||||
|
|
||||
/* Duktape/C function return value, platform int is enough for now to
|
|
||||
* represent 0, 1, or negative error code. Must be compatible with |
|
||||
* assigning truth values (e.g. duk_ret_t rc = (foo == bar);). |
|
||||
*/ |
|
||||
typedef duk_small_int_t duk_ret_t; |
|
||||
#define DUK_RET_MIN DUK_SMALL_INT_MIN |
|
||||
#define DUK_RET_MAX DUK_SMALL_INT_MAX |
|
||||
|
|
||||
/* Error codes are represented with platform int. High bits are used
|
|
||||
* for flags and such, so 32 bits are needed. |
|
||||
*/ |
|
||||
typedef duk_int_t duk_errcode_t; |
|
||||
#define DUK_ERRCODE_MIN DUK_INT_MIN |
|
||||
#define DUK_ERRCODE_MAX DUK_INT_MAX |
|
||||
|
|
||||
/* Codepoint type. Must be 32 bits or more because it is used also for
|
|
||||
* internal codepoints. The type is signed because negative codepoints |
|
||||
* are used as internal markers (e.g. to mark EOF or missing argument). |
|
||||
* (X)UTF-8/CESU-8 encode/decode take and return an unsigned variant to |
|
||||
* ensure duk_uint32_t casts back and forth nicely. Almost everything |
|
||||
* else uses the signed one. |
|
||||
*/ |
|
||||
typedef duk_int_t duk_codepoint_t; |
|
||||
typedef duk_uint_t duk_ucodepoint_t; |
|
||||
#define DUK_CODEPOINT_MIN DUK_INT_MIN |
|
||||
#define DUK_CODEPOINT_MAX DUK_INT_MAX |
|
||||
#define DUK_UCODEPOINT_MIN DUK_UINT_MIN |
|
||||
#define DUK_UCODEPOINT_MAX DUK_UINT_MAX |
|
||||
|
|
||||
/* IEEE float/double typedef. */ |
|
||||
typedef float duk_float_t; |
|
||||
typedef double duk_double_t; |
|
||||
|
|
||||
/* We're generally assuming that we're working on a platform with a 32-bit
|
|
||||
* address space. If DUK_SIZE_MAX is a typecast value (which is necessary |
|
||||
* if SIZE_MAX is missing), the check must be avoided because the |
|
||||
* preprocessor can't do a comparison. |
|
||||
*/ |
|
||||
#if !defined(DUK_SIZE_MAX) |
|
||||
#error DUK_SIZE_MAX is undefined, probably missing SIZE_MAX |
|
||||
#elif !defined(DUK_SIZE_MAX_COMPUTED) |
|
||||
#if DUK_SIZE_MAX < 0xffffffffUL |
|
||||
/* On some systems SIZE_MAX can be smaller than max unsigned 32-bit value
|
|
||||
* which seems incorrect if size_t is (at least) an unsigned 32-bit type. |
|
||||
* However, it doesn't seem useful to error out compilation if this is the |
|
||||
* case. |
|
||||
*/ |
|
||||
#endif |
|
||||
#endif |
|
||||
|
|
||||
/* Type for public API calls. */ |
|
||||
typedef struct duk_hthread duk_context; |
|
Loading…
Reference in new issue