From 54256c89eec80c2a909416dc86c1cc9e0ed0c046 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sat, 26 Nov 2016 19:46:18 -0800 Subject: 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. --- share/txr/stdlib/except.tl | 3 +++ share/txr/stdlib/place.tl | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'share') diff --git a/share/txr/stdlib/except.tl b/share/txr/stdlib/except.tl index ad5cb0b9..addc3a66 100644 --- a/share/txr/stdlib/except.tl +++ b/share/txr/stdlib/except.tl @@ -44,3 +44,6 @@ syms-fragments))) ,[mapcar car syms-fragments] ,try-form))) + +(defmacro ignwarn (. forms) + ^(handler-bind (lambda (exc-sym arg) (throw 'continue)) (warning) ,*forms)) diff --git a/share/txr/stdlib/place.tl b/share/txr/stdlib/place.tl index 20650ad0..b18fddbf 100644 --- a/share/txr/stdlib/place.tl +++ b/share/txr/stdlib/place.tl @@ -183,7 +183,7 @@ (expander (get-update-expander place)) (sys:*pl-env* env) (expansion [expander getter setter place body]) - (expansion-ex (sys:expand expansion env))) + (expansion-ex (ignwarn (sys:expand expansion env)))) (sys:cp-origin expansion-ex place))) (defun call-clobber-expander (ssetter unex-place env body) @@ -191,7 +191,7 @@ (expander (get-clobber-expander place)) (sys:*pl-env* env) (expansion [expander ssetter place body]) - (expansion-ex (sys:expand expansion env))) + (expansion-ex (ignwarn (sys:expand expansion env)))) (sys:cp-origin expansion-ex place))) (defun call-delete-expander (deleter unex-place env body) @@ -199,7 +199,7 @@ (expander (get-delete-expander place)) (sys:*pl-env* env) (expansion [expander deleter place body]) - (expansion-ex (sys:expand expansion env))) + (expansion-ex (ignwarn (sys:expand expansion env)))) (sys:cp-origin expansion-ex place)))) (defmacro with-update-expander ((getter setter) unex-place env body) -- cgit v1.2.3