Nymphium / opeth

Opeth is the optimizer and debug tools for Lua 5.3 VM bytecode, or Metal band
http://www.coins.tsukuba.ac.jp/syllabus/GB13312_GB13322.html
MIT License
70 stars 1 forks source link

error case #12

Open Nymphium opened 7 years ago

Nymphium commented 7 years ago
local f = function(a)
    return a + a
end

local g = function(b)
    return (f(b)) * (f(b))
end

local h = function(c)
    return g(c)
end

print(h(3))

Opeth returns the bytecode like :

main <?:0,0> (8 instructions at 0x1da19e0)
0+ params, 6 slots, 1 upvalue, 0 locals, 2 constants, 2 functions
        1       [-]     CLOSURE         0 0     ; 0x1da1b00
        2       [-]     CLOSURE         2 1     ; 0x1da1ba0
        3       [-]     GETTABUP        3 0 -1  ; - "print"
        4       [-]     MOVE            4 2
        5       [-]     LOADK           5 -2    ; 3
        6       [-]     CALL            4 2 0
        7       [-]     CALL            3 0 1
        8       [-]     RETURN          0 1
constants (2) for 0x1da19e0:
        1       "print"
        2       3
locals (0) for 0x1da19e0:
upvalues (1) for 0x1da19e0:
        0       -       1       0

function <?:1,3> (3 instructions at 0x1da1b00)
1 param, 2 slots, 0 upvalues, 0 locals, 0 constants, 0 functions
        1       [-]     ADD             1 0 0
        2       [-]     RETURN          1 2
        3       [-]     RETURN          0 1
constants (0) for 0x1da1b00:
locals (0) for 0x1da1b00:
upvalues (0) for 0x1da1b00:

function <?:9,11> (5 instructions at 0x1da1ba0)
1 param, 3 slots, 1 upvalue, 0 locals, 0 constants, 0 functions
        1       [-]     GETUPVAL        1 0     ; -
        2       [-]     MOVE            2 0
        3       [-]     TAILCALL        1 2 0
        4       [-]     RETURN          1 0
        5       [-]     RETURN          0 1
constants (0) for 0x1da1ba0:
locals (0) for 0x1da1ba0:
upvalues (1) for 0x1da1ba0:
        0       -       1       0

And get a result 6