diff --git a/core/bootstrap/stage2.factor b/core/bootstrap/stage2.factor index e8539d79e0..df9e59aec5 100755 --- a/core/bootstrap/stage2.factor +++ b/core/bootstrap/stage2.factor @@ -4,7 +4,7 @@ USING: init command-line namespaces words debugger io kernel.private math memory continuations kernel io.files io.backend system parser vocabs sequences prettyprint vocabs.loader combinators splitting source-files strings -definitions assocs ; +definitions assocs compiler.errors ; IN: bootstrap.stage2 ! Wrap everything in a catch which starts a listener so @@ -37,21 +37,25 @@ IN: bootstrap.stage2 "none" require ] if - "exclude" "include" - [ get-global " " split [ empty? not ] subset ] 2apply - seq-diff - [ "bootstrap." swap append require ] each + [ + "exclude" "include" + [ get-global " " split [ empty? not ] subset ] 2apply + seq-diff + [ "bootstrap." swap append require ] each - init-io - init-stdio + init-io + init-stdio - run-bootstrap-init + run-bootstrap-init + + "Compiling remaining words..." print + + all-words [ compiled? not ] subset recompile-hook get call + ] with-compiler-errors f error set-global f error-continuation set-global - all-words [ compiled? not ] subset recompile-hook get call - "deploy-vocab" get [ "tools.deploy.shaker" run ] [ diff --git a/core/compiler/compiler.factor b/core/compiler/compiler.factor index bd11e74ff5..0d4812626c 100755 --- a/core/compiler/compiler.factor +++ b/core/compiler/compiler.factor @@ -3,7 +3,7 @@ USING: kernel namespaces arrays sequences io inference.backend generator debugger math.parser prettyprint words words.private continuations vocabs assocs alien.compiler dlists optimizer -definitions ; +definitions math compiler.errors ; IN: compiler SYMBOL: compiler-hook @@ -33,7 +33,7 @@ SYMBOL: compiler-hook dup word-dataflow optimize >r over dup r> generate ] [ dup inference-error? [ rethrow ] unless - print-error f over compiled get set-at f + over compiler-error f over compiled get set-at f ] recover 2drop ; ! 2dup ripple-up save-effect ; @@ -63,7 +63,7 @@ SYMBOL: compiler-hook ] with-variable execute ; : recompile-all ( -- ) - all-words recompile ; + [ all-words recompile ] with-compiler-errors ; : decompile ( word -- ) f 2array 1array modify-code-heap ; diff --git a/core/compiler/errors/errors.factor b/core/compiler/errors/errors.factor new file mode 100755 index 0000000000..106b69893b --- /dev/null +++ b/core/compiler/errors/errors.factor @@ -0,0 +1,56 @@ +! Copyright (C) 2007 Slava Pestov. +! See http://factorcode.org/license.txt for BSD license. +USING: kernel namespaces assocs prettyprint io sequences +sorting continuations debugger math ; +IN: compiler.errors + +SYMBOL: compiler-errors + +SYMBOL: with-compiler-errors? + +: compiler-error ( error word -- ) + with-compiler-errors? get [ + compiler-errors get set-at + ] [ 2drop ] if ; + +: compiler-error. ( error word -- ) + nl + "While compiling " write pprint ": " print + nl + print-error ; + +: compiler-errors. ( assoc -- ) + >alist sort-keys [ swap compiler-error. ] assoc-each ; + +GENERIC: compiler-warning? ( error -- ? ) + +: (:errors) ( -- assoc ) + compiler-errors get-global + [ nip compiler-warning? not ] assoc-subset ; + +: :errors (:errors) compiler-errors. ; + +: (:warnings) ( -- seq ) + compiler-errors get-global + [ nip compiler-warning? ] assoc-subset ; + +: :warnings (:warnings) compiler-errors. ; + +: (compiler-report) ( what assoc -- ) + length dup zero? [ 2drop ] [ + ":" write over write " - print " write pprint + " compiler " write write "." print + ] if ; + +: compiler-report ( -- ) + "errors" (:errors) (compiler-report) + "warnings" (:warnings) (compiler-report) ; + +: with-compiler-errors ( quot -- ) + with-compiler-errors? get "quiet" get or [ call ] [ + [ + with-compiler-errors? on + V{ } clone compiler-errors set-global + [ compiler-report ] [ ] cleanup + ] with-scope + ] if ; inline diff --git a/core/continuations/continuations-tests.factor b/core/continuations/continuations-tests.factor index d4a8cfb6a6..667d81a30e 100755 --- a/core/continuations/continuations-tests.factor +++ b/core/continuations/continuations-tests.factor @@ -71,3 +71,38 @@ IN: temporary [ t ] [ \ bar word-def "c" get innermost-frame-quot = ] unit-test [ 1 ] [ "c" get innermost-frame-scan ] unit-test + +SYMBOL: always-counter +SYMBOL: error-counter + +[ + 0 always-counter set + 0 error-counter set + + [ ] [ always-counter inc ] [ error-counter inc ] cleanup + + [ 1 ] [ always-counter get ] unit-test + [ 0 ] [ error-counter get ] unit-test + + [ "a" ] [ + [ + [ "a" throw ] + [ always-counter inc ] + [ error-counter inc ] cleanup + ] catch + ] unit-test + + [ 2 ] [ always-counter get ] unit-test + [ 1 ] [ error-counter get ] unit-test + + [ "a" ] [ + [ + [ ] + [ always-counter inc "a" throw ] + [ error-counter inc ] cleanup + ] catch + ] unit-test + + [ 3 ] [ always-counter get ] unit-test + [ 2 ] [ error-counter get ] unit-test +] with-scope diff --git a/core/inference/backend/backend.factor b/core/inference/backend/backend.factor index f2f153e0bd..520b0ec485 100755 --- a/core/inference/backend/backend.factor +++ b/core/inference/backend/backend.factor @@ -4,7 +4,7 @@ IN: inference.backend USING: inference.dataflow arrays generic io io.streams.string kernel math namespaces parser prettyprint sequences strings vectors words quotations effects classes continuations -debugger assocs combinators ; +debugger assocs combinators compiler.errors ; : recursive-label ( word -- label/f ) recursive-state get at ; @@ -22,6 +22,9 @@ debugger assocs combinators ; TUPLE: inference-error rstate major? ; +M: inference-error compiler-warning? + inference-error-major? not ; + : (inference-error) ( ... class important? -- * ) >r construct-boa r> recursive-state get { diff --git a/core/parser/parser.factor b/core/parser/parser.factor index 3b9ba714f2..d3efd54904 100755 --- a/core/parser/parser.factor +++ b/core/parser/parser.factor @@ -5,7 +5,7 @@ namespaces prettyprint sequences strings vectors words quotations inspector io.styles io combinators sorting splitting math.parser effects continuations debugger io.files io.streams.string io.streams.lines vocabs -source-files classes hashtables ; +source-files classes hashtables compiler.errors ; IN: parser TUPLE: lexer text line column ; @@ -354,7 +354,7 @@ SYMBOL: bootstrap-syntax "arrays" "assocs" "combinators" - "compiler" + "compiler.errors" "continuations" "debugger" "definitions" @@ -455,9 +455,11 @@ SYMBOL: bootstrap-syntax : parse-file ( file -- quot ) [ - [ parsing-file ] keep - [ ?resource-path ] keep - parse-stream + [ + [ parsing-file ] keep + [ ?resource-path ] keep + parse-stream + ] with-compiler-errors ] [ over parse-file-restarts rethrow-restarts drop parse-file diff --git a/core/vocabs/loader/loader.factor b/core/vocabs/loader/loader.factor index a5d29804ad..306f357b72 100755 --- a/core/vocabs/loader/loader.factor +++ b/core/vocabs/loader/loader.factor @@ -3,7 +3,8 @@ USING: namespaces splitting sequences io.files kernel assocs words vocabs definitions parser continuations inspector debugger io io.styles io.streams.lines hashtables sorting prettyprint -source-files arrays combinators strings system math.parser ; +source-files arrays combinators strings system math.parser +compiler.errors ; IN: vocabs.loader SYMBOL: vocab-roots @@ -108,7 +109,8 @@ SYMBOL: load-help? drop no-vocab ] if ; -: require ( vocab -- ) load-vocab drop ; +: require ( vocab -- ) + load-vocab drop ; : run ( vocab -- ) dup load-vocab vocab-main [ @@ -150,11 +152,14 @@ SYMBOL: load-help? dup update-roots dup modified-sources swap modified-docs ; +: require-each ( seq -- ) + [ [ require ] each ] with-compiler-errors ; + : do-refresh ( modified-sources modified-docs -- ) 2dup [ f swap set-vocab-docs-loaded? ] each [ f swap set-vocab-source-loaded? ] each - append prune [ require ] each ; + append prune require-each ; : refresh ( prefix -- ) to-refresh do-refresh ; @@ -172,7 +177,7 @@ M: string (load-vocab) M: vocab-link (load-vocab) vocab-name (load-vocab) ; -[ dup vocab [ ] [ ] ?if (load-vocab) ] +[ [ dup vocab [ ] [ ] ?if (load-vocab) ] with-compiler-errors ] load-vocab-hook set-global : vocab-where ( vocab -- loc ) diff --git a/extra/tools/annotations/annotations.factor b/extra/tools/annotations/annotations.factor index 018b91d219..27c427ad25 100755 --- a/extra/tools/annotations/annotations.factor +++ b/extra/tools/annotations/annotations.factor @@ -6,7 +6,7 @@ IN: tools.annotations