[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Register allocation with shadowed locals at same level
- From: Roberto Ierusalimschy <roberto@...>
- Date: Mon, 18 Jan 2010 11:10:48 -0200
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
Have you ever needed more registers than the compiler provides?