1 \ ** ficl/softwords/softcore.fr
2 \ ** FICL soft extensions
3 \ ** John Sadler (john_sadler@alum.mit.edu)
6 \ $FreeBSD: src/sys/boot/ficl/softwords/softcore.fr,v 1.12 2002/04/09 17:45:28 dcs Exp $
7 \ $DragonFly: src/sys/boot/ficl/softwords/softcore.fr,v 1.3 2003/11/10 06:08:34 dillon Exp $
9 \ ** Ficl USER variables
10 \ ** See words.c for primitive def'n of USER
12 variable nUser 0 nUser !
14 nUser dup @ user 1 swap +! ;
19 \ EMPTY cleans the parameter stack
20 : empty ( xn..x1 -- ) depth 0 ?do drop loop ;
22 : cell- ( addr -- addr ) [ 1 cells ] literal - ;
23 : -rot ( a b c -- c a b ) 2 -roll ;
27 dup 0< if negate endif ;
28 decimal 32 constant bl
30 : space ( -- ) bl emit ;
32 : spaces ( n -- ) 0 ?do space loop ;
58 false invert constant true
62 : convert char+ 65535 >number drop ; \ cribbed from DPANS A.6.2.0970
63 : erase ( addr u -- ) 0 fill ;
65 : expect ( c-addr u1 -- ) accept span ! ;
66 \ see marker.fr for MARKER implementation
67 : nip ( y x -- x ) swap drop ;
68 : tuck ( y x -- x y x) swap over ;
69 : within ( test low high -- flag ) over - >r - r> u< ;
72 \ ** LOCAL EXT word set
73 \ #if FICL_WANT_LOCALS
74 : locals| ( name...name | -- )
77 dup 0= abort" where's the delimiter??"
82 repeat 2drop 0 0 (local)
85 : local ( name -- ) bl word count (local) ; immediate
87 : 2local ( name -- ) bl word count (2local) ; immediate
89 : end-locals ( -- ) 0 0 (local) ; immediate
93 \ ** TOOLS word set...
98 i 7 and 7 = if cr endif
102 \ ** SEARCH+EXT words and ficl helpers
103 \ BRAND-WORDLIST is a helper for ficl-named-wordlist. Usage idiom:
104 \ wordlist dup create , brand-wordlist
105 \ gets the name of the word made by create and applies it to the wordlist...
106 : brand-wordlist ( wid -- ) last-word >name drop wid-set-name ;
108 : ficl-named-wordlist \ ( hash-size name -- ) run: ( -- wid )
109 ficl-wordlist dup create , brand-wordlist does> @ ;
114 \ FICL-SET-CURRENT sets the compile wordlist and pushes the previous value
115 : ficl-set-current ( wid -- old-wid )
116 get-current swap set-current ;
118 \ DO_VOCABULARY handles the DOES> part of a VOCABULARY
119 \ When executed, new voc replaces top of search stack
120 : do-vocabulary ( -- )
121 does> @ search> drop >search ;
123 : ficl-vocabulary ( nBuckets name -- )
124 ficl-named-wordlist do-vocabulary ;
126 : vocabulary ( name -- )
129 \ PREVIOUS drops the search order stack
130 : previous ( -- ) search> drop ;
132 \ HIDDEN vocabulary is a place to keep helper words from cluttering the namespace
135 \ <definitions to hide>
137 \ <words that use hidden defs>
138 \ previous ( pop HIDDEN off the search order )
140 1 ficl-named-wordlist hidden
141 : hide hidden dup >search ficl-set-current ;
143 \ ALSO dups the search stack...
145 search> dup >search >search ;
147 \ FORTH drops the top of the search stack and pushes FORTH-WORDLIST
150 forth-wordlist >search ;
152 \ ONLY sets the search order to a default state
156 \ ORDER displays the compile wid and the search order list
158 : list-wid ( wid -- )
159 dup wid-get-name ( wid c-addr u )
163 drop ." (unnamed wid) " x.
166 set-current \ stop hiding words
170 get-order 0 ?do 3 spaces list-wid loop cr
171 ." Compile: " get-current list-wid cr
174 : debug ' debug-xt ; immediate
175 : on-step ." S: " .s cr ;
179 : strdup ( c-addr length -- c-addr2 length2 ior )
180 0 locals| addr2 length c-addr | end-locals
184 c-addr addr2 length move
191 : strcat ( 2:a 2:b -- 2:new-a )
192 0 locals| b-length b-u b-addr a-u a-addr | end-locals
194 b-addr a-addr a-u + b-length move
195 a-addr a-u b-length +
198 : strcpy ( 2:a 2:b -- 2:new-a )
199 locals| b-u b-addr a-u a-addr | end-locals
200 a-addr 0 b-addr b-u strcat
204 previous \ lose hidden words from search order
206 \ ** E N D S O F T C O R E . F R