Github User Fetcher 1.0.0
C Application with Server and GUI
Loading...
Searching...
No Matches
lvm.h File Reference
#include "ldo.h"
#include "lobject.h"
#include "ltm.h"

Go to the source code of this file.

Macros

#define cvt2str(o)   ttisnumber(o)
 
#define cvt2num(o)   ttisstring(o)
 
#define LUA_FLOORN2I   F2Ieq
 
#define tonumber(o, n)    (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n))
 
#define tonumberns(o, n)
 
#define tointeger(o, i)
 
#define tointegerns(o, i)
 
#define intop(op, v1, v2)   l_castU2S(l_castS2U(v1) op l_castS2U(v2))
 
#define luaV_rawequalobj(t1, t2)   luaV_equalobj(NULL,t1,t2)
 
#define luaV_fastget(L, t, k, slot, f)
 
#define luaV_fastgeti(L, t, k, slot)
 
#define luaV_finishfastset(L, t, slot, v)
 

Enumerations

enum  F2Imod { F2Ieq , F2Ifloor , F2Iceil }
 

Functions

LUAI_FUNC int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2)
 
LUAI_FUNC int luaV_lessthan (lua_State *L, const TValue *l, const TValue *r)
 
LUAI_FUNC int luaV_lessequal (lua_State *L, const TValue *l, const TValue *r)
 
LUAI_FUNC int luaV_tonumber_ (const TValue *obj, lua_Number *n)
 
LUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, F2Imod mode)
 
LUAI_FUNC int luaV_tointegerns (const TValue *obj, lua_Integer *p, F2Imod mode)
 
LUAI_FUNC int luaV_flttointeger (lua_Number n, lua_Integer *p, F2Imod mode)
 
LUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val, const TValue *slot)
 
LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key, TValue *val, const TValue *slot)
 
LUAI_FUNC void luaV_finishOp (lua_State *L)
 
LUAI_FUNC void luaV_execute (lua_State *L, CallInfo *ci)
 
LUAI_FUNC void luaV_concat (lua_State *L, int total)
 
LUAI_FUNC lua_Integer luaV_idiv (lua_State *L, lua_Integer x, lua_Integer y)
 
LUAI_FUNC lua_Integer luaV_mod (lua_State *L, lua_Integer x, lua_Integer y)
 
LUAI_FUNC lua_Number luaV_modf (lua_State *L, lua_Number x, lua_Number y)
 
LUAI_FUNC lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y)
 
LUAI_FUNC void luaV_objlen (lua_State *L, StkId ra, const TValue *rb)
 

Macro Definition Documentation

◆ cvt2num

#define cvt2num ( o)    ttisstring(o)

Definition at line 24 of file lua-5.4.3/src/lvm.h.

◆ cvt2str

#define cvt2str ( o)    ttisnumber(o)

Definition at line 17 of file lua-5.4.3/src/lvm.h.

◆ intop

#define intop ( op,
v1,
v2 )   l_castU2S(l_castS2U(v1) op l_castS2U(v2))

Definition at line 73 of file lua-5.4.3/src/lvm.h.

◆ LUA_FLOORN2I

#define LUA_FLOORN2I   F2Ieq

Definition at line 36 of file lua-5.4.3/src/lvm.h.

◆ luaV_fastget

#define luaV_fastget ( L,
t,
k,
slot,
f )
Value:
(!ttistable(t) \
? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \
: (slot = f(hvalue(t), k), /* else, do raw access */ \
!isempty(slot))) /* result not empty? */
#define NULL
Definition gmacros.h:924
#define hvalue(o)
#define ttistable(o)
#define isempty(v)

Definition at line 85 of file lua-5.4.3/src/lvm.h.

85#define luaV_fastget(L,t,k,slot,f) \
86 (!ttistable(t) \
87 ? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \
88 : (slot = f(hvalue(t), k), /* else, do raw access */ \
89 !isempty(slot))) /* result not empty? */

◆ luaV_fastgeti

#define luaV_fastgeti ( L,
t,
k,
slot )
Value:
(!ttistable(t) \
? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \
: (slot = (l_castS2U(k) - 1u < hvalue(t)->alimit) \
? &hvalue(t)->array[k - 1] : luaH_getint(hvalue(t), k), \
!isempty(slot))) /* result not empty? */
const TValue * luaH_getint(Table *t, int key)
#define l_castS2U(i)

Definition at line 96 of file lua-5.4.3/src/lvm.h.

96#define luaV_fastgeti(L,t,k,slot) \
97 (!ttistable(t) \
98 ? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \
99 : (slot = (l_castS2U(k) - 1u < hvalue(t)->alimit) \
100 ? &hvalue(t)->array[k - 1] : luaH_getint(hvalue(t), k), \
101 !isempty(slot))) /* result not empty? */

Referenced by lua_geti(), lua_seti(), and luaV_execute().

◆ luaV_finishfastset

#define luaV_finishfastset ( L,
t,
slot,
v )
Value:
{ setobj2t(L, cast(TValue *,slot), v); \
luaC_barrierback(L, gcvalue(t), v); }
#define cast(t, exp)
#define gcvalue(o)
#define setobj2t

Definition at line 108 of file lua-5.4.3/src/lvm.h.

108#define luaV_finishfastset(L,t,slot,v) \
109 { setobj2t(L, cast(TValue *,slot), v); \
110 luaC_barrierback(L, gcvalue(t), v); }

Referenced by auxsetstr(), lua_seti(), lua_settable(), luaV_execute(), and luaV_finishset().

◆ luaV_rawequalobj

#define luaV_rawequalobj ( t1,
t2 )   luaV_equalobj(NULL,t1,t2)

Definition at line 75 of file lua-5.4.3/src/lvm.h.

◆ tointeger

#define tointeger ( o,
i )
Value:
(l_likely(ttisinteger(o)) ? (*(i) = ivalue(o), 1) \
#define ttisinteger(o)
#define ivalue(o)
LUAI_FUNC int luaV_tointeger(const TValue *obj, lua_Integer *p, F2Imod mode)
#define LUA_FLOORN2I

Definition at line 62 of file lua-5.4.3/src/lvm.h.

62#define tointeger(o,i) \
63 (l_likely(ttisinteger(o)) ? (*(i) = ivalue(o), 1) \
64 : luaV_tointeger(o,i,LUA_FLOORN2I))

◆ tointegerns

#define tointegerns ( o,
i )
Value:
(l_likely(ttisinteger(o)) ? (*(i) = ivalue(o), 1) \
LUAI_FUNC int luaV_tointegerns(const TValue *obj, lua_Integer *p, F2Imod mode)

Definition at line 68 of file lua-5.4.3/src/lvm.h.

68#define tointegerns(o,i) \
69 (l_likely(ttisinteger(o)) ? (*(i) = ivalue(o), 1) \
70 : luaV_tointegerns(o,i,LUA_FLOORN2I))

Referenced by luaO_rawarith(), and luaV_execute().

◆ tonumber

#define tonumber ( o,
n )    (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n))

Definition at line 51 of file lua-5.4.3/src/lvm.h.

51#define tonumber(o,n) \
52 (ttisfloat(o) ? (*(n) = fltvalue(o), 1) : luaV_tonumber_(o,n))

◆ tonumberns

#define tonumberns ( o,
n )
Value:
(ttisfloat(o) ? ((n) = fltvalue(o), 1) : \
(ttisinteger(o) ? ((n) = cast_num(ivalue(o)), 1) : 0))
#define cast_num(i)
#define fltvalue(o)
#define ttisfloat(o)

Definition at line 56 of file lua-5.4.3/src/lvm.h.

56#define tonumberns(o,n) \
57 (ttisfloat(o) ? ((n) = fltvalue(o), 1) : \
58 (ttisinteger(o) ? ((n) = cast_num(ivalue(o)), 1) : 0))

Referenced by luaO_rawarith(), and luaV_execute().

Enumeration Type Documentation

◆ F2Imod

enum F2Imod
Enumerator
F2Ieq 
F2Ifloor 
F2Iceil 

Definition at line 43 of file lua-5.4.3/src/lvm.h.

