run-bootstrap-init
] with-compiler-errors
- :errors
f error set-global
f error-continuation set-global
combinators classes.algebra alien alien.c-types alien.structs
alien.strings alien.arrays alien.complex sets libc alien.libraries
continuations.private fry cpu.architecture
+source-files.errors
compiler.errors
compiler.alien
compiler.cfg
M: no-such-library summary
drop "Library not found" ;
-M: no-such-library compiler-error-type
- drop +linkage+ ;
+M: no-such-library source-file-error-type drop +linkage-error+ ;
: no-such-library ( name -- )
\ no-such-library boa
M: no-such-symbol summary
drop "Symbol not found" ;
-M: no-such-symbol compiler-error-type
- drop +linkage+ ;
+M: no-such-symbol source-file-error-type drop +linkage-error+ ;
: no-such-symbol ( name -- )
\ no-such-symbol boa
! See http://factorcode.org/license.txt for BSD license.
USING: accessors kernel namespaces arrays sequences io words fry
continuations vocabs assocs dlists definitions math graphs generic
-combinators deques search-deques macros io stack-checker
+combinators deques search-deques macros io source-files.errors stack-checker
stack-checker.state stack-checker.inlining combinators.short-circuit
compiler.errors compiler.units compiler.tree.builder
compiler.tree.optimizer compiler.cfg.builder compiler.cfg.optimizer
: ignore-error? ( word error -- ? )
[ [ inline? ] [ macro? ] bi or ]
- [ compiler-error-type +warning+ eq? ] bi* and ;
+ [ source-file-error-type +compiler-warning+ eq? ] bi* and ;
: fail ( word error -- * )
[ 2dup ignore-error? [ 2drop ] [ swap compiler-error ] if ]
] bi format nl
] [ error>> error. ] bi ;
-M: compiler-error summary word>> synopsis ;
+M: compiler-error summary asset>> summary ;
M: bad-effect summary
drop "Bad stack effect declaration" ;
! Copyright (C) 2005, 2009 Slava Pestov.
! See http://factorcode.org/license.txt for BSD license.
-USING: parser lexer kernel namespaces sequences definitions
-io.files io.backend io.pathnames io summary continuations
-tools.crossref tools.vocabs prettyprint source-files assocs
+USING: parser lexer kernel namespaces sequences definitions io.files
+io.backend io.pathnames io summary continuations tools.crossref
+tools.vocabs prettyprint source-files source-files.errors assocs
vocabs vocabs.loader splitting accessors debugger prettyprint
help.topics ;
IN: editors
! See http://factorcode.org/license.txt for BSD license.
USING: kernel generic sequences io words arrays summary effects
continuations assocs accessors namespaces compiler.errors
-stack-checker.values stack-checker.recursive-state ;
+stack-checker.values stack-checker.recursive-state
+source-files.errors compiler.errors ;
IN: stack-checker.errors
: pretty-word ( word -- word' )
TUPLE: inference-error error type word ;
-M: inference-error compiler-error-type type>> ;
+M: inference-error source-file-error-type type>> ;
: (inference-error) ( ... class type -- * )
[ boa ] dip
\ inference-error boa rethrow ; inline
: inference-error ( ... class -- * )
- +error+ (inference-error) ; inline
+ +compiler-error+ (inference-error) ; inline
: inference-warning ( ... class -- * )
- +warning+ (inference-error) ; inline
+ +compiler-warning+ (inference-error) ; inline
TUPLE: literal-expected what ;
--- /dev/null
+IN: tools.errors
+USING: compiler.errors tools.errors help.markup help.syntax vocabs.loader
+words quotations io ;
+
+ARTICLE: "compiler-errors" "Compiler warnings and errors"
+"After loading a vocabulary, you might see messages like:"
+{ $code
+ ":errors - print 2 compiler errors."
+ ":warnings - print 50 compiler warnings."
+}
+"These warnings arise from the compiler's stack effect checker. Warnings are non-fatal conditions -- not all code has a static stack effect, so you try to minimize warnings but understand that in many cases they cannot be eliminated. Errors indicate programming mistakes, such as erroneous stack effect declarations."
+$nl
+"The precise warning and error conditions are documented in " { $link "inference-errors" } "."
+$nl
+"Words to view warnings and errors:"
+{ $subsection :errors }
+{ $subsection :warnings }
+{ $subsection :linkage }
+"Words such as " { $link require } " use a combinator which counts errors and prints a report at the end:"
+{ $subsection with-compiler-errors } ;
+
+HELP: compiler-error
+{ $values { "error" "an error" } { "word" word } }
+{ $description "If inside a " { $link with-compiler-errors } ", saves the error for future persual via " { $link :errors } ", " { $link :warnings } " and " { $link :linkage } ". If not inside a " { $link with-compiler-errors } ", ignores the error." } ;
+
+HELP: with-compiler-errors
+{ $values { "quot" quotation } }
+{ $description "Calls the quotation and collects any compiler warnings and errors. Compiler warnings and errors are summarized at the end and can be viewed with " { $link :errors } ", " { $link :warnings } ", and " { $link :linkage } "." }
+{ $notes "Nested calls to " { $link with-compiler-errors } " are ignored, and only the outermost call collects warnings and errors." } ;
+
+HELP: :errors
+{ $description "Prints all serious compiler errors from the most recent compile to " { $link output-stream } "." } ;
+
+HELP: :warnings
+{ $description "Prints all ignorable compiler warnings from the most recent compile to " { $link output-stream } "." } ;
+
+HELP: :linkage
+{ $description "Prints all C library interface linkage errors from the most recent compile to " { $link output-stream } "." } ;
+
+{ :errors :warnings } related-words
: compiler-errors. ( type -- )
errors-of-type values errors. ;
-: :errors ( -- ) +error+ compiler-errors. ;
+: :errors ( -- ) +compiler-error+ compiler-errors. ;
-: :warnings ( -- ) +warning+ compiler-errors. ;
+: :warnings ( -- ) +compiler-warning+ compiler-errors. ;
-: :linkage ( -- ) +linkage+ compiler-errors. ;
+: :linkage ( -- ) +linkage-error+ compiler-errors. ;
ARTICLE: "tools.test.run" "Running unit tests"
"The following words run test harness files; any test failures are collected and printed at the end:"
{ $subsection test }
-{ $subsection test-all } ;
-
-ARTICLE: "tools.test.failure" "Handling test failures"
-"Most of the time the words documented in " { $link "tools.test.run" } " are used because they print all test failures in human-readable form. Some tools inspect the test failures and takes some kind of action instead, for example, " { $vocab-link "mason" } "."
-$nl
-"The following words output an association list mapping vocabulary names to sequences of failures; a failure is an array having the shape " { $snippet "{ error test continuation }" } ", and the elements are as follows:"
-{ $list
- { { $snippet "error" } " - the error thrown by the unit test" }
- { { $snippet "test" } " - a pair " { $snippet "{ output input }" } " containing expected output and a unit test quotation which didn't produce this output" }
- { { $snippet "continuation" } " - the traceback at the point of the error" }
-}
-"The following words run test harness files and output failures:"
-{ $subsection run-tests }
-{ $subsection run-all-tests }
+{ $subsection test-all }
"The following word prints failures:"
-{ $subsection results. } ;
+{ $subsection :failures }
+"Unit test failurs are instances of a class, and are stored in a global variable:"
+{ $subsection test-failure }
+{ $subsection test-failures } ;
ARTICLE: "tools.test" "Unit testing"
"A unit test is a piece of code which starts with known input values, then compares the output of a word with an expected output, where the expected output is defined by the word's contract."
$nl
"If the test harness needs to define words, they should be placed in a vocabulary named " { $snippet { $emphasis "vocab" } ".tests" } " where " { $emphasis "vocab" } " is the vocab being tested."
{ $subsection "tools.test.write" }
-{ $subsection "tools.test.run" }
-{ $subsection "tools.test.failure" } ;
+{ $subsection "tools.test.run" } ;
ABOUT: "tools.test"
{ $values { "prefix" "a vocabulary name" } }
{ $description "Runs unit tests for the vocabulary named " { $snippet "prefix" } " and all of its child vocabularies." } ;
-HELP: run-tests
-{ $values { "prefix" "a vocabulary name" } { "failures" "an association list of unit test failures" } }
-{ $description "Runs unit tests for the vocabulary named " { $snippet "prefix" } " and all of its child vocabularies. Outputs unit test failures as documented in " { $link "tools.test.failure" } "." } ;
-
HELP: test-all
{ $description "Runs unit tests for all loaded vocabularies." } ;
-HELP: run-all-tests
-{ $values { "failures" "an association list of unit test failures" } }
-{ $description "Runs unit tests for all loaded vocabularies and outputs unit test failures as documented in " { $link "tools.test.failure" } "." } ;
-
-HELP: results.
-{ $values { "assoc" "an association list of unit test failures" } }
-{ $description "Prints unit test failures output by " { $link run-tests } " or " { $link run-all-tests } " to " { $link output-stream } "." } ;
+HELP: :failures
+{ $description "Prints all pending unit test failures." } ;
io.styles kernel lexer locals macros math.parser namespaces
parser prettyprint quotations sequences source-files splitting
stack-checker summary unicode.case vectors vocabs vocabs.loader words
-tools.vocabs tools.errors source-files.errors io.streams.string make ;
+tools.vocabs tools.errors source-files.errors io.streams.string make
+compiler.errors ;
IN: tools.test
-TUPLE: test-failure < source-file-error experiment continuation ;
+TUPLE: test-failure < source-file-error continuation ;
-SYMBOL: passed-tests
-SYMBOL: failed-tests
+SYMBOL: +test-failure+
+
+M: test-failure source-file-error-type drop +test-failure+ ;
+
+SYMBOL: test-failures
+test-failures [ V{ } clone ] initialize
<PRIVATE
test-failure new
swap >>line#
swap >>file
- swap >>experiment
+ swap >>asset
swap >>error
error-continuation get >>continuation ;
: failure ( error experiment file line# -- )
"--> test failed!" print
- <test-failure> failed-tests get push ;
-
-: success ( experiment -- ) passed-tests get push ;
+ <test-failure> test-failures get push ;
: file-failure ( error file -- )
[ f ] [ f ] bi* failure ;
:: experiment ( word: ( -- error ? ) file line# -- )
word <experiment> :> e
e experiment.
- word execute [ e file line# failure ] [ drop e success ] if ; inline
+ word execute [ e file line# failure ] [ drop ] if ; inline
: parse-test ( accum word -- accum )
literalize parsed
>>
: run-test-file ( path -- )
- [ run-file ] [ swap file-failure ] recover ;
-
-: collect-results ( quot -- failed passed )
- [
- V{ } clone failed-tests set
- V{ } clone passed-tests set
- call
- failed-tests get
- passed-tests get
- ] with-scope ; inline
+ [ [ test-failures get ] dip '[ file>> _ = not ] filter-here ]
+ [ [ run-file ] [ swap file-failure ] recover ] bi ;
: run-vocab-tests ( vocab -- )
dup vocab source-loaded?>> [
TEST: must-fail
M: test-failure summary
- [ experiment>> experiment. ] with-string-writer ;
+ [ asset>> experiment. ] with-string-writer ;
M: test-failure error. ( error -- )
[ call-next-method ]
[ traceback-button. ]
bi ;
-: results. ( failed passed -- )
- [
- [
- [ length # " tests failed, " % ]
- [ length # " tests passed." % ]
- bi*
- ] "" make nl print nl
- ] [ drop errors. ] 2bi ;
-
-: run-tests ( prefix -- failed passed )
- [ child-vocabs [ run-vocab-tests ] each ] collect-results ;
+: :failures ( -- ) test-failures get errors. ;
: test ( prefix -- )
- run-tests results. ;
-
-: run-all-tests ( -- failed passed )
- "" run-tests ;
+ [ child-vocabs [ run-vocab-tests ] each ] with-compiler-errors
+ test-failures get [
+ ":failures - show " write length pprint " failing tests." print
+ ] unless-empty ;
-: test-all ( -- )
- run-all-tests results. ;
+: test-all ( -- ) "" test ;
! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays sequences sorting assocs colors.constants
combinators combinators.smart combinators.short-circuit editors
-compiler.errors compiler.units fonts kernel io.pathnames
+compiler.errors compiler.units fonts kernel io.pathnames prettyprint
stack-checker.errors source-files.errors math.parser math.order models
models.arrow models.search debugger namespaces summary locals ui
ui.commands ui.gadgets ui.gadgets.panes ui.gadgets.tables
ui.gadgets.labeled ui.gadgets.tracks ui.gestures ui.operations
ui.tools.browser ui.tools.common ui.gadgets.scrollers
ui.tools.inspector ui.gadgets.status-bar ui.operations
-ui.gadgets.buttons ui.gadgets.borders ui.images ;
+ui.gadgets.buttons ui.gadgets.borders ui.images tools.test ;
IN: ui.tools.compiler-errors
TUPLE: error-list-gadget < tool source-file error source-file-table error-table error-display ;
SINGLETON: source-file-renderer
M: source-file-renderer row-columns
- drop [ first2 length number>string 2array ] [ { "All" "" } ] if* ;
+ drop first2 length number>string 2array ;
M: source-file-renderer row-value
drop dup [ first <pathname> ] when ;
M: source-file-renderer filled-column drop 0 ;
: <source-file-model> ( model -- model' )
- [ values group-by-source-file >alist sort-keys f prefix ] <arrow> ;
+ [ group-by-source-file >alist sort-keys ] <arrow> ;
:: <source-file-table> ( error-list -- table )
error-list model>> <source-file-model>
SINGLETON: error-renderer
-GENERIC: error-icon ( error -- icon )
-
-: <error-icon> ( name -- image-name )
+: error-icon ( type -- icon )
+ {
+ { +compiler-error+ [ "compiler-error" ] }
+ { +compiler-warning+ [ "compiler-warning" ] }
+ { +linkage-error+ [ "linkage-error" ] }
+ { +test-failure+ [ "unit-test-error" ] }
+ } case
"vocab:ui/tools/error-list/icons/" ".tiff" surround <image-name> ;
-M: compiler-error error-icon
- compiler-error-type {
- { +error+ [ "compiler-error" ] }
- { +warning+ [ "compiler-warning" ] }
- { +linkage+ [ "linkage-error" ] }
- } case <error-icon> ;
-
M: error-renderer row-columns
drop [
{
- [ error-icon ]
+ [ source-file-error-type error-icon ]
[ line#>> number>string ]
- [ word>> name>> ]
+ [ asset>> unparse-short ]
[ error>> summary ]
} cleave
] output>array ;
M: error-renderer prototype-row
- drop [ "compiler-error" <error-icon> "" "" "" ] output>array ;
+ drop [ +compiler-error+ error-icon "" "" "" ] output>array ;
M: error-renderer row-value
drop ;
M: error-renderer column-titles
- drop { "" "Line" "Word" "Error" } ;
+ drop { "" "Line" "Asset" "Error" } ;
M: error-renderer column-alignment drop { 0 1 0 0 } ;
[ [ [ file>> ] [ line#>> ] bi 2array ] compare ] sort ;
: <error-table-model> ( error-list -- model )
- [ model>> [ values ] <arrow> ] [ source-file>> ] bi
- [ swap { [ drop not ] [ [ string>> ] [ file>> ] bi* = ] } 2|| ] <search>
+ [ model>> ] [ source-file>> ] bi
+ [ [ file>> ] [ string>> ] bi* = ] <search>
[ sort-errors ] <arrow> ;
:: <error-table> ( error-list -- table )
M: updater definitions-changed
2drop
- compiler-errors get-global
+ compiler-errors get-global values
+ test-failures get-global append
compiler-error-model get-global
set-model ;
ui.gadgets.presentations ui.gadgets.viewports ui.gadgets.tables
ui.gadgets.tracks ui.gadgets.scrollers ui.gadgets.panes
ui.gadgets.borders ui.gadgets.status-bar ui.tools.traceback
-ui.tools.inspector ;
+ui.tools.inspector ui.tools.browser ;
IN: ui.tools.debugger
TUPLE: debugger < track error restarts restart-hook restart-list continuation ;
USING: help.markup help.syntax vocabs.loader words io
quotations words.symbol ;
-ARTICLE: "compiler-errors" "Compiler warnings and errors"
-"After loading a vocabulary, you might see messages like:"
-{ $code
- ":errors - print 2 compiler errors."
- ":warnings - print 50 compiler warnings."
-}
-"These warnings arise from the compiler's stack effect checker. Warnings are non-fatal conditions -- not all code has a static stack effect, so you try to minimize warnings but understand that in many cases they cannot be eliminated. Errors indicate programming mistakes, such as erroneous stack effect declarations."
-$nl
-"The precise warning and error conditions are documented in " { $link "inference-errors" } "."
-$nl
-"Words to view warnings and errors:"
-{ $subsection :errors }
-{ $subsection :warnings }
-{ $subsection :linkage }
-"Words such as " { $link require } " use a combinator which counts errors and prints a report at the end:"
-{ $subsection with-compiler-errors } ;
-
HELP: compiler-errors
{ $var-description "Global variable holding an assoc mapping words to compiler errors. This variable is set by " { $link with-compiler-errors } "." } ;
ABOUT: "compiler-errors"
-
-HELP: compiler-error
-{ $values { "error" "an error" } { "word" word } }
-{ $description "If inside a " { $link with-compiler-errors } ", saves the error for future persual via " { $link :errors } ", " { $link :warnings } " and " { $link :linkage } ". If not inside a " { $link with-compiler-errors } ", ignores the error." } ;
-
-HELP: compiler-error.
-{ $values { "error" "an error" } { "word" word } }
-{ $description "Prints a compiler error to " { $link output-stream } "." } ;
-
-HELP: compiler-errors.
-{ $values { "type" symbol } }
-{ $description "Prints compiler errors to " { $link output-stream } ". The type parameter is one of " { $link +error+ } ", " { $link +warning+ } ", or " { $link +linkage+ } "." } ;
-HELP: :errors
-{ $description "Prints all serious compiler errors from the most recent compile to " { $link output-stream } "." } ;
-
-HELP: :warnings
-{ $description "Prints all ignorable compiler warnings from the most recent compile to " { $link output-stream } "." } ;
-
-HELP: :linkage
-{ $description "Prints all C library interface linkage errors from the most recent compile to " { $link output-stream } "." } ;
-
-{ :errors :warnings } related-words
-
-HELP: with-compiler-errors
-{ $values { "quot" quotation } }
-{ $description "Calls the quotation and collects any compiler warnings and errors. Compiler warnings and errors are summarized at the end and can be viewed with " { $link :errors } ", " { $link :warnings } ", and " { $link :linkage } "." }
-{ $notes "Nested calls to " { $link with-compiler-errors } " are ignored, and only the outermost call collects warnings and errors." } ;
source-files.errors ;
IN: compiler.errors
-SYMBOLS: +error+ +warning+ +linkage+ ;
+SYMBOLS: +compiler-error+ +compiler-warning+ +linkage-error+ ;
-TUPLE: compiler-error < source-file-error word ;
+TUPLE: compiler-error < source-file-error ;
-GENERIC: compiler-error-type ( error -- ? )
-
-M: object compiler-error-type drop +error+ ;
-
-M: compiler-error compiler-error-type error>> compiler-error-type ;
+M: compiler-error source-file-error-type error>> source-file-error-type ;
SYMBOL: compiler-errors
: errors-of-type ( type -- assoc )
compiler-errors get-global
- swap [ [ nip compiler-error-type ] dip eq? ] curry
+ swap [ [ nip source-file-error-type ] dip eq? ] curry
assoc-filter ;
: (compiler-report) ( what type word -- )
] if ;
: compiler-report ( -- )
- "semantic errors" +error+ "errors" (compiler-report)
- "semantic warnings" +warning+ "warnings" (compiler-report)
- "linkage errors" +linkage+ "linkage" (compiler-report) ;
+ "compiler errors" +compiler-error+ "errors" (compiler-report)
+ "compiler warnings" +compiler-warning+ "warnings" (compiler-report)
+ "linkage errors" +linkage-error+ "linkage" (compiler-report) ;
: <compiler-error> ( error word -- compiler-error )
\ compiler-error new
swap
- [ >>word ]
+ [ >>asset ]
[ where [ first2 ] [ "<unknown file>" 0 ] if* [ >>file ] [ >>line# ] bi* ] bi
swap >>error ;
USING: accessors assocs kernel math.order sorting sequences ;
IN: source-files.errors
-TUPLE: source-file-error error file line# ;
+TUPLE: source-file-error error asset file line# ;
: sort-errors ( errors -- alerrors'ist )
[ [ [ line#>> ] compare ] sort ] { } assoc-map-as sort-keys ;
: group-by-source-file ( errors -- assoc )
H{ } clone [ [ push-at ] curry [ dup file>> ] prepose each ] keep ;
+
+GENERIC: source-file-error-type ( error -- type )