Skip to content

Commit 561a12a

Browse files
authored
Merge pull request #939 from boriel-basic/fix/xor_boolean
fix: bug with <bool> XOR <bool>
2 parents 6594c1f + 10a6718 commit 561a12a

34 files changed

Lines changed: 596 additions & 18 deletions

src/arch/z80/visitor/translator_inst_visitor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,4 +244,4 @@ def ic_varx(self, name: str, type_: TYPE | sym.BASICTYPE, default_value: list) -
244244
self.emit("varx", name, self.TSUFFIX(type_), default_value)
245245

246246
def ic_xor(self, type_: TYPE | sym.BASICTYPE, t, t1, t2) -> None:
247-
self.emit("xor" + self.TSUFFIX(type_), t, t1, t2)
247+
self.emit(f"xor{self._no_bool(type_)}", t, t1, t2)

tests/functional/arch/zx48k/and16.asm

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,23 @@ _b:
4747
ld de, (_a)
4848
ld hl, (_a)
4949
call .core.__AND16
50+
sub 1
51+
sbc a, a
52+
inc a
53+
ld (_b), a
54+
ld de, (_a)
55+
ld hl, (_a)
56+
call .core.__EQ16
57+
push af
58+
ld de, (_a)
59+
ld hl, (_a)
60+
call .core.__EQ16
61+
ld h, a
62+
pop af
63+
or a
64+
jr z, .LABEL.__LABEL0
65+
ld a, h
66+
.LABEL.__LABEL0:
5067
sub 1
5168
sbc a, a
5269
inc a
@@ -80,5 +97,16 @@ __AND16:
8097
or e
8198
ret
8299
pop namespace
83-
#line 44 "arch/zx48k/and16.bas"
100+
#line 61 "arch/zx48k/and16.bas"
101+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/cmp/eq16.asm"
102+
push namespace core
103+
__EQ16: ; Test if 16bit values HL == DE
104+
; Returns result in A: 0 = False, FF = True
105+
xor a ; Reset carry flag
106+
sbc hl, de
107+
ret nz
108+
inc a
109+
ret
110+
pop namespace
111+
#line 62 "arch/zx48k/and16.bas"
84112
END

tests/functional/arch/zx48k/and16.bas

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ b = a AND 1
88
b = 0 AND a
99
b = 1 AND a
1010
b = a AND a
11+
b = (a = a) AND (a = a)
12+

tests/functional/arch/zx48k/and32.asm

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,31 @@ _b:
5757
ld hl, (_a)
5858
ld de, (_a + 2)
5959
call .core.__AND32
60+
sub 1
61+
sbc a, a
62+
inc a
63+
ld (_b), a
64+
ld hl, (_a + 2)
65+
push hl
66+
ld hl, (_a)
67+
push hl
68+
ld hl, (_a)
69+
ld de, (_a + 2)
70+
call .core.__EQ32
71+
push af
72+
ld hl, (_a + 2)
73+
push hl
74+
ld hl, (_a)
75+
push hl
76+
ld hl, (_a)
77+
ld de, (_a + 2)
78+
call .core.__EQ32
79+
ld h, a
80+
pop af
81+
or a
82+
jr z, .LABEL.__LABEL0
83+
ld a, h
84+
.LABEL.__LABEL0:
6085
sub 1
6186
sbc a, a
6287
inc a
@@ -98,5 +123,31 @@ __AND32:
98123
#line 28 "/zxbasic/src/lib/arch/zx48k/runtime/bool/and32.asm"
99124
ret
100125
pop namespace
101-
#line 54 "arch/zx48k/and32.bas"
126+
#line 79 "arch/zx48k/and32.bas"
127+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/cmp/eq32.asm"
128+
push namespace core
129+
__EQ32: ; Test if 32bit value HLDE equals top of the stack
130+
; Returns result in A: 0 = False, FF = True
131+
exx
132+
pop bc ; Return address
133+
exx
134+
xor a ; Reset carry flag
135+
pop bc
136+
sbc hl, bc ; Low part
137+
ex de, hl
138+
pop bc
139+
sbc hl, bc ; High part
140+
exx
141+
push bc ; CALLEE
142+
exx
143+
ld a, h
144+
or l
145+
or d
146+
or e ; a = 0 and Z flag set only if HLDE = 0
147+
ld a, 1
148+
ret z
149+
xor a
150+
ret
151+
pop namespace
152+
#line 80 "arch/zx48k/and32.bas"
102153
END

tests/functional/arch/zx48k/and32.bas

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ b = a AND 1
88
b = 0 AND a
99
b = 1 AND a
1010
b = a AND a
11+
b = (a = a) AND (a = a)
12+

