lua-users home
lua-l archive

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


Cosmin Apreutesei <cosmin.apreutesei@gmail.com> wrote:
>
>      do
>        local f, s, var_1, ···, var_n = explist --keep all init values
>        while true do
>          local var_1, ···, var_n = f(s, var_1, ···, var_n)  --pass all values back to f
>          if var_1 == nil then break end
>          block
>        end
>      end

This can't work in a straightforward way. At the moment, the Lua compiler
knows the stack depth at all points in the program, as a static property
of the program. This allows local variables and temporary values to
map to fixed stack locations, and these locations are written into the
argument fields of the bytecode instructions.

This fixed stack depth property does not hold for the body of your
proposed for loop.

In Lua, variable stack depth only occurs at function call and return. When
the reference manual talks about "adjusting" lists of values, this is
basically equivalent to restoring the stack to the correct statically
known depth.

So to make your proposal work on anything like the current Lua
implementation, you would need to make the loop body into a closure, which
completely negates your aim of eliminating an allocation.

Tony.
-- 
f.anthony.n.finch  <dot@dotat.at>  http://dotat.at/
Bailey, Fair Isle, Faeroes: Northeast backing northwest 5 or 6, occasionally 7
at first in Fair Isle, decreasing 4 for a time. Moderate or rough,
occasionally very rough at first in Fair Isle. Wintry showers. Moderate or
good.