Chained comparison operators (a < b < c) use a "short-circuit"
mechanism much like the boolean operators 'and' and 'or'. This
requires some fancy hacks in snek and there were a few mistakes:
The left-hand operand ('a') was left on the stack
The second operator (b < c) would set the 'push' bit, which is on
the first comparison operator so that 'b' would be on the
stack. If the first comparison was false, that push wouldn't be
appropriate. So, we reset the 'push' flag when branching.
We need an instruction to land on after branching that can get the
'push' bit set in case the following operations need it. So we
insert a 'nop' there, just like the short-circuited 'and'/'or'
does.
Chained comparison operators (a < b < c) use a "short-circuit" mechanism much like the boolean operators 'and' and 'or'. This requires some fancy hacks in snek and there were a few mistakes:
The left-hand operand ('a') was left on the stack
The second operator (b < c) would set the 'push' bit, which is on the first comparison operator so that 'b' would be on the stack. If the first comparison was false, that push wouldn't be appropriate. So, we reset the 'push' flag when branching.
We need an instruction to land on after branching that can get the 'push' bit set in case the following operations need it. So we insert a 'nop' there, just like the short-circuited 'and'/'or' does.
Also add some tests which detect these mistakes.
Signed-off-by: Keith Packard keithp@keithp.com
Closes #50