]> gitweb.factorcode.org Git - factor.git/commitdiff
parser, source-files, syntax: have MAIN: store the main entry point in the source...
authorJoe Groff <arcata@gmail.com>
Thu, 18 Aug 2011 03:58:09 +0000 (20:58 -0700)
committerJoe Groff <arcata@gmail.com>
Thu, 18 Aug 2011 03:58:09 +0000 (20:58 -0700)
basis/command-line/command-line-docs.factor
core/parser/parser-docs.factor
core/parser/parser.factor
core/source-files/source-files.factor
core/syntax/syntax-docs.factor
core/syntax/syntax.factor

index 067360530d23b84f613e49ec6ab386a4ce011b94..264e4e8c8bee9b4d9f3faf06af200d9811bdb4b2 100644 (file)
@@ -135,7 +135,7 @@ $nl
 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>" }
index 24ddc0b7c9f82d1ed83758bbb3bdae6266f6e4de..aadd651a01ba5fea3496131ef441401fde09b7a1 100644 (file)
@@ -238,8 +238,8 @@ HELP: parse-file
 
 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" } }
index be43979b31a6181b9f89cf5ab1096cfc89acad47..f9883837fb0bbe8187741a7b21a1f92cf4a2b9d7 100644 (file)
@@ -203,7 +203,8 @@ print-use-hook [ [ ] ] initialize
     ] 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 ;
index 120d91bb2269f8165aefda082d3a8b60c1cc0b8a..6807e51515b0b2aed64354b16f21d78c04ccdf56 100644 (file)
@@ -13,7 +13,8 @@ TUPLE: source-file
 path
 top-level-form
 checksum
-definitions ;
+definitions
+main ;
 
 : record-top-level-form ( quot file -- )
     top-level-form<<
index 2afefe1f2bf10cc65431df546de1acf879b8a22d..7fda5b406b4b0a98e3c3d4435c44c797673042e1 100644 (file)
@@ -858,7 +858,7 @@ HELP: C:
 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>" }
index 07ff0d3c922a99020c39524e9fd14d1ab26a0c8d..864c67d172cbc568a281a46699e049250a5e421a 100644 (file)
@@ -8,7 +8,7 @@ generic.standard generic.hook generic.math generic.parser classes
 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
@@ -233,7 +233,11 @@ IN: bootstrap.syntax
         "))" 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
 
     "<<" [
         [