Skip to content

Commit b5a6eec

Browse files
authored
Merge pull request #1064 from boriel-basic/fix/fastcall_string_function
fix: Do not insert dummy ld hl, 0 in Fastcall String functions
2 parents 269ac08 + f89b794 commit b5a6eec

3 files changed

Lines changed: 92 additions & 30 deletions

File tree

src/api/optimize.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def visit_FUNCTION(self, node: symbols.ID):
9999
lineno = node.lineno if not node.body else node.body[-1].lineno
100100
errmsg.warning_function_should_return_a_value(lineno, node.name, node.filename)
101101
type_ = node.type_
102-
if type_ is not None and type_ == self.TYPE(TYPE.string):
102+
if type_ is not None and type_ == self.TYPE(TYPE.string) and node.convention != CONVENTION.fastcall:
103103
node.body.append(symbols.ASM("\nld hl, 0\n", lineno, node.filename, is_sentinel=True))
104104

105105
yield self.generic_visit(node)

tests/functional/arch/zx48k/stdlib_hex.asm

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ END_CHAR:
9191
ENDP
9292
pop namespace
9393
#line 91 "/zxbasic/src/lib/arch/zx48k/stdlib/hex.bas"
94-
#line 30 "/zxbasic/src/lib/arch/zx48k/stdlib/hex.bas"
95-
ld hl, 0
96-
#line 33 "/zxbasic/src/lib/arch/zx48k/stdlib/hex.bas"
9794
_hex__leave:
9895
ret
9996
_hex16:
@@ -175,7 +172,7 @@ _hex8__leave:
175172
exx
176173
ret
177174
;; --- end of user code ---
178-
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm"
175+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mem/alloc.asm"
179176
; vim: ts=4:et:sw=4:
180177
; Copyleft (K) by Jose M. Rodriguez de la Rosa
181178
; (a.k.a. Boriel)
@@ -269,8 +266,8 @@ __STOP:
269266
ld (ERR_NR), a
270267
ret
271268
pop namespace
272-
#line 69 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm"
273-
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/heapinit.asm"
269+
#line 69 "/zxbasic/src/lib/arch/zx48k/runtime/mem/alloc.asm"
270+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mem/heapinit.asm"
274271
; vim: ts=4:et:sw=4:
275272
; Copyleft (K) by Jose M. Rodriguez de la Rosa
276273
; (a.k.a. Boriel)
@@ -377,7 +374,7 @@ __MEM_INIT2:
377374
ret
378375
ENDP
379376
pop namespace
380-
#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm"
377+
#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/mem/alloc.asm"
381378
; ---------------------------------------------------------------------
382379
; MEM_ALLOC
383380
; Allocates a block of memory in the heap.
@@ -408,9 +405,9 @@ __MEM_START:
408405
__MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE
409406
ld a, h ; HL = NULL (No memory available?)
410407
or l
411-
#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm"
408+
#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/mem/alloc.asm"
412409
ret z ; NULL
413-
#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/alloc.asm"
410+
#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/mem/alloc.asm"
414411
; HL = Pointer to Free block
415412
ld e, (hl)
416413
inc hl
@@ -475,8 +472,8 @@ __MEM_SUBTRACT:
475472
ret
476473
ENDP
477474
pop namespace
478-
#line 116 "/zxbasic/src/lib/arch/zx48k/stdlib/hex.bas"
479-
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/free.asm"
475+
#line 174 "/zxbasic/src/lib/arch/zx48k/stdlib/hex.bas"
476+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mem/free.asm"
480477
; vim: ts=4:et:sw=4:
481478
; Copyleft (K) by Jose M. Rodriguez de la Rosa
482479
; (a.k.a. Boriel)
@@ -634,7 +631,7 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed
634631
ret
635632
ENDP
636633
pop namespace
637-
#line 117 "/zxbasic/src/lib/arch/zx48k/stdlib/hex.bas"
634+
#line 175 "/zxbasic/src/lib/arch/zx48k/stdlib/hex.bas"
638635
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/pstorestr2.asm"
639636
; vim:ts=4:et:sw=4
640637
;
@@ -683,7 +680,7 @@ __PSTORE_STR2:
683680
add hl, bc
684681
jp __STORE_STR2
685682
pop namespace
686-
#line 118 "/zxbasic/src/lib/arch/zx48k/stdlib/hex.bas"
683+
#line 176 "/zxbasic/src/lib/arch/zx48k/stdlib/hex.bas"
687684
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/strslice.asm"
688685
; String slicing library
689686
; HL = Str pointer
@@ -785,5 +782,5 @@ __FREE_ON_EXIT:
785782
ret
786783
ENDP
787784
pop namespace
788-
#line 119 "/zxbasic/src/lib/arch/zx48k/stdlib/hex.bas"
785+
#line 177 "/zxbasic/src/lib/arch/zx48k/stdlib/hex.bas"
789786
END

