diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2021-03-27 16:55:59 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2021-03-27 16:55:59 -0700 |
commit | 893431eca5abc7df6f788912b9e7179bc47faf34 (patch) | |
tree | 16ae29fd01b678eab2ec4a5f1302664481191b67 | |
parent | fcd5374bc0a3cc878cfacea092ce074326ac5940 (diff) | |
download | txr-893431eca5abc7df6f788912b9e7179bc47faf34.tar.gz txr-893431eca5abc7df6f788912b9e7179bc47faf34.tar.bz2 txr-893431eca5abc7df6f788912b9e7179bc47faf34.zip |
compile/eval: more standard formatting for diags.
This patch eliminates parentheses from the error messages,
as well as a leading ./ being added to relative paths.
The word "warning: " is moved into the error message, so that
it does not appear before the location.
Example, when doing (compile-file "path/to/foo.tl").
Before patch:
warning: (./path/to/foo.tl:37): unbound function foo
After:
path/to/foo.tl:37: warning: unbound function foo
Now when I compile out of Vim, it nicely jumps to errors in
Lisp code.
* eval.c (eval_exception): Drop parentheses from error
location, add colon.
(eval_warn): Prepend "warning: " to format string.
(eval_defr_warn): Drop parentheses from location, and
prepend "warning: " to format string.
* parser.c (repl-warning): Drop "warning:" prefix.
* share/txr/stdlib/compiler.tl (open-compile-streams): Do not
do parent substitution for relative paths if the parent path
is the empty string "", to avoid inserting ./ onto relative
paths in that case.
* share/txr/stdlib/error.tl (sys:loc): Drop parentheses and
space from location.
(compile-error) Separate location with colon and space.
(compile-warning, compile-defr-warning): Likewise and add
"warning: " prefix.
* unwind.c (uw_rthrow): Drop "warning: " prefix.
(uw_warningf): Add "warning: " prefix.
(uw_dump_deferred_warnings): Drop "warning: " prefix.
-rw-r--r-- | eval.c | 8 | ||||
-rw-r--r-- | parser.c | 2 | ||||
-rw-r--r-- | share/txr/stdlib/compiler.tl | 2 | ||||
-rw-r--r-- | share/txr/stdlib/error.tl | 9 | ||||
-rw-r--r-- | unwind.c | 5 |
5 files changed, 13 insertions, 13 deletions
@@ -294,7 +294,7 @@ static void eval_exception(val sym, val ctx, val fmt, va_list vl) source_loc_str(last_form_evaled, nil)); if (loc) - format(stream, lit("(~a) "), loc, nao); + format(stream, lit("~a: "), loc, nao); (void) vformat(stream, fmt, vl); @@ -319,7 +319,7 @@ static val eval_warn(val ctx, val fmt, ...) uw_catch_begin (cons(continue_s, nil), exsym, exvals); va_start (vl, fmt); - eval_exception(warning_s, ctx, fmt, vl); + eval_exception(warning_s, ctx, scat2(lit("warning: "), fmt), vl); va_end (vl); uw_catch(exsym, exvals) { (void) exsym; (void) exvals; } @@ -347,9 +347,9 @@ static val eval_defr_warn(val ctx, val tag, val fmt, ...) source_loc_str(last_form_evaled, nil)); if (loc) - format(stream, lit("(~a) "), loc, nao); + format(stream, lit("~a: "), loc, nao); - (void) vformat(stream, fmt, vl); + (void) vformat(stream, scat2(lit("warning: "), fmt), vl); uw_rthrow(defr_warning_s, cons(get_string_from_stream(stream), cons(tag, nil))); @@ -1188,7 +1188,7 @@ static val repl_warning(val out_stream, val exc, struct args *rest) if (cdr(args)) uw_defer_warning(args); else - format(out_stream, lit("** warning: ~!~a\n"), car(args), nao); + format(out_stream, lit("** ~!~a\n"), car(args), nao); return uw_rthrow(continue_s, nil); } diff --git a/share/txr/stdlib/compiler.tl b/share/txr/stdlib/compiler.tl index 39cda32d..1ab48537 100644 --- a/share/txr/stdlib/compiler.tl +++ b/share/txr/stdlib/compiler.tl @@ -2139,7 +2139,7 @@ (defun open-compile-streams (in-path out-path test-fn) (let* ((parent (or *load-path* "")) (sep [path-sep-chars 0]) - (in-path (if (pure-rel-path-p in-path) + (in-path (if (and (pure-rel-path-p in-path) (not (empty parent))) `@(dir-name parent)@sep@{in-path}` in-path)) (rsuff (r$ %file-suff-rx% in-path)) diff --git a/share/txr/stdlib/error.tl b/share/txr/stdlib/error.tl index 8a0a93fa..42d5d6b9 100644 --- a/share/txr/stdlib/error.tl +++ b/share/txr/stdlib/error.tl @@ -32,22 +32,21 @@ ctx) (defun sys:loc (ctx) - (let ((form (sys:ctx-form ctx))) - `(@(source-loc-str form)) `)) + (source-loc-str (sys:ctx-form ctx))) (defun compile-error (ctx fmt . args) (let* ((nctx (sys:dig ctx)) (loc (sys:loc nctx)) (name (sys:ctx-name nctx))) (dump-deferred-warnings *stderr*) - (throwf 'eval-error `@loc~s: @fmt` name . args))) + (throwf 'eval-error `@loc: ~s: @fmt` name . args))) (defun compile-warning (ctx fmt . args) (let* ((nctx (sys:dig ctx)) (loc (sys:loc nctx)) (name (sys:ctx-name nctx))) (usr:catch - (throwf 'warning `@loc~s: @fmt` name . args) + (throwf 'warning `@loc: warning: ~s: @fmt` name . args) (continue ())))) (defun compile-defr-warning (ctx tag fmt . args) @@ -55,7 +54,7 @@ (loc (sys:loc nctx)) (name (sys:ctx-name nctx))) (usr:catch - (throw 'defr-warning (fmt `@loc~s: @fmt` name . args) tag) + (throw 'defr-warning (fmt `@loc: warning: ~s: @fmt` name . args) tag) (continue ())))) (defun sys:bind-mac-error (ctx-form params obj too-few-p) @@ -713,7 +713,7 @@ val uw_rthrow(val sym, val args) if (uw_exception_subtype_p(sym, defr_warning_s)) uw_defer_warning(args); else if (std_error != 0) - format(std_error, lit("warning: ~a\n"), car(args), nao); + format(std_error, lit("~a\n"), car(args), nao); if (!opt_compat || opt_compat >= 234) { uw_rthrow(continue_s, nil); return nil; @@ -818,6 +818,7 @@ val uw_warningf(val fmt, ...) val stream = make_string_output_stream(); va_start (vl, fmt); + put_string(lit("warning: "), stream); (void) vformat(stream, fmt, vl); va_end (vl); @@ -879,7 +880,7 @@ val uw_dump_deferred_warnings(val stream) for (; wl; wl = cdr(wl)) { val args = car(wl); - format(stream, lit("warning: ~a\n"), car(args), nao); + format(stream, lit("~a\n"), car(args), nao); } return nil; |