Browse code

Extracted string library from asma

Andrew Alderwick authored on 06/10/2021 05:54:03
Showing 3 changed files
... ...
@@ -54,20 +54,3 @@ found:
54 54
 	STH2r ADD2 ( incoming-ptr* / search-key* )
55 55
 	,&loop JMP
56 56
 
57
-@strcmp ( a* b* -- a-end* b-end* order nonzero if strings differ
58
-                OR a-end* b-end* 00    00      if strings match )
59
-	STH2
60
-	,&entry JMP
61
-
62
-	&loop ( a* a b / b* )
63
-	SUB ,&nomatch JCNk ( a* a-b nonzero / b* )
64
-	POP2 ( a* / b* )
65
-	INC2 INC2r
66
-	&entry ( a* / b* )
67
-	LDAk LDAkr STHr ( a* a b / b* )
68
-	ORAk ,&loop JCN
69
-
70
-	&nomatch ( a* a-b flag / b* )
71
-	STH2r SWP2 ( a* b* a-b flag )
72
-	JMP2r
73
-
74 57
new file mode 100644
... ...
@@ -0,0 +1,28 @@
1
+@strcmp ( a* b* -- a-end* b-end* order nonzero if strings differ
2
+                OR a-end* b-end* 00    00      if strings match )
3
+	STH2
4
+	,&entry JMP
5
+
6
+	&loop ( a* a b / b* )
7
+	SUB ,&nomatch JCNk ( a* a-b nonzero / b* )
8
+	POP2 ( a* / b* )
9
+	INC2 INC2r
10
+	&entry ( a* / b* )
11
+	LDAk LDAkr STHr ( a* a b / b* )
12
+	ORAk ,&loop JCN
13
+
14
+	&nomatch ( a* a-b flag / b* )
15
+	STH2r SWP2 ( a* b* a-b flag )
16
+	JMP2r
17
+
18
+@strlen ( string-ptr* -- length^ )
19
+	LIT2r 0000
20
+	,&entry JMP
21
+
22
+	&loop
23
+	INC2 INC2r
24
+	&entry
25
+	LDAk ,&loop JCN
26
+	POP2 STH2r
27
+	JMP2r
28
+
... ...
@@ -423,7 +423,7 @@ include projects/library/file-read-chunks.tal
423 423
 @asma-parse-hex-string ( -- value* 06 if valid hex and length > 2
424 424
                          OR value* 03 if valid hex and length <= 2
425 425
                          OR 00 otherwise )
426
-	;asma/token LDA2 DUP2 ,asma-strlen JSR #02 GTH ROT ROT
426
+	;asma/token LDA2 DUP2 ,strlen JSR #0002 GTH2 ROT ROT
427 427
 	LIT2r 0000
428 428
 
429 429
 	&loop
... ...
@@ -446,28 +446,22 @@ include projects/library/file-read-chunks.tal
446 446
 	DUP EOR
447 447
 	JMP2r
448 448
 
449
-@asma-strlen ( string-ptr* -- length )
450
-	LITr 00
451
-
452
-	&loop
453
-	LDAk
454
-	,&not-end JCN
455
-	POP2 STHr
456
-	JMP2r
457
-
458
-	&not-end
459
-	LITr 01 ADDr
460
-	INC2
461
-	,&loop JMP
462
-
463 449
 %asma-SHORT-FLAG { #20 }
464 450
 %asma-RETURN-FLAG { #40 }
465 451
 %asma-KEEP-FLAG { #80 }
466 452
 
453
+@asma-traverse-tree ( incoming-ptr* -- binary-ptr* 00 if key found
454
+                                    OR node-incoming-ptr* 01 if key not found )
455
+	;asma/token LDA2
456
+	( fall through to traverse-tree )
457
+
458
+include projects/library/binary-tree.tal
459
+include projects/library/string.tal
460
+
467 461
 @asma-parse-opcode ( -- byte 00 if valid opcode
468 462
                      OR 01 otherwise )
469 463
 	;asma/token LDA2
470
-	DUP2 ,asma-strlen JSR #03 LTH ,&too-short JCN
464
+	DUP2 ,strlen JSR #0003 LTH2 ,&too-short JCN
471 465
 
472 466
 	( truncate to three chars long )
473 467
 	#0003 ADD2 ( end* / )
... ...
@@ -561,13 +555,6 @@ include projects/library/file-read-chunks.tal
561 555
 
562 556
 include projects/library/heap.tal
563 557
 
564
-@asma-traverse-tree ( incoming-ptr* -- binary-ptr* 00 if key found
565
-                                    OR node-incoming-ptr* 01 if key not found )
566
-	;asma/token LDA2
567
-	( fall through to traverse-tree )
568
-
569
-include projects/library/binary-tree.tal
570
-
571 558
 (
572 559
 	First character routines.
573 560
 	The following routines (that don't have a FORTH-like signature) are called
... ...
@@ -817,7 +804,7 @@ include projects/library/binary-tree.tal
817 804
 	JMP2r
818 805
 
819 806
 	&keep-going
820
-	DUP2k ;asma-strlen JSR2 #00 SWP INC2 ADD2
807
+	DUP2k ;strlen JSR2 INC2 ADD2
821 808
 	SWP2 ;asma-assemble-token JSR2 asma-IF-ERROR ,&error JCN
822 809
 	,&macro-loop JMP
823 810