New implementation of compiler error reporting
parent
1caa78f618
commit
58da31c071
|
@ -4,7 +4,7 @@ USING: init command-line namespaces words debugger io
|
||||||
kernel.private math memory continuations kernel io.files
|
kernel.private math memory continuations kernel io.files
|
||||||
io.backend system parser vocabs sequences prettyprint
|
io.backend system parser vocabs sequences prettyprint
|
||||||
vocabs.loader combinators splitting source-files strings
|
vocabs.loader combinators splitting source-files strings
|
||||||
definitions assocs ;
|
definitions assocs compiler.errors ;
|
||||||
IN: bootstrap.stage2
|
IN: bootstrap.stage2
|
||||||
|
|
||||||
! Wrap everything in a catch which starts a listener so
|
! Wrap everything in a catch which starts a listener so
|
||||||
|
@ -37,6 +37,7 @@ IN: bootstrap.stage2
|
||||||
"none" require
|
"none" require
|
||||||
] if
|
] if
|
||||||
|
|
||||||
|
[
|
||||||
"exclude" "include"
|
"exclude" "include"
|
||||||
[ get-global " " split [ empty? not ] subset ] 2apply
|
[ get-global " " split [ empty? not ] subset ] 2apply
|
||||||
seq-diff
|
seq-diff
|
||||||
|
@ -47,10 +48,13 @@ IN: bootstrap.stage2
|
||||||
|
|
||||||
run-bootstrap-init
|
run-bootstrap-init
|
||||||
|
|
||||||
f error set-global
|
"Compiling remaining words..." print
|
||||||
f error-continuation set-global
|
|
||||||
|
|
||||||
all-words [ compiled? not ] subset recompile-hook get call
|
all-words [ compiled? not ] subset recompile-hook get call
|
||||||
|
] with-compiler-errors
|
||||||
|
|
||||||
|
f error set-global
|
||||||
|
f error-continuation set-global
|
||||||
|
|
||||||
"deploy-vocab" get [
|
"deploy-vocab" get [
|
||||||
"tools.deploy.shaker" run
|
"tools.deploy.shaker" run
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
USING: kernel namespaces arrays sequences io inference.backend
|
USING: kernel namespaces arrays sequences io inference.backend
|
||||||
generator debugger math.parser prettyprint words words.private
|
generator debugger math.parser prettyprint words words.private
|
||||||
continuations vocabs assocs alien.compiler dlists optimizer
|
continuations vocabs assocs alien.compiler dlists optimizer
|
||||||
definitions ;
|
definitions math compiler.errors ;
|
||||||
IN: compiler
|
IN: compiler
|
||||||
|
|
||||||
SYMBOL: compiler-hook
|
SYMBOL: compiler-hook
|
||||||
|
@ -33,7 +33,7 @@ SYMBOL: compiler-hook
|
||||||
dup word-dataflow optimize >r over dup r> generate
|
dup word-dataflow optimize >r over dup r> generate
|
||||||
] [
|
] [
|
||||||
dup inference-error? [ rethrow ] unless
|
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
|
] recover
|
||||||
2drop ;
|
2drop ;
|
||||||
! 2dup ripple-up save-effect ;
|
! 2dup ripple-up save-effect ;
|
||||||
|
@ -63,7 +63,7 @@ SYMBOL: compiler-hook
|
||||||
] with-variable execute ;
|
] with-variable execute ;
|
||||||
|
|
||||||
: recompile-all ( -- )
|
: recompile-all ( -- )
|
||||||
all-words recompile ;
|
[ all-words recompile ] with-compiler-errors ;
|
||||||
|
|
||||||
: decompile ( word -- )
|
: decompile ( word -- )
|
||||||
f 2array 1array modify-code-heap ;
|
f 2array 1array modify-code-heap ;
|
||||||
|
|
|
@ -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
|
|
@ -71,3 +71,38 @@ IN: temporary
|
||||||
[ t ] [ \ bar word-def "c" get innermost-frame-quot = ] unit-test
|
[ t ] [ \ bar word-def "c" get innermost-frame-quot = ] unit-test
|
||||||
|
|
||||||
[ 1 ] [ "c" get innermost-frame-scan ] 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
|
||||||
|
|
|
@ -4,7 +4,7 @@ IN: inference.backend
|
||||||
USING: inference.dataflow arrays generic io io.streams.string
|
USING: inference.dataflow arrays generic io io.streams.string
|
||||||
kernel math namespaces parser prettyprint sequences
|
kernel math namespaces parser prettyprint sequences
|
||||||
strings vectors words quotations effects classes continuations
|
strings vectors words quotations effects classes continuations
|
||||||
debugger assocs combinators ;
|
debugger assocs combinators compiler.errors ;
|
||||||
|
|
||||||
: recursive-label ( word -- label/f )
|
: recursive-label ( word -- label/f )
|
||||||
recursive-state get at ;
|
recursive-state get at ;
|
||||||
|
@ -22,6 +22,9 @@ debugger assocs combinators ;
|
||||||
|
|
||||||
TUPLE: inference-error rstate major? ;
|
TUPLE: inference-error rstate major? ;
|
||||||
|
|
||||||
|
M: inference-error compiler-warning?
|
||||||
|
inference-error-major? not ;
|
||||||
|
|
||||||
: (inference-error) ( ... class important? -- * )
|
: (inference-error) ( ... class important? -- * )
|
||||||
>r construct-boa r>
|
>r construct-boa r>
|
||||||
recursive-state get {
|
recursive-state get {
|
||||||
|
|
|
@ -5,7 +5,7 @@ namespaces prettyprint sequences strings vectors words
|
||||||
quotations inspector io.styles io combinators sorting
|
quotations inspector io.styles io combinators sorting
|
||||||
splitting math.parser effects continuations debugger
|
splitting math.parser effects continuations debugger
|
||||||
io.files io.streams.string io.streams.lines vocabs
|
io.files io.streams.string io.streams.lines vocabs
|
||||||
source-files classes hashtables ;
|
source-files classes hashtables compiler.errors ;
|
||||||
IN: parser
|
IN: parser
|
||||||
|
|
||||||
TUPLE: lexer text line column ;
|
TUPLE: lexer text line column ;
|
||||||
|
@ -354,7 +354,7 @@ SYMBOL: bootstrap-syntax
|
||||||
"arrays"
|
"arrays"
|
||||||
"assocs"
|
"assocs"
|
||||||
"combinators"
|
"combinators"
|
||||||
"compiler"
|
"compiler.errors"
|
||||||
"continuations"
|
"continuations"
|
||||||
"debugger"
|
"debugger"
|
||||||
"definitions"
|
"definitions"
|
||||||
|
@ -454,10 +454,12 @@ SYMBOL: bootstrap-syntax
|
||||||
"Load " swap " again" 3append t 2array 1array ;
|
"Load " swap " again" 3append t 2array 1array ;
|
||||||
|
|
||||||
: parse-file ( file -- quot )
|
: parse-file ( file -- quot )
|
||||||
|
[
|
||||||
[
|
[
|
||||||
[ parsing-file ] keep
|
[ parsing-file ] keep
|
||||||
[ ?resource-path <file-reader> ] keep
|
[ ?resource-path <file-reader> ] keep
|
||||||
parse-stream
|
parse-stream
|
||||||
|
] with-compiler-errors
|
||||||
] [
|
] [
|
||||||
over parse-file-restarts rethrow-restarts
|
over parse-file-restarts rethrow-restarts
|
||||||
drop parse-file
|
drop parse-file
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
USING: namespaces splitting sequences io.files kernel assocs
|
USING: namespaces splitting sequences io.files kernel assocs
|
||||||
words vocabs definitions parser continuations inspector debugger
|
words vocabs definitions parser continuations inspector debugger
|
||||||
io io.styles io.streams.lines hashtables sorting prettyprint
|
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
|
IN: vocabs.loader
|
||||||
|
|
||||||
SYMBOL: vocab-roots
|
SYMBOL: vocab-roots
|
||||||
|
@ -108,7 +109,8 @@ SYMBOL: load-help?
|
||||||
drop no-vocab
|
drop no-vocab
|
||||||
] if ;
|
] if ;
|
||||||
|
|
||||||
: require ( vocab -- ) load-vocab drop ;
|
: require ( vocab -- )
|
||||||
|
load-vocab drop ;
|
||||||
|
|
||||||
: run ( vocab -- )
|
: run ( vocab -- )
|
||||||
dup load-vocab vocab-main [
|
dup load-vocab vocab-main [
|
||||||
|
@ -150,11 +152,14 @@ SYMBOL: load-help?
|
||||||
dup update-roots
|
dup update-roots
|
||||||
dup modified-sources swap modified-docs ;
|
dup modified-sources swap modified-docs ;
|
||||||
|
|
||||||
|
: require-each ( seq -- )
|
||||||
|
[ [ require ] each ] with-compiler-errors ;
|
||||||
|
|
||||||
: do-refresh ( modified-sources modified-docs -- )
|
: do-refresh ( modified-sources modified-docs -- )
|
||||||
2dup
|
2dup
|
||||||
[ f swap set-vocab-docs-loaded? ] each
|
[ f swap set-vocab-docs-loaded? ] each
|
||||||
[ f swap set-vocab-source-loaded? ] each
|
[ f swap set-vocab-source-loaded? ] each
|
||||||
append prune [ require ] each ;
|
append prune require-each ;
|
||||||
|
|
||||||
: refresh ( prefix -- ) to-refresh do-refresh ;
|
: refresh ( prefix -- ) to-refresh do-refresh ;
|
||||||
|
|
||||||
|
@ -172,7 +177,7 @@ M: string (load-vocab)
|
||||||
M: vocab-link (load-vocab)
|
M: vocab-link (load-vocab)
|
||||||
vocab-name (load-vocab) ;
|
vocab-name (load-vocab) ;
|
||||||
|
|
||||||
[ dup vocab [ ] [ ] ?if (load-vocab) ]
|
[ [ dup vocab [ ] [ ] ?if (load-vocab) ] with-compiler-errors ]
|
||||||
load-vocab-hook set-global
|
load-vocab-hook set-global
|
||||||
|
|
||||||
: vocab-where ( vocab -- loc )
|
: vocab-where ( vocab -- loc )
|
||||||
|
|
|
@ -6,7 +6,7 @@ IN: tools.annotations
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
: check-compound ( word -- word )
|
: check-compound ( word -- )
|
||||||
compound? [
|
compound? [
|
||||||
"Annotations can only be used with compound words" throw
|
"Annotations can only be used with compound words" throw
|
||||||
] unless ;
|
] unless ;
|
||||||
|
|
|
@ -117,7 +117,7 @@ M: vocab-link summary vocab-summary ;
|
||||||
: load-everything ( -- )
|
: load-everything ( -- )
|
||||||
all-vocabs-seq
|
all-vocabs-seq
|
||||||
[ vocab-name dangerous? not ] subset
|
[ vocab-name dangerous? not ] subset
|
||||||
[ require ] each ;
|
require-each ;
|
||||||
|
|
||||||
: unrooted-child-vocabs ( prefix -- seq )
|
: unrooted-child-vocabs ( prefix -- seq )
|
||||||
dup empty? [ CHAR: . add ] unless
|
dup empty? [ CHAR: . add ] unless
|
||||||
|
@ -137,7 +137,7 @@ M: vocab-link summary vocab-summary ;
|
||||||
|
|
||||||
: load-children ( prefix -- )
|
: load-children ( prefix -- )
|
||||||
all-child-vocabs values concat
|
all-child-vocabs values concat
|
||||||
[ require ] each ;
|
require-each ;
|
||||||
|
|
||||||
: vocab-status-string ( vocab -- string )
|
: vocab-status-string ( vocab -- string )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue