lua-users home
lua-l archive

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


Adam D. Moss wrote:
Mike Pall pointed out to me that the Lua 5.1 compiler
started to use constant folding optimizations at some
point in its development lifetime, which had somehow
escaped me previously.

Thanks to the Lua authors for that; e.g. now I can
write stuff like degrees-to-radians conversion in a
more obvious way, at least, without fear of wasting
VM instructions. :)

It is not heavy-duty constant folding, though. According to my observations, the terms of an expression are not reordered, so the following is not optimized:

  local a = a+1+2

since it is parsed as:

  local a = (a+1)+2

It appears the rule is that such optimization opportunities are checked in the order the expression is parsed, and for binary operators, both terms must be a number.

Also, placing local declarations without assignments at the very beginning of a function will eliminate some LOADNILs.

--
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia