Skip to content

Commit 8769583

Browse files
authored
Merge pull request #934 from boriel-basic/fix/crash_with_for_using_constants
fix: crash with FOR loop using constants
2 parents 3f1835e + 9f69a49 commit 8769583

3 files changed

Lines changed: 60 additions & 2 deletions

File tree

src/api/optimize.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -419,10 +419,10 @@ def visit_FOR(self, node):
419419
body_ = node.children[4]
420420

421421
if self.O_LEVEL > 0 and chk.is_number(from_, to_, step_) and not chk.is_block_accessed(body_):
422-
if from_ > to_ and step_ > 0:
422+
if from_.value > to_.value and step_.value > 0:
423423
yield self.NOP
424424
return
425-
if from_ < to_ and step_ < 0:
425+
if from_.value < to_.value and step_.value < 0:
426426
yield self.NOP
427427
return
428428

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
_i:
22+
DEFB 00
23+
.core.ZXBASIC_USER_DATA_END:
24+
.core.__MAIN_PROGRAM__:
25+
ld a, 14
26+
ld (_i), a
27+
jp .LABEL.__LABEL0
28+
.LABEL.__LABEL3:
29+
.LABEL.__LABEL4:
30+
ld hl, _i
31+
inc (hl)
32+
.LABEL.__LABEL0:
33+
ld a, 23
34+
ld hl, (_i - 1)
35+
cp h
36+
jp nc, .LABEL.__LABEL3
37+
.LABEL.__LABEL2:
38+
ld hl, 0
39+
ld b, h
40+
ld c, l
41+
.core.__END_PROGRAM:
42+
di
43+
ld hl, (.core.__CALL_BACK__)
44+
ld sp, hl
45+
exx
46+
pop hl
47+
exx
48+
pop iy
49+
pop ix
50+
ei
51+
ret
52+
;; --- end of user code ---
53+
END
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const SCR_FIRST_LINE_ANSWER as ubyte = 14
2+
const SCR_MAX_LINES as ubyte = 23
3+
4+
for i = SCR_FIRST_LINE_ANSWER to SCR_MAX_LINES
5+
next

0 commit comments

Comments
 (0)