1 \ ** ficl/softwords/softcore.fr
2 \ ** FICL soft extensions
3 \ ** John Sadler (john_sadler@alum.mit.edu)
8 \ EMPTY cleans the parameter stack
9 : empty ( xn..x1 -- ) depth 0 ?do drop loop ;
11 : cell- ( addr -- addr ) [ 1 cells ] literal - ;
12 : -rot ( a b c -- c a b ) 2 -roll ;
16 dup 0< if negate endif ;
17 decimal 32 constant bl
19 : space ( -- ) bl emit ;
21 : spaces ( n -- ) 0 ?do space loop ;
45 .( loading CORE EXT words ) cr
47 false invert constant true
51 : convert char+ 65535 >number drop ; \ cribbed from DPANS A.6.2.0970
52 : erase ( addr u -- ) 0 fill ;
54 : expect ( c-addr u1 -- ) accept span ! ;
55 \ see marker.fr for MARKER implementation
56 : nip ( y x -- x ) swap drop ;
57 : tuck ( y x -- x y x) swap over ;
58 : within ( test low high -- flag ) over - >r - r> u< ;
60 : dnegate ( d -- -d ) invert swap negate tuck 0= - ;
61 : dabs ( d -- ud ) dup 0< if dnegate endif ;
64 swap dup abs 0 <# #s rot sign #>
78 swap over dabs <# #s rot sign #> type space ;
81 -rot swap over dabs <# #s rot sign #>
91 -rot <# #s #> rot over - dup 0< if drop else spaces then type space ;
93 : d>s ( d -- n ) drop ;
95 : d0= ( d -- flag ) or 0= ;
96 : d= ( d1 d2 -- flag ) rot = -rot = and ;
97 : d0< ( d -- f ) nip 0< ;
99 : d< ( d1 d2 -- flag )
113 : dmax ( d1 d2 -- d3 )
121 : dmin ( d1 d2 -- d3 )
131 : d+ ( d1 d2 -- d3 ) rot + >r tuck + tuck swap u< r> swap - ;
132 : d- ( d1 d2 -- d3 ) dnegate d+ ;
133 : d2* ( d1 -- d2 ) 2dup d+ ;
135 dup 1 and >r 2/ swap 2/ [ 1 8 cells 1- lshift 1- ] literal and
137 [ 1 8 cells 1- lshift ] literal +
142 : m+ ( d1 +n -- d2 ) s>d d+ ;
144 \ ** TOOLS word set...
145 : ? ( addr -- ) @ . ;
149 : i' ( R:w R:w2 -- R:w R:w2 w )
150 r> r> r> dup >r swap >r swap >r ;
152 : .4 ( addr -- addr' )
153 4 0 DO -1 /dump +! /dump @ 0<
154 IF 3 spaces ELSE dup c@ 0 <# # # #> type space THEN
159 ?DO I c@ dup 127 bl within
160 IF drop [char] . THEN emit
164 dup .4 space .4 ." - " .4 space .4 drop 16 /dump +! space .chars ;
166 : dump ( addr u -- ) \ tools dump
167 cr base @ >r hex \ save base on return stack
168 0 ?DO I' I - 16 min /dump !
169 dup 8 u.r ." : " dup .line cr 16 +
173 \ ** SEARCH+EXT words and ficl helpers
174 .( loading SEARCH & SEARCH-EXT words ) cr
175 \ BRAND-WORDLIST is a helper for ficl-named-wordlist. Usage idiom:
176 \ wordlist dup create , brand-wordlist
177 \ gets the name of the word made by create and applies it to the wordlist...
178 : brand-wordlist ( wid -- ) last-word >name drop wid-set-name ;
180 : ficl-named-wordlist \ ( hash-size name -- ) run: ( -- wid )
181 ficl-wordlist dup create , brand-wordlist does> @ ;
186 \ FICL-SET-CURRENT sets the compile wordlist and pushes the previous value
187 : ficl-set-current ( wid -- old-wid )
188 get-current swap set-current ;
190 \ DO_VOCABULARY handles the DOES> part of a VOCABULARY
191 \ When executed, new voc replaces top of search stack
192 : do-vocabulary ( -- )
193 does> @ search> drop >search ;
195 : ficl-vocabulary ( nBuckets name -- )
196 ficl-named-wordlist do-vocabulary ;
198 : vocabulary ( name -- )
201 \ PREVIOUS drops the search order stack
202 : previous ( -- ) search> drop ;
204 \ HIDDEN vocabulary is a place to keep helper words from cluttering the namespace
207 \ <definitions to hide>
209 \ <words that use hidden defs>
210 \ previous ( pop HIDDEN off the search order )
212 1 ficl-named-wordlist hidden
213 : hide hidden dup >search ficl-set-current ;
215 \ ALSO dups the search stack...
217 search> dup >search >search ;
219 \ FORTH drops the top of the search stack and pushes FORTH-WORDLIST
222 forth-wordlist >search ;
224 \ ONLY sets the search order to a default state
228 \ ORDER displays the compile wid and the search order list
230 : list-wid ( wid -- )
231 dup wid-get-name ( wid c-addr u )
235 drop ." (unnamed wid) " x.
238 set-current \ stop hiding words
242 get-order 0 ?do 3 spaces list-wid loop cr
243 ." Compile: " get-current list-wid cr
246 : debug ' debug-xt ; immediate
247 : on-step ." S: " .s-simple cr ;
250 previous \ lose hidden words from search order
252 \ ** E N D S O F T C O R E . F R