From 0465c23b3ee214ea3a117ab9d69a83cf85e7a82f Mon Sep 17 00:00:00 2001 From: Roberto I Date: Thu, 28 May 2026 15:10:17 -0300 Subject: [PATCH] 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. --- lcode.c | 2 -- lopcodes.c | 23 +++++++---------------- lopcodes.h | 15 ++++++++++----- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/lcode.c b/lcode.c index e0024432..8b61d5de 100644 --- a/lcode.c +++ b/lcode.c @@ -1934,8 +1934,6 @@ void luaK_finish (FuncState *fs) { p->flag &= cast_byte(~PF_VAHID); /* then it will not use hidden args. */ for (i = 0; i < fs->pc; i++) { Instruction *pc = &p->code[i]; - /* avoid "not used" warnings when assert is off (for 'onelua.c') */ - (void)luaP_isOT; (void)luaP_isIT; lua_assert(i == 0 || luaP_isOT(*(pc - 1)) == luaP_isIT(*pc)); switch (GET_OPCODE(*pc)) { case OP_RETURN0: case OP_RETURN1: { diff --git a/lopcodes.c b/lopcodes.c index da64ff18..bb1a4162 100644 --- a/lopcodes.c +++ b/lopcodes.c @@ -109,30 +109,21 @@ LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { }; - -/* -** Check whether instruction sets top for next instruction, that is, -** it results in multiple values. -*/ -int luaP_isOT (Instruction i) { - OpCode op = GET_OPCODE(i); - switch (op) { - case OP_TAILCALL: return 1; - default: - return testOTMode(op) && GETARG_C(i) == 0; - } -} +#define testITMode(m) (luaP_opmodes[m] & (1 << 5)) /* -** Check whether instruction uses top from previous instruction, that is, -** it accepts multiple results. +** Check whether instruction uses top. That happens for OP_VARARGPREP +** and for instructions that use multiple values set by the previous +** instruction. */ int luaP_isIT (Instruction i) { OpCode op = GET_OPCODE(i); switch (op) { case OP_SETLIST: - return testITMode(GET_OPCODE(i)) && GETARG_vB(i) == 0; + return GETARG_vB(i) == 0; + case OP_VARARGPREP: + return 1; default: return testITMode(GET_OPCODE(i)) && GETARG_B(i) == 0; } diff --git a/lopcodes.h b/lopcodes.h index b6bd182e..86cff065 100644 --- a/lopcodes.h +++ b/lopcodes.h @@ -417,8 +417,8 @@ OP_EXTRAARG/* Ax extra (larger) argument for previous opcode */ ** bits 0-2: op mode ** bit 3: instruction set register A ** bit 4: operator is a test (next instruction must be a jump) -** bit 5: instruction uses 'L->top' set by previous instruction (when B == 0) -** bit 6: instruction sets 'L->top' for next instruction (when C == 0) +** bit 5: used by 'luaP_isIT' +** bit 6: used by 'luaP_isOT' ** bit 7: instruction is an MM instruction (call a metamethod) */ @@ -427,12 +427,17 @@ LUAI_DDEC(const lu_byte luaP_opmodes[NUM_OPCODES];) #define getOpMode(m) (cast(enum OpMode, luaP_opmodes[m] & 7)) #define testAMode(m) (luaP_opmodes[m] & (1 << 3)) #define testTMode(m) (luaP_opmodes[m] & (1 << 4)) -#define testITMode(m) (luaP_opmodes[m] & (1 << 5)) -#define testOTMode(m) (luaP_opmodes[m] & (1 << 6)) #define testMMMode(m) (luaP_opmodes[m] & (1 << 7)) -LUAI_FUNC int luaP_isOT (Instruction i); +/* Check whether instruction sets top for next instruction, that is, +** it results in multiple values. Used only for tests. +*/ +#define luaP_isOT(i) \ + (GET_OPCODE(i) == OP_TAILCALL || \ + ((luaP_opmodes[GET_OPCODE(i)] & (1 << 6)) && GETARG_C(i) == 0)) + + LUAI_FUNC int luaP_isIT (Instruction i);