Skip to content

Commit 8c8bba8

Browse files
committed
Fix let local array const index
1 parent f139796 commit 8c8bba8

5 files changed

Lines changed: 1977 additions & 9 deletions

File tree

src/arch/zx48k/backend/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ def _store8(ins):
794794
if immediate:
795795
op = op[1:]
796796

797-
if is_int(op) or op[0] == '_':
797+
if is_int(op) or op[0] in '_.':
798798
if is_int(op):
799799
op = str(int(op) & 0xFFFF)
800800

@@ -837,9 +837,10 @@ def _store16(ins):
837837
"""
838838
output = _16bit_oper(ins.quad[2])
839839

840+
value = ins.quad[1]
841+
indirect = False
842+
840843
try:
841-
value = ins.quad[1]
842-
indirect = False
843844
if value[0] == '*':
844845
indirect = True
845846
value = value[1:]
@@ -854,7 +855,7 @@ def _store16(ins):
854855
else:
855856
output.append('ld (%s), hl' % str(value))
856857
except ValueError:
857-
if value[0] == '_':
858+
if value[0] in '_.':
858859
if indirect:
859860
output.append('ex de, hl')
860861
output.append('ld hl, (%s)' % str(value))
@@ -905,7 +906,7 @@ def _store32(ins):
905906
if immediate:
906907
op = op[1:]
907908

908-
if is_int(op) or op[0] == '_' or immediate:
909+
if is_int(op) or op[0] in '_.' or immediate:
909910
output = _32bit_oper(ins.quad[2], preserveHL=indirect)
910911

911912
if is_int(op):
@@ -963,7 +964,7 @@ def _storef(ins):
963964
if immediate:
964965
op = op[1:]
965966

966-
if is_int(op) or op[0] == '_':
967+
if is_int(op) or op[0] in '_.':
967968
if is_int(op):
968969
op = str(int(op) & 0xFFFF)
969970

src/arch/zx48k/backend/__parray.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ def _pastore16(ins):
168168
indirect = False
169169

170170
try:
171-
value = int(ins.quad[2]) & 0xFFFF
171+
value = int(value) & 0xFFFF
172172
output.append('ld de, %i' % value)
173173
if indirect:
174174
output.append(runtime_call(RuntimeLabel.LOAD_DE_DE))

src/arch/zx48k/translator.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,11 @@ def visit_LETARRAY(self, node):
282282
if self.O_LEVEL > 1 and not node.children[0].entry.accessed:
283283
return
284284

285-
yield node.children[1] # Right expression
286285
arr = node.children[0] # Array access
287286
scope = arr.scope
288287

289288
if arr.offset is None:
289+
yield node.children[1] # Right expression
290290
yield arr
291291

292292
if scope == SCOPE.global_:
@@ -299,14 +299,17 @@ def visit_LETARRAY(self, node):
299299
else:
300300
name = arr.entry.data_label
301301
if scope == SCOPE.global_:
302+
yield node.children[1] # Right expression
302303
self.ic_store(arr.type_, '%s + %i' % (name, arr.offset), node.children[1].t)
303304
elif scope == SCOPE.local:
304305
t1 = optemps.new_t()
305306
t2 = optemps.new_t()
306307
self.ic_pload(gl.PTR_TYPE, t1, -(arr.entry.offset - self.TYPE(gl.PTR_TYPE).size))
307308
self.ic_add(gl.PTR_TYPE, t2, t1, arr.offset)
309+
yield node.children[1] # Right expression
310+
308311
if arr.type_ == Type.string:
309-
self.ic_store(arr.type_, '*{}'.format(t2), node.children[1].t)
312+
self.ic_store(arr.type_, f'*{t2}', node.children[1].t)
310313
else:
311314
self.ic_store(arr.type_, t2, node.children[1].t)
312315
else:

0 commit comments

Comments
 (0)