tests/functional/arch/zxnext/stdlib_hex.asm

Lines changed: 80 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
ei
3232
ret
3333
_hex:
34-
#line 30 "/zxbasic/src/lib/arch/zxnext/stdlib/hex.bas"
34+
#line 30 "/zxbasic/src/lib/arch/zx48k/stdlib/hex.bas"
3535
push namespace core
3636
PROC
3737
LOCAL SUB_CHAR
@@ -83,10 +83,7 @@ END_CHAR:
8383
ret
8484
ENDP
8585
pop namespace
86-
#line 91 "/zxbasic/src/lib/arch/zxnext/stdlib/hex.bas"
87-
#line 30 "/zxbasic/src/lib/arch/zxnext/stdlib/hex.bas"
88-
ld hl, 0
89-
#line 33 "/zxbasic/src/lib/arch/zxnext/stdlib/hex.bas"
86+
#line 91 "/zxbasic/src/lib/arch/zx48k/stdlib/hex.bas"
9087
_hex__leave:
9188
ret
9289
_hex16:
@@ -169,6 +166,17 @@ _hex8__leave:
169166
ret
170167
;; --- end of user code ---
171168
#line 1 "/zxbasic/src/lib/arch/zxnext/runtime/mem/alloc.asm"
169+
; vim: ts=4:et:sw=4:
170+
; Copyleft (K) by Jose M. Rodriguez de la Rosa
171+
; (a.k.a. Boriel)
172+
; http://www.boriel.com
173+
;
174+
; This ASM library is licensed under the MIT license
175+
; you can use it for any purpose (even for commercial
176+
; closed source programs).
177+
;
178+
; Please read the MIT license on the internet
179+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mem/alloc.asm"
172180
; vim: ts=4:et:sw=4:
173181
; Copyleft (K) by Jose M. Rodriguez de la Rosa
174182
; (a.k.a. Boriel)
@@ -229,6 +237,13 @@ _hex8__leave:
229237
; An init directive is useful for initialization routines.
230238
; They will be added automatically if needed.
231239
#line 1 "/zxbasic/src/lib/arch/zxnext/runtime/error.asm"
240+
; ----------------------------------------------------------------
241+
; This file is released under the MIT License
242+
;
243+
; Copyleft (k) 2008
244+
; by Jose Rodriguez-Rosa (a.k.a. Boriel) <https://www.boriel.com>
245+
; ----------------------------------------------------------------
246+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/error.asm"
232247
; Simple error control routines
233248
; vim:ts=4:et:
234249
push namespace core
@@ -262,8 +277,16 @@ __STOP:
262277
ld (ERR_NR), a
263278
ret
264279
pop namespace
265-
#line 69 "/zxbasic/src/lib/arch/zxnext/runtime/mem/alloc.asm"
280+
#line 9 "/zxbasic/src/lib/arch/zxnext/runtime/error.asm"
281+
#line 69 "/zxbasic/src/lib/arch/zx48k/runtime/mem/alloc.asm"
266282
#line 1 "/zxbasic/src/lib/arch/zxnext/runtime/mem/heapinit.asm"
283+
; ----------------------------------------------------------------
284+
; This file is released under the MIT License
285+
;
286+
; Copyleft (k) 2008
287+
; by Jose Rodriguez-Rosa (a.k.a. Boriel) <https://www.boriel.com>
288+
; ----------------------------------------------------------------
289+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mem/heapinit.asm"
267290
; vim: ts=4:et:sw=4:
268291
; Copyleft (K) by Jose M. Rodriguez de la Rosa
269292
; (a.k.a. Boriel)
@@ -370,7 +393,8 @@ __MEM_INIT2:
370393
ret
371394
ENDP
372395
pop namespace
373-
#line 70 "/zxbasic/src/lib/arch/zxnext/runtime/mem/alloc.asm"
396+
#line 9 "/zxbasic/src/lib/arch/zxnext/runtime/mem/heapinit.asm"
397+
#line 70 "/zxbasic/src/lib/arch/zx48k/runtime/mem/alloc.asm"
374398
; ---------------------------------------------------------------------
375399
; MEM_ALLOC
376400
; Allocates a block of memory in the heap.
@@ -401,9 +425,9 @@ __MEM_START:
401425
__MEM_LOOP: ; Loads lengh at (HL, HL+). If Lenght >= BC, jump to __MEM_DONE
402426
ld a, h ; HL = NULL (No memory available?)
403427
or l
404-
#line 113 "/zxbasic/src/lib/arch/zxnext/runtime/mem/alloc.asm"
428+
#line 113 "/zxbasic/src/lib/arch/zx48k/runtime/mem/alloc.asm"
405429
ret z ; NULL
406-
#line 115 "/zxbasic/src/lib/arch/zxnext/runtime/mem/alloc.asm"
430+
#line 115 "/zxbasic/src/lib/arch/zx48k/runtime/mem/alloc.asm"
407431
; HL = Pointer to Free block
408432
ld e, (hl)
409433
inc hl
@@ -468,8 +492,16 @@ __MEM_SUBTRACT:
468492
ret
469493
ENDP
470494
pop namespace
471-
#line 116 "/zxbasic/src/lib/arch/zxnext/stdlib/hex.bas"
495+
#line 13 "/zxbasic/src/lib/arch/zxnext/runtime/mem/alloc.asm"
496+
#line 174 "/zxbasic/src/lib/arch/zx48k/stdlib/hex.bas"
472497
#line 1 "/zxbasic/src/lib/arch/zxnext/runtime/mem/free.asm"
498+
; ----------------------------------------------------------------
499+
; This file is released under the MIT License
500+
;
501+
; Copyleft (k) 2008
502+
; by Jose Rodriguez-Rosa (a.k.a. Boriel) <https://www.boriel.com>
503+
; ----------------------------------------------------------------
504+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/mem/free.asm"
473505
; vim: ts=4:et:sw=4:
474506
; Copyleft (K) by Jose M. Rodriguez de la Rosa
475507
; (a.k.a. Boriel)
@@ -627,15 +659,30 @@ __MEM_BLOCK_JOIN: ; Joins current block (pointed by HL) with next one (pointed
627659
ret
628660
ENDP
629661
pop namespace
630-
#line 117 "/zxbasic/src/lib/arch/zxnext/stdlib/hex.bas"
662+
#line 9 "/zxbasic/src/lib/arch/zxnext/runtime/mem/free.asm"
663+
#line 175 "/zxbasic/src/lib/arch/zx48k/stdlib/hex.bas"
631664
#line 1 "/zxbasic/src/lib/arch/zxnext/runtime/pstorestr2.asm"
665+
; ----------------------------------------------------------------
666+
; This file is released under the MIT License
667+
;
668+
; Copyleft (k) 2008
669+
; by Jose Rodriguez-Rosa (a.k.a. Boriel) <https://www.boriel.com>
670+
; ----------------------------------------------------------------
671+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/pstorestr2.asm"
632672
; vim:ts=4:et:sw=4
633673
;
634674
; Stores an string (pointer to the HEAP by DE) into the address pointed
635675
; by (IX + BC). No new copy of the string is created into the HEAP, since
636676
; it's supposed it's already created (temporary string)
637677
;
638678
#line 1 "/zxbasic/src/lib/arch/zxnext/runtime/storestr2.asm"
679+
; ----------------------------------------------------------------
680+
; This file is released under the MIT License
681+
;
682+
; Copyleft (k) 2008
683+
; by Jose Rodriguez-Rosa (a.k.a. Boriel) <https://www.boriel.com>
684+
; ----------------------------------------------------------------
685+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/storestr2.asm"
639686
; Similar to __STORE_STR, but this one is called when
640687
; the value of B$ if already duplicated onto the stack.
641688
; So we needn't call STRASSING to create a duplication
@@ -668,16 +715,25 @@ __STORE_STR2:
668715
dec hl ; HL points to mem address variable. This might be useful in the future.
669716
ret
670717
pop namespace
671-
#line 9 "/zxbasic/src/lib/arch/zxnext/runtime/pstorestr2.asm"
718+
#line 9 "/zxbasic/src/lib/arch/zxnext/runtime/storestr2.asm"
719+
#line 9 "/zxbasic/src/lib/arch/zx48k/runtime/pstorestr2.asm"
672720
push namespace core
673721
__PSTORE_STR2:
674722
push ix
675723
pop hl
676724
add hl, bc
677725
jp __STORE_STR2
678726
pop namespace
679-
#line 118 "/zxbasic/src/lib/arch/zxnext/stdlib/hex.bas"
727+
#line 9 "/zxbasic/src/lib/arch/zxnext/runtime/pstorestr2.asm"
728+
#line 176 "/zxbasic/src/lib/arch/zx48k/stdlib/hex.bas"
680729
#line 1 "/zxbasic/src/lib/arch/zxnext/runtime/strslice.asm"
730+
; ----------------------------------------------------------------
731+
; This file is released under the MIT License
732+
;
733+
; Copyleft (k) 2008
734+
; by Jose Rodriguez-Rosa (a.k.a. Boriel) <https://www.boriel.com>
735+
; ----------------------------------------------------------------
736+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/strslice.asm"
681737
; String slicing library
682738
; HL = Str pointer
683739
; DE = String start
@@ -692,6 +748,13 @@ __PSTORE_STR2:
692748
; string. NULL (0) if no memory for padding.
693749
;
694750
#line 1 "/zxbasic/src/lib/arch/zxnext/runtime/strlen.asm"
751+
; ----------------------------------------------------------------
752+
; This file is released under the MIT License
753+
;
754+
; Copyleft (k) 2008
755+
; by Jose Rodriguez-Rosa (a.k.a. Boriel) <https://www.boriel.com>
756+
; ----------------------------------------------------------------
757+
#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/strlen.asm"
695758
; Returns len if a string
696759
; If a string is NULL, its len is also 0
697760
; Result returned in HL
@@ -706,7 +769,8 @@ __STRLEN: ; Direct FASTCALL entry
706769
ld l, a
707770
ret
708771
pop namespace
709-
#line 18 "/zxbasic/src/lib/arch/zxnext/runtime/strslice.asm"
772+
#line 9 "/zxbasic/src/lib/arch/zxnext/runtime/strlen.asm"
773+
#line 18 "/zxbasic/src/lib/arch/zx48k/runtime/strslice.asm"
710774
push namespace core
711775
__STRSLICE: ; Callee entry
712776
pop hl ; Return ADDRESS
@@ -778,5 +842,6 @@ __FREE_ON_EXIT:
778842
ret
779843
ENDP
780844
pop namespace
781-
#line 119 "/zxbasic/src/lib/arch/zxnext/stdlib/hex.bas"
845+
#line 9 "/zxbasic/src/lib/arch/zxnext/runtime/strslice.asm"
846+
#line 177 "/zxbasic/src/lib/arch/zx48k/stdlib/hex.bas"
782847
END

0 commit comments

Comments
 (0)