"alien.remote-control" require
] unless
-"prettyprint" vocab [
- "stack-checker.errors.prettyprint" require
- "alien.prettyprint" require
- "alien.debugger" require
-] when
+{
+ "stack-checker.errors.prettyprint"
+ "alien.prettyprint"
+ "alien.debugger"
+} [ "prettyprint" swap require-when ] each
"cpu." cpu name>> append require
USING: vocabs.loader vocabs kernel ;\r
IN: bootstrap.handbook\r
\r
-"bootstrap.help" vocab [ "help.handbook" require ] when\r
+"bootstrap.help" "help.handbook" require-when\r
! Copyright (C) 2008, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: vocabs vocabs.loader kernel io.thread threads
+USING: vocabs.loader kernel io.thread threads
compiler.utilities namespaces ;
IN: bootstrap.threads
-"debugger" vocab [
- "debugger.threads" require
-] when
+"debugger" "debugger.threads" require-when
-[ yield ] yield-hook set-global
\ No newline at end of file
+[ yield ] yield-hook set-global
[ "bootstrap." prepend vocab ] all? [
"ui.tools" require
- "ui.backend.cocoa" vocab [
- "ui.backend.cocoa.tools" require
- ] when
+ "ui.backend.cocoa" "ui.backend.cocoa.tools" require-when
"ui.tools.walker" require
] when
USING: vocabs vocabs.loader ;
-"prettyprint" vocab [ "classes.struct.prettyprint" require ] when
+"prettyprint" "classes.struct.prettyprint" require-when
USING: vocabs vocabs.loader ;
-"debugger" vocab [ "http.client.debugger" require ] when
+"debugger" "http.client.debugger" require-when
"locals.fry"
} [ require ] each
-"prettyprint" vocab [
- "locals.definitions" require
- "locals.prettyprint" require
-] when
+"prettyprint" "locals.definitions" require-when
+"prettyprint" "locals.prettyprint" require-when
[ [ dim>> ] dip (>>dim) ]
2bi ; inline
-USING: vocabs vocabs.loader ;
+USE: vocabs.loader
-"prettyprint" vocab [ "math.rectangles.prettyprint" require ] when
+"prettyprint" "math.rectangles.prettyprint" require-when
M: int-4 v*hs+
int-4-rep [ (simd-v*hs+) ] [ call-next-method ] vv->v-op longlong-2-cast ; inline
-"mirrors" vocab [
- "math.vectors.simd.mirrors" require
-] when
+"mirrors" "math.vectors.simd.mirrors" require-when
M: integer make-mirror drop f ;
M: enumerated-sequence make-mirror <enum> ;
M: object make-mirror <mirror> ;
-
-"specialized-arrays" vocab [
- "specialized-arrays.mirrors" require
-] when
USING: vocabs vocabs.loader ;
-"debugger" vocab [
- "peg.debugger" require
-] when
+"debugger" "peg.debugger" require-when
USING: vocabs vocabs.loader ;
-"prettyprint" vocab [
- "regexp.prettyprint" require
-] when
+"prettyprint" "regexp.prettyprint" require-when
SYNTAX: SPECIALIZED-ARRAY:
scan-c-type define-array-vocab use-vocab ;
-"prettyprint" vocab [
- "specialized-arrays.prettyprint" require
-] when
+"prettyprint" "specialized-arrays.prettyprint" require-when
-"mirrors" vocab [
- "specialized-arrays.mirrors" require
-] when
+"mirrors" "specialized-arrays.mirrors" require-when
USING: vocabs vocabs.loader ;
-"prettyprint" vocab [ "typed.prettyprint" require ] when
+"prettyprint" "typed.prettyprint" require-when
: focus-path ( gadget -- seq )
[ focus>> ] follow ;
-USING: vocabs vocabs.loader ;
+USE: vocabs.loader
-"prettyprint" vocab [ "ui.gadgets.prettyprint" require ] when
+"prettyprint" "ui.gadgets.prettyprint" require-when
<<
-"debugger" vocab [
- "unix.debugger" require
-] when
+"debugger" "unix.debugger" require-when
>>
! Literal syntax
SYNTAX: URL" lexer get skip-blank parse-string >url suffix! ;
-USING: vocabs vocabs.loader ;
+USE: vocabs.loader
-"prettyprint" vocab [
- "urls.prettyprint" require
-] when
+"prettyprint" "urls.prettyprint" require-when
SYNTAX: GUID: scan string>guid suffix! ;
-USING: vocabs vocabs.loader ;
+USE: vocabs.loader
-"prettyprint" vocab [
- "windows.com.prettyprint" require
-] when
+"prettyprint" "windows.com.prettyprint" require-when
: with-x ( display-string quot -- )
[ init-x ] dip [ close-x ] [ ] cleanup ; inline
-"io.backend.unix" vocab [ "x11.io.unix" require ] when
\ No newline at end of file
+"io.backend.unix" "x11.io.unix" require-when
--- /dev/null
+! Copyright (C) 2005, 2009 Daniel Ehrenberg
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors arrays assocs combinators
+combinators.short-circuit fry generalizations inverse kernel
+namespaces sequences sorting strings unicode.categories
+xml.data xml.syntax xml.syntax.private ;
+IN: xml.syntax.inverse
+
+: remove-blanks ( seq -- newseq )
+ [ { [ string? not ] [ [ blank? ] all? not ] } 1|| ] filter ;
+
+GENERIC: >xml ( xml -- tag )
+M: xml >xml body>> ;
+M: tag >xml ;
+M: xml-chunk >xml
+ remove-blanks
+ [ length 1 =/fail ]
+ [ first dup tag? [ fail ] unless ] bi ;
+M: object >xml fail ;
+
+: 1chunk ( object -- xml-chunk )
+ 1array <xml-chunk> ;
+
+GENERIC: >xml-chunk ( xml -- chunk )
+M: xml >xml-chunk body>> 1chunk ;
+M: xml-chunk >xml-chunk ;
+M: object >xml-chunk 1chunk ;
+
+GENERIC: [undo-xml] ( xml -- quot )
+
+M: xml [undo-xml]
+ body>> [undo-xml] '[ >xml @ ] ;
+
+M: xml-chunk [undo-xml]
+ seq>> [undo-xml] '[ >xml-chunk @ ] ;
+
+: undo-attrs ( attrs -- quot: ( attrs -- ) )
+ [
+ [ main>> ] dip dup interpolated?
+ [ var>> '[ _ attr _ set ] ]
+ [ '[ _ attr _ =/fail ] ] if
+ ] { } assoc>map '[ _ cleave ] ;
+
+M: tag [undo-xml] ( tag -- quot: ( tag -- ) )
+ {
+ [ name>> main>> '[ name>> main>> _ =/fail ] ]
+ [ attrs>> undo-attrs ]
+ [ children>> [undo-xml] '[ children>> @ ] ]
+ } cleave '[ _ _ _ tri ] ;
+
+: firstn-strong ( seq n -- ... )
+ [ swap length =/fail ]
+ [ firstn ] 2bi ; inline
+
+M: sequence [undo-xml] ( sequence -- quot: ( seq -- ) )
+ remove-blanks [ length ] [ [ [undo-xml] ] { } map-as ] bi
+ '[ remove-blanks _ firstn-strong _ spread ] ;
+
+M: string [undo-xml] ( string -- quot: ( string -- ) )
+ '[ _ =/fail ] ;
+
+M: xml-data [undo-xml] ( datum -- quot: ( datum -- ) )
+ '[ _ =/fail ] ;
+
+M: interpolated [undo-xml]
+ var>> '[ _ set ] ;
+
+: >enum ( assoc -- enum )
+ ! Assumes keys are 0..n
+ >alist sort-keys values <enum> ;
+
+: undo-xml ( xml -- quot )
+ [undo-xml] '[ H{ } clone [ _ bind ] keep >enum ] ;
+
+\ interpolate-xml 1 [ undo-xml ] define-pop-inverse
sequences summary lexer splitting combinators locals
memoize sequences.deep xml.data xml.state xml namespaces present
arrays generalizations strings make math macros multiline
-inverse combinators.short-circuit sorting fry unicode.categories
+combinators.short-circuit sorting fry unicode.categories
effects ;
IN: xml.syntax
SYNTAX: [XML
"XML]" [ string>chunk ] parse-def ;
-<PRIVATE
-
-: remove-blanks ( seq -- newseq )
- [ { [ string? not ] [ [ blank? ] all? not ] } 1|| ] filter ;
-
-GENERIC: >xml ( xml -- tag )
-M: xml >xml body>> ;
-M: tag >xml ;
-M: xml-chunk >xml
- remove-blanks
- [ length 1 =/fail ]
- [ first dup tag? [ fail ] unless ] bi ;
-M: object >xml fail ;
-
-: 1chunk ( object -- xml-chunk )
- 1array <xml-chunk> ;
-
-GENERIC: >xml-chunk ( xml -- chunk )
-M: xml >xml-chunk body>> 1chunk ;
-M: xml-chunk >xml-chunk ;
-M: object >xml-chunk 1chunk ;
-
-GENERIC: [undo-xml] ( xml -- quot )
+USE: vocabs.loader
-M: xml [undo-xml]
- body>> [undo-xml] '[ >xml @ ] ;
-
-M: xml-chunk [undo-xml]
- seq>> [undo-xml] '[ >xml-chunk @ ] ;
-
-: undo-attrs ( attrs -- quot: ( attrs -- ) )
- [
- [ main>> ] dip dup interpolated?
- [ var>> '[ _ attr _ set ] ]
- [ '[ _ attr _ =/fail ] ] if
- ] { } assoc>map '[ _ cleave ] ;
-
-M: tag [undo-xml] ( tag -- quot: ( tag -- ) )
- {
- [ name>> main>> '[ name>> main>> _ =/fail ] ]
- [ attrs>> undo-attrs ]
- [ children>> [undo-xml] '[ children>> @ ] ]
- } cleave '[ _ _ _ tri ] ;
-
-: firstn-strong ( seq n -- ... )
- [ swap length =/fail ]
- [ firstn ] 2bi ; inline
-
-M: sequence [undo-xml] ( sequence -- quot: ( seq -- ) )
- remove-blanks [ length ] [ [ [undo-xml] ] { } map-as ] bi
- '[ remove-blanks _ firstn-strong _ spread ] ;
-
-M: string [undo-xml] ( string -- quot: ( string -- ) )
- '[ _ =/fail ] ;
-
-M: xml-data [undo-xml] ( datum -- quot: ( datum -- ) )
- '[ _ =/fail ] ;
-
-M: interpolated [undo-xml]
- var>> '[ _ set ] ;
-
-: >enum ( assoc -- enum )
- ! Assumes keys are 0..n
- >alist sort-keys values <enum> ;
-
-: undo-xml ( xml -- quot )
- [undo-xml] '[ H{ } clone [ _ bind ] keep >enum ] ;
-
-\ interpolate-xml 1 [ undo-xml ] define-pop-inverse
-
-PRIVATE>
+"inverse" "xml.syntax.inverse" require-when
{ $subsections "vocabs.metadata" "vocabs.icons" }
"Vocabularies can also be loaded at run time, without altering the vocabulary search path. This is done by calling a word which loads a vocabulary if it is not in the image, doing nothing if it is:"
{ $subsections require }
-"The above word will only ever load a vocabulary once in a given session. There is another word which unconditionally loads vocabulary from disk, regardless of whether or not is has already been loaded:"
+"The above word will only ever load a vocabulary once in a given session. Sometimes, two vocabularies require special code to interact. The following word is used to load one vocabulary when another is present:"
+{ $subsections require-when }
+"There is another word which unconditionally loads vocabulary from disk, regardless of whether or not is has already been loaded:"
{ $subsections reload }
"For interactive development in the listener, calling " { $link reload } " directly is usually not necessary, since a better facility exists for " { $link "vocabs.refresh" } "."
$nl
{ $description "Loads a vocabulary if it has not already been loaded." }
{ $notes "To unconditionally reload a vocabulary, use " { $link reload } ". To reload changed source files only, use the words in " { $link "vocabs.refresh" } "." } ;
+HELP: require-when
+{ $values { "if" "a vocabulary specifier" } { "then" "a vocabulary specifier" } }
+{ $description "Loads the " { $snippet "then" } " vocabulary if it is not loaded and the " { $snippet "if" } " vocabulary is. If the " { $snippet "if" } " vocabulary is not loaded now, but it is later, then the " { $snippet "then" } " vocabulary will be loaded along with it at that time." }
+{ $notes "This is used to express a joint dependency of vocabularies. If vocabularies " { $snippet "a" } " and " { $snippet "b" } " use code in vocabulary " { $snippet "c" } " to interact, then the following line can be placed in " { $snippet "a" } " in order express the dependency."
+{ $code "\"b\" \"c\" require-when" } } ;
+
HELP: run
{ $values { "vocab" "a vocabulary specifier" } }
{ $description "Runs a vocabulary's main entry point. The main entry point is set with the " { $link POSTPONE: MAIN: } " parsing word." } ;
] 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
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 -- )
[
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 -- )
: require ( vocab -- )
load-vocab drop ;
+: require-when ( if then -- )
+ over vocab
+ [ nip require ]
+ [ swap conditional-requires get [ swap suffix ] change-at ]
+ if ;
+
: reload ( name -- )
dup vocab
[ [ load-source ] [ load-docs ] bi ]
--- /dev/null
+USE: vocabs.loader
+IN: vocabs.loader.test.m
+
+"vocabs.loader.test.o" "vocabs.loader.test.n" require-when
--- /dev/null
+IN: vocabs.loader.test.n
--- /dev/null
+IN: vocabs.loader.test.o
! 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
: 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
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 ;
USING: vocabs vocabs.loader ;
-"prettyprint" vocab [ "game.loop.prettyprint" require ] when
+"prettyprint" "game.loop.prettyprint" require-when
[ world>> ] [ program>> instances>> ] [ ] tri ?delete-at
reset-memos ;
-"prettyprint" vocab [ "gpu.shaders.prettyprint" require ] when
+"prettyprint" "gpu.shaders.prettyprint" require-when