New module system

darcs
slava 2006-06-19 00:58:11 +00:00
parent 4297d2b4f2
commit 0205234638
22 changed files with 165 additions and 127 deletions

View File

@ -1,7 +1,6 @@
IN: scratchpad IN: scratchpad
USING: kernel parser sequences words compiler ; USING: kernel parser sequences words compiler ;
{ REQUIRE: crypto ;
"net-bytes"
"aim" PROVIDE: aim { "net-bytes.factor" "aim.factor" } ;
} [ "/contrib/aim/" swap ".factor" append3 run-resource ] each

10
contrib/all.factor Normal file
View File

@ -0,0 +1,10 @@
USING: modules words ;
REQUIRE: aim cairo concurrency coroutines crypto dlists
gap-buffer httpd math postgresql process random-tester
splay-trees sqlite units ;
"x11" vocab [
"factory" require
"x11" require
]

View File

@ -3,6 +3,6 @@ USING: alien kernel parser compiler words sequences ;
"cairo" "libcairo" add-simple-library "cairo" "libcairo" add-simple-library
"/contrib/cairo/cairo.factor" run-resource PROVIDE: cairo { "/contrib/cairo/cairo.factor" } ;
{ "cairo" } compile-vocabs { "cairo" } compile-vocabs

View File

@ -1,6 +1,7 @@
IN: scratchpad USING: modules ;
USING: kernel parser compiler words sequences ;
"/contrib/concurrency/concurrency.factor" run-resource REQUIRE: dlists ;
"/contrib/concurrency/concurrency-examples.factor" run-resource
"/contrib/concurrency/concurrency-tests.factor" run-resource PROVIDE: concurrency
{ "concurrency.factor" }
{ "concurrency-examples.factor" "concurrency-tests.factor" } ;

View File

@ -69,3 +69,5 @@ test2 f swap coresume . f swap coresume . f swap coresume . drop
test3 f swap coresume . f swap coresume . f swap coresume . drop test3 f swap coresume . f swap coresume . f swap coresume . drop
PROVIDE: coroutines ;

View File

@ -1,26 +1,28 @@
IN: scratchpad IN: scratchpad
USING: kernel parser sequences words compiler ; USING: kernel parser sequences words compiler ;
{ REQUIRE: math ;
"common"
"base64" PROVIDE: crypto {
"barrett" "common.factor"
"montgomery" "base64.factor"
"random" "barrett.factor"
"miller-rabin" "montgomery.factor"
"random.factor"
"miller-rabin.factor"
! Rngs ! Rngs
"blum-blum-shub" "blum-blum-shub.factor"
! Hash ! Hash
"crc32" "crc32.factor"
"md5" "md5.factor"
"sha1" "sha1.factor"
! Block ciphers ! Block ciphers
"rc4" "rc4.factor"
! Public key ! Public key
"rsa" "rsa.factor"
} [ "/contrib/crypto/" swap ".factor" append3 run-resource ] each } ;

View File

@ -1,6 +1,7 @@
! Copyright (C) 2005 Mackenzie Straight. ! Copyright (C) 2005 Mackenzie Straight.
! See http://factor.sf.net/license.txt for BSD license. ! See http://factor.sf.net/license.txt for BSD license.
IN: dlists USING: generic kernel math ; IN: dlists
USING: generic kernel math modules ;
! Double-linked lists. ! Double-linked lists.
@ -60,3 +61,5 @@ C: dlist-node
: dlist-length ( dlist -- length ) : dlist-length ( dlist -- length )
0 swap [ drop 1 + ] dlist-each ; 0 swap [ drop 1 + ] dlist-each ;
PROVIDE: dlists ;

View File

@ -0,0 +1,5 @@
USING: modules ;
REQUIRE: process concurrency x11 ;
PROVIDE: factory { "factory.factor" } ;

View File

