From fb44adef99a6eb53a8d21f5486560454c288dd97 Mon Sep 17 00:00:00 2001 From: Doug Coleman Date: Wed, 2 Nov 2011 16:30:00 -0700 Subject: [PATCH] Clean up formatting, rename load-vocab-hook to require-hook. Add a unit test for vocabs.loader. --- basis/bootstrap/help/help.factor | 2 +- basis/tools/deploy/shaker/shaker.factor | 2 +- core/vocabs/loader/loader-tests.factor | 5 ++++- core/vocabs/loader/loader.factor | 4 ++-- core/vocabs/vocabs-docs.factor | 4 ++-- core/vocabs/vocabs.factor | 27 ++++++++++++------------- 6 files changed, 23 insertions(+), 21 deletions(-) diff --git a/basis/bootstrap/help/help.factor b/basis/bootstrap/help/help.factor index 9004d556f6..0b85468b08 100644 --- a/basis/bootstrap/help/help.factor +++ b/basis/bootstrap/help/help.factor @@ -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 diff --git a/basis/tools/deploy/shaker/shaker.factor b/basis/tools/deploy/shaker/shaker.factor index 38109cd10d..05234e544b 100755 --- a/basis/tools/deploy/shaker/shaker.factor +++ b/basis/tools/deploy/shaker/shaker.factor @@ -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 diff --git a/core/vocabs/loader/loader-tests.factor b/core/vocabs/loader/loader-tests.factor index d5fbacf5f1..dd0bc493d9 100644 --- a/core/vocabs/loader/loader-tests.factor +++ b/core/vocabs/loader/loader-tests.factor @@ -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 diff --git a/core/vocabs/loader/loader.factor b/core/vocabs/loader/loader.factor index 5e6a3259e5..d5a344f6bd 100644 --- a/core/vocabs/loader/loader.factor +++ b/core/vocabs/loader/loader.factor @@ -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 ; diff --git a/core/vocabs/vocabs-docs.factor b/core/vocabs/vocabs-docs.factor index c67cdb4508..301b4b838b 100644 --- a/core/vocabs/vocabs-docs.factor +++ b/core/vocabs/vocabs-docs.factor @@ -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" } } diff --git a/core/vocabs/vocabs.factor b/core/vocabs/vocabs.factor index 7f1200ea70..1b3c15a9b4 100644 --- a/core/vocabs/vocabs.factor +++ b/core/vocabs/vocabs.factor @@ -125,34 +125,33 @@ M: object >vocab-link dup lookup-vocab [ ] [ ] ?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 - ] [ - nip call-load-vocab-hook - ] if + over lookup-vocab + [ 2drop ] + [ nip call-require-hook ] + if ] [ - nip call-load-vocab-hook + nip call-require-hook ] if ; : load-vocab ( name -- vocab )