From bd8d57bc27d2f88f2248eb88272e0cc149a3a8d0 Mon Sep 17 00:00:00 2001 From: Jose Rodriguez Date: Sun, 8 Dec 2024 11:40:49 +0100 Subject: [PATCH] fix: crash when using -(bool expression) --- src/api/constants.py | 2 +- .../{008_sbc_jp.opt => 008_o1_sbc_jp.opt} | 0 .../{009_inc_mem.opt => 009_o1_inc_mem.opt} | 0 src/arch/z80/peephole/opts/013_o1_neg_neg.opt | 16 +++++++ .../{letnotbool.asm => let_not_bool.asm} | 0 .../{letnotbool.bas => let_not_bool.bas} | 0 .../functional/arch/zx48k/let_uminus_bool.asm | 46 +++++++++++++++++++ .../functional/arch/zx48k/let_uminus_bool.bas | 4 ++ 8 files changed, 67 insertions(+), 1 deletion(-) rename src/arch/z80/peephole/opts/{008_sbc_jp.opt => 008_o1_sbc_jp.opt} (100%) rename src/arch/z80/peephole/opts/{009_inc_mem.opt => 009_o1_inc_mem.opt} (100%) create mode 100644 src/arch/z80/peephole/opts/013_o1_neg_neg.opt rename tests/functional/arch/zx48k/{letnotbool.asm => let_not_bool.asm} (100%) rename tests/functional/arch/zx48k/{letnotbool.bas => let_not_bool.bas} (100%) create mode 100644 tests/functional/arch/zx48k/let_uminus_bool.asm create mode 100644 tests/functional/arch/zx48k/let_uminus_bool.bas diff --git a/src/api/constants.py b/src/api/constants.py index 489b496ac..f5907072a 100644 --- a/src/api/constants.py +++ b/src/api/constants.py @@ -148,7 +148,7 @@ def to_signed(cls, type_: "TYPE") -> "TYPE": """Return signed type or equivalent""" if type_ in cls.unsigned: return { - TYPE.boolean: TYPE.boolean, + TYPE.boolean: TYPE.byte, TYPE.ubyte: TYPE.byte, TYPE.uinteger: TYPE.integer, TYPE.ulong: TYPE.long, diff --git a/src/arch/z80/peephole/opts/008_sbc_jp.opt b/src/arch/z80/peephole/opts/008_o1_sbc_jp.opt similarity index 100% rename from src/arch/z80/peephole/opts/008_sbc_jp.opt rename to src/arch/z80/peephole/opts/008_o1_sbc_jp.opt diff --git a/src/arch/z80/peephole/opts/009_inc_mem.opt b/src/arch/z80/peephole/opts/009_o1_inc_mem.opt similarity index 100% rename from src/arch/z80/peephole/opts/009_inc_mem.opt rename to src/arch/z80/peephole/opts/009_o1_inc_mem.opt diff --git a/src/arch/z80/peephole/opts/013_o1_neg_neg.opt b/src/arch/z80/peephole/opts/013_o1_neg_neg.opt new file mode 100644 index 000000000..6c625562a --- /dev/null +++ b/src/arch/z80/peephole/opts/013_o1_neg_neg.opt @@ -0,0 +1,16 @@ +;; Replaces sequence: +;; neg +;; neg +;; with +;; ; nop ;; double neg can be removed + +OLEVEL: 1 +OFLAG: 13 + +REPLACE {{ + neg + neg +}} + +WITH {{ +}} diff --git a/tests/functional/arch/zx48k/letnotbool.asm b/tests/functional/arch/zx48k/let_not_bool.asm similarity index 100% rename from tests/functional/arch/zx48k/letnotbool.asm rename to tests/functional/arch/zx48k/let_not_bool.asm diff --git a/tests/functional/arch/zx48k/letnotbool.bas b/tests/functional/arch/zx48k/let_not_bool.bas similarity index 100% rename from tests/functional/arch/zx48k/letnotbool.bas rename to tests/functional/arch/zx48k/let_not_bool.bas diff --git a/tests/functional/arch/zx48k/let_uminus_bool.asm b/tests/functional/arch/zx48k/let_uminus_bool.asm new file mode 100644 index 000000000..94a59f760 --- /dev/null +++ b/tests/functional/arch/zx48k/let_uminus_bool.asm @@ -0,0 +1,46 @@ + org 32768 +.core.__START_PROGRAM: + di + push ix + push iy + exx + push hl + exx + ld hl, 0 + add hl, sp + ld (.core.__CALL_BACK__), hl + ei + jp .core.__MAIN_PROGRAM__ +.core.__CALL_BACK__: + DEFW 0 +.core.ZXBASIC_USER_DATA: + ; Defines USER DATA Length in bytes +.core.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_END - .core.ZXBASIC_USER_DATA + .core.__LABEL__.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_LEN + .core.__LABEL__.ZXBASIC_USER_DATA EQU .core.ZXBASIC_USER_DATA +_a: + DEFB 00 +.core.ZXBASIC_USER_DATA_END: +.core.__MAIN_PROGRAM__: + ld hl, (_a - 1) + ld a, (_a) + sub h + sub 1 + sbc a, a + ld (_a), a + ld hl, 0 + ld b, h + ld c, l +.core.__END_PROGRAM: + di + ld hl, (.core.__CALL_BACK__) + ld sp, hl + exx + pop hl + exx + pop iy + pop ix + ei + ret + ;; --- end of user code --- + END diff --git a/tests/functional/arch/zx48k/let_uminus_bool.bas b/tests/functional/arch/zx48k/let_uminus_bool.bas new file mode 100644 index 000000000..b91f69249 --- /dev/null +++ b/tests/functional/arch/zx48k/let_uminus_bool.bas @@ -0,0 +1,4 @@ +DIM a As Ubyte + +LET a = -(a = a) +