• Check out the results of the Techtree Contest #19!
  • Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

[Solved] constant variables doesn't get inlined?

Status
Not open for further replies.
Level 23
Joined
Feb 6, 2014
Messages
2,466
I tried testing it, the code is:
JASS:
library L initializer F
    
    globals
        constant integer INT1 = 42
        constant integer INT2 = 42 + 73
        constant real REAL1 = 2.718281828
        constant real REAL2 = 1/32
        constant real REAL3 = SquareRoot(5)
        constant real REAL4 = Pow(2, 128)
        constant boolean BOOL = true
        constant player PLAYER = Player(14)
    endglobals
    
    function Inline takes nothing returns real
        return 42.0
    endfunction
    
    function F takes nothing returns nothing
        local integer i = INT1 + INT2
        local real r = REAL1 + REAL2 + REAL3 + REAL4
        local player p = PLAYER
        if BOOL then
            set r = Inline()
        endif
    endfunction
    
endlibrary

And the generated JASS script is:
JASS:
globals
//globals from L:
constant boolean LIBRARY_L=true
constant integer INT1= 42
constant integer INT2= 42 + 73
constant real REAL1= 2.718281828
constant real REAL2= 1 / 32
constant real REAL3= SquareRoot(5)
constant real REAL4= Pow(2, 128)
constant boolean BOOL= true
constant player PLAYER= Player(14)
//endglobals from L
    // Generated
trigger gg_trg_Inlining= null

trigger l__library_init

//JASSHelper struct globals:

endglobals


//library L:
    
    
    function Inline takes nothing returns real
        return 42.0
    endfunction
    
    function F takes nothing returns nothing
        local integer i= INT1 + INT2
        local real r= REAL1 + REAL2 + REAL3 + REAL4
        local player p= PLAYER
        if BOOL then
            set r=(42.0) // INLINED!!
        endif
    endfunction
    

//library L ends

However
JassHelper Manual said:
Global declaration freedom simply allows you to write globals blocks wherever you want, for example in the custom script section or in a 'trigger', and because of this you can even use the constant prefix which can even make finalizers able to inline constants and stuff.

And if you can see, I got DEBUG_MODE disabled because it was able to inline a function. So does this mean constant variables doesn't get inlined and the inlining mentioned in the JassHelper Manual is false?

However when dealing with static if, the constant boolean are pre-evaluated upon compilation of the script so it doesn't make sense not to inline the constants. Perhaps I'm doing something wrong here?
 
The manual is talking about other finalizers (like the WC3 Map Optimizer) being able to inline constants.
 
Status
Not open for further replies.
Back
Top