lua/llimits.h

Go to the documentation of this file.
00001 /*
00002 ** $Id: llimits.h,v 1.95 2011/12/06 16:58:36 roberto Exp $
00003 ** Limits, basic types, and some other `installation-dependent' definitions
00004 ** See Copyright Notice in lua.h
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 /* chars used as small naturals (so that `char' is reserved for characters) */
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)  /* maximum value of an int (-2 for safety) */
00036 
00037 /*
00038 ** conversion of pointer to integer
00039 ** this is for hashing only; there is no problem if the integer
00040 ** cannot hold the whole pointer value
00041 */
00042 #define IntPoint(p)  ((unsigned int)(lu_mem)(p))
00043 
00044 
00045 
00046 /* type to ensure maximum alignment */
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 /* result of a `usual argument conversion' over lua_Number */
00055 typedef LUAI_UACNUMBER l_uacNumber;
00056 
00057 
00058 /* internal assertions for in-house debugging */
00059 #if defined(lua_assert)
00060 #define check_exp(c,e)      (lua_assert(c), (e))
00061 /* to avoid problems with conditions too long */
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 ** assertion for checking API calls
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)) /* to avoid warnings */
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 ** non-return type
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 ** maximum depth for nested C calls and syntactical nested non-terminals
00114 ** in a program. (Value must fit in an unsigned short int.)
00115 */
00116 #if !defined(LUAI_MAXCCALLS)
00117 #define LUAI_MAXCCALLS      200
00118 #endif
00119 
00120 /*
00121 ** maximum number of upvalues in a closure (both C and Lua). (Value
00122 ** must fit in an unsigned char.)
00123 */
00124 #define MAXUPVAL    UCHAR_MAX
00125 
00126 
00127 /*
00128 ** type for virtual-machine instructions
00129 ** must be an unsigned with (at least) 4 bytes (see details in lopcodes.h)
00130 */
00131 typedef lu_int32 Instruction;
00132 
00133 
00134 
00135 /* maximum stack for a Lua function */
00136 #define MAXSTACK    250
00137 
00138 
00139 
00140 /* minimum size for the string table (must be power of 2) */
00141 #if !defined(MINSTRTABSIZE)
00142 #define MINSTRTABSIZE   32
00143 #endif
00144 
00145 
00146 /* minimum size for string buffer */
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 ** these macros allow user-specific actions on threads when you defined
00164 ** LUAI_EXTRASPACE and need to do something extra when a thread is
00165 ** created/deleted/resumed/yielded.
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 ** lua_number2int is a macro to convert lua_Number to int.
00193 ** lua_number2integer is a macro to convert lua_Number to lua_Integer.
00194 ** lua_number2unsigned is a macro to convert a lua_Number to a lua_Unsigned.
00195 ** lua_unsigned2number is a macro to convert a lua_Unsigned to a lua_Number.
00196 ** luai_hashnum is a macro to hash a lua_Number value into an integer.
00197 ** The hash must be deterministic and give reasonable values for
00198 ** both small and large values (outside the range of integers).
00199 */
00200 
00201 #if defined(MS_ASMTRICK)    /* { */
00202 /* trick with Microsoft assembler for X86 */
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 /* the next trick should work on any machine using IEEE754 with
00212    a 32-bit integer type */
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      /* empty */
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;  /* avoid -0 */ \
00231     (i) = u.l_p[0]; (i) += u.l_p[1]; }  /* add double bits for his hash */
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 /* the following definitions always work, but may be slow */
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 /* the following definition assures proper modulo behavior */
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 /* on several machines, coercion from unsigned to double is slow,
00265    so it may be worth to avoid */
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 ** macro to control inclusion of some hard tests on stack reallocation
00287 */
00288 #if !defined(HARDSTACKTESTS)
00289 #define condmovestack(L)    ((void)0)
00290 #else
00291 /* realloc stack keeping its size */
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
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated by doxygen 1.7.1 on Fri May 25 2012 01:03:04 for The Battle for Wesnoth
Gna! | Forum | Wiki | CIA | devdocs