prog8
prog8 copied to clipboard
long array comparisons wrong
Inequality results seem to be backwards when a long array element is involved
%import textio
%zeropage basicsafe
main {
sub start() {
long[] foo = [1,2,3]
long bar = 0
bar = 4
txt.print("bar: ") txt.print_l(bar) txt.nl()
txt.print("foo[0]: ") txt.print_l(foo[0]) txt.nl()
txt.print("bar < foo[0]: ") txt.print_bool(bar < foo[0]) txt.nl()
txt.print("bar <= foo[0]: ") txt.print_bool(bar <= foo[0]) txt.nl()
txt.print("bar > foo[0]: ") txt.print_bool(bar > foo[0]) txt.nl()
txt.nl()
long baz = foo[0]
txt.print("baz: ") txt.print_l(baz) txt.nl()
txt.print("bar < baz: ") txt.print_bool(bar < baz) txt.nl()
txt.print("bar <= baz: ") txt.print_bool(bar <= baz) txt.nl()
txt.print("bar > baz: ") txt.print_bool(bar > baz) txt.nl()
}
}
Result:
BAR: 4
FOO[0]: 1
BAR < FOO[0]: TRUE
BAR <= FOO[0]: TRUE
BAR > FOO[0]: FALSE
BAZ: 1
BAR < BAZ: FALSE
BAR <= BAZ: FALSE
BAR > BAZ: TRUE
READY.
Seems to be correct in virtual target so is 6502 code gen problem
I won't be able to fix this for the v12.0 release - postponing. comparing long variables is fine, the problem lies with comparing more complicated operand expressions. Adding a TODO exception in the code gen when it encounters such cases