1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;; UrForth level
1: self
-hosting
32-bit Forth compiler
3 ;; Copyright
(C
) 2020 Ketmar Dark
// Invisible Vector
5 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7 code: NULLSTRING ( addr 0 -- )
12 nullstring_data
: dw
0,0
16 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17 ;; length of asciiz string
18 code: ZCOUNT ( addr -- addr count )
36 : zcount
-only
( addr
-- count
)
41 alias @ COUNT
-ONLY
( addr
-- count
)
43 code: COUNT ( addr -- addr+4 count )
44 ;;UF dup count_only swap cellinc swap exit
53 alias W@ WCOUNT
-ONLY
( addr
-- count
)
55 code: WCOUNT ( addr -- addr+2 count )
63 alias C@ CCOUNT
-ONLY
( addr
-- count
)
64 alias C@ BCOUNT
-ONLY
( addr
-- count
)
66 code: CCOUNT ( addr -- addr+1 count )
77 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
78 ;; adjust the
character string at c
-addr1 by n characters
.
79 ;; the resulting
character string
, specified by c
-addr2 u2
,
80 ;; begins at c
-addr1 plus n characters and is u1 minus n characters long
.
81 ;; doesn
't check length, allows negative n.
82 : /STRING ( c-addr1 u1 n -- c-addr2 u2 )
83 dup >r - swap r> + swap
86 ;; checks length, doesn't strip anything from an empty string
87 : /CHAR
( c
-addr1 u1
-- c
-addr
+1 u1
-1 )
88 1- dup
-if drop
0 else swap
1+ swap
endif
91 ;; checks length
, doesn
't strip anything from an empty string
92 : /2CHARS ( c-addr1 u1 -- c-addr+2 u1-2 )
93 2- dup -if drop 0 else swap 2+ swap endif
97 ;; if n1 is greater than zero, n2 is equal to n1 less the number of
98 ;; spaces at the end of the character string specified by c-addr n1.
99 ;; if n1 is zero or the entire string consists of spaces, n2 is zero.
100 : -TRAILING ( c-addr n1 -- c-addr n2 )
101 0 max begin dup while 2dup + 1- c@ bl <= while 1- repeat
104 ;; strips leading blanks
105 : -LEADING ( c-addr1 n1 -- c-addr2 n2 )
106 0 max begin dup while over c@ bl <= while /char repeat
110 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
111 ;; converts some escape codes in-place
112 ;; used for `."` and `"`
113 ;; the resulting string is never bigger than a source one
114 ;; this will not preserve the trailing zero byte
115 code: STR-UNESCAPE ( addr count -- addr count )
125 ;; edi is after backslash
126 ;; ecx is number of chars left after backslash
127 ;; found backslash, check next char
130 or ah,32 ;; lowercase it
167 ;; '\`
'? (double quote)
208 movzx eax,byte [edi+1]
211 ;; save original string position
230 ;; combine two hex digits
240 ;; remove leftover chars
242 ;; ESI: position after backslash
243 ;; EDI: rest position
244 ;; old ESI is on the stack
245 push esi ;; to be restored in EDI
250 pop edi ;; get back to backslash
251 pop esi ;; restore old ESI
269 ;; maybe its lowercase?