ansi-aux-macros.lsp 1.33 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Wed Jul  2 07:05:41 2003
;;;; Contains: Macros used in ansi-aux and elsewhere.

(in-package :cl-test)

(declaim (optimize (safety 3)))

;;; Macros to avoid annoying sbcl warning notes

(defmacro handler-case (form &rest cases)
  `(let () (cl:handler-case ,form ,@cases)))

(defmacro handler-bind (handlers &rest body)
  `(let () (cl:handler-bind ,handlers (normally (progn ,@body)))))

;;; Macros for avoiding dead code warnings

(defvar *should-always-be-true* t)

(declaim (notinline should-never-be-called))

(defun should-never-be-called () nil)

(defmacro normally (form &optional (default-form
sds's avatar
sds committed
27
                                     '(should-never-be-called)))
28 29
  `(if *should-always-be-true* ,form ,default-form))

30 31
;;; Macro to ignore errors, but report them anyway

32 33 34
(defparameter *report-and-ignore-errors-break* nil
  "When true, REPORT-AND-IGNORE-ERRORS breaks instead of discarding the error condition.")

35 36 37 38
(defmacro report-and-ignore-errors (&body body)
  `(eval-when (:load-toplevel :compile-toplevel :execute)
     (#+sbcl let #+sbcl () #-sbcl progn
       (handler-case
sds's avatar
sds committed
39 40 41 42 43 44 45 46
        (progn ,@body)
        (error (condition)
               (princ condition)
               (terpri)
               (when *report-and-ignore-errors-break* (break))
               (values nil condition))))))