lua-users home
lua-l archive

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


> Recently I've been working on a C# lua compiler from scratch, and I'm
> interested in understanding better how register allocation is done in Lua.
> I'm a bit confused in a few scenarios and how the compiler knows where to
> allocate, mainly as I couldn't find any documentation on lua's compiler.

Register allocation in Lua is done basically in a stack approach.
(Actually, several instructions use the registers as a stack.)
There is no optimizations at all, as there are plenty of registers.

During compilation there is a "top" variable (field FuncState.freereg in
the current version); when an expression needs a register it increments
that counter, which is decremented after that result has been used.

-- Roberto