38#if !defined(LUA_USE_JUMPTABLE)
40#define LUA_USE_JUMPTABLE 1
42#define LUA_USE_JUMPTABLE 0
49#define MAXTAGLOOP 2000
58#define NBM (l_floatatt(MANT_DIG))
67#if ((((LUA_MAXINTEGER >> (NBM / 4)) >> (NBM / 4)) >> (NBM / 4)) \
68 >> (NBM - (3 * (NBM / 4)))) > 0
71#define MAXINTFITSF ((lua_Unsigned)1 << NBM)
74#define l_intfitsf(i) ((MAXINTFITSF + l_castS2U(i)) <= (2 * MAXINTFITSF))
78#define l_intfitsf(i) 1
91 lua_assert(obj != result);
95 return (luaO_str2num(svalue(obj), result) == vslen(obj) + 1);
103int luaV_tonumber_ (
const TValue *obj, lua_Number *n) {
105 if (ttisinteger(obj)) {
106 *n = cast_num(ivalue(obj));
109 else if (l_strton(obj, &v)) {
121int luaV_flttointeger (lua_Number n, lua_Integer *p, F2Imod mode) {
122 lua_Number f = l_floor(n);
124 if (mode == F2Ieq)
return 0;
125 else if (mode == F2Iceil)
128 return lua_numbertointeger(f, p);
137int luaV_tointegerns (
const TValue *obj, lua_Integer *p, F2Imod mode) {
139 return luaV_flttointeger(fltvalue(obj), p, mode);
140 else if (ttisinteger(obj)) {
152int luaV_tointeger (
const TValue *obj, lua_Integer *p, F2Imod mode) {
154 if (l_strton(obj, &v))
156 return luaV_tointegerns(obj, p, mode);
177 lua_Integer *p, lua_Integer step) {
178 if (!luaV_tointeger(lim, p, (step < 0 ? F2Iceil : F2Ifloor))) {
181 if (!tonumber(lim, &flim))
182 luaG_forerror(L, lim,
"limit");
184 if (luai_numlt(0, flim)) {
185 if (step < 0)
return 1;
189 if (step > 0)
return 1;
193 return (step > 0 ? init > *p : init < *p);
206static int forprep (
lua_State *L, StkId ra) {
208 TValue *plimit = s2v(ra + 1);
209 TValue *pstep = s2v(ra + 2);
210 if (ttisinteger(pinit) && ttisinteger(pstep)) {
211 lua_Integer init = ivalue(pinit);
212 lua_Integer step = ivalue(pstep);
215 luaG_runerror(L,
"'for' step is zero");
216 setivalue(s2v(ra + 3), init);
217 if (forlimit(L, init, plimit, &limit, step))
222 count = l_castS2U(limit) - l_castS2U(init);
224 count /= l_castS2U(step);
227 count = l_castS2U(init) - l_castS2U(limit);
229 count /= l_castS2U(-(step + 1)) + 1u;
233 setivalue(plimit, l_castU2S(count));
237 lua_Number init; lua_Number limit; lua_Number step;
238 if (l_unlikely(!tonumber(plimit, &limit)))
239 luaG_forerror(L, plimit,
"limit");
240 if (l_unlikely(!tonumber(pstep, &step)))
241 luaG_forerror(L, pstep,
"step");
242 if (l_unlikely(!tonumber(pinit, &init)))
243 luaG_forerror(L, pinit,
"initial value");
245 luaG_runerror(L,
"'for' step is zero");
246 if (luai_numlt(0, step) ? luai_numlt(limit, init)
247 : luai_numlt(init, limit))
251 setfltvalue(plimit, limit);
252 setfltvalue(pstep, step);
253 setfltvalue(s2v(ra), init);
254 setfltvalue(s2v(ra + 3), init);
266static int floatforloop (StkId ra) {
267 lua_Number step = fltvalue(s2v(ra + 2));
268 lua_Number limit = fltvalue(s2v(ra + 1));
269 lua_Number idx = fltvalue(s2v(ra));
270 idx = luai_numadd(L, idx, step);
271 if (luai_numlt(0, step) ? luai_numle(idx, limit)
272 : luai_numle(limit, idx)) {
273 chgfltvalue(s2v(ra), idx);
274 setfltvalue(s2v(ra + 3), idx);
291 for (loop = 0; loop < MAXTAGLOOP; loop++) {
293 lua_assert(!ttistable(t));
294 tm = luaT_gettmbyobj(L, t, TM_INDEX);
295 if (l_unlikely(notm(tm)))
296 luaG_typeerror(L, t,
"index");
300 lua_assert(isempty(slot));
301 tm = fasttm(L, hvalue(t)->metatable, TM_INDEX);
303 setnilvalue(s2v(val));
308 if (ttisfunction(tm)) {
309 luaT_callTMres(L, tm, t, key, val);
313 if (luaV_fastget(L, t, key, slot, luaH_get)) {
314 setobj2s(L, val, slot);
319 luaG_runerror(L,
"'__index' chain too long; possible loop");
333 for (loop = 0; loop < MAXTAGLOOP; loop++) {
336 Table *h = hvalue(t);
337 lua_assert(isempty(slot));
338 tm = fasttm(L, h->metatable, TM_NEWINDEX);
340 luaH_finishset(L, h, key, slot, val);
341 invalidateTMcache(h);
342 luaC_barrierback(L, obj2gco(h), val);
348 tm = luaT_gettmbyobj(L, t, TM_NEWINDEX);
349 if (l_unlikely(notm(tm)))
350 luaG_typeerror(L, t,
"index");
353 if (ttisfunction(tm)) {
354 luaT_callTM(L, tm, t, key, val);
358 if (luaV_fastget(L, t, key, slot, luaH_get)) {
359 luaV_finishfastset(L, t, slot, val);
364 luaG_runerror(L,
"'__newindex' chain too long; possible loop");
376 const char *l = getstr(ls);
377 size_t ll = tsslen(ls);
378 const char *r = getstr(rs);
379 size_t lr = tsslen(rs);
381 int temp = strcoll(l, r);
385 size_t len = strlen(l);
387 return (len == ll) ? 0 : 1;
392 l += len; ll -= len; r += len; lr -= len;
409l_sinline
int LTintfloat (lua_Integer i, lua_Number f) {
411 return luai_numlt(cast_num(i), f);
414 if (luaV_flttointeger(f, &fi, F2Iceil))
426l_sinline
int LEintfloat (lua_Integer i, lua_Number f) {
428 return luai_numle(cast_num(i), f);
431 if (luaV_flttointeger(f, &fi, F2Ifloor))
443l_sinline
int LTfloatint (lua_Number f, lua_Integer i) {
445 return luai_numlt(f, cast_num(i));
448 if (luaV_flttointeger(f, &fi, F2Ifloor))
460l_sinline
int LEfloatint (lua_Number f, lua_Integer i) {
462 return luai_numle(f, cast_num(i));
465 if (luaV_flttointeger(f, &fi, F2Iceil))
477 lua_assert(ttisnumber(l) && ttisnumber(r));
478 if (ttisinteger(l)) {
479 lua_Integer li = ivalue(l);
481 return li < ivalue(r);
483 return LTintfloat(li, fltvalue(r));
486 lua_Number lf = fltvalue(l);
488 return luai_numlt(lf, fltvalue(r));
490 return LTfloatint(lf, ivalue(r));
499 lua_assert(ttisnumber(l) && ttisnumber(r));
500 if (ttisinteger(l)) {
501 lua_Integer li = ivalue(l);
503 return li <= ivalue(r);
505 return LEintfloat(li, fltvalue(r));
508 lua_Number lf = fltvalue(l);
510 return luai_numle(lf, fltvalue(r));
512 return LEfloatint(lf, ivalue(r));
521 lua_assert(!ttisnumber(l) || !ttisnumber(r));
522 if (ttisstring(l) && ttisstring(r))
523 return l_strcmp(tsvalue(l), tsvalue(r)) < 0;
525 return luaT_callorderTM(L, l, r, TM_LT);
533 if (ttisnumber(l) && ttisnumber(r))
535 else return lessthanothers(L, l, r);
543 lua_assert(!ttisnumber(l) || !ttisnumber(r));
544 if (ttisstring(l) && ttisstring(r))
545 return l_strcmp(tsvalue(l), tsvalue(r)) <= 0;
547 return luaT_callorderTM(L, l, r, TM_LE);
555 if (ttisnumber(l) && ttisnumber(r))
557 else return lessequalothers(L, l, r);
567 if (ttypetag(t1) != ttypetag(t2)) {
568 if (ttype(t1) != ttype(t2) || ttype(t1) != LUA_TNUMBER)
575 return (luaV_tointegerns(t1, &i1, F2Ieq) &&
576 luaV_tointegerns(t2, &i2, F2Ieq) &&
581 switch (ttypetag(t1)) {
582 case LUA_VNIL:
case LUA_VFALSE:
case LUA_VTRUE:
return 1;
583 case LUA_VNUMINT:
return (ivalue(t1) == ivalue(t2));
584 case LUA_VNUMFLT:
return luai_numeq(fltvalue(t1), fltvalue(t2));
585 case LUA_VLIGHTUSERDATA:
return pvalue(t1) == pvalue(t2);
586 case LUA_VLCF:
return fvalue(t1) == fvalue(t2);
587 case LUA_VSHRSTR:
return eqshrstr(tsvalue(t1), tsvalue(t2));
588 case LUA_VLNGSTR:
return luaS_eqlngstr(tsvalue(t1), tsvalue(t2));
589 case LUA_VUSERDATA: {
590 if (uvalue(t1) == uvalue(t2))
return 1;
591 else if (L == NULL)
return 0;
592 tm = fasttm(L, uvalue(t1)->metatable, TM_EQ);
594 tm = fasttm(L, uvalue(t2)->metatable, TM_EQ);
598 if (hvalue(t1) == hvalue(t2))
return 1;
599 else if (L == NULL)
return 0;
600 tm = fasttm(L, hvalue(t1)->metatable, TM_EQ);
602 tm = fasttm(L, hvalue(t2)->metatable, TM_EQ);
606 return gcvalue(t1) == gcvalue(t2);
611 luaT_callTMres(L, tm, t1, t2, L->top.p);
612 return !l_isfalse(s2v(L->top.p));
618#define tostring(L,o) \
619 (ttisstring(o) || (cvt2str(o) && (luaO_tostring(L, o), 1)))
621#define isemptystr(o) (ttisshrstring(o) && tsvalue(o)->shrlen == 0)
624static void copy2buff (StkId top,
int n,
char *buff) {
627 size_t l = vslen(s2v(top - n));
628 memcpy(buff + tl, svalue(s2v(top - n)), l *
sizeof(
char));
638void luaV_concat (
lua_State *L,
int total) {
642 StkId top = L->top.p;
644 if (!(ttisstring(s2v(top - 2)) || cvt2str(s2v(top - 2))) ||
645 !tostring(L, s2v(top - 1)))
647 else if (isemptystr(s2v(top - 1)))
648 cast_void(tostring(L, s2v(top - 2)));
649 else if (isemptystr(s2v(top - 2))) {
650 setobjs2s(L, top - 2, top - 1);
654 size_t tl = vslen(s2v(top - 1));
657 for (n = 1; n < total && tostring(L, s2v(top - n - 1)); n++) {
658 size_t l = vslen(s2v(top - n - 1));
659 if (l_unlikely(l >= (MAX_SIZE/
sizeof(
char)) - tl)) {
660 L->top.p = top - total;
661 luaG_runerror(L,
"string length overflow");
665 if (tl <= LUAI_MAXSHORTLEN) {
666 char buff[LUAI_MAXSHORTLEN];
667 copy2buff(top, n, buff);
668 ts = luaS_newlstr(L, buff, tl);
671 ts = luaS_createlngstrobj(L, tl);
672 copy2buff(top, n, getstr(ts));
674 setsvalue2s(L, top - n, ts);
687 switch (ttypetag(rb)) {
689 Table *h = hvalue(rb);
690 tm = fasttm(L, h->metatable, TM_LEN);
692 setivalue(s2v(ra), luaH_getn(h));
696 setivalue(s2v(ra), tsvalue(rb)->shrlen);
700 setivalue(s2v(ra), tsvalue(rb)->u.lnglen);
704 tm = luaT_gettmbyobj(L, rb, TM_LEN);
705 if (l_unlikely(notm(tm)))
706 luaG_typeerror(L, rb,
"get length of");
710 luaT_callTMres(L, tm, rb, rb, ra);
720lua_Integer luaV_idiv (
lua_State *L, lua_Integer m, lua_Integer n) {
721 if (l_unlikely(l_castS2U(n) + 1u <= 1u)) {
723 luaG_runerror(L,
"attempt to divide by zero");
724 return intop(-, 0, m);
727 lua_Integer q = m / n;
728 if ((m ^ n) < 0 && m % n != 0)
740lua_Integer luaV_mod (
lua_State *L, lua_Integer m, lua_Integer n) {
741 if (l_unlikely(l_castS2U(n) + 1u <= 1u)) {
743 luaG_runerror(L,
"attempt to perform 'n%%0'");
747 lua_Integer r = m % n;
748 if (r != 0 && (r ^ n) < 0)
758lua_Number luaV_modf (
lua_State *L, lua_Number m, lua_Number n) {
760 luai_nummod(L, m, n, r);
766#define NBITS cast_int(sizeof(lua_Integer) * CHAR_BIT)
772lua_Integer luaV_shiftl (lua_Integer x, lua_Integer y) {
774 if (y <= -NBITS)
return 0;
775 else return intop(>>, x, -y);
778 if (y >= NBITS)
return 0;
779 else return intop(<<, x, y);
790 int nup = p->sizeupvalues;
793 LClosure *ncl = luaF_newLclosure(L, nup);
795 setclLvalue2s(L, ra, ncl);
796 for (i = 0; i < nup; i++) {
798 ncl->upvals[i] = luaF_findupval(L, base + uv[i].idx);
800 ncl->upvals[i] = encup[uv[i].idx];
801 luaC_objbarrier(L, ncl, ncl->upvals[i]);
811 StkId base = ci->func.p + 1;
812 Instruction inst = *(ci->u.l.savedpc - 1);
813 OpCode op = GET_OPCODE(inst);
815 case OP_MMBIN:
case OP_MMBINI:
case OP_MMBINK: {
816 setobjs2s(L, base + GETARG_A(*(ci->u.l.savedpc - 2)), --L->top.p);
819 case OP_UNM:
case OP_BNOT:
case OP_LEN:
820 case OP_GETTABUP:
case OP_GETTABLE:
case OP_GETI:
821 case OP_GETFIELD:
case OP_SELF: {
822 setobjs2s(L, base + GETARG_A(inst), --L->top.p);
825 case OP_LT:
case OP_LE:
826 case OP_LTI:
case OP_LEI:
827 case OP_GTI:
case OP_GEI:
829 int res = !l_isfalse(s2v(L->top.p - 1));
831#if defined(LUA_COMPAT_LT_LE)
832 if (ci->callstatus & CIST_LEQ) {
833 ci->callstatus ^= CIST_LEQ;
837 lua_assert(GET_OPCODE(*ci->u.l.savedpc) == OP_JMP);
838 if (res != GETARG_k(inst))
843 StkId top = L->top.p - 1;
844 int a = GETARG_A(inst);
845 int total = cast_int(top - 1 - (base + a));
846 setobjs2s(L, top - 2, top);
848 luaV_concat(L, total);
856 StkId ra = base + GETARG_A(inst);
859 L->top.p = ra + ci->u2.nres;
866 lua_assert(op == OP_TFORCALL || op == OP_CALL ||
867 op == OP_TAILCALL || op == OP_SETTABUP || op == OP_SETTABLE ||
868 op == OP_SETI || op == OP_SETFIELD);
883#define l_addi(L,a,b) intop(+, a, b)
884#define l_subi(L,a,b) intop(-, a, b)
885#define l_muli(L,a,b) intop(*, a, b)
886#define l_band(a,b) intop(&, a, b)
887#define l_bor(a,b) intop(|, a, b)
888#define l_bxor(a,b) intop(^, a, b)
890#define l_lti(a,b) (a < b)
891#define l_lei(a,b) (a <= b)
892#define l_gti(a,b) (a > b)
893#define l_gei(a,b) (a >= b)
900#define op_arithI(L,iop,fop) { \
902 TValue *v1 = vRB(i); \
903 int imm = GETARG_sC(i); \
904 if (ttisinteger(v1)) { \
905 lua_Integer iv1 = ivalue(v1); \
906 pc++; setivalue(s2v(ra), iop(L, iv1, imm)); \
908 else if (ttisfloat(v1)) { \
909 lua_Number nb = fltvalue(v1); \
910 lua_Number fimm = cast_num(imm); \
911 pc++; setfltvalue(s2v(ra), fop(L, nb, fimm)); \
919#define op_arithf_aux(L,v1,v2,fop) { \
920 lua_Number n1; lua_Number n2; \
921 if (tonumberns(v1, n1) && tonumberns(v2, n2)) { \
922 pc++; setfltvalue(s2v(ra), fop(L, n1, n2)); \
929#define op_arithf(L,fop) { \
931 TValue *v1 = vRB(i); \
932 TValue *v2 = vRC(i); \
933 op_arithf_aux(L, v1, v2, fop); }
939#define op_arithfK(L,fop) { \
941 TValue *v1 = vRB(i); \
942 TValue *v2 = KC(i); lua_assert(ttisnumber(v2)); \
943 op_arithf_aux(L, v1, v2, fop); }
949#define op_arith_aux(L,v1,v2,iop,fop) { \
951 if (ttisinteger(v1) && ttisinteger(v2)) { \
952 lua_Integer i1 = ivalue(v1); lua_Integer i2 = ivalue(v2); \
953 pc++; setivalue(s2v(ra), iop(L, i1, i2)); \
955 else op_arithf_aux(L, v1, v2, fop); }
961#define op_arith(L,iop,fop) { \
962 TValue *v1 = vRB(i); \
963 TValue *v2 = vRC(i); \
964 op_arith_aux(L, v1, v2, iop, fop); }
970#define op_arithK(L,iop,fop) { \
971 TValue *v1 = vRB(i); \
972 TValue *v2 = KC(i); lua_assert(ttisnumber(v2)); \
973 op_arith_aux(L, v1, v2, iop, fop); }
979#define op_bitwiseK(L,op) { \
981 TValue *v1 = vRB(i); \
982 TValue *v2 = KC(i); \
984 lua_Integer i2 = ivalue(v2); \
985 if (tointegerns(v1, &i1)) { \
986 pc++; setivalue(s2v(ra), op(i1, i2)); \
993#define op_bitwise(L,op) { \
995 TValue *v1 = vRB(i); \
996 TValue *v2 = vRC(i); \
997 lua_Integer i1; lua_Integer i2; \
998 if (tointegerns(v1, &i1) && tointegerns(v2, &i2)) { \
999 pc++; setivalue(s2v(ra), op(i1, i2)); \
1008#define op_order(L,opi,opn,other) { \
1011 TValue *rb = vRB(i); \
1012 if (ttisinteger(s2v(ra)) && ttisinteger(rb)) { \
1013 lua_Integer ia = ivalue(s2v(ra)); \
1014 lua_Integer ib = ivalue(rb); \
1015 cond = opi(ia, ib); \
1017 else if (ttisnumber(s2v(ra)) && ttisnumber(rb)) \
1018 cond = opn(s2v(ra), rb); \
1020 Protect(cond = other(L, s2v(ra), rb)); \
1028#define op_orderI(L,opi,opf,inv,tm) { \
1031 int im = GETARG_sB(i); \
1032 if (ttisinteger(s2v(ra))) \
1033 cond = opi(ivalue(s2v(ra)), im); \
1034 else if (ttisfloat(s2v(ra))) { \
1035 lua_Number fa = fltvalue(s2v(ra)); \
1036 lua_Number fim = cast_num(im); \
1037 cond = opf(fa, fim); \
1040 int isf = GETARG_C(i); \
1041 Protect(cond = luaT_callorderiTM(L, s2v(ra), im, inv, isf, tm)); \
1059#define RA(i) (base+GETARG_A(i))
1060#define RB(i) (base+GETARG_B(i))
1061#define vRB(i) s2v(RB(i))
1062#define KB(i) (k+GETARG_B(i))
1063#define RC(i) (base+GETARG_C(i))
1064#define vRC(i) s2v(RC(i))
1065#define KC(i) (k+GETARG_C(i))
1066#define RKC(i) ((TESTARG_k(i)) ? k + GETARG_C(i) : s2v(base + GETARG_C(i)))
1070#define updatetrap(ci) (trap = ci->u.l.trap)
1072#define updatebase(ci) (base = ci->func.p + 1)
1075#define updatestack(ci) \
1076 { if (l_unlikely(trap)) { updatebase(ci); ra = RA(i); } }
1083#define dojump(ci,i,e) { pc += GETARG_sJ(i) + e; updatetrap(ci); }
1087#define donextjump(ci) { Instruction ni = *pc; dojump(ci, ni, 1); }
1094#define docondjump() if (cond != GETARG_k(i)) pc++; else donextjump(ci);
1100#define savepc(L) (ci->u.l.savedpc = pc)
1107#define savestate(L,ci) (savepc(L), L->top.p = ci->top.p)
1114#define Protect(exp) (savestate(L,ci), (exp), updatetrap(ci))
1117#define ProtectNT(exp) (savepc(L), (exp), updatetrap(ci))
1123#define halfProtect(exp) (savestate(L,ci), (exp))
1126#define checkGC(L,c) \
1127 { luaC_condGC(L, (savepc(L), L->top.p = (c)), \
1129 luai_threadyield(L); }
1133#define vmfetch() { \
1134 if (l_unlikely(trap)) { \
1135 trap = luaG_traceexec(L, pc); \
1141#define vmdispatch(o) switch(o)
1142#define vmcase(l) case l:
1143#define vmbreak break
1150 const Instruction *pc;
1152#if LUA_USE_JUMPTABLE
1158 cl = clLvalue(s2v(ci->func.p));
1160 pc = ci->u.l.savedpc;
1161 if (l_unlikely(trap)) {
1162 if (pc == cl->p->code) {
1163 if (cl->p->is_vararg)
1166 luaD_hookcall(L, ci);
1170 base = ci->func.p + 1;
1177 printf(
"line: %d\n", luaG_getfuncline(cl->p, pcRel(pc, cl->p)));
1179 lua_assert(base == ci->func.p + 1);
1180 lua_assert(base <= L->top.p && L->top.p <= L->stack_last.p);
1182 lua_assert(isIT(i) || (cast_void(L->top.p = base), 1));
1183 vmdispatch (GET_OPCODE(i)) {
1186 setobjs2s(L, ra, RB(i));
1191 lua_Integer b = GETARG_sBx(i);
1192 setivalue(s2v(ra), b);
1197 int b = GETARG_sBx(i);
1198 setfltvalue(s2v(ra), cast_num(b));
1203 TValue *rb = k + GETARG_Bx(i);
1204 setobj2s(L, ra, rb);
1210 rb = k + GETARG_Ax(*pc); pc++;
1211 setobj2s(L, ra, rb);
1214 vmcase(OP_LOADFALSE) {
1216 setbfvalue(s2v(ra));
1219 vmcase(OP_LFALSESKIP) {
1221 setbfvalue(s2v(ra));
1225 vmcase(OP_LOADTRUE) {
1227 setbtvalue(s2v(ra));
1230 vmcase(OP_LOADNIL) {
1232 int b = GETARG_B(i);
1234 setnilvalue(s2v(ra++));
1238 vmcase(OP_GETUPVAL) {
1240 int b = GETARG_B(i);
1241 setobj2s(L, ra, cl->upvals[b]->v.p);
1244 vmcase(OP_SETUPVAL) {
1246 UpVal *uv = cl->upvals[GETARG_B(i)];
1247 setobj(L, uv->v.p, s2v(ra));
1248 luaC_barrier(L, uv, s2v(ra));
1251 vmcase(OP_GETTABUP) {
1254 TValue *upval = cl->upvals[GETARG_B(i)]->v.p;
1257 if (luaV_fastget(L, upval, key, slot, luaH_getshortstr)) {
1258 setobj2s(L, ra, slot);
1261 Protect(luaV_finishget(L, upval, rc, ra, slot));
1264 vmcase(OP_GETTABLE) {
1271 ? (cast_void(n = ivalue(rc)), luaV_fastgeti(L, rb, n, slot))
1272 : luaV_fastget(L, rb, rc, slot, luaH_get)) {
1273 setobj2s(L, ra, slot);
1276 Protect(luaV_finishget(L, rb, rc, ra, slot));
1283 int c = GETARG_C(i);
1284 if (luaV_fastgeti(L, rb, c, slot)) {
1285 setobj2s(L, ra, slot);
1290 Protect(luaV_finishget(L, rb, &key, ra, slot));
1294 vmcase(OP_GETFIELD) {
1300 if (luaV_fastget(L, rb, key, slot, luaH_getshortstr)) {
1301 setobj2s(L, ra, slot);
1304 Protect(luaV_finishget(L, rb, rc, ra, slot));
1307 vmcase(OP_SETTABUP) {
1309 TValue *upval = cl->upvals[GETARG_A(i)]->v.p;
1313 if (luaV_fastget(L, upval, key, slot, luaH_getshortstr)) {
1314 luaV_finishfastset(L, upval, slot, rc);
1317 Protect(luaV_finishset(L, upval, rb, rc, slot));
1320 vmcase(OP_SETTABLE) {
1327 ? (cast_void(n = ivalue(rb)), luaV_fastgeti(L, s2v(ra), n, slot))
1328 : luaV_fastget(L, s2v(ra), rb, slot, luaH_get)) {
1329 luaV_finishfastset(L, s2v(ra), slot, rc);
1332 Protect(luaV_finishset(L, s2v(ra), rb, rc, slot));
1338 int c = GETARG_B(i);
1340 if (luaV_fastgeti(L, s2v(ra), c, slot)) {
1341 luaV_finishfastset(L, s2v(ra), slot, rc);
1346 Protect(luaV_finishset(L, s2v(ra), &key, rc, slot));
1350 vmcase(OP_SETFIELD) {
1356 if (luaV_fastget(L, s2v(ra), key, slot, luaH_getshortstr)) {
1357 luaV_finishfastset(L, s2v(ra), slot, rc);
1360 Protect(luaV_finishset(L, s2v(ra), rb, rc, slot));
1363 vmcase(OP_NEWTABLE) {
1365 int b = GETARG_B(i);
1366 int c = GETARG_C(i);
1370 lua_assert((!TESTARG_k(i)) == (GETARG_Ax(*pc) == 0));
1372 c += GETARG_Ax(*pc) * (MAXARG_C + 1);
1376 sethvalue2s(L, ra, t);
1377 if (b != 0 || c != 0)
1378 luaH_resize(L, t, c, b);
1388 setobj2s(L, ra + 1, rb);
1389 if (luaV_fastget(L, rb, key, slot, luaH_getstr)) {
1390 setobj2s(L, ra, slot);
1393 Protect(luaV_finishget(L, rb, rc, ra, slot));
1397 op_arithI(L, l_addi, luai_numadd);
1401 op_arithK(L, l_addi, luai_numadd);
1405 op_arithK(L, l_subi, luai_numsub);
1409 op_arithK(L, l_muli, luai_nummul);
1414 op_arithK(L, luaV_mod, luaV_modf);
1418 op_arithfK(L, luai_numpow);
1422 op_arithfK(L, luai_numdiv);
1427 op_arithK(L, luaV_idiv, luai_numidiv);
1431 op_bitwiseK(L, l_band);
1435 op_bitwiseK(L, l_bor);
1439 op_bitwiseK(L, l_bxor);
1445 int ic = GETARG_sC(i);
1447 if (tointegerns(rb, &ib)) {
1448 pc++; setivalue(s2v(ra), luaV_shiftl(ib, -ic));
1455 int ic = GETARG_sC(i);
1457 if (tointegerns(rb, &ib)) {
1458 pc++; setivalue(s2v(ra), luaV_shiftl(ic, ib));
1463 op_arith(L, l_addi, luai_numadd);
1467 op_arith(L, l_subi, luai_numsub);
1471 op_arith(L, l_muli, luai_nummul);
1476 op_arith(L, luaV_mod, luaV_modf);
1480 op_arithf(L, luai_numpow);
1484 op_arithf(L, luai_numdiv);
1489 op_arith(L, luaV_idiv, luai_numidiv);
1493 op_bitwise(L, l_band);
1497 op_bitwise(L, l_bor);
1501 op_bitwise(L, l_bxor);
1505 op_bitwise(L, luaV_shiftr);
1509 op_bitwise(L, luaV_shiftl);
1514 Instruction pi = *(pc - 2);
1516 TMS tm = (TMS)GETARG_C(i);
1517 StkId result = RA(pi);
1518 lua_assert(OP_ADD <= GET_OPCODE(pi) && GET_OPCODE(pi) <= OP_SHR);
1519 Protect(luaT_trybinTM(L, s2v(ra), rb, result, tm));
1524 Instruction pi = *(pc - 2);
1525 int imm = GETARG_sB(i);
1526 TMS tm = (TMS)GETARG_C(i);
1527 int flip = GETARG_k(i);
1528 StkId result = RA(pi);
1529 Protect(luaT_trybiniTM(L, s2v(ra), imm, flip, result, tm));
1534 Instruction pi = *(pc - 2);
1536 TMS tm = (TMS)GETARG_C(i);
1537 int flip = GETARG_k(i);
1538 StkId result = RA(pi);
1539 Protect(luaT_trybinassocTM(L, s2v(ra), imm, flip, result, tm));
1546 if (ttisinteger(rb)) {
1547 lua_Integer ib = ivalue(rb);
1548 setivalue(s2v(ra), intop(-, 0, ib));
1550 else if (tonumberns(rb, nb)) {
1551 setfltvalue(s2v(ra), luai_numunm(L, nb));
1554 Protect(luaT_trybinTM(L, rb, rb, ra, TM_UNM));
1561 if (tointegerns(rb, &ib)) {
1562 setivalue(s2v(ra), intop(^, ~l_castS2U(0), ib));
1565 Protect(luaT_trybinTM(L, rb, rb, ra, TM_BNOT));
1572 setbtvalue(s2v(ra));
1574 setbfvalue(s2v(ra));
1579 Protect(luaV_objlen(L, ra, vRB(i)));
1584 int n = GETARG_B(i);
1586 ProtectNT(luaV_concat(L, n));
1587 checkGC(L, L->top.p);
1592 Protect(luaF_close(L, ra, LUA_OK, 1));
1598 halfProtect(luaF_newtbcupval(L, ra));
1609 Protect(cond = luaV_equalobj(L, s2v(ra), rb));
1614 op_order(L, l_lti, LTnum, lessthanothers);
1618 op_order(L, l_lei, LEnum, lessequalothers);
1625 int cond = luaV_rawequalobj(s2v(ra), rb);
1632 int im = GETARG_sB(i);
1633 if (ttisinteger(s2v(ra)))
1634 cond = (ivalue(s2v(ra)) == im);
1635 else if (ttisfloat(s2v(ra)))
1636 cond = luai_numeq(fltvalue(s2v(ra)), cast_num(im));
1643 op_orderI(L, l_lti, luai_numlt, 0, TM_LT);
1647 op_orderI(L, l_lei, luai_numle, 0, TM_LE);
1651 op_orderI(L, l_gti, luai_numgt, 1, TM_LT);
1655 op_orderI(L, l_gei, luai_numge, 1, TM_LE);
1660 int cond = !l_isfalse(s2v(ra));
1664 vmcase(OP_TESTSET) {
1667 if (l_isfalse(rb) == GETARG_k(i))
1670 setobj2s(L, ra, rb);
1678 int b = GETARG_B(i);
1679 int nresults = GETARG_C(i) - 1;
1684 if ((newci = luaD_precall(L, ra, nresults)) == NULL)
1692 vmcase(OP_TAILCALL) {
1694 int b = GETARG_B(i);
1696 int nparams1 = GETARG_C(i);
1698 int delta = (nparams1) ? ci->u.l.nextraargs + nparams1 : 0;
1702 b = cast_int(L->top.p - ra);
1705 luaF_closeupval(L, base);
1706 lua_assert(L->tbclist.p < base);
1707 lua_assert(base == ci->func.p + 1);
1709 if ((n = luaD_pretailcall(L, ci, ra, b, delta)) < 0)
1712 ci->func.p -= delta;
1713 luaD_poscall(L, ci, n);
1720 int n = GETARG_B(i) - 1;
1721 int nparams1 = GETARG_C(i);
1723 n = cast_int(L->top.p - ra);
1727 if (L->top.p < ci->top.p)
1728 L->top.p = ci->top.p;
1729 luaF_close(L, base, CLOSEKTOP, 1);
1734 ci->func.p -= ci->u.l.nextraargs + nparams1;
1736 luaD_poscall(L, ci, n);
1740 vmcase(OP_RETURN0) {
1741 if (l_unlikely(L->hookmask)) {
1745 luaD_poscall(L, ci, 0);
1750 L->ci = ci->previous;
1751 L->top.p = base - 1;
1752 for (nres = ci->nresults; l_unlikely(nres > 0); nres--)
1753 setnilvalue(s2v(L->top.p++));
1757 vmcase(OP_RETURN1) {
1758 if (l_unlikely(L->hookmask)) {
1762 luaD_poscall(L, ci, 1);
1766 int nres = ci->nresults;
1767 L->ci = ci->previous;
1769 L->top.p = base - 1;
1772 setobjs2s(L, base - 1, ra);
1774 for (; l_unlikely(nres > 1); nres--)
1775 setnilvalue(s2v(L->top.p++));
1779 if (ci->callstatus & CIST_FRESH)
1786 vmcase(OP_FORLOOP) {
1788 if (ttisinteger(s2v(ra + 2))) {
1789 lua_Unsigned count = l_castS2U(ivalue(s2v(ra + 1)));
1791 lua_Integer step = ivalue(s2v(ra + 2));
1792 lua_Integer idx = ivalue(s2v(ra));
1793 chgivalue(s2v(ra + 1), count - 1);
1794 idx = intop(+, idx, step);
1795 chgivalue(s2v(ra), idx);
1796 setivalue(s2v(ra + 3), idx);
1800 else if (floatforloop(ra))
1805 vmcase(OP_FORPREP) {
1809 pc += GETARG_Bx(i) + 1;
1812 vmcase(OP_TFORPREP) {
1815 halfProtect(luaF_newtbcupval(L, ra + 3));
1818 lua_assert(GET_OPCODE(i) == OP_TFORCALL && ra == RA(i));
1821 vmcase(OP_TFORCALL) {
1830 memcpy(ra + 4, ra, 3 *
sizeof(*ra));
1831 L->top.p = ra + 4 + 3;
1832 ProtectNT(luaD_call(L, ra + 4, GETARG_C(i)));
1835 lua_assert(GET_OPCODE(i) == OP_TFORLOOP && ra == RA(i));
1838 vmcase(OP_TFORLOOP) {
1841 if (!ttisnil(s2v(ra + 4))) {
1842 setobjs2s(L, ra + 2, ra + 4);
1847 vmcase(OP_SETLIST) {
1849 int n = GETARG_B(i);
1850 unsigned int last = GETARG_C(i);
1851 Table *h = hvalue(s2v(ra));
1853 n = cast_int(L->top.p - ra) - 1;
1855 L->top.p = ci->top.p;
1858 last += GETARG_Ax(*pc) * (MAXARG_C + 1);
1861 if (last > luaH_realasize(h))
1862 luaH_resizearray(L, h, last);
1863 for (; n > 0; n--) {
1864 TValue *val = s2v(ra + n);
1865 setobj2t(L, &h->array[last - 1], val);
1867 luaC_barrierback(L, obj2gco(h), val);
1871 vmcase(OP_CLOSURE) {
1873 Proto *p = cl->p->p[GETARG_Bx(i)];
1874 halfProtect(pushclosure(L, p, cl->upvals, base, ra));
1880 int n = GETARG_C(i) - 1;
1881 Protect(luaT_getvarargs(L, ci, ra, n));
1884 vmcase(OP_VARARGPREP) {
1885 ProtectNT(luaT_adjustvarargs(L, GETARG_A(i), ci, cl->p));
1886 if (l_unlikely(trap)) {
1887 luaD_hookcall(L, ci);
1893 vmcase(OP_EXTRAARG) {