Skip to content

Commit e5e66bc

Browse files
authored
Merge pull request #502 from boriel/bugfix/RESTORE_with_no_label
Fix bug in RESTORE with no label
2 parents eb75bef + a0f9ffc commit e5e66bc

11 files changed

Lines changed: 1264 additions & 6 deletions

File tree

src/api/errmsg.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,4 +295,11 @@ def syntax_error_address_must_be_constant(lineno: int):
295295
def syntax_error_cannot_pass_array_by_value(lineno: int, id_: str):
296296
error(lineno, "Array parameter '%s' must be passed ByRef" % id_)
297297

298+
299+
# ----------------------------------------
300+
# Cannot pass an array by value
301+
# ----------------------------------------
302+
def syntax_error_no_data_defined(lineno: int):
303+
error(lineno, "No DATA defined")
304+
298305
# endregion

src/api/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242

4343
class DataRef(NamedTuple):
44-
label: str
44+
label: symbols.LABEL
4545
datas: List[Any]
4646

4747

src/arch/zx48k/translator.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,20 @@ def visit_FUNCCALL(self, node):
431431
def visit_RESTORE(self, node):
432432
if not gl.DATA_IS_USED:
433433
return # If no READ is used, ignore all DATA related statements
434-
lbl = gl.DATA_LABELS[node.args[0].name]
434+
435+
if not node.args: # No label?
436+
if not gl.DATAS:
437+
src.api.errmsg.syntax_error_no_data_defined(node.lineno)
438+
return
439+
440+
lbl = gl.DATAS[0].label.name
441+
type_ = gl.PTR_TYPE
442+
else:
443+
lbl = gl.DATA_LABELS[node.args[0].name]
444+
type_ = node.args[0].type_
445+
435446
gl.DATA_LABELS_REQUIRED.add(lbl)
436-
self.ic_fparam(node.args[0].type_, '#' + lbl)
447+
self.ic_fparam(type_, '#' + lbl)
437448
self.runtime_call(RuntimeLabel.RESTORE, 0)
438449

439450
def visit_READ(self, node):

src/zxbc/zxbparser.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,11 +1736,10 @@ def p_restore(p):
17361736
| RESTORE NUMBER
17371737
"""
17381738
if len(p) == 2:
1739-
id_ = '__DATA__{0}'.format(len(gl.DATAS))
1739+
lbl = None
17401740
else:
1741-
id_ = p[2]
1741+
lbl = check_and_make_label(p[2], p.lineno(1))
17421742

1743-
lbl = check_and_make_label(id_, p.lineno(1))
17441743
p[0] = make_sentence(p.lineno(1), 'RESTORE', lbl)
17451744

17461745

tests/functional/restore0.asm

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
org 32768
2+
__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 (__CALL_BACK__), hl
12+
ei
13+
jp __MAIN_PROGRAM__
14+
__CALL_BACK__:
15+
DEFW 0
16+
ZXBASIC_USER_DATA:
17+
; Defines USER DATA Length in bytes
18+
ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA
19+
.__LABEL__.ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_LEN
20+
.__LABEL__.ZXBASIC_USER_DATA EQU ZXBASIC_USER_DATA
21+
ZXBASIC_USER_DATA_END:
22+
__MAIN_PROGRAM__:
23+
ld hl, 0
24+
ld b, h
25+
ld c, l
26+
__END_PROGRAM:
27+
di
28+
ld hl, (__CALL_BACK__)
29+
ld sp, hl
30+
exx
31+
pop hl
32+
exx
33+
pop iy
34+
pop ix
35+
ei
36+
ret
37+
;; --- end of user code ---
38+
END

tests/functional/restore0.bas

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
REM should be ignored since there's no READ sentence
2+
restore
3+

tests/functional/restore2.asm

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
org 32768
2+
__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 (__CALL_BACK__), hl
12+
ei
13+
jp __MAIN_PROGRAM__
14+
__CALL_BACK__:
15+
DEFW 0
16+
ZXBASIC_USER_DATA:
17+
; Defines USER DATA Length in bytes
18+
ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA
19+
.__LABEL__.ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_LEN
20+
.__LABEL__.ZXBASIC_USER_DATA EQU ZXBASIC_USER_DATA
21+
ZXBASIC_USER_DATA_END:
22+
__MAIN_PROGRAM__:
23+
ld hl, 0
24+
ld b, h
25+
ld c, l
26+
__END_PROGRAM:
27+
di
28+
ld hl, (__CALL_BACK__)
29+
ld sp, hl
30+
exx
31+
pop hl
32+
exx
33+
pop iy
34+
pop ix
35+
ei
36+
ret
37+
;; --- end of user code ---
38+
END

tests/functional/restore2.bas

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
REM should be ignored since there's no READ sentence
2+
DATA 10
3+
4+
restore

0 commit comments

Comments
 (0)