From 9b13bf8e2c31c2982cf2a46351be6ff2ec7d0283 Mon Sep 17 00:00:00 2001 From: Jose Rodriguez Date: Sun, 27 Apr 2025 18:03:19 +0200 Subject: [PATCH] fix: crash on cast i32 to u32 --- src/arch/z80/backend/common.py | 3 ++ tests/functional/arch/zx48k/cast_i32tou32.asm | 42 +++++++++++++++++++ tests/functional/arch/zx48k/cast_i32tou32.bas | 4 ++ 3 files changed, 49 insertions(+) create mode 100644 tests/functional/arch/zx48k/cast_i32tou32.asm create mode 100644 tests/functional/arch/zx48k/cast_i32tou32.bas diff --git a/src/arch/z80/backend/common.py b/src/arch/z80/backend/common.py index ec789ff1d..a0af28828 100644 --- a/src/arch/z80/backend/common.py +++ b/src/arch/z80/backend/common.py @@ -392,6 +392,9 @@ def to_long(stype: DataType) -> list[str]: output.append("ld e, a") output.append("ld d, a") + elif stype in (U32_t, I32_t): + return [] + elif stype == U16_t: output.append("ld de, 0") diff --git a/tests/functional/arch/zx48k/cast_i32tou32.asm b/tests/functional/arch/zx48k/cast_i32tou32.asm new file mode 100644 index 000000000..b1a1da513 --- /dev/null +++ b/tests/functional/arch/zx48k/cast_i32tou32.asm @@ -0,0 +1,42 @@ + org 32768 +.core.__START_PROGRAM: + di + push ix + push iy + exx + push hl + exx + ld (.core.__CALL_BACK__), sp + 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, 00, 00, 00 +.core.ZXBASIC_USER_DATA_END: +.core.__MAIN_PROGRAM__: + ld hl, (_a) + ld de, (_a + 2) + ld (_a), hl + ld (_a + 2), de + 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/cast_i32tou32.bas b/tests/functional/arch/zx48k/cast_i32tou32.bas new file mode 100644 index 000000000..81eee4fbb --- /dev/null +++ b/tests/functional/arch/zx48k/cast_i32tou32.bas @@ -0,0 +1,4 @@ +DIM a as ULong + +LET a = INT(a) +