Attempting to make require-when work with multiple vocabs
parent
265fe6208f
commit
00176e7bd1
|
@ -3,7 +3,7 @@
|
||||||
USING: namespaces make sequences io io.files io.pathnames kernel
|
USING: namespaces make sequences io io.files io.pathnames kernel
|
||||||
assocs words vocabs definitions parser continuations hashtables
|
assocs words vocabs definitions parser continuations hashtables
|
||||||
sorting source-files arrays combinators strings system
|
sorting source-files arrays combinators strings system
|
||||||
math.parser splitting init accessors sets ;
|
math.parser splitting init accessors sets fry ;
|
||||||
IN: vocabs.loader
|
IN: vocabs.loader
|
||||||
|
|
||||||
SYMBOL: vocab-roots
|
SYMBOL: vocab-roots
|
||||||
|
@ -66,9 +66,17 @@ DEFER: require
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
|
: transfer-conditionals ( vocab-name record -- )
|
||||||
|
{
|
||||||
|
[ unloaded>> delete ]
|
||||||
|
[ loaded>> adjoin ]
|
||||||
|
[ swap partly-required get adjoin-at ]
|
||||||
|
[ unloaded>> null? swap '[ _ require ] when ]
|
||||||
|
} 2cleave ;
|
||||||
|
|
||||||
: load-conditional-requires ( vocab-name -- )
|
: load-conditional-requires ( vocab-name -- )
|
||||||
conditional-requires get
|
conditional-requires get
|
||||||
[ at [ require ] each ]
|
[ dupd at members [ transfer-conditionals ] with each ]
|
||||||
[ delete-at ] 2bi ;
|
[ delete-at ] 2bi ;
|
||||||
|
|
||||||
: load-source ( vocab -- )
|
: load-source ( vocab -- )
|
||||||
|
@ -96,11 +104,22 @@ PRIVATE>
|
||||||
: require ( vocab -- )
|
: require ( vocab -- )
|
||||||
load-vocab drop ;
|
load-vocab drop ;
|
||||||
|
|
||||||
|
<PRIVATE
|
||||||
|
|
||||||
|
: adjoin-each-at ( elt seq assoc -- )
|
||||||
|
[ swap ] dip '[ _ swap _ adjoin-at ] each ;
|
||||||
|
|
||||||
|
: record-require-when ( then loaded unloaded -- )
|
||||||
|
[ [ fast-set ] bi@ <require-when-record> ] 2keep
|
||||||
|
[ conditional-requires get adjoin-each-at ]
|
||||||
|
[ partly-required get adjoin-each-at ]
|
||||||
|
bi-curry* bi ;
|
||||||
|
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
: require-when ( if then -- )
|
: require-when ( if then -- )
|
||||||
over vocab
|
swap [ vocab ] partition
|
||||||
[ nip require ]
|
[ drop require ] [ record-require-when ] if-empty ;
|
||||||
[ swap conditional-requires get [ swap suffix ] change-at ]
|
|
||||||
if ;
|
|
||||||
|
|
||||||
: reload ( name -- )
|
: reload ( name -- )
|
||||||
dup vocab
|
dup vocab
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
USE: vocabs.loader
|
USE: vocabs.loader
|
||||||
IN: vocabs.loader.test.m
|
IN: vocabs.loader.test.m
|
||||||
|
|
||||||
"vocabs.loader.test.o" "vocabs.loader.test.n" require-when
|
{ "vocabs.loader.test.o" "vocabs.loader.test.m" }
|
||||||
|
"vocabs.loader.test.n" require-when
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2007, 2009 Eduardo Cavazos, Slava Pestov.
|
! Copyright (C) 2007, 2009 Eduardo Cavazos, Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors assocs strings kernel sorting namespaces
|
USING: accessors assocs strings kernel sorting namespaces
|
||||||
sequences definitions sets ;
|
sequences definitions sets combinators ;
|
||||||
IN: vocabs
|
IN: vocabs
|
||||||
|
|
||||||
SYMBOL: dictionary
|
SYMBOL: dictionary
|
||||||
|
@ -83,9 +83,25 @@ ERROR: bad-vocab-name name ;
|
||||||
: check-vocab-name ( name -- name )
|
: check-vocab-name ( name -- name )
|
||||||
dup string? [ bad-vocab-name ] unless ;
|
dup string? [ bad-vocab-name ] unless ;
|
||||||
|
|
||||||
|
TUPLE: require-when-record
|
||||||
|
vocab loaded unloaded ;
|
||||||
|
|
||||||
|
! These are identified by their vocab
|
||||||
|
M: require-when-record equal?
|
||||||
|
over require-when-record?
|
||||||
|
[ [ vocab>> ] bi@ = ] [ 2drop f ] if ;
|
||||||
|
|
||||||
|
M: require-when-record hashcode*
|
||||||
|
vocab>> hashcode* ;
|
||||||
|
|
||||||
|
C: <require-when-record> require-when-record
|
||||||
|
|
||||||
SYMBOL: conditional-requires
|
SYMBOL: conditional-requires
|
||||||
conditional-requires [ H{ } clone ] initialize
|
conditional-requires [ H{ } clone ] initialize
|
||||||
|
|
||||||
|
SYMBOL: partly-required
|
||||||
|
partly-required [ H{ } clone ] initialize
|
||||||
|
|
||||||
: create-vocab ( name -- vocab )
|
: create-vocab ( name -- vocab )
|
||||||
check-vocab-name
|
check-vocab-name
|
||||||
dictionary get [ <vocab> ] cache
|
dictionary get [ <vocab> ] cache
|
||||||
|
@ -120,9 +136,26 @@ M: vocab-spec >vocab-link ;
|
||||||
|
|
||||||
M: string >vocab-link dup vocab [ ] [ <vocab-link> ] ?if ;
|
M: string >vocab-link dup vocab [ ] [ <vocab-link> ] ?if ;
|
||||||
|
|
||||||
|
<PRIVATE
|
||||||
|
|
||||||
|
: untransfer-conditionals ( vocab-name record -- )
|
||||||
|
{
|
||||||
|
[ loaded>> delete ]
|
||||||
|
[ unloaded>> adjoin ]
|
||||||
|
[ swap conditional-requires get adjoin-at ]
|
||||||
|
} 2cleave ;
|
||||||
|
|
||||||
|
: unload-conditional-requires ( vocab-name -- )
|
||||||
|
partly-required get
|
||||||
|
[ dupd at members [ untransfer-conditionals ] with each ]
|
||||||
|
[ delete-at ] 2bi ;
|
||||||
|
|
||||||
|
PRIVATE>
|
||||||
|
|
||||||
: forget-vocab ( vocab -- )
|
: forget-vocab ( vocab -- )
|
||||||
[ words forget-all ]
|
[ words forget-all ]
|
||||||
[ vocab-name dictionary get delete-at ] bi
|
[ vocab-name dictionary get delete-at ]
|
||||||
|
[ unload-conditional-requires ] tri
|
||||||
notify-vocab-observers ;
|
notify-vocab-observers ;
|
||||||
|
|
||||||
M: vocab-spec forget* forget-vocab ;
|
M: vocab-spec forget* forget-vocab ;
|
||||||
|
|
Loading…
Reference in New Issue