-
Notifications
You must be signed in to change notification settings - Fork 5
/
block-003.fth
55 lines (44 loc) · 1.46 KB
/
block-003.fth
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
\ block-003 - some string words
' LEX-STRING loaded?
LEX-C3 : LEX-STRING 3 LEX! ;
LEX-STRING
\ Some temp buffers
: pad1 VHERE 256 + ;
: pad2 pad1 256 + ;
: pad3 pad2 256 + ;
\ Words for NULL-Terminated strings
: S-CATN ( str num -- ) ITOA S-CAT ; INLINE
: S-SCATN ( num str -- ) SWAP S-CATN ; INLINE
: S-SCPY ( src dst -- ) SWAP S-CPY ; INLINE
: S-SCAT ( src dst -- ) SWAP S-CAT ; INLINE
: S-SCATC ( ch dst -- ) SWAP S-CATC ; INLINE
: S-END ( str -- end ) DUP S-LEN + ; INLINE
: FILL ( DST NUM CH-- ) >R 0 DO R@ OVER C! 1+ LOOP R> 2DROP ;
: CMOVE ( SRC DST NUM -- )
+REGS s3 s2 s1
r3 0 DO r1+ C@ r2+ C! LOOP
-REGS ;
: CMOVE> ( SRC DST NUM-- )
+REGS s3 r3 1- + s2 r3 1- + s1
r3 0 DO r1- C@ r2- C! LOOP
-REGS ;
: S-CPYLEN ( DST SRC LEN -- ) \ Copy LEN bytes from SRC to DST
>R SWAP R> CMOVE ;
: S-CATLEN ( DST SRC LEN -- ) \ Concat LEN bytes from SRC to DST
>R >R S-END R> R> S-CPYLEN ;
: S-FIND ( LF STR -- ADDR|0 ) \ Look for string LF in STR
\ Returns 0 if not found, else the address in STR
+regs s2 s1
r1 C@ s6 r1 S-LEN s3
BEGIN
r6 r2 S-FINDC DUP s2 0= IF 0 -EXIT THEN
r1 r2 r3 S-EQN IF r2 -EXIT THEN
i2
AGAIN ;
\ Words for Counted strings
: COUNT ( sc -- a n ) 1+ DUP 1- C@ ; INLINE
: sc-len ( str -- len ) C@ ; INLINE
: sc->sz ( sc sz -- ) SWAP 1+ S-CPY ; INLINE
: sz->sc ( sz sc -- ) +REGS s2 s1
r1 S-LEN r2+ C! r2 r1 S-CPY
-REGS ;