2e770ec5c4235062712972f7b11a45bc935a83a7
[sbcl.git] / src / compiler / compiler-error.lisp
1 ;;;; the bare essentials of compiler error handling (FIXME: to be
2 ;;;; moved to early-c.lisp when stable)
3
4 ;;;; This software is part of the SBCL system. See the README file for
5 ;;;; more information.
6 ;;;;
7 ;;;; This software is derived from the CMU CL system, which was
8 ;;;; written at Carnegie Mellon University and released into the
9 ;;;; public domain. The software is in the public domain and is
10 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
11 ;;;; files for more information.
12
13 (in-package "SB!C")
14
15 ;;; a function that is called to unwind out of COMPILER-ERROR
16 (declaim (type (function () nil) *compiler-error-bailout*))
17 (defvar *compiler-error-bailout*
18   (lambda () (error "COMPILER-ERROR with no bailout")))
19
20 ;;; We have a separate COMPILER-ERROR condition to allow us to
21 ;;; distinguish internal compiler errors from user errors.
22 ;;; Non-compiler errors put us in the debugger.
23 (define-condition compiler-error (simple-error) ())
24
25 ;;; Signal the appropriate condition. COMPILER-ERROR calls the bailout
26 ;;; function so that it never returns (but compilation continues).
27 ;;; COMPILER-ABORT falls through to the default error handling, so
28 ;;; compilation terminates. 
29 (declaim (ftype (function (string &rest t) nil) compiler-error compiler-abort))
30 (declaim (ftype (function (string &rest t) (values))
31                 compiler-warning compiler-style-warning))
32 (defun compiler-abort (format-string &rest format-args)
33   (error 'compiler-error
34          :format-control format-string
35          :format-arguments format-args))
36 (defun compiler-error (format-string &rest format-args)
37   (cerror "Replace form with call to ERROR."
38           'compiler-error
39           :format-control format-string
40           :format-arguments format-args)
41   (funcall *compiler-error-bailout*)
42   ;; FIXME: It might be nice to define a BUG or OOPS function for "shouldn't
43   ;; happen" cases like this.
44   (error "internal error, control returned from *COMPILER-ERROR-BAILOUT*"))
45 (defun compiler-warning (format-string &rest format-args)
46   (apply #'warn format-string format-args)
47   (values))
48 (defun compiler-style-warning (format-string &rest format-args)
49   (apply #'style-warn format-string format-args)
50   (values))