Skip to content

Commit 0c22aa3

Browse files
authored
Merge pull request #950 from boriel-basic/refact/runtime_lib
refact: move array runtime into its own folder
2 parents 71b567f + 94355ae commit 0c22aa3

File tree

23 files changed

+4055
-74
lines changed

23 files changed

+4055
-74
lines changed

src/arch/z80/backend/runtime/core.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,16 @@ class CoreLabels:
138138
CoreLabels.ABS32: "abs32.asm",
139139
CoreLabels.ADDF: "arith/addf.asm",
140140
CoreLabels.ADDSTR: "strcat.asm",
141-
CoreLabels.ALLOC_INITIALIZED_LOCAL_ARRAY: "arrayalloc.asm",
142-
CoreLabels.ALLOC_INITIALIZED_LOCAL_ARRAY_WITH_BOUNDS: "arrayalloc.asm",
143-
CoreLabels.ALLOC_LOCAL_ARRAY: "arrayalloc.asm",
144-
CoreLabels.ALLOC_LOCAL_ARRAY_WITH_BOUNDS: "arrayalloc.asm",
141+
CoreLabels.ALLOC_INITIALIZED_LOCAL_ARRAY: "array/arrayalloc.asm",
142+
CoreLabels.ALLOC_INITIALIZED_LOCAL_ARRAY_WITH_BOUNDS: "array/arrayalloc.asm",
143+
CoreLabels.ALLOC_LOCAL_ARRAY: "array/arrayalloc.asm",
144+
CoreLabels.ALLOC_LOCAL_ARRAY_WITH_BOUNDS: "array/arrayalloc.asm",
145145
CoreLabels.AND16: "bool/and16.asm",
146146
CoreLabels.AND32: "bool/and32.asm",
147147
CoreLabels.ANDF: "bool/andf.asm",
148-
CoreLabels.ARRAY: "array.asm",
149-
CoreLabels.ARRAY_PTR: "array.asm",
150-
CoreLabels.ARRAYSTR_FREE_MEM: "arraystrfree.asm",
148+
CoreLabels.ARRAY: "array/array.asm",
149+
CoreLabels.ARRAY_PTR: "array/array.asm",
150+
CoreLabels.ARRAYSTR_FREE_MEM: "array/arraystrfree.asm",
151151
CoreLabels.BAND16: "bitwise/band16.asm",
152152
CoreLabels.BAND32: "bitwise/band32.asm",
153153
CoreLabels.BNOT16: "bitwise/bnot16.asm",
@@ -239,7 +239,7 @@ class CoreLabels:
239239
CoreLabels.STORE32: "store32.asm",
240240
CoreLabels.STORE_STR: "storestr.asm",
241241
CoreLabels.STORE_STR2: "storestr2.asm",
242-
CoreLabels.STR_ARRAYCOPY: "strarraycpy.asm",
242+
CoreLabels.STR_ARRAYCOPY: "array/strarraycpy.asm",
243243
CoreLabels.STR_FAST: "str.asm",
244244
CoreLabels.STREQ: "string.asm",
245245
CoreLabels.STRGE: "string.asm",
File renamed without changes.
File renamed without changes.

src/lib/arch/zx48k/runtime/arraystrfree.asm renamed to src/lib/arch/zx48k/runtime/array/arraystrfree.asm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,3 @@ __ARRAYSTR_FREE_MEM: ; like the above, buf also frees the array itself
6161
jp __MEM_FREE ; Frees it and returns from __MEM_FREE
6262

6363
pop namespace
64-
File renamed without changes.
File renamed without changes.
File renamed without changes.

src/lib/arch/zxnext/runtime/arraystrfree.asm renamed to src/lib/arch/zxnext/runtime/array/arraystrfree.asm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,3 @@ __ARRAYSTR_FREE_MEM: ; like the above, buf also frees the array itself
6161
jp __MEM_FREE ; Frees it and returns from __MEM_FREE
6262

6363
pop namespace
64-
File renamed without changes.

