Skip to content

Commit 3a463be

Browse files
committed
refact: don´t allow labels declared everywhere
Labels need to be declared at the beginning of the line (indentation allowd) and followed by a colon.
1 parent aeb7e07 commit 3a463be

7 files changed

Lines changed: 139 additions & 1 deletion

File tree

src/zxbc/zxblex.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ def is_label(token) -> bool:
716716

717717
i = token.lexpos + len(token.value)
718718
while i < len(input):
719-
if input[i] in {"\n", ":"}:
719+
if input[i] == ":":
720720
return True
721721

722722
if input[i] not in {" ", "\t"}:
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
.core.ZXBASIC_USER_DATA_END:
22+
.core.__MAIN_PROGRAM__:
23+
.LABEL._MYLABEL:
24+
jp .LABEL._MYLABEL
25+
;; --- end of user code ---
26+
END
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
REM labels needs to be declared at the beginning of line
3+
REM with a trailing colon
4+
5+
MYLABEL:
6+
GOTO MYLABEL
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
REM Will fail because it lacks a trailing COLON
3+
4+
WRONG_LABEL
5+
GOTO WRONG_LABEL
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
REM will fail because labels must be declared
3+
REM at the begining of the line
4+
5+
IF a > 10 THEN MYLABEL
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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+
_a:
22+
DEFB 00
23+
.core.ZXBASIC_USER_DATA_END:
24+
.core.__MAIN_PROGRAM__:
25+
ld a, 1
26+
ld hl, (_a - 1)
27+
cp h
28+
jp c, .LABEL._BREAK
29+
.LABEL.__LABEL1:
30+
ld a, 8
31+
call .core.__STOP
32+
ld hl, 0
33+
ld b, h
34+
ld c, l
35+
.core.__END_PROGRAM:
36+
di
37+
ld hl, (.core.__CALL_BACK__)
38+
ld sp, hl
39+
exx
40+
pop hl
41+
exx
42+
pop iy
43+
pop ix
44+
ei
45+
ret
46+
.LABEL._BREAK:
47+
ld hl, _a
48+
inc (hl)
49+
ld hl, 0
50+
ld b, h
51+
ld c, l
52+
jp .core.__END_PROGRAM
53+
;; --- end of user code ---
54+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm"
55+
; Simple error control routines
56+
; vim:ts=4:et:
57+
push namespace core
58+
ERR_NR EQU 23610 ; Error code system variable
59+
; Error code definitions (as in ZX spectrum manual)
60+
; Set error code with:
61+
; ld a, ERROR_CODE
62+
; ld (ERR_NR), a
63+
ERROR_Ok EQU -1
64+
ERROR_SubscriptWrong EQU 2
65+
ERROR_OutOfMemory EQU 3
66+
ERROR_OutOfScreen EQU 4
67+
ERROR_NumberTooBig EQU 5
68+
ERROR_InvalidArg EQU 9
69+
ERROR_IntOutOfRange EQU 10
70+
ERROR_NonsenseInBasic EQU 11
71+
ERROR_InvalidFileName EQU 14
72+
ERROR_InvalidColour EQU 19
73+
ERROR_BreakIntoProgram EQU 20
74+
ERROR_TapeLoadingErr EQU 26
75+
; Raises error using RST #8
76+
__ERROR:
77+
ld (__ERROR_CODE), a
78+
rst 8
79+
__ERROR_CODE:
80+
nop
81+
ret
82+
; Sets the error system variable, but keeps running.
83+
; Usually this instruction if followed by the END intermediate instruction.
84+
__STOP:
85+
ld (ERR_NR), a
86+
ret
87+
pop namespace
88+
#line 31 "label_decl3.bas"
89+
END
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
DIM a As UByte
3+
4+
IF a > 1 THEN GOTO BREAK
5+
STOP
6+
7+
BREAK: LET a = a + 1

0 commit comments

Comments
 (0)