Simplify vocab.loader even further

db4
Slava Pestov 2008-03-19 14:39:08 -05:00
parent 3d43c0350e
commit 3591ed402d
10 changed files with 69 additions and 94 deletions

View File

@ -30,6 +30,7 @@ crossref off
"syntax" vocab vocab-words bootstrap-syntax set
H{ } clone dictionary set
H{ } clone changed-words set
H{ } clone root-cache set
! Trivial recompile hook. We don't want to touch the code heap
! during stage1 bootstrap, it would just waste time.

View File

@ -43,8 +43,6 @@ HELP: find-vocab-root
{ $values { "vocab" "a vocabulary specifier" } { "path/f" "a pathname string" } }
{ $description "Searches for a vocabulary in the vocabulary roots." } ;
{ vocab-root find-vocab-root } related-words
HELP: no-vocab
{ $values { "name" "a vocabulary name" } }
{ $description "Throws a " { $link no-vocab } "." }

View File

@ -13,15 +13,15 @@ debugger compiler.units tools.vocabs ;
] unit-test
[ T{ vocab-link f "vocabs.loader.test" } ]
[ "vocabs.loader.test" f >vocab-link ] unit-test
[ "vocabs.loader.test" >vocab-link ] unit-test
[ t ]
[ "kernel" f >vocab-link "kernel" vocab = ] unit-test
[ "kernel" >vocab-link "kernel" vocab = ] unit-test
[ t ] [
"kernel" vocab-files
"kernel" vocab vocab-files
"kernel" f <vocab-link> vocab-files
"kernel" <vocab-link> vocab-files
3array all-equal?
] unit-test
@ -36,7 +36,7 @@ IN: vocabs.loader.tests
[ { 3 3 3 } ] [
"vocabs.loader.test.2" run
"vocabs.loader.test.2" vocab run
"vocabs.loader.test.2" f <vocab-link> run
"vocabs.loader.test.2" <vocab-link> run
3array
] unit-test
@ -115,7 +115,7 @@ IN: vocabs.loader.tests
[ 3 ] [ "count-me" get-global ] unit-test
[ { "resource:core/kernel/kernel.factor" 1 } ]
[ "kernel" f <vocab-link> where ] unit-test
[ "kernel" <vocab-link> where ] unit-test
[ { "resource:core/kernel/kernel.factor" 1 } ]
[ "kernel" vocab where ] unit-test

View File

