lua-users home
lua-l archive

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


Patrick Donnelly wrote:
I'm curious what kind of compiler optimizations Lua does when creating
the byte code, if any?

e.g.

x = 5 *  32 * i

becomes

x = 160 * i

internally.


a = 100
b = 5 * 32 * a

luac -l testfile.lua

0+ params, 2 slots, 0 upvalues, 0 locals, 4 constants, 0 functions
        1       [1]     LOADK           0 -2    ; 100
        2       [1]     SETGLOBAL       0 -1    ; a
        3       [2]     GETGLOBAL       0 -1    ; a
        4       [2]     MUL             0 -4 0  ; 160 -
        5       [2]     SETGLOBAL       0 -3    ; b
        6       [2]     RETURN          0 1




-----------------------------------------------------------------
                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
                                             | www.pragma-pod.nl
-----------------------------------------------------------------