43 {
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;
@ F2Ifloor
@ F2Ieq
@ F2Iceil

Function Documentation

◆ luaV_concat()

LUAI_FUNC void luaV_concat ( lua_State * L,
int total )

Definition at line 293 of file lua-5.2.4/src/lvm.c.

293 {
294 lua_assert(total >= 2);
295 do {
296 StkId top = L->top;
297 int n = 2; /* number of elements handled in this pass (at least 2) */
298 if (!(ttisstring(top-2) || ttisnumber(top-2)) || !tostring(L, top-1)) {
299 if (!call_binTM(L, top-2, top-1, top-2, TM_CONCAT))
300 luaG_concaterror(L, top-2, top-1);
301 }
302 else if (tsvalue(top-1)->len == 0) /* second operand is empty? */
303 (void)tostring(L, top - 2); /* result is first operand */
304 else if (ttisstring(top-2) && tsvalue(top-2)->len == 0) {
305 setobjs2s(L, top - 2, top - 1); /* result is second op. */
306 }
307 else {
308 /* at least two non-empty string values; get as many as possible */
309 size_t tl = tsvalue(top-1)->len;
310 char *buffer;
311 int i;
312 /* collect total length */
313 for (i = 1; i < total && tostring(L, top-i-1); i++) {
314 size_t l = tsvalue(top-i-1)->len;
315 if (l >= (MAX_SIZET/sizeof(char)) - tl)
316 luaG_runerror(L, "string length overflow");
317 tl += l;
318 }
319 buffer = luaZ_openspace(L, &G(L)->buff, tl);
320 tl = 0;
321 n = i;
322 do { /* concat all strings */
323 size_t l = tsvalue(top-i)->len;
324 memcpy(buffer+tl, svalue(top-i), l * sizeof(char));
325 tl += l;
326 } while (--i > 0);
327 setsvalue2s(L, top-n, luaS_newlstr(L, buffer, tl));
328 }
329 total -= n-1; /* got 'n' strings to create 1 new */
330 L->top -= n-1; /* popped 'n' strings and pushed one */
331 } while (total > 1); /* repeat until only 1 result left */
332}
void luaG_concaterror(lua_State *L, StkId p1, StkId p2)
void luaG_runerror(lua_State *L, const char *fmt,...)
#define lua_assert(c)
#define MAX_SIZET
#define setsvalue2s
#define setobjs2s
#define ttisnumber(o)
#define tsvalue(o)
#define ttisstring(o)
#define svalue(o)
#define G(L)
TString * luaS_newlstr(lua_State *L, const char *str, size_t l)
@ TM_CONCAT
#define tostring(L, o)
char * luaZ_openspace(lua_State *L, Mbuffer *buff, size_t n)
static int call_binTM(lua_State *L, const TValue *p1, const TValue *p2, StkId res, TMS event)

References call_binTM(), cast_void, copy2buff(), copy2buff(), cvt2str, G, getstr, isemptystr, lua_assert, luaG_concaterror(), luaG_runerror(), LUAI_MAXSHORTLEN, luaS_createlngstrobj(), luaS_newlstr(), luaT_trybinTM(), luaT_tryconcatTM(), luaZ_openspace(), MAX_SIZE, MAX_SIZET, s2v, setobjs2s, setsvalue2s, svalue, TM_CONCAT, lua_State::top, tostring, tsvalue, ttisnumber, ttisstring, and vslen.

Referenced by luaV_execute(), luaV_execute(), and luaV_finishOp().

◆ luaV_equalobj()

LUAI_FUNC int luaV_equalobj ( lua_State * L,
const TValue * t1,
const TValue * t2 )

Definition at line 407 of file lua-5.3.6/src/lvm.c.

407 {
408 const TValue *tm;
409 if (ttype(t1) != ttype(t2)) { /* not the same variant? */
410 if (ttnov(t1) != ttnov(t2) || ttnov(t1) != LUA_TNUMBER)
411 return 0; /* only numbers can be equal with different variants */
412 else { /* two numbers with different variants */
413 lua_Integer i1, i2; /* compare them as integers */
414 return (tointeger(t1, &i1) && tointeger(t2, &i2) && i1 == i2);
415 }
416 }
417 /* values have same type and same variant */
418 switch (ttype(t1)) {
419 case LUA_TNIL: return 1;
420 case LUA_TNUMINT: return (ivalue(t1) == ivalue(t2));
421 case LUA_TNUMFLT: return luai_numeq(fltvalue(t1), fltvalue(t2));
422 case LUA_TBOOLEAN: return bvalue(t1) == bvalue(t2); /* true must be 1 !! */
423 case LUA_TLIGHTUSERDATA: return pvalue(t1) == pvalue(t2);
424 case LUA_TLCF: return fvalue(t1) == fvalue(t2);
425 case LUA_TSHRSTR: return eqshrstr(tsvalue(t1), tsvalue(t2));
426 case LUA_TLNGSTR: return luaS_eqlngstr(tsvalue(t1), tsvalue(t2));
427 case LUA_TUSERDATA: {
428 if (uvalue(t1) == uvalue(t2)) return 1;
429 else if (L == NULL) return 0;
430 tm = fasttm(L, uvalue(t1)->metatable, TM_EQ);
431 if (tm == NULL)
432 tm = fasttm(L, uvalue(t2)->metatable, TM_EQ);
433 break; /* will try TM */
434 }
435 case LUA_TTABLE: {
436 if (hvalue(t1) == hvalue(t2)) return 1;
437 else if (L == NULL) return 0;
438 tm = fasttm(L, hvalue(t1)->metatable, TM_EQ);
439 if (tm == NULL)
440 tm = fasttm(L, hvalue(t2)->metatable, TM_EQ);
441 break; /* will try TM */
442 }
443 default:
444 return gcvalue(t1) == gcvalue(t2);
445 }
446 if (tm == NULL) /* no TM? */
447 return 0; /* objects are different */
448 luaT_callTM(L, tm, t1, t2, L->top, 1); /* call TM */
449 return !l_isfalse(L->top);
450}
#define pvalue(o)
#define l_isfalse(o)
#define uvalue(o)
#define bvalue(o)
#define ttype(o)
#define fasttm(l, et, e)
@ TM_EQ
#define LUA_TTABLE
LUA_INTEGER lua_Integer
#define LUA_TBOOLEAN
#define LUA_TNUMBER
#define LUA_TUSERDATA
#define LUA_TLIGHTUSERDATA
#define LUA_TNIL
#define LUA_TSHRSTR
#define fvalue(o)
#define LUA_TLNGSTR
#define LUA_TLCF
int luaS_eqlngstr(TString *a, TString *b)
#define eqshrstr(a, b)
#define luai_numeq(a, b)
#define LUA_TNUMINT
#define ttnov(o)
#define LUA_TNUMFLT
void luaT_callTM(lua_State *L, const TValue *f, const TValue *p1, const TValue *p2, TValue *p3, int hasres)
#define tointeger(o, i)

References bvalue, eqshrstr, F2Ieq, fasttm, fltvalue, fvalue, gcvalue, hvalue, ivalue, l_isfalse, LUA_TBOOLEAN, LUA_TLCF, LUA_TLIGHTUSERDATA, LUA_TLNGSTR, LUA_TNIL, LUA_TNUMBER, LUA_TNUMFLT, LUA_TNUMINT, LUA_TSHRSTR, LUA_TTABLE, LUA_TUSERDATA, LUA_VFALSE, LUA_VLCF, LUA_VLIGHTUSERDATA, LUA_VLNGSTR, LUA_VNIL, LUA_VNUMFLT, LUA_VNUMINT, LUA_VSHRSTR, LUA_VTABLE, LUA_VTRUE, LUA_VUSERDATA, luai_numeq, luaS_eqlngstr(), luaT_callTM(), luaT_callTMres(), luaV_tointegerns(), NULL, pvalue, s2v, TM_EQ, tointeger, lua_State::top, tsvalue, ttnov, ttype, ttypetag, and uvalue.

Referenced by lua_compare(), luaV_execute(), and luaV_execute().

◆ luaV_execute()

LUAI_FUNC void luaV_execute ( lua_State * L,
CallInfo * ci )

Definition at line 1129 of file lua-5.4.3/src/lvm.c.

1129 {
1130 LClosure *cl;
1131 TValue *k;
1132 StkId base;
1133 const Instruction *pc;
1134 int trap;
1135#if LUA_USE_JUMPTABLE
1136#include "ljumptab.h"
1137#endif
1138 startfunc:
1139 trap = L->hookmask;
1140 returning: /* trap already set */
1141 cl = clLvalue(s2v(ci->func));
1142 k = cl->p->k;
1143 pc = ci->u.l.savedpc;
1144 if (l_unlikely(trap)) {
1145 if (pc == cl->p->code) { /* first instruction (not resuming)? */
1146 if (cl->p->is_vararg)
1147 trap = 0; /* hooks will start after VARARGPREP instruction */
1148 else /* check 'call' hook */
1149 luaD_hookcall(L, ci);
1150 }
1151 ci->u.l.trap = 1; /* assume trap is on, for now */
1152 }
1153 base = ci->func + 1;
1154 /* main loop of interpreter */
1155 for (;;) {
1156 Instruction i; /* instruction being executed */
1157 StkId ra; /* instruction's A register */
1158 vmfetch();
1159// low-level line tracing for debugging Lua
1160// printf("line: %d\n", luaG_getfuncline(cl->p, pcRel(pc, cl->p)));
1161 lua_assert(base == ci->func + 1);
1162 lua_assert(base <= L->top && L->top < L->stack_last);
1163 /* invalidate top for instructions not expecting it */
1164 lua_assert(isIT(i) || (cast_void(L->top = base), 1));
1165 vmdispatch (GET_OPCODE(i)) {
1166 vmcase(OP_MOVE) {
1167 setobjs2s(L, ra, RB(i));
1168 vmbreak;
1169 }
1170 vmcase(OP_LOADI) {
1171 lua_Integer b = GETARG_sBx(i);
1172 setivalue(s2v(ra), b);
1173 vmbreak;
1174 }
1175 vmcase(OP_LOADF) {
1176 int b = GETARG_sBx(i);
1177 setfltvalue(s2v(ra), cast_num(b));
1178 vmbreak;
1179 }
1180 vmcase(OP_LOADK) {
1181 TValue *rb = k + GETARG_Bx(i);
1182 setobj2s(L, ra, rb);
1183 vmbreak;
1184 }
1185 vmcase(OP_LOADKX) {
1186 TValue *rb;
1187 rb = k + GETARG_Ax(*pc); pc++;
1188 setobj2s(L, ra, rb);
1189 vmbreak;
1190 }
1192 setbfvalue(s2v(ra));
1193 vmbreak;
1194 }
1196 setbfvalue(s2v(ra));
1197 pc++; /* skip next instruction */
1198 vmbreak;
1199 }
1201 setbtvalue(s2v(ra));
1202 vmbreak;
1203 }
1205 int b = GETARG_B(i);
1206 do {
1207 setnilvalue(s2v(ra++));
1208 } while (b--);
1209 vmbreak;
1210 }
1212 int b = GETARG_B(i);
1213 setobj2s(L, ra, cl->upvals[b]->v);
1214 vmbreak;
1215 }
1217 UpVal *uv = cl->upvals[GETARG_B(i)];
1218 setobj(L, uv->v, s2v(ra));
1219 luaC_barrier(L, uv, s2v(ra));
1220 vmbreak;
1221 }
1223 const TValue *slot;
1224 TValue *upval = cl->upvals[GETARG_B(i)]->v;
1225 TValue *rc = KC(i);
1226 TString *key = tsvalue(rc); /* key must be a string */
1227 if (luaV_fastget(L, upval, key, slot, luaH_getshortstr)) {
1228 setobj2s(L, ra, slot);
1229 }
1230 else
1231 Protect(luaV_finishget(L, upval, rc, ra, slot));
1232 vmbreak;
1233 }
1235 const TValue *slot;
1236 TValue *rb = vRB(i);
1237 TValue *rc = vRC(i);
1238 lua_Unsigned n;
1239 if (ttisinteger(rc) /* fast track for integers? */
1240 ? (cast_void(n = ivalue(rc)), luaV_fastgeti(L, rb, n, slot))
1241 : luaV_fastget(L, rb, rc, slot, luaH_get)) {
1242 setobj2s(L, ra, slot);
1243 }
1244 else
1245 Protect(luaV_finishget(L, rb, rc, ra, slot));
1246 vmbreak;
1247 }
1248 vmcase(OP_GETI) {
1249 const TValue *slot;
1250 TValue *rb = vRB(i);
1251 int c = GETARG_C(i);
1252 if (luaV_fastgeti(L, rb, c, slot)) {
1253 setobj2s(L, ra, slot);
1254 }
1255 else {
1256 TValue key;
1257 setivalue(&key, c);
1258 Protect(luaV_finishget(L, rb, &key, ra, slot));
1259 }
1260 vmbreak;
1261 }
1263 const TValue *slot;
1264 TValue *rb = vRB(i);
1265 TValue *rc = KC(i);
1266 TString *key = tsvalue(rc); /* key must be a string */
1267 if (luaV_fastget(L, rb, key, slot, luaH_getshortstr)) {
1268 setobj2s(L, ra, slot);
1269 }
1270 else
1271 Protect(luaV_finishget(L, rb, rc, ra, slot));
1272 vmbreak;
1273 }
1275 const TValue *slot;
1276 TValue *upval = cl->upvals[GETARG_A(i)]->v;
1277 TValue *rb = KB(i);
1278 TValue *rc = RKC(i);
1279 TString *key = tsvalue(rb); /* key must be a string */
1280 if (luaV_fastget(L, upval, key, slot, luaH_getshortstr)) {
1281 luaV_finishfastset(L, upval, slot, rc);
1282 }
1283 else
1284 Protect(luaV_finishset(L, upval, rb, rc, slot));
1285 vmbreak;
1286 }
1288 const TValue *slot;
1289 TValue *rb = vRB(i); /* key (table is in 'ra') */
1290 TValue *rc = RKC(i); /* value */
1291 lua_Unsigned n;
1292 if (ttisinteger(rb) /* fast track for integers? */
1293 ? (cast_void(n = ivalue(rb)), luaV_fastgeti(L, s2v(ra), n, slot))
1294 : luaV_fastget(L, s2v(ra), rb, slot, luaH_get)) {
1295 luaV_finishfastset(L, s2v(ra), slot, rc);
1296 }
1297 else
1298 Protect(luaV_finishset(L, s2v(ra), rb, rc, slot));
1299 vmbreak;
1300 }
1301 vmcase(OP_SETI) {
1302 const TValue *slot;
1303 int c = GETARG_B(i);
1304 TValue *rc = RKC(i);
1305 if (luaV_fastgeti(L, s2v(ra), c, slot)) {
1306 luaV_finishfastset(L, s2v(ra), slot, rc);
1307 }
1308 else {
1309 TValue key;
1310 setivalue(&key, c);
1311 Protect(luaV_finishset(L, s2v(ra), &key, rc, slot));
1312 }
1313 vmbreak;
1314 }
1316 const TValue *slot;
1317 TValue *rb = KB(i);
1318 TValue *rc = RKC(i);
1319 TString *key = tsvalue(rb); /* key must be a string */
1320 if (luaV_fastget(L, s2v(ra), key, slot, luaH_getshortstr)) {
1321 luaV_finishfastset(L, s2v(ra), slot, rc);
1322 }
1323 else
1324 Protect(luaV_finishset(L, s2v(ra), rb, rc, slot));
1325 vmbreak;
1326 }
1328 int b = GETARG_B(i); /* log2(hash size) + 1 */
1329 int c = GETARG_C(i); /* array size */
1330 Table *t;
1331 if (b > 0)
1332 b = 1 << (b - 1); /* size is 2^(b - 1) */
1333 lua_assert((!TESTARG_k(i)) == (GETARG_Ax(*pc) == 0));
1334 if (TESTARG_k(i)) /* non-zero extra argument? */
1335 c += GETARG_Ax(*pc) * (MAXARG_C + 1); /* add it to size */
1336 pc++; /* skip extra argument */
1337 L->top = ra + 1; /* correct top in case of emergency GC */
1338 t = luaH_new(L); /* memory allocation */
1339 sethvalue2s(L, ra, t);
1340 if (b != 0 || c != 0)
1341 luaH_resize(L, t, c, b); /* idem */
1342 checkGC(L, ra + 1);
1343 vmbreak;
1344 }
1345 vmcase(OP_SELF) {
1346 const TValue *slot;
1347 TValue *rb = vRB(i);
1348 TValue *rc = RKC(i);
1349 TString *key = tsvalue(rc); /* key must be a string */
1350 setobj2s(L, ra + 1, rb);
1351 if (luaV_fastget(L, rb, key, slot, luaH_getstr)) {
1352 setobj2s(L, ra, slot);
1353 }
1354 else
1355 Protect(luaV_finishget(L, rb, rc, ra, slot));
1356 vmbreak;
1357 }
1358 vmcase(OP_ADDI) {
1360 vmbreak;
1361 }
1362 vmcase(OP_ADDK) {
1364 vmbreak;
1365 }
1366 vmcase(OP_SUBK) {
1368 vmbreak;
1369 }
1370 vmcase(OP_MULK) {
1372 vmbreak;
1373 }
1374 vmcase(OP_MODK) {
1376 vmbreak;
1377 }
1378 vmcase(OP_POWK) {
1380 vmbreak;
1381 }
1382 vmcase(OP_DIVK) {
1384 vmbreak;
1385 }
1386 vmcase(OP_IDIVK) {
1388 vmbreak;
1389 }
1390 vmcase(OP_BANDK) {
1391 op_bitwiseK(L, l_band);
1392 vmbreak;
1393 }
1394 vmcase(OP_BORK) {
1395 op_bitwiseK(L, l_bor);
1396 vmbreak;
1397 }
1398 vmcase(OP_BXORK) {
1399 op_bitwiseK(L, l_bxor);
1400 vmbreak;
1401 }
1402 vmcase(OP_SHRI) {
1403 TValue *rb = vRB(i);
1404 int ic = GETARG_sC(i);
1405 lua_Integer ib;
1406 if (tointegerns(rb, &ib)) {
1407 pc++; setivalue(s2v(ra), luaV_shiftl(ib, -ic));
1408 }
1409 vmbreak;
1410 }
1411 vmcase(OP_SHLI) {
1412 TValue *rb = vRB(i);
1413 int ic = GETARG_sC(i);
1414 lua_Integer ib;
1415 if (tointegerns(rb, &ib)) {
1416 pc++; setivalue(s2v(ra), luaV_shiftl(ic, ib));
1417 }
1418 vmbreak;
1419 }
1420 vmcase(OP_ADD) {
1422 vmbreak;
1423 }
1424 vmcase(OP_SUB) {
1426 vmbreak;
1427 }
1428 vmcase(OP_MUL) {
1430 vmbreak;
1431 }
1432 vmcase(OP_MOD) {
1434 vmbreak;
1435 }
1436 vmcase(OP_POW) {
1438 vmbreak;
1439 }
1440 vmcase(OP_DIV) { /* float division (always with floats) */
1442 vmbreak;
1443 }
1444 vmcase(OP_IDIV) { /* floor division */
1446 vmbreak;
1447 }
1448 vmcase(OP_BAND) {
1449 op_bitwise(L, l_band);
1450 vmbreak;
1451 }
1452 vmcase(OP_BOR) {
1453 op_bitwise(L, l_bor);
1454 vmbreak;
1455 }
1456 vmcase(OP_BXOR) {
1457 op_bitwise(L, l_bxor);
1458 vmbreak;
1459 }
1460 vmcase(OP_SHR) {
1462 vmbreak;
1463 }
1464 vmcase(OP_SHL) {
1466 vmbreak;
1467 }
1468 vmcase(OP_MMBIN) {
1469 Instruction pi = *(pc - 2); /* original arith. expression */
1470 TValue *rb = vRB(i);
1471 TMS tm = (TMS)GETARG_C(i);
1472 StkId result = RA(pi);
1473 lua_assert(OP_ADD <= GET_OPCODE(pi) && GET_OPCODE(pi) <= OP_SHR);
1474 Protect(luaT_trybinTM(L, s2v(ra), rb, result, tm));
1475 vmbreak;
1476 }
1477 vmcase(OP_MMBINI) {
1478 Instruction pi = *(pc - 2); /* original arith. expression */
1479 int imm = GETARG_sB(i);
1480 TMS tm = (TMS)GETARG_C(i);
1481 int flip = GETARG_k(i);
1482 StkId result = RA(pi);
1483 Protect(luaT_trybiniTM(L, s2v(ra), imm, flip, result, tm));
1484 vmbreak;
1485 }
1486 vmcase(OP_MMBINK) {
1487 Instruction pi = *(pc - 2); /* original arith. expression */
1488 TValue *imm = KB(i);
1489 TMS tm = (TMS)GETARG_C(i);
1490 int flip = GETARG_k(i);
1491 StkId result = RA(pi);
1492 Protect(luaT_trybinassocTM(L, s2v(ra), imm, flip, result, tm));
1493 vmbreak;
1494 }
1495 vmcase(OP_UNM) {
1496 TValue *rb = vRB(i);
1497 lua_Number nb;
1498 if (ttisinteger(rb)) {
1499 lua_Integer ib = ivalue(rb);
1500 setivalue(s2v(ra), intop(-, 0, ib));
1501 }
1502 else if (tonumberns(rb, nb)) {
1503 setfltvalue(s2v(ra), luai_numunm(L, nb));
1504 }
1505 else
1506 Protect(luaT_trybinTM(L, rb, rb, ra, TM_UNM));
1507 vmbreak;
1508 }
1509 vmcase(OP_BNOT) {
1510 TValue *rb = vRB(i);
1511 lua_Integer ib;
1512 if (tointegerns(rb, &ib)) {
1513 setivalue(s2v(ra), intop(^, ~l_castS2U(0), ib));
1514 }
1515 else
1516 Protect(luaT_trybinTM(L, rb, rb, ra, TM_BNOT));
1517 vmbreak;
1518 }
1519 vmcase(OP_NOT) {
1520 TValue *rb = vRB(i);
1521 if (l_isfalse(rb))
1522 setbtvalue(s2v(ra));
1523 else
1524 setbfvalue(s2v(ra));
1525 vmbreak;
1526 }
1527 vmcase(OP_LEN) {
1528 Protect(luaV_objlen(L, ra, vRB(i)));
1529 vmbreak;
1530 }
1531 vmcase(OP_CONCAT) {
1532 int n = GETARG_B(i); /* number of elements to concatenate */
1533 L->top = ra + n; /* mark the end of concat operands */
1534 ProtectNT(luaV_concat(L, n));
1535 checkGC(L, L->top); /* 'luaV_concat' ensures correct top */
1536 vmbreak;
1537 }
1538 vmcase(OP_CLOSE) {
1539 Protect(luaF_close(L, ra, LUA_OK, 1));
1540 vmbreak;
1541 }
1542 vmcase(OP_TBC) {
1543 /* create new to-be-closed upvalue */
1545 vmbreak;
1546 }
1547 vmcase(OP_JMP) {
1548 dojump(ci, i, 0);
1549 vmbreak;
1550 }
1551 vmcase(OP_EQ) {
1552 int cond;
1553 TValue *rb = vRB(i);
1554 Protect(cond = luaV_equalobj(L, s2v(ra), rb));
1555 docondjump();
1556 vmbreak;
1557 }
1558 vmcase(OP_LT) {
1560 vmbreak;
1561 }
1562 vmcase(OP_LE) {
1564 vmbreak;
1565 }
1566 vmcase(OP_EQK) {
1567 TValue *rb = KB(i);
1568 /* basic types do not use '__eq'; we can use raw equality */
1569 int cond = luaV_rawequalobj(s2v(ra), rb);
1570 docondjump();
1571 vmbreak;
1572 }
1573 vmcase(OP_EQI) {
1574 int cond;
1575 int im = GETARG_sB(i);
1576 if (ttisinteger(s2v(ra)))
1577 cond = (ivalue(s2v(ra)) == im);
1578 else if (ttisfloat(s2v(ra)))
1579 cond = luai_numeq(fltvalue(s2v(ra)), cast_num(im));
1580 else
1581 cond = 0; /* other types cannot be equal to a number */
1582 docondjump();
1583 vmbreak;
1584 }
1585 vmcase(OP_LTI) {
1587 vmbreak;
1588 }
1589 vmcase(OP_LEI) {
1591 vmbreak;
1592 }
1593 vmcase(OP_GTI) {
1595 vmbreak;
1596 }
1597 vmcase(OP_GEI) {
1599 vmbreak;
1600 }
1601 vmcase(OP_TEST) {
1602 int cond = !l_isfalse(s2v(ra));
1603 docondjump();
1604 vmbreak;
1605 }
1607 TValue *rb = vRB(i);
1608 if (l_isfalse(rb) == GETARG_k(i))
1609 pc++;
1610 else {
1611 setobj2s(L, ra, rb);
1612 donextjump(ci);
1613 }
1614 vmbreak;
1615 }
1616 vmcase(OP_CALL) {
1617 CallInfo *newci;
1618 int b = GETARG_B(i);
1619 int nresults = GETARG_C(i) - 1;
1620 if (b != 0) /* fixed number of arguments? */
1621 L->top = ra + b; /* top signals number of arguments */
1622 /* else previous instruction set top */
1623 savepc(L); /* in case of errors */
1624 if ((newci = luaD_precall(L, ra, nresults)) == NULL)
1625 updatetrap(ci); /* C call; nothing else to be done */
1626 else { /* Lua call: run function in this same C frame */
1627 ci = newci;
1628 ci->callstatus = 0; /* call re-uses 'luaV_execute' */
1629 goto startfunc;
1630 }
1631 vmbreak;
1632 }
1634 int b = GETARG_B(i); /* number of arguments + 1 (function) */
1635 int nparams1 = GETARG_C(i);
1636 /* delta is virtual 'func' - real 'func' (vararg functions) */
1637 int delta = (nparams1) ? ci->u.l.nextraargs + nparams1 : 0;
1638 if (b != 0)
1639 L->top = ra + b;
1640 else /* previous instruction set top */
1641 b = cast_int(L->top - ra);
1642 savepc(ci); /* several calls here can raise errors */
1643 if (TESTARG_k(i)) {
1644 luaF_closeupval(L, base); /* close upvalues from current call */
1645 lua_assert(L->tbclist < base); /* no pending tbc variables */
1646 lua_assert(base == ci->func + 1);
1647 }
1648 while (!ttisfunction(s2v(ra))) { /* not a function? */
1649 luaD_tryfuncTM(L, ra); /* try '__call' metamethod */
1650 b++; /* there is now one extra argument */
1651 checkstackGCp(L, 1, ra);
1652 }
1653 if (!ttisLclosure(s2v(ra))) { /* C function? */
1654 luaD_precall(L, ra, LUA_MULTRET); /* call it */
1655 updatetrap(ci);
1656 updatestack(ci); /* stack may have been relocated */
1657 ci->func -= delta; /* restore 'func' (if vararg) */
1658 luaD_poscall(L, ci, cast_int(L->top - ra)); /* finish caller */
1659 updatetrap(ci); /* 'luaD_poscall' can change hooks */
1660 goto ret; /* caller returns after the tail call */
1661 }
1662 ci->func -= delta; /* restore 'func' (if vararg) */
1663 luaD_pretailcall(L, ci, ra, b); /* prepare call frame */
1664 goto startfunc; /* execute the callee */
1665 }
1666 vmcase(OP_RETURN) {
1667 int n = GETARG_B(i) - 1; /* number of results */
1668 int nparams1 = GETARG_C(i);
1669 if (n < 0) /* not fixed? */
1670 n = cast_int(L->top - ra); /* get what is available */
1671 savepc(ci);
1672 if (TESTARG_k(i)) { /* may there be open upvalues? */
1673 if (L->top < ci->top)
1674 L->top = ci->top;
1675 luaF_close(L, base, CLOSEKTOP, 1);
1676 updatetrap(ci);
1677 updatestack(ci);
1678 }
1679 if (nparams1) /* vararg function? */
1680 ci->func -= ci->u.l.nextraargs + nparams1;
1681 L->top = ra + n; /* set call for 'luaD_poscall' */
1682 luaD_poscall(L, ci, n);
1683 updatetrap(ci); /* 'luaD_poscall' can change hooks */
1684 goto ret;
1685 }
1687 if (l_unlikely(L->hookmask)) {
1688 L->top = ra;
1689 savepc(ci);
1690 luaD_poscall(L, ci, 0); /* no hurry... */
1691 trap = 1;
1692 }
1693 else { /* do the 'poscall' here */
1694 int nres;
1695 L->ci = ci->previous; /* back to caller */
1696 L->top = base - 1;
1697 for (nres = ci->nresults; l_unlikely(nres > 0); nres--)
1698 setnilvalue(s2v(L->top++)); /* all results are nil */
1699 }
1700 goto ret;
1701 }
1703 if (l_unlikely(L->hookmask)) {
1704 L->top = ra + 1;
1705 savepc(ci);
1706 luaD_poscall(L, ci, 1); /* no hurry... */
1707 trap = 1;
1708 }
1709 else { /* do the 'poscall' here */
1710 int nres = ci->nresults;
1711 L->ci = ci->previous; /* back to caller */
1712 if (nres == 0)
1713 L->top = base - 1; /* asked for no results */
1714 else {
1715 setobjs2s(L, base - 1, ra); /* at least this result */
1716 L->top = base;
1717 for (; l_unlikely(nres > 1); nres--)
1718 setnilvalue(s2v(L->top++)); /* complete missing results */
1719 }
1720 }
1721 ret: /* return from a Lua function */
1722 if (ci->callstatus & CIST_FRESH)
1723 return; /* end this frame */
1724 else {
1725 ci = ci->previous;
1726 goto returning; /* continue running caller in this frame */
1727 }
1728 }
1730 if (ttisinteger(s2v(ra + 2))) { /* integer loop? */
1731 lua_Unsigned count = l_castS2U(ivalue(s2v(ra + 1)));
1732 if (count > 0) { /* still more iterations? */
1733 lua_Integer step = ivalue(s2v(ra + 2));
1734 lua_Integer idx = ivalue(s2v(ra)); /* internal index */
1735 chgivalue(s2v(ra + 1), count - 1); /* update counter */
1736 idx = intop(+, idx, step); /* add step to index */
1737 chgivalue(s2v(ra), idx); /* update internal index */
1738 setivalue(s2v(ra + 3), idx); /* and control variable */
1739 pc -= GETARG_Bx(i); /* jump back */
1740 }
1741 }
1742 else if (floatforloop(ra)) /* float loop */
1743 pc -= GETARG_Bx(i); /* jump back */
1744 updatetrap(ci); /* allows a signal to break the loop */
1745 vmbreak;
1746 }
1748 savestate(L, ci); /* in case of errors */
1749 if (forprep(L, ra))
1750 pc += GETARG_Bx(i) + 1; /* skip the loop */
1751 vmbreak;
1752 }
1754 /* create to-be-closed upvalue (if needed) */
1755 halfProtect(luaF_newtbcupval(L, ra + 3));
1756 pc += GETARG_Bx(i);
1757 i = *(pc++); /* go to next instruction */
1758 lua_assert(GET_OPCODE(i) == OP_TFORCALL && ra == RA(i));
1759 goto l_tforcall;
1760 }
1762 l_tforcall:
1763 /* 'ra' has the iterator function, 'ra + 1' has the state,
1764 'ra + 2' has the control variable, and 'ra + 3' has the
1765 to-be-closed variable. The call will use the stack after
1766 these values (starting at 'ra + 4')
1767 */
1768 /* push function, state, and control variable */
1769 memcpy(ra + 4, ra, 3 * sizeof(*ra));
1770 L->top = ra + 4 + 3;
1771 ProtectNT(luaD_call(L, ra + 4, GETARG_C(i))); /* do the call */
1772 updatestack(ci); /* stack may have changed */
1773 i = *(pc++); /* go to next instruction */
1774 lua_assert(GET_OPCODE(i) == OP_TFORLOOP && ra == RA(i));
1775 goto l_tforloop;
1776 }
1778 l_tforloop:
1779 if (!ttisnil(s2v(ra + 4))) { /* continue loop? */
1780 setobjs2s(L, ra + 2, ra + 4); /* save control variable */
1781 pc -= GETARG_Bx(i); /* jump back */
1782 }
1783 vmbreak;
1784 }
1786 int n = GETARG_B(i);
1787 unsigned int last = GETARG_C(i);
1788 Table *h = hvalue(s2v(ra));
1789 if (n == 0)
1790 n = cast_int(L->top - ra) - 1; /* get up to the top */
1791 else
1792 L->top = ci->top; /* correct top in case of emergency GC */
1793 last += n;
1794 if (TESTARG_k(i)) {
1795 last += GETARG_Ax(*pc) * (MAXARG_C + 1);
1796 pc++;
1797 }
1798 if (last > luaH_realasize(h)) /* needs more space? */
1799 luaH_resizearray(L, h, last); /* preallocate it at once */
1800 for (; n > 0; n--) {
1801 TValue *val = s2v(ra + n);
1802 setobj2t(L, &h->array[last - 1], val);
1803 last--;
1804 luaC_barrierback(L, obj2gco(h), val);
1805 }
1806 vmbreak;
1807 }
1809 Proto *p = cl->p->p[GETARG_Bx(i)];
1810 halfProtect(pushclosure(L, p, cl->upvals, base, ra));
1811 checkGC(L, ra + 1);
1812 vmbreak;
1813 }
1814 vmcase(OP_VARARG) {
1815 int n = GETARG_C(i) - 1; /* required results */
1816 Protect(luaT_getvarargs(L, ci, ra, n));
1817 vmbreak;
1818 }
1820 ProtectNT(luaT_adjustvarargs(L, GETARG_A(i), ci, cl->p));
1821 if (l_unlikely(trap)) { /* previous "Protect" updated trap */
1822 luaD_hookcall(L, ci);
1823 L->oldpc = 1; /* next opcode will be seen as a "new" line */
1824 }
1825 updatebase(ci); /* function has new base after adjustment */
1826 vmbreak;
1827 }
1829 lua_assert(0);
1830 vmbreak;
1831 }
1832 }
1833 }
1834}
int luaD_precall(lua_State *L, StkId func, int nresults)
void luaD_call(lua_State *L, StkId func, int nResults)
int luaD_poscall(lua_State *L, StkId firstResult)
void luaF_close(lua_State *L, StkId level)
#define luaC_barrier(L, p, v)
lu_int32 Instruction
#define cast_int(i)
#define setobj2s
#define sethvalue2s
#define ttisfunction(o)
#define ttisnil(o)
#define setobj(L, obj1, obj2)
#define setnilvalue(obj)
#define MAXARG_C
#define GETARG_A(i)
#define GETARG_sBx(i)
#define GETARG_B(i)
#define GET_OPCODE(i)
#define GETARG_Bx(i)
#define GETARG_C(i)
static int cond(LexState *ls)
#define obj2gco(v)
const TValue * luaH_get(Table *t, const TValue *key)
Table * luaH_new(lua_State *L, int narray, int nhash)
const TValue * luaH_getstr(Table *t, TString *key)
void luaH_resizearray(lua_State *L, Table *t, int nasize)
@ TM_UNM
@ TM_LE
@ TM_LT
#define LUA_MULTRET
LUA_NUMBER lua_Number
#define luaC_barrierback(L, p, v)
#define ttisLclosure(o)
#define clLvalue(o)
#define GETARG_Ax(i)
void luaH_resize(lua_State *L, Table *t, int nasize, int nhsize)
LUA_UNSIGNED lua_Unsigned
#define LUA_OK
#define luaV_rawequalobj(o1, o2)
#define luai_nummul(L, a, b)
#define luai_numdiv(L, a, b)
#define luai_numpow(L, a, b)
#define cast_void(i)
#define luai_numunm(L, a)
#define luai_numsub(L, a, b)
#define luai_numidiv(L, a, b)
#define luai_numlt(a, b)
#define luai_numadd(L, a, b)
#define luai_numle(a, b)
#define chgivalue(obj, x)
#define setfltvalue(obj, x)
#define setivalue(obj, x)
#define CIST_FRESH
const TValue * luaH_getshortstr(Table *t, TString *key)
void luaT_trybinTM(lua_State *L, const TValue *p1, const TValue *p2, StkId res, TMS event)
@ TM_BNOT
#define luaV_fastget(L, t, k, slot, f)
#define intop(op, v1, v2)
void luaD_pretailcall(lua_State *L, CallInfo *ci, StkId func, int narg1)
void luaD_hookcall(lua_State *L, CallInfo *ci)
void luaD_tryfuncTM(lua_State *L, StkId func)
#define checkstackGCp(L, n, p)
void luaF_newtbcupval(lua_State *L, StkId level)
void luaF_closeupval(lua_State *L, StkId level)
#define CLOSEKTOP
#define luai_numgt(a, b)
#define luai_numge(a, b)
#define setbtvalue(obj)
#define s2v(o)
#define setbfvalue(obj)
#define GETARG_sC(i)
#define GETARG_sB(i)
#define TESTARG_k(i)
#define GETARG_k(i)
#define isIT(i)
LUAI_FUNC unsigned int luaH_realasize(const Table *t)
void luaT_adjustvarargs(lua_State *L, int nfixparams, CallInfo *ci, const Proto *p)
void luaT_trybiniTM(lua_State *L, const TValue *p1, lua_Integer i2, int flip, StkId res, TMS event)
void luaT_trybinassocTM(lua_State *L, const TValue *p1, const TValue *p2, int flip, StkId res, TMS event)
void luaT_getvarargs(lua_State *L, CallInfo *ci, StkId where, int wanted)
#define checkGC(L, c)
#define vRC(i)
#define KB(i)
static int lessthanothers(lua_State *L, const TValue *l, const TValue *r)
#define dojump(ci, i, e)
#define luaV_shiftr(x, y)
#define l_bxor(a, b)
void luaV_finishset(lua_State *L, const TValue *t, TValue *key, TValue *val, const TValue *slot)
static int LTnum(const TValue *l, const TValue *r)
#define ProtectNT(exp)
#define RB(i)
#define l_band(a, b)
#define op_arithfK(L, fop)
#define l_bor(a, b)
void luaV_concat(lua_State *L, int total)
#define vmbreak
#define l_gei(a, b)
#define op_arithf(L, fop)
#define op_order(L, opi, opn, other)
void luaV_finishget(lua_State *L, const TValue *t, TValue *key, StkId val, const TValue *slot)
int luaV_equalobj(lua_State *L, const TValue *t1, const TValue *t2)
static void pushclosure(lua_State *L, Proto *p, UpVal **encup, StkId base, StkId ra)
#define l_lti(a, b)
#define op_bitwiseK(L, op)
#define savestate(L, ci)
#define RKC(i)
#define vmcase(l)
#define op_arithI(L, iop, fop)
#define op_bitwise(L, op)
#define RA(i)
#define vRB(i)
#define l_muli(L, a, b)
lua_Integer luaV_idiv(lua_State *L, lua_Integer m, lua_Integer n)
#define halfProtect(exp)
static int forprep(lua_State *L, StkId ra)
#define updatebase(ci)
#define l_gti(a, b)
static int lessequalothers(lua_State *L, const TValue *l, const TValue *r)
#define updatestack(ci)
static int LEnum(const TValue *l, const TValue *r)
void luaV_objlen(lua_State *L, StkId ra, const TValue *rb)
#define donextjump(ci)
#define updatetrap(ci)
lua_Number luaV_modf(lua_State *L, lua_Number m, lua_Number n)
#define KC(i)
#define op_orderI(L, opi, opf, inv, tm)
#define op_arith(L, iop, fop)
#define l_addi(L, a, b)
#define l_subi(L, a, b)
lua_Integer luaV_shiftl(lua_Integer x, lua_Integer y)
static int floatforloop(StkId ra)
#define Protect(exp)
#define vmfetch()
#define vmdispatch(o)
#define l_lei(a, b)
#define savepc(L)
lua_Integer luaV_mod(lua_State *L, lua_Integer m, lua_Integer n)
#define docondjump()
#define op_arithK(L, iop, fop)
#define tointegerns(o, i)
#define tonumberns(o, n)
#define luaV_fastgeti(L, t, k, slot)
#define luaV_finishfastset(L, t, slot, v)
volatile l_signalT trap
struct CallInfo * previous
struct CallInfo::@64::@65 l
const Instruction * savedpc
union CallInfo::@64 u
struct Proto * p
Instruction * code
struct Proto ** p
const Instruction * oldpc

