1/* A few types are assumed to always exist. */ 2typedef size_t duk_size_t; 3typedef ptrdiff_t duk_ptrdiff_t; 4 5/* The best type for an "all around int" in Duktape internals is "at least 6 * 32 bit signed integer" which is most convenient. Same for unsigned type. 7 * Prefer 'int' when large enough, as it is almost always a convenient type. 8 */ 9#if defined(UINT_MAX) && (UINT_MAX >= 0xffffffffUL) 10typedef int duk_int_t; 11typedef unsigned int duk_uint_t; 12#define DUK_INT_MIN INT_MIN 13#define DUK_INT_MAX INT_MAX 14#define DUK_UINT_MIN 0 15#define DUK_UINT_MAX UINT_MAX 16#else 17typedef duk_int_fast32_t duk_int_t; 18typedef duk_uint_fast32_t duk_uint_t; 19#define DUK_INT_MIN DUK_INT_FAST32_MIN 20#define DUK_INT_MAX DUK_INT_FAST32_MAX 21#define DUK_UINT_MIN DUK_UINT_FAST32_MIN 22#define DUK_UINT_MAX DUK_UINT_FAST32_MAX 23#endif 24 25/* Same as 'duk_int_t' but guaranteed to be a 'fast' variant if this 26 * distinction matters for the CPU. These types are used mainly in the 27 * executor where it might really matter. 28 */ 29typedef duk_int_fast32_t duk_int_fast_t; 30typedef duk_uint_fast32_t duk_uint_fast_t; 31#define DUK_INT_FAST_MIN DUK_INT_FAST32_MIN 32#define DUK_INT_FAST_MAX DUK_INT_FAST32_MAX 33#define DUK_UINT_FAST_MIN DUK_UINT_FAST32_MIN 34#define DUK_UINT_FAST_MAX DUK_UINT_FAST32_MAX 35 36/* Small integers (16 bits or more) can fall back to the 'int' type, but 37 * have a typedef so they are marked "small" explicitly. 38 */ 39typedef int duk_small_int_t; 40typedef unsigned int duk_small_uint_t; 41#define DUK_SMALL_INT_MIN INT_MIN 42#define DUK_SMALL_INT_MAX INT_MAX 43#define DUK_SMALL_UINT_MIN 0 44#define DUK_SMALL_UINT_MAX UINT_MAX 45 46/* Fast variants of small integers, again for really fast paths like the 47 * executor. 48 */ 49typedef duk_int_fast16_t duk_small_int_fast_t; 50typedef duk_uint_fast16_t duk_small_uint_fast_t; 51#define DUK_SMALL_INT_FAST_MIN DUK_INT_FAST16_MIN 52#define DUK_SMALL_INT_FAST_MAX DUK_INT_FAST16_MAX 53#define DUK_SMALL_UINT_FAST_MIN DUK_UINT_FAST16_MIN 54#define DUK_SMALL_UINT_FAST_MAX DUK_UINT_FAST16_MAX 55 56/* Boolean values are represented with the platform 'unsigned int'. */ 57typedef duk_small_uint_t duk_bool_t; 58#define DUK_BOOL_MIN DUK_SMALL_UINT_MIN 59#define DUK_BOOL_MAX DUK_SMALL_UINT_MAX 60 61/* Index values must have at least 32-bit signed range. */ 62typedef duk_int_t duk_idx_t; 63#define DUK_IDX_MIN DUK_INT_MIN 64#define DUK_IDX_MAX DUK_INT_MAX 65 66/* Unsigned index variant. */ 67typedef duk_uint_t duk_uidx_t; 68#define DUK_UIDX_MIN DUK_UINT_MIN 69#define DUK_UIDX_MAX DUK_UINT_MAX 70 71/* Array index values, could be exact 32 bits. 72 * Currently no need for signed duk_arridx_t. 73 */ 74typedef duk_uint_t duk_uarridx_t; 75#define DUK_UARRIDX_MIN DUK_UINT_MIN 76#define DUK_UARRIDX_MAX DUK_UINT_MAX 77 78/* Duktape/C function return value, platform int is enough for now to 79 * represent 0, 1, or negative error code. Must be compatible with 80 * assigning truth values (e.g. duk_ret_t rc = (foo == bar);). 81 */ 82typedef duk_small_int_t duk_ret_t; 83#define DUK_RET_MIN DUK_SMALL_INT_MIN 84#define DUK_RET_MAX DUK_SMALL_INT_MAX 85 86/* Error codes are represented with platform int. High bits are used 87 * for flags and such, so 32 bits are needed. 88 */ 89typedef duk_int_t duk_errcode_t; 90#define DUK_ERRCODE_MIN DUK_INT_MIN 91#define DUK_ERRCODE_MAX DUK_INT_MAX 92 93/* Codepoint type. Must be 32 bits or more because it is used also for 94 * internal codepoints. The type is signed because negative codepoints 95 * are used as internal markers (e.g. to mark EOF or missing argument). 96 * (X)UTF-8/CESU-8 encode/decode take and return an unsigned variant to 97 * ensure duk_uint32_t casts back and forth nicely. Almost everything 98 * else uses the signed one. 99 */ 100typedef duk_int_t duk_codepoint_t; 101typedef duk_uint_t duk_ucodepoint_t; 102#define DUK_CODEPOINT_MIN DUK_INT_MIN 103#define DUK_CODEPOINT_MAX DUK_INT_MAX 104#define DUK_UCODEPOINT_MIN DUK_UINT_MIN 105#define DUK_UCODEPOINT_MAX DUK_UINT_MAX 106 107/* IEEE float/double typedef. */ 108typedef float duk_float_t; 109typedef double duk_double_t; 110 111/* We're generally assuming that we're working on a platform with a 32-bit 112 * address space. If DUK_SIZE_MAX is a typecast value (which is necessary 113 * if SIZE_MAX is missing), the check must be avoided because the 114 * preprocessor can't do a comparison. 115 */ 116#if !defined(DUK_SIZE_MAX) 117#error DUK_SIZE_MAX is undefined, probably missing SIZE_MAX 118#elif !defined(DUK_SIZE_MAX_COMPUTED) 119#if DUK_SIZE_MAX < 0xffffffffUL 120/* On some systems SIZE_MAX can be smaller than max unsigned 32-bit value 121 * which seems incorrect if size_t is (at least) an unsigned 32-bit type. 122 * However, it doesn't seem useful to error out compilation if this is the 123 * case. 124 */ 125#endif 126#endif 127 128/* Type used in public API declarations and user code. Typedef maps to 129 * 'struct duk_hthread' like the 'duk_hthread' typedef which is used 130 * exclusively in internals. 131 */ 132typedef struct duk_hthread duk_context; 133