prog8 icon indicating copy to clipboard operation
prog8 copied to clipboard

long array comparisons wrong

Open markjreed opened this issue 1 month ago • 2 comments

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.

markjreed avatar Oct 30 '25 16:10 markjreed

Seems to be correct in virtual target so is 6502 code gen problem

irmen avatar Oct 30 '25 20:10 irmen

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

irmen avatar Oct 31 '25 23:10 irmen