Skip to content

Commit 77ca256

Browse files
committed
fix: Fixes assigning a constant string to a local array
For a local array (parameter ByRef, or locally declared) the assignation of a constant string value to an array element was broken.
1 parent 438a044 commit 77ca256

File tree

10 files changed

+2034
-135
lines changed

10 files changed

+2034
-135
lines changed

src/arch/z80/backend/_array.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,8 @@ def _astoref(ins: Quad) -> list[str]:
313313

314314
def _astorestr(ins: Quad) -> list[str]:
315315
"""Stores a string value into a memory address.
316-
It copies content of 2nd operand (string), into 1st, reallocating
317-
dynamic memory for the 1st str. These instruction DOES ALLOW
316+
It copies the content of the 2nd operand (string), into 1st, reallocating
317+
dynamic memory for the 1st str. These instructions DO ALLOW
318318
immediate strings for the 2nd parameter, starting with '#'.
319319
"""
320320
output = _addr(ins[1])

src/arch/z80/backend/_parray.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,17 +289,20 @@ def _pastorestr(ins: Quad) -> list[str]:
289289
immediate strings for the 2nd parameter, starting with '#'.
290290
"""
291291
output = _paddr(ins[1])
292-
temporal = False
293292
value = ins[2]
294293

295294
indirect = value[0] == "*"
296295
if indirect:
297296
value = value[1:]
298297

299-
immediate = value[0]
298+
immediate = value[0] == "#"
300299
if immediate:
301300
value = value[1:]
302301

302+
temporal = not immediate and value[0] != "$"
303+
if temporal:
304+
value = value[1:]
305+
303306
if value[0] == "_":
304307
if indirect:
305308
if immediate:
@@ -313,8 +316,10 @@ def _pastorestr(ins: Quad) -> list[str]:
313316
else:
314317
output.append("ld de, (%s)" % value)
315318
else:
316-
output.append("pop de")
317-
temporal = True
319+
if immediate:
320+
output.append("ld de, %s" % value)
321+
else:
322+
output.append("pop de")
318323

319324
if indirect:
320325
output.append(runtime_call(RuntimeLabel.LOAD_DE_DE))

src/symbols/id_/ref/varref.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def t(self) -> str:
3939
if self.parent.type_ is None or not self.parent.type_.is_dynamic:
4040
return self._t
4141

42-
return f"${self._t}" # Local string variables (and parameters) use '$' (see backend)
42+
return f"${self._t}" # Local string variables (and ByVal parameters) use '$' (see backend)
4343

4444
@property
4545
def size(self) -> int:

src/zxbc/zxbparser.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1198,7 +1198,8 @@ def p_arr_assignment(p):
11981198

11991199
if entry.type_ == TYPE.string:
12001200
variable = gl.SYMBOL_TABLE.access_array(id_, p.lineno(i))
1201-
if len(variable.ref.bounds) + 1 == len(arg_list):
1201+
# variable is an array. If it has 0 bounds means they are undefined (param byref)
1202+
if len(variable.ref.bounds) and len(variable.ref.bounds) + 1 == len(arg_list):
12021203
ss = arg_list.children.pop().value
12031204
p[0] = make_array_substr_assign(p.lineno(i), id_, arg_list, (ss, ss), expr)
12041205
return

0 commit comments

Comments
 (0)