Skip to content

Commit 9600f5b

Browse files
committed
refact: type str instrs
Also rename __str to _str
1 parent c1465d2 commit 9600f5b

2 files changed

Lines changed: 21 additions & 20 deletions

File tree

src/arch/z80/backend/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@
9595
from ._float import _orf, _andf, _notf, _xorf
9696

9797
# String arithmetic functions
98-
from .__str import _addstr, _loadstr, _storestr, _jzerostr, _jnzerostr, _retstr, _paramstr, _fparamstr
98+
from ._str import _addstr, _loadstr, _storestr, _jzerostr, _jnzerostr, _retstr, _paramstr, _fparamstr
9999

100100
# String comparison functions
101-
from .__str import _ltstr, _gtstr, _eqstr, _lestr, _gestr, _nestr, _lenstr
101+
from ._str import _ltstr, _gtstr, _eqstr, _lestr, _gestr, _nestr, _lenstr
102102

103103
# Param load and store instructions
104104
from .__pload import _pload8, _pload16, _pload32, _ploadf, _ploadstr, _fploadstr
Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010
# comparison intermediate-code translation
1111
# --------------------------------------------------------------
1212

13-
from .common import runtime_call
13+
from typing import List
1414

15+
from src.arch.z80.backend.errors import InvalidICError as InvalidIC
1516
from src.arch.z80.backend.runtime import Labels as RuntimeLabels, Labels as RuntimeLabel
16-
from .errors import InvalidICError as InvalidIC
17+
from src.arch.z80.backend.common import runtime_call, Quad
1718

1819

1920
def _str_oper(op1, op2=None, reversed=False, no_exaf=False):
@@ -100,7 +101,7 @@ def _str_oper(op1, op2=None, reversed=False, no_exaf=False):
100101
return tmp1, output
101102

102103

103-
def _free_sequence(tmp1, tmp2=False):
104+
def _free_sequence(tmp1, tmp2=False) -> List[str]:
104105
"""Outputs a FREEMEM sequence for 1 or 2 ops"""
105106
if not tmp1 and not tmp2:
106107
return []
@@ -121,7 +122,7 @@ def _free_sequence(tmp1, tmp2=False):
121122
return output
122123

123124

124-
def _addstr(ins):
125+
def _addstr(ins: Quad) -> List[str]:
125126
"""Adds 2 string values. The result is pushed onto the stack.
126127
Note: This instruction does admit direct strings (as labels).
127128
"""
@@ -139,7 +140,7 @@ def _addstr(ins):
139140
return output
140141

141142

142-
def _ltstr(ins):
143+
def _ltstr(ins: Quad) -> List[str]:
143144
"""Compares & pops top 2 strings out of the stack.
144145
Temporal values are freed from memory. (a$ < b$)
145146
"""
@@ -149,7 +150,7 @@ def _ltstr(ins):
149150
return output
150151

151152

152-
def _gtstr(ins):
153+
def _gtstr(ins: Quad) -> List[str]:
153154
"""Compares & pops top 2 strings out of the stack.
154155
Temporal values are freed from memory. (a$ > b$)
155156
"""
@@ -159,7 +160,7 @@ def _gtstr(ins):
159160
return output
160161

161162

162-
def _lestr(ins):
163+
def _lestr(ins: Quad) -> List[str]:
163164
"""Compares & pops top 2 strings out of the stack.
164165
Temporal values are freed from memory. (a$ <= b$)
165166
"""
@@ -169,7 +170,7 @@ def _lestr(ins):
169170
return output
170171

171172

172-
def _gestr(ins):
173+
def _gestr(ins: Quad) -> List[str]:
173174
"""Compares & pops top 2 strings out of the stack.
174175
Temporal values are freed from memory. (a$ >= b$)
175176
"""
@@ -179,7 +180,7 @@ def _gestr(ins):
179180
return output
180181

181182

182-
def _eqstr(ins):
183+
def _eqstr(ins: Quad) -> List[str]:
183184
"""Compares & pops top 2 strings out of the stack.
184185
Temporal values are freed from memory. (a$ == b$)
185186
"""
@@ -189,7 +190,7 @@ def _eqstr(ins):
189190
return output
190191

191192

192-
def _nestr(ins):
193+
def _nestr(ins: Quad) -> List[str]:
193194
"""Compares & pops top 2 strings out of the stack.
194195
Temporal values are freed from memory. (a$ != b$)
195196
"""
@@ -199,7 +200,7 @@ def _nestr(ins):
199200
return output
200201

201202

202-
def _lenstr(ins):
203+
def _lenstr(ins: Quad) -> List[str]:
203204
"""Returns string length"""
204205
(tmp1, output) = _str_oper(ins.quad[2], no_exaf=True)
205206
if tmp1:
@@ -211,7 +212,7 @@ def _lenstr(ins):
211212
return output
212213

213214

214-
def _loadstr(ins):
215+
def _loadstr(ins: Quad) -> List[str]:
215216
"""Loads a string value from a memory address."""
216217
temporal, output = _str_oper(ins.quad[2], no_exaf=True)
217218

@@ -222,7 +223,7 @@ def _loadstr(ins):
222223
return output
223224

224225

225-
def _storestr(ins):
226+
def _storestr(ins: Quad) -> List[str]:
226227
"""Stores a string value into a memory address.
227228
It copies content of 2nd operand (string), into 1st, reallocating
228229
dynamic memory for the 1st str. These instruction DOES ALLOW
@@ -253,7 +254,7 @@ def _storestr(ins):
253254
return output
254255

255256

256-
def _jzerostr(ins):
257+
def _jzerostr(ins: Quad) -> List[str]:
257258
"""Jumps if top of the stack contains a NULL pointer
258259
or its len is Zero
259260
"""
@@ -281,7 +282,7 @@ def _jzerostr(ins):
281282
return output
282283

283284

284-
def _jnzerostr(ins):
285+
def _jnzerostr(ins: Quad) -> List[str]:
285286
"""Jumps if top of the stack contains a string with
286287
at less 1 char
287288
"""
@@ -309,7 +310,7 @@ def _jnzerostr(ins):
309310
return output
310311

311312

312-
def _retstr(ins):
313+
def _retstr(ins: Quad) -> List[str]:
313314
"""Returns from a procedure / function a string pointer (16bits) value"""
314315
tmp, output = _str_oper(ins.quad[1], no_exaf=True)
315316

@@ -321,7 +322,7 @@ def _retstr(ins):
321322
return output
322323

323324

324-
def _paramstr(ins):
325+
def _paramstr(ins: Quad) -> List[str]:
325326
"""Pushes an 16 bit unsigned value, which points
326327
to a string. For indirect values, it will push
327328
the pointer to the pointer :-)
@@ -337,7 +338,7 @@ def _paramstr(ins):
337338
return output
338339

339340

340-
def _fparamstr(ins):
341+
def _fparamstr(ins: Quad) -> List[str]:
341342
"""Passes a string ptr as a __FASTCALL__ parameter.
342343
This is done by popping out of the stack for a
343344
value, or by loading it from memory (indirect)

0 commit comments

Comments
 (0)