0.7.12.19:
[sbcl/lichteblau.git] / src / compiler / compiler-error.lisp
blob0c5e75148672a7a2181a5e02ba31c4b182856a67
1 ;;;; the bare essentials of compiler error handling
2 ;;;;
3 ;;;; (Logically, this might belong in early-c.lisp, since it's stuff
4 ;;;; which might as well be visible to all compiler code. However,
5 ;;;; physically its DEFINE-CONDITION forms depend on the condition
6 ;;;; system being set up before it can be cold loaded, so we keep it
7 ;;;; in this separate, loaded-later file instead of in early-c.lisp.)
9 ;;;; This software is part of the SBCL system. See the README file for
10 ;;;; more information.
11 ;;;;
12 ;;;; This software is derived from the CMU CL system, which was
13 ;;;; written at Carnegie Mellon University and released into the
14 ;;;; public domain. The software is in the public domain and is
15 ;;;; provided with absolutely no warranty. See the COPYING and CREDITS
16 ;;;; files for more information.
18 (in-package "SB!C")
20 ;;;; error-handling definitions which are easy to define early and
21 ;;;; which are nice to have visible everywhere
23 ;;; a function that is called to unwind out of COMPILER-ERROR
24 (declaim (type (function () nil) *compiler-error-bailout*))
25 (defvar *compiler-error-bailout*
26 (lambda () (error "COMPILER-ERROR with no bailout")))
28 ;;; an application programmer's error caught by the compiler
29 ;;;
30 ;;; We want a separate condition for application programmer errors so
31 ;;; that we can distinguish them from system programming errors (bugs
32 ;;; in SBCL itself). Application programmer errors should be caught
33 ;;; and turned into diagnostic output and a FAILURE-P return value
34 ;;; from COMPILE or COMPILE-FILE. Bugs in SBCL itself throw us into
35 ;;; the debugger.
36 (define-condition compiler-error (simple-error) ())
38 ;;; Signal the appropriate condition. COMPILER-ERROR calls the bailout
39 ;;; function so that it never returns (but compilation continues).
40 ;;; COMPILER-ABORT falls through to the default error handling, so
41 ;;; compilation terminates.
42 (declaim (ftype (function (string &rest t) nil) compiler-error compiler-abort))
43 (declaim (ftype (function (string &rest t) (values))
44 compiler-warning compiler-style-warning))
45 (defun compiler-abort (format-string &rest format-args)
46 (error 'compiler-error
47 :format-control format-string
48 :format-arguments format-args))
49 (defun compiler-error (format-string &rest format-args)
50 (cerror "Replace form with call to ERROR."
51 'compiler-error
52 :format-control format-string
53 :format-arguments format-args)
54 (funcall *compiler-error-bailout*)
55 (bug "Control returned from *COMPILER-ERROR-BAILOUT*."))
56 (defun compiler-warn (format-string &rest format-args)
57 (apply #'warn format-string format-args)
58 (values))
59 (defun compiler-style-warn (format-string &rest format-args)
60 (apply #'style-warn format-string format-args)
61 (values))
63 ;;; the condition of COMPILE-FILE being unable to READ from the
64 ;;; source file
65 ;;;
66 ;;; This is not a COMPILER-ERROR, since we don't try to recover from
67 ;;; it and keep chugging along, but instead immediately bail out of
68 ;;; the entire COMPILE-FILE.
69 ;;;
70 ;;; (The old CMU CL code did try to recover from this condition, but
71 ;;; the code for doing that was messy and didn't always work right.
72 ;;; Since in Common Lisp the simple act of reading and compiling code
73 ;;; (even without ever loading the compiled result) can have side
74 ;;; effects, it's a little scary to go on reading code when you're
75 ;;; deeply confused, so we violate what'd otherwise be good compiler
76 ;;; practice by not trying to recover from this error and bailing out
77 ;;; instead.)
78 (define-condition input-error-in-compile-file (error)
79 (;; the original error which was trapped to produce this condition
80 (error :reader input-error-in-compile-file-error
81 :initarg :error)
82 ;; the position where the bad READ began, or NIL if unavailable,
83 ;; redundant, or irrelevant
84 (position :reader input-error-in-compile-file-position
85 :initarg :position
86 :initform nil))
87 (:report
88 (lambda (condition stream)
89 (format stream
90 "~@<~S failure in ~S~@[ at character ~W~]: ~2I~_~A~:>"
91 'read
92 'compile-file
93 (input-error-in-compile-file-position condition)
94 (input-error-in-compile-file-error condition)))))