parser, source-files, syntax: have MAIN: store the main entry point in the source-file record in addition to the vocabulary. Have run-file execute the MAIN: word for a file if present after evaluating its contents.
parent
8feb6c68e2
commit
e1390875ca
|
@ -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-file } ". 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>" }
|
||||||
|
|
|
@ -238,8 +238,8 @@ HELP: parse-file
|
||||||
|
|
||||||
HELP: run-file
|
HELP: run-file
|
||||||
{ $values { "file" "a pathname string" } }
|
{ $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." }
|
{ $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." } ;
|
{ $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
|
HELP: ?run-file
|
||||||
{ $values { "path" "a pathname string" } }
|
{ $values { "path" "a pathname string" } }
|
||||||
|
|
|
@ -203,7 +203,8 @@ print-use-hook [ [ ] ] initialize
|
||||||
] recover ;
|
] recover ;
|
||||||
|
|
||||||
: run-file ( file -- )
|
: run-file ( file -- )
|
||||||
parse-file call( -- ) ;
|
[ parse-file call( -- ) ]
|
||||||
|
[ source-file main>> [ execute( -- ) ] when* ] bi ;
|
||||||
|
|
||||||
: ?run-file ( path -- )
|
: ?run-file ( path -- )
|
||||||
dup exists? [ run-file ] [ drop ] if ;
|
dup exists? [ run-file ] [ drop ] if ;
|
||||||
|
|
|
@ -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<<
|
||||||
|
|
|
@ -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-file } "." } ;
|
||||||
|
|
||||||
HELP: <PRIVATE
|
HELP: <PRIVATE
|
||||||
{ $syntax "<PRIVATE ... PRIVATE>" }
|
{ $syntax "<PRIVATE ... PRIVATE>" }
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
"<<" [
|
"<<" [
|
||||||
[
|
[
|
||||||
|
|
Loading…
Reference in New Issue