diff options
-rw-r--r-- | lcode.c | 52 | ||||
-rw-r--r-- | ldebug.c | 5 | ||||
-rw-r--r-- | lopcodes.c | 8 | ||||
-rw-r--r-- | lopcodes.h | 6 | ||||
-rw-r--r-- | ltm.c | 19 | ||||
-rw-r--r-- | ltm.h | 4 | ||||
-rw-r--r-- | lvm.c | 36 |
7 files changed, 107 insertions, 23 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lcode.c,v 2.141 2017/11/30 15:37:16 roberto Exp roberto $ | 2 | ** $Id: lcode.c,v 2.142 2017/12/04 17:41:30 roberto Exp roberto $ |
3 | ** Code generator for Lua | 3 | ** Code generator for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -1196,6 +1196,15 @@ static void codeunexpval (FuncState *fs, OpCode op, expdesc *e, int line) { | |||
1196 | } | 1196 | } |
1197 | 1197 | ||
1198 | 1198 | ||
1199 | static void finishbinexpval (FuncState *fs, expdesc *e1, expdesc *e2, | ||
1200 | int pc, int line) { | ||
1201 | freeexps(fs, e1, e2); | ||
1202 | e1->u.info = pc; | ||
1203 | e1->k = VRELOCABLE; /* all those operations are relocatable */ | ||
1204 | luaK_fixline(fs, line); | ||
1205 | } | ||
1206 | |||
1207 | |||
1199 | /* | 1208 | /* |
1200 | ** Emit code for binary expressions that "produce values" | 1209 | ** Emit code for binary expressions that "produce values" |
1201 | ** (everything but logical operators 'and'/'or' and comparison | 1210 | ** (everything but logical operators 'and'/'or' and comparison |
@@ -1209,10 +1218,8 @@ static void codebinexpval (FuncState *fs, OpCode op, | |||
1209 | expdesc *e1, expdesc *e2, int line) { | 1218 | expdesc *e1, expdesc *e2, int line) { |
1210 | int v2 = luaK_exp2anyreg(fs, e2); /* both operands are in registers */ | 1219 | int v2 = luaK_exp2anyreg(fs, e2); /* both operands are in registers */ |
1211 | int v1 = luaK_exp2anyreg(fs, e1); | 1220 | int v1 = luaK_exp2anyreg(fs, e1); |
1212 | freeexps(fs, e1, e2); | 1221 | int pc = luaK_codeABC(fs, op, 0, v1, v2); /* generate opcode */ |
1213 | e1->u.info = luaK_codeABC(fs, op, 0, v1, v2); /* generate opcode */ | 1222 | finishbinexpval(fs, e1, e2, pc, line); |
1214 | e1->k = VRELOCABLE; /* all those operations are relocatable */ | ||
1215 | luaK_fixline(fs, line); | ||
1216 | } | 1223 | } |
1217 | 1224 | ||
1218 | 1225 | ||
@@ -1223,10 +1230,8 @@ static void codebini (FuncState *fs, OpCode op, | |||
1223 | expdesc *e1, expdesc *e2, int k, int line) { | 1230 | expdesc *e1, expdesc *e2, int k, int line) { |
1224 | int v2 = cast_int(e2->u.ival); /* immediate operand */ | 1231 | int v2 = cast_int(e2->u.ival); /* immediate operand */ |
1225 | int v1 = luaK_exp2anyreg(fs, e1); | 1232 | int v1 = luaK_exp2anyreg(fs, e1); |
1226 | freeexp(fs, e1); | 1233 | int pc = codeABsC(fs, op, 0, v1, v2, k); /* generate opcode */ |
1227 | e1->u.info = codeABsC(fs, op, 0, v1, v2, k); /* generate opcode */ | 1234 | finishbinexpval(fs, e1, e2, pc, line); |
1228 | e1->k = VRELOCABLE; /* all those operations are relocatable */ | ||
1229 | luaK_fixline(fs, line); | ||
1230 | } | 1235 | } |
1231 | 1236 | ||
1232 | 1237 | ||
@@ -1265,6 +1270,33 @@ static void codecommutative (FuncState *fs, OpCode op, | |||
1265 | 1270 | ||
1266 | 1271 | ||
1267 | /* | 1272 | /* |
1273 | ** Code bitwise operations; they are all associative, so the function | ||
1274 | ** tries to put an integer constant as the 2nd operand (a K operand). | ||
1275 | */ | ||
1276 | static void codebitwise (FuncState *fs, BinOpr opr, | ||
1277 | expdesc *e1, expdesc *e2, int line) { | ||
1278 | int inv = 0; | ||
1279 | int v1, v2, pc; | ||
1280 | OpCode op; | ||
1281 | if (e1->k == VKINT && luaK_exp2RK(fs, e1)) { | ||
1282 | swapexps(e1, e2); /* 'e2' will be the constant operand */ | ||
1283 | inv = 1; | ||
1284 | } | ||
1285 | else if (!(e2->k == VKINT && luaK_exp2RK(fs, e2))) { /* no constants? */ | ||
1286 | op = cast(OpCode, opr - OPR_BAND + OP_BAND); | ||
1287 | codebinexpval(fs, op, e1, e2, line); /* all-register opcodes */ | ||
1288 | return; | ||
1289 | } | ||
1290 | v1 = luaK_exp2anyreg(fs, e1); | ||
1291 | v2 = e2->u.info; /* index in K array */ | ||
1292 | op = cast(OpCode, opr - OPR_BAND + OP_BANDK); | ||
1293 | lua_assert(ttisinteger(&fs->f->k[v2])); | ||
1294 | pc = luaK_codeABCk(fs, op, 0, v1, v2, inv); | ||
1295 | finishbinexpval(fs, e1, e2, pc, line); | ||
1296 | } | ||
1297 | |||
1298 | |||
1299 | /* | ||
1268 | ** Code shift operators. If second operand is constant, use immediate | 1300 | ** Code shift operators. If second operand is constant, use immediate |
1269 | ** operand (negating it if shift is in the other direction). | 1301 | ** operand (negating it if shift is in the other direction). |
1270 | */ | 1302 | */ |
@@ -1468,7 +1500,7 @@ void luaK_posfix (FuncState *fs, BinOpr opr, | |||
1468 | } | 1500 | } |
1469 | case OPR_BAND: case OPR_BOR: case OPR_BXOR: { | 1501 | case OPR_BAND: case OPR_BOR: case OPR_BXOR: { |
1470 | if (!constfolding(fs, opr + LUA_OPADD, e1, e2)) | 1502 | if (!constfolding(fs, opr + LUA_OPADD, e1, e2)) |
1471 | codebinexpval(fs, cast(OpCode, opr + OP_ADD), e1, e2, line); | 1503 | codebitwise(fs, opr, e1, e2, line); |
1472 | break; | 1504 | break; |
1473 | } | 1505 | } |
1474 | case OPR_SHL: { | 1506 | case OPR_SHL: { |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldebug.c,v 2.146 2017/11/23 19:29:04 roberto Exp roberto $ | 2 | ** $Id: ldebug.c,v 2.147 2017/12/07 15:44:10 roberto Exp roberto $ |
3 | ** Debug Interface | 3 | ** Debug Interface |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -589,7 +589,8 @@ static const char *funcnamefromcode (lua_State *L, CallInfo *ci, | |||
589 | tm = TM_NEWINDEX; | 589 | tm = TM_NEWINDEX; |
590 | break; | 590 | break; |
591 | case OP_ADDI: case OP_SUBI: case OP_MULI: case OP_MODI: | 591 | case OP_ADDI: case OP_SUBI: case OP_MULI: case OP_MODI: |
592 | case OP_POWI: case OP_DIVI: case OP_IDIVI: { | 592 | case OP_POWI: case OP_DIVI: case OP_IDIVI: |
593 | case OP_BANDK: case OP_BORK: case OP_BXORK: { | ||
593 | int offset = GET_OPCODE(i) - OP_ADDI; /* ORDER OP */ | 594 | int offset = GET_OPCODE(i) - OP_ADDI; /* ORDER OP */ |
594 | tm = cast(TMS, offset + TM_ADD); /* ORDER TM */ | 595 | tm = cast(TMS, offset + TM_ADD); /* ORDER TM */ |
595 | break; | 596 | break; |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lopcodes.c,v 1.71 2017/11/29 16:57:36 roberto Exp roberto $ | 2 | ** $Id: lopcodes.c,v 1.72 2017/12/04 17:41:30 roberto Exp roberto $ |
3 | ** Opcodes for Lua virtual machine | 3 | ** Opcodes for Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -44,6 +44,9 @@ LUAI_DDEF const char *const luaP_opnames[NUM_OPCODES+1] = { | |||
44 | "POWI", | 44 | "POWI", |
45 | "DIVI", | 45 | "DIVI", |
46 | "IDIVI", | 46 | "IDIVI", |
47 | "BANDK", | ||
48 | "BORK", | ||
49 | "BXORK", | ||
47 | "SHRI", | 50 | "SHRI", |
48 | "SHLI", | 51 | "SHLI", |
49 | "ADD", | 52 | "ADD", |
@@ -119,6 +122,9 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { | |||
119 | ,opmode(0, 1, iABC) /* OP_POWI */ | 122 | ,opmode(0, 1, iABC) /* OP_POWI */ |
120 | ,opmode(0, 1, iABC) /* OP_DIVI */ | 123 | ,opmode(0, 1, iABC) /* OP_DIVI */ |
121 | ,opmode(0, 1, iABC) /* OP_IDIVI */ | 124 | ,opmode(0, 1, iABC) /* OP_IDIVI */ |
125 | ,opmode(0, 1, iABC) /* OP_BANDK */ | ||
126 | ,opmode(0, 1, iABC) /* OP_BORK */ | ||
127 | ,opmode(0, 1, iABC) /* OP_BXORK */ | ||
122 | ,opmode(0, 1, iABC) /* OP_SHRI */ | 128 | ,opmode(0, 1, iABC) /* OP_SHRI */ |
123 | ,opmode(0, 1, iABC) /* OP_SHLI */ | 129 | ,opmode(0, 1, iABC) /* OP_SHLI */ |
124 | ,opmode(0, 1, iABC) /* OP_ADD */ | 130 | ,opmode(0, 1, iABC) /* OP_ADD */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lopcodes.h,v 1.175 2017/11/30 13:16:43 roberto Exp roberto $ | 2 | ** $Id: lopcodes.h,v 1.176 2017/12/04 17:41:30 roberto Exp roberto $ |
3 | ** Opcodes for Lua virtual machine | 3 | ** Opcodes for Lua virtual machine |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -217,6 +217,10 @@ OP_POWI,/* A B sC R(A) := R(B) ^ C */ | |||
217 | OP_DIVI,/* A B sC R(A) := R(B) / C */ | 217 | OP_DIVI,/* A B sC R(A) := R(B) / C */ |
218 | OP_IDIVI,/* A B sC R(A) := R(B) // C */ | 218 | OP_IDIVI,/* A B sC R(A) := R(B) // C */ |
219 | 219 | ||
220 | OP_BANDK,/* A B C R(A) := R(B) & K(C):integer */ | ||
221 | OP_BORK,/* A B C R(A) := R(B) | K(C):integer */ | ||
222 | OP_BXORK,/* A B C R(A) := R(B) ~ K(C):integer */ | ||
223 | |||
220 | OP_SHRI,/* A B C R(A) := R(B) >> C */ | 224 | OP_SHRI,/* A B C R(A) := R(B) >> C */ |
221 | OP_SHLI,/* A B C R(A) := C << R(B) */ | 225 | OP_SHLI,/* A B C R(A) := C << R(B) */ |
222 | 226 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltm.c,v 2.50 2017/11/27 17:44:31 roberto Exp roberto $ | 2 | ** $Id: ltm.c,v 2.51 2017/11/30 15:37:16 roberto Exp roberto $ |
3 | ** Tag methods | 3 | ** Tag methods |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -166,15 +166,20 @@ void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, | |||
166 | } | 166 | } |
167 | 167 | ||
168 | 168 | ||
169 | void luaT_trybinassocTM (lua_State *L, const TValue *p1, const TValue *p2, | ||
170 | StkId res, int inv, TMS event) { | ||
171 | if (inv) | ||
172 | luaT_trybinTM(L, p2, p1, res, event); | ||
173 | else | ||
174 | luaT_trybinTM(L, p1, p2, res, event); | ||
175 | } | ||
176 | |||
177 | |||
169 | void luaT_trybiniTM (lua_State *L, const TValue *p1, int i2, | 178 | void luaT_trybiniTM (lua_State *L, const TValue *p1, int i2, |
170 | int inv, StkId res, TMS event) { | 179 | int inv, StkId res, TMS event) { |
171 | TValue aux; const TValue *p2; | 180 | TValue aux; |
172 | setivalue(&aux, i2); | 181 | setivalue(&aux, i2); |
173 | if (inv) { /* arguments were exchanged? */ | 182 | luaT_trybinassocTM(L, p1, &aux, res, inv, event); |
174 | p2 = p1; p1 = &aux; /* correct them */ | ||
175 | } | ||
176 | else p2 = &aux; | ||
177 | luaT_trybinTM(L, p1, p2, res, event); | ||
178 | } | 183 | } |
179 | 184 | ||
180 | 185 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltm.h,v 2.26 2017/09/27 18:59:08 roberto Exp roberto $ | 2 | ** $Id: ltm.h,v 2.27 2017/11/27 17:44:31 roberto Exp roberto $ |
3 | ** Tag methods | 3 | ** Tag methods |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -68,6 +68,8 @@ LUAI_FUNC void luaT_callTMres (lua_State *L, const TValue *f, | |||
68 | const TValue *p1, const TValue *p2, StkId p3); | 68 | const TValue *p1, const TValue *p2, StkId p3); |
69 | LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, | 69 | LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, |
70 | StkId res, TMS event); | 70 | StkId res, TMS event); |
71 | LUAI_FUNC void luaT_trybinassocTM (lua_State *L, const TValue *p1, | ||
72 | const TValue *p2, StkId res, int inv, TMS event); | ||
71 | LUAI_FUNC void luaT_trybiniTM (lua_State *L, const TValue *p1, int i2, | 73 | LUAI_FUNC void luaT_trybiniTM (lua_State *L, const TValue *p1, int i2, |
72 | int inv, StkId res, TMS event); | 74 | int inv, StkId res, TMS event); |
73 | LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1, | 75 | LUAI_FUNC int luaT_callorderTM (lua_State *L, const TValue *p1, |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lvm.c,v 2.323 2017/11/30 13:29:18 roberto Exp roberto $ | 2 | ** $Id: lvm.c,v 2.324 2017/12/04 17:41:30 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 | */ |
@@ -687,6 +687,7 @@ void luaV_finishOp (lua_State *L) { | |||
687 | case OP_MODI: case OP_POWI: | 687 | case OP_MODI: case OP_POWI: |
688 | case OP_ADD: case OP_SUB: | 688 | case OP_ADD: case OP_SUB: |
689 | case OP_MUL: case OP_DIV: case OP_IDIV: | 689 | case OP_MUL: case OP_DIV: case OP_IDIV: |
690 | case OP_BANDK: case OP_BORK: case OP_BXORK: | ||
690 | case OP_BAND: case OP_BOR: case OP_BXOR: | 691 | case OP_BAND: case OP_BOR: case OP_BXOR: |
691 | case OP_SHRI: case OP_SHL: case OP_SHR: | 692 | case OP_SHRI: case OP_SHL: case OP_SHR: |
692 | case OP_MOD: case OP_POW: | 693 | case OP_MOD: case OP_POW: |
@@ -1182,6 +1183,39 @@ void luaV_execute (lua_State *L, CallInfo *ci) { | |||
1182 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_DIV)); | 1183 | Protect(luaT_trybinTM(L, rb, rc, ra, TM_DIV)); |
1183 | vmbreak; | 1184 | vmbreak; |
1184 | } | 1185 | } |
1186 | vmcase(OP_BANDK) { | ||
1187 | TValue *p1 = vRB(i); | ||
1188 | TValue *p2 = KC(i); | ||
1189 | lua_Integer i1; | ||
1190 | if (tointegerns(p1, &i1)) { | ||
1191 | setivalue(vra, intop(&, i1, ivalue(p2))); | ||
1192 | } | ||
1193 | else | ||
1194 | Protect(luaT_trybinassocTM(L, p1, p2, ra, TESTARG_k(i), TM_BAND)); | ||
1195 | vmbreak; | ||
1196 | } | ||
1197 | vmcase(OP_BORK) { | ||
1198 | TValue *p1 = vRB(i); | ||
1199 | TValue *p2 = KC(i); | ||
1200 | lua_Integer i1; | ||
1201 | if (tointegerns(p1, &i1)) { | ||
1202 | setivalue(vra, intop(|, i1, ivalue(p2))); | ||
1203 | } | ||
1204 | else | ||
1205 | Protect(luaT_trybinassocTM(L, p1, p2, ra, TESTARG_k(i), TM_BOR)); | ||
1206 | vmbreak; | ||
1207 | } | ||
1208 | vmcase(OP_BXORK) { | ||
1209 | TValue *p1 = vRB(i); | ||
1210 | TValue *p2 = KC(i); | ||
1211 | lua_Integer i1; | ||
1212 | if (tointegerns(p1, &i1)) { | ||
1213 | setivalue(vra, intop(^, i1, ivalue(p2))); | ||
1214 | } | ||
1215 | else | ||
1216 | Protect(luaT_trybinassocTM(L, p1, p2, ra, TESTARG_k(i), TM_BXOR)); | ||
1217 | vmbreak; | ||
1218 | } | ||
1185 | vmcase(OP_BAND) { | 1219 | vmcase(OP_BAND) { |
1186 | TValue *rb = vRB(i); | 1220 | TValue *rb = vRB(i); |
1187 | TValue *rc = vRC(i); | 1221 | TValue *rc = vRC(i); |