@ -1,13 +1,5 @@
USING: kernel sequences parser words compiler ; USING: kernel sequences parser words compiler ;
[ "circular" "gap-buffer" ] PROVIDE: gap-buffer
{ "circular.factor" "gap-buffer.factor" }
! load { "circular-tests.factor" "gap-buffer-tests.factor" } ;
dup [ "contrib/gap-buffer/" swap append ".factor" append run-file ] each
! compile
dup [ words [ try-compile ] each ] each
! test
[ "contrib/gap-buffer/" swap append "-tests.factor" append run-file ] each

View File

@ -1,30 +1,30 @@
IN: scratchpad IN: scratchpad
USING: words kernel parser sequences io compiler ; USING: words kernel parser sequences io compiler ;
{ PROVIDE: httpd {
"mime" "mime.factor"
"xml" "xml.factor"
"http-common" "http-common.factor"
"html-tags" "html-tags.factor"
"responder" "responder.factor"
"httpd" "httpd.factor"
"cont-responder" "cont-responder.factor"
"callback-responder" "callback-responder.factor"
"prototype-js" "prototype-js.factor"
"html" "html.factor"
"embedded" "embedded.factor"
"file-responder" "file-responder.factor"
"help-responder" "help-responder.factor"
"inspect-responder" "inspect-responder.factor"
"browser-responder" "browser-responder.factor"
"default-responders" "default-responders.factor"
"http-client" "http-client.factor"
"test/html" "test/html.factor"
"test/http-client" "test/http-client.factor"
"test/httpd" "test/httpd.factor"
"test/url-encoding" "test/url-encoding.factor"
} [ "/contrib/httpd/" swap ".factor" append3 run-resource ] each } ;
"To start the HTTP server, issue the following command in the listener:" print "To start the HTTP server, issue the following command in the listener:" print
" USE: httpd" print " USE: httpd" print

View File

@ -1,21 +0,0 @@
USING: kernel parser sequences ;
{
"coroutines"
"dlists"
"process"
"splay-trees"
} [ "/contrib/" swap ".factor" append3 run-resource ] each
{
"cairo"
"concurrency"
"math"
"crypto"
"aim"
"gap-buffer"
"httpd"
"units"
"sqlite"
"postgresql"
"random-tester"
} [ "/contrib/" swap "/load.factor" append3 run-resource ] each

View File

@ -1,13 +1,13 @@
IN: scratchpad IN: scratchpad
USING: kernel parser sequences words compiler ; USING: modules ;
{ PROVIDE: math {
"utils" "utils.factor"
"combinatorics" "combinatorics.factor"
"analysis" "analysis.factor"
"polynomials" "polynomials.factor"
"quaternions" "quaternions.factor"
"matrices" "matrices.factor"
"statistics" "statistics.factor"
"numerical-integration" "numerical-integration.factor"
} [ "/contrib/math/" swap ".factor" append3 run-resource ] each } ;

View File

@ -1,11 +1,7 @@
IN: scratchpad USING: alien modules ;
USING: alien compiler kernel parser sequences words ;
"postgresql" "libpq" add-simple-library "postgresql" "libpq" add-simple-library
{ PROVIDE: postgresql
"libpq" { "libpq" "postgresql" }
"postgresql" { "postgresql-test" } ;
"postgresql-test"
! "private" ! Put your password in this file
} [ "/contrib/postgresql/" swap ".factor" append3 run-resource ] each

View File

@ -9,3 +9,5 @@ FUNCTION: void* popen ( char* command, char* type ) ; compiled
popen dup <c-stream> ; popen dup <c-stream> ;
: !" parse-string system drop ; parsing : !" parse-string system drop ; parsing
PROVIDE: process ;

View File

@ -1,8 +1,5 @@
USING: kernel parser sequences words compiler ; PROVIDE: random-tester {
IN: scratchpad "utils.factor"
"random.factor"
{ "random-tester.factor"
"utils" } ;
"random"
"random-tester"
} [ "/contrib/random-tester/" swap ".factor" append3 run-resource ] each

View File

@ -113,3 +113,5 @@ USING: namespaces words ;
<splay-tree> "foo" set <splay-tree> "foo" set
all-words [ dup word-name "foo" get set-splay ] each all-words [ dup word-name "foo" get set-splay ] each
all-words [ dup word-name "foo" get get-splay drop ] each all-words [ dup word-name "foo" get get-splay drop ] each
PROVIDE: splay-trees ;

