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.

779db2b7-feed-40e9-8c19-b878763b7f97.png

In this example (Lua 5.1), the return starts with values at R(1) -> R(3), but how does it know that it should start at R1? Does the table constructor set the current register = old (since those new registers can be discarded, I assume) and then the return statement just uses it? How is this communication done? Is it just keeping track of the current register and using it in every statement, and what happens if the compiler has a target register (as when doing a assign), how does it understand to use the target and not the current register?
That's what I'm currently doing, but I don't think it's the optimal or best way to do so, it feels too hacky in my opinion.

Thanks in advance.