summaryrefslogtreecommitdiffstats
path: root/parser.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-11-26 19:46:18 -0800
committerKaz Kylheku <kaz@kylheku.com>2016-11-26 19:46:18 -0800
commit54256c89eec80c2a909416dc86c1cc9e0ed0c046 (patch)
treedd76b6320af000965982dbf9d6a8dc7a609812fa /parser.c
parent30b30d178a59ba42182d707061b86bb7580ebeb6 (diff)
downloadtxr-54256c89eec80c2a909416dc86c1cc9e0ed0c046.tar.gz
txr-54256c89eec80c2a909416dc86c1cc9e0ed0c046.tar.bz2
txr-54256c89eec80c2a909416dc86c1cc9e0ed0c046.zip
Expander warns about unbound variables.
* eval.c (eval_exception): New static function. (eval_error): Reduced to wrapper around eval_exception. (eval_warn): New function. (me_op): Bind the rest symbol in a shadowing env to suppress watnings about unbound rest. (do_expand): Throw a warning when a bindable symbol is traversed that has no binding. (expand): Don't install atoms as last_form_expanded. * lib.c (warning_s, restart_s, continue_s): New symbol variables. (obj_init): Initialize new symbol variables. * lib.h (warning_s, restart_s, continue_s): Declared. * lisplib.c (except_set_entries): New entries for ignwarn and macro-time-ignwarn. * parser.c (repl_warning): New static function. (repl): Use repl_warning function as a handler for warning exceptions: to print their message and then continue by throwing a continue exception. * parser.y (warning_continue): New static function. (parse_once): Use warning_continue to ignore warnings. In other words, we suppress warnings from Lisp that is mixed into TXR pattern language code, because this produces too many false positives. * share/txr/stdlib/except.tl (ignwarn, macro-time-ignwarn): New macros. * share/txr/stdlib/place.tl (call-update-expander, call-clobber-expander, call-delete-expander): Ignore warnings around calls to sys:expand, because of some gensym-related false positives (we expand code into which we inserted some gensyms, without having inserted the constructs which bind them. * tests/011/macros-2.txr: Suppress unbound variable warnings from a test case. * tests/012/ifa.tl: Bind unbound x y variables in one test case. * tests/012/struct.tl: Suppress unbound variable warnings in some test cases. * uwind.c (uw_throw): If a warning is unhandled, then print its message with a "warning" prefix and then throw a continue exception. (uw_register_subtype): Eliminate the check for sub already being a subtype of sup. This allows us to officially register new types against t. (uw_late_init): Register continue exception type as a subtype of the restart type. Formally register warning type. * txr.1: Documented ignwarn.
Diffstat (limited to 'parser.c')
-rw-r--r--parser.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/parser.c b/parser.c
index 681ffe75..f4f1c1ce 100644
--- a/parser.c
+++ b/parser.c
@@ -887,6 +887,12 @@ static val get_home_path(void)
return getenv_wrap(lit("HOME"));
}
+static val repl_warning(val out_stream, val exc, val arg)
+{
+ format(out_stream, lit("** warning: ~!~a\n"), arg, nao);
+ uw_throw(continue_s, nil);
+}
+
val repl(val bindings, val in_stream, val out_stream)
{
val ifd = stream_get_prop(in_stream, fd_k);
@@ -911,6 +917,7 @@ val repl(val bindings, val in_stream, val out_stream)
val hist_len_var = lookup_global_var(listener_hist_len_s);
val multi_line_var = lookup_global_var(listener_multi_line_p_s);
val sel_inclusive_var = lookup_global_var(listener_sel_inclusive_p_s);
+ val rw_f = func_f2(out_stream, repl_warning);
for (; bindings; bindings = cdr(bindings)) {
val binding = car(bindings);
@@ -937,6 +944,7 @@ val repl(val bindings, val in_stream, val out_stream)
val var_counter = mod(counter, num_fast(100));
val var_name = format(nil, lit("*~d"), var_counter, nao);
val var_sym = intern(var_name, user_package);
+ uw_frame_t uw_handler;
char *prompt_u8 = utf8_dup_to(c_str(prompt));
@@ -984,6 +992,8 @@ val repl(val bindings, val in_stream, val out_stream)
uw_catch_begin (catch_all, exsym, exvals);
+ uw_push_handler(&uw_handler, cons(warning_s, nil), rw_f);
+
{
val name = format(nil, lit("expr-~d"), prev_counter, nao);
val line = string_utf8(line_u8);
@@ -1003,6 +1013,8 @@ val repl(val bindings, val in_stream, val out_stream)
}
}
+ uw_pop_frame(&uw_handler);
+
uw_catch (exsym, exvals) {
val exinfo = cons(exsym, exvals);
reg_varl(var_sym, exinfo);