From 43dd70398140fdb83a595e3f81df739bc364d0d7 Mon Sep 17 00:00:00 2001 From: Slava Pestov Date: Sun, 16 Dec 2007 20:35:00 -0500 Subject: [PATCH] Simplifying the compiler and parser a little bit --- core/bootstrap/stage2.factor | 6 ++- core/compiler/compiler-docs.factor | 4 +- core/compiler/compiler.factor | 67 +++--------------------------- core/generator/generator.factor | 2 - core/listener/listener.factor | 3 +- core/parser/parser-docs.factor | 6 +-- core/parser/parser.factor | 8 ++-- core/vocabs/loader/loader.factor | 2 +- 8 files changed, 18 insertions(+), 80 deletions(-) mode change 100644 => 100755 core/listener/listener.factor mode change 100644 => 100755 core/parser/parser.factor mode change 100644 => 100755 core/vocabs/loader/loader.factor diff --git a/core/bootstrap/stage2.factor b/core/bootstrap/stage2.factor index 59daa3ab53..3973af8bf4 100755 --- a/core/bootstrap/stage2.factor +++ b/core/bootstrap/stage2.factor @@ -40,12 +40,14 @@ IN: bootstrap.stage2 "listener" use+ ] if - [ + f parse-hook [ "exclude" "include" [ get-global " " split [ empty? not ] subset ] 2apply seq-diff [ "bootstrap." swap append require ] each - ] no-parse-hook + ] with-variable + + do-parse-hook init-io init-stdio diff --git a/core/compiler/compiler-docs.factor b/core/compiler/compiler-docs.factor index b7e96a33ff..018336803e 100755 --- a/core/compiler/compiler-docs.factor +++ b/core/compiler/compiler-docs.factor @@ -20,9 +20,7 @@ ARTICLE: "compiler-usage" "Calling the optimizing compiler" ARTICLE: "recompile" "Automatic recompilation" "When a word is redefined, you can recompile all affected words automatically:" -{ $subsection recompile } -"Normally loading a source file or a module also calls " { $link recompile } ". This can be disabled by wrapping file loading in a combinator:" -{ $subsection no-parse-hook } ; +{ $subsection recompile } ; ARTICLE: "compiler" "Optimizing compiler" "Factor is a fully compiled language implementation with two distinct compilers:" diff --git a/core/compiler/compiler.factor b/core/compiler/compiler.factor index 42de8225c9..4d6529fc7f 100755 --- a/core/compiler/compiler.factor +++ b/core/compiler/compiler.factor @@ -5,71 +5,14 @@ generator debugger math.parser prettyprint words continuations vocabs assocs alien.compiler ; IN: compiler -M: object inference-error-major? drop t ; - -: compile-error ( word error -- ) - compile-errors get [ - >r 2array r> push - ] [ - "quiet" get [ 2drop ] [ print-error flush drop ] if - ] if* ; - -: begin-batch ( -- ) - V{ } clone compile-errors set-global ; - -: compile-error. ( pair -- ) - nl - "While compiling " write dup first pprint ": " print - nl - second print-error ; - -: (:errors) ( -- seq ) - compile-errors get-global - [ second inference-error-major? ] subset ; - -: :errors (:errors) [ compile-error. ] each ; - -: (:warnings) ( -- seq ) - compile-errors get-global - [ second inference-error-major? not ] subset ; - -: :warnings (:warnings) [ compile-error. ] each ; - -: end-batch ( -- ) - "quiet" get [ - "Compile finished." print - nl - ":errors - print " write (:errors) length pprint - " compiler errors." print - ":warnings - print " write (:warnings) length pprint - " compiler warnings." print - nl - ] unless ; - -: with-compile-errors ( quot -- ) - [ begin-batch call end-batch ] with-scope ; inline - -: compile ( word -- ) - H{ } clone [ - compiled-xts [ (compile) ] with-variable - ] keep [ swap add* ] { } assoc>map modify-code-heap ; - -: compile-failed ( word error -- ) - dupd compile-error dup update-xt unchanged-word ; - -: (compile-batch) ( words -- ) +: compile-batch ( words -- ) H{ } clone [ compiled-xts [ - [ [ (compile) ] [ compile-failed ] recover ] each + [ [ (compile) ] curry [ print-error ] recover ] each ] with-variable ] keep [ swap add* ] { } assoc>map modify-code-heap ; -: compile-batch ( seq -- ) - dup empty? [ - drop - ] [ - [ (compile-batch) ] with-compile-errors - ] if ; +: compile ( word -- ) 1array compile-batch ; : compile-vocabs ( seq -- ) [ words ] map concat compile-batch ; @@ -86,4 +29,6 @@ M: object inference-error-major? drop t ; [ f "no-effect" set-word-prop ] each ; : compile-all ( -- ) - all-words dup forget-errors [ changed-word ] each recompile ; + all-words + dup forget-errors [ changed-word ] each + recompile ; diff --git a/core/generator/generator.factor b/core/generator/generator.factor index 6b18e32204..b2868b5a96 100755 --- a/core/generator/generator.factor +++ b/core/generator/generator.factor @@ -83,8 +83,6 @@ SYMBOL: compiler-hook SYMBOL: compile-errors -SYMBOL: batch-mode - : compile-begins ( word -- ) compiler-hook get call "quiet" get [ drop ] [ "Compiling " write . flush ] if ; diff --git a/core/listener/listener.factor b/core/listener/listener.factor old mode 100644 new mode 100755 index 188a5e354d..6ff8d6a4af --- a/core/listener/listener.factor +++ b/core/listener/listener.factor @@ -47,7 +47,8 @@ M: duplex-stream parse-interactive : listen ( -- ) listener-hook get call prompt. [ - stdio get parse-interactive [ call ] [ bye ] if* + stdio get parse-interactive + [ do-parse-hook call ] [ bye ] if* ] try ; : until-quit ( -- ) diff --git a/core/parser/parser-docs.factor b/core/parser/parser-docs.factor index eea23733eb..2fd560943e 100755 --- a/core/parser/parser-docs.factor +++ b/core/parser/parser-docs.factor @@ -528,11 +528,7 @@ HELP: eval HELP: parse-hook { $var-description "A quotation called by " { $link parse-stream } " after parsing the input stream. The default value recompiles new word definitions; see " { $link "recompile" } " for details." } ; -{ parse-hook no-parse-hook } related-words - -HELP: no-parse-hook -{ $values { "quot" "a quotation" } } -{ $description "Runs the quotation in a new dynamic scope where " { $link parse-hook } " is set to " { $link f } ", then calls the outer " { $link parse-hook } " after the quotation returns. This has the effect of postponing any recompilation to the end of a quotation." } ; +{ parse-hook do-parse-hook } related-words HELP: start-parsing { $values { "stream" "an input stream" } { "name" "a pathname string" } } diff --git a/core/parser/parser.factor b/core/parser/parser.factor old mode 100644 new mode 100755 index 235d0e935a..441eaca9cf --- a/core/parser/parser.factor +++ b/core/parser/parser.factor @@ -372,9 +372,6 @@ SYMBOL: parse-hook "Loading " write . flush ] if ; -: no-parse-hook ( quot -- ) - >r f parse-hook r> with-variable do-parse-hook ; inline - : start-parsing ( stream name -- ) H{ } clone new-definitions set dup [ @@ -445,8 +442,9 @@ SYMBOL: parse-hook start-parsing \ contents get string-lines parse-fresh dup finish-parsing - ] [ ] [ undo-parsing ] cleanup - ] no-parse-hook ; + do-parse-hook + ] with-scope + ] [ ] [ undo-parsing ] cleanup ; : parse-file-restarts ( file -- restarts ) "Load " swap " again" 3append t 2array 1array ; diff --git a/core/vocabs/loader/loader.factor b/core/vocabs/loader/loader.factor old mode 100644 new mode 100755 index a7a112b58a..e24955481b --- a/core/vocabs/loader/loader.factor +++ b/core/vocabs/loader/loader.factor @@ -154,7 +154,7 @@ SYMBOL: load-help? 2dup [ f swap set-vocab-docs-loaded? ] each [ f swap set-vocab-source-loaded? ] each - append prune [ [ require ] each ] no-parse-hook ; + append prune [ require ] each ; : refresh ( prefix -- ) to-refresh do-refresh ;