[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Some comments on CPS control flow functions in Lua 5.2
- From: Roberto Ierusalimschy <roberto@...>
- Date: Fri, 21 May 2010 09:32:24 -0300
> > Another alternative would be for Lua itself to call the continuation
> > every time, so that these functions never return. But then they could
> > only be used in places where it is safe to yield, resulting in quite
> > complex restrictions.
> That was what I meant by "all require being called at the end of a
> lua_CFunction" above.
> I agree that doing CPS in C in this manner requires destroying the C
> frames and that this can make things quite inconvenient. However, I
> do not think that the current behavior of the callk functions is
> simpler. [...]
I think I was not clear about the "quite complex restrictions". Surely
destroying the C frames at each callk would be simpler for the one
programming that particular function. (As you said, there would be
only one continuation.) The problem is for people *using* such function.
Lua can destroy a C frame only when there is a "protection point"
(setjmp) down the stack *and* all intermediate C frames have
continuations. Several functions in the standard libraries do
not work with continuations (e.g., sort and gsub). With your
proposal, such functions could never call any function that uses
callk. With the current implementation, the only restricition is
that there are on actual yields in the process.