• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] constant variables doesn't get inlined?

Status
Not open for further replies.
Level 22
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?
 
Level 7
Joined
Oct 19, 2015
Messages
286
The manual is talking about other finalizers (like the WC3 Map Optimizer) being able to inline constants.
 
Status
Not open for further replies.
Top