omni icon indicating copy to clipboard operation
omni copied to clipboard

loop unroll for values known at compile time

Open vitreo12 opened this issue 3 years ago • 1 comments

As of now, all loop with integer literals are unrolled:

loop 4 i:
    print i

In the typed section, however, it would be cool to unroll all loops where the integer is known (like coming from a const)

CONST = 4 #known at compile time
loop CONST i:
    print i

vitreo12 avatar Oct 01 '20 15:10 vitreo12

Also, this would require a new const mechanism for def arguments:

def something_unroll(AMT):
    loop AMT i: #<-- with this mechanism, this will be unrolled!
        print i

def something_normal(amt):
    loop amt i: #<-- not unrolled, amt is not a const
        print i

init:
    something_unroll 10
    something_unroll 5
    
    CONST = 10; something_unroll CONST #All good, explicit const
    CONST = in1; something_unroll CONST #<-- ERROR: CONST value not known at compile time

    a = 10; something_unroll a #<-- ERROR: a is not an int or float lit!
    a = 10; something_normal a #<-- This would still work, normal call

For implementation specifics, check explicitUnrolls/explicitUnroll.nim in omni_lang/tests.

vitreo12 avatar Oct 02 '20 18:10 vitreo12