aboutsummaryrefslogtreecommitdiff
path: root/lvm.c
diff options
context:
space:
mode:
Diffstat (limited to 'lvm.c')
-rw-r--r--lvm.c54
1 files changed, 29 insertions, 25 deletions
diff --git a/lvm.c b/lvm.c
index cfdcf97a..bde850ea 100644
--- a/lvm.c
+++ b/lvm.c
@@ -910,6 +910,10 @@ void luaV_finishOp (lua_State *L) {
910/* 910/*
911** {================================================================== 911** {==================================================================
912** Macros for arithmetic/bitwise/comparison opcodes in 'luaV_execute' 912** 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.).
913** =================================================================== 917** ===================================================================
914*/ 918*/
915 919
@@ -931,17 +935,17 @@ void luaV_finishOp (lua_State *L) {
931** operation, 'fop' is the float operation. 935** operation, 'fop' is the float operation.
932*/ 936*/
933#define op_arithI(L,iop,fop) { \ 937#define op_arithI(L,iop,fop) { \
934 StkId ra = RA(i); \ 938 TValue *ra = vRA(i); \
935 TValue *v1 = vRB(i); \ 939 TValue *v1 = vRB(i); \
936 int imm = GETARG_sC(i); \ 940 int imm = GETARG_sC(i); \
937 if (ttisinteger(v1)) { \ 941 if (ttisinteger(v1)) { \
938 lua_Integer iv1 = ivalue(v1); \ 942 lua_Integer iv1 = ivalue(v1); \
939 pc++; setivalue(s2v(ra), iop(L, iv1, imm)); \ 943 pc++; setivalue(ra, iop(L, iv1, imm)); \
940 } \ 944 } \
941 else if (ttisfloat(v1)) { \ 945 else if (ttisfloat(v1)) { \
942 lua_Number nb = fltvalue(v1); \ 946 lua_Number nb = fltvalue(v1); \
943 lua_Number fimm = cast_num(imm); \ 947 lua_Number fimm = cast_num(imm); \
944 pc++; setfltvalue(s2v(ra), fop(L, nb, fimm)); \ 948 pc++; setfltvalue(ra, fop(L, nb, fimm)); \
945 }} 949 }}
946 950
947 951
@@ -952,6 +956,7 @@ void luaV_finishOp (lua_State *L) {
952#define op_arithf_aux(L,v1,v2,fop) { \ 956#define op_arithf_aux(L,v1,v2,fop) { \
953 lua_Number n1; lua_Number n2; \ 957 lua_Number n1; lua_Number n2; \
954 if (tonumberns(v1, n1) && tonumberns(v2, n2)) { \ 958 if (tonumberns(v1, n1) && tonumberns(v2, n2)) { \
959 StkId ra = RA(i); \
955 pc++; setfltvalue(s2v(ra), fop(L, n1, n2)); \ 960 pc++; setfltvalue(s2v(ra), fop(L, n1, n2)); \
956 }} 961 }}
957 962
@@ -960,7 +965,6 @@ void luaV_finishOp (lua_State *L) {
960** Arithmetic operations over floats and others with register operands. 965** Arithmetic operations over floats and others with register operands.
961*/ 966*/
962#define op_arithf(L,fop) { \ 967#define op_arithf(L,fop) { \
963 StkId ra = RA(i); \
964 TValue *v1 = vRB(i); \ 968 TValue *v1 = vRB(i); \
965 TValue *v2 = vRC(i); \ 969 TValue *v2 = vRC(i); \
966 op_arithf_aux(L, v1, v2, fop); } 970 op_arithf_aux(L, v1, v2, fop); }
@@ -970,7 +974,6 @@ void luaV_finishOp (lua_State *L) {
970** Arithmetic operations with K operands for floats. 974** Arithmetic operations with K operands for floats.
971*/ 975*/
972#define op_arithfK(L,fop) { \ 976#define op_arithfK(L,fop) { \
973 StkId ra = RA(i); \
974 TValue *v1 = vRB(i); \ 977 TValue *v1 = vRB(i); \
975 TValue *v2 = KC(i); lua_assert(ttisnumber(v2)); \ 978 TValue *v2 = KC(i); lua_assert(ttisnumber(v2)); \
976 op_arithf_aux(L, v1, v2, fop); } 979 op_arithf_aux(L, v1, v2, fop); }
@@ -980,8 +983,8 @@ void luaV_finishOp (lua_State *L) {
980** Arithmetic operations over integers and floats. 983** Arithmetic operations over integers and floats.
981*/ 984*/
982#define op_arith_aux(L,v1,v2,iop,fop) { \ 985#define op_arith_aux(L,v1,v2,iop,fop) { \
983 StkId ra = RA(i); \
984 if (ttisinteger(v1) && ttisinteger(v2)) { \ 986 if (ttisinteger(v1) && ttisinteger(v2)) { \
987 StkId ra = RA(i); \
985 lua_Integer i1 = ivalue(v1); lua_Integer i2 = ivalue(v2); \ 988 lua_Integer i1 = ivalue(v1); lua_Integer i2 = ivalue(v2); \
986 pc++; setivalue(s2v(ra), iop(L, i1, i2)); \ 989 pc++; setivalue(s2v(ra), iop(L, i1, i2)); \
987 } \ 990 } \
@@ -1010,12 +1013,12 @@ void luaV_finishOp (lua_State *L) {
1010** Bitwise operations with constant operand. 1013** Bitwise operations with constant operand.
1011*/ 1014*/
1012#define op_bitwiseK(L,op) { \ 1015#define op_bitwiseK(L,op) { \
1013 StkId ra = RA(i); \
1014 TValue *v1 = vRB(i); \ 1016 TValue *v1 = vRB(i); \
1015 TValue *v2 = KC(i); \ 1017 TValue *v2 = KC(i); \
1016 lua_Integer i1; \ 1018 lua_Integer i1; \
1017 lua_Integer i2 = ivalue(v2); \ 1019 lua_Integer i2 = ivalue(v2); \
1018 if (tointegerns(v1, &i1)) { \ 1020 if (tointegerns(v1, &i1)) { \
1021 StkId ra = RA(i); \
1019 pc++; setivalue(s2v(ra), op(i1, i2)); \ 1022 pc++; setivalue(s2v(ra), op(i1, i2)); \
1020 }} 1023 }}
1021 1024
@@ -1024,11 +1027,11 @@ void luaV_finishOp (lua_State *L) {
1024** Bitwise operations with register operands. 1027** Bitwise operations with register operands.
1025*/ 1028*/
1026#define op_bitwise(L,op) { \ 1029#define op_bitwise(L,op) { \
1027 StkId ra = RA(i); \
1028 TValue *v1 = vRB(i); \ 1030 TValue *v1 = vRB(i); \
1029 TValue *v2 = vRC(i); \ 1031 TValue *v2 = vRC(i); \
1030 lua_Integer i1; lua_Integer i2; \ 1032 lua_Integer i1; lua_Integer i2; \
1031 if (tointegerns(v1, &i1) && tointegerns(v2, &i2)) { \ 1033 if (tointegerns(v1, &i1) && tointegerns(v2, &i2)) { \
1034 StkId ra = RA(i); \
1032 pc++; setivalue(s2v(ra), op(i1, i2)); \ 1035 pc++; setivalue(s2v(ra), op(i1, i2)); \
1033 }} 1036 }}
1034 1037
@@ -1039,18 +1042,18 @@ void luaV_finishOp (lua_State *L) {
1039** integers. 1042** integers.
1040*/ 1043*/
1041#define op_order(L,opi,opn,other) { \ 1044#define op_order(L,opi,opn,other) { \
1042 StkId ra = RA(i); \ 1045 TValue *ra = vRA(i); \
1043 int cond; \ 1046 int cond; \
1044 TValue *rb = vRB(i); \ 1047 TValue *rb = vRB(i); \
1045 if (ttisinteger(s2v(ra)) && ttisinteger(rb)) { \ 1048 if (ttisinteger(ra) && ttisinteger(rb)) { \
1046 lua_Integer ia = ivalue(s2v(ra)); \ 1049 lua_Integer ia = ivalue(ra); \
1047 lua_Integer ib = ivalue(rb); \ 1050 lua_Integer ib = ivalue(rb); \
1048 cond = opi(ia, ib); \ 1051 cond = opi(ia, ib); \
1049 } \ 1052 } \
1050 else if (ttisnumber(s2v(ra)) && ttisnumber(rb)) \ 1053 else if (ttisnumber(ra) && ttisnumber(rb)) \
1051 cond = opn(s2v(ra), rb); \ 1054 cond = opn(ra, rb); \
1052 else \ 1055 else \
1053 Protect(cond = other(L, s2v(ra), rb)); \ 1056 Protect(cond = other(L, ra, rb)); \
1054 docondjump(); } 1057 docondjump(); }
1055 1058
1056 1059
@@ -1059,19 +1062,19 @@ void luaV_finishOp (lua_State *L) {
1059** always small enough to have an exact representation as a float.) 1062** always small enough to have an exact representation as a float.)
1060*/ 1063*/
1061#define op_orderI(L,opi,opf,inv,tm) { \ 1064#define op_orderI(L,opi,opf,inv,tm) { \
1062 StkId ra = RA(i); \ 1065 TValue *ra = vRA(i); \
1063 int cond; \ 1066 int cond; \
1064 int im = GETARG_sB(i); \ 1067 int im = GETARG_sB(i); \
1065 if (ttisinteger(s2v(ra))) \ 1068 if (ttisinteger(ra)) \
1066 cond = opi(ivalue(s2v(ra)), im); \ 1069 cond = opi(ivalue(ra), im); \
1067 else if (ttisfloat(s2v(ra))) { \ 1070 else if (ttisfloat(ra)) { \
1068 lua_Number fa = fltvalue(s2v(ra)); \ 1071 lua_Number fa = fltvalue(ra); \
1069 lua_Number fim = cast_num(im); \ 1072 lua_Number fim = cast_num(im); \
1070 cond = opf(fa, fim); \ 1073 cond = opf(fa, fim); \
1071 } \ 1074 } \
1072 else { \ 1075 else { \
1073 int isf = GETARG_C(i); \ 1076 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)); \
1075 } \ 1078 } \
1076 docondjump(); } 1079 docondjump(); }
1077 1080
@@ -1090,6 +1093,7 @@ void luaV_finishOp (lua_State *L) {
1090 1093
1091 1094
1092#define RA(i) (base+GETARG_A(i)) 1095#define RA(i) (base+GETARG_A(i))
1096#define vRA(i) s2v(RA(i))
1093#define RB(i) (base+GETARG_B(i)) 1097#define RB(i) (base+GETARG_B(i))
1094#define vRB(i) s2v(RB(i)) 1098#define vRB(i) s2v(RB(i))
1095#define KB(i) (k+GETARG_B(i)) 1099#define KB(i) (k+GETARG_B(i))
@@ -1130,14 +1134,14 @@ void luaV_finishOp (lua_State *L) {
1130/* 1134/*
1131** Correct global 'pc'. 1135** Correct global 'pc'.
1132*/ 1136*/
1133#define savepc(L) (ci->u.l.savedpc = pc) 1137#define savepc(ci) (ci->u.l.savedpc = pc)
1134 1138
1135 1139
1136/* 1140/*
1137** Whenever code can raise errors, the global 'pc' and the global 1141** Whenever code can raise errors, the global 'pc' and the global
1138** 'top' must be correct to report occasional errors. 1142** 'top' must be correct to report occasional errors.
1139*/ 1143*/
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)
1141 1145
1142 1146
1143/* 1147/*
@@ -1147,7 +1151,7 @@ void luaV_finishOp (lua_State *L) {
1147#define Protect(exp) (savestate(L,ci), (exp), updatetrap(ci)) 1151#define Protect(exp) (savestate(L,ci), (exp), updatetrap(ci))
1148 1152
1149/* special version that does not change the top */ 1153/* 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))
1151 1155
1152/* 1156/*
1153** Protect code that can only raise errors. (That is, it cannot change 1157** Protect code that can only raise errors. (That is, it cannot change
@@ -1165,7 +1169,7 @@ void luaV_finishOp (lua_State *L) {
1165 1169
1166/* 'c' is the limit of live values in the stack */ 1170/* 'c' is the limit of live values in the stack */
1167#define checkGC(L,c) \ 1171#define checkGC(L,c) \
1168 { luaC_condGC(L, (savepc(L), L->top.p = (c)), \ 1172 { luaC_condGC(L, (savepc(ci), L->top.p = (c)), \
1169 updatetrap(ci)); \ 1173 updatetrap(ci)); \
1170 luai_threadyield(L); } 1174 luai_threadyield(L); }
1171 1175
@@ -1714,7 +1718,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
1714 if (b != 0) /* fixed number of arguments? */ 1718 if (b != 0) /* fixed number of arguments? */
1715 L->top.p = ra + b; /* top signals number of arguments */ 1719 L->top.p = ra + b; /* top signals number of arguments */
1716 /* else previous instruction set top */ 1720 /* else previous instruction set top */
1717 savepc(L); /* in case of errors */ 1721 savepc(ci); /* in case of errors */
1718 if ((newci = luaD_precall(L, ra, nresults)) == NULL) 1722 if ((newci = luaD_precall(L, ra, nresults)) == NULL)
1719 updatetrap(ci); /* C call; nothing else to be done */ 1723 updatetrap(ci); /* C call; nothing else to be done */
1720 else { /* Lua call: run function in this same C frame */ 1724 else { /* Lua call: run function in this same C frame */