References Table::array, CallInfo::callstatus, cast_int, cast_num, cast_void, checkGC, checkstackGCp, chgivalue, lua_State::ci, CIST_FRESH, clLvalue, CLOSEKTOP, Proto::code, cond(), docondjump, dojump, donextjump, floatforloop(), fltvalue, forprep(), CallInfo::func, GET_OPCODE, GETARG_A, GETARG_Ax, GETARG_B, GETARG_Bx, GETARG_C, GETARG_k, GETARG_sB, GETARG_sBx, GETARG_sC, halfProtect, lua_State::hookmask, hvalue, intop, Proto::is_vararg, isIT, ivalue, Proto::k, KB, KC, CallInfo::l, l_addi, l_band, l_bor, l_bxor, l_castS2U, l_gei, l_gti, l_isfalse, l_lei, l_lti, l_muli, l_subi, LEnum(), lessequalothers(), lessthanothers(), LTnum(), lua_assert, LUA_MULTRET, LUA_OK, luaC_barrier, luaC_barrierback, luaD_call(), luaD_hookcall(), luaD_poscall(), luaD_precall(), luaD_pretailcall(), luaD_tryfuncTM(), luaF_close(), luaF_closeupval(), luaF_newtbcupval(), luaH_get(), luaH_getshortstr(), luaH_getstr(), luaH_new(), luaH_realasize(), luaH_resize(), luaH_resizearray(), luai_numadd, luai_numdiv, luai_numeq, luai_numge, luai_numgt, luai_numidiv, luai_numle, luai_numlt, luai_nummul, luai_numpow, luai_numsub, luai_numunm, luaT_adjustvarargs(), luaT_getvarargs(), luaT_trybinassocTM(), luaT_trybiniTM(), luaT_trybinTM(), luaV_concat(), luaV_equalobj(), luaV_fastget, luaV_fastgeti, luaV_finishfastset, luaV_finishget(), luaV_finishset(), luaV_idiv(), luaV_mod(), luaV_modf(), luaV_objlen(), luaV_rawequalobj, luaV_shiftl(), luaV_shiftr, MAXARG_C, CallInfo::nextraargs, CallInfo::nresults, NULL, obj2gco, lua_State::oldpc, OP_ADD, OP_ADDI, OP_ADDK, op_arith, op_arithf, op_arithfK, op_arithI, op_arithK, OP_BAND, OP_BANDK, op_bitwise, op_bitwiseK, OP_BNOT, OP_BOR, OP_BORK, OP_BXOR, OP_BXORK, OP_CALL, OP_CLOSE, OP_CLOSURE, OP_CONCAT, OP_DIV, OP_DIVK, OP_EQ, OP_EQI, OP_EQK, OP_EXTRAARG, OP_FORLOOP, OP_FORPREP, OP_GEI, OP_GETFIELD, OP_GETI, OP_GETTABLE, OP_GETTABUP, OP_GETUPVAL, OP_GTI, OP_IDIV, OP_IDIVK, OP_JMP, OP_LE, OP_LEI, OP_LEN, OP_LFALSESKIP, OP_LOADF, OP_LOADFALSE, OP_LOADI, OP_LOADK, OP_LOADKX, OP_LOADNIL, OP_LOADTRUE, OP_LT, OP_LTI, OP_MMBIN, OP_MMBINI, OP_MMBINK, OP_MOD, OP_MODK, OP_MOVE, OP_MUL, OP_MULK, OP_NEWTABLE, OP_NOT, op_order, op_orderI, OP_POW, OP_POWK, OP_RETURN, OP_RETURN0, OP_RETURN1, OP_SELF, OP_SETFIELD, OP_SETI, OP_SETLIST, OP_SETTABLE, OP_SETTABUP, OP_SETUPVAL, OP_SHL, OP_SHLI, OP_SHR, OP_SHRI, OP_SUB, OP_SUBK, OP_TAILCALL, OP_TBC, OP_TEST, OP_TESTSET, OP_TFORCALL, OP_TFORLOOP, OP_TFORPREP, OP_UNM, OP_VARARG, OP_VARARGPREP, Proto::p, LClosure::p, CallInfo::previous, Protect, ProtectNT, pushclosure(), RA, RB, RKC, s2v, CallInfo::savedpc, savepc, savestate, setbfvalue, setbtvalue, setfltvalue, sethvalue2s, setivalue, setnilvalue, setobj, setobj2s, setobj2t, setobjs2s, lua_State::stack_last, lua_State::tbclist, TESTARG_k, TM_BNOT, TM_LE, TM_LT, TM_UNM, tointegerns, tonumberns, CallInfo::top, lua_State::top, CallInfo::trap, tsvalue, ttisfloat, ttisfunction, ttisinteger, ttisLclosure, ttisnil, CallInfo::u, updatebase, updatestack, updatetrap, LClosure::upvals, UpVal::v, vmbreak, vmcase, vmdispatch, vmfetch, vRB, and vRC.

