diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lua/lvm.h | 134 |
1 files changed, 134 insertions, 0 deletions
diff --git a/src/lua/lvm.h b/src/lua/lvm.h new file mode 100644 index 0000000..2d4ac16 --- /dev/null +++ b/src/lua/lvm.h | |||
| @@ -0,0 +1,134 @@ | |||
| 1 | /* | ||
| 2 | ** $Id: lvm.h $ | ||
| 3 | ** Lua virtual machine | ||
| 4 | ** See Copyright Notice in lua.h | ||
| 5 | */ | ||
| 6 | |||
| 7 | #ifndef lvm_h | ||
| 8 | #define lvm_h | ||
| 9 | |||
| 10 | |||
| 11 | #include "ldo.h" | ||
| 12 | #include "lobject.h" | ||
| 13 | #include "ltm.h" | ||
| 14 | |||
| 15 | |||
| 16 | #if !defined(LUA_NOCVTN2S) | ||
| 17 | #define cvt2str(o) ttisnumber(o) | ||
| 18 | #else | ||
| 19 | #define cvt2str(o) 0 /* no conversion from numbers to strings */ | ||
| 20 | #endif | ||
| 21 | |||
| 22 | |||
| 23 | #if !defined(LUA_NOCVTS2N) | ||
| 24 | #define cvt2num(o) ttisstring(o) | ||
| 25 | #else | ||
| 26 | #define cvt2num(o) 0 /* no conversion from strings to numbers */ | ||
| 27 | #endif | ||
| 28 | |||
| 29 | |||
| 30 | /* | ||
| 31 | ** You can define LUA_FLOORN2I if you want to convert floats to integers | ||
| 32 | ** by flooring them (instead of raising an error if they are not | ||
| 33 | ** integral values) | ||
| 34 | */ | ||
| 35 | #if !defined(LUA_FLOORN2I) | ||
| 36 | #define LUA_FLOORN2I F2Ieq | ||
| 37 | #endif | ||
| 38 | |||
| 39 | |||
| 40 | /* | ||
| 41 | ** Rounding modes for float->integer coercion | ||
| 42 | */ | ||
| 43 | typedef enum { | ||
| 44 | F2Ieq, /* no rounding; accepts only integral values */ | ||
| 45 | F2Ifloor, /* takes the floor of the number */ | ||
| 46 | F2Iceil /* takes the ceil of the number */ | ||
| 47 | } F2Imod; | ||
| 48 | |||
| 49 | |||
| 50 | /* convert an object to a float (including string coercion) */ | ||
| 51 | #define tonumber(o,n) \ | ||
| 52 | (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n)) | ||
| 53 | |||
| 54 | |||
| 55 | /* convert an object to a float (without string coercion) */ | ||
| 56 | #define tonumberns(o,n) \ | ||
| 57 | (ttisfloat(o) ? ((n) = fltvalue(o), 1) : \ | ||
| 58 | (ttisinteger(o) ? ((n) = cast_num(ivalue(o)), 1) : 0)) | ||
| 59 | |||
| 60 | |||
| 61 | /* convert an object to an integer (including string coercion) */ | ||
| 62 | #define tointeger(o,i) \ | ||
| 63 | (ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointeger(o,i,LUA_FLOORN2I)) | ||
| 64 | |||
| 65 | |||
| 66 | /* convert an object to an integer (without string coercion) */ | ||
| 67 | #define tointegerns(o,i) \ | ||
| 68 | (ttisinteger(o) ? (*(i) = ivalue(o), 1) : luaV_tointegerns(o,i,LUA_FLOORN2I)) | ||
| 69 | |||
| 70 | |||
| 71 | #define intop(op,v1,v2) l_castU2S(l_castS2U(v1) op l_castS2U(v2)) | ||
| 72 | |||
| 73 | #define luaV_rawequalobj(t1,t2) luaV_equalobj(NULL,t1,t2) | ||
| 74 | |||
| 75 | |||
| 76 | /* | ||
| 77 | ** fast track for 'gettable': if 't' is a table and 't[k]' is present, | ||
| 78 | ** return 1 with 'slot' pointing to 't[k]' (position of final result). | ||
| 79 | ** Otherwise, return 0 (meaning it will have to check metamethod) | ||
| 80 | ** with 'slot' pointing to an empty 't[k]' (if 't' is a table) or NULL | ||
| 81 | ** (otherwise). 'f' is the raw get function to use. | ||
| 82 | */ | ||
| 83 | #define luaV_fastget(L,t,k,slot,f) \ | ||
| 84 | (!ttistable(t) \ | ||
| 85 | ? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \ | ||
| 86 | : (slot = f(hvalue(t), k), /* else, do raw access */ \ | ||
| 87 | !isempty(slot))) /* result not empty? */ | ||
| 88 | |||
| 89 | |||
| 90 | /* | ||
| 91 | ** Special case of 'luaV_fastget' for integers, inlining the fast case | ||
| 92 | ** of 'luaH_getint'. | ||
| 93 | */ | ||
| 94 | #define luaV_fastgeti(L,t,k,slot) \ | ||
| 95 | (!ttistable(t) \ | ||
| 96 | ? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \ | ||
| 97 | : (slot = (l_castS2U(k) - 1u < hvalue(t)->alimit) \ | ||
| 98 | ? &hvalue(t)->array[k - 1] : luaH_getint(hvalue(t), k), \ | ||
| 99 | !isempty(slot))) /* result not empty? */ | ||
| 100 | |||
| 101 | |||
| 102 | /* | ||
| 103 | ** Finish a fast set operation (when fast get succeeds). In that case, | ||
| 104 | ** 'slot' points to the place to put the value. | ||
| 105 | */ | ||
| 106 | #define luaV_finishfastset(L,t,slot,v) \ | ||
| 107 | { setobj2t(L, cast(TValue *,slot), v); \ | ||
| 108 | luaC_barrierback(L, gcvalue(t), v); } | ||
| 109 | |||
| 110 | |||
| 111 | |||
| 112 | |||
| 113 | LUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2); | ||
| 114 | LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r); | ||
| 115 | LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r); | ||
| 116 | LUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n); | ||
| 117 | LUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, F2Imod mode); | ||
| 118 | LUAI_FUNC int luaV_tointegerns (const TValue *obj, lua_Integer *p, | ||
| 119 | F2Imod mode); | ||
| 120 | LUAI_FUNC int luaV_flttointeger (lua_Number n, lua_Integer *p, F2Imod mode); | ||
| 121 | LUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key, | ||
| 122 | StkId val, const TValue *slot); | ||
| 123 | LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key, | ||
| 124 | TValue *val, const TValue *slot); | ||
| 125 | LUAI_FUNC void luaV_finishOp (lua_State *L); | ||
| 126 | LUAI_FUNC void luaV_execute (lua_State *L, CallInfo *ci); | ||
| 127 | LUAI_FUNC void luaV_concat (lua_State *L, int total); | ||
| 128 | LUAI_FUNC lua_Integer luaV_idiv (lua_State *L, lua_Integer x, lua_Integer y); | ||
| 129 | LUAI_FUNC lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y); | ||
| 130 | LUAI_FUNC lua_Number luaV_modf (lua_State *L, lua_Number x, lua_Number y); | ||
| 131 | LUAI_FUNC lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y); | ||
| 132 | LUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb); | ||
| 133 | |||
| 134 | #endif | ||
