Skip to content

Commit 7f845e1

Browse files
committed
Put labels into LABEL namespace
1 parent 90e0678 commit 7f845e1

5 files changed

Lines changed: 15 additions & 11 deletions

File tree

src/api/global_.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@
122122
# ----------------------------------------------------------------------
123123
DATAS_NAMESPACE = '.DATA'
124124

125+
# ----------------------------------------------------------------------
126+
# LABEL Labels namespace
127+
# ----------------------------------------------------------------------
128+
LABELS_NAMESPACE = '.LABEL'
129+
125130
# ----------------------------------------------------------------------
126131
# Data Type used for string chars index. Must be an integral
127132
# ----------------------------------------------------------------------

src/api/symboltable.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,8 @@ def declare_label(self, id_: str, lineno: int) -> Optional[SymbolLABEL]:
692692
# HINT: ??? Mangled name. Just the label, 'cause it starts with '.'
693693
entry.mangled = '%s' % id_
694694
else:
695-
# HINT: Mangled name. Labels are __LABEL__
696-
entry.mangled = '__LABEL__%s' % entry.name
695+
# TODO: This shouln't be needed (but still is). Need investigation
696+
entry.mangled = f'{global_.LABELS_NAMESPACE}.{symbols.LABEL.prefix}{entry.name}'
697697

698698
entry.is_line_number = isinstance(id1, int)
699699

src/arch/zx48k/backend/__common.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
from typing import List
88
from typing import Set
99

10+
import src.api.global_ as gl
1011
import src.api.errors
12+
1113
from .runtime import RUNTIME_LABELS
1214
from .runtime import LABEL_REQUIRED_MODULES
1315

@@ -69,7 +71,7 @@ def tmp_label() -> str:
6971
global LABEL_COUNTER
7072
global TMP_LABELS
7173

72-
result = '__LABEL%i' % LABEL_COUNTER
74+
result = f'{gl.LABELS_NAMESPACE}.__LABEL{LABEL_COUNTER}'
7375
TMP_LABELS.add(result)
7476
LABEL_COUNTER += 1
7577

src/arch/zx48k/backend/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2331,7 +2331,7 @@ def remove_unused_labels(output: List[str]):
23312331
labels_to_delete.pop(new_label, None)
23322332

23332333
if new_label != op:
2334-
output[i] = re.sub(r'\b' + op + r'\b', new_label, ins)
2334+
output[i] = re.sub(f"((?<![.a-zA-Z0-9_])){op.replace('.', '[.]')}(?=$|\\s)", new_label, ins)
23352335

23362336
for i in sorted(labels_to_delete.values(), reverse=True):
23372337
output.pop(i)

src/symbols/label.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
# the GNU General License
1010
# ----------------------------------------------------------------------
1111

12+
from src.api import global_
13+
1214
from src.api.constants import CLASS
1315
from .var import SymbolVAR
1416
from .symbol_ import Symbol
@@ -18,16 +20,11 @@ class SymbolLABEL(SymbolVAR):
1820
prefix = '__LABEL__'
1921

2022
def __init__(self, name, lineno):
21-
super(SymbolLABEL, self).__init__(name, lineno)
23+
super().__init__(name, lineno)
24+
self.mangled = f"{global_.LABELS_NAMESPACE}.{self.prefix}{name}"
2225
self.class_ = CLASS.label
2326
self._scope_owner = [] # list of nested functions containing this label (scope)
2427

25-
@property
26-
def t(self):
27-
""" t property is constant for labels
28-
"""
29-
return self.prefix + self.name
30-
3128
@property
3229
def accessed(self):
3330
return self._accessed

0 commit comments

Comments
 (0)