View File

@ -1,9 +1,7 @@
IN: scratchpad USING: alien ;
USING: kernel alien parser compiler words sequences ;
"sqlite" "libsqlite3" add-simple-library "sqlite" "libsqlite3" add-simple-library
{ PROVIDE: sqlite
"sqlite" { "sqlite.factor" "tuple-db.factor" }
"tuple-db" { "tuple-db-tests.factor" } ;
} [ "/contrib/sqlite/" swap ".factor" append3 run-resource ] each

View File

@ -1,8 +1,2 @@
IN: scratchpad PROVIDE: units
USING: kernel parser sequences words compiler ; { "dimensioned.factor" "si-units.factor" "constants.factor" } ;
{
"dimensioned"
"si-units"
"constants"
} [ "/contrib/units/" swap ".factor" append3 run-resource ] each

View File

@ -1,6 +1,5 @@
USING: kernel parser words compiler sequences ; REQUIRE: concurrency ;
! contrib/x11 depends on contrib/concurrency PROVIDE: x11 {
"rectangle.factor" "x.factor" "draw-string.factor" "concurrent-widgets.factor" "gl.factor"
{ "rectangle" "x" "draw-string" "concurrent-widgets" "gl" } } ;
[ "/contrib/x11/" swap ".factor" append3 run-resource ] each

View File

@ -117,6 +117,7 @@ vectors words ;
"/library/test/test.factor" "/library/test/test.factor"
"/library/modules.factor"
"/library/threads.factor" "/library/threads.factor"
"/library/io/server.factor" "/library/io/server.factor"

49
library/modules.factor Normal file
View File

@ -0,0 +1,49 @@
! Copyright (C) 2006 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
IN: modules
USING: hashtables io kernel namespaces parser sequences words ;
TUPLE: module name files tests ;
: module-path ( name -- path )
"/contrib/" swap append ;
: module-paths ( name seq -- seq )
>r module-path r> [ "/" swap append3 ] map-with ;
C: module ( name files tests -- module )
[ >r >r over r> module-paths r> set-module-tests ] keep
[ >r dupd module-paths r> set-module-files ] keep
[ set-module-name ] keep ;
: module-def ( name -- path )
module-path dup ".factor" append dup resource-path exists?
[ nip ] [ drop "/load.factor" append ] if ;
SYMBOL: modules
H{ } clone modules set-global
: module modules get hash ;
: require ( name -- )
dup module [
drop
] [
"Loading module " write dup write "..." print
module-def run-resource
] if ;
: run-resources ( seq -- )
bootstrapping? get
[ parse-resource % ] [ run-resource ] ? each ;
: load-module ( module -- ) module-files run-resources ;
: provide ( name files tests -- )
<module> dup load-module
dup module-name modules get set-hash ;
: reload-module ( name -- ) module load-module ;
: test-module ( name -- ) module module-tests run-resources ;

View File

@ -4,7 +4,7 @@
! Bootstrapping trick; see doc/bootstrap.txt. ! Bootstrapping trick; see doc/bootstrap.txt.
IN: !syntax IN: !syntax
USING: alien arrays errors generic hashtables kernel math USING: alien arrays errors generic hashtables kernel math
namespaces parser sequences strings syntax vectors words ; modules namespaces parser sequences strings syntax vectors words ;
: ( : (
CHAR: ) column [ CHAR: ) column [
@ -69,3 +69,10 @@ DEFER: PRIMITIVE: parsing
[ define-constructor ] f ; parsing [ define-constructor ] f ; parsing
: FORGET: scan use get hash-stack [ forget ] when* ; parsing : FORGET: scan use get hash-stack [ forget ] when* ; parsing
: PROVIDE:
scan [ { { } { } } append first2 provide ] f ; parsing
: REQUIRE:
string-mode on
[ string-mode off [ require ] each ] f ; parsing