[b0ce08]: src / c / error.d Maximize Restore History

Download this file

error.d    268 lines (230 with data), 5.8 kB

  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
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/*
error.c -- Error handling.
*/
/*
Copyright (c) 1984, Taiichi Yuasa and Masami Hagiya.
Copyright (c) 1990, Giuseppe Attardi.
Copyright (c) 2001, Juan Jose Garcia Ripoll.
ECL is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
See file '../Copyright' for full details.
*/
#include "ecl.h"
#include <signal.h>
void
cs_overflow(void)
{
#ifdef DOWN_STACK
if (cs_limit < cs_org - cssize)
cs_limit -= CSGETA;
#else
if (cs_limit > cs_org + cssize)
cs_limit += CSGETA;
#endif
FEerror("Control stack overflow.", 0);
}
void
error(const char *s)
{
printf("\nUnrecoverable error: %s\n", s);
fflush(stdout);
#ifdef SIGIOT
signal(SIGIOT, SIG_DFL); /* avoid getting into a loop with abort */
#endif
abort();
}
void
internal_error(const char *s)
{
printf("\nInternal error in %s()\n", s);
fflush(stdout);
#ifdef SIGIOT
signal(SIGIOT, SIG_DFL); /* avoid getting into a loop with abort */
#endif
abort();
}
/*****************************************************************************/
/* Support for Lisp Error Handler */
/*****************************************************************************/
cl_object null_string;
void
terminal_interrupt(bool correctable)
{
funcall(2, @'si::terminal-interrupt', correctable? Ct : Cnil);
}
void
FEerror(char *s, int narg, ...)
{
cl_va_list args;
cl_va_start(args, narg, narg, 0);
funcall(4, @'si::universal-error-handler',
Cnil, /* not correctable */
make_constant_string(s), /* condition text */
cl_grab_rest_args(args));
}
cl_object
CEerror(char *err, int narg, ...)
{
cl_va_list args;
cl_va_start(args, narg, narg, 0);
return funcall(4, @'si::universal-error-handler',
Ct, /* correctable */
make_constant_string(err), /* continue-format-string */
cl_grab_rest_args(args));
}
/***********************
* Conditions signaler *
***********************/
void
FEcondition(int narg, cl_object name, ...)
{
cl_va_list args;
cl_va_start(args, name, narg, 1);
funcall(4, @'si::universal-error-handler',
Cnil, /* not correctable */
name, /* condition name */
cl_grab_rest_args(args));
}
void
FEprogram_error(const char *s, int narg, ...)
{
cl_va_list args;
gc(t_contiguous);
cl_va_start(args, narg, narg, 0);
funcall(4, @'si::universal-error-handler',
Cnil, /* not correctable */
@'si::simple-program-error', /* condition name */
cl_list(4, @':format-control', make_constant_string(s),
@':format-arguments', cl_grab_rest_args(args)));
}
void
FEcontrol_error(const char *s, int narg, ...)
{
cl_va_list args;
cl_va_start(args, narg, narg, 0);
funcall(4, @'si::universal-error-handler',
Cnil, /* not correctable */
@'si::simple-control-error', /* condition name */
cl_list(4, @':format-control', make_constant_string(s),
@':format-arguments', cl_grab_rest_args(args)));
}
void
FEcannot_open(cl_object fn)
{
FEcondition(3, @'file-error', @':pathname', fn);
}
void
FEend_of_file(cl_object strm)
{
FEcondition(3, @'end-of-file', @':stream', strm);
}
void
FEwrong_type_argument(cl_object type, cl_object value)
{
FEcondition(5, @'type-error', @':datum', value, @':expected-type', type);
}
void
FEunbound_variable(cl_object sym)
{
FEcondition(3, @'unbound-variable', @':name', sym);
}
void
FEundefined_function(cl_object fname)
{
FEcondition(3, @'undefined-function', @':name', fname);
}
/*************
* Shortcuts *
*************/
void
FEtoo_few_arguments(int narg)
{
cl_object fname = ihs_top_function_name();
FEprogram_error("Function ~S requires more than ~R argument~:p.",
2, fname, MAKE_FIXNUM(narg));
}
void
FEtoo_many_arguments(int narg)
{
cl_object fname = ihs_top_function_name();
FEprogram_error("Function ~S requires less than ~R argument~:p.",
2, fname, MAKE_FIXNUM(narg));
}
void
FEinvalid_macro_call(cl_object name)
{
FEerror("Invalid macro call to ~S.", 1, name);
}
void
FEinvalid_variable(char *s, cl_object obj)
{
FEerror(s, 1, obj);
}
void
FEassignment_to_constant(cl_object v)
{
FEprogram_error("SETQ: Tried to assign a value to the constant ~S.", 1, v);
}
void
FEinvalid_function(cl_object obj)
{
FEwrong_type_argument(@'function', obj);
}
/* bootstrap version */
static
@(defun "universal_error_handler" (c err args)
@
error("\nLisp initialization error.\n");
@)
void
check_arg_failed(int narg, int req)
{
cl_object fname = ihs_top_function_name();
FEprogram_error((narg < req)
? "Function ~S requires ~R argument~:p,~%\
but only ~R ~:*~[were~;was~:;were~] supplied."
: "Function ~S requires only ~R argument~:p,~%\
but ~R ~:*~[were~;was~:;were~] supplied.",
3, fname, MAKE_FIXNUM(req), MAKE_FIXNUM(narg));
}
void
illegal_index(cl_object x, cl_object i)
{
FEerror("~S is an illegal index to ~S.", 2, i, x);
}
void
FEtype_error_symbol(cl_object obj)
{
FEwrong_type_argument(@'symbol', obj);
}
void
not_a_variable(cl_object obj)
{
FEinvalid_variable("~S is not a variable.", obj);
}
/************************************
* Higher level interface to errors *
************************************/
@(defun error (eformat &rest args)
@
funcall(4, @'si::universal-error-handler',
Cnil,
eformat,
cl_grab_rest_args(args));
@)
@(defun cerror (cformat eformat &rest args)
@
return(funcall(4, @'si::universal-error-handler',
cformat,
eformat,
cl_grab_rest_args(args)));
@)
void
init_error(void)
{
cl_def_c_function_va(@'si::universal-error-handler', universal_error_handler);
null_string = make_constant_string("");
register_root(&null_string);
}