◆ luaV_finishget()

LUAI_FUNC void luaV_finishget ( lua_State * L,
const TValue * t,
TValue * key,
StkId val,
const TValue * slot )

Definition at line 160 of file lua-5.3.6/src/lvm.c.

161 {
162 int loop; /* counter to avoid infinite loops */
163 const TValue *tm; /* metamethod */
164 for (loop = 0; loop < MAXTAGLOOP; loop++) {
165 if (slot == NULL) { /* 't' is not a table? */
167 tm = luaT_gettmbyobj(L, t, TM_INDEX);
168 if (ttisnil(tm))
169 luaG_typeerror(L, t, "index"); /* no metamethod */
170 /* else will try the metamethod */
171 }
172 else { /* 't' is a table */
173 lua_assert(ttisnil(slot));
174 tm = fasttm(L, hvalue(t)->metatable, TM_INDEX); /* table's metamethod */
175 if (tm == NULL) { /* no metamethod? */
176 setnilvalue(val); /* result is nil */
177 return;
178 }
179 /* else will try the metamethod */
180 }
181 if (ttisfunction(tm)) { /* is metamethod a function? */
182 luaT_callTM(L, tm, t, key, val, 1); /* call it */
183 return;
184 }
185 t = tm; /* else try to access 'tm[key]' */
186 if (luaV_fastget(L,t,key,slot,luaH_get)) { /* fast track? */
187 setobj2s(L, val, slot); /* done */
188 return;
189 }
190 /* else repeat (tail call 'luaV_finishget') */
191 }
192 luaG_runerror(L, "'__index' chain too long; possible loop");
193}
void luaG_typeerror(lua_State *L, const TValue *o, const char *op)
const TValue * luaT_gettmbyobj(lua_State *L, const TValue *o, TMS event)
@ TM_INDEX
#define MAXTAGLOOP

