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