lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> I could have made a big mistake, but it would appear that the Lua compiler 
> (!?!?) actually expects OP_TAILCALL to create an extra frame in the calling 
> stack, 

The compiler generates an OP_TAILCALL as an optimization for the sequence 
OP_CALL - OP_RETURN, when the OP_CALL has a "MULT_RET" option (otherwise 
the results from the call should be discharged before returning). Because 
functions in Lua don't have proper names (but are called through variable 
names), the compiler cannot know whether a call is recursive, or even if 
the called function is a Lua function. To optimize this opcode as a "real" 
tail call (and avoid exiting the luaV_execute function), you must check at 
run-time whether what you are calling is a Lua function (or a recursive 
call).

-- Roberto