References fasttm, hvalue, isempty, lua_assert, luaG_runerror(), luaG_typeerror(), luaH_get(), luaT_callTM(), luaT_callTMres(), luaT_gettmbyobj(), luaV_fastget, MAXTAGLOOP, notm, NULL, s2v, setnilvalue, setobj2s, TM_INDEX, ttisfunction, ttisnil, and ttistable.

Referenced by auxgetstr(), auxgetstr(), lua_geti(), lua_gettable(), luaV_execute(), and luaV_execute().

◆ luaV_finishOp()

LUAI_FUNC void luaV_finishOp ( lua_State * L)

Definition at line 423 of file lua-5.2.4/src/lvm.c.

423 {
424 CallInfo *ci = L->ci;
425 StkId base = ci->u.l.base;
426 Instruction inst = *(ci->u.l.savedpc - 1); /* interrupted instruction */
427 OpCode op = GET_OPCODE(inst);
428 switch (op) { /* finish its execution */
429 case OP_ADD: case OP_SUB: case OP_MUL: case OP_DIV:
430 case OP_MOD: case OP_POW: case OP_UNM: case OP_LEN:
431 case OP_GETTABUP: case OP_GETTABLE: case OP_SELF: {
432 setobjs2s(L, base + GETARG_A(inst), --L->top);
433 break;
434 }
435 case OP_LE: case OP_LT: case OP_EQ: {
436 int res = !l_isfalse(L->top - 1);
437 L->top--;
438 /* metamethod should not be called when operand is K */
439 lua_assert(!ISK(GETARG_B(inst)));
440 if (op == OP_LE && /* "<=" using "<" instead? */
441 ttisnil(luaT_gettmbyobj(L, base + GETARG_B(inst), TM_LE)))
442 res = !res; /* invert result */
444 if (res != GETARG_A(inst)) /* condition failed? */
445 ci->u.l.savedpc++; /* skip jump instruction */
446 break;
447 }
448 case OP_CONCAT: {
449 StkId top = L->top - 1; /* top when 'call_binTM' was called */
450 int b = GETARG_B(inst); /* first element to concatenate */
451 int total = cast_int(top - 1 - (base + b)); /* yet to concatenate */
452 setobj2s(L, top - 2, top); /* put TM result in proper position */
453 if (total > 1) { /* are there elements to concat? */
454 L->top = top - 1; /* top is one after last element (at top-2) */
455 luaV_concat(L, total); /* concat them (may yield again) */
456 }
457 /* move final result to final position */
458 setobj2s(L, ci->u.l.base + GETARG_A(inst), L->top - 1);
459 L->top = ci->top; /* restore top */
460 break;
461 }
462 case OP_TFORCALL: {
464 L->top = ci->top; /* correct top */
465 break;
466 }
467 case OP_CALL: {
468 if (GETARG_C(inst) - 1 >= 0) /* nresults >= 0? */
469 L->top = ci->top; /* adjust results */
470 break;
471 }
472 case OP_TAILCALL: case OP_SETTABUP: case OP_SETTABLE:
473 break;
474 default: lua_assert(0);
475 }
476}
#define ISK(x)
void luaV_concat(lua_State *L, int total)

