lua-users home
lua-l archive

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

An interesting characteristic of the Lua virtual machine is that local
variables are always registers. That means that several optimizations
in Lua can be done at the source-code level. For instance, a change
         a.b.c = a.b.x[k+d] + y[k+d]
         local _1 = a.b; local _2 = k+d; _1.c = _1.x[_2] + y[_2]

is as good as you can get without changing the virtual machine.

A nice project would be a source-code optimizer for Lua (which could be
used as a pre-processor for luac, for instance). It could easily perform
constant propagation, common-subexpression ellimination (eventually with
switches to control how much it could assume about metamethods), loop
optimizations, etc.

-- Roberto