@@ -910,6 +910,10 @@ void luaV_finishOp (lua_State *L) {
910910/*
911911** {==================================================================
912912** Macros for arithmetic/bitwise/comparison opcodes in 'luaV_execute'
913+ **
914+ ** All these macros are to be used exclusively inside the main
915+ ** iterpreter loop (function luaV_execute) and may access directly
916+ ** the local variables of that function (L, i, pc, ci, etc.).
913917** ===================================================================
914918*/
915919
@@ -931,17 +935,17 @@ void luaV_finishOp (lua_State *L) {
931935** operation, 'fop' is the float operation.
932936*/
933937#define op_arithI (L ,iop ,fop ) { \
934- StkId ra = RA (i); \
938+ TValue * ra = vRA (i); \
935939 TValue *v1 = vRB(i); \
936940 int imm = GETARG_sC(i); \
937941 if (ttisinteger(v1)) { \
938942 lua_Integer iv1 = ivalue(v1); \
939- pc++; setivalue(s2v(ra) , iop(L, iv1, imm)); \
943+ pc++; setivalue(ra , iop(L, iv1, imm)); \
940944 } \
941945 else if (ttisfloat(v1)) { \
942946 lua_Number nb = fltvalue(v1); \
943947 lua_Number fimm = cast_num(imm); \
944- pc++; setfltvalue(s2v(ra) , fop(L, nb, fimm)); \
948+ pc++; setfltvalue(ra , fop(L, nb, fimm)); \
945949 }}
946950
947951
@@ -952,6 +956,7 @@ void luaV_finishOp (lua_State *L) {
952956#define op_arithf_aux (L ,v1 ,v2 ,fop ) { \
953957 lua_Number n1; lua_Number n2; \
954958 if (tonumberns(v1, n1) && tonumberns(v2, n2)) { \
959+ StkId ra = RA(i); \
955960 pc++; setfltvalue(s2v(ra), fop(L, n1, n2)); \
956961 }}
957962
@@ -960,7 +965,6 @@ void luaV_finishOp (lua_State *L) {
960965** Arithmetic operations over floats and others with register operands.
961966*/
962967#define op_arithf (L ,fop ) { \
963- StkId ra = RA(i); \
964968 TValue *v1 = vRB(i); \
965969 TValue *v2 = vRC(i); \
966970 op_arithf_aux(L, v1, v2, fop); }
@@ -970,7 +974,6 @@ void luaV_finishOp (lua_State *L) {
970974** Arithmetic operations with K operands for floats.
971975*/
972976#define op_arithfK (L ,fop ) { \
973- StkId ra = RA(i); \
974977 TValue *v1 = vRB(i); \
975978 TValue *v2 = KC(i); lua_assert(ttisnumber(v2)); \
976979 op_arithf_aux(L, v1, v2, fop); }
@@ -980,8 +983,8 @@ void luaV_finishOp (lua_State *L) {
980983** Arithmetic operations over integers and floats.
981984*/
982985#define op_arith_aux (L ,v1 ,v2 ,iop ,fop ) { \
983- StkId ra = RA(i); \
984986 if (ttisinteger(v1) && ttisinteger(v2)) { \
987+ StkId ra = RA(i); \
985988 lua_Integer i1 = ivalue(v1); lua_Integer i2 = ivalue(v2); \
986989 pc++; setivalue(s2v(ra), iop(L, i1, i2)); \
987990 } \
@@ -1010,12 +1013,12 @@ void luaV_finishOp (lua_State *L) {
10101013** Bitwise operations with constant operand.
10111014*/
10121015#define op_bitwiseK (L ,op ) { \
1013- StkId ra = RA(i); \
10141016 TValue *v1 = vRB(i); \
10151017 TValue *v2 = KC(i); \
10161018 lua_Integer i1; \
10171019 lua_Integer i2 = ivalue(v2); \
10181020 if (tointegerns(v1, &i1)) { \
1021+ StkId ra = RA(i); \
10191022 pc++; setivalue(s2v(ra), op(i1, i2)); \
10201023 }}
10211024
@@ -1024,11 +1027,11 @@ void luaV_finishOp (lua_State *L) {
10241027** Bitwise operations with register operands.
10251028*/
10261029#define op_bitwise (L ,op ) { \
1027- StkId ra = RA(i); \
10281030 TValue *v1 = vRB(i); \
10291031 TValue *v2 = vRC(i); \
10301032 lua_Integer i1; lua_Integer i2; \
10311033 if (tointegerns(v1, &i1) && tointegerns(v2, &i2)) { \
1034+ StkId ra = RA(i); \
10321035 pc++; setivalue(s2v(ra), op(i1, i2)); \
10331036 }}
10341037
@@ -1039,18 +1042,18 @@ void luaV_finishOp (lua_State *L) {
10391042** integers.
10401043*/
10411044#define op_order (L ,opi ,opn ,other ) { \
1042- StkId ra = RA (i); \
1045+ TValue * ra = vRA (i); \
10431046 int cond; \
10441047 TValue *rb = vRB(i); \
1045- if (ttisinteger(s2v(ra) ) && ttisinteger(rb)) { \
1046- lua_Integer ia = ivalue(s2v(ra) ); \
1048+ if (ttisinteger(ra ) && ttisinteger(rb)) { \
1049+ lua_Integer ia = ivalue(ra ); \
10471050 lua_Integer ib = ivalue(rb); \
10481051 cond = opi(ia, ib); \
10491052 } \
1050- else if (ttisnumber(s2v(ra) ) && ttisnumber(rb)) \
1051- cond = opn(s2v(ra) , rb); \
1053+ else if (ttisnumber(ra ) && ttisnumber(rb)) \
1054+ cond = opn(ra , rb); \
10521055 else \
1053- Protect(cond = other(L, s2v(ra) , rb)); \
1056+ Protect(cond = other(L, ra , rb)); \
10541057 docondjump(); }
10551058
10561059
@@ -1059,19 +1062,19 @@ void luaV_finishOp (lua_State *L) {
10591062** always small enough to have an exact representation as a float.)
10601063*/
10611064#define op_orderI (L ,opi ,opf ,inv ,tm ) { \
1062- StkId ra = RA (i); \
1065+ TValue * ra = vRA (i); \
10631066 int cond; \
10641067 int im = GETARG_sB(i); \
1065- if (ttisinteger(s2v(ra) )) \
1066- cond = opi(ivalue(s2v(ra) ), im); \
1067- else if (ttisfloat(s2v(ra) )) { \
1068- lua_Number fa = fltvalue(s2v(ra) ); \
1068+ if (ttisinteger(ra )) \
1069+ cond = opi(ivalue(ra ), im); \
1070+ else if (ttisfloat(ra )) { \
1071+ lua_Number fa = fltvalue(ra ); \
10691072 lua_Number fim = cast_num(im); \
10701073 cond = opf(fa, fim); \
10711074 } \
10721075 else { \
10731076 int isf = GETARG_C(i); \
1074- Protect(cond = luaT_callorderiTM(L, s2v(ra) , im, inv, isf, tm)); \
1077+ Protect(cond = luaT_callorderiTM(L, ra , im, inv, isf, tm)); \
10751078 } \
10761079 docondjump(); }
10771080
@@ -1090,6 +1093,7 @@ void luaV_finishOp (lua_State *L) {
10901093
10911094
10921095#define RA (i ) (base+GETARG_A(i))
1096+ #define vRA (i ) s2v(RA(i))
10931097#define RB (i ) (base+GETARG_B(i))
10941098#define vRB (i ) s2v(RB(i))
10951099#define KB (i ) (k+GETARG_B(i))
@@ -1130,14 +1134,14 @@ void luaV_finishOp (lua_State *L) {
11301134/*
11311135** Correct global 'pc'.
11321136*/
1133- #define savepc (L ) (ci->u.l.savedpc = pc)
1137+ #define savepc (ci ) (ci->u.l.savedpc = pc)
11341138
11351139
11361140/*
11371141** Whenever code can raise errors, the global 'pc' and the global
11381142** 'top' must be correct to report occasional errors.
11391143*/
1140- #define savestate (L ,ci ) (savepc(L ), L->top.p = ci->top.p)
1144+ #define savestate (L ,ci ) (savepc(ci ), L->top.p = ci->top.p)
11411145
11421146
11431147/*
@@ -1147,7 +1151,7 @@ void luaV_finishOp (lua_State *L) {
11471151#define Protect (exp ) (savestate(L,ci), (exp), updatetrap(ci))
11481152
11491153/* special version that does not change the top */
1150- #define ProtectNT (exp ) (savepc(L ), (exp), updatetrap(ci))
1154+ #define ProtectNT (exp ) (savepc(ci ), (exp), updatetrap(ci))
11511155
11521156/*
11531157** Protect code that can only raise errors. (That is, it cannot change
@@ -1165,7 +1169,7 @@ void luaV_finishOp (lua_State *L) {
11651169
11661170/* 'c' is the limit of live values in the stack */
11671171#define checkGC (L ,c ) \
1168- { luaC_condGC(L, (savepc(L ), L->top.p = (c)), \
1172+ { luaC_condGC(L, (savepc(ci ), L->top.p = (c)), \
11691173 updatetrap(ci)); \
11701174 luai_threadyield(L); }
11711175
@@ -1714,7 +1718,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
17141718 if (b != 0 ) /* fixed number of arguments? */
17151719 L -> top .p = ra + b ; /* top signals number of arguments */
17161720 /* else previous instruction set top */
1717- savepc (L ); /* in case of errors */
1721+ savepc (ci ); /* in case of errors */
17181722 if ((newci = luaD_precall (L , ra , nresults )) == NULL )
17191723 updatetrap (ci ); /* C call; nothing else to be done */
17201724 else { /* Lua call: run function in this same C frame */
0 commit comments