[Snek] [keith-packard/snek] 96963f: Correct stack usage during chained comparison oper...
Keith Packard
noreply at github.com
Fri Jan 14 12:32:05 PST 2022
Branch: refs/heads/compare-chain
Home: https://github.com/keith-packard/snek
Commit: 96963f0c670f269a44168e7739474e2dc02502bb
https://github.com/keith-packard/snek/commit/96963f0c670f269a44168e7739474e2dc02502bb
Author: Keith Packard <keithp at keithp.com>
Date: 2022-01-14 (Fri, 14 Jan 2022)
Changed paths:
M snek-exec.c
M snek-gram.ll
M test/pass-chain-op.py
Log Message:
-----------
Correct stack usage during chained comparison operations
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:
1. The left-hand operand ('a') was left on the stack
2. 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.
3. 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 at keithp.com>
More information about the Snek
mailing list