References CallInfo::base, CallInfo::callstatus, cast_int, lua_State::ci, CIST_LEQ, CallInfo::func, GET_OPCODE, GETARG_A, GETARG_B, GETARG_C, GETARG_k, ISK, CallInfo::l, l_isfalse, lua_assert, luaT_gettmbyobj(), luaV_concat(), OP_ADD, OP_BAND, OP_BNOT, OP_BOR, OP_BXOR, OP_CALL, OP_CLOSE, OP_CONCAT, OP_DIV, OP_EQ, OP_GEI, OP_GETFIELD, OP_GETI, OP_GETTABLE, OP_GETTABUP, OP_GTI, OP_IDIV, OP_JMP, OP_LE, OP_LEI, OP_LEN, OP_LT, OP_LTI, OP_MMBIN, OP_MMBINI, OP_MMBINK, OP_MOD, OP_MUL, OP_POW, OP_RETURN, OP_SELF, OP_SETFIELD, OP_SETI, OP_SETTABLE, OP_SETTABUP, OP_SHL, OP_SHR, OP_SUB, OP_TAILCALL, OP_TFORCALL, OP_TFORLOOP, OP_UNM, s2v, CallInfo::savedpc, setobj2s, setobjs2s, TM_LE, CallInfo::top, lua_State::top, ttisnil, and CallInfo::u.

