]> gitweb.factorcode.org Git - factor.git/commitdiff
Factor out some compiler error code into source-files.errors
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 9 Apr 2009 09:50:38 +0000 (04:50 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 9 Apr 2009 09:50:38 +0000 (04:50 -0500)
basis/debugger/debugger.factor
basis/stack-checker/errors/prettyprint/prettyprint.factor
basis/tools/errors/authors.txt [new file with mode: 0644]
basis/tools/errors/errors.factor [new file with mode: 0644]
core/compiler/errors/errors.factor
core/parser/parser-tests.factor
core/parser/parser.factor
core/source-files/errors/authors.txt [new file with mode: 0644]
core/source-files/errors/errors.factor [new file with mode: 0644]
core/source-files/source-files.factor

index 04f43043b5f987e57cad0bb3eb9f1448515547dd..202cf7eb5ec19d85e21eec585f2c5fd5addd518e 100644 (file)
@@ -9,7 +9,8 @@ combinators generic.math classes.builtin classes compiler.units
 generic.standard vocabs init kernel.private io.encodings
 accessors math.order destructors source-files parser
 classes.tuple.parser effects.parser lexer compiler.errors
-generic.parser strings.parser vocabs.loader vocabs.parser see ;
+generic.parser strings.parser vocabs.loader vocabs.parser see
+source-files.errors ;
 IN: debugger
 
 GENERIC: error. ( error -- )
@@ -268,11 +269,6 @@ M: duplicate-slot-names summary
 M: invalid-slot-name summary
     drop "Invalid slot name" ;
 
-: file. ( file -- ) path>> <pathname> . ;
-
-M: source-file-error error.
-    [ file>> file. ] [ error>> error. ] bi ;
-
 M: source-file-error summary
     error>> summary ;
 
@@ -309,12 +305,13 @@ M: lexer-error compute-restarts
 M: lexer-error error-help
     error>> error-help ;
 
-M: compiler-error compiler-error. ( error -- )
+M: source-file-error error.
     [
         [
             [
-                [ line#>> # ": " % ]
-                [ word>> synopsis % ] bi
+                [ file>> [ % ": " % ] when* ]
+                [ line#>> [ # ": " % ] when* ]
+                [ summary % ] tri
             ] "" make
         ] [
             [
@@ -324,7 +321,7 @@ M: compiler-error compiler-error. ( error -- )
         ] bi format nl
     ] [ error>> error. ] bi ;
 
-M: compiler-error error. compiler-error. ;
+M: compiler-error summary word>> synopsis ;
 
 M: bad-effect summary
     drop "Bad stack effect declaration" ;
index c111f3bb9f4c66ddfedd8dd4599a47e2d42fa2f2..de73a3e731341be773f558c651952ca36283a93c 100644 (file)
@@ -41,7 +41,7 @@ M: missing-effect summary
 
 M: effect-error summary
     [
-        "Stack effect declaration of the word  " %
+        "Stack effect declaration of the word " %
         word>> name>> % " is wrong" %
     ] "" make ;
 
diff --git a/basis/tools/errors/authors.txt b/basis/tools/errors/authors.txt
new file mode 100644 (file)
index 0000000..d4f5d6b
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov
\ No newline at end of file
diff --git a/basis/tools/errors/errors.factor b/basis/tools/errors/errors.factor
new file mode 100644 (file)
index 0000000..a11b60d
--- /dev/null
@@ -0,0 +1,25 @@
+! Copyright (C) 2009 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: assocs compiler.errors debugger io kernel sequences
+source-files.errors ;
+IN: tools.errors
+
+#! Tools for source-files.errors. Used by tools.tests and others
+#! for error reporting
+
+: errors. ( errors -- )
+    group-by-source-file sort-errors
+    [
+        [ nl "==== " write print nl ]
+        [ [ nl ] [ error. ] interleave ]
+        bi*
+    ] assoc-each ;
+
+: compiler-errors. ( type -- )
+    errors-of-type errors. ;
+
+: :errors ( -- ) +error+ compiler-errors. ;
+
+: :warnings ( -- ) +warning+ compiler-errors. ;
+
+: :linkage ( -- ) +linkage+ compiler-errors. ;
index f5e6fda646807f00d912fac5e73a470f7d24676a..9d8ab3deab530da6dabe827930a68199b4a30a94 100644 (file)
@@ -1,15 +1,13 @@
 ! Copyright (C) 2007, 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: kernel namespaces make assocs io sequences
-sorting continuations math math.order math.parser accessors
-definitions ;
+continuations math math.parser accessors definitions
+source-files.errors ;
 IN: compiler.errors
 
-SYMBOL: +error+
-SYMBOL: +warning+
-SYMBOL: +linkage+
+SYMBOLS: +error+ +warning+ +linkage+ ;
 
-TUPLE: compiler-error error word file line# ;
+TUPLE: compiler-error < source-file-error word ;
 
 GENERIC: compiler-error-type ( error -- ? )
 
@@ -17,8 +15,6 @@ M: object compiler-error-type drop +error+ ;
 
 M: compiler-error compiler-error-type error>> compiler-error-type ;
 
-GENERIC: compiler-error. ( error -- )
-
 SYMBOL: compiler-errors
 
 compiler-errors [ H{ } clone ] initialize
@@ -30,20 +26,6 @@ SYMBOL: with-compiler-errors?
     swap [ [ nip compiler-error-type ] dip eq? ] curry
     assoc-filter ;
 
-: sort-compile-errors ( assoc -- alist )
-    [ [ [ line#>> ] compare ] sort ] { } assoc-map-as sort-keys ;
-
-: group-by-source-file ( errors -- assoc )
-    H{ } clone [ [ push-at ] curry [ nip dup file>> ] prepose assoc-each ] keep ;
-
-: compiler-errors. ( type -- )
-    errors-of-type group-by-source-file sort-compile-errors
-    [
-        [ nl "==== " write print nl ]
-        [ [ nl ] [ compiler-error. ] interleave ]
-        bi*
-    ] assoc-each ;
-
 : (compiler-report) ( what type word -- )
     over errors-of-type assoc-empty? [ 3drop ] [
         [
@@ -62,14 +44,12 @@ SYMBOL: with-compiler-errors?
     "semantic warnings" +warning+ "warnings" (compiler-report)
     "linkage errors" +linkage+ "linkage" (compiler-report) ;
 
-: :errors ( -- ) +error+ compiler-errors. ;
-
-: :warnings ( -- ) +warning+ compiler-errors. ;
-
-: :linkage ( -- ) +linkage+ compiler-errors. ;
-
 : <compiler-error> ( error word -- compiler-error )
-    dup where [ first2 ] [ "<unknown file>" 0 ] if* \ compiler-error boa ;
+    \ compiler-error new
+        swap
+        [ >>word ]
+        [ where [ first2 ] [ "<unknown file>" 0 ] if* [ >>file ] [ >>line# ] bi* ] bi
+        swap >>error ;
 
 : compiler-error ( error word -- )
     compiler-errors get-global pick
index 3ba414fe6beb9304cbd6ff56def0e823ddd92697..9e1fcb95bdcc1c49a940a07386b46657d3dc3514 100644 (file)
@@ -3,7 +3,7 @@ io.streams.string namespaces classes effects source-files assocs
 sequences strings io.files io.pathnames definitions
 continuations sorting classes.tuple compiler.units debugger
 vocabs vocabs.loader accessors eval combinators lexer
-vocabs.parser words.symbol multiline ;
+vocabs.parser words.symbol multiline source-files.errors ;
 IN: parser.tests
 
 \ run-file must-infer
index 6d613a8b2459e30340bc3a46ec36a3845ba2f3da..04fa7fa03f7e04b92ae631f4466956ff23ff89b3 100644 (file)
@@ -190,6 +190,7 @@ SYMBOL: interactive-vocabs
     "tools.annotations"
     "tools.crossref"
     "tools.disassembler"
+    "tools.errors"
     "tools.memory"
     "tools.profiler"
     "tools.test"
diff --git a/core/source-files/errors/authors.txt b/core/source-files/errors/authors.txt
new file mode 100644 (file)
index 0000000..d4f5d6b
--- /dev/null
@@ -0,0 +1 @@
+Slava Pestov
\ No newline at end of file
diff --git a/core/source-files/errors/errors.factor b/core/source-files/errors/errors.factor
new file mode 100644 (file)
index 0000000..9972a68
--- /dev/null
@@ -0,0 +1,12 @@
+! Copyright (C) 2009 Slava Pestov.
+! See http://factorcode.org/license.txt for BSD license.
+USING: accessors assocs kernel math.order sorting ;
+IN: source-files.errors
+
+TUPLE: source-file-error error file line# ;
+
+: sort-errors ( assoc -- alist )
+    [ [ [ line#>> ] compare ] sort ] { } assoc-map-as sort-keys ;
+
+: group-by-source-file ( errors -- assoc )
+    H{ } clone [ [ push-at ] curry [ nip dup file>> ] prepose assoc-each ] keep ;
index c8441ba3b0a2bf65605720ee4f50f0a66aa1d976..8edd62260aa856ab460052e1ec029d230ec47c50 100644 (file)
@@ -4,7 +4,7 @@ USING: arrays definitions generic assocs kernel math namespaces
 sequences strings vectors words quotations io io.files
 io.pathnames combinators sorting splitting math.parser effects
 continuations checksums checksums.crc32 vocabs hashtables graphs
-compiler.units io.encodings.utf8 accessors ;
+compiler.units io.encodings.utf8 accessors source-files.errors ;
 IN: source-files
 
 SYMBOL: source-files
@@ -77,21 +77,20 @@ M: pathname forget*
 
 SYMBOL: file
 
-TUPLE: source-file-error error file ;
-
-: <source-file-error> ( msg -- error )
+: wrap-source-file-error ( error -- * )
+    file get rollback-source-file
     \ source-file-error new
-        file get >>file
-        swap >>error ;
+        f >>line#
+        file get path>> >>file
+        swap >>error rethrow  ;
 
 : with-source-file ( name quot -- )
     #! Should be called from inside with-compilation-unit.
     [
-        swap source-file
-        dup file set
-        definitions>> old-definitions set
         [
-            file get rollback-source-file
-            <source-file-error> rethrow
-        ] recover
+            source-file
+            [ file set ]
+            [ definitions>> old-definitions set ] bi
+        ] dip
+        [ wrap-source-file-error ] recover
     ] with-scope ; inline