Skip to content

Commit ea663ab

Browse files
authored
Merge pull request #903 from boriel-basic/fix/READ_without_data_should_fail_gracefully
fix: must show error when using READ with no DATA
2 parents 247e68e + 996bcde commit ea663ab

7 files changed

Lines changed: 18 additions & 1159 deletions

File tree

src/arch/z80/visitor/translator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,10 @@ def visit_RESTORE(self, node):
440440
self.runtime_call(RuntimeLabel.RESTORE, 0)
441441

442442
def visit_READ(self, node):
443+
if not gl.DATAS:
444+
src.api.errmsg.syntax_error_no_data_defined(node.lineno)
445+
return
446+
443447
self.ic_fparam(TYPE.ubyte, "#" + str(self.DATA_TYPES[self.TSUFFIX(node.args[0].type_)]))
444448
self.runtime_call(RuntimeLabel.READ, node.args[0].type_.size)
445449

src/arch/z80/visitor/translator_visitor.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def runtime_call(self, label: str, num: int):
117117

118118
# This function must be called before emit_strings
119119
def emit_data_blocks(self):
120-
if not gl.DATA_IS_USED:
120+
if not gl.DATA_IS_USED or not gl.DATAS:
121121
return # nothing to do
122122

123123
for label_, datas in gl.DATAS:
@@ -139,12 +139,9 @@ def emit_data_blocks(self):
139139
else:
140140
self.ic_data(d.value.type_, [self.traverse_const(d.value)])
141141

142-
if not gl.DATAS: # The above loop was not executed, because there's no data
143-
self.ic_label("__DATA__0")
144-
else:
145-
missing_data_labels = set(gl.DATA_LABELS_REQUIRED).difference([x.label.name for x in gl.DATAS])
146-
for data_label in missing_data_labels:
147-
self.ic_label(data_label) # A label reference by a RESTORE beyond the last DATA line
142+
missing_data_labels = set(gl.DATA_LABELS_REQUIRED).difference([x.label.name for x in gl.DATAS])
143+
for data_label in missing_data_labels:
144+
self.ic_label(data_label) # A label reference by a RESTORE beyond the last DATA line
148145

149146
self.ic_vard("__DATA__END", ["00"])
150147

tests/functional/arch/zx48k/arrbase1.asm

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ _c.__LBOUND__:
8787
pop ix
8888
ei
8989
ret
90-
__DATA__0:
90+
.DATA.__DATA__0:
91+
DEFB 3
92+
DEFB 1
9193
__DATA__END:
9294
DEFB 00h
9395
;; --- end of user code ---
@@ -247,7 +249,7 @@ __FNMUL2:
247249
ret
248250
ENDP
249251
pop namespace
250-
#line 46 "arch/zx48k/arrbase1.bas"
252+
#line 48 "arch/zx48k/arrbase1.bas"
251253
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/read_restore.asm"
252254
;; This implements READ & RESTORE functions
253255
;; Reads a new element from the DATA Address code
@@ -1344,5 +1346,5 @@ __DATA_ADDR: ;; Stores current DATA ptr
13441346
dw .DATA.__DATA__0
13451347
ENDP
13461348
pop namespace
1347-
#line 47 "arch/zx48k/arrbase1.bas"
1349+
#line 49 "arch/zx48k/arrbase1.bas"
13481350
END

tests/functional/arch/zx48k/arrbase1.bas

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ DIM k as Uinteger
77
FOR k=1 TO 2
88
READ c(k, 1)
99
NEXT k
10+
11+
DATA 1

0 commit comments

Comments
 (0)