2006-06-18 20:58:11 -04:00
|
|
|
! Copyright (C) 2006 Slava Pestov.
|
|
|
|
! See http://factorcode.org/license.txt for BSD license.
|
|
|
|
IN: modules
|
2006-09-06 18:06:11 -04:00
|
|
|
USING: hashtables io kernel namespaces parser sequences
|
2006-12-07 22:53:50 -05:00
|
|
|
words strings arrays math help errors ;
|
2006-06-18 20:58:11 -04:00
|
|
|
|
2006-09-06 19:49:48 -04:00
|
|
|
SYMBOL: modules
|
|
|
|
|
2006-12-07 22:53:50 -05:00
|
|
|
TUPLE: module name loc directory files tests help main ;
|
2006-11-17 01:40:23 -05:00
|
|
|
|
2006-09-06 19:49:48 -04:00
|
|
|
: module-def ( name -- path )
|
2006-12-10 14:59:32 -05:00
|
|
|
"resource:" over "/load.factor" 3append
|
2006-09-29 23:03:27 -04:00
|
|
|
dup ?resource-path exists? [
|
|
|
|
nip
|
|
|
|
] [
|
2006-12-10 14:59:32 -05:00
|
|
|
drop "resource:" swap ".factor" 3append
|
2006-09-29 23:03:27 -04:00
|
|
|
] if ;
|
2006-06-18 20:58:11 -04:00
|
|
|
|
2006-10-28 02:44:12 -04:00
|
|
|
: module modules get [ module-name = ] find-with nip ;
|
2006-06-18 20:58:11 -04:00
|
|
|
|
2006-11-10 22:49:03 -05:00
|
|
|
: process-files ( name seq -- newseq )
|
2006-09-06 17:01:38 -04:00
|
|
|
[ dup string? [ [ t ] 2array ] when ] map
|
|
|
|
[ second call ] subset
|
2006-11-10 22:49:03 -05:00
|
|
|
0 <column> >array
|
|
|
|
[ path+ "resource:" swap append ] map-with ;
|
|
|
|
|
|
|
|
: module-files* ( module -- seq )
|
2006-12-07 22:53:50 -05:00
|
|
|
dup module-directory swap module-files process-files ;
|
2006-11-10 22:49:03 -05:00
|
|
|
|
2006-12-10 21:33:13 -05:00
|
|
|
: loading-module ( name -- )
|
|
|
|
"quiet" get [
|
|
|
|
drop
|
|
|
|
] [
|
2006-12-11 02:47:57 -05:00
|
|
|
"Loading module " write print flush
|
2006-12-10 21:33:13 -05:00
|
|
|
] if ;
|
|
|
|
|
2006-11-18 03:51:34 -05:00
|
|
|
: load-module ( name -- )
|
|
|
|
[
|
2006-12-10 21:33:13 -05:00
|
|
|
dup loading-module
|
2006-11-18 03:51:34 -05:00
|
|
|
[ dup module-def run-file ] assert-depth drop
|
|
|
|
] no-parse-hook ;
|
|
|
|
|
|
|
|
: reload-module ( module -- )
|
|
|
|
dup module-name module-def source-modified? [
|
|
|
|
module-name load-module
|
|
|
|
] [
|
|
|
|
module-files* [ source-modified? ] subset run-files
|
|
|
|
] if ;
|
|
|
|
|
2006-12-07 22:53:50 -05:00
|
|
|
: reload-modules ( -- )
|
|
|
|
modules get [ reload-module ] each do-parse-hook ;
|
|
|
|
|
2006-11-18 03:51:34 -05:00
|
|
|
: require ( name -- )
|
2006-12-08 01:30:37 -05:00
|
|
|
dup module [ drop ] [ load-module ] if do-parse-hook ;
|
2006-11-18 03:51:34 -05:00
|
|
|
|
2006-09-08 21:12:18 -04:00
|
|
|
: remove-module ( name -- )
|
2006-10-28 02:44:12 -04:00
|
|
|
module [ modules get delete ] when* ;
|
2006-09-08 21:12:18 -04:00
|
|
|
|
2006-11-10 22:49:03 -05:00
|
|
|
: alist>module ( name loc hash -- module )
|
|
|
|
alist>hash [
|
2006-12-07 22:53:50 -05:00
|
|
|
+directory+ get [ over ] unless*
|
|
|
|
+files+ get
|
|
|
|
+tests+ get
|
|
|
|
+help+ get
|
2006-11-10 22:49:03 -05:00
|
|
|
] bind f <module> ;
|
|
|
|
|
|
|
|
: module>alist ( module -- hash )
|
|
|
|
[
|
2006-12-07 22:53:50 -05:00
|
|
|
+directory+ over module-directory 2array ,
|
2006-11-10 22:49:03 -05:00
|
|
|
+files+ over module-files 2array ,
|
|
|
|
+tests+ over module-tests 2array ,
|
|
|
|
+help+ swap module-help 2array ,
|
|
|
|
] { } make ;
|
|
|
|
|
|
|
|
: provide ( name loc hash -- )
|
|
|
|
pick remove-module
|
|
|
|
alist>module
|
|
|
|
[ module-files* run-files ] keep
|
2006-10-28 02:44:12 -04:00
|
|
|
modules get push ;
|