[Ecls-list] Detection and handling of compiler conditions

Juan Jose Garcia-Ripoll juanjose.garciaripoll at googlemail.com
Wed Aug 20 20:56:15 UTC 2008


 - WITH-COMPILATION-UNIT allows the user to set up handlers for different
   compiler conditions, including errors, warnings and simple notes. The
   recommended procedure is to use HANDLER-BIND and _NOT_ to transfer control
   out of the handler, but to defer to the default ones.
	(use-package :c)
	(let ((warnings nil))
	  (with-compilation-unit ()
	    (handler-bind ((compiler-error #'(lambda (c)
					       (push c warnings)
					       (abort)))
			   (compiler-message #'(lambda (c)
						 (push c warnings)
						 (muffle-warning))))
	      (let ((*compile-verbose* nil))
		(compile-file "foo.lsp"))))
	  (format t "~&;;; Printing compiler messages")
	  (loop for m in (nreverse warnings)
	     for i from 0
	     do (format t "~&~@<;;; ~@;Message #~D~%~A~:>" i m)))

Applied to this file: foo.lsp

(defun foo (x)
 (print x t extra-argument))

Gives the following

;;; Printing messages
;;; Message #0
;;; Variable EXTRA-ARGUMENT was undefined. Compiler assumes it is a global.
;;; Message #1
;;; Invoking external command:
;;; ;;; gcc  -g -O2 -fPIC -fno-common  -Ddarwin -O
"-I/Users/jjgarcia/include/" -w -c
"/Users/jjgarcia/src/ecl/build/foo.c" -o
"/Users/jjgarcia/src/ecl/build/foo.o"
;;; Message #2
;;; Invoking external command:
;;; ;;; gcc -o "/Users/jjgarcia/src/ecl/build/foo.fas"
-L"/Users/jjgarcia/lib/" "/Users/jjgarcia/src/ecl/build/foo.o"
-bundle    -lecl   -lm


Comments on the implementation are welcome :-)

-- 
Instituto de Física Fundamental
CSIC, Serrano, 113, Madrid 28040 (Spain)
http://juanjose.garciaripoll.googlepages.com


More information about the ecl-devel mailing list