Fixing up vocabularies and previous.

This commit is contained in:
Brad Nelson
2022-02-21 15:10:08 -08:00
parent 499450b5d8
commit 49e7bfe521
5 changed files with 32 additions and 1 deletions

View File

@ -361,6 +361,7 @@ e: check-blocks
e: check-vocabulary e: check-vocabulary
out: internals out: internals
out: sealed out: sealed
out: previous
out: also out: also
out: only out: only
out: transfer{ out: transfer{

View File

@ -39,6 +39,9 @@ forth definitions
: only forth 0 context cell+ ! ; : only forth 0 context cell+ ! ;
: voc-stack-end ( -- a ) context begin dup @ while cell+ repeat ; : voc-stack-end ( -- a ) context begin dup @ while cell+ repeat ;
: also context context cell+ voc-stack-end over - 2 cells + cmove> ; : also context context cell+ voc-stack-end over - 2 cells + cmove> ;
: previous
voc-stack-end context cell+ = throw
context cell+ context voc-stack-end over - cell+ cmove ;
: sealed 0 last-vocabulary @ >body ! ; : sealed 0 last-vocabulary @ >body ! ;
( Hide some words in an internals vocabulary ) ( Hide some words in an internals vocabulary )

View File

@ -57,6 +57,32 @@ e: test-order
only forth definitions only forth definitions
;e ;e
e: test-order-previous
vocabulary foo
vocabulary bar
vocabulary baz
also foo also bar also baz
order
out: baz >> FORTH
out: bar >> FORTH
out: foo >> FORTH
out: FORTH
previous order
out: bar >> FORTH
out: foo >> FORTH
out: FORTH
previous order
out: foo >> FORTH
out: FORTH
previous order
out: FORTH
;e
e: test-previous-throw
only forth definitions
' previous catch 0<> assert
;e
e: test-vocab-define-order e: test-vocab-define-order
vocabulary foo vocabulary foo
foo definitions foo definitions

View File

@ -39,4 +39,4 @@ z" setsockopt" 5 sysfunc setsockopt
( Fixup return ) ( Fixup return )
: sockaccept sockaccept sign-extend ; : sockaccept sockaccept sign-extend ;
forth definitions only forth definitions

View File

@ -68,6 +68,7 @@ TRANSFER ( "name" ) Move a word from its current dictionary to the current vocab
Useful for "hiding" built-in words Useful for "hiding" built-in words
TRANSFER{ ..words.. }TRANSFER ( -- ) Transfer multiple words to the current vocabulary TRANSFER{ ..words.. }TRANSFER ( -- ) Transfer multiple words to the current vocabulary
ALSO ( -- ) Duplicate the vocabulary at the top of the vocabulary stack ALSO ( -- ) Duplicate the vocabulary at the top of the vocabulary stack
PREVIOUS ( -- ) Drop the vocabulary at the top of the vocabulary stack
ONLY ( -- ) Reset context stack to one item, the FORTH dictionary ONLY ( -- ) Reset context stack to one item, the FORTH dictionary
Non-standard, as there's no distinct ONLY vocabulary Non-standard, as there's no distinct ONLY vocabulary
ORDER ( -- ) Print the vocabulary search order ORDER ( -- ) Print the vocabulary search order