Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #ifndef llimits_h
00008 #define llimits_h
00009
00010
00011 #include <limits.h>
00012 #include <stddef.h>
00013
00014
00015 #include "lua.h"
00016
00017
00018 typedef unsigned LUA_INT32 lu_int32;
00019
00020 typedef LUAI_UMEM lu_mem;
00021
00022 typedef LUAI_MEM l_mem;
00023
00024
00025
00026
00027 typedef unsigned char lu_byte;
00028
00029
00030 #define MAX_SIZET ((size_t)(~(size_t)0)-2)
00031
00032 #define MAX_LUMEM ((lu_mem)(~(lu_mem)0)-2)
00033
00034
00035 #define MAX_INT (INT_MAX-2)
00036
00037
00038
00039
00040
00041
00042 #define IntPoint(p) ((unsigned int)(lu_mem)(p))
00043
00044
00045
00046
00047 #if !defined(LUAI_USER_ALIGNMENT_T)
00048 #define LUAI_USER_ALIGNMENT_T union { double u; void *s; long l; }
00049 #endif
00050
00051 typedef LUAI_USER_ALIGNMENT_T L_Umaxalign;
00052
00053
00054
00055 typedef LUAI_UACNUMBER l_uacNumber;
00056
00057
00058
00059 #if defined(lua_assert)
00060 #define check_exp(c,e) (lua_assert(c), (e))
00061
00062 #define lua_longassert(c) { if (!(c)) lua_assert(0); }
00063 #else
00064 #define lua_assert(c) ((void)0)
00065 #define check_exp(c,e) (e)
00066 #define lua_longassert(c) ((void)0)
00067 #endif
00068
00069
00070
00071
00072 #if !defined(luai_apicheck)
00073
00074 #if defined(LUA_USE_APICHECK)
00075 #include <assert.h>
00076 #define luai_apicheck(L,e) assert(e)
00077 #else
00078 #define luai_apicheck(L,e) lua_assert(e)
00079 #endif
00080
00081 #endif
00082
00083 #define api_check(l,e,msg) luai_apicheck(l,(e) && msg)
00084
00085
00086 #if !defined(UNUSED)
00087 #define UNUSED(x) ((void)(x))
00088 #endif
00089
00090
00091 #define cast(t, exp) ((t)(exp))
00092
00093 #define cast_byte(i) cast(lu_byte, (i))
00094 #define cast_num(i) cast(lua_Number, (i))
00095 #define cast_int(i) cast(int, (i))
00096 #define cast_uchar(i) cast(unsigned char, (i))
00097
00098
00099
00100
00101
00102 #if defined(__GNUC__)
00103 #define l_noret void __attribute__((noreturn))
00104 #elif defined(_MSC_VER)
00105 #define l_noret void __declspec(noreturn)
00106 #else
00107 #define l_noret void
00108 #endif
00109
00110
00111
00112
00113
00114
00115
00116 #if !defined(LUAI_MAXCCALLS)
00117 #define LUAI_MAXCCALLS 200
00118 #endif
00119
00120
00121
00122
00123
00124 #define MAXUPVAL UCHAR_MAX
00125
00126
00127
00128
00129
00130
00131 typedef lu_int32 Instruction;
00132
00133
00134
00135
00136 #define MAXSTACK 250
00137
00138
00139
00140
00141 #if !defined(MINSTRTABSIZE)
00142 #define MINSTRTABSIZE 32
00143 #endif
00144
00145
00146
00147 #if !defined(LUA_MINBUFFER)
00148 #define LUA_MINBUFFER 32
00149 #endif
00150
00151
00152 #if !defined(lua_lock)
00153 #define lua_lock(L) ((void) 0)
00154 #define lua_unlock(L) ((void) 0)
00155 #endif
00156
00157 #if !defined(luai_threadyield)
00158 #define luai_threadyield(L) {lua_unlock(L); lua_lock(L);}
00159 #endif
00160
00161
00162
00163
00164
00165
00166
00167 #if !defined(luai_userstateopen)
00168 #define luai_userstateopen(L) ((void)L)
00169 #endif
00170
00171 #if !defined(luai_userstateclose)
00172 #define luai_userstateclose(L) ((void)L)
00173 #endif
00174
00175 #if !defined(luai_userstatethread)
00176 #define luai_userstatethread(L,L1) ((void)L)
00177 #endif
00178
00179 #if !defined(luai_userstatefree)
00180 #define luai_userstatefree(L,L1) ((void)L)
00181 #endif
00182
00183 #if !defined(luai_userstateresume)
00184 #define luai_userstateresume(L,n) ((void)L)
00185 #endif
00186
00187 #if !defined(luai_userstateyield)
00188 #define luai_userstateyield(L,n) ((void)L)
00189 #endif
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201 #if defined(MS_ASMTRICK)
00202
00203
00204 #define lua_number2int(i,n) __asm {__asm fld n __asm fistp i}
00205 #define lua_number2integer(i,n) lua_number2int(i, n)
00206 #define lua_number2unsigned(i,n) \
00207 {__int64 l; __asm {__asm fld n __asm fistp l} i = (unsigned int)l;}
00208
00209
00210 #elif defined(LUA_IEEE754TRICK)
00211
00212
00213
00214 union luai_Cast { double l_d; LUA_INT32 l_p[2]; };
00215
00216 #if !defined(LUA_IEEEENDIAN)
00217 #define LUAI_EXTRAIEEE \
00218 static const union luai_Cast ieeeendian = {-(33.0 + 6755399441055744.0)};
00219 #define LUA_IEEEENDIAN (ieeeendian.l_p[1] == 33)
00220 #else
00221 #define LUAI_EXTRAIEEE
00222 #endif
00223
00224 #define lua_number2int32(i,n,t) \
00225 { LUAI_EXTRAIEEE \
00226 volatile union luai_Cast u; u.l_d = (n) + 6755399441055744.0; \
00227 (i) = (t)u.l_p[LUA_IEEEENDIAN]; }
00228
00229 #define luai_hashnum(i,n) \
00230 { volatile union luai_Cast u; u.l_d = (n) + 1.0; \
00231 (i) = u.l_p[0]; (i) += u.l_p[1]; }
00232
00233 #define lua_number2int(i,n) lua_number2int32(i, n, int)
00234 #define lua_number2integer(i,n) lua_number2int32(i, n, lua_Integer)
00235 #define lua_number2unsigned(i,n) lua_number2int32(i, n, lua_Unsigned)
00236
00237 #endif
00238
00239
00240
00241
00242 #if !defined(lua_number2int)
00243 #define lua_number2int(i,n) ((i)=(int)(n))
00244 #endif
00245
00246 #if !defined(lua_number2integer)
00247 #define lua_number2integer(i,n) ((i)=(lua_Integer)(n))
00248 #endif
00249
00250 #if !defined(lua_number2unsigned)
00251
00252 #if defined(LUA_NUMBER_DOUBLE)
00253 #include <math.h>
00254 #define SUPUNSIGNED ((lua_Number)(~(lua_Unsigned)0) + 1)
00255 #define lua_number2unsigned(i,n) \
00256 ((i)=(lua_Unsigned)((n) - floor((n)/SUPUNSIGNED)*SUPUNSIGNED))
00257 #else
00258 #define lua_number2unsigned(i,n) ((i)=(lua_Unsigned)(n))
00259 #endif
00260 #endif
00261
00262
00263 #if !defined(lua_unsigned2number)
00264
00265
00266 #define lua_unsigned2number(u) \
00267 (((u) <= (lua_Unsigned)INT_MAX) ? (lua_Number)(int)(u) : (lua_Number)(u))
00268 #endif
00269
00270
00271
00272 #if defined(ltable_c) && !defined(luai_hashnum)
00273
00274 #include <float.h>
00275 #include <math.h>
00276
00277 #define luai_hashnum(i,n) { int e; \
00278 n = frexp(n, &e) * (lua_Number)(INT_MAX - DBL_MAX_EXP); \
00279 lua_number2int(i, n); i += e; }
00280
00281 #endif
00282
00283
00284
00285
00286
00287
00288 #if !defined(HARDSTACKTESTS)
00289 #define condmovestack(L) ((void)0)
00290 #else
00291
00292 #define condmovestack(L) luaD_reallocstack((L), (L)->stacksize)
00293 #endif
00294
00295 #if !defined(HARDMEMTESTS)
00296 #define condchangemem(L) condmovestack(L)
00297 #else
00298 #define condchangemem(L) \
00299 ((void)(!(G(L)->gcrunning) || (luaC_fullgc(L, 0), 1)))
00300 #endif
00301
00302 #endif