marsinator358 / luajit-decompiler-v2

LuaJIT bytecode decompiler
Other
217 stars 58 forks source link

Nested breaks turn into goto/label #17

Closed Aussiemon closed 7 months ago

Aussiemon commented 11 months ago

This snippet

for i = 1, 2, 3 do
    if x then
        print("Then")
        if y then
            print ("Nested then")
        else
            break
        end
    else
        break
    end
end

becomes

for i = 1, 2, 3 do
    if x then
        print("Then")

        if y then
            print("Nested then")

            goto label_0_0
        end
    end

    do break end

    if false then
        break
    end

    ::label_0_0::
end

Breaks converting to gotos is problematic when expecting Lua 5.1 output.

marsinator358 commented 11 months ago

This is a side effect of the current simple decompilation logic for if statements.

I'm planning to improve this by trying to rebuild them without gotos first, but this will only work
for blocks that don't contain real gotos because I can't think of an algorithm that finds a combination
with the least amount of gotos left without needing to brute force it.

marsinator358 commented 7 months ago

I've improved the decompilation logic, if the original code didn't have gotos the decompiled code should also not contain any.