Skip to content

Commit 5dcb67a

Browse files
committed
Refactorize ZXBASIC_USER_DATA labels
1 parent 7f845e1 commit 5dcb67a

5 files changed

Lines changed: 27 additions & 12 deletions

File tree

src/api/global_.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@
117117
# ----------------------------------------------------------------------
118118
SIZE_TYPE = None
119119

120+
# ----------------------------------------------------------------------
121+
# CORE namespace (for core runtime library, like FP Calc)
122+
# ----------------------------------------------------------------------
123+
CORE_NAMESPACE = 'core.'
124+
120125
# ----------------------------------------------------------------------
121126
# DATA Labels namespace
122127
# ----------------------------------------------------------------------
@@ -127,6 +132,13 @@
127132
# ----------------------------------------------------------------------
128133
LABELS_NAMESPACE = '.LABEL'
129134

135+
# ----------------------------------------------------------------------
136+
# USER DATA LABELS
137+
# ----------------------------------------------------------------------
138+
ZXBASIC_USER_DATA = f".{CORE_NAMESPACE}ZXBASIC_USER_DATA"
139+
ZXBASIC_USER_DATA_LEN = f".{CORE_NAMESPACE}ZXBASIC_USER_DATA_LEN"
140+
141+
130142
# ----------------------------------------------------------------------
131143
# Data Type used for string chars index. Must be an integral
132144
# ----------------------------------------------------------------------

src/api/symboltable.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -688,9 +688,8 @@ def declare_label(self, id_: str, lineno: int) -> Optional[SymbolLABEL]:
688688
entry = symbols.VAR.to_label(entry)
689689

690690
if id_[0] == '.':
691-
id_ = id_[1:]
692-
# HINT: ??? Mangled name. Just the label, 'cause it starts with '.'
693-
entry.mangled = '%s' % id_
691+
# Just the label, because it starts with '.' so it's a root-global label
692+
entry.mangled = f'{id_}'
694693
else:
695694
# TODO: This shouln't be needed (but still is). Need investigation
696695
entry.mangled = f'{global_.LABELS_NAMESPACE}.{symbols.LABEL.prefix}{entry.name}'

src/arch/zx48k/backend/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
from typing import List
1212
from typing import Set
1313

14+
from src.api import global_
15+
1416
from . import errors
1517
from .errors import InvalidICError as InvalidIC
1618

@@ -122,8 +124,8 @@
122124
END_LABEL = f'{NAMESPACE}__END_PROGRAM'
123125
CALL_BACK = f'{NAMESPACE}__CALL_BACK__'
124126
MAIN_LABEL = f'{NAMESPACE}__MAIN_PROGRAM__'
125-
DATA_LABEL = f'{NAMESPACE}ZXBASIC_USER_DATA'
126-
DATA_END_LABEL = f'{NAMESPACE}ZXBASIC_USER_DATA_END'
127+
DATA_LABEL = global_.ZXBASIC_USER_DATA.lstrip('.')
128+
DATA_END_LABEL = f'{DATA_LABEL}_END'.lstrip('.')
127129

128130
# Whether to use the FunctionExit scheme
129131
FLAG_use_function_exit = False
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
# Define just the main Private namespace
22

3-
NAMESPACE = 'core.'
3+
from src.api import global_
4+
5+
NAMESPACE = global_.CORE_NAMESPACE

src/zxbc/zxbparser.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,8 @@ def p_start(p):
516516
"""
517517
global ast, data_ast
518518

519-
make_label('.ZXBASIC_USER_DATA', 0)
520-
make_label('.ZXBASIC_USER_DATA_LEN', 0)
519+
make_label(gl.ZXBASIC_USER_DATA, 0)
520+
make_label(gl.ZXBASIC_USER_DATA_LEN, 0)
521521

522522
if PRINT_IS_USED:
523523
zxbpp.ID_TABLE.define('___PRINT_IS_USED___', 1)
@@ -2231,10 +2231,10 @@ def p_save_data(p):
22312231
else:
22322232
length = make_number(entry.type_.size, lineno=p.lineno(4))
22332233
else:
2234-
access = SYMBOL_TABLE.access_label('.ZXBASIC_USER_DATA', p.lineno(3), SYMBOL_TABLE.global_scope)
2234+
access = SYMBOL_TABLE.access_label(gl.ZXBASIC_USER_DATA, p.lineno(3), SYMBOL_TABLE.global_scope)
22352235
start = make_unary(p.lineno(3), 'ADDRESS', access, type_=TYPE.uinteger)
22362236

2237-
access = SYMBOL_TABLE.access_label('.ZXBASIC_USER_DATA_LEN', p.lineno(3), SYMBOL_TABLE.global_scope)
2237+
access = SYMBOL_TABLE.access_label(gl.ZXBASIC_USER_DATA_LEN, p.lineno(3), SYMBOL_TABLE.global_scope)
22382238
length = make_unary(p.lineno(3), 'ADDRESS', access, type_=TYPE.uinteger)
22392239

22402240
p[0] = make_sentence(p.lineno(1), p[1], p[2], start, length)
@@ -2300,10 +2300,10 @@ def p_load_data(p):
23002300
else:
23012301
length = make_number(entry.type_.size, lineno=p.lineno(4))
23022302
else:
2303-
entry = SYMBOL_TABLE.access_label('.ZXBASIC_USER_DATA', p.lineno(3), SYMBOL_TABLE.global_scope)
2303+
entry = SYMBOL_TABLE.access_label(gl.ZXBASIC_USER_DATA, p.lineno(3), SYMBOL_TABLE.global_scope)
23042304
start = make_unary(p.lineno(3), 'ADDRESS', entry, type_=TYPE.uinteger)
23052305

2306-
entry = SYMBOL_TABLE.access_label('.ZXBASIC_USER_DATA_LEN', p.lineno(3), SYMBOL_TABLE.global_scope)
2306+
entry = SYMBOL_TABLE.access_label(gl.ZXBASIC_USER_DATA_LEN, p.lineno(3), SYMBOL_TABLE.global_scope)
23072307
length = make_unary(p.lineno(3), 'ADDRESS', entry, type_=TYPE.uinteger)
23082308

23092309
p[0] = make_sentence(p.lineno(3), p[1], p[2], start, length)

0 commit comments

Comments
 (0)