[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Register allocation with shadowed locals at same level
- From: Rob Kendrick <rjek@...>
- Date: Fri, 15 Jan 2010 21:02:32 +0000
Hi,
I find myself writing code that looks a lot like this quite often:
local foo, err = make_foo()
if not foo then return nil, err end
local bar, err = make_err()
if not bar then return nil, err end
Looking at the output of luac -l, it looks as if this wastes a register
because Lua doesn't reuse the register allocated to the first local
definition containing an "err" for the second, even though the first is
no longer accessible, and never (I think) will become accessible again.
Two questions:
1) Is there some reason I've missed why it is essential that
Lua behaves this way?
2) Am I right in thinking that the value stored in the first err
will not be garbage collected until the scope containing both
errs is left?
B.