Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-07 10:37:57

0001 /*
0002 ** $Id: lvm.h $
0003 ** Lua virtual machine
0004 ** See Copyright Notice in lua.h
0005 */
0006 
0007 #ifndef lvm_h
0008 #define lvm_h
0009 
0010 
0011 #include "ldo.h"
0012 #include "lobject.h"
0013 #include "ltm.h"
0014 
0015 
0016 #if !defined(LUA_NOCVTN2S)
0017 #define cvt2str(o)  ttisnumber(o)
0018 #else
0019 #define cvt2str(o)  0   /* no conversion from numbers to strings */
0020 #endif
0021 
0022 
0023 #if !defined(LUA_NOCVTS2N)
0024 #define cvt2num(o)  ttisstring(o)
0025 #else
0026 #define cvt2num(o)  0   /* no conversion from strings to numbers */
0027 #endif
0028 
0029 
0030 /*
0031 ** You can define LUA_FLOORN2I if you want to convert floats to integers
0032 ** by flooring them (instead of raising an error if they are not
0033 ** integral values)
0034 */
0035 #if !defined(LUA_FLOORN2I)
0036 #define LUA_FLOORN2I        F2Ieq
0037 #endif
0038 
0039 
0040 /*
0041 ** Rounding modes for float->integer coercion
0042  */
0043 typedef enum {
0044   F2Ieq,     /* no rounding; accepts only integral values */
0045   F2Ifloor,  /* takes the floor of the number */
0046   F2Iceil    /* takes the ceil of the number */
0047 } F2Imod;
0048 
0049 
0050 /* convert an object to a float (including string coercion) */
0051 #define tonumber(o,n) \
0052     (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n))
0053 
0054 
0055 /* convert an object to a float (without string coercion) */
0056 #define tonumberns(o,n) \
0057     (ttisfloat(o) ? ((n) = fltvalue(o), 1) : \
0058     (ttisinteger(o) ? ((n) = cast_num(ivalue(o)), 1) : 0))
0059 
0060 
0061 /* convert an object to an integer (including string coercion) */
0062 #define tointeger(o,i) \
0063   (l_likely(ttisinteger(o)) ? (*(i) = ivalue(o), 1) \
0064                           : luaV_tointeger(o,i,LUA_FLOORN2I))
0065 
0066 
0067 /* convert an object to an integer (without string coercion) */
0068 #define tointegerns(o,i) \
0069   (l_likely(ttisinteger(o)) ? (*(i) = ivalue(o), 1) \
0070                           : luaV_tointegerns(o,i,LUA_FLOORN2I))
0071 
0072 
0073 #define intop(op,v1,v2) l_castU2S(l_castS2U(v1) op l_castS2U(v2))
0074 
0075 #define luaV_rawequalobj(t1,t2)     luaV_equalobj(NULL,t1,t2)
0076 
0077 
0078 /*
0079 ** fast track for 'gettable': if 't' is a table and 't[k]' is present,
0080 ** return 1 with 'slot' pointing to 't[k]' (position of final result).
0081 ** Otherwise, return 0 (meaning it will have to check metamethod)
0082 ** with 'slot' pointing to an empty 't[k]' (if 't' is a table) or NULL
0083 ** (otherwise). 'f' is the raw get function to use.
0084 */
0085 #define luaV_fastget(L,t,k,slot,f) \
0086   (!ttistable(t)  \
0087    ? (slot = NULL, 0)  /* not a table; 'slot' is NULL and result is 0 */  \
0088    : (slot = f(hvalue(t), k),  /* else, do raw access */  \
0089       !isempty(slot)))  /* result not empty? */
0090 
0091 
0092 /*
0093 ** Special case of 'luaV_fastget' for integers, inlining the fast case
0094 ** of 'luaH_getint'.
0095 */
0096 #define luaV_fastgeti(L,t,k,slot) \
0097   (!ttistable(t)  \
0098    ? (slot = NULL, 0)  /* not a table; 'slot' is NULL and result is 0 */  \
0099    : (slot = (l_castS2U(k) - 1u < hvalue(t)->alimit) \
0100               ? &hvalue(t)->array[k - 1] : luaH_getint(hvalue(t), k), \
0101       !isempty(slot)))  /* result not empty? */
0102 
0103 
0104 /*
0105 ** Finish a fast set operation (when fast get succeeds). In that case,
0106 ** 'slot' points to the place to put the value.
0107 */
0108 #define luaV_finishfastset(L,t,slot,v) \
0109     { setobj2t(L, cast(TValue *,slot), v); \
0110       luaC_barrierback(L, gcvalue(t), v); }
0111 
0112 
0113 /*
0114 ** Shift right is the same as shift left with a negative 'y'
0115 */
0116 #define luaV_shiftr(x,y)    luaV_shiftl(x,intop(-, 0, y))
0117 
0118 
0119 
0120 LUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2);
0121 LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r);
0122 LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r);
0123 LUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n);
0124 LUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, F2Imod mode);
0125 LUAI_FUNC int luaV_tointegerns (const TValue *obj, lua_Integer *p,
0126                                 F2Imod mode);
0127 LUAI_FUNC int luaV_flttointeger (lua_Number n, lua_Integer *p, F2Imod mode);
0128 LUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key,
0129                                StkId val, const TValue *slot);
0130 LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key,
0131                                TValue *val, const TValue *slot);
0132 LUAI_FUNC void luaV_finishOp (lua_State *L);
0133 LUAI_FUNC void luaV_execute (lua_State *L, CallInfo *ci);
0134 LUAI_FUNC void luaV_concat (lua_State *L, int total);
0135 LUAI_FUNC lua_Integer luaV_idiv (lua_State *L, lua_Integer x, lua_Integer y);
0136 LUAI_FUNC lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y);
0137 LUAI_FUNC lua_Number luaV_modf (lua_State *L, lua_Number x, lua_Number y);
0138 LUAI_FUNC lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y);
0139 LUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb);
0140 
0141 #endif