tests/functional/arch/zx48k/and8.asm

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,27 @@ _b:
4646
jr z, .LABEL.__LABEL0
4747
ld a, h
4848
.LABEL.__LABEL0:
49+
sub 1
50+
sbc a, a
51+
inc a
52+
ld (_b), a
53+
ld hl, (_a - 1)
54+
ld a, (_a)
55+
sub h
56+
sub 1
57+
sbc a, a
58+
push af
59+
ld hl, (_a - 1)
60+
ld a, (_a)
61+
sub h
62+
sub 1
63+
sbc a, a
64+
ld h, a
65+
pop af
66+
or a
67+
jr z, .LABEL.__LABEL1
68+
ld a, h
69+
.LABEL.__LABEL1:
4970
sub 1
5071
sbc a, a
5172
inc a

tests/functional/arch/zx48k/and8.bas

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ b = a AND 1
88
b = 0 AND a
99
b = 1 AND a
1010
b = a AND a
11+
b = (a = a) AND (a = a)
12+

tests/functional/arch/zx48k/andf.asm

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,29 @@ _b:
6767
call .core.__FP_PUSH_REV
6868
call .core.__ANDF
6969
ld (_b), a
70+
ld a, (_a)
71+
ld de, (_a + 1)
72+
ld bc, (_a + 3)
73+
ld hl, _a + 4
74+
call .core.__FP_PUSH_REV
75+
call .core.__EQF
76+
push af
77+
ld a, (_a)
78+
ld de, (_a + 1)
79+
ld bc, (_a + 3)
80+
ld hl, _a + 4
81+
call .core.__FP_PUSH_REV
82+
call .core.__EQF
83+
ld h, a
84+
pop af
85+
or a
86+
jr z, .LABEL.__LABEL0
87+
ld a, h
88+
.LABEL.__LABEL0:
89+
sub 1
90+
sbc a, a
91+
inc a
92+
ld (_b), a
7093
ld hl, 0
7194
ld b, h
7295
ld c, l
@@ -311,7 +334,28 @@ __ANDF: ; A & B
311334
call __FPSTACK_POP
312335
jp __FTOU8 ; Convert to 8 bits
313336
pop namespace
314-
#line 60 "arch/zx48k/andf.bas"
337+
#line 83 "arch/zx48k/andf.bas"
338+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/cmp/eqf.asm"
339+
; -------------------------------------------------------------
340+
; Floating point library using the FP ROM Calculator (ZX 48K)
341+
; All of them uses C EDHL registers as 1st paramter.
342+
; For binary operators, the 2n operator must be pushed into the
343+
; stack, in the order BC DE HL (B not used).
344+
;
345+
; Uses CALLEE convention
346+
; -------------------------------------------------------------
347+
push namespace core
348+
__EQF: ; A = B
349+
call __FPSTACK_PUSH2
350+
; ------------- ROM NOS-EQL
351+
ld b, 0Eh ; For comparison operators, OP must be in B also
352+
rst 28h
353+
defb 0Eh
354+
defb 38h; ; END CALC
355+
call __FPSTACK_POP
356+
jp __FTOU8 ; Convert to 8 bits
357+
pop namespace
358+
#line 84 "arch/zx48k/andf.bas"
315359
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/pushf.asm"
316360
; Routine to push Float pointed by HL
317361
; Into the stack. Notice that the hl points to the last
@@ -339,5 +383,5 @@ __FP_PUSH_REV:
339383
exx
340384
ret
341385
pop namespace
342-
#line 61 "arch/zx48k/andf.bas"
386+
#line 85 "arch/zx48k/andf.bas"
343387
END

tests/functional/arch/zx48k/andf.bas

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ b = a AND 1
88
b = 0 AND a
99
b = 1 AND a
1010
b = a AND a
11+
b = (a = a) AND (a = a)
12+

tests/functional/arch/zx48k/not16.asm

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ _b:
3535
sbc a, a
3636
neg
3737
ld (_b), a
38+
ld de, (_a)
39+
ld hl, (_a)
40+
call .core.__EQ16
41+
sub 1
42+
sbc a, a
43+
neg
44+
ld (_b), a
3845
ld hl, 0
3946
ld b, h
4047
ld c, l
@@ -50,4 +57,15 @@ _b:
5057
ei
5158
ret
5259
;; --- end of user code ---
60+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/cmp/eq16.asm"
61+
push namespace core
62+
__EQ16: ; Test if 16bit values HL == DE
63+
; Returns result in A: 0 = False, FF = True
64+
xor a ; Reset carry flag
65+
sbc hl, de
66+
ret nz
67+
inc a
68+
ret
69+
pop namespace
70+
#line 35 "arch/zx48k/not16.bas"
5371
END

0 commit comments

Comments
 (0)