Clean up formatting, rename load-vocab-hook to require-hook. Add a unit test for vocabs.loader.
parent
86e3817e40
commit
fb44adef99
|
@ -9,7 +9,7 @@ IN: bootstrap.help
|
||||||
|
|
||||||
t load-help? set-global
|
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
|
dictionary get values
|
||||||
[ docs-loaded?>> not ] filter
|
[ docs-loaded?>> not ] filter
|
||||||
[ load-docs ] each
|
[ load-docs ] each
|
||||||
|
|
|
@ -371,7 +371,7 @@ IN: tools.deploy.shaker
|
||||||
source-files.errors:error-types
|
source-files.errors:error-types
|
||||||
source-files.errors:error-observers
|
source-files.errors:error-observers
|
||||||
vocabs:dictionary
|
vocabs:dictionary
|
||||||
vocabs:load-vocab-hook
|
vocabs:require-hook
|
||||||
vocabs:vocab-observers
|
vocabs:vocab-observers
|
||||||
vocabs.loader:add-vocab-root-hook
|
vocabs.loader:add-vocab-root-hook
|
||||||
word
|
word
|
||||||
|
|
|
@ -185,6 +185,9 @@ forget-junk
|
||||||
[ ] [ "vocabs.loader.test.m" require ] unit-test
|
[ ] [ "vocabs.loader.test.m" require ] unit-test
|
||||||
[ t ] [ "vocabs.loader.test.n" lookup-vocab >boolean ] 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
|
] with-compilation-unit
|
||||||
|
|
|
@ -159,7 +159,7 @@ PRIVATE>
|
||||||
dup vocab-name blacklist get at* [ rethrow ] [
|
dup vocab-name blacklist get at* [ rethrow ] [
|
||||||
drop dup find-vocab-root
|
drop dup find-vocab-root
|
||||||
[ (load-vocab) ] [ dup lookup-vocab [ ] [ no-vocab ] ?if ] if
|
[ (load-vocab) ] [ dup lookup-vocab [ ] [ no-vocab ] ?if ] if
|
||||||
] if
|
] if drop
|
||||||
] load-vocab-hook set-global
|
] require-hook set-global
|
||||||
|
|
||||||
M: vocab-spec where vocab-source-path dup [ 1 2array ] when ;
|
M: vocab-spec where vocab-source-path dup [ 1 2array ] when ;
|
||||||
|
|
|
@ -76,8 +76,8 @@ HELP: forget-vocab
|
||||||
{ $description "Removes a vocabulary. All words in the vocabulary are forgotten." }
|
{ $description "Removes a vocabulary. All words in the vocabulary are forgotten." }
|
||||||
{ $notes "This word must be called from inside " { $link with-compilation-unit } "." } ;
|
{ $notes "This word must be called from inside " { $link with-compilation-unit } "." } ;
|
||||||
|
|
||||||
HELP: load-vocab-hook
|
HELP: require-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" } "." } ;
|
{ $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
|
HELP: words-named
|
||||||
{ $values { "str" string } { "seq" "a sequence of words" } }
|
{ $values { "str" string } { "seq" "a sequence of words" } }
|
||||||
|
|
|
@ -125,34 +125,33 @@ M: object >vocab-link dup lookup-vocab [ ] [ <vocab-link> ] ?if ;
|
||||||
|
|
||||||
M: vocab-spec forget* forget-vocab ;
|
M: vocab-spec forget* forget-vocab ;
|
||||||
|
|
||||||
SYMBOL: load-vocab-hook ! ( name -- vocab )
|
SYMBOL: require-hook
|
||||||
|
|
||||||
PREDICATE: runnable-vocab < vocab
|
PREDICATE: runnable-vocab < vocab
|
||||||
vocab-main >boolean ;
|
vocab-main >boolean ;
|
||||||
|
|
||||||
INSTANCE: vocab-spec definition
|
INSTANCE: vocab-spec definition
|
||||||
|
|
||||||
: call-load-vocab-hook ( name -- )
|
: call-require-hook ( name -- )
|
||||||
load-vocab-hook get call( name -- vocab ) drop ;
|
require-hook get call( name -- ) ;
|
||||||
|
|
||||||
GENERIC: require ( object -- )
|
GENERIC: require ( object -- )
|
||||||
|
|
||||||
M: vocab require name>> require ;
|
M: vocab require name>> require ;
|
||||||
|
M: vocab-link require name>> require ;
|
||||||
|
|
||||||
! When calling "foo.private" require, load "foo" instead,
|
! When calling "foo.private" require, load "foo" instead, ! but only when
|
||||||
! but only when "foo.private" does not exist.
|
! "foo.private" does not exist. The reason for this is that stage1 bootstrap
|
||||||
! The reason for this is that stage1 bootstrap starts out with some .private
|
! starts out with some .private vocabs that contain primitives, and
|
||||||
! vocabs that contain primitives, and loading the public vocabs would cause
|
! loading the public vocabs would cause circularity issues.
|
||||||
! circularity issues.
|
|
||||||
M: string require ( vocab -- )
|
M: string require ( vocab -- )
|
||||||
dup ".private" ?tail [
|
dup ".private" ?tail [
|
||||||
over lookup-vocab [
|
over lookup-vocab
|
||||||
2drop
|
[ 2drop ]
|
||||||
|
[ nip call-require-hook ]
|
||||||
|
if
|
||||||
] [
|
] [
|
||||||
nip call-load-vocab-hook
|
nip call-require-hook
|
||||||
] if
|
|
||||||
] [
|
|
||||||
nip call-load-vocab-hook
|
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
: load-vocab ( name -- vocab )
|
: load-vocab ( name -- vocab )
|
||||||
|
|
Loading…
Reference in New Issue