lua

A copy of the Lua development repository
Log | Files | Refs | README

commit d2fb34ac8865b2a7ec944a449d90145739030a98
parent ab0a851db438c4dd50b76bcf624c15623cc057e4
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date:   Sun, 14 Jan 2018 15:27:23 -0200

'OP_TAILCALL' calling C functions finishes the call and returns
(instead of waiting for following 'OP_RETURN')

Diffstat:
Mlvm.c | 15++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/lvm.c b/lvm.c @@ -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; }