wurstscript / WurstScript

Programming language and toolkit to create Warcraft III Maps
https://wurstlang.org
Apache License 2.0
225 stars 30 forks source link

Idea to inline functions with multiply returns #238

Open Crigges opened 10 years ago

Crigges commented 10 years ago

I will take this easy fuctions as example:

function meep(boolean b, int i) returns string
    if i > 5
        return "a"
    if b
        return "b"
    else
        return "c"

The function can be put inside jass into a loop, so the keyword exitwhen can be used to simulate returns inside the function to prevent further code execution:

function inlined takes nothing returns nothing
    local integer i = 123
    local boolean b = true
    local string res
    loop
        if i > 5 then
            set res = "a"
            exitwhen true
        endif
        if b then
            set res = "b"
        else
            set res = "c"
        exitwhen true
    endloop
    //use res here
endfunction

This is just an idea, close this if it is pointless.

peq commented 10 years ago

It is a bit more complicated, since the inlined function could have a return inside a loop. It would work for other functions, though.

Cokemonkey11 commented 9 years ago

I really doubt this would actually change performance.