diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lua/llimits.h (renamed from src/lua-5.3/llimits.h) | 108 |
1 files changed, 67 insertions, 41 deletions
diff --git a/src/lua-5.3/llimits.h b/src/lua/llimits.h index d1036f6..b86d345 100644 --- a/src/lua-5.3/llimits.h +++ b/src/lua/llimits.h | |||
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: llimits.h,v 1.141.1.1 2017/04/19 17:20:42 roberto Exp $ | 2 | ** $Id: llimits.h $ |
| 3 | ** Limits, basic types, and some other 'installation-dependent' definitions | 3 | ** Limits, basic types, and some other 'installation-dependent' definitions |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -14,6 +14,7 @@ | |||
| 14 | 14 | ||
| 15 | #include "lua.h" | 15 | #include "lua.h" |
| 16 | 16 | ||
| 17 | |||
| 17 | /* | 18 | /* |
| 18 | ** 'lu_mem' and 'l_mem' are unsigned/signed integers big enough to count | 19 | ** 'lu_mem' and 'l_mem' are unsigned/signed integers big enough to count |
| 19 | ** the total memory used by Lua (in bytes). Usually, 'size_t' and | 20 | ** the total memory used by Lua (in bytes). Usually, 'size_t' and |
| @@ -22,7 +23,7 @@ | |||
| 22 | #if defined(LUAI_MEM) /* { external definitions? */ | 23 | #if defined(LUAI_MEM) /* { external definitions? */ |
| 23 | typedef LUAI_UMEM lu_mem; | 24 | typedef LUAI_UMEM lu_mem; |
| 24 | typedef LUAI_MEM l_mem; | 25 | typedef LUAI_MEM l_mem; |
| 25 | #elif LUAI_BITSINT >= 32 /* }{ */ | 26 | #elif LUAI_IS32INT /* }{ */ |
| 26 | typedef size_t lu_mem; | 27 | typedef size_t lu_mem; |
| 27 | typedef ptrdiff_t l_mem; | 28 | typedef ptrdiff_t l_mem; |
| 28 | #else /* 16-bit ints */ /* }{ */ | 29 | #else /* 16-bit ints */ /* }{ */ |
| @@ -33,12 +34,13 @@ typedef long l_mem; | |||
| 33 | 34 | ||
| 34 | /* chars used as small naturals (so that 'char' is reserved for characters) */ | 35 | /* chars used as small naturals (so that 'char' is reserved for characters) */ |
| 35 | typedef unsigned char lu_byte; | 36 | typedef unsigned char lu_byte; |
| 37 | typedef signed char ls_byte; | ||
| 36 | 38 | ||
| 37 | 39 | ||
| 38 | /* maximum value for size_t */ | 40 | /* maximum value for size_t */ |
| 39 | #define MAX_SIZET ((size_t)(~(size_t)0)) | 41 | #define MAX_SIZET ((size_t)(~(size_t)0)) |
| 40 | 42 | ||
| 41 | /* maximum size visible for Lua (must be representable in a lua_Integer */ | 43 | /* maximum size visible for Lua (must be representable in a lua_Integer) */ |
| 42 | #define MAX_SIZE (sizeof(size_t) < sizeof(lua_Integer) ? MAX_SIZET \ | 44 | #define MAX_SIZE (sizeof(size_t) < sizeof(lua_Integer) ? MAX_SIZET \ |
| 43 | : (size_t)(LUA_MAXINTEGER)) | 45 | : (size_t)(LUA_MAXINTEGER)) |
| 44 | 46 | ||
| @@ -52,6 +54,23 @@ typedef unsigned char lu_byte; | |||
| 52 | 54 | ||
| 53 | 55 | ||
| 54 | /* | 56 | /* |
| 57 | ** floor of the log2 of the maximum signed value for integral type 't'. | ||
| 58 | ** (That is, maximum 'n' such that '2^n' fits in the given signed type.) | ||
| 59 | */ | ||
| 60 | #define log2maxs(t) (sizeof(t) * 8 - 2) | ||
| 61 | |||
| 62 | |||
| 63 | /* | ||
| 64 | ** test whether an unsigned value is a power of 2 (or zero) | ||
| 65 | */ | ||
| 66 | #define ispow2(x) (((x) & ((x) - 1)) == 0) | ||
| 67 | |||
| 68 | |||
| 69 | /* number of chars of a literal string without the ending \0 */ | ||
| 70 | #define LL(x) (sizeof(x)/sizeof(char) - 1) | ||
| 71 | |||
| 72 | |||
| 73 | /* | ||
| 55 | ** conversion of pointer to unsigned integer: | 74 | ** conversion of pointer to unsigned integer: |
| 56 | ** this is for hashing only; there is no problem if the integer | 75 | ** this is for hashing only; there is no problem if the integer |
| 57 | ** cannot hold the whole pointer value | 76 | ** cannot hold the whole pointer value |
| @@ -60,21 +79,6 @@ typedef unsigned char lu_byte; | |||
| 60 | 79 | ||
| 61 | 80 | ||
| 62 | 81 | ||
| 63 | /* type to ensure maximum alignment */ | ||
| 64 | #if defined(LUAI_USER_ALIGNMENT_T) | ||
| 65 | typedef LUAI_USER_ALIGNMENT_T L_Umaxalign; | ||
| 66 | #else | ||
| 67 | typedef union { | ||
| 68 | lua_Number n; | ||
| 69 | double u; | ||
| 70 | void *s; | ||
| 71 | lua_Integer i; | ||
| 72 | long l; | ||
| 73 | } L_Umaxalign; | ||
| 74 | #endif | ||
| 75 | |||
| 76 | |||
| 77 | |||
| 78 | /* types of 'usual argument conversions' for lua_Number and lua_Integer */ | 82 | /* types of 'usual argument conversions' for lua_Number and lua_Integer */ |
| 79 | typedef LUAI_UACNUMBER l_uacNumber; | 83 | typedef LUAI_UACNUMBER l_uacNumber; |
| 80 | typedef LUAI_UACINT l_uacInt; | 84 | typedef LUAI_UACINT l_uacInt; |
| @@ -95,7 +99,7 @@ typedef LUAI_UACINT l_uacInt; | |||
| 95 | ** assertion for checking API calls | 99 | ** assertion for checking API calls |
| 96 | */ | 100 | */ |
| 97 | #if !defined(luai_apicheck) | 101 | #if !defined(luai_apicheck) |
| 98 | #define luai_apicheck(l,e) lua_assert(e) | 102 | #define luai_apicheck(l,e) ((void)l, lua_assert(e)) |
| 99 | #endif | 103 | #endif |
| 100 | 104 | ||
| 101 | #define api_check(l,e,msg) luai_apicheck(l,(e) && msg) | 105 | #define api_check(l,e,msg) luai_apicheck(l,(e) && msg) |
| @@ -111,10 +115,15 @@ typedef LUAI_UACINT l_uacInt; | |||
| 111 | #define cast(t, exp) ((t)(exp)) | 115 | #define cast(t, exp) ((t)(exp)) |
| 112 | 116 | ||
| 113 | #define cast_void(i) cast(void, (i)) | 117 | #define cast_void(i) cast(void, (i)) |
| 114 | #define cast_byte(i) cast(lu_byte, (i)) | 118 | #define cast_voidp(i) cast(void *, (i)) |
| 115 | #define cast_num(i) cast(lua_Number, (i)) | 119 | #define cast_num(i) cast(lua_Number, (i)) |
| 116 | #define cast_int(i) cast(int, (i)) | 120 | #define cast_int(i) cast(int, (i)) |
| 121 | #define cast_uint(i) cast(unsigned int, (i)) | ||
| 122 | #define cast_byte(i) cast(lu_byte, (i)) | ||
| 117 | #define cast_uchar(i) cast(unsigned char, (i)) | 123 | #define cast_uchar(i) cast(unsigned char, (i)) |
| 124 | #define cast_char(i) cast(char, (i)) | ||
| 125 | #define cast_charp(i) cast(char *, (i)) | ||
| 126 | #define cast_sizet(i) cast(size_t, (i)) | ||
| 118 | 127 | ||
| 119 | 128 | ||
| 120 | /* cast a signed lua_Integer to lua_Unsigned */ | 129 | /* cast a signed lua_Integer to lua_Unsigned */ |
| @@ -133,38 +142,49 @@ typedef LUAI_UACINT l_uacInt; | |||
| 133 | 142 | ||
| 134 | 143 | ||
| 135 | /* | 144 | /* |
| 136 | ** non-return type | 145 | ** macros to improve jump prediction (used mainly for error handling) |
| 137 | */ | 146 | */ |
| 147 | #if !defined(likely) | ||
| 148 | |||
| 138 | #if defined(__GNUC__) | 149 | #if defined(__GNUC__) |
| 139 | #define l_noret void __attribute__((noreturn)) | 150 | #define likely(x) (__builtin_expect(((x) != 0), 1)) |
| 140 | #elif defined(_MSC_VER) && _MSC_VER >= 1200 | 151 | #define unlikely(x) (__builtin_expect(((x) != 0), 0)) |
| 141 | #define l_noret void __declspec(noreturn) | ||
| 142 | #else | 152 | #else |
| 143 | #define l_noret void | 153 | #define likely(x) (x) |
| 154 | #define unlikely(x) (x) | ||
| 144 | #endif | 155 | #endif |
| 145 | 156 | ||
| 157 | #endif | ||
| 146 | 158 | ||
| 147 | 159 | ||
| 148 | /* | 160 | /* |
| 149 | ** maximum depth for nested C calls and syntactical nested non-terminals | 161 | ** non-return type |
| 150 | ** in a program. (Value must fit in an unsigned short int.) | ||
| 151 | */ | 162 | */ |
| 152 | #if !defined(LUAI_MAXCCALLS) | 163 | #if !defined(l_noret) |
| 153 | #define LUAI_MAXCCALLS 200 | 164 | |
| 165 | #if defined(__GNUC__) | ||
| 166 | #define l_noret void __attribute__((noreturn)) | ||
| 167 | #elif defined(_MSC_VER) && _MSC_VER >= 1200 | ||
| 168 | #define l_noret void __declspec(noreturn) | ||
| 169 | #else | ||
| 170 | #define l_noret void | ||
| 154 | #endif | 171 | #endif |
| 155 | 172 | ||
| 173 | #endif | ||
| 156 | 174 | ||
| 157 | 175 | ||
| 158 | /* | 176 | /* |
| 159 | ** type for virtual-machine instructions; | 177 | ** type for virtual-machine instructions; |
| 160 | ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) | 178 | ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h) |
| 161 | */ | 179 | */ |
| 162 | #if LUAI_BITSINT >= 32 | 180 | #if LUAI_IS32INT |
| 163 | typedef unsigned int Instruction; | 181 | typedef unsigned int l_uint32; |
| 164 | #else | 182 | #else |
| 165 | typedef unsigned long Instruction; | 183 | typedef unsigned long l_uint32; |
| 166 | #endif | 184 | #endif |
| 167 | 185 | ||
| 186 | typedef l_uint32 Instruction; | ||
| 187 | |||
| 168 | 188 | ||
| 169 | 189 | ||
| 170 | /* | 190 | /* |
| @@ -225,8 +245,7 @@ typedef unsigned long Instruction; | |||
| 225 | 245 | ||
| 226 | 246 | ||
| 227 | /* | 247 | /* |
| 228 | ** these macros allow user-specific actions on threads when you defined | 248 | ** these macros allow user-specific actions when a thread is |
| 229 | ** LUAI_EXTRASPACE and need to do something extra when a thread is | ||
| 230 | ** created/deleted/resumed/yielded. | 249 | ** created/deleted/resumed/yielded. |
| 231 | */ | 250 | */ |
| 232 | #if !defined(luai_userstateopen) | 251 | #if !defined(luai_userstateopen) |
| @@ -270,15 +289,20 @@ typedef unsigned long Instruction; | |||
| 270 | #endif | 289 | #endif |
| 271 | 290 | ||
| 272 | /* | 291 | /* |
| 273 | ** modulo: defined as 'a - floor(a/b)*b'; this definition gives NaN when | 292 | ** modulo: defined as 'a - floor(a/b)*b'; the direct computation |
| 274 | ** 'b' is huge, but the result should be 'a'. 'fmod' gives the result of | 293 | ** using this definition has several problems with rounding errors, |
| 275 | ** 'a - trunc(a/b)*b', and therefore must be corrected when 'trunc(a/b) | 294 | ** so it is better to use 'fmod'. 'fmod' gives the result of |
| 276 | ** ~= floor(a/b)'. That happens when the division has a non-integer | 295 | ** 'a - trunc(a/b)*b', and therefore must be corrected when |
| 277 | ** negative result, which is equivalent to the test below. | 296 | ** 'trunc(a/b) ~= floor(a/b)'. That happens when the division has a |
| 297 | ** non-integer negative result: non-integer result is equivalent to | ||
| 298 | ** a non-zero remainder 'm'; negative result is equivalent to 'a' and | ||
| 299 | ** 'b' with different signs, or 'm' and 'b' with different signs | ||
| 300 | ** (as the result 'm' of 'fmod' has the same sign of 'a'). | ||
| 278 | */ | 301 | */ |
| 279 | #if !defined(luai_nummod) | 302 | #if !defined(luai_nummod) |
| 280 | #define luai_nummod(L,a,b,m) \ | 303 | #define luai_nummod(L,a,b,m) \ |
| 281 | { (m) = l_mathop(fmod)(a,b); if ((m)*(b) < 0) (m) += (b); } | 304 | { (void)L; (m) = l_mathop(fmod)(a,b); \ |
| 305 | if (((m) > 0) ? (b) < 0 : ((m) < 0 && (b) > 0)) (m) += (b); } | ||
| 282 | #endif | 306 | #endif |
| 283 | 307 | ||
| 284 | /* exponentiation */ | 308 | /* exponentiation */ |
| @@ -295,6 +319,8 @@ typedef unsigned long Instruction; | |||
| 295 | #define luai_numeq(a,b) ((a)==(b)) | 319 | #define luai_numeq(a,b) ((a)==(b)) |
| 296 | #define luai_numlt(a,b) ((a)<(b)) | 320 | #define luai_numlt(a,b) ((a)<(b)) |
| 297 | #define luai_numle(a,b) ((a)<=(b)) | 321 | #define luai_numle(a,b) ((a)<=(b)) |
| 322 | #define luai_numgt(a,b) ((a)>(b)) | ||
| 323 | #define luai_numge(a,b) ((a)>=(b)) | ||
| 298 | #define luai_numisnan(a) (!luai_numeq((a), (a))) | 324 | #define luai_numisnan(a) (!luai_numeq((a), (a))) |
| 299 | #endif | 325 | #endif |
| 300 | 326 | ||
| @@ -310,7 +336,7 @@ typedef unsigned long Instruction; | |||
| 310 | #else | 336 | #else |
| 311 | /* realloc stack keeping its size */ | 337 | /* realloc stack keeping its size */ |
| 312 | #define condmovestack(L,pre,pos) \ | 338 | #define condmovestack(L,pre,pos) \ |
| 313 | { int sz_ = (L)->stacksize; pre; luaD_reallocstack((L), sz_); pos; } | 339 | { int sz_ = (L)->stacksize; pre; luaD_reallocstack((L), sz_, 0); pos; } |
| 314 | #endif | 340 | #endif |
| 315 | 341 | ||
| 316 | #if !defined(HARDMEMTESTS) | 342 | #if !defined(HARDMEMTESTS) |
