Hash :
1a08f436
Author :
Date :
2010-08-25T09:23:17
change to well-formed svn directory structure. git-svn-id: svn://coreboot.org/openboot/trunk@2 4486e004-3823-0410-90c7-fb508cc143bb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
\ voccom.fth 3.15 02/05/02
\ Copyright 1985-1990 Bradley Forthware
\ Copyright: Copyright 1999-2002 Sun Microsystems, Inc. All Rights Reserved
\ Copyright: Use is subject to license terms.
\ Common routines for vocabularies, independent of name field
\ implementation details
headers
: wordlist ( -- wid ) (wordlist) lastacf ;
: vocabulary ( "name" -- ) header (wordlist) ;
defer $find-next
' ($find-next) is $find-next
\ : insert-after ( new-node old-node -- )
\ dup link@ ( new-node old-node next-node )
\ 2 pick link! ( new-node old-node )
\ link!
\ ;
tuser hidden-voc origin-t is hidden-voc
: not-hidden ( -- ) hidden-voc !null-token ;
\ WARNING: current-voc is patched later by fm/lib/hashcach.fth
: hide (s -- )
current-voc hidden-voc token!
last @
[ifexist] xref-hide-hook dup name>string xref-hide-hook 2drop [then]
n>link current-voc remove-word
;
\ WARNING: hidden-voc is patched later by fm/lib/hashcach.fth
: reveal (s -- )
hidden-voc get-token? if ( xt )
last @ ( xt )
[ifexist] xref-reveal-hook dup name>string xref-reveal-hook 2drop [then]
n>link 0 rot insert-word ( )
not-hidden
then
;
#threads-t constant #threads
auser voc-link \ points to newest vocabulary
headerless
: voc-link, (s -- ) \ links this vocabulary to the chain
lastacf voc-link link@ link, voc-link link!
;
hex
0 value fake-name-buf
headers
: fake-name ( xt -- anf )
base @ >r hex
<# 0 hold ascii ) hold u#s ascii ( hold u#> ( adr len )
fake-name-buf $save ( adr len )
tuck + 1- tuck ( anf len adr+len )
swap 1- h# 80 or swap c! ( adr )
r> base !
;
\ Returns the name field address, or if the word is headerless, the
\ address of a numeric string representing the xt in parentheses.
: >name ( xt -- anf )
dup >name? if nip else drop fake-name then
;
: immediate (s -- ) last @ n>flags dup c@ 40 or swap c! ;
: immediate? (s xt -- flag ) >flags c@ 40 and 0<> ;
: flagalias (s -- ) last @ n>flags dup c@ 20 or swap c! ;
: .last (s -- ) last @ .id ;
: current-voc ( -- voc-xt ) current token@ ;
: context-voc ( -- voc-xt ) context token@ ;
0 value canonical-word
headerless
: duplicate-notification ( adr len voc -- adr len voc )
where (compile-time-warning)
>r 2dup type r> ." isn't unique " cr
;
chain: init ( -- )
d# 20 alloc-mem is fake-name-buf
d# 32 alloc-mem is canonical-word
;
headers
: $canonical ( adr len -- adr' len' )
caps @ if d# 31 min canonical-word $save 2dup lower then
;
: $create-word ( adr len voc-xt -- )
>r $canonical
[ifexist] xref-header-hook
xref-header-hook
[then]
r> warning @ if
3dup $find-word if ( adr len voc-xt xt )
drop duplicate-notification
else ( adr len voc-xt adr len )
2drop
then
then ( adr len voc-xt )
$make-header
;
: ($header) (s adr len -- ) current-voc $create-word ;
' ($header) is $header
: (search-wordlist) ( adr len vocabulary -- false | xt +-1 )
$find-word dup 0= if nip nip then
;
: search-wordlist ( adr len vocabulary -- false | xt +-1 )
>r $canonical r> (search-wordlist)
;
: $vfind ( adr len vocabulary -- adr len false | xt +-1 )
>r $canonical r> $find-word
;
: find-fixup ( adr len alf true | adr len false -- xt +-1 | adr len 0 )
dup if ( adr len alf true )
drop nip nip ( alf )
dup link> swap l>name n>flags c@ ( xt flags )
dup h# 20 and if swap token@ swap then ( xt' flags ) \ alias?
h# 40 and if 1 else -1 then \ immediate?
then
;
headerless
2 /n-t * ualloc-t user tbuf
headers
: follow ( voc-acf -- ) tbuf token! 0 tbuf na1+ ! ;
: another? ( -- false | anf true )
tbuf na1+ @ tbuf token@ next-word ( 0 | alf true )
if dup tbuf na1+ ! l>name true else false then
;
: another-word? ( alf|0 voc-acf -- alf' voc-acf anf true | false )
tuck next-word if ( voc-acf alf' )
tuck l>name true ( alf' voc-acf anf true )
else ( voc-acf )
drop false ( false )
then
;
\ Forget
headerless
: trim (s alf voc-acf -- )
>r 0 ( adr 0 )
begin r@ next-word while ( adr alf )
2dup <= if dup r@ remove-word then ( adr alf )
repeat ( adr )
r> 2drop
;
headers
auser fence \ barrier for forgetting
: (forget) (s adr -- ) \ reclaim dictionary space above "adr"
dup fence a@ u< ( -15 ) abort" below fence" ( adr )
\ Forget any entire vocabularies defined after "adr"
voc-link ( adr first-voc )
begin ( adr voc )
\ XXX this may not work with a mixed RAM/ROM system where
\ RAM is at a lower address than ROM
link@ 2dup u< ( adr voc' more? )
while ( adr voc )
dup voc> current-voc = ( adr voc error? )
( -15 ) abort" I can't forget the current vocabulary."
\ Remove the voc from the search order
dup voc> (except ( adr voc )
>voc-link ( adr voc-link )
repeat ( adr voc )
dup voc-link link! ( adr voc )
\ For all remaining vocabularies, unlink words defined after "adr"
\ We assume that we haven't forgotten all the vocabularies;
\ otherwise this will fail. Forgetting all the vocabularies would
\ crash the system anyway, so we don't worry about it.
begin ( adr voc )
2dup voc> trim ( adr voc )
>voc-link ( adr voc-link-adr )
another-link? 0= ( adr voc' )
until ( adr )
l>beginning here - allot \ Reclaim dictionary space
;
: forget (s -- )
safe-parse-word current-voc $vfind $?missing drop
>link (forget)
;
: marker ( "name" -- )
create #user @ ,
does> dup @ #user ! body> >link (forget)
;
chain: init ( -- ) ['] ($find-next) is $find-next ;