[Ecls-list] Compiler conditions
Juan Jose Garcia-Ripoll
jjgarcia at users.sourceforge.net
Tue May 20 09:42:25 UTC 2008
On Mon, May 19, 2008 at 9:20 PM, Gabriel Dos Reis <gdr at cs.tamu.edu> wrote:
> "Juan Jose Garcia-Ripoll" <jjgarcia at users.sourceforge.net> writes:
> | My goal is to transform all compiler notes, warnings and errors into
> | conditions. They should be collected until compilation finishes,
> | either successfully or because one of the errors was severe. Using
> | conditions should allow you to capture the errors in an automated way.
>
> Yes, that is a better plan. Thanks!
Actually, it is mostly done in my laptop (See below for an excerpt).
What prevents me from adding it right now is that I cannot figure out
what is the best way to expose all those conditions. One serious
problem I find with Common-Lisp is that, from outside a function I
call, I cannot override the handlers for conditions generated in that
function, because the handlers established by the function take
priority.
Take for instance COMPILE-FILE. It has to set up handlers for
compiler-note, compiler-warning, compiler-error, etc. The ones for
compiler-note and -warning may just return NIL, and let outside
handlers defined by the user do whatever they want. But the errors
have to be caught somehow.
I can thus only think of two solutions:
1) Forget about the user setting handlers for different conditions.
Conditions are simply collected and processed by a function
(FINALIZE-COMPILATION). This function is either called by COMPILE-FILE
or at the end of a WITH-COMPILATION-UNIT. It calls itself a
*FINALIZE-COMPILATION-HOOK* before doing the required tasks.
2) Recode HANDLE-FATAL-ERROR so that it calls (SIGNAL c) _before_
invoking the restart. This way, if the user has a handler for such
conditions it may get invoked. We run the risk that the user sets up a
handler for any kind of conditions thus messing up the whole thing.
Indeed the last point raised in 2) is probably enough to consider 1) a
more viable option, even if less elegant.
Juanjo
+(defun handle-fatal-error (c)
+ (push c *compiler-conditions*)
+ (abort))
+
+(defun handle-note (c)
+ (push c *compiler-conditions*)
+ (if *suppress-compiler-notes*
+ (muffle-warning c)
+ (format t "~&~@<;;; ~@:;Note: ~A~@:>" c)))
+
+(defun handle-warning (c)
+ (push c *compiler-conditions*)
+ (if *suppress-compiler-warnings*
+ (muffle-warning c)
+ (format t "~&~@<;;; ~@;Warning: ~A~:>" c)))
+
+(defun handle-error (c)
+ (push c *compiler-conditions*)
+ (format t "~&~@<;;; ~@;Error:~%~A~:>" c)
+ (invoke-restart (find-restart-never-fail 'abort-form c)))
+
+(defmacro with-compiler-env ((error-flag) &body body)
+ `(with-lock (+load-compile-lock+)
+ (restart-case
+ (handler-bind ((compiler-note #'handle-note)
+ (compiler-warning #'handle-warning)
+ (compiler-error #'handle-error)
+ (compiler-fatal-error #'handle-fatal-error))
+ (let ,+init-env-form+
+ (setf ,error-flag nil)
+ , at body))
+ (abort (c) (setf ,error-flag t))
+ (abort-form (c) (setf ,error-flag t)))))
--
Facultad de Fisicas, Universidad Complutense,
Ciudad Universitaria s/n Madrid 28040 (Spain)
http://juanjose.garciaripoll.googlepages.com
More information about the ecl-devel
mailing list