From 4ddc751365cce6e9abdf8297a4924656403b5476 Mon Sep 17 00:00:00 2001 From: slava Date: Fri, 20 Oct 2006 02:41:20 +0000 Subject: [PATCH] run-module word --- TODO.FACTOR.txt | 2 +- contrib/factory/README.txt | 4 ++-- contrib/factory/load.factor | 4 ++++ contrib/httpd/httpd.factor | 7 ++++--- contrib/httpd/load.factor | 6 ++---- contrib/lambda/load.factor | 5 ++++- contrib/space-invaders/load.factor | 5 +++++ contrib/space-invaders/readme.txt | 5 ++--- contrib/tetris/README.txt | 3 +-- contrib/tetris/load.factor | 4 ++++ library/modules.factor | 14 ++++++++++++-- library/syntax/parse-syntax.factor | 3 +++ 12 files changed, 44 insertions(+), 18 deletions(-) diff --git a/TODO.FACTOR.txt b/TODO.FACTOR.txt index 5174c03839..159959e3c9 100644 --- a/TODO.FACTOR.txt +++ b/TODO.FACTOR.txt @@ -8,6 +8,7 @@ + ui: +- x11 double click - menu should stay up if mouse button released - completion is not ideal: eg, search for "buttons" - some way of intercepting all gestures @@ -35,7 +36,6 @@ + module system: -- convention for main entry point of a module - convention for main help article of a module - track a list of assets loaded from each module's file - C types should be words diff --git a/contrib/factory/README.txt b/contrib/factory/README.txt index a0896ca9c5..e06749f361 100644 --- a/contrib/factory/README.txt +++ b/contrib/factory/README.txt @@ -4,7 +4,7 @@ Loading factory Putting factory into your image is as simple as this: - "factory" require save + "contrib/factory" require save ---------------------------------------------------------------------- Running factory in Xnest @@ -17,7 +17,7 @@ can use 2 or greater. Start factor and launch factory on the appropriate display: - USE: factory ":2" start-factory + "contrib/factory" run-module In a terminal, start an application on the appropriate display: diff --git a/contrib/factory/load.factor b/contrib/factory/load.factor index 2873c0596c..7e5229717c 100644 --- a/contrib/factory/load.factor +++ b/contrib/factory/load.factor @@ -2,3 +2,7 @@ REQUIRES: contrib/process contrib/concurrency contrib/x11 contrib/vars ; PROVIDE: contrib/factory { "factory.factor" } ; + +USE: factory + +MAIN: contrib/factory f start-factory ; diff --git a/contrib/httpd/httpd.factor b/contrib/httpd/httpd.factor index 003ec82d91..8b8a794bbf 100644 --- a/contrib/httpd/httpd.factor +++ b/contrib/httpd/httpd.factor @@ -1,8 +1,8 @@ -! Copyright (C) 2003, 2005 Slava Pestov. -! See http://factor.sf.net/license.txt for BSD license. +! Copyright (C) 2003, 2006 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. IN: httpd USING: errors hashtables kernel namespaces io strings -threads http sequences ; +threads http sequences prettyprint ; : (url>path) ( uri -- path ) url-decode "http://" ?head [ @@ -50,6 +50,7 @@ threads http sequences ; ] if ; : httpd ( port -- ) + "Starting HTTP server on port " write dup . flush \ httpd [ 60000 stdio get set-timeout readln [ parse-request ] when* diff --git a/contrib/httpd/load.factor b/contrib/httpd/load.factor index 88679f19ea..ead65428ef 100644 --- a/contrib/httpd/load.factor +++ b/contrib/httpd/load.factor @@ -21,7 +21,5 @@ PROVIDE: contrib/httpd { "test/url-encoding.factor" } ; -"To start the HTTP server, issue the following command in the listener:" print -" USE: httpd" print -" [ 8888 httpd ] in-thread" print -"Replacing '8888' with whatever port number you desire." print +USE: httpd +MAIN: contrib/httpd 8888 httpd ; diff --git a/contrib/lambda/load.factor b/contrib/lambda/load.factor index 915ff01146..45dd6efe6b 100644 --- a/contrib/lambda/load.factor +++ b/contrib/lambda/load.factor @@ -6,4 +6,7 @@ PROVIDE: contrib/lambda { "lambda.factor" } { "test/lambda.factor" -} ; \ No newline at end of file +} ; + +USE: lambda +MAIN: contrib/lambda lambda ; \ No newline at end of file diff --git a/contrib/space-invaders/load.factor b/contrib/space-invaders/load.factor index 1fa2adfca5..aba30a4ad6 100644 --- a/contrib/space-invaders/load.factor +++ b/contrib/space-invaders/load.factor @@ -1,5 +1,10 @@ REQUIRES: contrib/parser-combinators contrib/concurrency ; + PROVIDE: contrib/space-invaders { "cpu-8080.factor" "space-invaders.factor" } { } ; + +USE: space-invaders + +MAIN: contrib/space-invaders run ; diff --git a/contrib/space-invaders/readme.txt b/contrib/space-invaders/readme.txt index 6f7c1bbe7e..f996d2f869 100644 --- a/contrib/space-invaders/readme.txt +++ b/contrib/space-invaders/readme.txt @@ -4,9 +4,8 @@ emulator, disassembler and assembler for the 8080 processor. It is integrated into the Factor module system, the following will load all necessary files and run it: - "space-invaders" require - USE: space-invaders - run + "contrib/space-invaders" require + "contrib/space-invaders" run-module For this to work it needs a ROM file called 'invaders.rom' in the factor root directory. diff --git a/contrib/tetris/README.txt b/contrib/tetris/README.txt index 49d3b6a628..99ce69937d 100644 --- a/contrib/tetris/README.txt +++ b/contrib/tetris/README.txt @@ -1,8 +1,7 @@ This is a simple tetris game. To play, open factor (in GUI mode), and run: "contrib/tetris" require -USING: tetris-gadget tetris ; -tetris-window +"contrib/tetris" run-module This should open a new window with a running tetris game. The commands are: diff --git a/contrib/tetris/load.factor b/contrib/tetris/load.factor index 644b0a4949..7a2a16fcd9 100644 --- a/contrib/tetris/load.factor +++ b/contrib/tetris/load.factor @@ -10,3 +10,7 @@ PROVIDE: contrib/tetris { } { "test/tetris-piece.factor" "test/tetris-board.factor" "test/tetris.factor" } ; + +USE: tetris + +MAIN: contrib/tetris tetris-window ; diff --git a/library/modules.factor b/library/modules.factor index 78361b9154..1acb720bae 100644 --- a/library/modules.factor +++ b/library/modules.factor @@ -2,11 +2,11 @@ ! See http://factorcode.org/license.txt for BSD license. IN: modules USING: hashtables io kernel namespaces parser sequences -test words strings arrays math ; +test words strings arrays math help ; SYMBOL: modules -TUPLE: module name files tests ; +TUPLE: module name files tests main ; : module-def ( name -- path ) "resource:" over ".factor" append3 @@ -74,3 +74,13 @@ C: module ( name files tests -- module ) : reload-modules ( -- ) all-modules [ reload-module ] each do-parse-hook ; + +: run-module ( name -- ) + dup module module-main [ + call + ] [ + "The module " write write + " does not define an entry point." print + "To define one, see the documentation for the " write + \ MAIN: ($link) " word." print + ] ?if ; diff --git a/library/syntax/parse-syntax.factor b/library/syntax/parse-syntax.factor index 030520b3a6..e0768f93cc 100644 --- a/library/syntax/parse-syntax.factor +++ b/library/syntax/parse-syntax.factor @@ -81,6 +81,9 @@ DEFER: !PRIMITIVE: parsing [ [ require ] each ] no-parse-hook ] f ; parsing +: !MAIN: + scan [ swap module set-module-main ] f ; parsing + : !( parse-effect word [ swap "declared-effect" set-word-prop