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.)
This commit is contained in:
Roberto Ierusalimschy
2019-08-27 13:59:39 -03:00
parent 643188d6e5
commit df13f25948
11 changed files with 132 additions and 104 deletions

View File

@@ -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 */
case OP_MMBIN: case OP_MMBINI: case OP_MMBINK: {
tm = cast(TMS, GETARG_C(i));
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 */
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;