! Copyright (C) 2007, 2009 Eduardo Cavazos, Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: accessors assocs definitions kernel namespaces
-sequences sorting splitting strings ;
+USING: accessors arrays assocs definitions kernel namespaces
+sequences sets sorting splitting strings ;
IN: vocabs
SYMBOL: dictionary
main help
source-loaded? docs-loaded? ;
-! sources-loaded? slot is one of these three
-SYMBOL: +parsing+
-SYMBOL: +running+
-SYMBOL: +done+
+! sources-loaded? and docs-loaded? slots could be
+SYMBOLS: +parsing+ +done+ ;
: <vocab> ( name -- vocab )
vocab new
UNION: vocab-spec vocab vocab-link ;
+INSTANCE: vocab-spec definition-mixin
+
GENERIC: vocab-name ( vocab-spec -- name )
M: vocab vocab-name name>> ;
M: f vocab-main ;
+PREDICATE: runnable-vocab < vocab
+ vocab-main >boolean ;
+
SYMBOL: vocab-observers
GENERIC: vocab-changed ( vocab obj -- )
SYMBOL: require-hook
-PREDICATE: runnable-vocab < vocab
- vocab-main >boolean ;
+<PRIVATE
-INSTANCE: vocab-spec definition-mixin
+SYMBOL: requiring
+
+: with-requiring ( quot -- )
+ requiring get [
+ call
+ ] [
+ HS{ } clone requiring [ call ] with-variable
+ ] if ; inline
+
+PRIVATE>
GENERIC: require ( object -- )
! that contain primitives, and loading the public vocabs would
! cause circularity issues.
M: string require
- [ ".private" ?tail ] keep swap [ lookup-vocab not ] when
- [ require-hook get call( name -- ) ] [ drop ] if ;
+ [ ".private" ?tail ] keep swap [ lookup-vocab not ] when [
+ [
+ dup requiring get ?adjoin
+ [ require-hook get call( name -- ) ] [ drop ] if
+ ] with-requiring
+ ] [ drop ] if ;
+
+: require-all ( vocabs -- )
+ [ [ require ] each ] with-requiring ;
: load-vocab ( name -- vocab )
[ require ] [ lookup-vocab ] bi ;