! Copyright (C) 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: assocs kernel namespaces memoize init vocabs
+USING: assocs kernel namespaces memoize init sequences vocabs
vocabs.hierarchy vocabs.loader vocabs.metadata vocabs.refresh ;
IN: vocabs.cache
-: reset-cache ( -- )
- root-cache get-global clear-assoc
+: reset-cache ( vocab -- )
+ vocab-name root-cache get-global delete-at
\ vocab-file-contents reset-memoized
\ all-vocabs-recursive reset-memoized
\ all-authors reset-memoized
SINGLETON: cache-observer
-M: cache-observer vocabs-changed drop reset-cache ;
+M: cache-observer vocab-changed drop reset-cache ;
[
f changed-vocabs set-global
: monitor-loop ( monitor -- )
#! On OS X, monitors give us the full path, so we chop it
#! off if its there.
- [ next-change path>> path>vocab changed-vocab reset-cache ]
+ [
+ next-change path>> path>vocab
+ [ changed-vocab ] [ reset-cache ] bi
+ ]
[ monitor-loop ]
bi ;
[ add-vocab-root-hook get-global call( root -- ) ] bi ;
SYMBOL: root-cache
-
root-cache [ H{ } clone ] initialize
ERROR: not-found-in-roots path ;
! Defined by vocabs.metadata
SYMBOL: check-vocab-hook
-
check-vocab-hook [ [ drop ] ] initialize
<PRIVATE
SYMBOL: vocab-observers
-GENERIC: vocabs-changed ( obj -- )
+GENERIC: vocab-changed ( vocab obj -- )
: add-vocab-observer ( obj -- )
vocab-observers get push ;
: remove-vocab-observer ( obj -- )
vocab-observers get remove-eq! drop ;
-: notify-vocab-observers ( -- )
- vocab-observers get [ vocabs-changed ] each ;
+: notify-vocab-observers ( vocab -- )
+ vocab-observers get [ vocab-changed ] with each ;
: create-vocab ( name -- vocab )
check-vocab-name
dictionary get [ <vocab> ] cache
- notify-vocab-observers ;
+ dup notify-vocab-observers ;
ERROR: no-vocab name ;
: forget-vocab ( vocab -- )
[ words forget-all ]
- [ vocab-name dictionary get delete-at ] bi
- notify-vocab-observers ;
+ [ vocab-name dictionary get delete-at ]
+ [ notify-vocab-observers ] tri ;
M: vocab-spec forget* forget-vocab ;