lua-users home
lua-l archive

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


A key design decision in the Lua compiler is that it is a one-pass
on-the-fly compiler. It has no intermediate representation at all.
It reads the source code and generates bytecode as it goes. Of course,
to know that a variable is not going to be used again requires
reading the source until the end of its scope. By that time, this
information is not very useful.


> Nod.  Although a simple algorithm to detect if there's already a local
> with the same name declared within the same scope, and to reuse that
> register (after emptying it) would be a solution to the problem. [...]

You cannot do that. Inner functions may still use the first variable,
even if its name is shadowed.


> [...] having a spare register for some more locals, should you need
> them.

Have you ever needed more registers than the compiler provides?

-- Roberto