Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/api/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,10 +419,10 @@ def visit_FOR(self, node):
body_ = node.children[4]

if self.O_LEVEL > 0 and chk.is_number(from_, to_, step_) and not chk.is_block_accessed(body_):
if from_ > to_ and step_ > 0:
if from_.value > to_.value and step_.value > 0:
yield self.NOP
return
if from_ < to_ and step_ < 0:
if from_.value < to_.value and step_.value < 0:
yield self.NOP
return

Expand Down
53 changes: 53 additions & 0 deletions tests/functional/arch/zx48k/for_const_crash1.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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
_i:
DEFB 00
.core.ZXBASIC_USER_DATA_END:
.core.__MAIN_PROGRAM__:
ld a, 14
ld (_i), a
jp .LABEL.__LABEL0
.LABEL.__LABEL3:
.LABEL.__LABEL4:
ld hl, _i
inc (hl)
.LABEL.__LABEL0:
ld a, 23
ld hl, (_i - 1)
cp h
jp nc, .LABEL.__LABEL3
.LABEL.__LABEL2:
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
5 changes: 5 additions & 0 deletions tests/functional/arch/zx48k/for_const_crash1.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const SCR_FIRST_LINE_ANSWER as ubyte = 14
const SCR_MAX_LINES as ubyte = 23

for i = SCR_FIRST_LINE_ANSWER to SCR_MAX_LINES
next
Loading