Mercurial > emacs
annotate src/eval.c @ 7099:59c3c3a1b571
(compilation-next-error-locus): Use compilation-error-message instead of
"Moved past last error" when MOVE is 1 (default value).
author | Roland McGrath <roland@gnu.org> |
---|---|
date | Mon, 25 Apr 1994 22:31:41 +0000 |
parents | c3af68680a33 |
children | bb5db306a305 |
rev | line source |
---|---|
272 | 1 /* Evaluator for GNU Emacs Lisp interpreter. |
2961 | 2 Copyright (C) 1985, 1986, 1987, 1993 Free Software Foundation, Inc. |
272 | 3 |
4 This file is part of GNU Emacs. | |
5 | |
6 GNU Emacs is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 1, or (at your option) | |
9 any later version. | |
10 | |
11 GNU Emacs is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | |
20 | |
4696
1fc792473491
Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents:
4474
diff
changeset
|
21 #include <config.h> |
272 | 22 #include "lisp.h" |
2439
b6c62e4abf59
Put interrupt input blocking in a separate file from xterm.h.
Jim Blandy <jimb@redhat.com>
parents:
1564
diff
changeset
|
23 #include "blockinput.h" |
272 | 24 |
25 #ifndef standalone | |
26 #include "commands.h" | |
515 | 27 #include "keyboard.h" |
272 | 28 #else |
29 #define INTERACTIVE 1 | |
30 #endif | |
31 | |
32 #include <setjmp.h> | |
33 | |
34 /* This definition is duplicated in alloc.c and keyboard.c */ | |
35 /* Putting it in lisp.h makes cc bomb out! */ | |
36 | |
37 struct backtrace | |
38 { | |
39 struct backtrace *next; | |
40 Lisp_Object *function; | |
41 Lisp_Object *args; /* Points to vector of args. */ | |
727 | 42 int nargs; /* Length of vector. |
43 If nargs is UNEVALLED, args points to slot holding | |
44 list of unevalled args */ | |
272 | 45 char evalargs; |
46 /* Nonzero means call value of debugger when done with this operation. */ | |
47 char debug_on_exit; | |
48 }; | |
49 | |
50 struct backtrace *backtrace_list; | |
51 | |
1196
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
52 /* This structure helps implement the `catch' and `throw' control |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
53 structure. A struct catchtag contains all the information needed |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
54 to restore the state of the interpreter after a non-local jump. |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
55 |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
56 Handlers for error conditions (represented by `struct handler' |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
57 structures) just point to a catch tag to do the cleanup required |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
58 for their jumps. |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
59 |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
60 catchtag structures are chained together in the C calling stack; |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
61 the `next' member points to the next outer catchtag. |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
62 |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
63 A call like (throw TAG VAL) searches for a catchtag whose `tag' |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
64 member is TAG, and then unbinds to it. The `val' member is used to |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
65 hold VAL while the stack is unwound; `val' is returned as the value |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
66 of the catch form. |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
67 |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
68 All the other members are concerned with restoring the interpreter |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
69 state. */ |
272 | 70 struct catchtag |
71 { | |
72 Lisp_Object tag; | |
73 Lisp_Object val; | |
74 struct catchtag *next; | |
75 struct gcpro *gcpro; | |
76 jmp_buf jmp; | |
77 struct backtrace *backlist; | |
78 struct handler *handlerlist; | |
79 int lisp_eval_depth; | |
80 int pdlcount; | |
81 int poll_suppress_count; | |
82 }; | |
83 | |
84 struct catchtag *catchlist; | |
85 | |
86 Lisp_Object Qautoload, Qmacro, Qexit, Qinteractive, Qcommandp, Qdefun; | |
381 | 87 Lisp_Object Qinhibit_quit, Vinhibit_quit, Vquit_flag; |
272 | 88 Lisp_Object Qmocklisp_arguments, Vmocklisp_arguments, Qmocklisp; |
89 Lisp_Object Qand_rest, Qand_optional; | |
90 Lisp_Object Qdebug_on_error; | |
91 | |
92 Lisp_Object Vrun_hooks; | |
93 | |
94 /* Non-nil means record all fset's and provide's, to be undone | |
95 if the file being autoloaded is not fully loaded. | |
96 They are recorded by being consed onto the front of Vautoload_queue: | |
97 (FUN . ODEF) for a defun, (OFEATURES . nil) for a provide. */ | |
98 | |
99 Lisp_Object Vautoload_queue; | |
100 | |
101 /* Current number of specbindings allocated in specpdl. */ | |
102 int specpdl_size; | |
103 | |
104 /* Pointer to beginning of specpdl. */ | |
105 struct specbinding *specpdl; | |
106 | |
107 /* Pointer to first unused element in specpdl. */ | |
108 struct specbinding *specpdl_ptr; | |
109 | |
110 /* Maximum size allowed for specpdl allocation */ | |
111 int max_specpdl_size; | |
112 | |
113 /* Depth in Lisp evaluations and function calls. */ | |
114 int lisp_eval_depth; | |
115 | |
116 /* Maximum allowed depth in Lisp evaluations and function calls. */ | |
117 int max_lisp_eval_depth; | |
118 | |
119 /* Nonzero means enter debugger before next function call */ | |
120 int debug_on_next_call; | |
121 | |
684 | 122 /* List of conditions (non-nil atom means all) which cause a backtrace |
706
86cb5db0b6c3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
687
diff
changeset
|
123 if an error is handled by the command loop's error handler. */ |
684 | 124 Lisp_Object Vstack_trace_on_error; |
272 | 125 |
684 | 126 /* List of conditions (non-nil atom means all) which enter the debugger |
706
86cb5db0b6c3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
687
diff
changeset
|
127 if an error is handled by the command loop's error handler. */ |
684 | 128 Lisp_Object Vdebug_on_error; |
272 | 129 |
130 /* Nonzero means enter debugger if a quit signal | |
684 | 131 is handled by the command loop's error handler. */ |
272 | 132 int debug_on_quit; |
133 | |
1196
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
134 /* The value of num_nonmacro_input_chars as of the last time we |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
135 started to enter the debugger. If we decide to enter the debugger |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
136 again when this is still equal to num_nonmacro_input_chars, then we |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
137 know that the debugger itself has an error, and we should just |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
138 signal the error instead of entering an infinite loop of debugger |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
139 invocations. */ |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
140 int when_entered_debugger; |
272 | 141 |
142 Lisp_Object Vdebugger; | |
143 | |
144 void specbind (), record_unwind_protect (); | |
145 | |
146 Lisp_Object funcall_lambda (); | |
147 extern Lisp_Object ml_apply (); /* Apply a mocklisp function to unevaluated argument list */ | |
148 | |
149 init_eval_once () | |
150 { | |
151 specpdl_size = 50; | |
152 specpdl = (struct specbinding *) malloc (specpdl_size * sizeof (struct specbinding)); | |
153 max_specpdl_size = 600; | |
154 max_lisp_eval_depth = 200; | |
155 } | |
156 | |
157 init_eval () | |
158 { | |
159 specpdl_ptr = specpdl; | |
160 catchlist = 0; | |
161 handlerlist = 0; | |
162 backtrace_list = 0; | |
163 Vquit_flag = Qnil; | |
164 debug_on_next_call = 0; | |
165 lisp_eval_depth = 0; | |
1196
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
166 when_entered_debugger = 0; |
272 | 167 } |
168 | |
169 Lisp_Object | |
170 call_debugger (arg) | |
171 Lisp_Object arg; | |
172 { | |
173 if (lisp_eval_depth + 20 > max_lisp_eval_depth) | |
174 max_lisp_eval_depth = lisp_eval_depth + 20; | |
175 if (specpdl_size + 40 > max_specpdl_size) | |
176 max_specpdl_size = specpdl_size + 40; | |
177 debug_on_next_call = 0; | |
1196
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
178 when_entered_debugger = num_nonmacro_input_chars; |
272 | 179 return apply1 (Vdebugger, arg); |
180 } | |
181 | |
182 do_debug_on_call (code) | |
183 Lisp_Object code; | |
184 { | |
185 debug_on_next_call = 0; | |
186 backtrace_list->debug_on_exit = 1; | |
187 call_debugger (Fcons (code, Qnil)); | |
188 } | |
189 | |
190 /* NOTE!!! Every function that can call EVAL must protect its args | |
191 and temporaries from garbage collection while it needs them. | |
192 The definition of `For' shows what you have to do. */ | |
193 | |
194 DEFUN ("or", For, Sor, 0, UNEVALLED, 0, | |
195 "Eval args until one of them yields non-nil, then return that value.\n\ | |
196 The remaining args are not evalled at all.\n\ | |
197 If all args return nil, return nil.") | |
198 (args) | |
199 Lisp_Object args; | |
200 { | |
201 register Lisp_Object val; | |
202 Lisp_Object args_left; | |
203 struct gcpro gcpro1; | |
204 | |
485 | 205 if (NILP(args)) |
272 | 206 return Qnil; |
207 | |
208 args_left = args; | |
209 GCPRO1 (args_left); | |
210 | |
211 do | |
212 { | |
213 val = Feval (Fcar (args_left)); | |
485 | 214 if (!NILP (val)) |
272 | 215 break; |
216 args_left = Fcdr (args_left); | |
217 } | |
485 | 218 while (!NILP(args_left)); |
272 | 219 |
220 UNGCPRO; | |
221 return val; | |
222 } | |
223 | |
224 DEFUN ("and", Fand, Sand, 0, UNEVALLED, 0, | |
225 "Eval args until one of them yields nil, then return nil.\n\ | |
226 The remaining args are not evalled at all.\n\ | |
227 If no arg yields nil, return the last arg's value.") | |
228 (args) | |
229 Lisp_Object args; | |
230 { | |
231 register Lisp_Object val; | |
232 Lisp_Object args_left; | |
233 struct gcpro gcpro1; | |
234 | |
485 | 235 if (NILP(args)) |
272 | 236 return Qt; |
237 | |
238 args_left = args; | |
239 GCPRO1 (args_left); | |
240 | |
241 do | |
242 { | |
243 val = Feval (Fcar (args_left)); | |
485 | 244 if (NILP (val)) |
272 | 245 break; |
246 args_left = Fcdr (args_left); | |
247 } | |
485 | 248 while (!NILP(args_left)); |
272 | 249 |
250 UNGCPRO; | |
251 return val; | |
252 } | |
253 | |
254 DEFUN ("if", Fif, Sif, 2, UNEVALLED, 0, | |
255 "(if COND THEN ELSE...): if COND yields non-nil, do THEN, else do ELSE...\n\ | |
256 Returns the value of THEN or the value of the last of the ELSE's.\n\ | |
257 THEN must be one expression, but ELSE... can be zero or more expressions.\n\ | |
258 If COND yields nil, and there are no ELSE's, the value is nil.") | |
259 (args) | |
260 Lisp_Object args; | |
261 { | |
262 register Lisp_Object cond; | |
263 struct gcpro gcpro1; | |
264 | |
265 GCPRO1 (args); | |
266 cond = Feval (Fcar (args)); | |
267 UNGCPRO; | |
268 | |
485 | 269 if (!NILP (cond)) |
272 | 270 return Feval (Fcar (Fcdr (args))); |
271 return Fprogn (Fcdr (Fcdr (args))); | |
272 } | |
273 | |
274 DEFUN ("cond", Fcond, Scond, 0, UNEVALLED, 0, | |
275 "(cond CLAUSES...): try each clause until one succeeds.\n\ | |
276 Each clause looks like (CONDITION BODY...). CONDITION is evaluated\n\ | |
277 and, if the value is non-nil, this clause succeeds:\n\ | |
278 then the expressions in BODY are evaluated and the last one's\n\ | |
279 value is the value of the cond-form.\n\ | |
280 If no clause succeeds, cond returns nil.\n\ | |
281 If a clause has one element, as in (CONDITION),\n\ | |
282 CONDITION's value if non-nil is returned from the cond-form.") | |
283 (args) | |
284 Lisp_Object args; | |
285 { | |
286 register Lisp_Object clause, val; | |
287 struct gcpro gcpro1; | |
288 | |
289 val = Qnil; | |
290 GCPRO1 (args); | |
485 | 291 while (!NILP (args)) |
272 | 292 { |
293 clause = Fcar (args); | |
294 val = Feval (Fcar (clause)); | |
485 | 295 if (!NILP (val)) |
272 | 296 { |
297 if (!EQ (XCONS (clause)->cdr, Qnil)) | |
298 val = Fprogn (XCONS (clause)->cdr); | |
299 break; | |
300 } | |
301 args = XCONS (args)->cdr; | |
302 } | |
303 UNGCPRO; | |
304 | |
305 return val; | |
306 } | |
307 | |
308 DEFUN ("progn", Fprogn, Sprogn, 0, UNEVALLED, 0, | |
309 "(progn BODY...): eval BODY forms sequentially and return value of last one.") | |
310 (args) | |
311 Lisp_Object args; | |
312 { | |
313 register Lisp_Object val, tem; | |
314 Lisp_Object args_left; | |
315 struct gcpro gcpro1; | |
316 | |
317 /* In Mocklisp code, symbols at the front of the progn arglist | |
318 are to be bound to zero. */ | |
319 if (!EQ (Vmocklisp_arguments, Qt)) | |
320 { | |
321 val = make_number (0); | |
485 | 322 while (!NILP (args) && (tem = Fcar (args), XTYPE (tem) == Lisp_Symbol)) |
272 | 323 { |
324 QUIT; | |
325 specbind (tem, val), args = Fcdr (args); | |
326 } | |
327 } | |
328 | |
485 | 329 if (NILP(args)) |
272 | 330 return Qnil; |
331 | |
332 args_left = args; | |
333 GCPRO1 (args_left); | |
334 | |
335 do | |
336 { | |
337 val = Feval (Fcar (args_left)); | |
338 args_left = Fcdr (args_left); | |
339 } | |
485 | 340 while (!NILP(args_left)); |
272 | 341 |
342 UNGCPRO; | |
343 return val; | |
344 } | |
345 | |
346 DEFUN ("prog1", Fprog1, Sprog1, 1, UNEVALLED, 0, | |
347 "(prog1 FIRST BODY...): eval FIRST and BODY sequentially; value from FIRST.\n\ | |
348 The value of FIRST is saved during the evaluation of the remaining args,\n\ | |
349 whose values are discarded.") | |
350 (args) | |
351 Lisp_Object args; | |
352 { | |
353 Lisp_Object val; | |
354 register Lisp_Object args_left; | |
355 struct gcpro gcpro1, gcpro2; | |
356 register int argnum = 0; | |
357 | |
485 | 358 if (NILP(args)) |
272 | 359 return Qnil; |
360 | |
361 args_left = args; | |
362 val = Qnil; | |
363 GCPRO2 (args, val); | |
364 | |
365 do | |
366 { | |
367 if (!(argnum++)) | |
368 val = Feval (Fcar (args_left)); | |
369 else | |
370 Feval (Fcar (args_left)); | |
371 args_left = Fcdr (args_left); | |
372 } | |
485 | 373 while (!NILP(args_left)); |
272 | 374 |
375 UNGCPRO; | |
376 return val; | |
377 } | |
378 | |
379 DEFUN ("prog2", Fprog2, Sprog2, 2, UNEVALLED, 0, | |
380 "(prog1 X Y BODY...): eval X, Y and BODY sequentially; value from Y.\n\ | |
381 The value of Y is saved during the evaluation of the remaining args,\n\ | |
382 whose values are discarded.") | |
383 (args) | |
384 Lisp_Object args; | |
385 { | |
386 Lisp_Object val; | |
387 register Lisp_Object args_left; | |
388 struct gcpro gcpro1, gcpro2; | |
389 register int argnum = -1; | |
390 | |
391 val = Qnil; | |
392 | |
6803 | 393 if (NILP (args)) |
272 | 394 return Qnil; |
395 | |
396 args_left = args; | |
397 val = Qnil; | |
398 GCPRO2 (args, val); | |
399 | |
400 do | |
401 { | |
402 if (!(argnum++)) | |
403 val = Feval (Fcar (args_left)); | |
404 else | |
405 Feval (Fcar (args_left)); | |
406 args_left = Fcdr (args_left); | |
407 } | |
6803 | 408 while (!NILP (args_left)); |
272 | 409 |
410 UNGCPRO; | |
411 return val; | |
412 } | |
413 | |
414 DEFUN ("setq", Fsetq, Ssetq, 0, UNEVALLED, 0, | |
415 "(setq SYM VAL SYM VAL ...): set each SYM to the value of its VAL.\n\ | |
6918 | 416 The symbols SYM are variables; they are literal (not evaluated).\n\ |
417 The values VAL are expressions; they are evaluated.\n\ | |
418 Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'.\n\ | |
419 The second VAL is not computed until after the first SYM is set, and so on;\n\ | |
420 each VAL can use the new value of variables set earlier in the `setq'.\n\ | |
6713 | 421 The return value of the `setq' form is the value of the last VAL.") |
272 | 422 (args) |
423 Lisp_Object args; | |
424 { | |
425 register Lisp_Object args_left; | |
426 register Lisp_Object val, sym; | |
427 struct gcpro gcpro1; | |
428 | |
485 | 429 if (NILP(args)) |
272 | 430 return Qnil; |
431 | |
432 args_left = args; | |
433 GCPRO1 (args); | |
434 | |
435 do | |
436 { | |
437 val = Feval (Fcar (Fcdr (args_left))); | |
438 sym = Fcar (args_left); | |
439 Fset (sym, val); | |
440 args_left = Fcdr (Fcdr (args_left)); | |
441 } | |
485 | 442 while (!NILP(args_left)); |
272 | 443 |
444 UNGCPRO; | |
445 return val; | |
446 } | |
447 | |
448 DEFUN ("quote", Fquote, Squote, 1, UNEVALLED, 0, | |
449 "Return the argument, without evaluating it. `(quote x)' yields `x'.") | |
450 (args) | |
451 Lisp_Object args; | |
452 { | |
453 return Fcar (args); | |
454 } | |
455 | |
456 DEFUN ("function", Ffunction, Sfunction, 1, UNEVALLED, 0, | |
457 "Like `quote', but preferred for objects which are functions.\n\ | |
458 In byte compilation, `function' causes its argument to be compiled.\n\ | |
459 `quote' cannot do that.") | |
460 (args) | |
461 Lisp_Object args; | |
462 { | |
463 return Fcar (args); | |
464 } | |
465 | |
466 DEFUN ("interactive-p", Finteractive_p, Sinteractive_p, 0, 0, 0, | |
467 "Return t if function in which this appears was called interactively.\n\ | |
468 This means that the function was called with call-interactively (which\n\ | |
469 includes being called as the binding of a key)\n\ | |
470 and input is currently coming from the keyboard (not in keyboard macro).") | |
471 () | |
472 { | |
473 register struct backtrace *btp; | |
474 register Lisp_Object fun; | |
475 | |
476 if (!INTERACTIVE) | |
477 return Qnil; | |
478 | |
479 btp = backtrace_list; | |
727 | 480 |
481 /* If this isn't a byte-compiled function, there may be a frame at | |
482 the top for Finteractive_p itself. If so, skip it. */ | |
483 fun = Findirect_function (*btp->function); | |
484 if (XTYPE (fun) == Lisp_Subr | |
485 && (struct Lisp_Subr *) XPNTR (fun) == &Sinteractive_p) | |
323 | 486 btp = btp->next; |
487 | |
727 | 488 /* If we're running an Emacs 18-style byte-compiled function, there |
489 may be a frame for Fbytecode. Now, given the strictest | |
490 definition, this function isn't really being called | |
491 interactively, but because that's the way Emacs 18 always builds | |
492 byte-compiled functions, we'll accept it for now. */ | |
493 if (EQ (*btp->function, Qbytecode)) | |
494 btp = btp->next; | |
495 | |
496 /* If this isn't a byte-compiled function, then we may now be | |
497 looking at several frames for special forms. Skip past them. */ | |
498 while (btp && | |
499 btp->nargs == UNEVALLED) | |
500 btp = btp->next; | |
501 | |
502 /* btp now points at the frame of the innermost function that isn't | |
503 a special form, ignoring frames for Finteractive_p and/or | |
504 Fbytecode at the top. If this frame is for a built-in function | |
505 (such as load or eval-region) return nil. */ | |
648 | 506 fun = Findirect_function (*btp->function); |
272 | 507 if (XTYPE (fun) == Lisp_Subr) |
508 return Qnil; | |
509 /* btp points to the frame of a Lisp function that called interactive-p. | |
510 Return t if that function was called interactively. */ | |
511 if (btp && btp->next && EQ (*btp->next->function, Qcall_interactively)) | |
512 return Qt; | |
513 return Qnil; | |
514 } | |
515 | |
516 DEFUN ("defun", Fdefun, Sdefun, 2, UNEVALLED, 0, | |
517 "(defun NAME ARGLIST [DOCSTRING] BODY...): define NAME as a function.\n\ | |
518 The definition is (lambda ARGLIST [DOCSTRING] BODY...).\n\ | |
519 See also the function `interactive'.") | |
520 (args) | |
521 Lisp_Object args; | |
522 { | |
523 register Lisp_Object fn_name; | |
524 register Lisp_Object defn; | |
525 | |
526 fn_name = Fcar (args); | |
527 defn = Fcons (Qlambda, Fcdr (args)); | |
485 | 528 if (!NILP (Vpurify_flag)) |
272 | 529 defn = Fpurecopy (defn); |
530 Ffset (fn_name, defn); | |
2547
c73c68a87cd5
(defun, defmacro, defvar, defconst):
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
531 LOADHIST_ATTACH (fn_name); |
272 | 532 return fn_name; |
533 } | |
534 | |
535 DEFUN ("defmacro", Fdefmacro, Sdefmacro, 2, UNEVALLED, 0, | |
536 "(defmacro NAME ARGLIST [DOCSTRING] BODY...): define NAME as a macro.\n\ | |
537 The definition is (macro lambda ARGLIST [DOCSTRING] BODY...).\n\ | |
538 When the macro is called, as in (NAME ARGS...),\n\ | |
539 the function (lambda ARGLIST BODY...) is applied to\n\ | |
540 the list ARGS... as it appears in the expression,\n\ | |
541 and the result should be a form to be evaluated instead of the original.") | |
542 (args) | |
543 Lisp_Object args; | |
544 { | |
545 register Lisp_Object fn_name; | |
546 register Lisp_Object defn; | |
547 | |
548 fn_name = Fcar (args); | |
549 defn = Fcons (Qmacro, Fcons (Qlambda, Fcdr (args))); | |
485 | 550 if (!NILP (Vpurify_flag)) |
272 | 551 defn = Fpurecopy (defn); |
552 Ffset (fn_name, defn); | |
2547
c73c68a87cd5
(defun, defmacro, defvar, defconst):
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
553 LOADHIST_ATTACH (fn_name); |
272 | 554 return fn_name; |
555 } | |
556 | |
557 DEFUN ("defvar", Fdefvar, Sdefvar, 1, UNEVALLED, 0, | |
558 "(defvar SYMBOL INITVALUE DOCSTRING): define SYMBOL as a variable.\n\ | |
559 You are not required to define a variable in order to use it,\n\ | |
560 but the definition can supply documentation and an initial value\n\ | |
561 in a way that tags can recognize.\n\n\ | |
562 INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is void.\n\ | |
687
e2b747dd6a6e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
684
diff
changeset
|
563 If SYMBOL is buffer-local, its default value is what is set;\n\ |
e2b747dd6a6e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
684
diff
changeset
|
564 buffer-local values are not affected.\n\ |
272 | 565 INITVALUE and DOCSTRING are optional.\n\ |
566 If DOCSTRING starts with *, this variable is identified as a user option.\n\ | |
567 This means that M-x set-variable and M-x edit-options recognize it.\n\ | |
568 If INITVALUE is missing, SYMBOL's value is not set.") | |
569 (args) | |
570 Lisp_Object args; | |
571 { | |
572 register Lisp_Object sym, tem; | |
573 | |
574 sym = Fcar (args); | |
575 tem = Fcdr (args); | |
485 | 576 if (!NILP (tem)) |
272 | 577 { |
578 tem = Fdefault_boundp (sym); | |
485 | 579 if (NILP (tem)) |
272 | 580 Fset_default (sym, Feval (Fcar (Fcdr (args)))); |
581 } | |
582 tem = Fcar (Fcdr (Fcdr (args))); | |
485 | 583 if (!NILP (tem)) |
272 | 584 { |
485 | 585 if (!NILP (Vpurify_flag)) |
272 | 586 tem = Fpurecopy (tem); |
587 Fput (sym, Qvariable_documentation, tem); | |
588 } | |
2547
c73c68a87cd5
(defun, defmacro, defvar, defconst):
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
589 LOADHIST_ATTACH (sym); |
272 | 590 return sym; |
591 } | |
592 | |
593 DEFUN ("defconst", Fdefconst, Sdefconst, 2, UNEVALLED, 0, | |
594 "(defconst SYMBOL INITVALUE DOCSTRING): define SYMBOL as a constant variable.\n\ | |
595 The intent is that programs do not change this value, but users may.\n\ | |
596 Always sets the value of SYMBOL to the result of evalling INITVALUE.\n\ | |
687
e2b747dd6a6e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
684
diff
changeset
|
597 If SYMBOL is buffer-local, its default value is what is set;\n\ |
e2b747dd6a6e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
684
diff
changeset
|
598 buffer-local values are not affected.\n\ |
272 | 599 DOCSTRING is optional.\n\ |
600 If DOCSTRING starts with *, this variable is identified as a user option.\n\ | |
601 This means that M-x set-variable and M-x edit-options recognize it.\n\n\ | |
602 Note: do not use `defconst' for user options in libraries that are not\n\ | |
603 normally loaded, since it is useful for users to be able to specify\n\ | |
604 their own values for such variables before loading the library.\n\ | |
605 Since `defconst' unconditionally assigns the variable,\n\ | |
606 it would override the user's choice.") | |
607 (args) | |
608 Lisp_Object args; | |
609 { | |
610 register Lisp_Object sym, tem; | |
611 | |
612 sym = Fcar (args); | |
613 Fset_default (sym, Feval (Fcar (Fcdr (args)))); | |
614 tem = Fcar (Fcdr (Fcdr (args))); | |
485 | 615 if (!NILP (tem)) |
272 | 616 { |
485 | 617 if (!NILP (Vpurify_flag)) |
272 | 618 tem = Fpurecopy (tem); |
619 Fput (sym, Qvariable_documentation, tem); | |
620 } | |
2547
c73c68a87cd5
(defun, defmacro, defvar, defconst):
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
621 LOADHIST_ATTACH (sym); |
272 | 622 return sym; |
623 } | |
624 | |
625 DEFUN ("user-variable-p", Fuser_variable_p, Suser_variable_p, 1, 1, 0, | |
626 "Returns t if VARIABLE is intended to be set and modified by users.\n\ | |
627 \(The alternative is a variable used internally in a Lisp program.)\n\ | |
628 Determined by whether the first character of the documentation\n\ | |
629 for the variable is \"*\"") | |
630 (variable) | |
631 Lisp_Object variable; | |
632 { | |
633 Lisp_Object documentation; | |
634 | |
635 documentation = Fget (variable, Qvariable_documentation); | |
636 if (XTYPE (documentation) == Lisp_Int && XINT (documentation) < 0) | |
637 return Qt; | |
638 if ((XTYPE (documentation) == Lisp_String) && | |
639 ((unsigned char) XSTRING (documentation)->data[0] == '*')) | |
640 return Qt; | |
641 return Qnil; | |
642 } | |
643 | |
644 DEFUN ("let*", FletX, SletX, 1, UNEVALLED, 0, | |
645 "(let* VARLIST BODY...): bind variables according to VARLIST then eval BODY.\n\ | |
646 The value of the last form in BODY is returned.\n\ | |
647 Each element of VARLIST is a symbol (which is bound to nil)\n\ | |
648 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).\n\ | |
649 Each VALUEFORM can refer to the symbols already bound by this VARLIST.") | |
650 (args) | |
651 Lisp_Object args; | |
652 { | |
653 Lisp_Object varlist, val, elt; | |
654 int count = specpdl_ptr - specpdl; | |
655 struct gcpro gcpro1, gcpro2, gcpro3; | |
656 | |
657 GCPRO3 (args, elt, varlist); | |
658 | |
659 varlist = Fcar (args); | |
485 | 660 while (!NILP (varlist)) |
272 | 661 { |
662 QUIT; | |
663 elt = Fcar (varlist); | |
664 if (XTYPE (elt) == Lisp_Symbol) | |
665 specbind (elt, Qnil); | |
604 | 666 else if (! NILP (Fcdr (Fcdr (elt)))) |
667 Fsignal (Qerror, | |
668 Fcons (build_string ("`let' bindings can have only one value-form"), | |
669 elt)); | |
272 | 670 else |
671 { | |
672 val = Feval (Fcar (Fcdr (elt))); | |
673 specbind (Fcar (elt), val); | |
674 } | |
675 varlist = Fcdr (varlist); | |
676 } | |
677 UNGCPRO; | |
678 val = Fprogn (Fcdr (args)); | |
679 return unbind_to (count, val); | |
680 } | |
681 | |
682 DEFUN ("let", Flet, Slet, 1, UNEVALLED, 0, | |
683 "(let VARLIST BODY...): bind variables according to VARLIST then eval BODY.\n\ | |
684 The value of the last form in BODY is returned.\n\ | |
685 Each element of VARLIST is a symbol (which is bound to nil)\n\ | |
686 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM).\n\ | |
687 All the VALUEFORMs are evalled before any symbols are bound.") | |
688 (args) | |
689 Lisp_Object args; | |
690 { | |
691 Lisp_Object *temps, tem; | |
692 register Lisp_Object elt, varlist; | |
693 int count = specpdl_ptr - specpdl; | |
694 register int argnum; | |
695 struct gcpro gcpro1, gcpro2; | |
696 | |
697 varlist = Fcar (args); | |
698 | |
699 /* Make space to hold the values to give the bound variables */ | |
700 elt = Flength (varlist); | |
701 temps = (Lisp_Object *) alloca (XFASTINT (elt) * sizeof (Lisp_Object)); | |
702 | |
703 /* Compute the values and store them in `temps' */ | |
704 | |
705 GCPRO2 (args, *temps); | |
706 gcpro2.nvars = 0; | |
707 | |
485 | 708 for (argnum = 0; !NILP (varlist); varlist = Fcdr (varlist)) |
272 | 709 { |
710 QUIT; | |
711 elt = Fcar (varlist); | |
712 if (XTYPE (elt) == Lisp_Symbol) | |
713 temps [argnum++] = Qnil; | |
604 | 714 else if (! NILP (Fcdr (Fcdr (elt)))) |
715 Fsignal (Qerror, | |
716 Fcons (build_string ("`let' bindings can have only one value-form"), | |
717 elt)); | |
272 | 718 else |
719 temps [argnum++] = Feval (Fcar (Fcdr (elt))); | |
720 gcpro2.nvars = argnum; | |
721 } | |
722 UNGCPRO; | |
723 | |
724 varlist = Fcar (args); | |
485 | 725 for (argnum = 0; !NILP (varlist); varlist = Fcdr (varlist)) |
272 | 726 { |
727 elt = Fcar (varlist); | |
728 tem = temps[argnum++]; | |
729 if (XTYPE (elt) == Lisp_Symbol) | |
730 specbind (elt, tem); | |
731 else | |
732 specbind (Fcar (elt), tem); | |
733 } | |
734 | |
735 elt = Fprogn (Fcdr (args)); | |
736 return unbind_to (count, elt); | |
737 } | |
738 | |
739 DEFUN ("while", Fwhile, Swhile, 1, UNEVALLED, 0, | |
740 "(while TEST BODY...): if TEST yields non-nil, eval BODY... and repeat.\n\ | |
741 The order of execution is thus TEST, BODY, TEST, BODY and so on\n\ | |
742 until TEST returns nil.") | |
743 (args) | |
744 Lisp_Object args; | |
745 { | |
746 Lisp_Object test, body, tem; | |
747 struct gcpro gcpro1, gcpro2; | |
748 | |
749 GCPRO2 (test, body); | |
750 | |
751 test = Fcar (args); | |
752 body = Fcdr (args); | |
4167
f037b1f51320
(Fwhile): If mocklisp, test for nonzeroness.
Richard M. Stallman <rms@gnu.org>
parents:
3973
diff
changeset
|
753 while (tem = Feval (test), |
f037b1f51320
(Fwhile): If mocklisp, test for nonzeroness.
Richard M. Stallman <rms@gnu.org>
parents:
3973
diff
changeset
|
754 (!EQ (Vmocklisp_arguments, Qt) ? XINT (tem) : !NILP (tem))) |
272 | 755 { |
756 QUIT; | |
757 Fprogn (body); | |
758 } | |
759 | |
760 UNGCPRO; | |
761 return Qnil; | |
762 } | |
763 | |
764 DEFUN ("macroexpand", Fmacroexpand, Smacroexpand, 1, 2, 0, | |
765 "Return result of expanding macros at top level of FORM.\n\ | |
766 If FORM is not a macro call, it is returned unchanged.\n\ | |
767 Otherwise, the macro is expanded and the expansion is considered\n\ | |
768 in place of FORM. When a non-macro-call results, it is returned.\n\n\ | |
769 The second optional arg ENVIRONMENT species an environment of macro\n\ | |
770 definitions to shadow the loaded ones for use in file byte-compilation.") | |
771 (form, env) | |
772 register Lisp_Object form; | |
773 Lisp_Object env; | |
774 { | |
753 | 775 /* With cleanups from Hallvard Furuseth. */ |
272 | 776 register Lisp_Object expander, sym, def, tem; |
777 | |
778 while (1) | |
779 { | |
780 /* Come back here each time we expand a macro call, | |
781 in case it expands into another macro call. */ | |
782 if (XTYPE (form) != Lisp_Cons) | |
783 break; | |
753 | 784 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */ |
785 def = sym = XCONS (form)->car; | |
786 tem = Qnil; | |
272 | 787 /* Trace symbols aliases to other symbols |
788 until we get a symbol that is not an alias. */ | |
753 | 789 while (XTYPE (def) == Lisp_Symbol) |
272 | 790 { |
791 QUIT; | |
753 | 792 sym = def; |
272 | 793 tem = Fassq (sym, env); |
485 | 794 if (NILP (tem)) |
272 | 795 { |
796 def = XSYMBOL (sym)->function; | |
753 | 797 if (!EQ (def, Qunbound)) |
798 continue; | |
272 | 799 } |
753 | 800 break; |
272 | 801 } |
802 /* Right now TEM is the result from SYM in ENV, | |
803 and if TEM is nil then DEF is SYM's function definition. */ | |
485 | 804 if (NILP (tem)) |
272 | 805 { |
806 /* SYM is not mentioned in ENV. | |
807 Look at its function definition. */ | |
808 if (EQ (def, Qunbound) | |
809 || XTYPE (def) != Lisp_Cons) | |
810 /* Not defined or definition not suitable */ | |
811 break; | |
812 if (EQ (XCONS (def)->car, Qautoload)) | |
813 { | |
814 /* Autoloading function: will it be a macro when loaded? */ | |
1564
b327816041d1
* eval.c (Fautoload): Renamed fifth argument TYPE. Document the
Jim Blandy <jimb@redhat.com>
parents:
1452
diff
changeset
|
815 tem = Fnth (make_number (4), def); |
5254
b38b74fe1722
(Fmacroexpand): For an autoload definition,
Richard M. Stallman <rms@gnu.org>
parents:
4782
diff
changeset
|
816 if (EQ (tem, Qt) || EQ (tem, Qmacro)) |
1564
b327816041d1
* eval.c (Fautoload): Renamed fifth argument TYPE. Document the
Jim Blandy <jimb@redhat.com>
parents:
1452
diff
changeset
|
817 /* Yes, load it and try again. */ |
b327816041d1
* eval.c (Fautoload): Renamed fifth argument TYPE. Document the
Jim Blandy <jimb@redhat.com>
parents:
1452
diff
changeset
|
818 { |
b327816041d1
* eval.c (Fautoload): Renamed fifth argument TYPE. Document the
Jim Blandy <jimb@redhat.com>
parents:
1452
diff
changeset
|
819 do_autoload (def, sym); |
b327816041d1
* eval.c (Fautoload): Renamed fifth argument TYPE. Document the
Jim Blandy <jimb@redhat.com>
parents:
1452
diff
changeset
|
820 continue; |
b327816041d1
* eval.c (Fautoload): Renamed fifth argument TYPE. Document the
Jim Blandy <jimb@redhat.com>
parents:
1452
diff
changeset
|
821 } |
b327816041d1
* eval.c (Fautoload): Renamed fifth argument TYPE. Document the
Jim Blandy <jimb@redhat.com>
parents:
1452
diff
changeset
|
822 else |
272 | 823 break; |
824 } | |
825 else if (!EQ (XCONS (def)->car, Qmacro)) | |
826 break; | |
827 else expander = XCONS (def)->cdr; | |
828 } | |
829 else | |
830 { | |
831 expander = XCONS (tem)->cdr; | |
485 | 832 if (NILP (expander)) |
272 | 833 break; |
834 } | |
835 form = apply1 (expander, XCONS (form)->cdr); | |
836 } | |
837 return form; | |
838 } | |
839 | |
840 DEFUN ("catch", Fcatch, Scatch, 1, UNEVALLED, 0, | |
841 "(catch TAG BODY...): eval BODY allowing nonlocal exits using `throw'.\n\ | |
842 TAG is evalled to get the tag to use. Then the BODY is executed.\n\ | |
843 Within BODY, (throw TAG) with same tag exits BODY and exits this `catch'.\n\ | |
844 If no throw happens, `catch' returns the value of the last BODY form.\n\ | |
845 If a throw happens, it specifies the value to return from `catch'.") | |
846 (args) | |
847 Lisp_Object args; | |
848 { | |
849 register Lisp_Object tag; | |
850 struct gcpro gcpro1; | |
851 | |
852 GCPRO1 (args); | |
853 tag = Feval (Fcar (args)); | |
854 UNGCPRO; | |
855 return internal_catch (tag, Fprogn, Fcdr (args)); | |
856 } | |
857 | |
858 /* Set up a catch, then call C function FUNC on argument ARG. | |
859 FUNC should return a Lisp_Object. | |
860 This is how catches are done from within C code. */ | |
861 | |
862 Lisp_Object | |
863 internal_catch (tag, func, arg) | |
864 Lisp_Object tag; | |
865 Lisp_Object (*func) (); | |
866 Lisp_Object arg; | |
867 { | |
868 /* This structure is made part of the chain `catchlist'. */ | |
869 struct catchtag c; | |
870 | |
871 /* Fill in the components of c, and put it on the list. */ | |
872 c.next = catchlist; | |
873 c.tag = tag; | |
874 c.val = Qnil; | |
875 c.backlist = backtrace_list; | |
876 c.handlerlist = handlerlist; | |
877 c.lisp_eval_depth = lisp_eval_depth; | |
878 c.pdlcount = specpdl_ptr - specpdl; | |
879 c.poll_suppress_count = poll_suppress_count; | |
880 c.gcpro = gcprolist; | |
881 catchlist = &c; | |
882 | |
883 /* Call FUNC. */ | |
884 if (! _setjmp (c.jmp)) | |
885 c.val = (*func) (arg); | |
886 | |
887 /* Throw works by a longjmp that comes right here. */ | |
888 catchlist = c.next; | |
889 return c.val; | |
890 } | |
891 | |
1199
ab2d88e2505b
* eval.c (unbind_catch): Do the long-jump here. Take a VALUE
Jim Blandy <jimb@redhat.com>
parents:
1196
diff
changeset
|
892 /* Unwind the specbind, catch, and handler stacks back to CATCH, and |
ab2d88e2505b
* eval.c (unbind_catch): Do the long-jump here. Take a VALUE
Jim Blandy <jimb@redhat.com>
parents:
1196
diff
changeset
|
893 jump to that CATCH, returning VALUE as the value of that catch. |
ab2d88e2505b
* eval.c (unbind_catch): Do the long-jump here. Take a VALUE
Jim Blandy <jimb@redhat.com>
parents:
1196
diff
changeset
|
894 |
ab2d88e2505b
* eval.c (unbind_catch): Do the long-jump here. Take a VALUE
Jim Blandy <jimb@redhat.com>
parents:
1196
diff
changeset
|
895 This is the guts Fthrow and Fsignal; they differ only in the way |
ab2d88e2505b
* eval.c (unbind_catch): Do the long-jump here. Take a VALUE
Jim Blandy <jimb@redhat.com>
parents:
1196
diff
changeset
|
896 they choose the catch tag to throw to. A catch tag for a |
ab2d88e2505b
* eval.c (unbind_catch): Do the long-jump here. Take a VALUE
Jim Blandy <jimb@redhat.com>
parents:
1196
diff
changeset
|
897 condition-case form has a TAG of Qnil. |
272 | 898 |
1199
ab2d88e2505b
* eval.c (unbind_catch): Do the long-jump here. Take a VALUE
Jim Blandy <jimb@redhat.com>
parents:
1196
diff
changeset
|
899 Before each catch is discarded, unbind all special bindings and |
ab2d88e2505b
* eval.c (unbind_catch): Do the long-jump here. Take a VALUE
Jim Blandy <jimb@redhat.com>
parents:
1196
diff
changeset
|
900 execute all unwind-protect clauses made above that catch. Unwind |
ab2d88e2505b
* eval.c (unbind_catch): Do the long-jump here. Take a VALUE
Jim Blandy <jimb@redhat.com>
parents:
1196
diff
changeset
|
901 the handler stack as we go, so that the proper handlers are in |
ab2d88e2505b
* eval.c (unbind_catch): Do the long-jump here. Take a VALUE
Jim Blandy <jimb@redhat.com>
parents:
1196
diff
changeset
|
902 effect for each unwind-protect clause we run. At the end, restore |
ab2d88e2505b
* eval.c (unbind_catch): Do the long-jump here. Take a VALUE
Jim Blandy <jimb@redhat.com>
parents:
1196
diff
changeset
|
903 some static info saved in CATCH, and longjmp to the location |
ab2d88e2505b
* eval.c (unbind_catch): Do the long-jump here. Take a VALUE
Jim Blandy <jimb@redhat.com>
parents:
1196
diff
changeset
|
904 specified in the |
272 | 905 |
1199
ab2d88e2505b
* eval.c (unbind_catch): Do the long-jump here. Take a VALUE
Jim Blandy <jimb@redhat.com>
parents:
1196
diff
changeset
|
906 This is used for correct unwinding in Fthrow and Fsignal. */ |
272 | 907 |
908 static void | |
1199
ab2d88e2505b
* eval.c (unbind_catch): Do the long-jump here. Take a VALUE
Jim Blandy <jimb@redhat.com>
parents:
1196
diff
changeset
|
909 unwind_to_catch (catch, value) |
272 | 910 struct catchtag *catch; |
1199
ab2d88e2505b
* eval.c (unbind_catch): Do the long-jump here. Take a VALUE
Jim Blandy <jimb@redhat.com>
parents:
1196
diff
changeset
|
911 Lisp_Object value; |
272 | 912 { |
913 register int last_time; | |
914 | |
1199
ab2d88e2505b
* eval.c (unbind_catch): Do the long-jump here. Take a VALUE
Jim Blandy <jimb@redhat.com>
parents:
1196
diff
changeset
|
915 /* Save the value in the tag. */ |
ab2d88e2505b
* eval.c (unbind_catch): Do the long-jump here. Take a VALUE
Jim Blandy <jimb@redhat.com>
parents:
1196
diff
changeset
|
916 catch->val = value; |
ab2d88e2505b
* eval.c (unbind_catch): Do the long-jump here. Take a VALUE
Jim Blandy <jimb@redhat.com>
parents:
1196
diff
changeset
|
917 |
1196
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
918 /* Restore the polling-suppression count. */ |
4474
23d5b09bd218
(unwind_to_catch): Call set_poll_suppress_count.
Richard M. Stallman <rms@gnu.org>
parents:
4462
diff
changeset
|
919 set_poll_suppress_count (catch->poll_suppress_count); |
1196
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
920 |
272 | 921 do |
922 { | |
923 last_time = catchlist == catch; | |
1196
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
924 |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
925 /* Unwind the specpdl stack, and then restore the proper set of |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
926 handlers. */ |
272 | 927 unbind_to (catchlist->pdlcount, Qnil); |
928 handlerlist = catchlist->handlerlist; | |
929 catchlist = catchlist->next; | |
930 } | |
931 while (! last_time); | |
932 | |
933 gcprolist = catch->gcpro; | |
934 backtrace_list = catch->backlist; | |
935 lisp_eval_depth = catch->lisp_eval_depth; | |
1199
ab2d88e2505b
* eval.c (unbind_catch): Do the long-jump here. Take a VALUE
Jim Blandy <jimb@redhat.com>
parents:
1196
diff
changeset
|
936 |
ab2d88e2505b
* eval.c (unbind_catch): Do the long-jump here. Take a VALUE
Jim Blandy <jimb@redhat.com>
parents:
1196
diff
changeset
|
937 _longjmp (catch->jmp, 1); |
272 | 938 } |
939 | |
940 DEFUN ("throw", Fthrow, Sthrow, 2, 2, 0, | |
941 "(throw TAG VALUE): throw to the catch for TAG and return VALUE from it.\n\ | |
942 Both TAG and VALUE are evalled.") | |
943 (tag, val) | |
944 register Lisp_Object tag, val; | |
945 { | |
946 register struct catchtag *c; | |
947 | |
948 while (1) | |
949 { | |
485 | 950 if (!NILP (tag)) |
272 | 951 for (c = catchlist; c; c = c->next) |
952 { | |
953 if (EQ (c->tag, tag)) | |
1199
ab2d88e2505b
* eval.c (unbind_catch): Do the long-jump here. Take a VALUE
Jim Blandy <jimb@redhat.com>
parents:
1196
diff
changeset
|
954 unwind_to_catch (c, val); |
272 | 955 } |
956 tag = Fsignal (Qno_catch, Fcons (tag, Fcons (val, Qnil))); | |
957 } | |
958 } | |
959 | |
960 | |
961 DEFUN ("unwind-protect", Funwind_protect, Sunwind_protect, 1, UNEVALLED, 0, | |
962 "Do BODYFORM, protecting with UNWINDFORMS.\n\ | |
963 Usage looks like (unwind-protect BODYFORM UNWINDFORMS...).\n\ | |
964 If BODYFORM completes normally, its value is returned\n\ | |
965 after executing the UNWINDFORMS.\n\ | |
966 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.") | |
967 (args) | |
968 Lisp_Object args; | |
969 { | |
970 Lisp_Object val; | |
971 int count = specpdl_ptr - specpdl; | |
972 | |
973 record_unwind_protect (0, Fcdr (args)); | |
974 val = Feval (Fcar (args)); | |
975 return unbind_to (count, val); | |
976 } | |
977 | |
978 /* Chain of condition handlers currently in effect. | |
979 The elements of this chain are contained in the stack frames | |
980 of Fcondition_case and internal_condition_case. | |
981 When an error is signaled (by calling Fsignal, below), | |
982 this chain is searched for an element that applies. */ | |
983 | |
984 struct handler *handlerlist; | |
985 | |
986 DEFUN ("condition-case", Fcondition_case, Scondition_case, 2, UNEVALLED, 0, | |
987 "Regain control when an error is signaled.\n\ | |
988 Usage looks like (condition-case VAR BODYFORM HANDLERS...).\n\ | |
989 executes BODYFORM and returns its value if no error happens.\n\ | |
990 Each element of HANDLERS looks like (CONDITION-NAME BODY...)\n\ | |
991 where the BODY is made of Lisp expressions.\n\n\ | |
992 A handler is applicable to an error\n\ | |
993 if CONDITION-NAME is one of the error's condition names.\n\ | |
994 If an error happens, the first applicable handler is run.\n\ | |
995 \n\ | |
5567
c61f49e4283a
(Fcondition_case): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
5566
diff
changeset
|
996 The car of a handler may be a list of condition names\n\ |
c61f49e4283a
(Fcondition_case): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
5566
diff
changeset
|
997 instead of a single condition name.\n\ |
c61f49e4283a
(Fcondition_case): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
5566
diff
changeset
|
998 \n\ |
272 | 999 When a handler handles an error,\n\ |
1000 control returns to the condition-case and the handler BODY... is executed\n\ | |
1001 with VAR bound to (SIGNALED-CONDITIONS . SIGNAL-DATA).\n\ | |
1002 VAR may be nil; then you do not get access to the signal information.\n\ | |
1003 \n\ | |
1004 The value of the last BODY form is returned from the condition-case.\n\ | |
1005 See also the function `signal' for more info.") | |
1006 (args) | |
1007 Lisp_Object args; | |
1008 { | |
1009 Lisp_Object val; | |
1010 struct catchtag c; | |
1011 struct handler h; | |
1196
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
1012 register Lisp_Object var, bodyform, handlers; |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
1013 |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
1014 var = Fcar (args); |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
1015 bodyform = Fcar (Fcdr (args)); |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
1016 handlers = Fcdr (Fcdr (args)); |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
1017 CHECK_SYMBOL (var, 0); |
272 | 1018 |
1196
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
1019 for (val = handlers; ! NILP (val); val = Fcdr (val)) |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
1020 { |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
1021 Lisp_Object tem; |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
1022 tem = Fcar (val); |
5563
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5254
diff
changeset
|
1023 if (! (NILP (tem) |
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5254
diff
changeset
|
1024 || (CONSP (tem) |
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5254
diff
changeset
|
1025 && (SYMBOLP (XCONS (tem)->car) |
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5254
diff
changeset
|
1026 || CONSP (XCONS (tem)->car))))) |
1196
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
1027 error ("Invalid condition handler", tem); |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
1028 } |
272 | 1029 |
1030 c.tag = Qnil; | |
1031 c.val = Qnil; | |
1032 c.backlist = backtrace_list; | |
1033 c.handlerlist = handlerlist; | |
1034 c.lisp_eval_depth = lisp_eval_depth; | |
1035 c.pdlcount = specpdl_ptr - specpdl; | |
1036 c.poll_suppress_count = poll_suppress_count; | |
1037 c.gcpro = gcprolist; | |
1038 if (_setjmp (c.jmp)) | |
1039 { | |
485 | 1040 if (!NILP (h.var)) |
6132
ddf57829cf03
(Fsignal): If DATA is memory_signal_data, don't add to it.
Richard M. Stallman <rms@gnu.org>
parents:
5807
diff
changeset
|
1041 specbind (h.var, c.val); |
ddf57829cf03
(Fsignal): If DATA is memory_signal_data, don't add to it.
Richard M. Stallman <rms@gnu.org>
parents:
5807
diff
changeset
|
1042 val = Fprogn (Fcdr (h.chosen_clause)); |
1196
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
1043 |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
1044 /* Note that this just undoes the binding of h.var; whoever |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
1045 longjumped to us unwound the stack to c.pdlcount before |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
1046 throwing. */ |
272 | 1047 unbind_to (c.pdlcount, Qnil); |
1048 return val; | |
1049 } | |
1050 c.next = catchlist; | |
1051 catchlist = &c; | |
1052 | |
1196
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
1053 h.var = var; |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
1054 h.handler = handlers; |
272 | 1055 h.next = handlerlist; |
1056 h.tag = &c; | |
1057 handlerlist = &h; | |
1058 | |
1196
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
1059 val = Feval (bodyform); |
272 | 1060 catchlist = c.next; |
1061 handlerlist = h.next; | |
1062 return val; | |
1063 } | |
1064 | |
1065 Lisp_Object | |
1066 internal_condition_case (bfun, handlers, hfun) | |
1067 Lisp_Object (*bfun) (); | |
1068 Lisp_Object handlers; | |
1069 Lisp_Object (*hfun) (); | |
1070 { | |
1071 Lisp_Object val; | |
1072 struct catchtag c; | |
1073 struct handler h; | |
1074 | |
1075 c.tag = Qnil; | |
1076 c.val = Qnil; | |
1077 c.backlist = backtrace_list; | |
1078 c.handlerlist = handlerlist; | |
1079 c.lisp_eval_depth = lisp_eval_depth; | |
1080 c.pdlcount = specpdl_ptr - specpdl; | |
1081 c.poll_suppress_count = poll_suppress_count; | |
1082 c.gcpro = gcprolist; | |
1083 if (_setjmp (c.jmp)) | |
1084 { | |
6132
ddf57829cf03
(Fsignal): If DATA is memory_signal_data, don't add to it.
Richard M. Stallman <rms@gnu.org>
parents:
5807
diff
changeset
|
1085 return (*hfun) (c.val); |
272 | 1086 } |
1087 c.next = catchlist; | |
1088 catchlist = &c; | |
1089 h.handler = handlers; | |
1090 h.var = Qnil; | |
1091 h.next = handlerlist; | |
1092 h.tag = &c; | |
1093 handlerlist = &h; | |
1094 | |
1095 val = (*bfun) (); | |
1096 catchlist = c.next; | |
1097 handlerlist = h.next; | |
1098 return val; | |
1099 } | |
1100 | |
5807
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1101 Lisp_Object |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1102 internal_condition_case_1 (bfun, arg, handlers, hfun) |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1103 Lisp_Object (*bfun) (); |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1104 Lisp_Object arg; |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1105 Lisp_Object handlers; |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1106 Lisp_Object (*hfun) (); |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1107 { |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1108 Lisp_Object val; |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1109 struct catchtag c; |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1110 struct handler h; |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1111 |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1112 c.tag = Qnil; |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1113 c.val = Qnil; |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1114 c.backlist = backtrace_list; |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1115 c.handlerlist = handlerlist; |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1116 c.lisp_eval_depth = lisp_eval_depth; |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1117 c.pdlcount = specpdl_ptr - specpdl; |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1118 c.poll_suppress_count = poll_suppress_count; |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1119 c.gcpro = gcprolist; |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1120 if (_setjmp (c.jmp)) |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1121 { |
6132
ddf57829cf03
(Fsignal): If DATA is memory_signal_data, don't add to it.
Richard M. Stallman <rms@gnu.org>
parents:
5807
diff
changeset
|
1122 return (*hfun) (c.val); |
5807
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1123 } |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1124 c.next = catchlist; |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1125 catchlist = &c; |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1126 h.handler = handlers; |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1127 h.var = Qnil; |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1128 h.next = handlerlist; |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1129 h.tag = &c; |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1130 handlerlist = &h; |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1131 |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1132 val = (*bfun) (arg); |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1133 catchlist = c.next; |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1134 handlerlist = h.next; |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1135 return val; |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1136 } |
cc9d9ab24008
(internal_condition_case_1): New function.
Richard M. Stallman <rms@gnu.org>
parents:
5567
diff
changeset
|
1137 |
272 | 1138 static Lisp_Object find_handler_clause (); |
1139 | |
1140 DEFUN ("signal", Fsignal, Ssignal, 2, 2, 0, | |
5566
e2925466c923
(Fsignal): Rename 1st arg to error_symbol.
Richard M. Stallman <rms@gnu.org>
parents:
5563
diff
changeset
|
1141 "Signal an error. Args are ERROR-SYMBOL and associated DATA.\n\ |
272 | 1142 This function does not return.\n\n\ |
5566
e2925466c923
(Fsignal): Rename 1st arg to error_symbol.
Richard M. Stallman <rms@gnu.org>
parents:
5563
diff
changeset
|
1143 An error symbol is a symbol with an `error-conditions' property\n\ |
272 | 1144 that is a list of condition names.\n\ |
1145 A handler for any of those names will get to handle this signal.\n\ | |
1146 The symbol `error' should normally be one of them.\n\ | |
1147 \n\ | |
1148 DATA should be a list. Its elements are printed as part of the error message.\n\ | |
1149 If the signal is handled, DATA is made available to the handler.\n\ | |
1150 See also the function `condition-case'.") | |
5566
e2925466c923
(Fsignal): Rename 1st arg to error_symbol.
Richard M. Stallman <rms@gnu.org>
parents:
5563
diff
changeset
|
1151 (error_symbol, data) |
e2925466c923
(Fsignal): Rename 1st arg to error_symbol.
Richard M. Stallman <rms@gnu.org>
parents:
5563
diff
changeset
|
1152 Lisp_Object error_symbol, data; |
272 | 1153 { |
1154 register struct handler *allhandlers = handlerlist; | |
1155 Lisp_Object conditions; | |
1156 extern int gc_in_progress; | |
1157 extern int waiting_for_input; | |
1158 Lisp_Object debugger_value; | |
1159 | |
1160 quit_error_check (); | |
1161 immediate_quit = 0; | |
1162 if (gc_in_progress || waiting_for_input) | |
1163 abort (); | |
1164 | |
732 | 1165 #ifdef HAVE_X_WINDOWS |
272 | 1166 TOTALLY_UNBLOCK_INPUT; |
732 | 1167 #endif |
272 | 1168 |
5566
e2925466c923
(Fsignal): Rename 1st arg to error_symbol.
Richard M. Stallman <rms@gnu.org>
parents:
5563
diff
changeset
|
1169 conditions = Fget (error_symbol, Qerror_conditions); |
272 | 1170 |
1171 for (; handlerlist; handlerlist = handlerlist->next) | |
1172 { | |
1173 register Lisp_Object clause; | |
1174 clause = find_handler_clause (handlerlist->handler, conditions, | |
5566
e2925466c923
(Fsignal): Rename 1st arg to error_symbol.
Richard M. Stallman <rms@gnu.org>
parents:
5563
diff
changeset
|
1175 error_symbol, data, &debugger_value); |
272 | 1176 |
1177 #if 0 /* Most callers are not prepared to handle gc if this returns. | |
1178 So, since this feature is not very useful, take it out. */ | |
1179 /* If have called debugger and user wants to continue, | |
1180 just return nil. */ | |
1181 if (EQ (clause, Qlambda)) | |
1182 return debugger_value; | |
1183 #else | |
1184 if (EQ (clause, Qlambda)) | |
1196
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
1185 { |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
1186 /* We can't return values to code which signalled an error, but we |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
1187 can continue code which has signalled a quit. */ |
5566
e2925466c923
(Fsignal): Rename 1st arg to error_symbol.
Richard M. Stallman <rms@gnu.org>
parents:
5563
diff
changeset
|
1188 if (EQ (error_symbol, Qquit)) |
1196
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
1189 return Qnil; |
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
1190 else |
3973
ab06b106c490
(Fsignal): Clarify error message.
Richard M. Stallman <rms@gnu.org>
parents:
3703
diff
changeset
|
1191 error ("Cannot return from the debugger in an error"); |
1196
65e2edefe748
* eval.c (Fcondition_case): Rearranged for clarity. Don't worry
Jim Blandy <jimb@redhat.com>
parents:
940
diff
changeset
|
1192 } |
272 | 1193 #endif |
1194 | |
485 | 1195 if (!NILP (clause)) |
272 | 1196 { |
6132
ddf57829cf03
(Fsignal): If DATA is memory_signal_data, don't add to it.
Richard M. Stallman <rms@gnu.org>
parents:
5807
diff
changeset
|
1197 Lisp_Object unwind_data; |
272 | 1198 struct handler *h = handlerlist; |
6132
ddf57829cf03
(Fsignal): If DATA is memory_signal_data, don't add to it.
Richard M. Stallman <rms@gnu.org>
parents:
5807
diff
changeset
|
1199 |
272 | 1200 handlerlist = allhandlers; |
6132
ddf57829cf03
(Fsignal): If DATA is memory_signal_data, don't add to it.
Richard M. Stallman <rms@gnu.org>
parents:
5807
diff
changeset
|
1201 if (data == memory_signal_data) |
ddf57829cf03
(Fsignal): If DATA is memory_signal_data, don't add to it.
Richard M. Stallman <rms@gnu.org>
parents:
5807
diff
changeset
|
1202 unwind_data = memory_signal_data; |
ddf57829cf03
(Fsignal): If DATA is memory_signal_data, don't add to it.
Richard M. Stallman <rms@gnu.org>
parents:
5807
diff
changeset
|
1203 else |
ddf57829cf03
(Fsignal): If DATA is memory_signal_data, don't add to it.
Richard M. Stallman <rms@gnu.org>
parents:
5807
diff
changeset
|
1204 unwind_data = Fcons (error_symbol, data); |
ddf57829cf03
(Fsignal): If DATA is memory_signal_data, don't add to it.
Richard M. Stallman <rms@gnu.org>
parents:
5807
diff
changeset
|
1205 h->chosen_clause = clause; |
ddf57829cf03
(Fsignal): If DATA is memory_signal_data, don't add to it.
Richard M. Stallman <rms@gnu.org>
parents:
5807
diff
changeset
|
1206 unwind_to_catch (h->tag, unwind_data); |
272 | 1207 } |
1208 } | |
1209 | |
1210 handlerlist = allhandlers; | |
1211 /* If no handler is present now, try to run the debugger, | |
1212 and if that fails, throw to top level. */ | |
5566
e2925466c923
(Fsignal): Rename 1st arg to error_symbol.
Richard M. Stallman <rms@gnu.org>
parents:
5563
diff
changeset
|
1213 find_handler_clause (Qerror, conditions, error_symbol, data, &debugger_value); |
272 | 1214 Fthrow (Qtop_level, Qt); |
1215 } | |
1216 | |
684 | 1217 /* Return nonzero iff LIST is a non-nil atom or |
1218 a list containing one of CONDITIONS. */ | |
1219 | |
1220 static int | |
1221 wants_debugger (list, conditions) | |
1222 Lisp_Object list, conditions; | |
1223 { | |
706
86cb5db0b6c3
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
687
diff
changeset
|
1224 if (NILP (list)) |
684 | 1225 return 0; |
1226 if (! CONSP (list)) | |
1227 return 1; | |
1228 | |
878
5b1c5b4286e7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
863
diff
changeset
|
1229 while (CONSP (conditions)) |
684 | 1230 { |
878
5b1c5b4286e7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
863
diff
changeset
|
1231 Lisp_Object this, tail; |
5b1c5b4286e7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
863
diff
changeset
|
1232 this = XCONS (conditions)->car; |
5b1c5b4286e7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
863
diff
changeset
|
1233 for (tail = list; CONSP (tail); tail = XCONS (tail)->cdr) |
5b1c5b4286e7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
863
diff
changeset
|
1234 if (EQ (XCONS (tail)->car, this)) |
684 | 1235 return 1; |
1236 conditions = XCONS (conditions)->cdr; | |
1237 } | |
878
5b1c5b4286e7
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
863
diff
changeset
|
1238 return 0; |
684 | 1239 } |
1240 | |
1241 /* Value of Qlambda means we have called debugger and user has continued. | |
1242 Store value returned from debugger into *DEBUGGER_VALUE_PTR. */ | |
272 | 1243 |
1244 static Lisp_Object | |
1245 find_handler_clause (handlers, conditions, sig, data, debugger_value_ptr) | |
1246 Lisp_Object handlers, conditions, sig, data; | |
1247 Lisp_Object *debugger_value_ptr; | |
1248 { | |
1249 register Lisp_Object h; | |
1250 register Lisp_Object tem; | |
1251 | |
1252 if (EQ (handlers, Qt)) /* t is used by handlers for all conditions, set up by C code. */ | |
1253 return Qt; | |
1254 if (EQ (handlers, Qerror)) /* error is used similarly, but means display a backtrace too */ | |
1255 { | |
684 | 1256 if (wants_debugger (Vstack_trace_on_error, conditions)) |
272 | 1257 internal_with_output_to_temp_buffer ("*Backtrace*", Fbacktrace, Qnil); |
1199
ab2d88e2505b
* eval.c (unbind_catch): Do the long-jump here. Take a VALUE
Jim Blandy <jimb@redhat.com>
parents:
1196
diff
changeset
|
1258 if ((EQ (sig, Qquit) |
ab2d88e2505b
* eval.c (unbind_catch): Do the long-jump here. Take a VALUE
Jim Blandy <jimb@redhat.com>
parents:
1196
diff
changeset
|
1259 ? debug_on_quit |
ab2d88e2505b
* eval.c (unbind_catch): Do the long-jump here. Take a VALUE
Jim Blandy <jimb@redhat.com>
parents:
1196
diff
changeset
|
1260 : wants_debugger (Vdebug_on_error, conditions)) |
ab2d88e2505b
* eval.c (unbind_catch): Do the long-jump here. Take a VALUE
Jim Blandy <jimb@redhat.com>
parents:
1196
diff
changeset
|
1261 && when_entered_debugger < num_nonmacro_input_chars) |
272 | 1262 { |
1263 int count = specpdl_ptr - specpdl; | |
1264 specbind (Qdebug_on_error, Qnil); | |
1265 *debugger_value_ptr = | |
1266 call_debugger (Fcons (Qerror, | |
1267 Fcons (Fcons (sig, data), | |
1268 Qnil))); | |
1269 return unbind_to (count, Qlambda); | |
1270 } | |
1271 return Qt; | |
1272 } | |
1273 for (h = handlers; CONSP (h); h = Fcdr (h)) | |
1274 { | |
5563
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5254
diff
changeset
|
1275 Lisp_Object handler, condit; |
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5254
diff
changeset
|
1276 |
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5254
diff
changeset
|
1277 handler = Fcar (h); |
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5254
diff
changeset
|
1278 if (!CONSP (handler)) |
272 | 1279 continue; |
5563
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5254
diff
changeset
|
1280 condit = Fcar (handler); |
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5254
diff
changeset
|
1281 /* Handle a single condition name in handler HANDLER. */ |
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5254
diff
changeset
|
1282 if (SYMBOLP (condit)) |
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5254
diff
changeset
|
1283 { |
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5254
diff
changeset
|
1284 tem = Fmemq (Fcar (handler), conditions); |
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5254
diff
changeset
|
1285 if (!NILP (tem)) |
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5254
diff
changeset
|
1286 return handler; |
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5254
diff
changeset
|
1287 } |
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5254
diff
changeset
|
1288 /* Handle a list of condition names in handler HANDLER. */ |
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5254
diff
changeset
|
1289 else if (CONSP (condit)) |
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5254
diff
changeset
|
1290 { |
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5254
diff
changeset
|
1291 while (CONSP (condit)) |
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5254
diff
changeset
|
1292 { |
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5254
diff
changeset
|
1293 tem = Fmemq (Fcar (condit), conditions); |
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5254
diff
changeset
|
1294 if (!NILP (tem)) |
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5254
diff
changeset
|
1295 return handler; |
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5254
diff
changeset
|
1296 condit = XCONS (condit)->cdr; |
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5254
diff
changeset
|
1297 } |
50ada322de3e
(Fcondition_case): Allow a list of condition names in a handler.
Richard M. Stallman <rms@gnu.org>
parents:
5254
diff
changeset
|
1298 } |
272 | 1299 } |
1300 return Qnil; | |
1301 } | |
1302 | |
1303 /* dump an error message; called like printf */ | |
1304 | |
1305 /* VARARGS 1 */ | |
1306 void | |
1307 error (m, a1, a2, a3) | |
1308 char *m; | |
6225
8f92cf89ed7c
(error): Use doprnt. Make buffer larger as necessary.
Richard M. Stallman <rms@gnu.org>
parents:
6132
diff
changeset
|
1309 char *a1, *a2, *a3; |
272 | 1310 { |
1311 char buf[200]; | |
6225
8f92cf89ed7c
(error): Use doprnt. Make buffer larger as necessary.
Richard M. Stallman <rms@gnu.org>
parents:
6132
diff
changeset
|
1312 int size = 200; |
8f92cf89ed7c
(error): Use doprnt. Make buffer larger as necessary.
Richard M. Stallman <rms@gnu.org>
parents:
6132
diff
changeset
|
1313 int mlen; |
8f92cf89ed7c
(error): Use doprnt. Make buffer larger as necessary.
Richard M. Stallman <rms@gnu.org>
parents:
6132
diff
changeset
|
1314 char *buffer = buf; |
8f92cf89ed7c
(error): Use doprnt. Make buffer larger as necessary.
Richard M. Stallman <rms@gnu.org>
parents:
6132
diff
changeset
|
1315 char *args[3]; |
8f92cf89ed7c
(error): Use doprnt. Make buffer larger as necessary.
Richard M. Stallman <rms@gnu.org>
parents:
6132
diff
changeset
|
1316 int allocated = 0; |
8f92cf89ed7c
(error): Use doprnt. Make buffer larger as necessary.
Richard M. Stallman <rms@gnu.org>
parents:
6132
diff
changeset
|
1317 Lisp_Object string; |
8f92cf89ed7c
(error): Use doprnt. Make buffer larger as necessary.
Richard M. Stallman <rms@gnu.org>
parents:
6132
diff
changeset
|
1318 |
8f92cf89ed7c
(error): Use doprnt. Make buffer larger as necessary.
Richard M. Stallman <rms@gnu.org>
parents:
6132
diff
changeset
|
1319 args[0] = a1; |
8f92cf89ed7c
(error): Use doprnt. Make buffer larger as necessary.
Richard M. Stallman <rms@gnu.org>
parents:
6132
diff
changeset
|
1320 args[1] = a2; |
8f92cf89ed7c
(error): Use doprnt. Make buffer larger as necessary.
Richard M. Stallman <rms@gnu.org>
parents:
6132
diff
changeset
|
1321 args[2] = a3; |
8f92cf89ed7c
(error): Use doprnt. Make buffer larger as necessary.
Richard M. Stallman <rms@gnu.org>
parents:
6132
diff
changeset
|
1322 |
8f92cf89ed7c
(error): Use doprnt. Make buffer larger as necessary.
Richard M. Stallman <rms@gnu.org>
parents:
6132
diff
changeset
|
1323 mlen = strlen (m); |
272 | 1324 |
1325 while (1) | |
6225
8f92cf89ed7c
(error): Use doprnt. Make buffer larger as necessary.
Richard M. Stallman <rms@gnu.org>
parents:
6132
diff
changeset
|
1326 { |
8f92cf89ed7c
(error): Use doprnt. Make buffer larger as necessary.
Richard M. Stallman <rms@gnu.org>
parents:
6132
diff
changeset
|
1327 int used = doprnt (buf, size, m, m + mlen, 3, args); |
8f92cf89ed7c
(error): Use doprnt. Make buffer larger as necessary.
Richard M. Stallman <rms@gnu.org>
parents:
6132
diff
changeset
|
1328 if (used < size) |
8f92cf89ed7c
(error): Use doprnt. Make buffer larger as necessary.
Richard M. Stallman <rms@gnu.org>
parents:
6132
diff
changeset
|
1329 break; |
8f92cf89ed7c
(error): Use doprnt. Make buffer larger as necessary.
Richard M. Stallman <rms@gnu.org>
parents:
6132
diff
changeset
|
1330 size *= 2; |
8f92cf89ed7c
(error): Use doprnt. Make buffer larger as necessary.
Richard M. Stallman <rms@gnu.org>
parents:
6132
diff
changeset
|
1331 if (allocated) |
8f92cf89ed7c
(error): Use doprnt. Make buffer larger as necessary.
Richard M. Stallman <rms@gnu.org>
parents:
6132
diff
changeset
|
1332 buffer = (char *) xrealloc (buffer, size); |
8f92cf89ed7c
(error): Use doprnt. Make buffer larger as necessary.
Richard M. Stallman <rms@gnu.org>
parents:
6132
diff
changeset
|
1333 buffer = (char *) xmalloc (size); |
8f92cf89ed7c
(error): Use doprnt. Make buffer larger as necessary.
Richard M. Stallman <rms@gnu.org>
parents:
6132
diff
changeset
|
1334 } |
8f92cf89ed7c
(error): Use doprnt. Make buffer larger as necessary.
Richard M. Stallman <rms@gnu.org>
parents:
6132
diff
changeset
|
1335 |
8f92cf89ed7c
(error): Use doprnt. Make buffer larger as necessary.
Richard M. Stallman <rms@gnu.org>
parents:
6132
diff
changeset
|
1336 string = build_string (buf); |
8f92cf89ed7c
(error): Use doprnt. Make buffer larger as necessary.
Richard M. Stallman <rms@gnu.org>
parents:
6132
diff
changeset
|
1337 if (allocated) |
8f92cf89ed7c
(error): Use doprnt. Make buffer larger as necessary.
Richard M. Stallman <rms@gnu.org>
parents:
6132
diff
changeset
|
1338 free (buffer); |
8f92cf89ed7c
(error): Use doprnt. Make buffer larger as necessary.
Richard M. Stallman <rms@gnu.org>
parents:
6132
diff
changeset
|
1339 |
8f92cf89ed7c
(error): Use doprnt. Make buffer larger as necessary.
Richard M. Stallman <rms@gnu.org>
parents:
6132
diff
changeset
|
1340 Fsignal (Qerror, Fcons (string, Qnil)); |
272 | 1341 } |
1342 | |
1343 DEFUN ("commandp", Fcommandp, Scommandp, 1, 1, 0, | |
1344 "T if FUNCTION makes provisions for interactive calling.\n\ | |
1345 This means it contains a description for how to read arguments to give it.\n\ | |
1346 The value is nil for an invalid function or a symbol with no function\n\ | |
1347 definition.\n\ | |
1348 \n\ | |
1349 Interactively callable functions include strings and vectors (treated\n\ | |
1350 as keyboard macros), lambda-expressions that contain a top-level call\n\ | |
1351 to `interactive', autoload definitions made by `autoload' with non-nil\n\ | |
1352 fourth argument, and some of the built-in functions of Lisp.\n\ | |
1353 \n\ | |
1354 Also, a symbol satisfies `commandp' if its function definition does so.") | |
1355 (function) | |
1356 Lisp_Object function; | |
1357 { | |
1358 register Lisp_Object fun; | |
1359 register Lisp_Object funcar; | |
1360 register Lisp_Object tem; | |
1361 register int i = 0; | |
1362 | |
1363 fun = function; | |
1364 | |
648 | 1365 fun = indirect_function (fun); |
1366 if (EQ (fun, Qunbound)) | |
1367 return Qnil; | |
272 | 1368 |
1369 /* Emacs primitives are interactive if their DEFUN specifies an | |
1370 interactive spec. */ | |
1371 if (XTYPE (fun) == Lisp_Subr) | |
1372 { | |
1373 if (XSUBR (fun)->prompt) | |
1374 return Qt; | |
1375 else | |
1376 return Qnil; | |
1377 } | |
1378 | |
1379 /* Bytecode objects are interactive if they are long enough to | |
1380 have an element whose index is COMPILED_INTERACTIVE, which is | |
1381 where the interactive spec is stored. */ | |
1382 else if (XTYPE (fun) == Lisp_Compiled) | |
1383 return (XVECTOR (fun)->size > COMPILED_INTERACTIVE | |
1384 ? Qt : Qnil); | |
1385 | |
1386 /* Strings and vectors are keyboard macros. */ | |
1387 if (XTYPE (fun) == Lisp_String | |
1388 || XTYPE (fun) == Lisp_Vector) | |
1389 return Qt; | |
1390 | |
1391 /* Lists may represent commands. */ | |
1392 if (!CONSP (fun)) | |
1393 return Qnil; | |
1394 funcar = Fcar (fun); | |
1395 if (XTYPE (funcar) != Lisp_Symbol) | |
1396 return Fsignal (Qinvalid_function, Fcons (fun, Qnil)); | |
1397 if (EQ (funcar, Qlambda)) | |
1398 return Fassq (Qinteractive, Fcdr (Fcdr (fun))); | |
1399 if (EQ (funcar, Qmocklisp)) | |
1400 return Qt; /* All mocklisp functions can be called interactively */ | |
1401 if (EQ (funcar, Qautoload)) | |
1402 return Fcar (Fcdr (Fcdr (Fcdr (fun)))); | |
1403 else | |
1404 return Qnil; | |
1405 } | |
1406 | |
1407 /* ARGSUSED */ | |
1408 DEFUN ("autoload", Fautoload, Sautoload, 2, 5, 0, | |
1409 "Define FUNCTION to autoload from FILE.\n\ | |
1410 FUNCTION is a symbol; FILE is a file name string to pass to `load'.\n\ | |
1411 Third arg DOCSTRING is documentation for the function.\n\ | |
1412 Fourth arg INTERACTIVE if non-nil says function can be called interactively.\n\ | |
1564
b327816041d1
* eval.c (Fautoload): Renamed fifth argument TYPE. Document the
Jim Blandy <jimb@redhat.com>
parents:
1452
diff
changeset
|
1413 Fifth arg TYPE indicates the type of the object:\n\ |
b327816041d1
* eval.c (Fautoload): Renamed fifth argument TYPE. Document the
Jim Blandy <jimb@redhat.com>
parents:
1452
diff
changeset
|
1414 nil or omitted says FUNCTION is a function,\n\ |
b327816041d1
* eval.c (Fautoload): Renamed fifth argument TYPE. Document the
Jim Blandy <jimb@redhat.com>
parents:
1452
diff
changeset
|
1415 `keymap' says FUNCTION is really a keymap, and\n\ |
b327816041d1
* eval.c (Fautoload): Renamed fifth argument TYPE. Document the
Jim Blandy <jimb@redhat.com>
parents:
1452
diff
changeset
|
1416 `macro' or t says FUNCTION is really a macro.\n\ |
272 | 1417 Third through fifth args give info about the real definition.\n\ |
1418 They default to nil.\n\ | |
1419 If FUNCTION is already defined other than as an autoload,\n\ | |
1420 this does nothing and returns nil.") | |
1564
b327816041d1
* eval.c (Fautoload): Renamed fifth argument TYPE. Document the
Jim Blandy <jimb@redhat.com>
parents:
1452
diff
changeset
|
1421 (function, file, docstring, interactive, type) |
b327816041d1
* eval.c (Fautoload): Renamed fifth argument TYPE. Document the
Jim Blandy <jimb@redhat.com>
parents:
1452
diff
changeset
|
1422 Lisp_Object function, file, docstring, interactive, type; |
272 | 1423 { |
1424 #ifdef NO_ARG_ARRAY | |
1425 Lisp_Object args[4]; | |
1426 #endif | |
1427 | |
1428 CHECK_SYMBOL (function, 0); | |
1429 CHECK_STRING (file, 1); | |
1430 | |
1431 /* If function is defined and not as an autoload, don't override */ | |
1432 if (!EQ (XSYMBOL (function)->function, Qunbound) | |
1433 && !(XTYPE (XSYMBOL (function)->function) == Lisp_Cons | |
1434 && EQ (XCONS (XSYMBOL (function)->function)->car, Qautoload))) | |
1435 return Qnil; | |
1436 | |
1437 #ifdef NO_ARG_ARRAY | |
1438 args[0] = file; | |
1439 args[1] = docstring; | |
1440 args[2] = interactive; | |
1564
b327816041d1
* eval.c (Fautoload): Renamed fifth argument TYPE. Document the
Jim Blandy <jimb@redhat.com>
parents:
1452
diff
changeset
|
1441 args[3] = type; |
272 | 1442 |
1443 return Ffset (function, Fcons (Qautoload, Flist (4, &args[0]))); | |
1444 #else /* NO_ARG_ARRAY */ | |
1445 return Ffset (function, Fcons (Qautoload, Flist (4, &file))); | |
1446 #endif /* not NO_ARG_ARRAY */ | |
1447 } | |
1448 | |
1449 Lisp_Object | |
1450 un_autoload (oldqueue) | |
1451 Lisp_Object oldqueue; | |
1452 { | |
1453 register Lisp_Object queue, first, second; | |
1454 | |
1455 /* Queue to unwind is current value of Vautoload_queue. | |
1456 oldqueue is the shadowed value to leave in Vautoload_queue. */ | |
1457 queue = Vautoload_queue; | |
1458 Vautoload_queue = oldqueue; | |
1459 while (CONSP (queue)) | |
1460 { | |
1461 first = Fcar (queue); | |
1462 second = Fcdr (first); | |
1463 first = Fcar (first); | |
1464 if (EQ (second, Qnil)) | |
1465 Vfeatures = first; | |
1466 else | |
1467 Ffset (first, second); | |
1468 queue = Fcdr (queue); | |
1469 } | |
1470 return Qnil; | |
1471 } | |
1472 | |
1473 do_autoload (fundef, funname) | |
1474 Lisp_Object fundef, funname; | |
1475 { | |
1476 int count = specpdl_ptr - specpdl; | |
2547
c73c68a87cd5
(defun, defmacro, defvar, defconst):
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
1477 Lisp_Object fun, val, queue, first, second; |
272 | 1478 |
1479 fun = funname; | |
1480 CHECK_SYMBOL (funname, 0); | |
1481 | |
1482 /* Value saved here is to be restored into Vautoload_queue */ | |
1483 record_unwind_protect (un_autoload, Vautoload_queue); | |
1484 Vautoload_queue = Qt; | |
1485 Fload (Fcar (Fcdr (fundef)), Qnil, noninteractive ? Qt : Qnil, Qnil); | |
2547
c73c68a87cd5
(defun, defmacro, defvar, defconst):
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
1486 |
c73c68a87cd5
(defun, defmacro, defvar, defconst):
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
1487 /* Save the old autoloads, in case we ever do an unload. */ |
c73c68a87cd5
(defun, defmacro, defvar, defconst):
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
1488 queue = Vautoload_queue; |
c73c68a87cd5
(defun, defmacro, defvar, defconst):
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
1489 while (CONSP (queue)) |
c73c68a87cd5
(defun, defmacro, defvar, defconst):
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
1490 { |
c73c68a87cd5
(defun, defmacro, defvar, defconst):
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
1491 first = Fcar (queue); |
c73c68a87cd5
(defun, defmacro, defvar, defconst):
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
1492 second = Fcdr (first); |
c73c68a87cd5
(defun, defmacro, defvar, defconst):
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
1493 first = Fcar (first); |
2599
5122736c0a03
(do_autoload): Fixed the bug in the autoload-saving code.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2596
diff
changeset
|
1494 |
5122736c0a03
(do_autoload): Fixed the bug in the autoload-saving code.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2596
diff
changeset
|
1495 /* Note: This test is subtle. The cdr of an autoload-queue entry |
5122736c0a03
(do_autoload): Fixed the bug in the autoload-saving code.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2596
diff
changeset
|
1496 may be an atom if the autoload entry was generated by a defalias |
5122736c0a03
(do_autoload): Fixed the bug in the autoload-saving code.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2596
diff
changeset
|
1497 or fset. */ |
5122736c0a03
(do_autoload): Fixed the bug in the autoload-saving code.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2596
diff
changeset
|
1498 if (CONSP (second)) |
4782 | 1499 Fput (first, Qautoload, (Fcdr (second))); |
2599
5122736c0a03
(do_autoload): Fixed the bug in the autoload-saving code.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2596
diff
changeset
|
1500 |
2547
c73c68a87cd5
(defun, defmacro, defvar, defconst):
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
1501 queue = Fcdr (queue); |
c73c68a87cd5
(defun, defmacro, defvar, defconst):
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
1502 } |
c73c68a87cd5
(defun, defmacro, defvar, defconst):
Richard M. Stallman <rms@gnu.org>
parents:
2439
diff
changeset
|
1503 |
272 | 1504 /* Once loading finishes, don't undo it. */ |
1505 Vautoload_queue = Qt; | |
1506 unbind_to (count, Qnil); | |
1507 | |
648 | 1508 fun = Findirect_function (fun); |
1509 | |
4462
9fbc6c74cab5
(do_autoload): Don't report autoload failure
Richard M. Stallman <rms@gnu.org>
parents:
4167
diff
changeset
|
1510 if (!NILP (Fequal (fun, fundef))) |
272 | 1511 error ("Autoloading failed to define function %s", |
1512 XSYMBOL (funname)->name->data); | |
1513 } | |
1514 | |
1515 DEFUN ("eval", Feval, Seval, 1, 1, 0, | |
1516 "Evaluate FORM and return its value.") | |
1517 (form) | |
1518 Lisp_Object form; | |
1519 { | |
1520 Lisp_Object fun, val, original_fun, original_args; | |
1521 Lisp_Object funcar; | |
1522 struct backtrace backtrace; | |
1523 struct gcpro gcpro1, gcpro2, gcpro3; | |
1524 | |
1525 if (XTYPE (form) == Lisp_Symbol) | |
1526 { | |
1527 if (EQ (Vmocklisp_arguments, Qt)) | |
1528 return Fsymbol_value (form); | |
1529 val = Fsymbol_value (form); | |
485 | 1530 if (NILP (val)) |
272 | 1531 XFASTINT (val) = 0; |
1532 else if (EQ (val, Qt)) | |
1533 XFASTINT (val) = 1; | |
1534 return val; | |
1535 } | |
1536 if (!CONSP (form)) | |
1537 return form; | |
1538 | |
1539 QUIT; | |
1540 if (consing_since_gc > gc_cons_threshold) | |
1541 { | |
1542 GCPRO1 (form); | |
1543 Fgarbage_collect (); | |
1544 UNGCPRO; | |
1545 } | |
1546 | |
1547 if (++lisp_eval_depth > max_lisp_eval_depth) | |
1548 { | |
1549 if (max_lisp_eval_depth < 100) | |
1550 max_lisp_eval_depth = 100; | |
1551 if (lisp_eval_depth > max_lisp_eval_depth) | |
1552 error ("Lisp nesting exceeds max-lisp-eval-depth"); | |
1553 } | |
1554 | |
1555 original_fun = Fcar (form); | |
1556 original_args = Fcdr (form); | |
1557 | |
1558 backtrace.next = backtrace_list; | |
1559 backtrace_list = &backtrace; | |
1560 backtrace.function = &original_fun; /* This also protects them from gc */ | |
1561 backtrace.args = &original_args; | |
1562 backtrace.nargs = UNEVALLED; | |
1563 backtrace.evalargs = 1; | |
1564 backtrace.debug_on_exit = 0; | |
1565 | |
1566 if (debug_on_next_call) | |
1567 do_debug_on_call (Qt); | |
1568 | |
1569 /* At this point, only original_fun and original_args | |
1570 have values that will be used below */ | |
1571 retry: | |
648 | 1572 fun = Findirect_function (original_fun); |
272 | 1573 |
1574 if (XTYPE (fun) == Lisp_Subr) | |
1575 { | |
1576 Lisp_Object numargs; | |
1577 Lisp_Object argvals[7]; | |
1578 Lisp_Object args_left; | |
1579 register int i, maxargs; | |
1580 | |
1581 args_left = original_args; | |
1582 numargs = Flength (args_left); | |
1583 | |
1584 if (XINT (numargs) < XSUBR (fun)->min_args || | |
1585 (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < XINT (numargs))) | |
1586 return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (numargs, Qnil))); | |
1587 | |
1588 if (XSUBR (fun)->max_args == UNEVALLED) | |
1589 { | |
1590 backtrace.evalargs = 0; | |
1591 val = (*XSUBR (fun)->function) (args_left); | |
1592 goto done; | |
1593 } | |
1594 | |
1595 if (XSUBR (fun)->max_args == MANY) | |
1596 { | |
1597 /* Pass a vector of evaluated arguments */ | |
1598 Lisp_Object *vals; | |
1599 register int argnum = 0; | |
1600 | |
1601 vals = (Lisp_Object *) alloca (XINT (numargs) * sizeof (Lisp_Object)); | |
1602 | |
1603 GCPRO3 (args_left, fun, fun); | |
1604 gcpro3.var = vals; | |
1605 gcpro3.nvars = 0; | |
1606 | |
485 | 1607 while (!NILP (args_left)) |
272 | 1608 { |
1609 vals[argnum++] = Feval (Fcar (args_left)); | |
1610 args_left = Fcdr (args_left); | |
1611 gcpro3.nvars = argnum; | |
1612 } | |
1613 | |
1614 backtrace.args = vals; | |
1615 backtrace.nargs = XINT (numargs); | |
1616 | |
1617 val = (*XSUBR (fun)->function) (XINT (numargs), vals); | |
323 | 1618 UNGCPRO; |
272 | 1619 goto done; |
1620 } | |
1621 | |
1622 GCPRO3 (args_left, fun, fun); | |
1623 gcpro3.var = argvals; | |
1624 gcpro3.nvars = 0; | |
1625 | |
1626 maxargs = XSUBR (fun)->max_args; | |
1627 for (i = 0; i < maxargs; args_left = Fcdr (args_left)) | |
1628 { | |
1629 argvals[i] = Feval (Fcar (args_left)); | |
1630 gcpro3.nvars = ++i; | |
1631 } | |
1632 | |
1633 UNGCPRO; | |
1634 | |
1635 backtrace.args = argvals; | |
1636 backtrace.nargs = XINT (numargs); | |
1637 | |
1638 switch (i) | |
1639 { | |
1640 case 0: | |
1641 val = (*XSUBR (fun)->function) (); | |
1642 goto done; | |
1643 case 1: | |
1644 val = (*XSUBR (fun)->function) (argvals[0]); | |
1645 goto done; | |
1646 case 2: | |
1647 val = (*XSUBR (fun)->function) (argvals[0], argvals[1]); | |
1648 goto done; | |
1649 case 3: | |
1650 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], | |
1651 argvals[2]); | |
1652 goto done; | |
1653 case 4: | |
1654 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], | |
1655 argvals[2], argvals[3]); | |
1656 goto done; | |
1657 case 5: | |
1658 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2], | |
1659 argvals[3], argvals[4]); | |
1660 goto done; | |
1661 case 6: | |
1662 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2], | |
1663 argvals[3], argvals[4], argvals[5]); | |
1664 goto done; | |
863
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
753
diff
changeset
|
1665 case 7: |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
753
diff
changeset
|
1666 val = (*XSUBR (fun)->function) (argvals[0], argvals[1], argvals[2], |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
753
diff
changeset
|
1667 argvals[3], argvals[4], argvals[5], |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
753
diff
changeset
|
1668 argvals[6]); |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
753
diff
changeset
|
1669 goto done; |
272 | 1670 |
1671 default: | |
604 | 1672 /* Someone has created a subr that takes more arguments than |
1673 is supported by this code. We need to either rewrite the | |
1674 subr to use a different argument protocol, or add more | |
1675 cases to this switch. */ | |
1676 abort (); | |
272 | 1677 } |
1678 } | |
1679 if (XTYPE (fun) == Lisp_Compiled) | |
1680 val = apply_lambda (fun, original_args, 1); | |
1681 else | |
1682 { | |
1683 if (!CONSP (fun)) | |
1684 return Fsignal (Qinvalid_function, Fcons (fun, Qnil)); | |
1685 funcar = Fcar (fun); | |
1686 if (XTYPE (funcar) != Lisp_Symbol) | |
1687 return Fsignal (Qinvalid_function, Fcons (fun, Qnil)); | |
1688 if (EQ (funcar, Qautoload)) | |
1689 { | |
1690 do_autoload (fun, original_fun); | |
1691 goto retry; | |
1692 } | |
1693 if (EQ (funcar, Qmacro)) | |
1694 val = Feval (apply1 (Fcdr (fun), original_args)); | |
1695 else if (EQ (funcar, Qlambda)) | |
1696 val = apply_lambda (fun, original_args, 1); | |
1697 else if (EQ (funcar, Qmocklisp)) | |
1698 val = ml_apply (fun, original_args); | |
1699 else | |
1700 return Fsignal (Qinvalid_function, Fcons (fun, Qnil)); | |
1701 } | |
1702 done: | |
1703 if (!EQ (Vmocklisp_arguments, Qt)) | |
1704 { | |
485 | 1705 if (NILP (val)) |
272 | 1706 XFASTINT (val) = 0; |
1707 else if (EQ (val, Qt)) | |
1708 XFASTINT (val) = 1; | |
1709 } | |
1710 lisp_eval_depth--; | |
1711 if (backtrace.debug_on_exit) | |
1712 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil))); | |
1713 backtrace_list = backtrace.next; | |
1714 return val; | |
1715 } | |
1716 | |
1717 DEFUN ("apply", Fapply, Sapply, 2, MANY, 0, | |
1718 "Call FUNCTION with our remaining args, using our last arg as list of args.\n\ | |
1719 Thus, (apply '+ 1 2 '(3 4)) returns 10.") | |
1720 (nargs, args) | |
1721 int nargs; | |
1722 Lisp_Object *args; | |
1723 { | |
1724 register int i, numargs; | |
1725 register Lisp_Object spread_arg; | |
1726 register Lisp_Object *funcall_args; | |
1727 Lisp_Object fun; | |
323 | 1728 struct gcpro gcpro1; |
272 | 1729 |
1730 fun = args [0]; | |
1731 funcall_args = 0; | |
1732 spread_arg = args [nargs - 1]; | |
1733 CHECK_LIST (spread_arg, nargs); | |
1734 | |
1735 numargs = XINT (Flength (spread_arg)); | |
1736 | |
1737 if (numargs == 0) | |
1738 return Ffuncall (nargs - 1, args); | |
1739 else if (numargs == 1) | |
1740 { | |
1741 args [nargs - 1] = XCONS (spread_arg)->car; | |
1742 return Ffuncall (nargs, args); | |
1743 } | |
1744 | |
323 | 1745 numargs += nargs - 2; |
272 | 1746 |
648 | 1747 fun = indirect_function (fun); |
1748 if (EQ (fun, Qunbound)) | |
272 | 1749 { |
648 | 1750 /* Let funcall get the error */ |
1751 fun = args[0]; | |
1752 goto funcall; | |
272 | 1753 } |
1754 | |
1755 if (XTYPE (fun) == Lisp_Subr) | |
1756 { | |
1757 if (numargs < XSUBR (fun)->min_args | |
1758 || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs)) | |
1759 goto funcall; /* Let funcall get the error */ | |
1760 else if (XSUBR (fun)->max_args > numargs) | |
1761 { | |
1762 /* Avoid making funcall cons up a yet another new vector of arguments | |
1763 by explicitly supplying nil's for optional values */ | |
1764 funcall_args = (Lisp_Object *) alloca ((1 + XSUBR (fun)->max_args) | |
1765 * sizeof (Lisp_Object)); | |
1766 for (i = numargs; i < XSUBR (fun)->max_args;) | |
1767 funcall_args[++i] = Qnil; | |
323 | 1768 GCPRO1 (*funcall_args); |
1769 gcpro1.nvars = 1 + XSUBR (fun)->max_args; | |
272 | 1770 } |
1771 } | |
1772 funcall: | |
1773 /* We add 1 to numargs because funcall_args includes the | |
1774 function itself as well as its arguments. */ | |
1775 if (!funcall_args) | |
323 | 1776 { |
1777 funcall_args = (Lisp_Object *) alloca ((1 + numargs) | |
1778 * sizeof (Lisp_Object)); | |
1779 GCPRO1 (*funcall_args); | |
1780 gcpro1.nvars = 1 + numargs; | |
1781 } | |
1782 | |
272 | 1783 bcopy (args, funcall_args, nargs * sizeof (Lisp_Object)); |
1784 /* Spread the last arg we got. Its first element goes in | |
1785 the slot that it used to occupy, hence this value of I. */ | |
1786 i = nargs - 1; | |
485 | 1787 while (!NILP (spread_arg)) |
272 | 1788 { |
1789 funcall_args [i++] = XCONS (spread_arg)->car; | |
1790 spread_arg = XCONS (spread_arg)->cdr; | |
1791 } | |
323 | 1792 |
1793 RETURN_UNGCPRO (Ffuncall (gcpro1.nvars, funcall_args)); | |
272 | 1794 } |
1795 | |
1796 /* Apply fn to arg */ | |
1797 Lisp_Object | |
1798 apply1 (fn, arg) | |
1799 Lisp_Object fn, arg; | |
1800 { | |
323 | 1801 struct gcpro gcpro1; |
1802 | |
1803 GCPRO1 (fn); | |
485 | 1804 if (NILP (arg)) |
323 | 1805 RETURN_UNGCPRO (Ffuncall (1, &fn)); |
1806 gcpro1.nvars = 2; | |
272 | 1807 #ifdef NO_ARG_ARRAY |
1808 { | |
1809 Lisp_Object args[2]; | |
1810 args[0] = fn; | |
1811 args[1] = arg; | |
323 | 1812 gcpro1.var = args; |
1813 RETURN_UNGCPRO (Fapply (2, args)); | |
272 | 1814 } |
1815 #else /* not NO_ARG_ARRAY */ | |
323 | 1816 RETURN_UNGCPRO (Fapply (2, &fn)); |
272 | 1817 #endif /* not NO_ARG_ARRAY */ |
1818 } | |
1819 | |
1820 /* Call function fn on no arguments */ | |
1821 Lisp_Object | |
1822 call0 (fn) | |
1823 Lisp_Object fn; | |
1824 { | |
323 | 1825 struct gcpro gcpro1; |
1826 | |
1827 GCPRO1 (fn); | |
1828 RETURN_UNGCPRO (Ffuncall (1, &fn)); | |
272 | 1829 } |
1830 | |
3703
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1831 /* Call function fn with 1 argument arg1 */ |
272 | 1832 /* ARGSUSED */ |
1833 Lisp_Object | |
3703
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1834 call1 (fn, arg1) |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1835 Lisp_Object fn, arg1; |
272 | 1836 { |
323 | 1837 struct gcpro gcpro1; |
272 | 1838 #ifdef NO_ARG_ARRAY |
323 | 1839 Lisp_Object args[2]; |
1840 | |
272 | 1841 args[0] = fn; |
3703
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1842 args[1] = arg1; |
323 | 1843 GCPRO1 (args[0]); |
1844 gcpro1.nvars = 2; | |
1845 RETURN_UNGCPRO (Ffuncall (2, args)); | |
272 | 1846 #else /* not NO_ARG_ARRAY */ |
323 | 1847 GCPRO1 (fn); |
1848 gcpro1.nvars = 2; | |
1849 RETURN_UNGCPRO (Ffuncall (2, &fn)); | |
272 | 1850 #endif /* not NO_ARG_ARRAY */ |
1851 } | |
1852 | |
3703
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1853 /* Call function fn with 2 arguments arg1, arg2 */ |
272 | 1854 /* ARGSUSED */ |
1855 Lisp_Object | |
3703
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1856 call2 (fn, arg1, arg2) |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1857 Lisp_Object fn, arg1, arg2; |
272 | 1858 { |
323 | 1859 struct gcpro gcpro1; |
272 | 1860 #ifdef NO_ARG_ARRAY |
1861 Lisp_Object args[3]; | |
1862 args[0] = fn; | |
3703
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1863 args[1] = arg1; |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1864 args[2] = arg2; |
323 | 1865 GCPRO1 (args[0]); |
1866 gcpro1.nvars = 3; | |
1867 RETURN_UNGCPRO (Ffuncall (3, args)); | |
272 | 1868 #else /* not NO_ARG_ARRAY */ |
323 | 1869 GCPRO1 (fn); |
1870 gcpro1.nvars = 3; | |
1871 RETURN_UNGCPRO (Ffuncall (3, &fn)); | |
272 | 1872 #endif /* not NO_ARG_ARRAY */ |
1873 } | |
1874 | |
3703
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1875 /* Call function fn with 3 arguments arg1, arg2, arg3 */ |
272 | 1876 /* ARGSUSED */ |
1877 Lisp_Object | |
3703
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1878 call3 (fn, arg1, arg2, arg3) |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1879 Lisp_Object fn, arg1, arg2, arg3; |
272 | 1880 { |
323 | 1881 struct gcpro gcpro1; |
272 | 1882 #ifdef NO_ARG_ARRAY |
1883 Lisp_Object args[4]; | |
1884 args[0] = fn; | |
3703
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1885 args[1] = arg1; |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1886 args[2] = arg2; |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1887 args[3] = arg3; |
323 | 1888 GCPRO1 (args[0]); |
1889 gcpro1.nvars = 4; | |
1890 RETURN_UNGCPRO (Ffuncall (4, args)); | |
272 | 1891 #else /* not NO_ARG_ARRAY */ |
323 | 1892 GCPRO1 (fn); |
1893 gcpro1.nvars = 4; | |
1894 RETURN_UNGCPRO (Ffuncall (4, &fn)); | |
272 | 1895 #endif /* not NO_ARG_ARRAY */ |
1896 } | |
1897 | |
3703
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1898 /* Call function fn with 4 arguments arg1, arg2, arg3, arg4 */ |
3598
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
parents:
2961
diff
changeset
|
1899 /* ARGSUSED */ |
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
parents:
2961
diff
changeset
|
1900 Lisp_Object |
3703
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1901 call4 (fn, arg1, arg2, arg3, arg4) |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1902 Lisp_Object fn, arg1, arg2, arg3, arg4; |
3598
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
parents:
2961
diff
changeset
|
1903 { |
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
parents:
2961
diff
changeset
|
1904 struct gcpro gcpro1; |
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
parents:
2961
diff
changeset
|
1905 #ifdef NO_ARG_ARRAY |
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
parents:
2961
diff
changeset
|
1906 Lisp_Object args[5]; |
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
parents:
2961
diff
changeset
|
1907 args[0] = fn; |
3703
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1908 args[1] = arg1; |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1909 args[2] = arg2; |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1910 args[3] = arg3; |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1911 args[4] = arg4; |
3598
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
parents:
2961
diff
changeset
|
1912 GCPRO1 (args[0]); |
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
parents:
2961
diff
changeset
|
1913 gcpro1.nvars = 5; |
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
parents:
2961
diff
changeset
|
1914 RETURN_UNGCPRO (Ffuncall (5, args)); |
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
parents:
2961
diff
changeset
|
1915 #else /* not NO_ARG_ARRAY */ |
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
parents:
2961
diff
changeset
|
1916 GCPRO1 (fn); |
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
parents:
2961
diff
changeset
|
1917 gcpro1.nvars = 5; |
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
parents:
2961
diff
changeset
|
1918 RETURN_UNGCPRO (Ffuncall (5, &fn)); |
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
parents:
2961
diff
changeset
|
1919 #endif /* not NO_ARG_ARRAY */ |
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
parents:
2961
diff
changeset
|
1920 } |
3c4b5489d2b4
* fileio.c (Frename_file): Pass all arguments to the file name handler.
Jim Blandy <jimb@redhat.com>
parents:
2961
diff
changeset
|
1921 |
3703
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1922 /* Call function fn with 5 arguments arg1, arg2, arg3, arg4, arg5 */ |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1923 /* ARGSUSED */ |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1924 Lisp_Object |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1925 call5 (fn, arg1, arg2, arg3, arg4, arg5) |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1926 Lisp_Object fn, arg1, arg2, arg3, arg4, arg5; |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1927 { |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1928 struct gcpro gcpro1; |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1929 #ifdef NO_ARG_ARRAY |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1930 Lisp_Object args[6]; |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1931 args[0] = fn; |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1932 args[1] = arg1; |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1933 args[2] = arg2; |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1934 args[3] = arg3; |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1935 args[4] = arg4; |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1936 args[5] = arg5; |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1937 GCPRO1 (args[0]); |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1938 gcpro1.nvars = 6; |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1939 RETURN_UNGCPRO (Ffuncall (6, args)); |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1940 #else /* not NO_ARG_ARRAY */ |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1941 GCPRO1 (fn); |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1942 gcpro1.nvars = 6; |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1943 RETURN_UNGCPRO (Ffuncall (6, &fn)); |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1944 #endif /* not NO_ARG_ARRAY */ |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1945 } |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1946 |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1947 /* Call function fn with 6 arguments arg1, arg2, arg3, arg4, arg5, arg6 */ |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1948 /* ARGSUSED */ |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1949 Lisp_Object |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1950 call6 (fn, arg1, arg2, arg3, arg4, arg5, arg6) |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1951 Lisp_Object fn, arg1, arg2, arg3, arg4, arg5, arg6; |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1952 { |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1953 struct gcpro gcpro1; |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1954 #ifdef NO_ARG_ARRAY |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1955 Lisp_Object args[7]; |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1956 args[0] = fn; |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1957 args[1] = arg1; |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1958 args[2] = arg2; |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1959 args[3] = arg3; |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1960 args[4] = arg4; |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1961 args[5] = arg5; |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1962 args[6] = arg6; |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1963 GCPRO1 (args[0]); |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1964 gcpro1.nvars = 7; |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1965 RETURN_UNGCPRO (Ffuncall (7, args)); |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1966 #else /* not NO_ARG_ARRAY */ |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1967 GCPRO1 (fn); |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1968 gcpro1.nvars = 7; |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1969 RETURN_UNGCPRO (Ffuncall (7, &fn)); |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1970 #endif /* not NO_ARG_ARRAY */ |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1971 } |
6930e8f81c88
(call5, call6): New functions.
Richard M. Stallman <rms@gnu.org>
parents:
3598
diff
changeset
|
1972 |
272 | 1973 DEFUN ("funcall", Ffuncall, Sfuncall, 1, MANY, 0, |
1974 "Call first argument as a function, passing remaining arguments to it.\n\ | |
1975 Thus, (funcall 'cons 'x 'y) returns (x . y).") | |
1976 (nargs, args) | |
1977 int nargs; | |
1978 Lisp_Object *args; | |
1979 { | |
1980 Lisp_Object fun; | |
1981 Lisp_Object funcar; | |
1982 int numargs = nargs - 1; | |
1983 Lisp_Object lisp_numargs; | |
1984 Lisp_Object val; | |
1985 struct backtrace backtrace; | |
1986 register Lisp_Object *internal_args; | |
1987 register int i; | |
1988 | |
1989 QUIT; | |
1990 if (consing_since_gc > gc_cons_threshold) | |
323 | 1991 Fgarbage_collect (); |
272 | 1992 |
1993 if (++lisp_eval_depth > max_lisp_eval_depth) | |
1994 { | |
1995 if (max_lisp_eval_depth < 100) | |
1996 max_lisp_eval_depth = 100; | |
1997 if (lisp_eval_depth > max_lisp_eval_depth) | |
1998 error ("Lisp nesting exceeds max-lisp-eval-depth"); | |
1999 } | |
2000 | |
2001 backtrace.next = backtrace_list; | |
2002 backtrace_list = &backtrace; | |
2003 backtrace.function = &args[0]; | |
2004 backtrace.args = &args[1]; | |
2005 backtrace.nargs = nargs - 1; | |
2006 backtrace.evalargs = 0; | |
2007 backtrace.debug_on_exit = 0; | |
2008 | |
2009 if (debug_on_next_call) | |
2010 do_debug_on_call (Qlambda); | |
2011 | |
2012 retry: | |
2013 | |
2014 fun = args[0]; | |
648 | 2015 |
2016 fun = Findirect_function (fun); | |
272 | 2017 |
2018 if (XTYPE (fun) == Lisp_Subr) | |
2019 { | |
2020 if (numargs < XSUBR (fun)->min_args | |
2021 || (XSUBR (fun)->max_args >= 0 && XSUBR (fun)->max_args < numargs)) | |
2022 { | |
2023 XFASTINT (lisp_numargs) = numargs; | |
2024 return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (lisp_numargs, Qnil))); | |
2025 } | |
2026 | |
2027 if (XSUBR (fun)->max_args == UNEVALLED) | |
2028 return Fsignal (Qinvalid_function, Fcons (fun, Qnil)); | |
2029 | |
2030 if (XSUBR (fun)->max_args == MANY) | |
2031 { | |
2032 val = (*XSUBR (fun)->function) (numargs, args + 1); | |
2033 goto done; | |
2034 } | |
2035 | |
2036 if (XSUBR (fun)->max_args > numargs) | |
2037 { | |
2038 internal_args = (Lisp_Object *) alloca (XSUBR (fun)->max_args * sizeof (Lisp_Object)); | |
2039 bcopy (args + 1, internal_args, numargs * sizeof (Lisp_Object)); | |
2040 for (i = numargs; i < XSUBR (fun)->max_args; i++) | |
2041 internal_args[i] = Qnil; | |
2042 } | |
2043 else | |
2044 internal_args = args + 1; | |
2045 switch (XSUBR (fun)->max_args) | |
2046 { | |
2047 case 0: | |
2048 val = (*XSUBR (fun)->function) (); | |
2049 goto done; | |
2050 case 1: | |
2051 val = (*XSUBR (fun)->function) (internal_args[0]); | |
2052 goto done; | |
2053 case 2: | |
2054 val = (*XSUBR (fun)->function) (internal_args[0], | |
2055 internal_args[1]); | |
2056 goto done; | |
2057 case 3: | |
2058 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1], | |
2059 internal_args[2]); | |
2060 goto done; | |
2061 case 4: | |
2062 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1], | |
2063 internal_args[2], | |
2064 internal_args[3]); | |
2065 goto done; | |
2066 case 5: | |
2067 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1], | |
2068 internal_args[2], internal_args[3], | |
2069 internal_args[4]); | |
2070 goto done; | |
2071 case 6: | |
2072 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1], | |
2073 internal_args[2], internal_args[3], | |
2074 internal_args[4], internal_args[5]); | |
2075 goto done; | |
863
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
753
diff
changeset
|
2076 case 7: |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
753
diff
changeset
|
2077 val = (*XSUBR (fun)->function) (internal_args[0], internal_args[1], |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
753
diff
changeset
|
2078 internal_args[2], internal_args[3], |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
753
diff
changeset
|
2079 internal_args[4], internal_args[5], |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
753
diff
changeset
|
2080 internal_args[6]); |
427299469901
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
753
diff
changeset
|
2081 goto done; |
272 | 2082 |
2083 default: | |
573 | 2084 |
2085 /* If a subr takes more than 6 arguments without using MANY | |
2086 or UNEVALLED, we need to extend this function to support it. | |
2087 Until this is done, there is no way to call the function. */ | |
2088 abort (); | |
272 | 2089 } |
2090 } | |
2091 if (XTYPE (fun) == Lisp_Compiled) | |
2092 val = funcall_lambda (fun, numargs, args + 1); | |
2093 else | |
2094 { | |
2095 if (!CONSP (fun)) | |
2096 return Fsignal (Qinvalid_function, Fcons (fun, Qnil)); | |
2097 funcar = Fcar (fun); | |
2098 if (XTYPE (funcar) != Lisp_Symbol) | |
2099 return Fsignal (Qinvalid_function, Fcons (fun, Qnil)); | |
2100 if (EQ (funcar, Qlambda)) | |
2101 val = funcall_lambda (fun, numargs, args + 1); | |
2102 else if (EQ (funcar, Qmocklisp)) | |
2103 val = ml_apply (fun, Flist (numargs, args + 1)); | |
2104 else if (EQ (funcar, Qautoload)) | |
2105 { | |
2106 do_autoload (fun, args[0]); | |
2107 goto retry; | |
2108 } | |
2109 else | |
2110 return Fsignal (Qinvalid_function, Fcons (fun, Qnil)); | |
2111 } | |
2112 done: | |
2113 lisp_eval_depth--; | |
2114 if (backtrace.debug_on_exit) | |
2115 val = call_debugger (Fcons (Qexit, Fcons (val, Qnil))); | |
2116 backtrace_list = backtrace.next; | |
2117 return val; | |
2118 } | |
2119 | |
2120 Lisp_Object | |
2121 apply_lambda (fun, args, eval_flag) | |
2122 Lisp_Object fun, args; | |
2123 int eval_flag; | |
2124 { | |
2125 Lisp_Object args_left; | |
2126 Lisp_Object numargs; | |
2127 register Lisp_Object *arg_vector; | |
2128 struct gcpro gcpro1, gcpro2, gcpro3; | |
2129 register int i; | |
2130 register Lisp_Object tem; | |
2131 | |
2132 numargs = Flength (args); | |
2133 arg_vector = (Lisp_Object *) alloca (XINT (numargs) * sizeof (Lisp_Object)); | |
2134 args_left = args; | |
2135 | |
2136 GCPRO3 (*arg_vector, args_left, fun); | |
2137 gcpro1.nvars = 0; | |
2138 | |
2139 for (i = 0; i < XINT (numargs);) | |
2140 { | |
2141 tem = Fcar (args_left), args_left = Fcdr (args_left); | |
2142 if (eval_flag) tem = Feval (tem); | |
2143 arg_vector[i++] = tem; | |
2144 gcpro1.nvars = i; | |
2145 } | |
2146 | |
2147 UNGCPRO; | |
2148 | |
2149 if (eval_flag) | |
2150 { | |
2151 backtrace_list->args = arg_vector; | |
2152 backtrace_list->nargs = i; | |
2153 } | |
2154 backtrace_list->evalargs = 0; | |
2155 tem = funcall_lambda (fun, XINT (numargs), arg_vector); | |
2156 | |
2157 /* Do the debug-on-exit now, while arg_vector still exists. */ | |
2158 if (backtrace_list->debug_on_exit) | |
2159 tem = call_debugger (Fcons (Qexit, Fcons (tem, Qnil))); | |
2160 /* Don't do it again when we return to eval. */ | |
2161 backtrace_list->debug_on_exit = 0; | |
2162 return tem; | |
2163 } | |
2164 | |
2165 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR | |
2166 and return the result of evaluation. | |
2167 FUN must be either a lambda-expression or a compiled-code object. */ | |
2168 | |
2169 Lisp_Object | |
2170 funcall_lambda (fun, nargs, arg_vector) | |
2171 Lisp_Object fun; | |
2172 int nargs; | |
2173 register Lisp_Object *arg_vector; | |
2174 { | |
2175 Lisp_Object val, tem; | |
2176 register Lisp_Object syms_left; | |
2177 Lisp_Object numargs; | |
2178 register Lisp_Object next; | |
2179 int count = specpdl_ptr - specpdl; | |
2180 register int i; | |
2181 int optional = 0, rest = 0; | |
2182 | |
2183 specbind (Qmocklisp_arguments, Qt); /* t means NOT mocklisp! */ | |
2184 | |
2185 XFASTINT (numargs) = nargs; | |
2186 | |
2187 if (XTYPE (fun) == Lisp_Cons) | |
2188 syms_left = Fcar (Fcdr (fun)); | |
2189 else if (XTYPE (fun) == Lisp_Compiled) | |
2190 syms_left = XVECTOR (fun)->contents[COMPILED_ARGLIST]; | |
2191 else abort (); | |
2192 | |
2193 i = 0; | |
485 | 2194 for (; !NILP (syms_left); syms_left = Fcdr (syms_left)) |
272 | 2195 { |
2196 QUIT; | |
2197 next = Fcar (syms_left); | |
431 | 2198 while (XTYPE (next) != Lisp_Symbol) |
2199 next = Fsignal (Qinvalid_function, Fcons (fun, Qnil)); | |
272 | 2200 if (EQ (next, Qand_rest)) |
2201 rest = 1; | |
2202 else if (EQ (next, Qand_optional)) | |
2203 optional = 1; | |
2204 else if (rest) | |
2205 { | |
431 | 2206 specbind (next, Flist (nargs - i, &arg_vector[i])); |
272 | 2207 i = nargs; |
2208 } | |
2209 else if (i < nargs) | |
2210 { | |
2211 tem = arg_vector[i++]; | |
2212 specbind (next, tem); | |
2213 } | |
2214 else if (!optional) | |
2215 return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (numargs, Qnil))); | |
2216 else | |
2217 specbind (next, Qnil); | |
2218 } | |
2219 | |
2220 if (i < nargs) | |
2221 return Fsignal (Qwrong_number_of_arguments, Fcons (fun, Fcons (numargs, Qnil))); | |
2222 | |
2223 if (XTYPE (fun) == Lisp_Cons) | |
2224 val = Fprogn (Fcdr (Fcdr (fun))); | |
2225 else | |
2226 val = Fbyte_code (XVECTOR (fun)->contents[COMPILED_BYTECODE], | |
2227 XVECTOR (fun)->contents[COMPILED_CONSTANTS], | |
2228 XVECTOR (fun)->contents[COMPILED_STACK_DEPTH]); | |
2229 return unbind_to (count, val); | |
2230 } | |
2231 | |
2232 void | |
2233 grow_specpdl () | |
2234 { | |
2235 register int count = specpdl_ptr - specpdl; | |
2236 if (specpdl_size >= max_specpdl_size) | |
2237 { | |
2238 if (max_specpdl_size < 400) | |
2239 max_specpdl_size = 400; | |
2240 if (specpdl_size >= max_specpdl_size) | |
2241 { | |
1452
ed79bb8047e8
(grow_specpdl): Increase max_specpdl_size before Fsignal.
Richard M. Stallman <rms@gnu.org>
parents:
1199
diff
changeset
|
2242 if (!NILP (Vdebug_on_error)) |
ed79bb8047e8
(grow_specpdl): Increase max_specpdl_size before Fsignal.
Richard M. Stallman <rms@gnu.org>
parents:
1199
diff
changeset
|
2243 /* Leave room for some specpdl in the debugger. */ |
ed79bb8047e8
(grow_specpdl): Increase max_specpdl_size before Fsignal.
Richard M. Stallman <rms@gnu.org>
parents:
1199
diff
changeset
|
2244 max_specpdl_size = specpdl_size + 100; |
272 | 2245 Fsignal (Qerror, |
2246 Fcons (build_string ("Variable binding depth exceeds max-specpdl-size"), Qnil)); | |
2247 } | |
2248 } | |
2249 specpdl_size *= 2; | |
2250 if (specpdl_size > max_specpdl_size) | |
2251 specpdl_size = max_specpdl_size; | |
2252 specpdl = (struct specbinding *) xrealloc (specpdl, specpdl_size * sizeof (struct specbinding)); | |
2253 specpdl_ptr = specpdl + count; | |
2254 } | |
2255 | |
2256 void | |
2257 specbind (symbol, value) | |
2258 Lisp_Object symbol, value; | |
2259 { | |
2260 extern void store_symval_forwarding (); /* in eval.c */ | |
2261 Lisp_Object ovalue; | |
2262 | |
431 | 2263 CHECK_SYMBOL (symbol, 0); |
2264 | |
272 | 2265 if (specpdl_ptr == specpdl + specpdl_size) |
2266 grow_specpdl (); | |
2267 specpdl_ptr->symbol = symbol; | |
2268 specpdl_ptr->func = 0; | |
6826
903d03ddf99c
(specbind): Use find_symbol_value.
Richard M. Stallman <rms@gnu.org>
parents:
6803
diff
changeset
|
2269 specpdl_ptr->old_value = ovalue = find_symbol_value (symbol); |
272 | 2270 specpdl_ptr++; |
2271 if (XTYPE (ovalue) == Lisp_Buffer_Objfwd) | |
2272 store_symval_forwarding (symbol, ovalue, value); | |
2273 else | |
2274 Fset (symbol, value); | |
2275 } | |
2276 | |
2277 void | |
2278 record_unwind_protect (function, arg) | |
2279 Lisp_Object (*function)(); | |
2280 Lisp_Object arg; | |
2281 { | |
2282 if (specpdl_ptr == specpdl + specpdl_size) | |
2283 grow_specpdl (); | |
2284 specpdl_ptr->func = function; | |
2285 specpdl_ptr->symbol = Qnil; | |
2286 specpdl_ptr->old_value = arg; | |
2287 specpdl_ptr++; | |
2288 } | |
2289 | |
2290 Lisp_Object | |
2291 unbind_to (count, value) | |
2292 int count; | |
2293 Lisp_Object value; | |
2294 { | |
485 | 2295 int quitf = !NILP (Vquit_flag); |
272 | 2296 struct gcpro gcpro1; |
2297 | |
2298 GCPRO1 (value); | |
2299 | |
2300 Vquit_flag = Qnil; | |
2301 | |
2302 while (specpdl_ptr != specpdl + count) | |
2303 { | |
2304 --specpdl_ptr; | |
2305 if (specpdl_ptr->func != 0) | |
2306 (*specpdl_ptr->func) (specpdl_ptr->old_value); | |
2307 /* Note that a "binding" of nil is really an unwind protect, | |
2308 so in that case the "old value" is a list of forms to evaluate. */ | |
485 | 2309 else if (NILP (specpdl_ptr->symbol)) |
272 | 2310 Fprogn (specpdl_ptr->old_value); |
2311 else | |
2312 Fset (specpdl_ptr->symbol, specpdl_ptr->old_value); | |
2313 } | |
485 | 2314 if (NILP (Vquit_flag) && quitf) Vquit_flag = Qt; |
272 | 2315 |
2316 UNGCPRO; | |
2317 | |
2318 return value; | |
2319 } | |
2320 | |
2321 #if 0 | |
2322 | |
2323 /* Get the value of symbol's global binding, even if that binding | |
2324 is not now dynamically visible. */ | |
2325 | |
2326 Lisp_Object | |
2327 top_level_value (symbol) | |
2328 Lisp_Object symbol; | |
2329 { | |
2330 register struct specbinding *ptr = specpdl; | |
2331 | |
2332 CHECK_SYMBOL (symbol, 0); | |
2333 for (; ptr != specpdl_ptr; ptr++) | |
2334 { | |
2335 if (EQ (ptr->symbol, symbol)) | |
2336 return ptr->old_value; | |
2337 } | |
2338 return Fsymbol_value (symbol); | |
2339 } | |
2340 | |
2341 Lisp_Object | |
2342 top_level_set (symbol, newval) | |
2343 Lisp_Object symbol, newval; | |
2344 { | |
2345 register struct specbinding *ptr = specpdl; | |
2346 | |
2347 CHECK_SYMBOL (symbol, 0); | |
2348 for (; ptr != specpdl_ptr; ptr++) | |
2349 { | |
2350 if (EQ (ptr->symbol, symbol)) | |
2351 { | |
2352 ptr->old_value = newval; | |
2353 return newval; | |
2354 } | |
2355 } | |
2356 return Fset (symbol, newval); | |
2357 } | |
2358 | |
2359 #endif /* 0 */ | |
2360 | |
2361 DEFUN ("backtrace-debug", Fbacktrace_debug, Sbacktrace_debug, 2, 2, 0, | |
2362 "Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.\n\ | |
2363 The debugger is entered when that frame exits, if the flag is non-nil.") | |
2364 (level, flag) | |
2365 Lisp_Object level, flag; | |
2366 { | |
2367 register struct backtrace *backlist = backtrace_list; | |
2368 register int i; | |
2369 | |
2370 CHECK_NUMBER (level, 0); | |
2371 | |
2372 for (i = 0; backlist && i < XINT (level); i++) | |
2373 { | |
2374 backlist = backlist->next; | |
2375 } | |
2376 | |
2377 if (backlist) | |
485 | 2378 backlist->debug_on_exit = !NILP (flag); |
272 | 2379 |
2380 return flag; | |
2381 } | |
2382 | |
2383 DEFUN ("backtrace", Fbacktrace, Sbacktrace, 0, 0, "", | |
2384 "Print a trace of Lisp function calls currently active.\n\ | |
2385 Output stream used is value of `standard-output'.") | |
2386 () | |
2387 { | |
2388 register struct backtrace *backlist = backtrace_list; | |
2389 register int i; | |
2390 Lisp_Object tail; | |
2391 Lisp_Object tem; | |
2392 extern Lisp_Object Vprint_level; | |
2393 struct gcpro gcpro1; | |
2394 | |
2395 XFASTINT (Vprint_level) = 3; | |
2396 | |
2397 tail = Qnil; | |
2398 GCPRO1 (tail); | |
2399 | |
2400 while (backlist) | |
2401 { | |
2402 write_string (backlist->debug_on_exit ? "* " : " ", 2); | |
2403 if (backlist->nargs == UNEVALLED) | |
2404 { | |
2405 Fprin1 (Fcons (*backlist->function, *backlist->args), Qnil); | |
2406 } | |
2407 else | |
2408 { | |
2409 tem = *backlist->function; | |
2410 Fprin1 (tem, Qnil); /* This can QUIT */ | |
2411 write_string ("(", -1); | |
2412 if (backlist->nargs == MANY) | |
2413 { | |
2414 for (tail = *backlist->args, i = 0; | |
485 | 2415 !NILP (tail); |
272 | 2416 tail = Fcdr (tail), i++) |
2417 { | |
2418 if (i) write_string (" ", -1); | |
2419 Fprin1 (Fcar (tail), Qnil); | |
2420 } | |
2421 } | |
2422 else | |
2423 { | |
2424 for (i = 0; i < backlist->nargs; i++) | |
2425 { | |
2426 if (i) write_string (" ", -1); | |
2427 Fprin1 (backlist->args[i], Qnil); | |
2428 } | |
2429 } | |
2430 } | |
2431 write_string (")\n", -1); | |
2432 backlist = backlist->next; | |
2433 } | |
2434 | |
2435 Vprint_level = Qnil; | |
2436 UNGCPRO; | |
2437 return Qnil; | |
2438 } | |
2439 | |
2440 DEFUN ("backtrace-frame", Fbacktrace_frame, Sbacktrace_frame, 1, 1, "", | |
2441 "Return the function and arguments N frames up from current execution point.\n\ | |
2442 If that frame has not evaluated the arguments yet (or is a special form),\n\ | |
2443 the value is (nil FUNCTION ARG-FORMS...).\n\ | |
2444 If that frame has evaluated its arguments and called its function already,\n\ | |
2445 the value is (t FUNCTION ARG-VALUES...).\n\ | |
2446 A &rest arg is represented as the tail of the list ARG-VALUES.\n\ | |
2447 FUNCTION is whatever was supplied as car of evaluated list,\n\ | |
2448 or a lambda expression for macro calls.\n\ | |
2449 If N is more than the number of frames, the value is nil.") | |
2450 (nframes) | |
2451 Lisp_Object nframes; | |
2452 { | |
2453 register struct backtrace *backlist = backtrace_list; | |
2454 register int i; | |
2455 Lisp_Object tem; | |
2456 | |
2457 CHECK_NATNUM (nframes, 0); | |
2458 | |
2459 /* Find the frame requested. */ | |
2460 for (i = 0; i < XFASTINT (nframes); i++) | |
2461 backlist = backlist->next; | |
2462 | |
2463 if (!backlist) | |
2464 return Qnil; | |
2465 if (backlist->nargs == UNEVALLED) | |
2466 return Fcons (Qnil, Fcons (*backlist->function, *backlist->args)); | |
2467 else | |
2468 { | |
2469 if (backlist->nargs == MANY) | |
2470 tem = *backlist->args; | |
2471 else | |
2472 tem = Flist (backlist->nargs, backlist->args); | |
2473 | |
2474 return Fcons (Qt, Fcons (*backlist->function, tem)); | |
2475 } | |
2476 } | |
2477 | |
2478 syms_of_eval () | |
2479 { | |
2480 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size, | |
2481 "Limit on number of Lisp variable bindings & unwind-protects before error."); | |
2482 | |
2483 DEFVAR_INT ("max-lisp-eval-depth", &max_lisp_eval_depth, | |
2484 "Limit on depth in `eval', `apply' and `funcall' before error.\n\ | |
2485 This limit is to catch infinite recursions for you before they cause\n\ | |
2486 actual stack overflow in C, which would be fatal for Emacs.\n\ | |
2487 You can safely make it considerably larger than its default value,\n\ | |
2488 if that proves inconveniently small."); | |
2489 | |
2490 DEFVAR_LISP ("quit-flag", &Vquit_flag, | |
2491 "Non-nil causes `eval' to abort, unless `inhibit-quit' is non-nil.\n\ | |
2492 Typing C-G sets `quit-flag' non-nil, regardless of `inhibit-quit'."); | |
2493 Vquit_flag = Qnil; | |
2494 | |
2495 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit, | |
2496 "Non-nil inhibits C-g quitting from happening immediately.\n\ | |
2497 Note that `quit-flag' will still be set by typing C-g,\n\ | |
2498 so a quit will be signalled as soon as `inhibit-quit' is nil.\n\ | |
2499 To prevent this happening, set `quit-flag' to nil\n\ | |
2500 before making `inhibit-quit' nil."); | |
2501 Vinhibit_quit = Qnil; | |
2502 | |
381 | 2503 Qinhibit_quit = intern ("inhibit-quit"); |
2504 staticpro (&Qinhibit_quit); | |
2505 | |
272 | 2506 Qautoload = intern ("autoload"); |
2507 staticpro (&Qautoload); | |
2508 | |
2509 Qdebug_on_error = intern ("debug-on-error"); | |
2510 staticpro (&Qdebug_on_error); | |
2511 | |
2512 Qmacro = intern ("macro"); | |
2513 staticpro (&Qmacro); | |
2514 | |
2515 /* Note that the process handling also uses Qexit, but we don't want | |
2516 to staticpro it twice, so we just do it here. */ | |
2517 Qexit = intern ("exit"); | |
2518 staticpro (&Qexit); | |
2519 | |
2520 Qinteractive = intern ("interactive"); | |
2521 staticpro (&Qinteractive); | |
2522 | |
2523 Qcommandp = intern ("commandp"); | |
2524 staticpro (&Qcommandp); | |
2525 | |
2526 Qdefun = intern ("defun"); | |
2527 staticpro (&Qdefun); | |
2528 | |
2529 Qand_rest = intern ("&rest"); | |
2530 staticpro (&Qand_rest); | |
2531 | |
2532 Qand_optional = intern ("&optional"); | |
2533 staticpro (&Qand_optional); | |
2534 | |
684 | 2535 DEFVAR_LISP ("stack-trace-on-error", &Vstack_trace_on_error, |
272 | 2536 "*Non-nil means automatically display a backtrace buffer\n\ |
684 | 2537 after any error that is handled by the editor command loop.\n\ |
2538 If the value is a list, an error only means to display a backtrace\n\ | |
2539 if one of its condition symbols appears in the list."); | |
2540 Vstack_trace_on_error = Qnil; | |
272 | 2541 |
684 | 2542 DEFVAR_LISP ("debug-on-error", &Vdebug_on_error, |
272 | 2543 "*Non-nil means enter debugger if an error is signaled.\n\ |
2544 Does not apply to errors handled by `condition-case'.\n\ | |
684 | 2545 If the value is a list, an error only means to enter the debugger\n\ |
2546 if one of its condition symbols appears in the list.\n\ | |
272 | 2547 See also variable `debug-on-quit'."); |
684 | 2548 Vdebug_on_error = Qnil; |
272 | 2549 |
2550 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit, | |
2551 "*Non-nil means enter debugger if quit is signaled (C-G, for example).\n\ | |
940 | 2552 Does not apply if quit is handled by a `condition-case'."); |
272 | 2553 debug_on_quit = 0; |
2554 | |
2555 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call, | |
2556 "Non-nil means enter debugger before next `eval', `apply' or `funcall'."); | |
2557 | |
2558 DEFVAR_LISP ("debugger", &Vdebugger, | |
2559 "Function to call to invoke debugger.\n\ | |
2560 If due to frame exit, args are `exit' and the value being returned;\n\ | |
2561 this function's value will be returned instead of that.\n\ | |
2562 If due to error, args are `error' and a list of the args to `signal'.\n\ | |
2563 If due to `apply' or `funcall' entry, one arg, `lambda'.\n\ | |
2564 If due to `eval' entry, one arg, t."); | |
2565 Vdebugger = Qnil; | |
2566 | |
2567 Qmocklisp_arguments = intern ("mocklisp-arguments"); | |
2568 staticpro (&Qmocklisp_arguments); | |
2569 DEFVAR_LISP ("mocklisp-arguments", &Vmocklisp_arguments, | |
2570 "While in a mocklisp function, the list of its unevaluated args."); | |
2571 Vmocklisp_arguments = Qt; | |
2572 | |
2573 DEFVAR_LISP ("run-hooks", &Vrun_hooks, | |
2574 "Set to the function `run-hooks', if that function has been defined.\n\ | |
2575 Otherwise, nil (in a bare Emacs without preloaded Lisp code)."); | |
2576 Vrun_hooks = Qnil; | |
2577 | |
2578 staticpro (&Vautoload_queue); | |
2579 Vautoload_queue = Qnil; | |
2580 | |
2581 defsubr (&Sor); | |
2582 defsubr (&Sand); | |
2583 defsubr (&Sif); | |
2584 defsubr (&Scond); | |
2585 defsubr (&Sprogn); | |
2586 defsubr (&Sprog1); | |
2587 defsubr (&Sprog2); | |
2588 defsubr (&Ssetq); | |
2589 defsubr (&Squote); | |
2590 defsubr (&Sfunction); | |
2591 defsubr (&Sdefun); | |
2592 defsubr (&Sdefmacro); | |
2593 defsubr (&Sdefvar); | |
2594 defsubr (&Sdefconst); | |
2595 defsubr (&Suser_variable_p); | |
2596 defsubr (&Slet); | |
2597 defsubr (&SletX); | |
2598 defsubr (&Swhile); | |
2599 defsubr (&Smacroexpand); | |
2600 defsubr (&Scatch); | |
2601 defsubr (&Sthrow); | |
2602 defsubr (&Sunwind_protect); | |
2603 defsubr (&Scondition_case); | |
2604 defsubr (&Ssignal); | |
2605 defsubr (&Sinteractive_p); | |
2606 defsubr (&Scommandp); | |
2607 defsubr (&Sautoload); | |
2608 defsubr (&Seval); | |
2609 defsubr (&Sapply); | |
2610 defsubr (&Sfuncall); | |
2611 defsubr (&Sbacktrace_debug); | |
2612 defsubr (&Sbacktrace); | |
2613 defsubr (&Sbacktrace_frame); | |
2614 } |