Skip to content

Commit bfee37e

Browse files
committed
Fix LETSUBSTR nor working in SUBs
When LETSUBSTR is used with local vars or parameters it does now work properly. Fixed.
1 parent 3295ec4 commit bfee37e

9 files changed

Lines changed: 924 additions & 567 deletions

src/arch/zx48k/translator.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,9 @@ def visit_LETARRAY(self, node):
323323
raise InternalError("Invalid scope {} for variable '{}'".format(scope, arr.entry.name))
324324

325325
def visit_LETSUBSTR(self, node):
326+
""" LET X$(a TO b) = Y$
327+
"""
328+
# load Y$
326329
yield node.children[3]
327330

328331
if check.is_temporary_value(node.children[3]):
@@ -332,11 +335,30 @@ def visit_LETSUBSTR(self, node):
332335
self.ic_param(gl.PTR_TYPE, node.children[3].t)
333336
self.ic_param(TYPE.ubyte, 0)
334337

338+
# Load a
335339
yield node.children[1]
336340
self.ic_param(gl.PTR_TYPE, node.children[1].t)
341+
# Load b
337342
yield node.children[2]
338343
self.ic_param(gl.PTR_TYPE, node.children[2].t)
339-
self.ic_fparam(gl.PTR_TYPE, node.children[0].t)
344+
# Load x$
345+
str_var = node.children[0]
346+
scope = str_var.scope
347+
348+
if scope == SCOPE.global_:
349+
self.ic_fparam(gl.PTR_TYPE, str_var.t)
350+
elif scope == SCOPE.local:
351+
self.ic_pload(gl.PTR_TYPE, str_var.t, -str_var.offset)
352+
self.ic_fparam(gl.PTR_TYPE, f"{str_var.t}")
353+
elif scope == SCOPE.parameter:
354+
self.ic_pload(gl.PTR_TYPE, str_var.t, str_var.offset)
355+
if str_var.byref:
356+
self.ic_fparam(gl.PTR_TYPE, f"*{str_var.t}")
357+
else:
358+
self.ic_fparam(gl.PTR_TYPE, f"{str_var.t}")
359+
else:
360+
raise InternalError("Invalid scope {} for variable '{}'".format(scope, node.name))
361+
340362
self.ic_call('__LETSUBSTR', 0)
341363
backend.REQUIRES.add('letsubstr.asm')
342364

0 commit comments

Comments
 (0)