'OP_TAILCALL' calling C functions finishes the call and returns

(instead of waiting for following 'OP_RETURN')
This commit is contained in:
Roberto Ierusalimschy 2018-01-14 15:27:50 -02:00
parent ab0a851db4
commit d2fb34ac88

15
lvm.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lvm.c,v 2.332 2018/01/09 14:23:40 roberto Exp roberto $
** $Id: lvm.c,v 2.333 2018/01/10 19:19:27 roberto Exp roberto $
** Lua virtual machine
** See Copyright Notice in lua.h
*/
@ -1504,13 +1504,18 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
ProtectNT(luaD_tryfuncTM(L, ra)); /* try '__call' metamethod */
b++; /* there is now one extra argument */
}
if (TESTARG_k(i))
luaF_close(L, base); /* close upvalues from current call */
if (!ttisLclosure(vra)) { /* C function? */
ProtectNT(luaD_call(L, ra, LUA_MULTRET)); /* call it */
/* next instruction will do the return */
if (trap) {
updatebase(ci);
ra = RA(i);
}
luaD_poscall(L, ci, ra, cast_int(L->top - ra));
return;
}
else { /* tail call */
if (TESTARG_k(i)) /* close upvalues from previous call */
luaF_close(L, ci->func + 1);
else { /* Lua tail call */
luaD_pretailcall(L, ci, ra, b); /* prepare call frame */
goto tailcall;
}