Open altmank opened 6 months ago
Hey @altmank! Welcome here!
Could you explain better what you mean by "broken IC code that incorrectly uses 'and' keyword"?
If I consider line 17:
IF outsideTempCool && tankBelowMaxPressure THEN
This line is compiled into:
and r0 r3 r1 # r3 is outsideTempCool, and r1 is tankBelowMaxPressure
beqz r0 22 # if the result is false, it jumps directly to line 22, which is the ELSEIF line
The and is correct here, and you want both conditions to be set to true.
I'm always using this kind of logic in my scripts, and never had any issues with it. Could you please provide more info so we can debug it better?
What are you observing while running the code? Which part of the logic is not running or not executed the way you wanted it to be?
If you want, you can join us on Discord, so I can answer faster there. https://discord.gg/2rnpHTWVyV
Thanks!
I think he accidentally posted the working code, not the one where he tried to use inline statements. I had problems with that too until I realized that you have to put the statements in brackets when using && or ||.
IF GasSensor.Temperature < 128C && AirTank.Pressure < 1MPa THEN
would compare 128C with AirTank.Pressure
l r2 d2 Temperature
l r0 d0 Pressure
and r1 401.15 r0
slt r0 r1 1000
bge r2 r0 14
IF (GasSensor.Temperature < 128C) && (AirTank.Pressure < 1MPa) THEN
works as intended
l r0 d2 Temperature
slt r2 r0 401.15
l r0 d0 Pressure
slt r1 r0 1000
and r0 r2 r1
beqz r0 15
Hey @maschine34675 ! Thanks for the help with this bug report.
You're right, the problem is that, currently, I can't set different operator priorities between:
&&
and ||
)==
and !=
)<
, <=
, >
, >=
)+
and -
)Only the Multiplicative operators (*
and /
) have a separate priority level.
For now, the workaround is to use parenthesis, but I will work on an improvement to allow more priority levels in the compiler.
Cheers!
If instead of declaring all of the conditions as variables, I inline them into the IF statements, this results in broken IC code that incorrectly uses 'and' keyword.