Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

Jass Hot Code Reload

Discussion in 'Warcraft Editing Tools' started by LeP, Mar 20, 2019.

  1. LeP

    LeP

    Joined:
    Feb 13, 2008
    Messages:
    479
    Resources:
    0
    Resources:
    0
    Thanks! Should be fixed here.
     
  2. Aniki

    Aniki

    Joined:
    Nov 7, 2014
    Messages:
    564
    Resources:
    6
    Tools:
    1
    Maps:
    1
    Spells:
    1
    JASS:
    3
    Resources:
    6
    Tried with the 'jhcr-1.29.zip' and common.j (1.26, 1.29 and 1.31) but in-game (running 1.31) it I am getting an error (when the map gets selected). Previously I was using 'jhcr-126b-128.zip' (v. git-c50f36) with common.j-1.26 (again running 1.31).

    I still think the bytecode generated by the 'nested ifs' is better than that of the 'and's:
    Code (Text):

    fun 5 foo
    call -5 1 B1
    not -6 -5
    jmpt 4 -6
    call -5 2 B2
    label 4
    set boolean -3 -5
    not -4 -3
    jmpt 3 -4
    call -3 3 B3
    label 3
    set boolean -1 -3
    not -2 -1
    jmpt 2 -2
    call -1 4 B4
    label 2
    set boolean 0 -1
    ret boolean
     
    When 'B1()' returns false the above executes a "cascade of falseness", while the 'nested ifs' jumps out =).
     
  3. LeP

    LeP

    Joined:
    Feb 13, 2008
    Messages:
    479
    Resources:
    0
    Resources:
    0
    The mistake was that i included
    framehandle
    handing in table for 1.29 when they only appeared in 1.3x. Unfortunately i don't have a modern version of WC3 installed so i'm actually dependent on posts in here (and i'm thankful for them).


    While not as good but a small improvement would be to group those
    and
    s to the right like this
    B1() and (B2() and (B3() and B4()))
    .
    You could even write a rewrite rule for that
    Code (Haskell):

    mkRR ["a", "b","c"] "a and b and c" "a and (b and c)"
     
     
  4. Aniki

    Aniki

    Joined:
    Nov 7, 2014
    Messages:
    564
    Resources:
    6
    Tools:
    1
    Maps:
    1
    Spells:
    1
    JASS:
    3
    Resources:
    6
    Yeah, it works now with common.j-1.26.

    Have you tried this (not very modern though)?

    Hm... the order of evaluation is different. Well... actually it isn't =).

    I'll be trying 'or' expressions next (to see if there are any bugs lurking there =)).

    Edit: 'or' expressions seem fine (although they do enter in a 'cascade of trueness'):

    Code (vJASS):

    function B1 takes nothing returns boolean
        return false
    endfunction

    function B2 takes nothing returns boolean
        return false
    endfunction

    function B3 takes nothing returns boolean
        return false
    endfunction

    function B4 takes nothing returns boolean
        return false
    endfunction

    function foo takes nothing returns boolean
        // return B1() or B2() or B3() or B4()
        // =>
        // fun 5 foo
        // call -3 1 B1
        // jmpt 4 -3
        // call -3 2 B2
        // label 4
        // set boolean -2 -3
        // jmpt 3 -2
        // call -2 3 B3
        // label 3
        // set boolean -1 -2
        // jmpt 2 -1
        // call -1 4 B4
        // label 2
        // set boolean 0 -1
        // ret boolean

        // local boolean b = true
        // if B1() then
        // elseif B2() then
        // elseif B3() then
        // elseif B4() then
        // else
        //     set b = false
        // endif
        // return b
        // =>
        // fun 5 foo
        // lit boolean 1 true
        // call -2 1 B1
        // jmpt 2 -2
        // call -3 2 B2
        // jmpt 4 -3
        // call -4 3 B3
        // jmpt 6 -4
        // call -5 4 B4
        // jmpt 8 -5
        // lit boolean 1 false
        // jmp 9
        // label 8
        // label 9
        // jmp 7
        // label 6
        // label 7
        // jmp 5
        // label 4
        // label 5
        // jmp 3
        // label 2
        // label 3
        // set boolean 0 1
        // ret boolean
    endfunction
     


    The 'or' emulation I tried with 'elseif's starts up well but then ends with a strange jump cascade.

    Edit2:
    My "quest" for the optimized (but a bit verbose) 'or' is now complete:
    Code (vJASS):

    function foo takes nothing returns boolean
        local boolean b = true
        loop
        exitwhen B1()
        exitwhen B2()
        exitwhen B3()
        exitwhen B4()
        set b = false
        exitwhen true
        endloop
        return b
    endfunction
     


    Code (Text):

    fun 5 foo
    lit boolean 1 true
    label 2
    call -2 1 B1
    jmpt 3 -2
    call -3 2 B2
    jmpt 3 -3
    call -4 3 B3
    jmpt 3 -4
    call -5 4 B4
    jmpt 3 -5
    lit boolean 1 false
    lit boolean -7 true
    label 3
    set boolean 0 1
    ret boolean
     
     
    Last edited: Oct 23, 2020
  5. LeP

    LeP

    Joined:
    Feb 13, 2008
    Messages:
    479
    Resources:
    0
    Resources:
    0
    Small update for jhcr to not die on
    debug
    statements.
    I also provide both 1.31 as latest pre-reforged patch and 1.32.9 for the latest patch (as of writing).
    Pls tell me if/what other patches you're using (if any).