Skip to content

Commit 910c87e

Browse files
committed
Bugfix: fix debug array check not working
The flag --debug-array emited wrong code. The Array calculation routine has been optimized (a little) and now does the check correctly. Also de translator was not correctly emiting the IC.
1 parent efd3020 commit 910c87e

2 files changed

Lines changed: 6 additions & 17 deletions

File tree

arch/zx48k/translator.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,11 @@ def visit_ARGLIST(self, node):
460460
for i in range(len(node) - 1, -1, -1): # visit in reverse order
461461
yield node[i]
462462

463+
if isinstance(node.parent, symbols.ARRAYACCESS) and OPTIONS.arrayCheck.value:
464+
upper = node.parent.entry.bounds[i].upper
465+
lower = node.parent.entry.bounds[i].lower
466+
self.emit('paramu16', upper - lower)
467+
463468
def visit_ARGUMENT(self, node):
464469
if not node.byref:
465470
suffix = self.TSUFFIX(node.type_)
@@ -499,11 +504,6 @@ def visit_ARRAYLOAD(self, node):
499504
if node.offset is None:
500505
yield node.args
501506

502-
if OPTIONS.arrayCheck.value:
503-
upper = node.entry.bounds[0].upper
504-
lower = node.entry.bounds[0].lower
505-
self.emit('paramu16', upper - lower)
506-
507507
if scope == SCOPE.global_:
508508
self.emit('aload' + self.TSUFFIX(node.type_), node.entry.t, node.entry.mangled)
509509
elif scope == SCOPE.parameter:
@@ -647,9 +647,6 @@ def visit_LETARRAYSUBSTR(self, node):
647647
def visit_ARRAYACCESS(self, node):
648648
yield node.arglist
649649

650-
if OPTIONS.arrayCheck.value:
651-
self.emit('param' + self.TSUFFIX(gl.BOUND_TYPE), len(node.entry.bounds))
652-
653650
def visit_STRSLICE(self, node):
654651
yield node.string
655652
if node.string.token == 'STRING' or \

library-asm/array.asm

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,10 @@ __ARRAY:
4242
4343
ld hl, 0 ; BC = Offset "accumulator"
4444

45+
LOOP:
4546
#ifdef __CHECK_ARRAY_BOUNDARY__
4647
pop de
4748
#endif
48-
49-
LOOP:
5049
pop bc ; Get next index (Ai) from the stack
5150

5251
#ifdef __CHECK_ARRAY_BOUNDARY__
@@ -74,15 +73,8 @@ LOOP:
7473
exx
7574
pop de ; DE = Max bound Number (i-th dimension)
7675

77-
#ifdef __CHECK_ARRAY_BOUNDARY__
78-
push de
79-
#endif
8076
;call __MUL16_FAST ; HL *= DE
8177
call __FNMUL
82-
#ifdef __CHECK_ARRAY_BOUNDARY__
83-
pop de
84-
dec de
85-
#endif
8678
jp LOOP
8779
8880
ARRAY_END:

0 commit comments

Comments
 (0)