Skip to content

Commit d8150bb

Browse files
authored
Merge pull request #954 from boriel-basic/fix/missing_check_pending_calls
Fix/missing check pending calls
2 parents 9b93c89 + 3a463be commit d8150bb

File tree

10 files changed

+170
-8
lines changed

10 files changed

+170
-8
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ htmlcov/
1818
build/
1919
venv/
2020
.pypi-token
21+
.coverage.*

src/zxbc/zxbc.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import re
55
import sys
6+
from argparse import Namespace
67
from io import StringIO
78

89
import src.api.optimize
@@ -61,7 +62,12 @@ def output(memory, ofile=None):
6162
ofile.write("%s\n" % m)
6263

6364

64-
def main(args=None, emitter=None):
65+
def save_config(options: Namespace) -> None:
66+
if not gl.has_errors and options.save_config:
67+
src.api.config.save_config_into_file(options.save_config, src.api.config.ConfigSections.ZXBC)
68+
69+
70+
def main(args=None, emitter=None) -> int:
6571
"""Entry point when executed from command line.
6672
zxbc can be used as python module. If so, bear in mind this function
6773
won't be executed unless explicitly called.
@@ -124,6 +130,10 @@ def main(args=None, emitter=None):
124130
debug.__DEBUG__("exiting due to errors.")
125131
return 1 # Exit with errors
126132

133+
if options.parse_only:
134+
save_config(options)
135+
return gl.has_errors
136+
127137
# Emits data lines
128138
translator.emit_data_blocks()
129139
# Emits default constant strings
@@ -216,8 +226,7 @@ def main(args=None, emitter=None):
216226
with open_file(OPTIONS.memory_map, "wt", "utf-8") as f:
217227
f.write(asmparse.MEMORY.memory_map)
218228

219-
if not gl.has_errors and options.save_config:
220-
src.api.config.save_config_into_file(options.save_config, src.api.config.ConfigSections.ZXBC)
229+
save_config(options)
221230

222231
return gl.has_errors # Exit success
223232

src/zxbc/zxblex.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,8 @@ def t_ID(t):
617617
entry = api.global_.SYMBOL_TABLE.get_entry(t.value) if api.global_.SYMBOL_TABLE is not None else None
618618
if entry:
619619
t.type = callables.get(entry.class_, t.type)
620+
elif is_label(t):
621+
t.type = "LABEL"
620622

621623
if t.type == "BIN":
622624
t.lexer.begin("bin")
@@ -683,7 +685,7 @@ def find_column(token):
683685
return column
684686

685687

686-
def is_label(token):
688+
def is_label(token) -> bool:
687689
"""Return whether the token is a label (an integer number or id
688690
at the beginning of a line.
689691
@@ -706,11 +708,23 @@ def is_label(token):
706708
i -= 1
707709

708710
column = c - i
711+
if column != 0:
712+
return False
713+
714+
if token.type == "NUMBER":
715+
return True
716+
717+
i = token.lexpos + len(token.value)
718+
while i < len(input):
719+
if input[i] == ":":
720+
return True
721+
722+
if input[i] not in {" ", "\t"}:
723+
break
709724

710-
if column == 0:
711-
column += 1
725+
i += 1
712726

713-
return column == 1
727+
return False
714728

715729

716730
lexer = lex.lex()

src/zxbc/zxbparser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ def p_statement_call(p):
10741074
p[0] = None
10751075
elif len(p) == 2:
10761076
entry = SYMBOL_TABLE.get_entry(p[1])
1077-
if not entry or entry.class_ in (CLASS.label, CLASS.unknown):
1077+
if entry is not None and entry.class_ in (CLASS.label, CLASS.unknown):
10781078
p[0] = make_label(p[1], p.lineno(1))
10791079
else:
10801080
p[0] = make_sub_call(p[1], p.lineno(1), make_arg_list(None))
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)