Skip to content

Commit 8d3c992

Browse files
authored
Merge pull request #924 from boriel-basic/fix/let_not_crash
fix: crash on NOT (bool expr)
2 parents 0efe923 + 47b4007 commit 8d3c992

4 files changed

Lines changed: 74 additions & 1 deletion

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
;; The sequence:
2+
;; sbc a, a ; A is either 0 or -1
3+
;; sub 1
4+
;; sbc a, a
5+
;; neg
6+
;; can be replaced by
7+
;; sbc a, a ; A is either 0 or -1
8+
;; inc a
9+
10+
OLEVEL: 1
11+
OFLAG: 24
12+
13+
REPLACE {{
14+
sbc a, a
15+
sub 1
16+
sbc a, a
17+
neg
18+
}}
19+
20+
WITH {{
21+
sbc a, a
22+
inc a
23+
}}

src/arch/z80/visitor/translator_inst_visitor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def ic_nop(self) -> None:
181181
self.emit("nop")
182182

183183
def ic_not(self, type_: TYPE | symbols.BASICTYPE, t1, t2) -> None:
184-
self.emit("not" + self.TSUFFIX(type_), t1, t2)
184+
self.emit(f"not{self._no_bool(type_)}", t1, t2)
185185

186186
def ic_or(self, type_: TYPE | symbols.BASICTYPE, t, t1, t2) -> None:
187187
self.emit(f"or{self._no_bool(type_)}", t, t1, t2)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
org 32768
2+
.core.__START_PROGRAM:
3+
di
4+
push ix
5+
push iy
6+
exx
7+
push hl
8+
exx
9+
ld hl, 0
10+
add hl, sp
11+
ld (.core.__CALL_BACK__), hl
12+
ei
13+
jp .core.__MAIN_PROGRAM__
14+
.core.__CALL_BACK__:
15+
DEFW 0
16+
.core.ZXBASIC_USER_DATA:
17+
; Defines USER DATA Length in bytes
18+
.core.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_END - .core.ZXBASIC_USER_DATA
19+
.core.__LABEL__.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_LEN
20+
.core.__LABEL__.ZXBASIC_USER_DATA EQU .core.ZXBASIC_USER_DATA
21+
_a:
22+
DEFB 00
23+
.core.ZXBASIC_USER_DATA_END:
24+
.core.__MAIN_PROGRAM__:
25+
ld hl, (_a - 1)
26+
ld a, (_a)
27+
sub h
28+
sub 1
29+
sbc a, a
30+
inc a
31+
ld (_a), a
32+
ld hl, 0
33+
ld b, h
34+
ld c, l
35+
.core.__END_PROGRAM:
36+
di
37+
ld hl, (.core.__CALL_BACK__)
38+
ld sp, hl
39+
exx
40+
pop hl
41+
exx
42+
pop iy
43+
pop ix
44+
ei
45+
ret
46+
;; --- end of user code ---
47+
END
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
DIM a As Ubyte
2+
3+
LET a = NOT (a = a)

0 commit comments

Comments
 (0)