Referenced by unroll(), unroll(), and unroll().

◆ luaV_finishset()

LUAI_FUNC void luaV_finishset ( lua_State * L,
const TValue * t,
TValue * key,
TValue * val,
const TValue * slot )

Definition at line 330 of file lua-5.4.3/src/lvm.c.

331 {
332 int loop; /* counter to avoid infinite loops */
333 for (loop = 0; loop < MAXTAGLOOP; loop++) {
334 const TValue *tm; /* '__newindex' metamethod */
335 if (slot != NULL) { /* is 't' a table? */
336 Table *h = hvalue(t); /* save 't' table */
337 lua_assert(isempty(slot)); /* slot must be empty */
338 tm = fasttm(L, h->metatable, TM_NEWINDEX); /* get metamethod */
339 if (tm == NULL) { /* no metamethod? */
340 luaH_finishset(L, h, key, slot, val); /* set new value */
342 luaC_barrierback(L, obj2gco(h), val);
343 return;
344 }
345 /* else will try the metamethod */
346 }
347 else { /* not a table; check metamethod */
348 tm = luaT_gettmbyobj(L, t, TM_NEWINDEX);
349 if (l_unlikely(notm(tm)))
350 luaG_typeerror(L, t, "index");
351 }
352 /* try the metamethod */
353 if (ttisfunction(tm)) {
354 luaT_callTM(L, tm, t, key, val);
355 return;
356 }
357 t = tm; /* else repeat assignment over 'tm' */
358 if (luaV_fastget(L, t, key, slot, luaH_get)) {
359 luaV_finishfastset(L, t, slot, val);
360 return; /* done */
361 }
362 /* else 'return luaV_finishset(L, t, key, val, slot)' (loop) */
363 }
364 luaG_runerror(L, "'__newindex' chain too long; possible loop");
365}
@ TM_NEWINDEX
#define invalidateTMcache(t)
void luaH_finishset(lua_State *L, Table *t, const TValue *key, const TValue *slot, TValue *value)
#define notm(tm)
#define MAXTAGLOOP
struct Table * metatable

References fasttm, hvalue, invalidateTMcache, isempty, lua_assert, luaC_barrierback, luaG_runerror(), luaG_typeerror(), luaH_finishset(), luaH_get(), luaT_callTM(), luaT_gettmbyobj(), luaV_fastget, luaV_finishfastset, MAXTAGLOOP, Table::metatable, notm, NULL, obj2gco, TM_NEWINDEX, and ttisfunction.

Referenced by luaV_execute().

◆ luaV_flttointeger()

LUAI_FUNC int luaV_flttointeger ( lua_Number n,
lua_Integer * p,
F2Imod mode )

Definition at line 121 of file lua-5.4.3/src/lvm.c.

121 {
122 lua_Number f = l_floor(n);
123 if (n != f) { /* not an integral value? */
124 if (mode == F2Ieq) return 0; /* fails if mode demands integral value */
125 else if (mode == F2Iceil) /* needs ceil? */
126 f += 1; /* convert floor to ceil (remember: n != f) */
127 }
128 return lua_numbertointeger(f, p);
129}
#define lua_numbertointeger(n, p)
#define l_floor(x)

References F2Iceil, F2Ieq, l_floor, and lua_numbertointeger.

Referenced by isSCnumber(), LEfloatint(), LEintfloat(), LTfloatint(), LTintfloat(), luaH_get(), luaH_newkey(), luaK_float(), and luaV_tointegerns().

◆ luaV_idiv()

Definition at line 718 of file lua-5.4.3/src/lvm.c.