tests/functional/arch/zx48k/arraycopy5.asm

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,30 @@ _c.__DATA__:
9999
DEFB 6Ch
100100
DEFB 64h
101101
;; --- end of user code ---
102-
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/storestr.asm"
103-
; vim:ts=4:et:sw=4
104-
; Stores value of current string pointed by DE register into address pointed by HL
105-
; Returns DE = Address pointer (&a$)
106-
; Returns HL = HL (b$ => might be needed later to free it from the heap)
107-
;
108-
; e.g. => HL = _variableName (DIM _variableName$)
109-
; DE = Address into the HEAP
110-
;
111-
; This function will resize (REALLOC) the space pointed by HL
112-
; before copying the content of b$ into a$
102+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/array/strarraycpy.asm"
103+
; (K)opyleft - by Jose M. Rodriguez de la Rosa (a.k.a. Boriel)
104+
; 2009 - This is Free OpenSource BSD code
105+
; vim: et:ts=4:sw=4
106+
; Copies a vector of strings from one place to another
107+
; reallocating strings of the destiny vector to hold source strings.
108+
; This is used in the following code:
109+
; DIM a$(20) : DIM b$(20): a$ = b$
110+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/lddede.asm"
111+
; Loads DE into DE
112+
; Modifies C register
113+
; There is a routine similar to this one
114+
; at ROM address L2AEE
115+
push namespace core
116+
__LOAD_DE_DE:
117+
ex de, hl
118+
ld c, (hl)
119+
inc hl
120+
ld h, (hl)
121+
ld l, c
122+
ex de, hl
123+
ret
124+
pop namespace
125+
#line 11 "/zxbasic/src/lib/arch/zx48k/runtime/array/strarraycpy.asm"
113126
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/strcpy.asm"
114127
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/realloc.asm"
115128
; vim: ts=4:et:sw=4:
@@ -780,58 +793,7 @@ __NOTHING_TO_COPY:
780793
ret
781794
ENDP
782795
pop namespace
783-
#line 14 "/zxbasic/src/lib/arch/zx48k/runtime/storestr.asm"
784-
push namespace core
785-
__PISTORE_STR: ; Indirect assignment at (IX + BC)
786-
push ix
787-
pop hl
788-
add hl, bc
789-
__ISTORE_STR: ; Indirect assignment, hl point to a pointer to a pointer to the heap!
790-
ld c, (hl)
791-
inc hl
792-
ld h, (hl)
793-
ld l, c ; HL = (HL)
794-
__STORE_STR:
795-
push de ; Pointer to b$
796-
push hl ; Pointer to a$
797-
ld c, (hl)
798-
inc hl
799-
ld h, (hl)
800-
ld l, c ; HL = (HL)
801-
call __STRASSIGN ; HL (a$) = DE (b$); HL changed to a new dynamic memory allocation
802-
ex de, hl ; DE = new address of a$
803-
pop hl ; Recover variable memory address pointer
804-
ld (hl), e
805-
inc hl
806-
ld (hl), d ; Stores a$ ptr into element ptr
807-
pop hl ; Returns ptr to b$ in HL (Caller might needed to free it from memory)
808-
ret
809-
pop namespace
810-
#line 40 "arch/zx48k/arraycopy5.bas"
811-
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/strarraycpy.asm"
812-
; (K)opyleft - by Jose M. Rodriguez de la Rosa (a.k.a. Boriel)
813-
; 2009 - This is Free OpenSource BSD code
814-
; vim: et:ts=4:sw=4
815-
; Copies a vector of strings from one place to another
816-
; reallocating strings of the destiny vector to hold source strings.
817-
; This is used in the following code:
818-
; DIM a$(20) : DIM b$(20): a$ = b$
819-
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/lddede.asm"
820-
; Loads DE into DE
821-
; Modifies C register
822-
; There is a routine similar to this one
823-
; at ROM address L2AEE
824-
push namespace core
825-
__LOAD_DE_DE:
826-
ex de, hl
827-
ld c, (hl)
828-
inc hl
829-
ld h, (hl)
830-
ld l, c
831-
ex de, hl
832-
ret
833-
pop namespace
834-
#line 11 "/zxbasic/src/lib/arch/zx48k/runtime/strarraycpy.asm"
796+
#line 12 "/zxbasic/src/lib/arch/zx48k/runtime/array/strarraycpy.asm"
835797
push namespace core
836798
STR_ARRAYCOPY:
837799
; Copies an array of string a$ = b$
@@ -877,5 +839,43 @@ LOOP:
877839
jp LOOP
878840
ENDP
879841
pop namespace
842+
#line 40 "arch/zx48k/arraycopy5.bas"
843+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/storestr.asm"
844+
; vim:ts=4:et:sw=4
845+
; Stores value of current string pointed by DE register into address pointed by HL
846+
; Returns DE = Address pointer (&a$)
847+
; Returns HL = HL (b$ => might be needed later to free it from the heap)
848+
;
849+
; e.g. => HL = _variableName (DIM _variableName$)
850+
; DE = Address into the HEAP
851+
;
852+
; This function will resize (REALLOC) the space pointed by HL
853+
; before copying the content of b$ into a$
854+
push namespace core
855+
__PISTORE_STR: ; Indirect assignment at (IX + BC)
856+
push ix
857+
pop hl
858+
add hl, bc
859+
__ISTORE_STR: ; Indirect assignment, hl point to a pointer to a pointer to the heap!
860+
ld c, (hl)
861+
inc hl
862+
ld h, (hl)
863+
ld l, c ; HL = (HL)
864+
__STORE_STR:
865+
push de ; Pointer to b$
866+
push hl ; Pointer to a$
867+
ld c, (hl)
868+
inc hl
869+
ld h, (hl)
870+
ld l, c ; HL = (HL)
871+
call __STRASSIGN ; HL (a$) = DE (b$); HL changed to a new dynamic memory allocation
872+
ex de, hl ; DE = new address of a$
873+
pop hl ; Recover variable memory address pointer
874+
ld (hl), e
875+
inc hl
876+
ld (hl), d ; Stores a$ ptr into element ptr
877+
pop hl ; Returns ptr to b$ in HL (Caller might needed to free it from memory)
878+
ret
879+
pop namespace
880880
#line 41 "arch/zx48k/arraycopy5.bas"
881881
END

0 commit comments

Comments
 (0)