Skip to content

Commit 729087d

Browse files
committed
fix: do not emit warn on sentinel END
1 parent 04b0b1b commit 729087d

5 files changed

Lines changed: 145 additions & 14 deletions

File tree

src/api/optimize.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,7 @@ def visit_BLOCK(self, node):
120120
j += 1
121121
continue
122122

123-
if (
124-
node[j].token == "SENTENCE" and node[j].is_sentinel
125-
): # "Sentinel" instructions can be freely removed
123+
if node[j].token == "END" and node[j].is_sentinel: # "Sentinel" instructions can be freely removed
126124
node.pop(j)
127125
continue
128126

tests/functional/test_errmsg.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ dim_str_error0.bas:3: error: Cannot initialize array of type string
206206
>>> process_file('zx48k/dim_str_error1.bas')
207207
dim_str_error1.bas:3: error: Cannot initialize array of type string
208208

209+
# Unreachable code detection
210+
# Should not emit warning for these case:
211+
>>> process_file('zx48k/warn_unreach0.bas')
212+
209213
# Test warning silencing
210214
>>> process_file('zx48k/mcleod3.bas', ['-S', '-q', '-O --expect-warnings=2'])
211215
mcleod3.bas:3: error: 'GenerateSpaces' is neither an array nor a function.

tests/functional/zx48k/slice2.asm

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,6 @@
5050
pop ix
5151
ei
5252
ret
53-
ld hl, 0
54-
ld b, h
55-
ld c, l
56-
jp .core.__END_PROGRAM
5753
_doubleSizePrint:
5854
push ix
5955
ld ix, 0
@@ -198,7 +194,7 @@ __CLS_SCR:
198194
; to get the start of the screen
199195
ENDP
200196
pop namespace
201-
#line 110 "slice2.bas"
197+
#line 106 "zx48k/slice2.bas"
202198
#line 1 "/zxbasic/src/arch/zx48k/library-asm/error.asm"
203199
; Simple error control routines
204200
; vim:ts=4:et:
@@ -233,7 +229,7 @@ __STOP:
233229
ld (ERR_NR), a
234230
ret
235231
pop namespace
236-
#line 111 "slice2.bas"
232+
#line 107 "zx48k/slice2.bas"
237233
#line 1 "/zxbasic/src/arch/zx48k/library-asm/free.asm"
238234
; vim: ts=4:et:sw=4:
239235
; Copyleft (K) by Jose M. Rodriguez de la Rosa
@@ -500,7 +496,7 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed
500496
ret
501497
ENDP
502498
pop namespace
503-
#line 112 "slice2.bas"
499+
#line 108 "zx48k/slice2.bas"
504500
#line 1 "/zxbasic/src/arch/zx48k/library-asm/loadstr.asm"
505501
#line 1 "/zxbasic/src/arch/zx48k/library-asm/alloc.asm"
506502
; vim: ts=4:et:sw=4:
@@ -696,7 +692,7 @@ __LOADSTR: ; __FASTCALL__ entry
696692
pop hl ; Recovers destiny in hl as result
697693
ret
698694
pop namespace
699-
#line 113 "slice2.bas"
695+
#line 109 "zx48k/slice2.bas"
700696
#line 1 "/zxbasic/src/arch/zx48k/library-asm/pstorestr2.asm"
701697
; vim:ts=4:et:sw=4
702698
;
@@ -745,7 +741,7 @@ __PSTORE_STR2:
745741
add hl, bc
746742
jp __STORE_STR2
747743
pop namespace
748-
#line 114 "slice2.bas"
744+
#line 110 "zx48k/slice2.bas"
749745
#line 1 "/zxbasic/src/arch/zx48k/library-asm/strlen.asm"
750746
; Returns len if a string
751747
; If a string is NULL, its len is also 0
@@ -761,7 +757,7 @@ __STRLEN: ; Direct FASTCALL entry
761757
ld l, a
762758
ret
763759
pop namespace
764-
#line 115 "slice2.bas"
760+
#line 111 "zx48k/slice2.bas"
765761
#line 1 "/zxbasic/src/arch/zx48k/library-asm/strslice.asm"
766762
; String slicing library
767763
; HL = Str pointer
@@ -847,5 +843,5 @@ __FREE_ON_EXIT:
847843
ret
848844
ENDP
849845
pop namespace
850-
#line 116 "slice2.bas"
846+
#line 112 "zx48k/slice2.bas"
851847
END
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
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+
_myNumber:
22+
DEFB 00
23+
.core.ZXBASIC_USER_DATA_END:
24+
.core.__MAIN_PROGRAM__:
25+
call .core.CLS
26+
.LABEL._myBucle:
27+
xor a
28+
ld (_myNumber), a
29+
jp .LABEL.__LABEL0
30+
.LABEL.__LABEL3:
31+
call _mySub
32+
.LABEL.__LABEL4:
33+
ld hl, _myNumber
34+
inc (hl)
35+
.LABEL.__LABEL0:
36+
ld a, 7
37+
ld hl, (_myNumber - 1)
38+
cp h
39+
jp nc, .LABEL.__LABEL3
40+
.LABEL.__LABEL2:
41+
jp .LABEL._myBucle
42+
_mySub:
43+
push ix
44+
ld ix, 0
45+
add ix, sp
46+
_mySub__leave:
47+
ld sp, ix
48+
pop ix
49+
ret
50+
;; --- end of user code ---
51+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/cls.asm"
52+
; JUMPS directly to spectrum CLS
53+
; This routine does not clear lower screen
54+
;CLS EQU 0DAFh
55+
; Our faster implementation
56+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/sposn.asm"
57+
; Printing positioning library.
58+
push namespace core
59+
PROC
60+
LOCAL ECHO_E
61+
__LOAD_S_POSN: ; Loads into DE current ROW, COL print position from S_POSN mem var.
62+
ld de, (S_POSN)
63+
ld hl, (MAXX)
64+
or a
65+
sbc hl, de
66+
ex de, hl
67+
ret
68+
__SAVE_S_POSN: ; Saves ROW, COL from DE into S_POSN mem var.
69+
ld hl, (MAXX)
70+
or a
71+
sbc hl, de
72+
ld (S_POSN), hl ; saves it again
73+
ret
74+
ECHO_E EQU 23682
75+
MAXX EQU ECHO_E ; Max X position + 1
76+
MAXY EQU MAXX + 1 ; Max Y position + 1
77+
S_POSN EQU 23688
78+
POSX EQU S_POSN ; Current POS X
79+
POSY EQU S_POSN + 1 ; Current POS Y
80+
ENDP
81+
pop namespace
82+
#line 9 "/zxbasic/src/arch/zx48k/library-asm/cls.asm"
83+
push namespace core
84+
CLS:
85+
PROC
86+
LOCAL COORDS
87+
LOCAL __CLS_SCR
88+
LOCAL ATTR_P
89+
LOCAL SCREEN
90+
ld hl, 0
91+
ld (COORDS), hl
92+
ld hl, 1821h
93+
ld (S_POSN), hl
94+
__CLS_SCR:
95+
ld hl, SCREEN
96+
ld (hl), 0
97+
ld d, h
98+
ld e, l
99+
inc de
100+
ld bc, 6144
101+
ldir
102+
; Now clear attributes
103+
ld a, (ATTR_P)
104+
ld (hl), a
105+
ld bc, 767
106+
ldir
107+
ret
108+
COORDS EQU 23677
109+
SCREEN EQU 16384 ; Default start of the screen (can be changed)
110+
ATTR_P EQU 23693
111+
;you can poke (SCREEN_SCRADDR) to change CLS, DRAW & PRINTing address
112+
SCREEN_ADDR EQU (__CLS_SCR + 1) ; Address used by print and other screen routines
113+
; to get the start of the screen
114+
ENDP
115+
pop namespace
116+
#line 28 "zx48k/warn_unreach0.bas"
117+
END
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
' EXAMPE UNRECHABLE CODE
2+
3+
declare sub mySub()
4+
5+
Dim myNumber As uByte
6+
cls
7+
8+
myBucle:
9+
for myNumber = 0 to 7
10+
mySub()
11+
next myNumber
12+
goto myBucle
13+
14+
sub mySub()
15+
16+
end sub

0 commit comments

Comments
 (0)