From df13f259487459f3a28d31d76c890aa6c2d061e0 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 27 Aug 2019 13:59:39 -0300 Subject: First version of OP_MMBIN opcodes In arithmetic/bitwise operators, the call to metamethods is made in a separate opcode following the main one. (The main opcode skips this next one when the operation succeeds.) This change reduces slightly the size of the binary and the complexity of the arithmetic/bitwise opcodes. It also simplfies the treatment of errors and yeld/resume in these operations, as there are much fewer cases to consider. (Only OP_MMBIN/OP_MMBINI/OP_MMBINK, instead of all variants of all arithmetic/bitwise operators.) --- ldebug.c | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) (limited to 'ldebug.c') diff --git a/ldebug.c b/ldebug.c index 9593039b..4e1dc6b9 100644 --- a/ldebug.c +++ b/ldebug.c @@ -471,6 +471,10 @@ static int findsetreg (const Proto *p, int lastpc, int reg) { int pc; int setreg = -1; /* keep last instruction that changed 'reg' */ int jmptarget = 0; /* any code before this address is conditional */ + if (GET_OPCODE(p->code[lastpc]) == OP_MMBIN || + GET_OPCODE(p->code[lastpc]) == OP_MMBINI || + GET_OPCODE(p->code[lastpc]) == OP_MMBINK) + lastpc--; for (pc = 0; pc < lastpc; pc++) { Instruction i = p->code[pc]; OpCode op = GET_OPCODE(i); @@ -620,22 +624,11 @@ static const char *funcnamefromcode (lua_State *L, CallInfo *ci, case OP_SETTABUP: case OP_SETTABLE: case OP_SETI: case OP_SETFIELD: tm = TM_NEWINDEX; break; - case OP_ADDI: case OP_SUBI: case OP_MULI: case OP_MODI: - case OP_POWI: case OP_DIVI: case OP_IDIVI: { - int offset = GET_OPCODE(i) - OP_ADDI; /* ORDER OP */ - tm = cast(TMS, offset + TM_ADD); /* ORDER TM */ - break; - } - case OP_ADDK: case OP_SUBK: case OP_MULK: case OP_MODK: - case OP_POWK: case OP_DIVK: case OP_IDIVK: - case OP_BANDK: case OP_BORK: case OP_BXORK: { - int offset = GET_OPCODE(i) - OP_ADDK; /* ORDER OP */ - tm = cast(TMS, offset + TM_ADD); /* ORDER TM */ + case OP_MMBIN: case OP_MMBINI: case OP_MMBINK: { + tm = cast(TMS, GETARG_C(i)); break; } - case OP_ADD: case OP_SUB: case OP_MUL: case OP_MOD: - case OP_POW: case OP_DIV: case OP_IDIV: case OP_BAND: - case OP_BOR: case OP_BXOR: case OP_SHL: case OP_SHR: { + case OP_SHL: case OP_SHR: { int offset = GET_OPCODE(i) - OP_ADD; /* ORDER OP */ tm = cast(TMS, offset + TM_ADD); /* ORDER TM */ break; -- cgit v1.2.3-55-g6feb