diff options
| author | Roberto I <roberto@inf.puc-rio.br> | 2026-05-28 15:10:17 -0300 |
|---|---|---|
| committer | Roberto I <roberto@inf.puc-rio.br> | 2026-05-28 15:10:17 -0300 |
| commit | 0465c23b3ee214ea3a117ab9d69a83cf85e7a82f (patch) | |
| tree | 2c286695a3c00501c2c8610844f968472ec85903 | |
| parent | 53b41d0cddd80bf33fdc631bdd32e3ba53842b89 (diff) | |
| download | lua-0465c23b3ee214ea3a117ab9d69a83cf85e7a82f.tar.gz lua-0465c23b3ee214ea3a117ab9d69a83cf85e7a82f.tar.bz2 lua-0465c23b3ee214ea3a117ab9d69a83cf85e7a82f.zip | |
Cleaning 'luaP_isIT' and 'luaP_isOT'
- 'luaP_isOT' is only used for tests, so it is defined as a macro to avoid
wasting space with an unused function.
- 'luaP_isIT' must include OP_VARARGPREP.
| -rw-r--r-- | lcode.c | 2 | ||||
| -rw-r--r-- | lopcodes.c | 23 | ||||
| -rw-r--r-- | lopcodes.h | 15 |
3 files changed, 17 insertions, 23 deletions
| @@ -1934,8 +1934,6 @@ void luaK_finish (FuncState *fs) { | |||
| 1934 | p->flag &= cast_byte(~PF_VAHID); /* then it will not use hidden args. */ | 1934 | p->flag &= cast_byte(~PF_VAHID); /* then it will not use hidden args. */ |
| 1935 | for (i = 0; i < fs->pc; i++) { | 1935 | for (i = 0; i < fs->pc; i++) { |
| 1936 | Instruction *pc = &p->code[i]; | 1936 | Instruction *pc = &p->code[i]; |
| 1937 | /* avoid "not used" warnings when assert is off (for 'onelua.c') */ | ||
| 1938 | (void)luaP_isOT; (void)luaP_isIT; | ||
| 1939 | lua_assert(i == 0 || luaP_isOT(*(pc - 1)) == luaP_isIT(*pc)); | 1937 | lua_assert(i == 0 || luaP_isOT(*(pc - 1)) == luaP_isIT(*pc)); |
| 1940 | switch (GET_OPCODE(*pc)) { | 1938 | switch (GET_OPCODE(*pc)) { |
| 1941 | case OP_RETURN0: case OP_RETURN1: { | 1939 | case OP_RETURN0: case OP_RETURN1: { |
| @@ -109,30 +109,21 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { | |||
| 109 | }; | 109 | }; |
| 110 | 110 | ||
| 111 | 111 | ||
| 112 | 112 | #define testITMode(m) (luaP_opmodes[m] & (1 << 5)) | |
| 113 | /* | ||
| 114 | ** Check whether instruction sets top for next instruction, that is, | ||
| 115 | ** it results in multiple values. | ||
| 116 | */ | ||
| 117 | int luaP_isOT (Instruction i) { | ||
| 118 | OpCode op = GET_OPCODE(i); | ||
| 119 | switch (op) { | ||
| 120 | case OP_TAILCALL: return 1; | ||
| 121 | default: | ||
| 122 | return testOTMode(op) && GETARG_C(i) == 0; | ||
| 123 | } | ||
| 124 | } | ||
| 125 | 113 | ||
| 126 | 114 | ||
| 127 | /* | 115 | /* |
| 128 | ** Check whether instruction uses top from previous instruction, that is, | 116 | ** Check whether instruction uses top. That happens for OP_VARARGPREP |
| 129 | ** it accepts multiple results. | 117 | ** and for instructions that use multiple values set by the previous |
| 118 | ** instruction. | ||
| 130 | */ | 119 | */ |
| 131 | int luaP_isIT (Instruction i) { | 120 | int luaP_isIT (Instruction i) { |
| 132 | OpCode op = GET_OPCODE(i); | 121 | OpCode op = GET_OPCODE(i); |
| 133 | switch (op) { | 122 | switch (op) { |
| 134 | case OP_SETLIST: | 123 | case OP_SETLIST: |
| 135 | return testITMode(GET_OPCODE(i)) && GETARG_vB(i) == 0; | 124 | return GETARG_vB(i) == 0; |
| 125 | case OP_VARARGPREP: | ||
| 126 | return 1; | ||
| 136 | default: | 127 | default: |
| 137 | return testITMode(GET_OPCODE(i)) && GETARG_B(i) == 0; | 128 | return testITMode(GET_OPCODE(i)) && GETARG_B(i) == 0; |
| 138 | } | 129 | } |
| @@ -417,8 +417,8 @@ OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */ | |||
| 417 | ** bits 0-2: op mode | 417 | ** bits 0-2: op mode |
| 418 | ** bit 3: instruction set register A | 418 | ** bit 3: instruction set register A |
| 419 | ** bit 4: operator is a test (next instruction must be a jump) | 419 | ** bit 4: operator is a test (next instruction must be a jump) |
| 420 | ** bit 5: instruction uses 'L->top' set by previous instruction (when B == 0) | 420 | ** bit 5: used by 'luaP_isIT' |
| 421 | ** bit 6: instruction sets 'L->top' for next instruction (when C == 0) | 421 | ** bit 6: used by 'luaP_isOT' |
| 422 | ** bit 7: instruction is an MM instruction (call a metamethod) | 422 | ** bit 7: instruction is an MM instruction (call a metamethod) |
| 423 | */ | 423 | */ |
| 424 | 424 | ||
| @@ -427,12 +427,17 @@ LUAI_DDEC(const lu_byte luaP_opmodes[NUM_OPCODES];) | |||
| 427 | #define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 7)) | 427 | #define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 7)) |
| 428 | #define testAMode(m) (luaP_opmodes[m] & (1 << 3)) | 428 | #define testAMode(m) (luaP_opmodes[m] & (1 << 3)) |
| 429 | #define testTMode(m) (luaP_opmodes[m] & (1 << 4)) | 429 | #define testTMode(m) (luaP_opmodes[m] & (1 << 4)) |
| 430 | #define testITMode(m) (luaP_opmodes[m] & (1 << 5)) | ||
| 431 | #define testOTMode(m) (luaP_opmodes[m] & (1 << 6)) | ||
| 432 | #define testMMMode(m) (luaP_opmodes[m] & (1 << 7)) | 430 | #define testMMMode(m) (luaP_opmodes[m] & (1 << 7)) |
| 433 | 431 | ||
| 434 | 432 | ||
| 435 | LUAI_FUNC int luaP_isOT (Instruction i); | 433 | /* Check whether instruction sets top for next instruction, that is, |
| 434 | ** it results in multiple values. Used only for tests. | ||
| 435 | */ | ||
| 436 | #define luaP_isOT(i) \ | ||
| 437 | (GET_OPCODE(i) == OP_TAILCALL || \ | ||
| 438 | ((luaP_opmodes[GET_OPCODE(i)] & (1 << 6)) && GETARG_C(i) == 0)) | ||
| 439 | |||
| 440 | |||
| 436 | LUAI_FUNC int luaP_isIT (Instruction i); | 441 | LUAI_FUNC int luaP_isIT (Instruction i); |
| 437 | 442 | ||
| 438 | 443 | ||
