cardillan / mindcode

A high level language for Mindustry Logic and Mindustry Schematics.

Home Page:http://mindcode.herokuapp.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Optimization removes an assignment to variable

cardillan opened this issue · comments

The following code

alive = @unit.dead === 0
if alive
  print(alive)
end

compiled with optimization produces:

sensor __tmp0 @unit @dead
jump 4 notEqual __tmp0 0
print alive
jump 4 always 0 0
end

A correct result would be more akin to this:

sensor __tmp0 @unit @dead
op strictEqual alive __tmp0 0
jump 4 equal alive 0
print alive
jump 4 always 0 0
end

I don't think it's caused by dead code elimination, as alive is clearly used. Other optimization probably should only remove variables that are created by the compiler itself (the __tmp ones) -- that could be an easy check to add.

I'll try to fix the issue, I'm putting it here for reference.

(Edited to fix the examples.)