Merge git://factorcode.org/git/factor

db4
Doug Coleman 2011-08-17 22:07:57 -07:00
commit 46dac71d45
5 changed files with 22 additions and 8 deletions

View File

@ -135,7 +135,7 @@ $nl
ARTICLE: "cli" "Command line arguments" ARTICLE: "cli" "Command line arguments"
"Factor command line usage:" "Factor command line usage:"
{ $code "factor [VM args...] [script] [args...]" } { $code "factor [VM args...] [script] [args...]" }
"Zero or more VM arguments can be passed in, followed by an optional script file name. If the script file is specified, it will be run on startup, any arguments after the script file are stored in the following variable, with no further processing by Factor itself:" "Zero or more VM arguments can be passed in, followed by an optional script file name. If the script file is specified, it will be run on startup using " { $link run-script } ". Any arguments after the script file are stored in the following variable, with no further processing by Factor itself:"
{ $subsections command-line } { $subsections command-line }
"Instead of running a script, it is also possible to run a vocabulary; this invokes the vocabulary's " { $link POSTPONE: MAIN: } " word:" "Instead of running a script, it is also possible to run a vocabulary; this invokes the vocabulary's " { $link POSTPONE: MAIN: } " word:"
{ $code "factor [system switches...] -run=<vocab name>" } { $code "factor [system switches...] -run=<vocab name>" }
@ -159,4 +159,9 @@ $nl
"There is a way to override the default vocabulary to run on startup, if no script name or " { $snippet "-run" } " switch is specified:" "There is a way to override the default vocabulary to run on startup, if no script name or " { $snippet "-run" } " switch is specified:"
{ $subsections main-vocab-hook } ; { $subsections main-vocab-hook } ;
HELP: run-script
{ $values { "file" "a pathname string" } }
{ $description "Parses the Factor source code stored in a file and runs it. The initial vocabulary search path is used. If the source file contains a " { $link POSTPONE: MAIN: } " declaration, the main entry point of the file will be also be executed. Loading messages will be suppressed." }
{ $errors "Throws an error if loading the file fails, there input is malformed, or if a runtime error occurs while calling the parsed quotation or executing the main entry point." } ;
ABOUT: "cli" ABOUT: "cli"

View File

@ -2,7 +2,8 @@
! See http://factorcode.org/license.txt for BSD license. ! See http://factorcode.org/license.txt for BSD license.
USING: init continuations hashtables io io.encodings.utf8 USING: init continuations hashtables io io.encodings.utf8
io.files io.pathnames kernel kernel.private namespaces parser io.files io.pathnames kernel kernel.private namespaces parser
sequences strings system splitting vocabs.loader alien.strings ; sequences source-files strings system splitting vocabs.loader
alien.strings accessors ;
IN: command-line IN: command-line
SYMBOL: script SYMBOL: script
@ -39,7 +40,10 @@ SYMBOL: command-line
"=" split1 [ var-param ] [ bool-param ] if* ; "=" split1 [ var-param ] [ bool-param ] if* ;
: run-script ( file -- ) : run-script ( file -- )
t "quiet" set-global run-file ; t "quiet" [
[ run-file ]
[ source-file main>> [ execute( -- ) ] when* ] bi
] with-variable ;
: parse-command-line ( args -- ) : parse-command-line ( args -- )
[ command-line off script off ] [ [ command-line off script off ] [

View File

@ -13,7 +13,8 @@ TUPLE: source-file
path path
top-level-form top-level-form
checksum checksum
definitions ; definitions
main ;
: record-top-level-form ( quot file -- ) : record-top-level-form ( quot file -- )
top-level-form<< top-level-form<<

View File

@ -1,7 +1,7 @@
USING: generic help.syntax help.markup kernel math parser words USING: generic help.syntax help.markup kernel math parser words
effects classes classes.tuple generic.math generic.single arrays effects classes classes.tuple generic.math generic.single arrays
io.pathnames vocabs.loader io sequences assocs words.symbol io.pathnames vocabs.loader io sequences assocs words.symbol
words.alias words.constant combinators vocabs.parser ; words.alias words.constant combinators vocabs.parser command-line ;
IN: syntax IN: syntax
ARTICLE: "parser-algorithm" "Parser algorithm" ARTICLE: "parser-algorithm" "Parser algorithm"
@ -858,7 +858,7 @@ HELP: C:
HELP: MAIN: HELP: MAIN:
{ $syntax "MAIN: word" } { $syntax "MAIN: word" }
{ $values { "word" word } } { $values { "word" word } }
{ $description "Defines the main entry point for the current vocabulary. This word will be executed when this vocabulary is passed to " { $link run } "." } ; { $description "Defines the main entry point for the current vocabulary and source file. This word will be executed when this vocabulary is passed to " { $link run } " or the source file is passed to " { $link run-script } "." } ;
HELP: <PRIVATE HELP: <PRIVATE
{ $syntax "<PRIVATE ... PRIVATE>" } { $syntax "<PRIVATE ... PRIVATE>" }

View File

@ -8,7 +8,7 @@ generic.standard generic.hook generic.math generic.parser classes
io.pathnames vocabs vocabs.parser classes.parser classes.union io.pathnames vocabs vocabs.parser classes.parser classes.union
classes.intersection classes.mixin classes.predicate classes.intersection classes.mixin classes.predicate
classes.singleton classes.tuple.parser compiler.units classes.singleton classes.tuple.parser compiler.units
combinators effects.parser slots hash-sets ; combinators effects.parser slots hash-sets source-files ;
IN: bootstrap.syntax IN: bootstrap.syntax
! These words are defined as a top-level form, instead of with ! These words are defined as a top-level form, instead of with
@ -233,7 +233,11 @@ IN: bootstrap.syntax
"))" parse-effect suffix! "))" parse-effect suffix!
] define-core-syntax ] define-core-syntax
"MAIN:" [ scan-word current-vocab main<< ] define-core-syntax "MAIN:" [
scan-word
[ current-vocab main<< ]
[ file get [ main<< ] [ drop ] if* ] bi
] define-core-syntax
"<<" [ "<<" [
[ [