@ -23,15 +23,6 @@ V{
[ >r dup peek r> append add ] when*
"/" join ;
: vocab-path+ ( vocab path -- newpath )
swap vocab-root dup [ swap path+ ] [ 2drop f ] if ;
: vocab-source-path ( vocab -- path/f )
dup ".factor" vocab-dir+ vocab-path+ ;
: vocab-docs-path ( vocab -- path/f )
dup "-docs.factor" vocab-dir+ vocab-path+ ;
: vocab-dir? ( root name -- ? )
over [
".factor" vocab-dir+ path+ resource-exists?
@ -39,14 +30,23 @@ V{
2drop f
] if ;
SYMBOL: root-cache
H{ } clone root-cache set-global
: find-vocab-root ( vocab -- path/f )
vocab-roots get swap [ vocab-dir? ] curry find nip ;
vocab-name root-cache get [
vocab-roots get swap [ vocab-dir? ] curry find nip
] cache ;
M: string vocab-root
vocab dup [ vocab-root ] when ;
: vocab-path+ ( vocab path -- newpath )
swap find-vocab-root dup [ swap path+ ] [ 2drop f ] if ;
M: vocab-link vocab-root
vocab-link-root ;
: vocab-source-path ( vocab -- path/f )
dup ".factor" vocab-dir+ vocab-path+ ;
: vocab-docs-path ( vocab -- path/f )
dup "-docs.factor" vocab-dir+ vocab-path+ ;
SYMBOL: load-help?
@ -56,7 +56,7 @@ SYMBOL: load-help?
: load-source ( vocab -- )
[ source-wasn't-loaded ] keep
[ vocab-source-path bootstrap-file ] keep
[ vocab-source-path [ bootstrap-file ] when* ] keep
source-was-loaded ;
: docs-were-loaded t swap set-vocab-docs-loaded? ;
@ -70,18 +70,9 @@ SYMBOL: load-help?
docs-were-loaded
] [ drop ] if ;
: create-vocab-with-root ( name root -- vocab )
swap create-vocab [ set-vocab-root ] keep ;
: update-root ( vocab -- )
dup vocab-root
[ drop ] [ dup find-vocab-root swap set-vocab-root ] if ;
: reload ( name -- )
[
dup vocab [
dup update-root dup load-source load-docs
] [ no-vocab ] ?if
dup vocab [ dup load-source load-docs ] [ no-vocab ] ?if
] with-compiler-errors ;
: require ( vocab -- )
@ -104,22 +95,17 @@ SYMBOL: blacklist
GENERIC: (load-vocab) ( name -- )
M: vocab (load-vocab)
dup update-root
dup vocab-root [
[
dup vocab-source-loaded? [ dup load-source ] unless
dup vocab-docs-loaded? [ dup load-docs ] unless
] [ [ swap add-to-blacklist ] keep rethrow ] recover
] when drop ;
M: string (load-vocab)
! ".private" ?tail drop
dup find-vocab-root >vocab-link (load-vocab) ;
[
dup vocab-source-loaded? [ dup load-source ] unless
dup vocab-docs-loaded? [ dup load-docs ] unless
drop
] [ [ swap add-to-blacklist ] keep rethrow ] recover ;
M: vocab-link (load-vocab)
dup vocab-name swap vocab-root dup
[ create-vocab-with-root (load-vocab) ] [ 2drop ] if ;
vocab-name create-vocab (load-vocab) ;
M: string (load-vocab)
create-vocab (load-vocab) ;
[
[

View File

@ -16,7 +16,6 @@ $nl
{ $subsection vocab }
"Accessors for various vocabulary attributes:"
{ $subsection vocab-name }
{ $subsection vocab-root }
{ $subsection vocab-main }
{ $subsection vocab-help }
"Looking up existing vocabularies and creating new vocabularies:"
@ -50,10 +49,6 @@ HELP: vocab-name
{ $values { "vocab" "a vocabulary specifier" } { "name" string } }
{ $description "Outputs the name of a vocabulary." } ;
HELP: vocab-root
{ $values { "vocab" "a vocabulary specifier" } { "root" "a pathname string or " { $link f } } }
{ $description "Outputs the vocabulary root where the source code for a vocabulary is located, or " { $link f } " if the vocabulary is not defined in source files." } ;
HELP: vocab-words
{ $values { "vocab" "a vocabulary specifier" } { "words" "an assoc mapping strings to words" } }
{ $description "Outputs the words defined in a vocabulary." } ;
@ -101,11 +96,11 @@ HELP: child-vocabs
} ;
HELP: vocab-link
{ $class-description "Instances of this class identify vocabularies which are potentially not loaded. The " { $link vocab-name } " slot is the vocabulary name, and " { $link vocab-root } " is a pathname string identifying the vocabulary root where the sources to this vocabulary are located, or " { $link f } " if the root is not known."
{ $class-description "Instances of this class identify vocabularies which are potentially not loaded. The " { $link vocab-name } " slot is the vocabulary name."
$nl
"Vocabulary links are created by calling " { $link >vocab-link } "."
} ;
HELP: >vocab-link
{ $values { "name" string } { "root" "a pathname string or " { $link f } } { "vocab" "a vocabulary specifier" } }
{ $values { "name" string } { "vocab" "a vocabulary specifier" } }
{ $description "If the vocabulary is loaded, outputs the corresponding " { $link vocab } " instance, otherwise creates a new " { $link vocab-link } "." } ;

View File

@ -92,10 +92,10 @@ SYMBOL: load-vocab-hook ! ( name -- )
: child-vocabs ( vocab -- seq )
vocab-name vocabs [ child-vocab? ] with subset ;
TUPLE: vocab-link name root ;
TUPLE: vocab-link name ;
: <vocab-link> ( name root -- vocab-link )
[ dup vocab-root ] unless* vocab-link construct-boa ;
: <vocab-link> ( name -- vocab-link )
vocab-link construct-boa ;
M: vocab-link equal?
over vocab-link?
@ -106,17 +106,14 @@ M: vocab-link hashcode*
M: vocab-link vocab-name vocab-link-name ;
GENERIC# >vocab-link 1 ( name root -- vocab )
M: vocab >vocab-link drop ;
M: vocab-link >vocab-link drop ;
M: string >vocab-link
over vocab dup [ 2nip ] [ drop <vocab-link> ] if ;
UNION: vocab-spec vocab vocab-link ;
GENERIC: >vocab-link ( name -- vocab )
M: vocab-spec >vocab-link ;
M: string >vocab-link dup vocab [ ] [ <vocab-link> ] ?if ;
: forget-vocab ( vocab -- )
dup words forget-all
vocab-name dictionary get delete-at ;

View File

@ -159,7 +159,7 @@ M: f print-element drop ;
[ first ($long-link) ] ($subsection) ;
: ($vocab-link) ( text vocab -- )
dup vocab-root >vocab-link write-link ;
>vocab-link write-link ;
: $vocab-subsection ( element -- )
[

View File

@ -26,6 +26,10 @@ tools.deploy.backend math sequences io.launcher arrays ;
[ ] [ "hello-ui" shake-and-bake ] unit-test
[ "staging.math-compiler-ui-strip.image" ] [
"hello-ui" deploy-config [ staging-image-name ] bind
] unit-test
[ t ] [
2000000 small-enough?
] unit-test

View File

@ -127,7 +127,7 @@ C: <vocab-author> vocab-author
: $describe-vocab ( element -- )
first
dup describe-children
dup vocab-root over vocab-dir? [
dup find-vocab-root [
dup describe-summary
dup describe-tags
dup describe-authors

View File

@ -6,29 +6,27 @@ memoize inspector sorting splitting combinators source-files
io debugger continuations compiler.errors init io.crc32 ;
IN: tools.vocabs
: vocab-tests-file, ( vocab -- )
dup "-tests.factor" vocab-dir+ vocab-path+
dup resource-exists? [ , ] [ drop ] if ;
: vocab-tests-file ( vocab -- path )
dup "-tests.factor" vocab-dir+ vocab-path+ dup
[ dup resource-exists? [ drop f ] unless ] [ drop f ] if ;
: vocab-tests-dir, ( vocab -- )
dup vocab-dir "tests" path+ vocab-path+
dup resource-exists? [
dup ?resource-path directory keys
[ ".factor" tail? ] subset
[ path+ , ] with each
] [ drop ] if ;
: vocab-tests-dir ( vocab -- paths )
dup vocab-dir "tests" path+ vocab-path+ dup [
dup resource-exists? [
dup ?resource-path directory keys
[ ".factor" tail? ] subset
[ path+ ] with map
] [ drop f ] if
] [ drop f ] if ;
: vocab-tests ( vocab -- tests )
dup vocab-root dup [
[
>vocab-link dup
vocab-tests-file,
vocab-tests-dir,
] { } make
] [ 2drop f ] if ;
[
dup vocab-tests-file [ , ] when*
vocab-tests-dir [ % ] when*
] { } make ;
: vocab-files ( vocab -- seq )
dup find-vocab-root >vocab-link [
[
dup vocab-source-path [ , ] when*
dup vocab-docs-path [ , ] when*
vocab-tests %
@ -53,12 +51,8 @@ IN: tools.vocabs
: modified-docs ( vocabs -- seq )
[ vocab-docs-path ] modified ;
: update-roots ( vocabs -- )
[ dup find-vocab-root swap vocab set-vocab-root ] each ;
: to-refresh ( prefix -- modified-sources modified-docs )
child-vocabs
dup update-roots
dup modified-sources swap modified-docs ;
: vocab-heading. ( vocab -- )
@ -180,7 +174,7 @@ M: vocab-link summary vocab-summary ;
: vocabs-in-dir ( root name -- )
dupd (all-child-vocabs) [
2dup vocab-dir? [ 2dup swap >vocab-link , ] when
2dup vocab-dir? [ dup >vocab-link , ] when
vocabs-in-dir
] with each ;
@ -233,7 +227,7 @@ MEMO: all-vocabs-seq ( -- seq )
: unrooted-child-vocabs ( prefix -- seq )
dup empty? [ CHAR: . add ] unless
vocabs
[ vocab-root not ] subset
[ find-vocab-root not ] subset
[
vocab-name swap ?head CHAR: . rot member? not and
] with subset
@ -241,10 +235,9 @@ MEMO: all-vocabs-seq ( -- seq )
: all-child-vocabs ( prefix -- assoc )
vocab-roots get [
over dupd dupd (all-child-vocabs)
swap [ >vocab-link ] curry map
dup pick (all-child-vocabs) [ >vocab-link ] map
] { } map>assoc
f rot unrooted-child-vocabs 2array add ;
swap unrooted-child-vocabs f swap 2array add ;
: all-child-vocabs-seq ( prefix -- assoc )
vocab-roots get swap [
@ -262,6 +255,7 @@ MEMO: all-authors ( -- seq )
all-vocabs-seq [ vocab-authors ] map>set ;
: reset-cache ( -- )
root-cache get-global clear-assoc
\ (vocab-file-contents) reset-memoized
\ all-vocabs-seq reset-memoized
\ all-authors reset-memoized