Skip to content

Commit 949b0ee

Browse files
authored
Merge pull request #348 from boriel/bugfix/data_label
Bugfix/data label
2 parents 7b170b9 + b104678 commit 949b0ee

7 files changed

Lines changed: 1158 additions & 1 deletion

File tree

api/global_.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
# DATA blocks
147147
# ----------------------------------------------------------------------
148148
DATAS = []
149+
DATA_LABELS_REQUIRED = set() # DATA labels used by RESTORE that must be emitted
149150
DATA_LABELS = {} # Maps declared labels to current data ptr
150151
DATA_PTR_CURRENT = None
151152
DATA_IS_USED = False

api/utils.py

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

44
import os
55
import shelve
6+
from typing import NamedTuple, List, Any
67

78
from . import constants
89
from . import global_
@@ -21,6 +22,11 @@
2122
SHELVE = shelve.open(SHELVE_PATH)
2223

2324

25+
class DataRef(NamedTuple):
26+
label: str
27+
datas: List[Any]
28+
29+
2430
def read_txt_file(fname):
2531
"""Reads a txt file, regardless of its encoding
2632
"""

arch/zx48k/translator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ def visit_RESTORE(self, node):
424424
if not gl.DATA_IS_USED:
425425
return # If no READ is used, ignore all DATA related statements
426426
lbl = gl.DATA_LABELS[node.args[0].name]
427+
gl.DATA_LABELS_REQUIRED.add(lbl)
427428
self.ic_fparam(node.args[0].type_, '#' + lbl)
428429
self.ic_call('__RESTORE', 0)
429430
backend.REQUIRES.add('read_restore.asm')

arch/zx48k/translatorvisitor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ def emit_data_blocks(self):
141141

142142
if not gl.DATAS: # The above loop was not executed, because there's no data
143143
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
144148

145149
self.ic_vard('__DATA__END', ['00'])
146150

0 commit comments

Comments
 (0)