aboutsummaryrefslogtreecommitdiff
path: root/lcode.c
diff options
context:
space:
mode:
Diffstat (limited to 'lcode.c')
-rw-r--r--lcode.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/lcode.c b/lcode.c
index 25fb0770..eb5a2c82 100644
--- a/lcode.c
+++ b/lcode.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lcode.c,v 2.152 2018/01/28 15:13:26 roberto Exp roberto $ 2** $Id: lcode.c,v 2.153 2018/02/09 15:16:06 roberto Exp roberto $
3** Code generator for Lua 3** Code generator for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -158,16 +158,12 @@ int luaK_jump (FuncState *fs) {
158*/ 158*/
159void luaK_ret (FuncState *fs, int first, int nret) { 159void luaK_ret (FuncState *fs, int first, int nret) {
160 OpCode op; 160 OpCode op;
161 if (fs->f->is_vararg) 161 switch (nret) {
162 op = OP_RETVARARG; 162 case 0: op = OP_RETURN0; break;
163 else { 163 case 1: op = OP_RETURN1; break;
164 switch (nret) { 164 default: op = OP_RETURN; break;
165 case 0: op = OP_RETURN0; break;
166 case 1: op = OP_RETURN1; break;
167 default: op = OP_RETURN; break;
168 }
169 } 165 }
170 luaK_codeABC(fs, op, first, nret + 1, fs->f->numparams); 166 luaK_codeABC(fs, op, first, nret + 1, 0);
171} 167}
172 168
173 169
@@ -1646,10 +1642,18 @@ void luaK_finish (FuncState *fs) {
1646 Instruction *pc = &p->code[i]; 1642 Instruction *pc = &p->code[i];
1647 lua_assert(i == 0 || isOT(*(pc - 1)) == isIT(*pc)); 1643 lua_assert(i == 0 || isOT(*(pc - 1)) == isIT(*pc));
1648 switch (GET_OPCODE(*pc)) { 1644 switch (GET_OPCODE(*pc)) {
1649 case OP_RETURN: case OP_RETURN0: case OP_RETURN1: 1645 case OP_RETURN0: case OP_RETURN1: {
1650 case OP_RETVARARG: case OP_TAILCALL: { 1646 if (p->sizep == 0 && !p->is_vararg)
1651 if (p->sizep > 0) 1647 break; /* no extra work */
1652 SETARG_k(*pc, 1); /* signal that they must close upvalues */ 1648 /* else use OP_RETURN to do the extra work */
1649 SET_OPCODE(*pc, OP_RETURN);
1650 /* FALLTHROUGH */
1651 }
1652 case OP_RETURN: case OP_TAILCALL: {
1653 if (p->sizep > 0 || p->is_vararg) {
1654 SETARG_C(*pc, p->is_vararg ? p->numparams + 1 : 0);
1655 SETARG_k(*pc, 1); /* signal that there is extra work */
1656 }
1653 break; 1657 break;
1654 } 1658 }
1655 case OP_JMP: { 1659 case OP_JMP: {