Clean up formatting, rename load-vocab-hook to require-hook. Add a unit test for vocabs.loader.

db4
Doug Coleman 2011-11-02 16:30:00 -07:00
parent 86e3817e40
commit fb44adef99
6 changed files with 23 additions and 21 deletions

View File

@ -9,7 +9,7 @@ IN: bootstrap.help
t load-help? set-global
[ dup lookup-vocab [ ] [ no-vocab ] ?if ] load-vocab-hook [
[ dup lookup-vocab [ ] [ no-vocab ] ?if ] require-hook [
dictionary get values
[ docs-loaded?>> not ] filter
[ load-docs ] each

View File

@ -371,7 +371,7 @@ IN: tools.deploy.shaker
source-files.errors:error-types
source-files.errors:error-observers
vocabs:dictionary
vocabs:load-vocab-hook
vocabs:require-hook
vocabs:vocab-observers
vocabs.loader:add-vocab-root-hook
word

View File

@ -185,6 +185,9 @@ forget-junk
[ ] [ "vocabs.loader.test.m" require ] unit-test
[ t ] [ "vocabs.loader.test.n" lookup-vocab >boolean ] unit-test
[ ] [ "vocabs.loader.test.p.private" require ] unit-test
[ { "foo" } ] [ "vocabs.loader.test.p" words [ name>> ] map ] unit-test
[
"mno" [ "vocabs.loader.test." swap suffix forget-vocab ] each
"mnop" [ "vocabs.loader.test." swap suffix forget-vocab ] each
] with-compilation-unit

View File

@ -159,7 +159,7 @@ PRIVATE>
dup vocab-name blacklist get at* [ rethrow ] [
drop dup find-vocab-root
[ (load-vocab) ] [ dup lookup-vocab [ ] [ no-vocab ] ?if ] if
] if
] load-vocab-hook set-global
] if drop
] require-hook set-global
M: vocab-spec where vocab-source-path dup [ 1 2array ] when ;

View File

@ -76,8 +76,8 @@ HELP: forget-vocab
{ $description "Removes a vocabulary. All words in the vocabulary are forgotten." }
{ $notes "This word must be called from inside " { $link with-compilation-unit } "." } ;
HELP: load-vocab-hook
{ $var-description { $quotation "( name -- vocab )" } " which loads a vocabulary. This quotation is called by " { $link load-vocab } ". The default value should not need to be changed; this functionality is implemented via a hook stored in a variable to break a circular dependency which would otherwise exist from " { $vocab-link "vocabs" } " to " { $vocab-link "vocabs.loader" } " to " { $vocab-link "parser" } " back to " { $vocab-link "vocabs" } "." } ;
HELP: require-hook
{ $var-description { $quotation "( name -- )" } " which loads a vocabulary. This quotation is called by " { $link require } ". The default value should not need to be changed; this functionality is implemented via a hook stored in a variable to break a circular dependency which would otherwise exist from " { $vocab-link "vocabs" } " to " { $vocab-link "vocabs.loader" } " to " { $vocab-link "parser" } " back to " { $vocab-link "vocabs" } "." } ;
HELP: words-named
{ $values { "str" string } { "seq" "a sequence of words" } }

View File

@ -125,34 +125,33 @@ M: object >vocab-link dup lookup-vocab [ ] [ <vocab-link> ] ?if ;
M: vocab-spec forget* forget-vocab ;
SYMBOL: load-vocab-hook ! ( name -- vocab )
SYMBOL: require-hook
PREDICATE: runnable-vocab < vocab
vocab-main >boolean ;
INSTANCE: vocab-spec definition
: call-load-vocab-hook ( name -- )
load-vocab-hook get call( name -- vocab ) drop ;
: call-require-hook ( name -- )
require-hook get call( name -- ) ;
GENERIC: require ( object -- )
M: vocab require name>> require ;
M: vocab-link require name>> require ;
! When calling "foo.private" require, load "foo" instead,
! but only when "foo.private" does not exist.
! The reason for this is that stage1 bootstrap starts out with some .private
! vocabs that contain primitives, and loading the public vocabs would cause
! circularity issues.
! When calling "foo.private" require, load "foo" instead, ! but only when
! "foo.private" does not exist. The reason for this is that stage1 bootstrap
! starts out with some .private vocabs that contain primitives, and
! loading the public vocabs would cause circularity issues.
M: string require ( vocab -- )
dup ".private" ?tail [
over lookup-vocab [
2drop
over lookup-vocab
[ 2drop ]
[ nip call-require-hook ]
if
] [
nip call-load-vocab-hook
] if
] [
nip call-load-vocab-hook
nip call-require-hook
] if ;
: load-vocab ( name -- vocab )