Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
Merge pull request boriel-basic#627 from boriel/fix/array_assignement…
Browse files Browse the repository at this point in the history
…_str

fix: array a$=b$ assignation
  • Loading branch information
boriel committed Oct 23, 2022
2 parents 33c1ad6 + 7c10682 commit 1804109
Show file tree
Hide file tree
Showing 5 changed files with 903 additions and 14 deletions.
23 changes: 16 additions & 7 deletions src/arch/z80/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,25 @@ def _emit_arraycopy_child(self, child: symbols.VARARRAY):
return t

def visit_ARRAYCOPY(self, node):
t1 = self._emit_arraycopy_child(node.children[0])
t2 = self._emit_arraycopy_child(node.children[1])

tr = node.children[1]
t_source = node.args[1]
t_dest = node.args[0]
t = optemps.new_t()
if tr.type_ != Type.string:
self.ic_load(gl.PTR_TYPE, t, "%i" % tr.size)

if t_source.type_ != Type.string:
t1 = self._emit_arraycopy_child(t_dest)
t2 = self._emit_arraycopy_child(t_source)
self.ic_load(gl.BOUND_TYPE, t, "%i" % t_source.size)
self.ic_memcopy(t1, t2, t)
else:
self.ic_load(gl.PTR_TYPE, t, "%i" % tr.count)
t2 = self._emit_arraycopy_child(t_dest)
if t_dest.scope == SCOPE.global_:
self.ic_load(gl.PTR_TYPE, optemps.new_t(), t2)

t1 = self._emit_arraycopy_child(t_source)
if t_source.scope == SCOPE.global_:
self.ic_load(gl.PTR_TYPE, optemps.new_t(), t1)

self.ic_load(gl.BOUND_TYPE, t, "%i" % t_source.count)
self.runtime_call(RuntimeLabel.STR_ARRAYCOPY, 0)

def visit_LETARRAY(self, node):
Expand Down
4 changes: 1 addition & 3 deletions src/arch/zx48k/library-asm/strarraycpy.asm
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ STR_ARRAYCOPY:
pop hl ; ret address
pop bc ; num of elements
pop de ; source array + offset to the 1st elem.
ex (sp), hl ; Calle -> hl = destiny array + offset to the 1st elem.
ex (sp), hl ; Callee -> hl = destiny array + offset to the 1st elem.

; FASTCALL ENTRY

Expand Down Expand Up @@ -66,5 +66,3 @@ LOOP:
ENDP

pop namespace


8 changes: 4 additions & 4 deletions tests/functional/zx48k/arraycopy4.asm
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ __ALLOC_INITIALIZED_LOCAL_ARRAY:
ret
#line 139 "/zxbasic/src/arch/zx48k/library-asm/arrayalloc.asm"
pop namespace
#line 66 "arraycopy4.bas"
#line 66 "zx48k/arraycopy4.bas"
#line 1 "/zxbasic/src/arch/zx48k/library-asm/arraystrfree.asm"
; This routine is in charge of freeing an array of strings from memory
; HL = Pointer to start of array in memory
Expand Down Expand Up @@ -706,7 +706,7 @@ __ARRAYSTR_FREE_MEM: ; like the above, buf also frees the array itself
pop hl ; recovers array block pointer
jp __MEM_FREE ; Frees it and returns from __MEM_FREE
pop namespace
#line 67 "arraycopy4.bas"
#line 67 "zx48k/arraycopy4.bas"
#line 1 "/zxbasic/src/arch/zx48k/library-asm/strarraycpy.asm"
; (K)opyleft - by Jose M. Rodriguez de la Rosa (a.k.a. Boriel)
; 2009 - This is Free OpenSource BSD code
Expand Down Expand Up @@ -950,7 +950,7 @@ STR_ARRAYCOPY:
pop hl ; ret address
pop bc ; num of elements
pop de ; source array + offset to the 1st elem.
ex (sp), hl ; Calle -> hl = destiny array + offset to the 1st elem.
ex (sp), hl ; Callee -> hl = destiny array + offset to the 1st elem.
; FASTCALL ENTRY
; HL = a$ + offset
; DE = b$ + offset
Expand Down Expand Up @@ -987,7 +987,7 @@ LOOP:
jp LOOP
ENDP
pop namespace
#line 68 "arraycopy4.bas"
#line 68 "zx48k/arraycopy4.bas"
.LABEL.__LABEL0:
DEFB 00h
DEFB 00h
Expand Down

0 comments on commit 1804109

Please sign in to comment.