ARTICLE: "cli" "Command line arguments"
"Factor command line usage:"
{ $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-file } ". Any arguments after the script file are stored in the following variable, with no further processing by Factor itself:"
{ $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:"
{ $code "factor [system switches...] -run=<vocab name>" }
HELP: run-file
{ $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." }
-{ $errors "Throws an error if loading the file fails, there input is malformed, or if a runtime error occurs while calling the parsed quotation." } ;
+{ $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." }
+{ $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." } ;
HELP: ?run-file
{ $values { "path" "a pathname string" } }
] recover ;
: run-file ( file -- )
- parse-file call( -- ) ;
+ [ parse-file call( -- ) ]
+ [ source-file main>> [ execute( -- ) ] when* ] bi ;
: ?run-file ( path -- )
dup exists? [ run-file ] [ drop ] if ;
path
top-level-form
checksum
-definitions ;
+definitions
+main ;
: record-top-level-form ( quot file -- )
top-level-form<<
HELP: MAIN:
{ $syntax "MAIN: 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-file } "." } ;
HELP: <PRIVATE
{ $syntax "<PRIVATE ... PRIVATE>" }
io.pathnames vocabs vocabs.parser classes.parser classes.union
classes.intersection classes.mixin classes.predicate
classes.singleton classes.tuple.parser compiler.units
-combinators effects.parser slots hash-sets ;
+combinators effects.parser slots hash-sets source-files ;
IN: bootstrap.syntax
! These words are defined as a top-level form, instead of with
"))" parse-effect suffix!
] 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
"<<" [
[