1280405Srpaulo/* 2344220Skevans** $Id: lvm.h,v 2.41.1.1 2017/04/19 17:20:42 roberto Exp $ 3280405Srpaulo** Lua virtual machine 4280405Srpaulo** See Copyright Notice in lua.h 5280405Srpaulo*/ 6280405Srpaulo 7280405Srpaulo#ifndef lvm_h 8280405Srpaulo#define lvm_h 9280405Srpaulo 10280405Srpaulo 11280405Srpaulo#include "ldo.h" 12280405Srpaulo#include "lobject.h" 13280405Srpaulo#include "ltm.h" 14280405Srpaulo 15280405Srpaulo 16280405Srpaulo#if !defined(LUA_NOCVTN2S) 17280405Srpaulo#define cvt2str(o) ttisnumber(o) 18280405Srpaulo#else 19280405Srpaulo#define cvt2str(o) 0 /* no conversion from numbers to strings */ 20280405Srpaulo#endif 21280405Srpaulo 22280405Srpaulo 23280405Srpaulo#if !defined(LUA_NOCVTS2N) 24280405Srpaulo#define cvt2num(o) ttisstring(o) 25280405Srpaulo#else 26280405Srpaulo#define cvt2num(o) 0 /* no conversion from strings to numbers */ 27280405Srpaulo#endif 28280405Srpaulo 29280405Srpaulo 30326344Simp/* 31326344Simp** You can define LUA_FLOORN2I if you want to convert floats to integers 32326344Simp** by flooring them (instead of raising an error if they are not 33326344Simp** integral values) 34326344Simp*/ 35326344Simp#if !defined(LUA_FLOORN2I) 36326344Simp#define LUA_FLOORN2I 0 37326344Simp#endif 38326344Simp 39326344Simp 40280405Srpaulo#define tonumber(o,n) \ 41280405Srpaulo (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n)) 42280405Srpaulo 43280405Srpaulo#define tointeger(o,i) \ 44326344Simp (ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointeger(o,i,LUA_FLOORN2I)) 45280405Srpaulo 46280405Srpaulo#define intop(op,v1,v2) l_castU2S(l_castS2U(v1) op l_castS2U(v2)) 47280405Srpaulo 48280405Srpaulo#define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2) 49280405Srpaulo 50280405Srpaulo 51326344Simp/* 52326344Simp** fast track for 'gettable': if 't' is a table and 't[k]' is not nil, 53326344Simp** return 1 with 'slot' pointing to 't[k]' (final result). Otherwise, 54326344Simp** return 0 (meaning it will have to check metamethod) with 'slot' 55326344Simp** pointing to a nil 't[k]' (if 't' is a table) or NULL (otherwise). 56326344Simp** 'f' is the raw get function to use. 57326344Simp*/ 58326344Simp#define luaV_fastget(L,t,k,slot,f) \ 59326344Simp (!ttistable(t) \ 60326344Simp ? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \ 61326344Simp : (slot = f(hvalue(t), k), /* else, do raw access */ \ 62326344Simp !ttisnil(slot))) /* result not nil? */ 63326344Simp 64326344Simp/* 65326344Simp** standard implementation for 'gettable' 66326344Simp*/ 67326344Simp#define luaV_gettable(L,t,k,v) { const TValue *slot; \ 68326344Simp if (luaV_fastget(L,t,k,slot,luaH_get)) { setobj2s(L, v, slot); } \ 69326344Simp else luaV_finishget(L,t,k,v,slot); } 70326344Simp 71326344Simp 72326344Simp/* 73326344Simp** Fast track for set table. If 't' is a table and 't[k]' is not nil, 74326344Simp** call GC barrier, do a raw 't[k]=v', and return true; otherwise, 75326344Simp** return false with 'slot' equal to NULL (if 't' is not a table) or 76326344Simp** 'nil'. (This is needed by 'luaV_finishget'.) Note that, if the macro 77326344Simp** returns true, there is no need to 'invalidateTMcache', because the 78326344Simp** call is not creating a new entry. 79326344Simp*/ 80326344Simp#define luaV_fastset(L,t,k,slot,f,v) \ 81326344Simp (!ttistable(t) \ 82326344Simp ? (slot = NULL, 0) \ 83326344Simp : (slot = f(hvalue(t), k), \ 84326344Simp ttisnil(slot) ? 0 \ 85326344Simp : (luaC_barrierback(L, hvalue(t), v), \ 86326344Simp setobj2t(L, cast(TValue *,slot), v), \ 87326344Simp 1))) 88326344Simp 89326344Simp 90326344Simp#define luaV_settable(L,t,k,v) { const TValue *slot; \ 91326344Simp if (!luaV_fastset(L,t,k,slot,luaH_get,v)) \ 92326344Simp luaV_finishset(L,t,k,v,slot); } 93326344Simp 94326344Simp 95326344Simp 96280405SrpauloLUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2); 97280405SrpauloLUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); 98280405SrpauloLUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); 99280405SrpauloLUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n); 100326344SimpLUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, int mode); 101326344SimpLUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key, 102326344Simp StkId val, const TValue *slot); 103326344SimpLUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key, 104326344Simp StkId val, const TValue *slot); 105280405SrpauloLUAI_FUNC void luaV_finishOp (lua_State *L); 106280405SrpauloLUAI_FUNC void luaV_execute (lua_State *L); 107280405SrpauloLUAI_FUNC void luaV_concat (lua_State *L, int total); 108280405SrpauloLUAI_FUNC lua_Integer luaV_div (lua_State *L, lua_Integer x, lua_Integer y); 109280405SrpauloLUAI_FUNC lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y); 110280405SrpauloLUAI_FUNC lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y); 111280405SrpauloLUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb); 112280405Srpaulo 113280405Srpaulo#endif 114