softcore.fr revision 43078
1\ ** ficl/softwords/softcore.fr 2\ ** FICL soft extensions 3\ ** John Sadler (john_sadler@alum.mit.edu) 4\ ** September, 1998 5 6\ ** Ficl USER variables 7\ ** See words.c for primitive def'n of USER 8\ #if FICL_WANT_USER 9 10variable nUser 0 nUser ! 11: user \ name ( -- ) 12 nUser dup @ user 1 swap +! ; 13 14\ #endif 15 16\ ** ficl extras 17\ EMPTY cleans the parameter stack 18: empty ( xn..x1 -- ) depth 0 ?do drop loop ; 19\ CELL- undoes CELL+ 20: cell- ( addr -- addr ) [ 1 cells ] literal - ; 21: -rot ( a b c -- c a b ) 2 -roll ; 22 23\ ** CORE 24: abs ( x -- x ) 25 dup 0< if negate endif ; 26decimal 32 constant bl 27 28: space ( -- ) bl emit ; 29 30: spaces ( n -- ) 0 ?do space loop ; 31 32: abort" 33 postpone if 34 postpone ." 35 postpone cr 36 -2 37 postpone literal 38 postpone throw 39 postpone endif 40; immediate 41 42 43\ ** CORE EXT 440 constant false 45-1 constant true 46: <> = invert ; 47: 0<> 0= invert ; 48: compile, , ; 49: erase ( addr u -- ) 0 fill ; 50: nip ( y x -- x ) swap drop ; 51: tuck ( y x -- x y x) swap over ; 52 53\ ** LOCAL EXT word set 54\ #if FICL_WANT_LOCALS 55: locals| ( name...name | -- ) 56 begin 57 bl word count 58 dup 0= abort" where's the delimiter??" 59 over c@ 60 [char] | - over 1- or 61 while 62 (local) 63 repeat 2drop 0 0 (local) 64; immediate 65 66: local ( name -- ) bl word count (local) ; immediate 67 68: end-locals ( -- ) 0 0 (local) ; immediate 69 70\ #endif 71 72\ ** TOOLS word set... 73: ? ( addr -- ) @ . ; 74: dump ( addr u -- ) 75 0 ?do 76 dup c@ . 1+ 77 i 7 and 7 = if cr endif 78 loop drop 79; 80 81\ ** SEARCH+EXT words and ficl helpers 82\ 83: wordlist ( -- ) 84 1 ficl-wordlist ; 85 86\ DO_VOCABULARY handles the DOES> part of a VOCABULARY 87\ When executed, new voc replaces top of search stack 88: do-vocabulary ( -- ) 89 does> @ search> drop >search ; 90 91: vocabulary ( name -- ) 92 wordlist create , do-vocabulary ; 93 94: ficl-vocabulary ( nBuckets name -- ) 95 ficl-wordlist create , do-vocabulary ; 96 97\ ALSO dups the search stack... 98: also ( -- ) 99 search> dup >search >search ; 100 101\ FORTH drops the top of the search stack and pushes FORTH-WORDLIST 102: forth ( -- ) 103 search> drop 104 forth-wordlist >search ; 105 106\ ONLY sets the search order to a default state 107: only ( -- ) 108 -1 set-order ; 109 110\ ORDER displays the compile wid and the search order list 111: order ( -- ) 112 ." Search: " 113 get-order 0 ?do x. loop cr 114 ." Compile: " get-current x. cr ; 115 116\ PREVIOUS drops the search order stack 117: previous ( -- ) search> drop ; 118 119\ FICL-SET-CURRENT sets the compile wordlist and pushes the previous value 120: ficl-set-current ( wid -- old-wid ) 121 get-current swap set-current ; 122 123wordlist constant hidden 124: hide hidden dup >search ficl-set-current ; 125 126\ ** E N D S O F T C O R E . F R 127 128