718 {
719 if (l_unlikely(l_castS2U(n) + 1u <= 1u)) { /* special cases: -1 or 0 */
720 if (n == 0)
721 luaG_runerror(L, "attempt to divide by zero");
722 return intop(-, 0, m); /* n==-1; avoid overflow with 0x80000...//-1 */
723 }
724 else {
725 lua_Integer q = m / n; /* perform C division */
726 if ((m ^ n) < 0 && m % n != 0) /* 'm/n' would be negative non-integer? */
727 q -= 1; /* correct result for different rounding */
728 return q;
729 }
730}

References intop, l_castS2U, and luaG_runerror().

Referenced by intarith(), and luaV_execute().

◆ luaV_lessequal()

LUAI_FUNC int luaV_lessequal ( lua_State * L,
const TValue * l,
const TValue * r )

Definition at line 243 of file lua-5.2.4/src/lvm.c.

243 {
244 int res;
245 if (ttisnumber(l) && ttisnumber(r))
246 return luai_numle(L, nvalue(l), nvalue(r));
247 else if (ttisstring(l) && ttisstring(r))
248 return l_strcmp(rawtsvalue(l), rawtsvalue(r)) <= 0;
249 else if ((res = call_orderTM(L, l, r, TM_LE)) >= 0) /* first try `le' */
250 return res;
251 else if ((res = call_orderTM(L, r, l, TM_LT)) < 0) /* else try `lt' */
252 luaG_ordererror(L, l, r);
253 return !res;
254}
int luaG_ordererror(lua_State *L, const TValue *p1, const TValue *p2)
#define nvalue(o)
#define rawtsvalue(o)
static int call_orderTM(lua_State *L, const TValue *p1, const TValue *p2, TMS event)
static int l_strcmp(const TString *ls, const TString *rs)

References call_orderTM(), CallInfo::callstatus, lua_State::ci, CIST_LEQ, l_strcmp(), l_strcmp(), LEnum(), LEnum(), lessequalothers(), luaG_ordererror(), luai_numle, luaT_callorderTM(), nvalue, rawtsvalue, TM_LE, TM_LT, tsvalue, ttisnumber, and ttisstring.

Referenced by lua_compare(), and luaV_execute().

◆ luaV_lessthan()

LUAI_FUNC int luaV_lessthan ( lua_State * L,
const TValue * l,
const TValue * r )

Definition at line 225 of file lua-5.1.5/src/lvm.c.

225 {
226 int res;
227 if (ttype(l) != ttype(r))
228 return luaG_ordererror(L, l, r);
229 else if (ttisnumber(l))
230 return luai_numlt(nvalue(l), nvalue(r));
231 else if (ttisstring(l))
232 return l_strcmp(rawtsvalue(l), rawtsvalue(r)) < 0;
233 else if ((res = call_orderTM(L, l, r, TM_LT)) != -1)
234 return res;
235 return luaG_ordererror(L, l, r);
236}
static int call_orderTM(lua_State *L, const TValue *p1, const TValue *p2, TMS event)
static int l_strcmp(const TString *ls, const TString *rs)

References call_orderTM(), call_orderTM(), l_strcmp(), l_strcmp(), l_strcmp(), lessthanothers(), LTnum(), LTnum(), luaG_ordererror(), luai_numlt, luaT_callorderTM(), nvalue, rawtsvalue, TM_LT, tsvalue, ttisnumber, ttisstring, and ttype.

Referenced by lua_compare(), lua_lessthan(), luaV_execute(), and luaV_execute().

◆ luaV_mod()

Definition at line 572 of file lua-5.3.6/src/lvm.c.

572 {
573 if (l_castS2U(n) + 1u <= 1u) { /* special cases: -1 or 0 */
574 if (n == 0)
575 luaG_runerror(L, "attempt to perform 'n%%0'");
576 return 0; /* m % -1 == 0; avoid overflow with 0x80000...%-1 */
577 }
578 else {
579 lua_Integer r = m % n;
580 if (r != 0 && (m ^ n) < 0) /* 'm/n' would be non-integer negative? */
581 r += n; /* correct result for different rounding */
582 return r;
583 }
584}

References l_castS2U, and luaG_runerror().

Referenced by intarith(), intarith(), luaV_execute(), and luaV_execute().

◆ luaV_modf()

Definition at line 756 of file lua-5.4.3/src/lvm.c.

756 {
757 lua_Number r;
758 luai_nummod(L, m, n, r);
759 return r;
760}
#define luai_nummod(L, a, b, m)

References luai_nummod.

Referenced by luaV_execute(), and numarith().

◆ luaV_objlen()

LUAI_FUNC void luaV_objlen ( lua_State * L,
StkId ra,
const TValue * rb )

Definition at line 335 of file lua-5.2.4/src/lvm.c.

335 {
336 const TValue *tm;
337 switch (ttypenv(rb)) {
338 case LUA_TTABLE: {
339 Table *h = hvalue(rb);
340 tm = fasttm(L, h->metatable, TM_LEN);
341 if (tm) break; /* metamethod? break switch to call it */
342 setnvalue(ra, cast_num(luaH_getn(h))); /* else primitive len */
343 return;
344 }
345 case LUA_TSTRING: {
346 setnvalue(ra, cast_num(tsvalue(rb)->len));
347 return;
348 }
349 default: { /* try metamethod */
350 tm = luaT_gettmbyobj(L, rb, TM_LEN);
351 if (ttisnil(tm)) /* no metamethod? */
352 luaG_typeerror(L, rb, "get length of");
353 break;
354 }
355 }
356 callTM(L, tm, rb, rb, ra, 1);
357}
#define setnvalue(obj, x)
int luaH_getn(Table *t)
@ TM_LEN
#define LUA_TSTRING
#define ttypenv(o)
static void callTM(lua_State *L, const TValue *f, const TValue *p1, const TValue *p2, TValue *p3, int hasres)

References callTM(), cast_num, fasttm, hvalue, LUA_TLNGSTR, LUA_TSHRSTR, LUA_TSTRING, LUA_TTABLE, LUA_VLNGSTR, LUA_VSHRSTR, LUA_VTABLE, luaG_typeerror(), luaH_getn(), luaT_callTM(), luaT_callTMres(), luaT_gettmbyobj(), Table::metatable, notm, s2v, setivalue, setnvalue, TM_LEN, tsvalue, ttisnil, ttype, ttypenv, and ttypetag.

Referenced by lua_len(), luaV_execute(), and luaV_execute().

◆ luaV_shiftl()

Definition at line 593 of file lua-5.3.6/src/lvm.c.

593 {
594 if (y < 0) { /* shift right? */
595 if (y <= -NBITS) return 0;
596 else return intop(>>, x, -y);
597 }
598 else { /* shift left */
599 if (y >= NBITS) return 0;
600 else return intop(<<, x, y);
601 }
602}
#define NBITS

References intop, and NBITS.

Referenced by intarith(), intarith(), luaV_execute(), and luaV_execute().

◆ luaV_tointeger()

LUAI_FUNC int luaV_tointeger ( const TValue * obj,
lua_Integer * p,
F2Imod mode )

Definition at line 152 of file lua-5.4.3/src/lvm.c.

152 {
153 TValue v;
154 if (l_strton(obj, &v)) /* does 'obj' point to a numerical string? */
155 obj = &v; /* change it to point to its corresponding number */
156 return luaV_tointegerns(obj, p, mode);
157}
static int l_strton(const TValue *obj, TValue *result)
int luaV_tointegerns(const TValue *obj, lua_Integer *p, F2Imod mode)

References l_strton(), and luaV_tointegerns().

Referenced by forlimit().

◆ luaV_tointegerns()

LUAI_FUNC int luaV_tointegerns ( const TValue * obj,
lua_Integer * p,
F2Imod mode )

Definition at line 137 of file lua-5.4.3/src/lvm.c.

137 {
138 if (ttisfloat(obj))
139 return luaV_flttointeger(fltvalue(obj), p, mode);
140 else if (ttisinteger(obj)) {
141 *p = ivalue(obj);
142 return 1;
143 }
144 else
145 return 0;
146}
int luaV_flttointeger(lua_Number n, lua_Integer *p, F2Imod mode)

References fltvalue, ivalue, luaV_flttointeger(), ttisfloat, and ttisinteger.

Referenced by luaG_tointerror(), luaV_equalobj(), luaV_tointeger(), and validop().

◆ luaV_tonumber_()

LUAI_FUNC int luaV_tonumber_ ( const TValue * obj,
lua_Number * n )

Definition at line 72 of file lua-5.3.6/src/lvm.c.

72 {
73 TValue v;
74 if (ttisinteger(obj)) {
75 *n = cast_num(ivalue(obj));
76 return 1;
77 }
78 else if (cvt2num(obj) && /* string convertible to number? */
79 luaO_str2num(svalue(obj), &v) == vslen(obj) + 1) {
80 *n = nvalue(&v); /* convert result of 'luaO_str2num' to a float */
81 return 1;
82 }
83 else
84 return 0; /* conversion failed */
85}
size_t luaO_str2num(const char *s, TValue *o)
#define vslen(o)
#define cvt2num(o)

References cast_num, cvt2num, ivalue, l_strton(), luaO_str2num(), nvalue, svalue, ttisinteger, and vslen.