cardillan / mindcode

A high level language for Mindustry Logic (mlog) and Mindustry Schematics.
http://mindcode.herokuapp.com/
MIT License
87 stars 13 forks source link

Wrong expression handling in loops #131

Closed cardillan closed 2 months ago

cardillan commented 7 months ago

The Data Flow Optimizer mishandles loop expression. This code

x = 0
while true
    print(x + 1)
    x = rand(10)
    print(x + 1)
end

compiles into

print __tmp2
op rand x 10 0
op add __tmp2 x 1
print __tmp2
jump 0 always 0 0

and produces (correctly) a warning about the __tmp2 variable being uninitialized.