2008-02-18 08:30:16 -05:00
|
|
|
! Copyright (C) 2008 Slava Pestov.
|
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
|
USING: threads io.files io.monitors init kernel
|
2008-04-09 01:19:56 -04:00
|
|
|
vocabs vocabs.loader tools.vocabs namespaces continuations
|
|
|
|
|
sequences splitting assocs ;
|
2008-03-12 20:55:06 -04:00
|
|
|
IN: tools.vocabs.monitor
|
2008-02-05 19:55:10 -05:00
|
|
|
|
2008-04-09 01:19:56 -04:00
|
|
|
: vocab-dir>vocab-name ( path -- vocab )
|
|
|
|
|
left-trim-separators right-trim-separators
|
|
|
|
|
{ { CHAR: / CHAR: . } { CHAR: \\ CHAR: . } } substitute ;
|
2008-02-05 19:55:10 -05:00
|
|
|
|
2008-04-09 01:19:56 -04:00
|
|
|
: path>vocab-name ( path -- vocab )
|
|
|
|
|
dup ".factor" tail? [ parent-directory ] when
|
2008-04-09 03:53:29 -04:00
|
|
|
;
|
|
|
|
|
|
|
|
|
|
: chop-vocab-root ( path -- path' )
|
|
|
|
|
"resource:" prepend-path (normalize-path)
|
|
|
|
|
dup vocab-roots get
|
|
|
|
|
[ (normalize-path) ] map
|
|
|
|
|
[ head? ] with find nip
|
|
|
|
|
?head drop ;
|
|
|
|
|
|
|
|
|
|
: path>vocab ( path -- vocab )
|
|
|
|
|
chop-vocab-root path>vocab-name vocab-dir>vocab-name ;
|
2008-02-18 06:07:40 -05:00
|
|
|
|
2008-04-09 01:19:56 -04:00
|
|
|
: changed-vocab ( vocab -- )
|
|
|
|
|
dup vocab
|
|
|
|
|
[ dup changed-vocabs get-global set-at ] [ drop ] if ;
|
|
|
|
|
|
2008-04-09 03:53:29 -04:00
|
|
|
: monitor-thread ( monitor -- )
|
2008-04-09 01:19:56 -04:00
|
|
|
#! On OS X, monitors give us the full path, so we chop it
|
|
|
|
|
#! off if its there.
|
2008-04-09 03:53:29 -04:00
|
|
|
next-change drop path>vocab changed-vocab reset-cache ;
|
2008-04-09 01:19:56 -04:00
|
|
|
|
2008-04-09 03:53:29 -04:00
|
|
|
: start-monitor-thread ( monitor -- )
|
2008-02-12 13:19:25 -05:00
|
|
|
#! Silently ignore errors during monitor creation since
|
|
|
|
|
#! monitors are not supported on all platforms.
|
2008-04-09 03:53:29 -04:00
|
|
|
[ monitor-thread t ] curry
|
|
|
|
|
"Vocabulary monitor" spawn-server
|
|
|
|
|
drop ;
|
2008-04-09 01:19:56 -04:00
|
|
|
|
|
|
|
|
: start-monitor-threads ( -- )
|
2008-02-18 08:30:16 -05:00
|
|
|
[
|
2008-04-09 03:53:29 -04:00
|
|
|
"" resource-path t <monitor> start-monitor-thread
|
2008-04-09 01:19:56 -04:00
|
|
|
H{ } clone changed-vocabs set-global
|
|
|
|
|
vocabs [ changed-vocab ] each
|
2008-02-26 15:58:02 -05:00
|
|
|
] ignore-errors ;
|
2008-02-05 19:55:10 -05:00
|
|
|
|
2008-04-09 01:19:56 -04:00
|
|
|
[ start-monitor-threads ] "tools.vocabs.monitor" add-init-hook
|