diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-11-28 12:51:00 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2017-11-28 12:51:00 -0200 |
commit | 1a5e8c1014a5416108032042d57f06595553d2bd (patch) | |
tree | bafd4c086839196ded55d17bcb409c03fb4093ed /lvm.c | |
parent | ff5fe5104413cf2a5156f86479d4b9b130bad7a6 (diff) | |
download | lua-1a5e8c1014a5416108032042d57f06595553d2bd.tar.gz lua-1a5e8c1014a5416108032042d57f06595553d2bd.tar.bz2 lua-1a5e8c1014a5416108032042d57f06595553d2bd.zip |
conditional jumps unified in label "condjump' + new variable 'vra'
to avoid excessive use of macro 's2v'
Diffstat (limited to 'lvm.c')
-rw-r--r-- | lvm.c | 234 |
1 files changed, 106 insertions, 128 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.318 2017/11/27 17:44:31 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.319 2017/11/28 12:58:18 roberto Exp roberto $ |
3 | ** Lua virtual machine | 3 | ** Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -815,6 +815,7 @@ void luaV_finishOp (lua_State *L) { | |||
815 | updatebase(ci); /* the trap may be just for that */ \ | 815 | updatebase(ci); /* the trap may be just for that */ \ |
816 | } \ | 816 | } \ |
817 | ra = RA(i); /* WARNING: any stack reallocation invalidates 'ra' */ \ | 817 | ra = RA(i); /* WARNING: any stack reallocation invalidates 'ra' */ \ |
818 | vra = s2v(ra); \ | ||
818 | } | 819 | } |
819 | 820 | ||
820 | #define vmdispatch(o) switch(o) | 821 | #define vmdispatch(o) switch(o) |
@@ -831,8 +832,10 @@ void luaV_execute (lua_State *L) { | |||
831 | const Instruction *pc = ci->u.l.savedpc; | 832 | const Instruction *pc = ci->u.l.savedpc; |
832 | /* main loop of interpreter */ | 833 | /* main loop of interpreter */ |
833 | for (;;) { | 834 | for (;;) { |
834 | Instruction i; | 835 | int cond; /* flag for conditional jumps */ |
835 | StkId ra; | 836 | Instruction i; /* instruction being executed */ |
837 | StkId ra; /* instruction's A register */ | ||
838 | TValue *vra; /* corresponding value */ | ||
836 | vmfetch(); | 839 | vmfetch(); |
837 | lua_assert(base == ci->func + 1); | 840 | lua_assert(base == ci->func + 1); |
838 | lua_assert(base <= L->top && L->top < L->stack + L->stacksize); | 841 | lua_assert(base <= L->top && L->top < L->stack + L->stacksize); |
@@ -848,12 +851,12 @@ void luaV_execute (lua_State *L) { | |||
848 | } | 851 | } |
849 | vmcase(OP_LOADI) { | 852 | vmcase(OP_LOADI) { |
850 | lua_Integer b = GETARG_sBx(i); | 853 | lua_Integer b = GETARG_sBx(i); |
851 | setivalue(s2v(ra), b); | 854 | setivalue(vra, b); |
852 | vmbreak; | 855 | vmbreak; |
853 | } | 856 | } |
854 | vmcase(OP_LOADF) { | 857 | vmcase(OP_LOADF) { |
855 | int b = GETARG_sBx(i); | 858 | int b = GETARG_sBx(i); |
856 | setfltvalue(s2v(ra), cast_num(b)); | 859 | setfltvalue(vra, cast_num(b)); |
857 | vmbreak; | 860 | vmbreak; |
858 | } | 861 | } |
859 | vmcase(OP_LOADKX) { | 862 | vmcase(OP_LOADKX) { |
@@ -863,7 +866,7 @@ void luaV_execute (lua_State *L) { | |||
863 | vmbreak; | 866 | vmbreak; |
864 | } | 867 | } |
865 | vmcase(OP_LOADBOOL) { | 868 | vmcase(OP_LOADBOOL) { |
866 | setbvalue(s2v(ra), GETARG_B(i)); | 869 | setbvalue(vra, GETARG_B(i)); |
867 | if (GETARG_C(i)) pc++; /* skip next instruction (if C) */ | 870 | if (GETARG_C(i)) pc++; /* skip next instruction (if C) */ |
868 | vmbreak; | 871 | vmbreak; |
869 | } | 872 | } |
@@ -881,8 +884,8 @@ void luaV_execute (lua_State *L) { | |||
881 | } | 884 | } |
882 | vmcase(OP_SETUPVAL) { | 885 | vmcase(OP_SETUPVAL) { |
883 | UpVal *uv = cl->upvals[GETARG_B(i)]; | 886 | UpVal *uv = cl->upvals[GETARG_B(i)]; |
884 | setobj(L, uv->v, s2v(ra)); | 887 | setobj(L, uv->v, vra); |
885 | luaC_barrier(L, uv, s2v(ra)); | 888 | luaC_barrier(L, uv, vra); |
886 | vmbreak; | 889 | vmbreak; |
887 | } | 890 | } |
888 | vmcase(OP_GETTABUP) { | 891 | vmcase(OP_GETTABUP) { |
@@ -956,25 +959,25 @@ void luaV_execute (lua_State *L) { | |||
956 | TValue *rc = RKC(i); /* value */ | 959 | TValue *rc = RKC(i); /* value */ |
957 | lua_Unsigned n; | 960 | lua_Unsigned n; |
958 | if (ttisinteger(rb) /* fast track for integers? */ | 961 | if (ttisinteger(rb) /* fast track for integers? */ |
959 | ? (n = ivalue(rb), luaV_fastgeti(L, s2v(ra), n, slot)) | 962 | ? (n = ivalue(rb), luaV_fastgeti(L, vra, n, slot)) |
960 | : luaV_fastget(L, s2v(ra), rb, slot, luaH_get)) { | 963 | : luaV_fastget(L, vra, rb, slot, luaH_get)) { |
961 | luaV_finishfastset(L, s2v(ra), slot, rc); | 964 | luaV_finishfastset(L, vra, slot, rc); |
962 | } | 965 | } |
963 | else | 966 | else |
964 | Protect(luaV_finishset(L, s2v(ra), rb, rc, slot)); | 967 | Protect(luaV_finishset(L, vra, rb, rc, slot)); |
965 | vmbreak; | 968 | vmbreak; |
966 | } | 969 | } |
967 | vmcase(OP_SETI) { | 970 | vmcase(OP_SETI) { |
968 | const TValue *slot; | 971 | const TValue *slot; |
969 | int c = GETARG_B(i); | 972 | int c = GETARG_B(i); |
970 | TValue *rc = RKC(i); | 973 | TValue *rc = RKC(i); |
971 | if (luaV_fastgeti(L, s2v(ra), c, slot)) { | 974 | if (luaV_fastgeti(L, vra, c, slot)) { |
972 | luaV_finishfastset(L, s2v(ra), slot, rc); | 975 | luaV_finishfastset(L, vra, slot, rc); |
973 | } | 976 | } |
974 | else { | 977 | else { |
975 | TValue key; | 978 | TValue key; |
976 | setivalue(&key, c); | 979 | setivalue(&key, c); |
977 | Protect(luaV_finishset(L, s2v(ra), &key, rc, slot)); | 980 | Protect(luaV_finishset(L, vra, &key, rc, slot)); |
978 | } | 981 | } |
979 | vmbreak; | 982 | vmbreak; |
980 | } | 983 | } |
@@ -983,11 +986,11 @@ void luaV_execute (lua_State *L) { | |||
983 | TValue *rb = KB(i); | 986 | TValue *rb = KB(i); |
984 | TValue *rc = RKC(i); | 987 | TValue *rc = RKC(i); |
985 | TString *key = tsvalue(rb); /* key must be a string */ | 988 | TString *key = tsvalue(rb); /* key must be a string */ |
986 | if (luaV_fastget(L, s2v(ra), key, slot, luaH_getshortstr)) { | 989 | if (luaV_fastget(L, vra, key, slot, luaH_getshortstr)) { |
987 | luaV_finishfastset(L, s2v(ra), slot, rc); | 990 | luaV_finishfastset(L, vra, slot, rc); |
988 | } | 991 | } |
989 | else | 992 | else |
990 | Protect(luaV_finishset(L, s2v(ra), rb, rc, slot)); | 993 | Protect(luaV_finishset(L, vra, rb, rc, slot)); |
991 | vmbreak; | 994 | vmbreak; |
992 | } | 995 | } |
993 | vmcase(OP_NEWTABLE) { | 996 | vmcase(OP_NEWTABLE) { |
@@ -1020,10 +1023,10 @@ void luaV_execute (lua_State *L) { | |||
1020 | int ic = GETARG_sC(i); | 1023 | int ic = GETARG_sC(i); |
1021 | lua_Number nb; | 1024 | lua_Number nb; |
1022 | if (ttisinteger(rb)) { | 1025 | if (ttisinteger(rb)) { |
1023 | setivalue(s2v(ra), intop(+, ivalue(rb), ic)); | 1026 | setivalue(vra, intop(+, ivalue(rb), ic)); |
1024 | } | 1027 | } |
1025 | else if (tonumberns(rb, nb)) { | 1028 | else if (tonumberns(rb, nb)) { |
1026 | setfltvalue(s2v(ra), luai_numadd(L, nb, cast_num(ic))); | 1029 | setfltvalue(vra, luai_numadd(L, nb, cast_num(ic))); |
1027 | } | 1030 | } |
1028 | else | 1031 | else |
1029 | Protect(luaT_trybiniTM(L, rb, ic, GETARG_k(i), ra, TM_ADD)); | 1032 | Protect(luaT_trybiniTM(L, rb, ic, GETARG_k(i), ra, TM_ADD)); |
@@ -1034,10 +1037,10 @@ void luaV_execute (lua_State *L) { | |||
1034 | int ic = GETARG_sC(i); | 1037 | int ic = GETARG_sC(i); |
1035 | lua_Number nb; | 1038 | lua_Number nb; |
1036 | if (ttisinteger(rb)) { | 1039 | if (ttisinteger(rb)) { |
1037 | setivalue(s2v(ra), intop(-, ivalue(rb), ic)); | 1040 | setivalue(vra, intop(-, ivalue(rb), ic)); |
1038 | } | 1041 | } |
1039 | else if (tonumberns(rb, nb)) { | 1042 | else if (tonumberns(rb, nb)) { |
1040 | setfltvalue(s2v(ra), luai_numsub(L, nb, cast_num(ic))); | 1043 | setfltvalue(vra, luai_numsub(L, nb, cast_num(ic))); |
1041 | } | 1044 | } |
1042 | else | 1045 | else |
1043 | Protect(luaT_trybiniTM(L, rb, ic, 0, ra, TM_SUB)); | 1046 | Protect(luaT_trybiniTM(L, rb, ic, 0, ra, TM_SUB)); |
@@ -1048,10 +1051,10 @@ void luaV_execute (lua_State *L) { | |||
1048 | int ic = GETARG_sC(i); | 1051 | int ic = GETARG_sC(i); |
1049 | lua_Number nb; | 1052 | lua_Number nb; |
1050 | if (ttisinteger(rb)) { | 1053 | if (ttisinteger(rb)) { |
1051 | setivalue(s2v(ra), intop(*, ivalue(rb), ic)); | 1054 | setivalue(vra, intop(*, ivalue(rb), ic)); |
1052 | } | 1055 | } |
1053 | else if (tonumberns(rb, nb)) { | 1056 | else if (tonumberns(rb, nb)) { |
1054 | setfltvalue(s2v(ra), luai_nummul(L, nb, cast_num(ic))); | 1057 | setfltvalue(vra, luai_nummul(L, nb, cast_num(ic))); |
1055 | } | 1058 | } |
1056 | else | 1059 | else |
1057 | Protect(luaT_trybiniTM(L, rb, ic, GETARG_k(i), ra, TM_MUL)); | 1060 | Protect(luaT_trybiniTM(L, rb, ic, GETARG_k(i), ra, TM_MUL)); |
@@ -1062,13 +1065,13 @@ void luaV_execute (lua_State *L) { | |||
1062 | int ic = GETARG_sC(i); | 1065 | int ic = GETARG_sC(i); |
1063 | lua_Number nb; | 1066 | lua_Number nb; |
1064 | if (ttisinteger(rb)) { | 1067 | if (ttisinteger(rb)) { |
1065 | setivalue(s2v(ra), luaV_mod(L, ivalue(rb), ic)); | 1068 | setivalue(vra, luaV_mod(L, ivalue(rb), ic)); |
1066 | } | 1069 | } |
1067 | else if (tonumberns(rb, nb)) { | 1070 | else if (tonumberns(rb, nb)) { |
1068 | lua_Number m; | 1071 | lua_Number m; |
1069 | lua_Number nc = cast_num(ic); | 1072 | lua_Number nc = cast_num(ic); |
1070 | luai_nummod(L, nb, nc, m); | 1073 | luai_nummod(L, nb, nc, m); |
1071 | setfltvalue(s2v(ra), m); | 1074 | setfltvalue(vra, m); |
1072 | } | 1075 | } |
1073 | else | 1076 | else |
1074 | Protect(luaT_trybiniTM(L, rb, ic, 0, ra, TM_MOD)); | 1077 | Protect(luaT_trybiniTM(L, rb, ic, 0, ra, TM_MOD)); |
@@ -1080,7 +1083,7 @@ void luaV_execute (lua_State *L) { | |||
1080 | lua_Number nb; | 1083 | lua_Number nb; |
1081 | if (tonumberns(rb, nb)) { | 1084 | if (tonumberns(rb, nb)) { |
1082 | lua_Number nc = cast_num(ic); | 1085 | lua_Number nc = cast_num(ic); |
1083 | setfltvalue(s2v(ra), luai_numpow(L, nb, nc)); | 1086 | setfltvalue(vra, luai_numpow(L, nb, nc)); |
1084 | } | 1087 | } |
1085 | else | 1088 | else |
1086 | Protect(luaT_trybiniTM(L, rb, ic, 0, ra, TM_POW)); | 1089 | Protect(luaT_trybiniTM(L, rb, ic, 0, ra, TM_POW)); |
@@ -1092,7 +1095,7 @@ void luaV_execute (lua_State *L) { | |||
1092 | lua_Number nb; | 1095 | lua_Number nb; |
1093 | if (tonumberns(rb, nb)) { | 1096 | if (tonumberns(rb, nb)) { |
1094 | lua_Number nc = cast_num(ic); | 1097 | lua_Number nc = cast_num(ic); |
1095 | setfltvalue(s2v(ra), luai_numdiv(L, nb, nc)); | 1098 | setfltvalue(vra, luai_numdiv(L, nb, nc)); |
1096 | } | 1099 | } |
1097 | else | 1100 | else |
1098 | Protect(luaT_trybiniTM(L, rb, ic, 0, ra, TM_DIV)); | 1101 | Protect(luaT_trybiniTM(L, rb, ic, 0, ra, TM_DIV)); |
@@ -1103,11 +1106,11 @@ void luaV_execute (lua_State *L) { | |||
1103 | int ic = GETARG_sC(i); | 1106 | int ic = GETARG_sC(i); |
1104 | lua_Number nb; | 1107 | lua_Number nb; |
1105 | if (ttisinteger(rb)) { | 1108 | if (ttisinteger(rb)) { |
1106 | setivalue(s2v(ra), luaV_div(L, ivalue(rb), ic)); | 1109 | setivalue(vra, luaV_div(L, ivalue(rb), ic)); |
1107 | } | 1110 | } |
1108 | else if (tonumberns(rb, nb)) { | 1111 | else if (tonumberns(rb, nb)) { |
1109 | lua_Number nc = cast_num(ic); | 1112 | lua_Number nc = cast_num(ic); |
1110 | setfltvalue(s2v(ra), luai_numdiv(L, nb, nc)); | 1113 | setfltvalue(vra, luai_numdiv(L, nb, nc)); |
1111 | } | 1114 | } |
1112 | else | 1115 | else |
1113 | Protect(luaT_trybiniTM(L, rb, ic, 0, ra, TM_IDIV)); | 1116 | Protect(luaT_trybiniTM(L, rb, ic, 0, ra, TM_IDIV)); |
@@ -1119,10 +1122,10 @@ void luaV_execute (lua_State *L) { | |||
1119 | lua_Number nb; lua_Number nc; | 1122 | lua_Number nb; lua_Number nc; |
1120 | if (ttisinteger(rb) && ttisinteger(rc)) { | 1123 | if (ttisinteger(rb) && ttisinteger(rc)) { |
1121 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); | 1124 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); |
1122 | setivalue(s2v(ra), intop(+, ib, ic)); | 1125 | setivalue(vra, intop(+, ib, ic)); |
1123 | } | 1126 | } |
1124 | else if (tonumberns(rb, nb) && tonumberns(rc, nc)) { | 1127 | else if (tonumberns(rb, nb) && tonumberns(rc, nc)) { |
1125 | setfltvalue(s2v(ra), luai_numadd(L, nb, nc)); | 1128 | setfltvalue(vra, luai_numadd(L, nb, nc)); |
1126 | } | 1129 | } |
1127 | else | 1130 | else |
1128 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_ADD)); | 1131 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_ADD)); |
@@ -1134,10 +1137,10 @@ void luaV_execute (lua_State *L) { | |||
1134 | lua_Number nb; lua_Number nc; | 1137 | lua_Number nb; lua_Number nc; |
1135 | if (ttisinteger(rb) && ttisinteger(rc)) { | 1138 | if (ttisinteger(rb) && ttisinteger(rc)) { |
1136 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); | 1139 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); |
1137 | setivalue(s2v(ra), intop(-, ib, ic)); | 1140 | setivalue(vra, intop(-, ib, ic)); |
1138 | } | 1141 | } |
1139 | else if (tonumberns(rb, nb) && tonumberns(rc, nc)) { | 1142 | else if (tonumberns(rb, nb) && tonumberns(rc, nc)) { |
1140 | setfltvalue(s2v(ra), luai_numsub(L, nb, nc)); | 1143 | setfltvalue(vra, luai_numsub(L, nb, nc)); |
1141 | } | 1144 | } |
1142 | else | 1145 | else |
1143 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_SUB)); | 1146 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_SUB)); |
@@ -1149,10 +1152,10 @@ void luaV_execute (lua_State *L) { | |||
1149 | lua_Number nb; lua_Number nc; | 1152 | lua_Number nb; lua_Number nc; |
1150 | if (ttisinteger(rb) && ttisinteger(rc)) { | 1153 | if (ttisinteger(rb) && ttisinteger(rc)) { |
1151 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); | 1154 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); |
1152 | setivalue(s2v(ra), intop(*, ib, ic)); | 1155 | setivalue(vra, intop(*, ib, ic)); |
1153 | } | 1156 | } |
1154 | else if (tonumberns(rb, nb) && tonumberns(rc, nc)) { | 1157 | else if (tonumberns(rb, nb) && tonumberns(rc, nc)) { |
1155 | setfltvalue(s2v(ra), luai_nummul(L, nb, nc)); | 1158 | setfltvalue(vra, luai_nummul(L, nb, nc)); |
1156 | } | 1159 | } |
1157 | else | 1160 | else |
1158 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_MUL)); | 1161 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_MUL)); |
@@ -1163,7 +1166,7 @@ void luaV_execute (lua_State *L) { | |||
1163 | TValue *rc = vRC(i); | 1166 | TValue *rc = vRC(i); |
1164 | lua_Number nb; lua_Number nc; | 1167 | lua_Number nb; lua_Number nc; |
1165 | if (tonumberns(rb, nb) && tonumberns(rc, nc)) { | 1168 | if (tonumberns(rb, nb) && tonumberns(rc, nc)) { |
1166 | setfltvalue(s2v(ra), luai_numdiv(L, nb, nc)); | 1169 | setfltvalue(vra, luai_numdiv(L, nb, nc)); |
1167 | } | 1170 | } |
1168 | else | 1171 | else |
1169 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_DIV)); | 1172 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_DIV)); |
@@ -1174,7 +1177,7 @@ void luaV_execute (lua_State *L) { | |||
1174 | TValue *rc = vRC(i); | 1177 | TValue *rc = vRC(i); |
1175 | lua_Integer ib; lua_Integer ic; | 1178 | lua_Integer ib; lua_Integer ic; |
1176 | if (tointegerns(rb, &ib) && tointegerns(rc, &ic)) { | 1179 | if (tointegerns(rb, &ib) && tointegerns(rc, &ic)) { |
1177 | setivalue(s2v(ra), intop(&, ib, ic)); | 1180 | setivalue(vra, intop(&, ib, ic)); |
1178 | } | 1181 | } |
1179 | else | 1182 | else |
1180 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_BAND)); | 1183 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_BAND)); |
@@ -1185,7 +1188,7 @@ void luaV_execute (lua_State *L) { | |||
1185 | TValue *rc = vRC(i); | 1188 | TValue *rc = vRC(i); |
1186 | lua_Integer ib; lua_Integer ic; | 1189 | lua_Integer ib; lua_Integer ic; |
1187 | if (tointegerns(rb, &ib) && tointegerns(rc, &ic)) { | 1190 | if (tointegerns(rb, &ib) && tointegerns(rc, &ic)) { |
1188 | setivalue(s2v(ra), intop(|, ib, ic)); | 1191 | setivalue(vra, intop(|, ib, ic)); |
1189 | } | 1192 | } |
1190 | else | 1193 | else |
1191 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_BOR)); | 1194 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_BOR)); |
@@ -1196,7 +1199,7 @@ void luaV_execute (lua_State *L) { | |||
1196 | TValue *rc = vRC(i); | 1199 | TValue *rc = vRC(i); |
1197 | lua_Integer ib; lua_Integer ic; | 1200 | lua_Integer ib; lua_Integer ic; |
1198 | if (tointegerns(rb, &ib) && tointegerns(rc, &ic)) { | 1201 | if (tointegerns(rb, &ib) && tointegerns(rc, &ic)) { |
1199 | setivalue(s2v(ra), intop(^, ib, ic)); | 1202 | setivalue(vra, intop(^, ib, ic)); |
1200 | } | 1203 | } |
1201 | else | 1204 | else |
1202 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_BXOR)); | 1205 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_BXOR)); |
@@ -1207,7 +1210,7 @@ void luaV_execute (lua_State *L) { | |||
1207 | TValue *rc = vRC(i); | 1210 | TValue *rc = vRC(i); |
1208 | lua_Integer ib; lua_Integer ic; | 1211 | lua_Integer ib; lua_Integer ic; |
1209 | if (tointegerns(rb, &ib) && tointegerns(rc, &ic)) { | 1212 | if (tointegerns(rb, &ib) && tointegerns(rc, &ic)) { |
1210 | setivalue(s2v(ra), luaV_shiftl(ib, ic)); | 1213 | setivalue(vra, luaV_shiftl(ib, ic)); |
1211 | } | 1214 | } |
1212 | else | 1215 | else |
1213 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHL)); | 1216 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHL)); |
@@ -1218,7 +1221,7 @@ void luaV_execute (lua_State *L) { | |||
1218 | TValue *rc = vRC(i); | 1221 | TValue *rc = vRC(i); |
1219 | lua_Integer ib; lua_Integer ic; | 1222 | lua_Integer ib; lua_Integer ic; |
1220 | if (tointegerns(rb, &ib) && tointegerns(rc, &ic)) { | 1223 | if (tointegerns(rb, &ib) && tointegerns(rc, &ic)) { |
1221 | setivalue(s2v(ra), luaV_shiftl(ib, -ic)); | 1224 | setivalue(vra, luaV_shiftl(ib, -ic)); |
1222 | } | 1225 | } |
1223 | else | 1226 | else |
1224 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHR)); | 1227 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_SHR)); |
@@ -1230,12 +1233,12 @@ void luaV_execute (lua_State *L) { | |||
1230 | lua_Number nb; lua_Number nc; | 1233 | lua_Number nb; lua_Number nc; |
1231 | if (ttisinteger(rb) && ttisinteger(rc)) { | 1234 | if (ttisinteger(rb) && ttisinteger(rc)) { |
1232 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); | 1235 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); |
1233 | setivalue(s2v(ra), luaV_mod(L, ib, ic)); | 1236 | setivalue(vra, luaV_mod(L, ib, ic)); |
1234 | } | 1237 | } |
1235 | else if (tonumberns(rb, nb) && tonumberns(rc, nc)) { | 1238 | else if (tonumberns(rb, nb) && tonumberns(rc, nc)) { |
1236 | lua_Number m; | 1239 | lua_Number m; |
1237 | luai_nummod(L, nb, nc, m); | 1240 | luai_nummod(L, nb, nc, m); |
1238 | setfltvalue(s2v(ra), m); | 1241 | setfltvalue(vra, m); |
1239 | } | 1242 | } |
1240 | else | 1243 | else |
1241 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_MOD)); | 1244 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_MOD)); |
@@ -1247,10 +1250,10 @@ void luaV_execute (lua_State *L) { | |||
1247 | lua_Number nb; lua_Number nc; | 1250 | lua_Number nb; lua_Number nc; |
1248 | if (ttisinteger(rb) && ttisinteger(rc)) { | 1251 | if (ttisinteger(rb) && ttisinteger(rc)) { |
1249 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); | 1252 | lua_Integer ib = ivalue(rb); lua_Integer ic = ivalue(rc); |
1250 | setivalue(s2v(ra), luaV_div(L, ib, ic)); | 1253 | setivalue(vra, luaV_div(L, ib, ic)); |
1251 | } | 1254 | } |
1252 | else if (tonumberns(rb, nb) && tonumberns(rc, nc)) { | 1255 | else if (tonumberns(rb, nb) && tonumberns(rc, nc)) { |
1253 | setfltvalue(s2v(ra), luai_numidiv(L, nb, nc)); | 1256 | setfltvalue(vra, luai_numidiv(L, nb, nc)); |
1254 | } | 1257 | } |
1255 | else | 1258 | else |
1256 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_IDIV)); | 1259 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_IDIV)); |
@@ -1261,7 +1264,7 @@ void luaV_execute (lua_State *L) { | |||
1261 | TValue *rc = vRC(i); | 1264 | TValue *rc = vRC(i); |
1262 | lua_Number nb; lua_Number nc; | 1265 | lua_Number nb; lua_Number nc; |
1263 | if (tonumberns(rb, nb) && tonumberns(rc, nc)) { | 1266 | if (tonumberns(rb, nb) && tonumberns(rc, nc)) { |
1264 | setfltvalue(s2v(ra), luai_numpow(L, nb, nc)); | 1267 | setfltvalue(vra, luai_numpow(L, nb, nc)); |
1265 | } | 1268 | } |
1266 | else | 1269 | else |
1267 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_POW)); | 1270 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_POW)); |
@@ -1272,10 +1275,10 @@ void luaV_execute (lua_State *L) { | |||
1272 | lua_Number nb; | 1275 | lua_Number nb; |
1273 | if (ttisinteger(rb)) { | 1276 | if (ttisinteger(rb)) { |
1274 | lua_Integer ib = ivalue(rb); | 1277 | lua_Integer ib = ivalue(rb); |
1275 | setivalue(s2v(ra), intop(-, 0, ib)); | 1278 | setivalue(vra, intop(-, 0, ib)); |
1276 | } | 1279 | } |
1277 | else if (tonumberns(rb, nb)) { | 1280 | else if (tonumberns(rb, nb)) { |
1278 | setfltvalue(s2v(ra), luai_numunm(L, nb)); | 1281 | setfltvalue(vra, luai_numunm(L, nb)); |
1279 | } | 1282 | } |
1280 | else | 1283 | else |
1281 | Protect(luaT_trybinTM(L, rb, rb, ra, TM_UNM)); | 1284 | Protect(luaT_trybinTM(L, rb, rb, ra, TM_UNM)); |
@@ -1285,7 +1288,7 @@ void luaV_execute (lua_State *L) { | |||
1285 | TValue *rb = vRB(i); | 1288 | TValue *rb = vRB(i); |
1286 | lua_Integer ib; | 1289 | lua_Integer ib; |
1287 | if (tointegerns(rb, &ib)) { | 1290 | if (tointegerns(rb, &ib)) { |
1288 | setivalue(s2v(ra), intop(^, ~l_castS2U(0), ib)); | 1291 | setivalue(vra, intop(^, ~l_castS2U(0), ib)); |
1289 | } | 1292 | } |
1290 | else | 1293 | else |
1291 | Protect(luaT_trybinTM(L, rb, rb, ra, TM_BNOT)); | 1294 | Protect(luaT_trybinTM(L, rb, rb, ra, TM_BNOT)); |
@@ -1293,8 +1296,8 @@ void luaV_execute (lua_State *L) { | |||
1293 | } | 1296 | } |
1294 | vmcase(OP_NOT) { | 1297 | vmcase(OP_NOT) { |
1295 | TValue *rb = vRB(i); | 1298 | TValue *rb = vRB(i); |
1296 | int res = l_isfalse(rb); /* next assignment may change this value */ | 1299 | int nrb = l_isfalse(rb); /* next assignment may change this value */ |
1297 | setbvalue(s2v(ra), res); | 1300 | setbvalue(vra, nrb); |
1298 | vmbreak; | 1301 | vmbreak; |
1299 | } | 1302 | } |
1300 | vmcase(OP_LEN) { | 1303 | vmcase(OP_LEN) { |
@@ -1327,105 +1330,79 @@ void luaV_execute (lua_State *L) { | |||
1327 | } | 1330 | } |
1328 | vmcase(OP_EQ) { | 1331 | vmcase(OP_EQ) { |
1329 | TValue *rb = vRB(i); | 1332 | TValue *rb = vRB(i); |
1330 | int res; | 1333 | Protect(cond = luaV_equalobj(L, vra, rb)); |
1331 | Protect(res = luaV_equalobj(L, s2v(ra), rb)); | 1334 | condjump: |
1332 | if (res != GETARG_k(i)) | 1335 | if (cond != GETARG_k(i)) |
1333 | pc++; | 1336 | pc++; /* skip next jump */ |
1334 | else | 1337 | else |
1335 | donextjump(ci); | 1338 | donextjump(ci); |
1336 | vmbreak; | 1339 | vmbreak; |
1337 | } | 1340 | } |
1338 | vmcase(OP_LT) { | 1341 | vmcase(OP_LT) { |
1339 | TValue *rb = vRB(i); | 1342 | TValue *rb = vRB(i); |
1340 | int res; | 1343 | if (ttisinteger(vra) && ttisinteger(rb)) |
1341 | if (ttisinteger(s2v(ra)) && ttisinteger(rb)) | 1344 | cond = (ivalue(vra) < ivalue(rb)); |
1342 | res = (ivalue(s2v(ra)) < ivalue(rb)); | 1345 | else if (ttisnumber(vra) && ttisnumber(rb)) |
1343 | else if (ttisnumber(s2v(ra)) && ttisnumber(rb)) | 1346 | cond = LTnum(vra, rb); |
1344 | res = LTnum(s2v(ra), rb); | ||
1345 | else | ||
1346 | Protect(res = lessthanothers(L, s2v(ra), rb)); | ||
1347 | if (res != GETARG_k(i)) | ||
1348 | pc++; | ||
1349 | else | 1347 | else |
1350 | donextjump(ci); | 1348 | Protect(cond = lessthanothers(L, vra, rb)); |
1351 | vmbreak; | 1349 | goto condjump; |
1352 | } | 1350 | } |
1353 | vmcase(OP_LE) { | 1351 | vmcase(OP_LE) { |
1354 | TValue *rb = vRB(i); | 1352 | TValue *rb = vRB(i); |
1355 | int res; | 1353 | if (ttisinteger(vra) && ttisinteger(rb)) |
1356 | if (ttisinteger(s2v(ra)) && ttisinteger(rb)) | 1354 | cond = (ivalue(vra) <= ivalue(rb)); |
1357 | res = (ivalue(s2v(ra)) <= ivalue(rb)); | 1355 | else if (ttisnumber(vra) && ttisnumber(rb)) |
1358 | else if (ttisnumber(s2v(ra)) && ttisnumber(rb)) | 1356 | cond = LEnum(vra, rb); |
1359 | res = LEnum(s2v(ra), rb); | ||
1360 | else | ||
1361 | Protect(res = lessequalothers(L, s2v(ra), rb)); | ||
1362 | if (res != GETARG_k(i)) | ||
1363 | pc++; | ||
1364 | else | 1357 | else |
1365 | donextjump(ci); | 1358 | Protect(cond = lessequalothers(L, vra, rb)); |
1366 | vmbreak; | 1359 | goto condjump; |
1367 | } | 1360 | } |
1368 | vmcase(OP_EQK) { | 1361 | vmcase(OP_EQK) { |
1369 | TValue *rb = KB(i); | 1362 | TValue *rb = KB(i); |
1370 | /* basic types do not use '__eq'; we can use raw equality */ | 1363 | /* basic types do not use '__eq'; we can use raw equality */ |
1371 | if (luaV_equalobj(NULL, s2v(ra), rb) != GETARG_k(i)) | 1364 | cond = luaV_equalobj(NULL, vra, rb); |
1372 | pc++; | 1365 | goto condjump; |
1373 | else | ||
1374 | donextjump(ci); | ||
1375 | vmbreak; | ||
1376 | } | 1366 | } |
1377 | vmcase(OP_EQI) { | 1367 | vmcase(OP_EQI) { |
1378 | int im = GETARG_sB(i); | 1368 | int im = GETARG_sB(i); |
1379 | if ((ttisinteger(s2v(ra)) ? (ivalue(s2v(ra)) == im) | 1369 | if (ttisinteger(vra)) |
1380 | :ttisfloat(s2v(ra)) ? luai_numeq(fltvalue(s2v(ra)), cast_num(im)) | 1370 | cond = (ivalue(vra) == im); |
1381 | : 0) != GETARG_k(i)) | 1371 | else if (ttisfloat(vra)) |
1382 | pc++; | 1372 | cond = luai_numeq(fltvalue(vra), cast_num(im)); |
1383 | else | 1373 | else |
1384 | donextjump(ci); | 1374 | cond = 0; /* other types cannot be equal to a number */ |
1385 | vmbreak; | 1375 | goto condjump; |
1386 | } | 1376 | } |
1387 | vmcase(OP_LTI) { | 1377 | vmcase(OP_LTI) { |
1388 | int res; | ||
1389 | int im = GETARG_sB(i); | 1378 | int im = GETARG_sB(i); |
1390 | if (ttisinteger(s2v(ra))) | 1379 | if (ttisinteger(vra)) |
1391 | res = (ivalue(s2v(ra)) < im); | 1380 | cond = (ivalue(vra) < im); |
1392 | else if (ttisfloat(s2v(ra))) { | 1381 | else if (ttisfloat(vra)) { |
1393 | lua_Number f = fltvalue(s2v(ra)); | 1382 | lua_Number f = fltvalue(vra); |
1394 | res = (!luai_numisnan(f)) ? luai_numlt(f, cast_num(im)) | 1383 | cond = (!luai_numisnan(f)) ? luai_numlt(f, cast_num(im)) |
1395 | : GETARG_C(i); /* NaN? */ | 1384 | : GETARG_C(i); /* NaN */ |
1396 | } | 1385 | } |
1397 | else | 1386 | else |
1398 | Protect(res = luaT_callorderiTM(L, s2v(ra), im, GETARG_C(i), TM_LT)); | 1387 | Protect(cond = luaT_callorderiTM(L, vra, im, GETARG_C(i), TM_LT)); |
1399 | if (res != GETARG_k(i)) | 1388 | goto condjump; |
1400 | pc++; | ||
1401 | else | ||
1402 | donextjump(ci); | ||
1403 | vmbreak; | ||
1404 | } | 1389 | } |
1405 | vmcase(OP_LEI) { | 1390 | vmcase(OP_LEI) { |
1406 | int res; | ||
1407 | int im = GETARG_sB(i); | 1391 | int im = GETARG_sB(i); |
1408 | if (ttisinteger(s2v(ra))) | 1392 | if (ttisinteger(vra)) |
1409 | res = (ivalue(s2v(ra)) <= im); | 1393 | cond = (ivalue(vra) <= im); |
1410 | else if (ttisfloat(s2v(ra))) { | 1394 | else if (ttisfloat(vra)) { |
1411 | lua_Number f = fltvalue(s2v(ra)); | 1395 | lua_Number f = fltvalue(vra); |
1412 | res = (!luai_numisnan(f)) ? luai_numle(f, cast_num(im)) | 1396 | cond = (!luai_numisnan(f)) ? luai_numle(f, cast_num(im)) |
1413 | : GETARG_C(i); /* NaN? */ | 1397 | : GETARG_C(i); /* NaN? */ |
1414 | } | 1398 | } |
1415 | else | 1399 | else |
1416 | Protect(res = luaT_callorderiTM(L, s2v(ra), im, GETARG_C(i), TM_LE)); | 1400 | Protect(cond = luaT_callorderiTM(L, vra, im, GETARG_C(i), TM_LE)); |
1417 | if (res != GETARG_k(i)) | 1401 | goto condjump; |
1418 | pc++; | ||
1419 | else | ||
1420 | donextjump(ci); | ||
1421 | vmbreak; | ||
1422 | } | 1402 | } |
1423 | vmcase(OP_TEST) { | 1403 | vmcase(OP_TEST) { |
1424 | if (l_isfalse(s2v(ra)) == GETARG_k(i)) | 1404 | cond = !l_isfalse(vra); |
1425 | pc++; | 1405 | goto condjump; |
1426 | else | ||
1427 | donextjump(ci); | ||
1428 | vmbreak; | ||
1429 | } | 1406 | } |
1430 | vmcase(OP_TESTSET) { | 1407 | vmcase(OP_TESTSET) { |
1431 | TValue *rb = vRB(i); | 1408 | TValue *rb = vRB(i); |
@@ -1456,12 +1433,13 @@ void luaV_execute (lua_State *L) { | |||
1456 | else /* previous instruction set top */ | 1433 | else /* previous instruction set top */ |
1457 | b = L->top - ra; | 1434 | b = L->top - ra; |
1458 | lua_assert(GETARG_C(i) - 1 == LUA_MULTRET); | 1435 | lua_assert(GETARG_C(i) - 1 == LUA_MULTRET); |
1459 | if (!ttisfunction(s2v(ra))) { /* not a function? */ | 1436 | if (!ttisfunction(vra)) { /* not a function? */ |
1460 | /* try to get '__call' metamethod */ | 1437 | /* try to get '__call' metamethod */ |
1461 | Protect(ra = luaD_tryfuncTM(L, ra)); | 1438 | Protect(ra = luaD_tryfuncTM(L, ra)); |
1439 | vra = s2v(ra); | ||
1462 | b++; /* there is now one extra argument */ | 1440 | b++; /* there is now one extra argument */ |
1463 | } | 1441 | } |
1464 | if (!ttisLclosure(s2v(ra))) /* C function? */ | 1442 | if (!ttisLclosure(vra)) /* C function? */ |
1465 | Protect(luaD_call(L, ra, LUA_MULTRET)); /* call it */ | 1443 | Protect(luaD_call(L, ra, LUA_MULTRET)); /* call it */ |
1466 | else { /* tail call */ | 1444 | else { /* tail call */ |
1467 | if (cl->p->sizep > 0) /* close upvalues from previous call */ | 1445 | if (cl->p->sizep > 0) /* close upvalues from previous call */ |
@@ -1483,25 +1461,25 @@ void luaV_execute (lua_State *L) { | |||
1483 | return; /* external invocation: return */ | 1461 | return; /* external invocation: return */ |
1484 | } | 1462 | } |
1485 | vmcase(OP_FORLOOP) { | 1463 | vmcase(OP_FORLOOP) { |
1486 | if (ttisinteger(s2v(ra))) { /* integer loop? */ | 1464 | if (ttisinteger(vra)) { /* integer loop? */ |
1487 | lua_Integer step = ivalue(s2v(ra + 2)); | 1465 | lua_Integer step = ivalue(s2v(ra + 2)); |
1488 | lua_Integer idx = intop(+, ivalue(s2v(ra)), step); /* increment index */ | 1466 | lua_Integer idx = intop(+, ivalue(vra), step); /* increment index */ |
1489 | lua_Integer limit = ivalue(s2v(ra + 1)); | 1467 | lua_Integer limit = ivalue(s2v(ra + 1)); |
1490 | if ((0 < step) ? (idx <= limit) : (limit <= idx)) { | 1468 | if ((0 < step) ? (idx <= limit) : (limit <= idx)) { |
1491 | pc -= GETARG_Bx(i); /* jump back */ | 1469 | pc -= GETARG_Bx(i); /* jump back */ |
1492 | chgivalue(s2v(ra), idx); /* update internal index... */ | 1470 | chgivalue(vra, idx); /* update internal index... */ |
1493 | setivalue(s2v(ra + 3), idx); /* ...and external index */ | 1471 | setivalue(s2v(ra + 3), idx); /* ...and external index */ |
1494 | } | 1472 | } |
1495 | } | 1473 | } |
1496 | else { /* floating loop */ | 1474 | else { /* floating loop */ |
1497 | lua_Number step = fltvalue(s2v(ra + 2)); | 1475 | lua_Number step = fltvalue(s2v(ra + 2)); |
1498 | lua_Number limit = fltvalue(s2v(ra + 1)); | 1476 | lua_Number limit = fltvalue(s2v(ra + 1)); |
1499 | lua_Number idx = fltvalue(s2v(ra)); | 1477 | lua_Number idx = fltvalue(vra); |
1500 | idx = luai_numadd(L, idx, step); /* inc. index */ | 1478 | idx = luai_numadd(L, idx, step); /* inc. index */ |
1501 | if (luai_numlt(0, step) ? luai_numle(idx, limit) | 1479 | if (luai_numlt(0, step) ? luai_numle(idx, limit) |
1502 | : luai_numle(limit, idx)) { | 1480 | : luai_numle(limit, idx)) { |
1503 | pc -= GETARG_Bx(i); /* jump back */ | 1481 | pc -= GETARG_Bx(i); /* jump back */ |
1504 | chgfltvalue(s2v(ra), idx); /* update internal index... */ | 1482 | chgfltvalue(vra, idx); /* update internal index... */ |
1505 | setfltvalue(s2v(ra + 3), idx); /* ...and external index */ | 1483 | setfltvalue(s2v(ra + 3), idx); /* ...and external index */ |
1506 | } | 1484 | } |
1507 | } | 1485 | } |
@@ -1509,7 +1487,7 @@ void luaV_execute (lua_State *L) { | |||
1509 | vmbreak; | 1487 | vmbreak; |
1510 | } | 1488 | } |
1511 | vmcase(OP_FORPREP) { | 1489 | vmcase(OP_FORPREP) { |
1512 | TValue *init = s2v(ra); | 1490 | TValue *init = vra; |
1513 | TValue *plimit = s2v(ra + 1); | 1491 | TValue *plimit = s2v(ra + 1); |
1514 | TValue *pstep = s2v(ra + 2); | 1492 | TValue *pstep = s2v(ra + 2); |
1515 | lua_Integer ilimit; | 1493 | lua_Integer ilimit; |
@@ -1569,7 +1547,7 @@ void luaV_execute (lua_State *L) { | |||
1569 | if (c == 0) { | 1547 | if (c == 0) { |
1570 | c = GETARG_Ax(*pc); pc++; | 1548 | c = GETARG_Ax(*pc); pc++; |
1571 | } | 1549 | } |
1572 | h = hvalue(s2v(ra)); | 1550 | h = hvalue(vra); |
1573 | last = ((c-1)*LFIELDS_PER_FLUSH) + n; | 1551 | last = ((c-1)*LFIELDS_PER_FLUSH) + n; |
1574 | savepc(L); /* in case of allocation errors */ | 1552 | savepc(L); /* in case of allocation errors */ |
1575 | if (last > h->sizearray) /* needs more space? */ | 1553 | if (last > h->sizearray) /* needs more space? */ |