diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-08-27 13:59:39 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-08-27 13:59:39 -0300 |
commit | df13f259487459f3a28d31d76c890aa6c2d061e0 (patch) | |
tree | f354a0746530369d4dd70113c9752d019fbd200b /ldebug.c | |
parent | 643188d6e58dfd3270d689230867289347260b74 (diff) | |
download | lua-df13f259487459f3a28d31d76c890aa6c2d061e0.tar.gz lua-df13f259487459f3a28d31d76c890aa6c2d061e0.tar.bz2 lua-df13f259487459f3a28d31d76c890aa6c2d061e0.zip |
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.)
Diffstat (limited to 'ldebug.c')
-rw-r--r-- | ldebug.c | 21 |
1 files changed, 7 insertions, 14 deletions
@@ -471,6 +471,10 @@ static int findsetreg (const Proto *p, int lastpc, int reg) { | |||
471 | int pc; | 471 | int pc; |
472 | int setreg = -1; /* keep last instruction that changed 'reg' */ | 472 | int setreg = -1; /* keep last instruction that changed 'reg' */ |
473 | int jmptarget = 0; /* any code before this address is conditional */ | 473 | int jmptarget = 0; /* any code before this address is conditional */ |
474 | if (GET_OPCODE(p->code[lastpc]) == OP_MMBIN || | ||
475 | GET_OPCODE(p->code[lastpc]) == OP_MMBINI || | ||
476 | GET_OPCODE(p->code[lastpc]) == OP_MMBINK) | ||
477 | lastpc--; | ||
474 | for (pc = 0; pc < lastpc; pc++) { | 478 | for (pc = 0; pc < lastpc; pc++) { |
475 | Instruction i = p->code[pc]; | 479 | Instruction i = p->code[pc]; |
476 | OpCode op = GET_OPCODE(i); | 480 | OpCode op = GET_OPCODE(i); |
@@ -620,22 +624,11 @@ static const char *funcnamefromcode (lua_State *L, CallInfo *ci, | |||
620 | case OP_SETTABUP: case OP_SETTABLE: case OP_SETI: case OP_SETFIELD: | 624 | case OP_SETTABUP: case OP_SETTABLE: case OP_SETI: case OP_SETFIELD: |
621 | tm = TM_NEWINDEX; | 625 | tm = TM_NEWINDEX; |
622 | break; | 626 | break; |
623 | case OP_ADDI: case OP_SUBI: case OP_MULI: case OP_MODI: | 627 | case OP_MMBIN: case OP_MMBINI: case OP_MMBINK: { |
624 | case OP_POWI: case OP_DIVI: case OP_IDIVI: { | 628 | tm = cast(TMS, GETARG_C(i)); |
625 | int offset = GET_OPCODE(i) - OP_ADDI; /* ORDER OP */ | ||
626 | tm = cast(TMS, offset + TM_ADD); /* ORDER TM */ | ||
627 | break; | ||
628 | } | ||
629 | case OP_ADDK: case OP_SUBK: case OP_MULK: case OP_MODK: | ||
630 | case OP_POWK: case OP_DIVK: case OP_IDIVK: | ||
631 | case OP_BANDK: case OP_BORK: case OP_BXORK: { | ||
632 | int offset = GET_OPCODE(i) - OP_ADDK; /* ORDER OP */ | ||
633 | tm = cast(TMS, offset + TM_ADD); /* ORDER TM */ | ||
634 | break; | 629 | break; |
635 | } | 630 | } |
636 | case OP_ADD: case OP_SUB: case OP_MUL: case OP_MOD: | 631 | case OP_SHL: case OP_SHR: { |
637 | case OP_POW: case OP_DIV: case OP_IDIV: case OP_BAND: | ||
638 | case OP_BOR: case OP_BXOR: case OP_SHL: case OP_SHR: { | ||
639 | int offset = GET_OPCODE(i) - OP_ADD; /* ORDER OP */ | 632 | int offset = GET_OPCODE(i) - OP_ADD; /* ORDER OP */ |
640 | tm = cast(TMS, offset + TM_ADD); /* ORDER TM */ | 633 | tm = cast(TMS, offset + TM_ADD); /* ORDER TM */ |
641 | break; | 634 | break; |