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
USING: kernel parser sequences words compiler ;
{
"net-bytes"
"aim"
} [ "/contrib/aim/" swap ".factor" append3 run-resource ] each
REQUIRE: crypto ;
PROVIDE: aim { "net-bytes.factor" "aim.factor" } ;

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
"/contrib/cairo/cairo.factor" run-resource
PROVIDE: cairo { "/contrib/cairo/cairo.factor" } ;
{ "cairo" } compile-vocabs

View File

@ -1,6 +1,7 @@
IN: scratchpad
USING: kernel parser compiler words sequences ;
USING: modules ;
"/contrib/concurrency/concurrency.factor" run-resource
"/contrib/concurrency/concurrency-examples.factor" run-resource
"/contrib/concurrency/concurrency-tests.factor" run-resource
REQUIRE: dlists ;
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
PROVIDE: coroutines ;

View File

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

View File

@ -1,6 +1,7 @@
! Copyright (C) 2005 Mackenzie Straight.
! 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.
@ -60,3 +61,5 @@ C: dlist-node
: dlist-length ( dlist -- length )
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 ;
[ "circular" "gap-buffer" ]
! load
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
PROVIDE: gap-buffer
{ "circular.factor" "gap-buffer.factor" }
{ "circular-tests.factor" "gap-buffer-tests.factor" } ;

View File

@ -1,30 +1,30 @@
IN: scratchpad
USING: words kernel parser sequences io compiler ;
{
"mime"
"xml"
"http-common"
"html-tags"
"responder"
"httpd"
"cont-responder"
"callback-responder"
"prototype-js"
"html"
"embedded"
"file-responder"
"help-responder"
"inspect-responder"
"browser-responder"
"default-responders"
"http-client"
PROVIDE: httpd {
"mime.factor"
"xml.factor"
"http-common.factor"
"html-tags.factor"
"responder.factor"
"httpd.factor"
"cont-responder.factor"
"callback-responder.factor"
"prototype-js.factor"
"html.factor"
"embedded.factor"
"file-responder.factor"
"help-responder.factor"
"inspect-responder.factor"
"browser-responder.factor"
"default-responders.factor"
"http-client.factor"
"test/html"
"test/http-client"
"test/httpd"
"test/url-encoding"
} [ "/contrib/httpd/" swap ".factor" append3 run-resource ] each
"test/html.factor"
"test/http-client.factor"
"test/httpd.factor"
"test/url-encoding.factor"
} ;
"To start the HTTP server, issue the following command in the listener:" 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
USING: kernel parser sequences words compiler ;
USING: modules ;
{
"utils"
"combinatorics"
"analysis"
"polynomials"
"quaternions"
"matrices"
"statistics"
"numerical-integration"
} [ "/contrib/math/" swap ".factor" append3 run-resource ] each
PROVIDE: math {
"utils.factor"
"combinatorics.factor"
"analysis.factor"
"polynomials.factor"
"quaternions.factor"
"matrices.factor"
"statistics.factor"
"numerical-integration.factor"
} ;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -117,6 +117,7 @@ vectors words ;
"/library/test/test.factor"
"/library/modules.factor"
"/library/threads.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.
IN: !syntax
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 [
@ -69,3 +69,10 @@ DEFER: PRIMITIVE: parsing
[ define-constructor ] f ; 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