omni
omni copied to clipboard
loop unroll for values known at compile time
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
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
.