require-if loads vocabs conditionally, now or later
parent
8f92583946
commit
043578ca1d
|
@ -170,3 +170,21 @@ forget-junk
|
|||
] with-compilation-unit
|
||||
|
||||
[ ] [ [ "vocabs.loader.test.j" require ] [ drop :1 ] recover ] unit-test
|
||||
|
||||
[ ] [ "vocabs.loader.test.m" require ] unit-test
|
||||
[ f ] [ "vocabs.loader.test.n" vocab ] unit-test
|
||||
[ ] [ "vocabs.loader.test.o" require ] unit-test
|
||||
[ t ] [ "vocabs.loader.test.n" vocab >boolean ] unit-test
|
||||
|
||||
[
|
||||
"mno" [ "vocabs.loader.test." swap suffix forget-vocab ] each
|
||||
] with-compilation-unit
|
||||
|
||||
[ ] [ "vocabs.loader.test.o" require ] unit-test
|
||||
[ f ] [ "vocabs.loader.test.n" vocab ] unit-test
|
||||
[ ] [ "vocabs.loader.test.m" require ] unit-test
|
||||
[ t ] [ "vocabs.loader.test.n" vocab >boolean ] unit-test
|
||||
|
||||
[
|
||||
"mno" [ "vocabs.loader.test." swap suffix forget-vocab ] each
|
||||
] with-compilation-unit
|
||||
|
|
|
@ -62,8 +62,15 @@ SYMBOL: check-vocab-hook
|
|||
|
||||
check-vocab-hook [ [ drop ] ] initialize
|
||||
|
||||
DEFER: require
|
||||
|
||||
<PRIVATE
|
||||
|
||||
: load-conditional-requires ( vocab-name -- )
|
||||
conditional-requires get
|
||||
[ at [ require ] each ]
|
||||
[ delete-at ] 2bi ;
|
||||
|
||||
: load-source ( vocab -- )
|
||||
dup check-vocab-hook get call( vocab -- )
|
||||
[
|
||||
|
@ -71,7 +78,8 @@ check-vocab-hook [ [ drop ] ] initialize
|
|||
dup vocab-source-path [ parse-file ] [ [ ] ] if*
|
||||
[ +parsing+ >>source-loaded? ] dip
|
||||
[ % ] [ call( -- ) ] if-bootstrapping
|
||||
+done+ >>source-loaded? drop
|
||||
+done+ >>source-loaded?
|
||||
vocab-name load-conditional-requires
|
||||
] [ ] [ f >>source-loaded? ] cleanup ;
|
||||
|
||||
: load-docs ( vocab -- )
|
||||
|
@ -88,6 +96,12 @@ PRIVATE>
|
|||
: require ( vocab -- )
|
||||
load-vocab drop ;
|
||||
|
||||
: require-if ( if then -- )
|
||||
over vocab
|
||||
[ nip require ]
|
||||
[ swap conditional-requires get [ swap suffix ] change-at ]
|
||||
if ;
|
||||
|
||||
: reload ( name -- )
|
||||
dup vocab
|
||||
[ [ load-source ] [ load-docs ] bi ]
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
USE: vocabs.loader
|
||||
IN: vocabs.loader.test.m
|
||||
|
||||
"vocabs.loader.test.o" "vocabs.loader.test.n" require-if
|
|
@ -0,0 +1 @@
|
|||
IN: vocabs.loader.test.n
|
|
@ -0,0 +1 @@
|
|||
IN: vocabs.loader.test.o
|
|
@ -1,7 +1,7 @@
|
|||
! Copyright (C) 2007, 2009 Eduardo Cavazos, Slava Pestov.
|
||||
! See http://factorcode.org/license.txt for BSD license.
|
||||
USING: accessors assocs strings kernel sorting namespaces
|
||||
sequences definitions ;
|
||||
sequences definitions sets ;
|
||||
IN: vocabs
|
||||
|
||||
SYMBOL: dictionary
|
||||
|
@ -83,6 +83,9 @@ ERROR: bad-vocab-name name ;
|
|||
: check-vocab-name ( name -- name )
|
||||
dup string? [ bad-vocab-name ] unless ;
|
||||
|
||||
SYMBOL: conditional-requires
|
||||
conditional-requires [ H{ } clone ] initialize
|
||||
|
||||
: create-vocab ( name -- vocab )
|
||||
check-vocab-name
|
||||
dictionary get [ <vocab> ] cache
|
||||
|
@ -118,8 +121,8 @@ 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
|
||||
[ words forget-all ]
|
||||
[ vocab-name dictionary get delete-at ] bi
|
||||
notify-vocab-observers ;
|
||||
|
||||
M: vocab-spec forget* forget-vocab ;
|
||||
|
|
Loading…
Reference in New Issue