lua-users home
lua-l archive

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


Rici Lake wrote:
> On 9-Feb-07, at 12:46 PM, Doug Rogers wrote:
>>   block ::= chunk | finally { stat[;] }
>> I believe this would preclude tail calls in functions with finalization.

> Not necessarily. I sketched out an implementation of finally clauses
> in the midst of a longer discussion about non-local exits some
> time ago. Thanks to the lua-l archives time machine, here it is:
> <http://lua-users.org/lists/lua-l/2005-08/msg00357.html>
> ...
> However, there is a stack slot associated with the current
> function, effectively stack slot 0. If we associate the finalizer
> with slot 0 instead of slot 1, and only close upvalues down to
> slot 1 on a tailcall, the finalizer will not be triggered until
> the call-frame is popped, which is the correct moment.

Clever! It will be laborious to verify its operation under all cases and
conditions. But we live to labor, do we not?

Doug

-- 
Innovative Concepts, Inc. www.innocon.com 703-893-2007 x220