1
;;; -*- Mode: Lisp; Syntax: Common-Lisp; Package: "CONDITIONS"; Base: 10 -*-
3
(in-package "CONDITIONS")
5
(defvar *internal-error-table* (make-hash-table :test 'equal))
7
(defmacro find-internal-error-data (error-name error-format-string)
8
`(gethash (list ,error-name ,error-format-string) *internal-error-table*))
10
(defun clcs-universal-error-handler (error-name correctable function-name
11
continue-format-string error-format-string
15
(continue "~a" (apply #'format nil continue-format-string args))
16
(error 'internal-simple-error
17
:function-name function-name
18
:format-string error-format-string
19
:format-arguments args))
20
(let ((e-d (find-internal-error-data error-name error-format-string)))
23
(let ((condition-name (car e-d)))
24
(apply #'error condition-name
25
:function-name function-name
26
(let ((k-a (mapcan #'list (cdr e-d) args)))
27
(if (simple-condition-class-p condition-name)
28
(list* :format-string error-format-string
29
:format-arguments args
32
(error 'internal-simple-error :function-name function-name
33
:format-string error-format-string :format-arguments args)))))
35
(defun set-internal-error (error-keyword error-format condition-name
37
(setf (find-internal-error-data error-keyword error-format)
38
(cons condition-name keyword-list)))
40
(defun initialize-internal-error-table ()
41
(declare (special *internal-error-list*))
42
(clrhash *internal-error-table*)
43
(dolist (error-data *internal-error-list*)
44
(apply #'set-internal-error (cdr error-data))))
46
(defparameter *internal-error-list*
47
'(("FEwrong_type_argument" :wrong-type-argument "~S is not of type ~S."
48
internal-type-error :datum :expected-type)
49
("FEtoo_few_arguments" :too-few-arguments "~S [or a callee] requires more than ~R argument~:p."
50
internal-simple-control-error) ; |<function>| |top - base|
51
("FEtoo_few_argumentsF" :too-few-arguments "Too few arguments."
52
internal-simple-control-error) ; |<function>| |args|
53
("FEtoo_many_arguments" :too-many-arguments "~S [or a callee] requires less than ~R argument~:p."
54
internal-simple-control-error) ; |<function>| |top - base|
55
("FEtoo_many_argumentsF" :too-many-arguments "Too many arguments."
56
internal-simple-control-error) ; |<function>| |args|
57
("FEinvalid_macro_call" :invalid-form "Invalid macro call to ~S."
58
internal-simple-program-error) ; |<function>|
59
("FEunexpected_keyword" :unexpected-keyword "~S does not allow the keyword ~S."
60
internal-simple-control-error) ; |<function>| |key|
61
("FEunbound_variable" :unbound-variable "The variable ~S is unbound."
62
internal-unbound-variable :name) ; |sym|
63
("FEundefined_function" :undefined-function "The function ~S is undefined."
64
internal-undefined-function :name)
65
("FEinvalid_function" :invalid-function "~S is invalid as a function."
66
internal-simple-program-error) ; |obj|
67
("check_arg_failed" :too-few-arguments "~S [or a callee] requires ~R argument~:p,~%\
68
but only ~R ~:*~[were~;was~:;were~] supplied."
69
internal-simple-control-error) ; |<function>| |n| |top - base|
70
("check_arg_failed" :too-many-arguments "~S [or a callee] requires only ~R argument~:p,~%\
71
but ~R ~:*~[were~;was~:;were~] supplied."
72
internal-simple-control-error) ; |<function>| |n| |top - base|
73
("ck_larg_at_least" :error "APPLY sended too few arguments to LAMBDA."
74
internal-simple-control-error)
75
("ck_larg_exactly" :error "APPLY sended too few arguments to LAMBDA."
76
internal-simple-control-error)
77
("keyword_value_mismatch" :error "Keywords and values do not match."
78
internal-simple-error) ;??
79
("not_a_keyword" :error "~S is not a keyword."
80
internal-simple-error) ;??
81
("illegal_declare" :invalid-form "~S is an illegal declaration form."
82
internal-simple-program-error)
83
("not_a_symbol" :invalid-variable "~S is not a symbol."
84
internal-simple-error) ;??
85
("not_a_variable" :invalid-variable "~S is not a variable."
86
internal-simple-program-error)
87
("illegal_index" :error "~S is an illegal index to ~S."
88
internal-simple-error)
89
("vfun_wrong_number_of_args" :error "Expected ~S args but received ~S args"
90
internal-simple-control-error)
92
("end_of_stream" :error "Unexpected end of ~S."
93
internal-end-of-file :stream)
94
("open_stream" :error "~S is an illegal IF-DOES-NOT-EXIST option."
95
internal-simple-control-error)
96
("open_stream" :error "The file ~A already exists."
97
internal-simple-file-error :pathname)
98
("open_stream" :error "Cannot append to the file ~A."
99
internal-simple-file-error :pathname)
100
("open_stream" :error "~S is an illegal IF-EXISTS option."
101
internal-simple-control-error)
102
("close_stream" :error "Cannot close the standard output."
103
internal-simple-stream-error) ; no stream here!!
104
("close_stream" :error "Cannot close the standard input."
105
internal-simple-stream-error) ; no stream here!!
106
("too_long_file_name" :error "~S is a too long file name."
107
internal-simple-file-error :pathname)
108
("cannot_open" :error "Cannot open the file ~A."
109
internal-simple-file-error :pathname)
110
("cannot_create" :error "Cannot create the file ~A."
111
internal-simple-file-error :pathname)
112
("cannot_read" :error "Cannot read the stream ~S."
113
internal-simple-stream-error :stream)
114
("cannot_write" :error "Cannot write to the stream ~S."
115
internal-simple-stream-error :stream)
118
(initialize-internal-error-table)
120
(defun condition-backtrace (condition)
121
(let* ((*debug-io* *error-output*)
122
(si::*ihs-base* (1+ si::*ihs-top*))
123
(si::*ihs-top* (1- (si::ihs-top)))
124
(si::*current-ihs* si::*ihs-top*)
125
(si::*frs-base* (or (si::sch-frs-base si::*frs-top* si::*ihs-base*)
127
(si::*frs-top* (si::frs-top))
128
(si::*break-env* nil))
129
(format *error-output* "~%~A~%" condition)
130
(si::simple-backtrace)))
132
(defvar *error-set-break-p* nil)
134
(defun clcs-error-set (form)
136
(restart-case (handler-bind ((error #'(lambda (condition)
137
(unless (or si::*break-enable*
139
(condition-backtrace condition)
140
(return-from clcs-error-set condition))
141
(setq cond condition)
143
(values-list (cons nil (multiple-value-list (eval form)))))
145
:report (lambda (stream)
146
(format stream "~S" `(si::error-set ',form)))
149
(eval-when (compile load eval)
151
(defun reset-function (symbol) ; invoke compiler::compiler-clear-compiler-properties
152
(setf (symbol-function symbol) (symbol-function symbol)))
154
(reset-function 'si::error-set)
155
(reset-function 'load)
156
(reset-function 'open)
159
(setq compiler::*compiler-break-enable* t)
161
(defun compiler::cmp-toplevel-eval (form)
162
(let* (;;(si::*ihs-base* si::*ihs-top*) ; show the whole stack
163
(si::*ihs-top* (1- (si::ihs-top)))
164
(*break-enable* compiler::*compiler-break-enable*)
165
(si::*break-hidden-packages*
166
(cons (find-package 'compiler)
167
si::*break-hidden-packages*)))
168
(si:error-set form)))