PageRenderTime 49ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/freebsd5/sys/boot/ficl/softwords/softcore.fr

https://github.com/kame/kame
Forth | 206 lines | 166 code | 40 blank | 0 comment | 7 complexity | 3d4bec6b3c9b50f909e9dd26e13c083c MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-2.0
  1. \ ** ficl/softwords/softcore.fr
  2. \ ** FICL soft extensions
  3. \ ** John Sadler (john_sadler@alum.mit.edu)
  4. \ ** September, 1998
  5. \
  6. \ $FreeBSD: src/sys/boot/ficl/softwords/softcore.fr,v 1.12 2002/04/09 17:45:28 dcs Exp $
  7. \ ** Ficl USER variables
  8. \ ** See words.c for primitive def'n of USER
  9. \ #if FICL_WANT_USER
  10. variable nUser 0 nUser !
  11. : user \ name ( -- )
  12. nUser dup @ user 1 swap +! ;
  13. \ #endif
  14. \ ** ficl extras
  15. \ EMPTY cleans the parameter stack
  16. : empty ( xn..x1 -- ) depth 0 ?do drop loop ;
  17. \ CELL- undoes CELL+
  18. : cell- ( addr -- addr ) [ 1 cells ] literal - ;
  19. : -rot ( a b c -- c a b ) 2 -roll ;
  20. \ ** CORE
  21. : abs ( x -- x )
  22. dup 0< if negate endif ;
  23. decimal 32 constant bl
  24. : space ( -- ) bl emit ;
  25. : spaces ( n -- ) 0 ?do space loop ;
  26. : abort"
  27. state @ if
  28. postpone if
  29. postpone ."
  30. postpone cr
  31. -2
  32. postpone literal
  33. postpone throw
  34. postpone endif
  35. else
  36. [char] " parse
  37. rot if
  38. type
  39. cr
  40. -2 throw
  41. else
  42. 2drop
  43. endif
  44. endif
  45. ; immediate
  46. \ ** CORE EXT
  47. 0 constant false
  48. false invert constant true
  49. : <> = 0= ;
  50. : 0<> 0= 0= ;
  51. : compile, , ;
  52. : convert char+ 65535 >number drop ; \ cribbed from DPANS A.6.2.0970
  53. : erase ( addr u -- ) 0 fill ;
  54. variable span
  55. : expect ( c-addr u1 -- ) accept span ! ;
  56. \ see marker.fr for MARKER implementation
  57. : nip ( y x -- x ) swap drop ;
  58. : tuck ( y x -- x y x) swap over ;
  59. : within ( test low high -- flag ) over - >r - r> u< ;
  60. \ ** LOCAL EXT word set
  61. \ #if FICL_WANT_LOCALS
  62. : locals| ( name...name | -- )
  63. begin
  64. bl word count
  65. dup 0= abort" where's the delimiter??"
  66. over c@
  67. [char] | - over 1- or
  68. while
  69. (local)
  70. repeat 2drop 0 0 (local)
  71. ; immediate
  72. : local ( name -- ) bl word count (local) ; immediate
  73. : 2local ( name -- ) bl word count (2local) ; immediate
  74. : end-locals ( -- ) 0 0 (local) ; immediate
  75. \ #endif
  76. \ ** TOOLS word set...
  77. : ? ( addr -- ) @ . ;
  78. : dump ( addr u -- )
  79. 0 ?do
  80. dup c@ . 1+
  81. i 7 and 7 = if cr endif
  82. loop drop
  83. ;
  84. \ ** SEARCH+EXT words and ficl helpers
  85. \ BRAND-WORDLIST is a helper for ficl-named-wordlist. Usage idiom:
  86. \ wordlist dup create , brand-wordlist
  87. \ gets the name of the word made by create and applies it to the wordlist...
  88. : brand-wordlist ( wid -- ) last-word >name drop wid-set-name ;
  89. : ficl-named-wordlist \ ( hash-size name -- ) run: ( -- wid )
  90. ficl-wordlist dup create , brand-wordlist does> @ ;
  91. : wordlist ( -- )
  92. 1 ficl-wordlist ;
  93. \ FICL-SET-CURRENT sets the compile wordlist and pushes the previous value
  94. : ficl-set-current ( wid -- old-wid )
  95. get-current swap set-current ;
  96. \ DO_VOCABULARY handles the DOES> part of a VOCABULARY
  97. \ When executed, new voc replaces top of search stack
  98. : do-vocabulary ( -- )
  99. does> @ search> drop >search ;
  100. : ficl-vocabulary ( nBuckets name -- )
  101. ficl-named-wordlist do-vocabulary ;
  102. : vocabulary ( name -- )
  103. 1 ficl-vocabulary ;
  104. \ PREVIOUS drops the search order stack
  105. : previous ( -- ) search> drop ;
  106. \ HIDDEN vocabulary is a place to keep helper words from cluttering the namespace
  107. \ USAGE:
  108. \ hide
  109. \ <definitions to hide>
  110. \ set-current
  111. \ <words that use hidden defs>
  112. \ previous ( pop HIDDEN off the search order )
  113. 1 ficl-named-wordlist hidden
  114. : hide hidden dup >search ficl-set-current ;
  115. \ ALSO dups the search stack...
  116. : also ( -- )
  117. search> dup >search >search ;
  118. \ FORTH drops the top of the search stack and pushes FORTH-WORDLIST
  119. : forth ( -- )
  120. search> drop
  121. forth-wordlist >search ;
  122. \ ONLY sets the search order to a default state
  123. : only ( -- )
  124. -1 set-order ;
  125. \ ORDER displays the compile wid and the search order list
  126. hide
  127. : list-wid ( wid -- )
  128. dup wid-get-name ( wid c-addr u )
  129. ?dup if
  130. type drop
  131. else
  132. drop ." (unnamed wid) " x.
  133. endif cr
  134. ;
  135. set-current \ stop hiding words
  136. : order ( -- )
  137. ." Search:" cr
  138. get-order 0 ?do 3 spaces list-wid loop cr
  139. ." Compile: " get-current list-wid cr
  140. ;
  141. : debug ' debug-xt ; immediate
  142. : on-step ." S: " .s cr ;
  143. \ Submitted by lch.
  144. : strdup ( c-addr length -- c-addr2 length2 ior )
  145. 0 locals| addr2 length c-addr | end-locals
  146. length 1 + allocate
  147. 0= if
  148. to addr2
  149. c-addr addr2 length move
  150. addr2 length 0
  151. else
  152. 0 -1
  153. endif
  154. ;
  155. : strcat ( 2:a 2:b -- 2:new-a )
  156. 0 locals| b-length b-u b-addr a-u a-addr | end-locals
  157. b-u to b-length
  158. b-addr a-addr a-u + b-length move
  159. a-addr a-u b-length +
  160. ;
  161. : strcpy ( 2:a 2:b -- 2:new-a )
  162. locals| b-u b-addr a-u a-addr | end-locals
  163. a-addr 0 b-addr b-u strcat
  164. ;
  165. previous \ lose hidden words from search order
  166. \ ** E N D S O F T C O R E . F R