aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lcode.c2
-rw-r--r--lopcodes.c23
-rw-r--r--lopcodes.h15
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) {
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: {
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] = {
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*/
117int 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*/
131int luaP_isIT (Instruction i) { 120int 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 }
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 */
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
435LUAI_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
436LUAI_FUNC int luaP_isIT (Instruction i); 441LUAI_FUNC int luaP_isIT (Instruction i);
437 442
438 443