From 04e19712a5d48b84869f9942836ff8314fb0be8e Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 14 Jun 2021 13:28:21 -0300 Subject: C functions can be tail called, too A tail call to a C function can have the behavior of a "real" tail call, reusing the stack frame of the caller. --- lvm.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'lvm.c') diff --git a/lvm.c b/lvm.c index 485b9caa..62ff70da 100644 --- a/lvm.c +++ b/lvm.c @@ -1636,7 +1636,6 @@ void luaV_execute (lua_State *L, CallInfo *ci) { updatetrap(ci); /* C call; nothing else to be done */ else { /* Lua call: run function in this same C frame */ ci = newci; - ci->callstatus = 0; goto startfunc; } vmbreak; @@ -1655,16 +1654,10 @@ void luaV_execute (lua_State *L, CallInfo *ci) { lua_assert(L->tbclist < base); /* no pending tbc variables */ lua_assert(base == ci->func + 1); } - if (luaD_precall(L, ra, LUA_MULTRET, delta + 1)) { /* Lua function? */ - ci->callstatus |= CIST_TAIL; + if (luaD_precall(L, ra, LUA_MULTRET, delta + 1)) /* Lua function? */ goto startfunc; /* execute the callee */ - } else { /* C function */ updatetrap(ci); - updatestack(ci); /* stack may have been relocated */ - ci->func -= delta; /* restore 'func' (if vararg) */ - luaD_poscall(L, ci, cast_int(L->top - ra)); /* finish caller */ - updatetrap(ci); /* 'luaD_poscall' can change hooks */ goto ret; /* caller returns after the tail call */ } } -- cgit v1.2.3-55-g6feb