Mercurial > hg > xemacs-beta
annotate src/eval.c @ 4686:cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
lisp/ChangeLog addition:
2009-08-31 Aidan Kehoe <kehoea@parhasard.net>
* byte-optimize.el (byte-optimize-form-code-walker):
Be careful about discarding multiple values when optimising
#'prog1 calls.
(byte-optimize-or):
Preserve any trailing nil, as this is a supported way to
explicitly discard multiple values.
(byte-optimize-cond-1):
Discard multiple values with a singleton followed by no more
clauses.
* bytecomp.el (progn):
(prog1):
(prog2):
Be careful about discarding multiple values in the byte-hunk
handler of these three forms.
* bytecomp.el (byte-compile-prog1, byte-compile-prog2):
Don't call #'values explicitly, use `(or ,(pop form) nil) instead,
since that compiles to bytecode, not a funcall.
* bytecomp.el (byte-compile-values):
With one non-const argument, byte-compile to `(or ,(second form)
nil), not an explicit #'values call.
* bytecomp.el (byte-compile-insert-header):
Be nicer in the error message to emacs versions that don't
understand our bytecode.
src/ChangeLog addition:
2009-08-31 Aidan Kehoe <kehoea@parhasard.net>
* eval.c (For, Fand):
Don't declare val as REGISTER in these functions, for some reason
it breaks the non-DEBUG union build. These functions are only
called from interpreted code, the performance implication doesn't
matter. Thank you Robert Delius Royar!
* eval.c (Fmultiple_value_list_internal):
Error on too many arguments.
tests/ChangeLog addition:
2009-08-31 Aidan Kehoe <kehoea@parhasard.net>
* automated/lisp-tests.el (Assert-rounding):
Remove an overly-verbose failure message here.
Correct a couple of tests which were buggy in themselves. Add
three new tests, checking the behaviour of #'or and #'and when
passed zero arguments, and a Known-Bug-Expect-Failure call
involving letf and values. (The bug predates the C-level
multiple-value implementation.)
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Sun, 06 Sep 2009 19:36:02 +0100 |
parents | 8f1ee2d15784 |
children | 80cd90837ac5 |
rev | line source |
---|---|
428 | 1 /* Evaluator for XEmacs Lisp interpreter. |
2 Copyright (C) 1985-1987, 1992-1994 Free Software Foundation, Inc. | |
3 Copyright (C) 1995 Sun Microsystems, Inc. | |
2421 | 4 Copyright (C) 2000, 2001, 2002, 2003, 2004 Ben Wing. |
428 | 5 |
6 This file is part of XEmacs. | |
7 | |
8 XEmacs is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
10 Free Software Foundation; either version 2, or (at your option) any | |
11 later version. | |
12 | |
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with XEmacs; see the file COPYING. If not, write to | |
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
21 Boston, MA 02111-1307, USA. */ | |
22 | |
23 /* Synched up with: FSF 19.30 (except for Fsignal), Mule 2.0. */ | |
24 | |
853 | 25 /* Authorship: |
26 | |
27 Based on code from pre-release FSF 19, c. 1991. | |
28 Some work by Richard Mlynarik long ago (c. 1993?) -- | |
29 added call-with-condition-handler; synch. up to released FSF 19.7 | |
30 for lemacs 19.8. some signal changes. | |
31 Various work by Ben Wing, 1995-1996: | |
32 added all stuff dealing with trapping errors, suspended-errors, etc. | |
33 added most Fsignal front ends. | |
34 added warning code. | |
35 reworked the Fsignal code and synched the rest up to FSF 19.30. | |
36 Some changes by Martin Buchholz c. 1999? | |
37 e.g. PRIMITIVE_FUNCALL macros. | |
38 New call_trapping_problems code and large comments below | |
39 by Ben Wing, Mar-Apr 2000. | |
40 */ | |
41 | |
42 /* This file has been Mule-ized. */ | |
43 | |
44 /* What is in this file? | |
45 | |
46 This file contains the engine for the ELisp interpreter in XEmacs. | |
47 The engine does the actual work of implementing function calls, | |
48 form evaluation, non-local exits (catch, throw, signal, | |
49 condition-case, call-with-condition-handler), unwind-protects, | |
50 dynamic bindings, let constructs, backtraces, etc. You might say | |
51 that this module is the very heart of XEmacs, and everything else | |
52 in XEmacs is merely an auxiliary module implementing some specific | |
53 functionality that may be called from the heart at an appropriate | |
54 time. | |
55 | |
56 The only exception is the alloc.c module, which implements the | |
57 framework upon which this module (eval.c) works. alloc.c works | |
58 with creating the actual Lisp objects themselves and garbage | |
1960 | 59 collecting them as necessary, presenting a nice, high-level |
853 | 60 interface for object creation, deletion, access, and modification. |
61 | |
62 The only other exception that could be cited is the event-handling | |
63 module in event-stream.c. From its perspective, it is also the | |
64 heart of XEmacs, and controls exactly what gets done at what time. | |
65 From its perspective, eval.c is merely one of the auxiliary modules | |
66 out there that can be invoked by event-stream.c. | |
67 | |
68 Although the event-stream-centric view is a convenient fiction that | |
69 makes sense particularly from the user's perspective and from the | |
70 perspective of time, the engine-centric view is actually closest to | |
71 the truth, because anywhere within the event-stream module, you are | |
72 still somewhere in a Lisp backtrace, and event-loops are begun by | |
73 functions such as `command-loop-1', a Lisp function. | |
74 | |
75 As the Lisp engine is doing its thing, it maintains the state of | |
1960 | 76 the engine primarily in five list-like items, which are: |
853 | 77 |
78 -- the backtrace list | |
79 -- the catchtag list | |
80 -- the condition-handler list | |
81 -- the specbind list | |
82 -- the GCPRO list. | |
83 | |
84 These are described in detail in the next comment. | |
85 | |
86 --ben | |
87 */ | |
88 | |
89 /* Note that there are five separate lists used to maintain state in | |
90 the evaluator. All of them conceptually are stacks (last-in, | |
91 first-out). All non-local exits happen ultimately through the | |
92 catch/throw mechanism, which uses one of the five lists (the | |
93 catchtag list) and records the current state of the others in each | |
94 frame of the list (some other information is recorded and restored | |
95 as well, such as the current eval depth), so that all the state of | |
96 the evaluator is restored properly when a non-local exit occurs. | |
97 (Note that the current state of the condition-handler list is not | |
98 recorded in the catchtag list. Instead, when a condition-case or | |
99 call-with-condition-handler is set up, it installs an | |
100 unwind-protect on the specbind list to restore the appropriate | |
101 setting for the condition-handler list. During the course of | |
102 handling the non-local exit, all entries on the specbind list that | |
103 are past the location stored in the catch frame are "unwound" | |
104 (i.e. variable bindings are restored and unwind-protects are | |
105 executed), so the condition-handler list gets reset properly. | |
106 | |
107 The five lists are | |
108 | |
109 1. The backtrace list, which is chained through `struct backtrace's | |
110 declared in the stack frames of various primitives, and keeps | |
111 track of all Lisp function call entries and exits. | |
112 2. The catchtag list, which is chained through `struct catchtag's | |
113 declared in the stack frames of internal_catch and condition_case_1, | |
114 and keeps track of information needed to reset the internal state | |
115 of the evaluator to the state that was current when the catch or | |
116 condition-case were established, in the event of a non-local exit. | |
117 3. The condition-handler list, which is a simple Lisp list with new | |
118 entries consed onto the front of the list. It records condition-cases | |
119 and call-with-condition-handlers established either from C or from | |
120 Lisp. Unlike with the other lists (but similar to everything else | |
121 of a similar nature in the rest of the C and Lisp code), it takes care | |
122 of restoring itself appropriately in the event of a non-local exit | |
123 through the use of the unwind-protect mechanism. | |
124 4. The specbind list, which is a contiguous array of `struct specbinding's, | |
125 expanded as necessary using realloc(). It holds dynamic variable | |
126 bindings (the only kind we currently have in ELisp) and unwind-protects. | |
127 5. The GCPRO list, which is chained through `struct gcpro's declared in | |
128 the stack frames of any functions that need to GC-protect Lisp_Objects | |
129 declared on the stack. This is one of the most fragile areas of the | |
130 entire scheme -- you must not forget to UNGCPRO at the end of your | |
131 function, you must make sure you GCPRO in many circumstances you don't | |
132 think you have to, etc. See the internals manual for more information | |
133 about this. | |
134 | |
135 --ben | |
136 */ | |
137 | |
428 | 138 #include <config.h> |
139 #include "lisp.h" | |
140 | |
141 #include "commands.h" | |
142 #include "backtrace.h" | |
143 #include "bytecode.h" | |
144 #include "buffer.h" | |
872 | 145 #include "console-impl.h" |
853 | 146 #include "device.h" |
147 #include "frame.h" | |
148 #include "lstream.h" | |
428 | 149 #include "opaque.h" |
1292 | 150 #include "profile.h" |
853 | 151 #include "window.h" |
428 | 152 |
153 struct backtrace *backtrace_list; | |
154 | |
155 /* Macros for calling subrs with an argument list whose length is only | |
156 known at runtime. See EXFUN and DEFUN for similar hackery. */ | |
157 | |
158 #define AV_0(av) | |
159 #define AV_1(av) av[0] | |
160 #define AV_2(av) AV_1(av), av[1] | |
161 #define AV_3(av) AV_2(av), av[2] | |
162 #define AV_4(av) AV_3(av), av[3] | |
163 #define AV_5(av) AV_4(av), av[4] | |
164 #define AV_6(av) AV_5(av), av[5] | |
165 #define AV_7(av) AV_6(av), av[6] | |
166 #define AV_8(av) AV_7(av), av[7] | |
167 | |
168 #define PRIMITIVE_FUNCALL_1(fn, av, ac) \ | |
444 | 169 (((Lisp_Object (*)(EXFUN_##ac)) (fn)) (AV_##ac (av))) |
428 | 170 |
171 /* If subrs take more than 8 arguments, more cases need to be added | |
172 to this switch. (But wait - don't do it - if you really need | |
173 a SUBR with more than 8 arguments, use max_args == MANY. | |
853 | 174 Or better, considering using a property list as one of your args. |
428 | 175 See the DEFUN macro in lisp.h) */ |
176 #define PRIMITIVE_FUNCALL(rv, fn, av, ac) do { \ | |
177 void (*PF_fn)(void) = (void (*)(void)) fn; \ | |
178 Lisp_Object *PF_av = (av); \ | |
179 switch (ac) \ | |
180 { \ | |
436 | 181 default:rv = PRIMITIVE_FUNCALL_1(PF_fn, PF_av, 0); break; \ |
428 | 182 case 1: rv = PRIMITIVE_FUNCALL_1(PF_fn, PF_av, 1); break; \ |
183 case 2: rv = PRIMITIVE_FUNCALL_1(PF_fn, PF_av, 2); break; \ | |
184 case 3: rv = PRIMITIVE_FUNCALL_1(PF_fn, PF_av, 3); break; \ | |
185 case 4: rv = PRIMITIVE_FUNCALL_1(PF_fn, PF_av, 4); break; \ | |
186 case 5: rv = PRIMITIVE_FUNCALL_1(PF_fn, PF_av, 5); break; \ | |
187 case 6: rv = PRIMITIVE_FUNCALL_1(PF_fn, PF_av, 6); break; \ | |
188 case 7: rv = PRIMITIVE_FUNCALL_1(PF_fn, PF_av, 7); break; \ | |
189 case 8: rv = PRIMITIVE_FUNCALL_1(PF_fn, PF_av, 8); break; \ | |
190 } \ | |
191 } while (0) | |
192 | |
193 #define FUNCALL_SUBR(rv, subr, av, ac) \ | |
194 PRIMITIVE_FUNCALL (rv, subr_function (subr), av, ac); | |
195 | |
196 | |
197 /* This is the list of current catches (and also condition-cases). | |
853 | 198 This is a stack: the most recent catch is at the head of the list. |
199 The list is threaded through the stack frames of the C functions | |
200 that set up the catches; this is similar to the way the GCPRO list | |
201 is handled, but different from the condition-handler list (which is | |
202 a simple Lisp list) and the specbind stack, which is a contiguous | |
203 array of `struct specbinding's, grown (using realloc()) as | |
204 necessary. (Note that all four of these lists behave as a stacks.) | |
205 | |
3025 | 206 Catches are created by declaring a `struct catchtag' locally, |
853 | 207 filling the .TAG field in with the tag, and doing a setjmp() on |
208 .JMP. Fthrow() will store the value passed to it in .VAL and | |
209 longjmp() back to .JMP, back to the function that established the | |
210 catch. This will always be either internal_catch() (catches | |
211 established internally or through `catch') or condition_case_1 | |
212 (condition-cases established internally or through | |
213 `condition-case'). | |
428 | 214 |
215 The catchtag also records the current position in the | |
216 call stack (stored in BACKTRACE_LIST), the current position | |
217 in the specpdl stack (used for variable bindings and | |
218 unwind-protects), the value of LISP_EVAL_DEPTH, and the | |
219 current position in the GCPRO stack. All of these are | |
220 restored by Fthrow(). | |
853 | 221 */ |
428 | 222 |
223 struct catchtag *catchlist; | |
224 | |
853 | 225 /* A special tag that can be used internally from C code to catch |
226 every attempt to throw past this level. */ | |
227 Lisp_Object Vcatch_everything_tag; | |
228 | |
428 | 229 Lisp_Object Qautoload, Qmacro, Qexit; |
230 Lisp_Object Qinteractive, Qcommandp, Qdefun, Qprogn, Qvalues; | |
231 Lisp_Object Vquit_flag, Vinhibit_quit; | |
232 Lisp_Object Qand_rest, Qand_optional; | |
233 Lisp_Object Qdebug_on_error, Qstack_trace_on_error; | |
234 Lisp_Object Qdebug_on_signal, Qstack_trace_on_signal; | |
235 Lisp_Object Qdebugger; | |
236 Lisp_Object Qinhibit_quit; | |
887 | 237 Lisp_Object Qfinalize_list; |
428 | 238 Lisp_Object Qrun_hooks; |
239 Lisp_Object Qsetq; | |
240 Lisp_Object Qdisplay_warning; | |
241 Lisp_Object Vpending_warnings, Vpending_warnings_tail; | |
242 Lisp_Object Qif; | |
243 | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
244 Lisp_Object Qthrow; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
245 Lisp_Object Qobsolete_throw; |
4686
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
246 Lisp_Object Qmultiple_value_list_internal; |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
247 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
248 static int first_desired_multiple_value; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
249 /* Used outside this file, somewhat uncleanly, in the IGNORE_MULTIPLE_VALUES |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
250 macro: */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
251 int multiple_value_current_limit; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
252 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
253 Fixnum Vmultiple_values_limit; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
254 |
853 | 255 /* Flags specifying which operations are currently inhibited. */ |
256 int inhibit_flags; | |
257 | |
258 /* Buffers, frames, windows, devices, and consoles created since most | |
259 recent active | |
260 call_trapping_problems (INHIBIT_EXISTING_PERMANENT_DISPLAY_OBJECT_DELETION). | |
261 */ | |
262 Lisp_Object Vdeletable_permanent_display_objects; | |
263 | |
264 /* Buffers created since most recent active | |
265 call_trapping_problems (INHIBIT_EXISTING_BUFFER_TEXT_MODIFICATION). */ | |
266 Lisp_Object Vmodifiable_buffers; | |
793 | 267 |
268 /* Minimum level at which warnings are logged. Below this, they're ignored | |
269 entirely -- not even generated. */ | |
270 Lisp_Object Vlog_warning_minimum_level; | |
271 | |
428 | 272 /* Non-nil means record all fset's and provide's, to be undone |
273 if the file being autoloaded is not fully loaded. | |
274 They are recorded by being consed onto the front of Vautoload_queue: | |
275 (FUN . ODEF) for a defun, (OFEATURES . nil) for a provide. */ | |
276 Lisp_Object Vautoload_queue; | |
277 | |
278 /* Current number of specbindings allocated in specpdl. */ | |
279 int specpdl_size; | |
280 | |
281 /* Pointer to beginning of specpdl. */ | |
282 struct specbinding *specpdl; | |
283 | |
284 /* Pointer to first unused element in specpdl. */ | |
285 struct specbinding *specpdl_ptr; | |
286 | |
287 /* specpdl_ptr - specpdl */ | |
288 int specpdl_depth_counter; | |
289 | |
290 /* Maximum size allowed for specpdl allocation */ | |
458 | 291 Fixnum max_specpdl_size; |
428 | 292 |
293 /* Depth in Lisp evaluations and function calls. */ | |
1292 | 294 int lisp_eval_depth; |
428 | 295 |
296 /* Maximum allowed depth in Lisp evaluations and function calls. */ | |
458 | 297 Fixnum max_lisp_eval_depth; |
428 | 298 |
299 /* Nonzero means enter debugger before next function call */ | |
300 static int debug_on_next_call; | |
301 | |
1292 | 302 int backtrace_with_internal_sections; |
303 | |
428 | 304 /* List of conditions (non-nil atom means all) which cause a backtrace |
305 if an error is handled by the command loop's error handler. */ | |
306 Lisp_Object Vstack_trace_on_error; | |
307 | |
308 /* List of conditions (non-nil atom means all) which enter the debugger | |
309 if an error is handled by the command loop's error handler. */ | |
310 Lisp_Object Vdebug_on_error; | |
311 | |
312 /* List of conditions and regexps specifying error messages which | |
313 do not enter the debugger even if Vdebug_on_error says they should. */ | |
314 Lisp_Object Vdebug_ignored_errors; | |
315 | |
316 /* List of conditions (non-nil atom means all) which cause a backtrace | |
317 if any error is signalled. */ | |
318 Lisp_Object Vstack_trace_on_signal; | |
319 | |
320 /* List of conditions (non-nil atom means all) which enter the debugger | |
321 if any error is signalled. */ | |
322 Lisp_Object Vdebug_on_signal; | |
323 | |
324 /* Nonzero means enter debugger if a quit signal | |
325 is handled by the command loop's error handler. | |
326 | |
327 From lisp, this is a boolean variable and may have the values 0 and 1. | |
328 But, eval.c temporarily uses the second bit of this variable to indicate | |
329 that a critical_quit is in progress. The second bit is reset immediately | |
330 after it is processed in signal_call_debugger(). */ | |
331 int debug_on_quit; | |
332 | |
333 #if 0 /* FSFmacs */ | |
334 /* entering_debugger is basically equivalent */ | |
335 /* The value of num_nonmacro_input_chars as of the last time we | |
336 started to enter the debugger. If we decide to enter the debugger | |
337 again when this is still equal to num_nonmacro_input_chars, then we | |
338 know that the debugger itself has an error, and we should just | |
339 signal the error instead of entering an infinite loop of debugger | |
340 invocations. */ | |
341 int when_entered_debugger; | |
342 #endif | |
343 | |
344 /* Nonzero means we are trying to enter the debugger. | |
345 This is to prevent recursive attempts. | |
346 Cleared by the debugger calling Fbacktrace */ | |
347 static int entering_debugger; | |
348 | |
349 /* Function to call to invoke the debugger */ | |
350 Lisp_Object Vdebugger; | |
351 | |
853 | 352 /* List of condition handlers currently in effect. |
353 The elements of this lists were at one point in the past | |
354 threaded through the stack frames of Fcondition_case and | |
355 related functions, but now are stored separately in a normal | |
356 stack. When an error is signaled (by calling Fsignal, below), | |
357 this list is searched for an element that applies. | |
428 | 358 |
359 Each element of this list is one of the following: | |
360 | |
853 | 361 -- A list of a handler function and possibly args to pass to the |
362 function. This is a handler established with the Lisp primitive | |
363 `call-with-condition-handler' or related C function | |
364 call_with_condition_handler(): | |
365 | |
366 If the handler function is an opaque ptr object, it is a handler | |
367 that was established in C using call_with_condition_handler(), | |
368 and the contents of the object are a function pointer which takes | |
369 three arguments, the signal name and signal data (same arguments | |
370 passed to `signal') and a third Lisp_Object argument, specified | |
371 in the call to call_with_condition_handler() and stored as the | |
372 second element of the list containing the handler functionl. | |
373 | |
374 If the handler function is a regular Lisp_Object, it is a handler | |
375 that was established using `call-with-condition-handler'. | |
376 Currently there are no more arguments in the list containing the | |
377 handler function, and only one argument is passed to the handler | |
378 function: a cons of the signal name and signal data arguments | |
379 passed to `signal'. | |
380 | |
381 -- A list whose car is Qunbound and whose cdr is Qt. This is a | |
382 special condition-case handler established by C code with | |
383 condition_case_1(). All errors are trapped; the debugger is not | |
384 invoked even if `debug-on-error' was set. | |
385 | |
386 -- A list whose car is Qunbound and whose cdr is Qerror. This is a | |
387 special condition-case handler established by C code with | |
388 condition_case_1(). It is like Qt except that the debugger is | |
389 invoked normally if it is called for. | |
390 | |
391 -- A list whose car is Qunbound and whose cdr is a list of lists | |
392 (CONDITION-NAME BODY ...) exactly as in `condition-case'. This is | |
393 a normal `condition-case' handler. | |
394 | |
395 Note that in all cases *except* the first, there is a corresponding | |
396 catch, whose TAG is the value of Vcondition_handlers just after the | |
397 handler data just described is pushed onto it. The reason is that | |
398 `condition-case' handlers need to throw back to the place where the | |
399 handler was installed before invoking it, while | |
400 `call-with-condition-handler' handlers are invoked in the | |
401 environment that `signal' was invoked in. */ | |
402 | |
403 | |
428 | 404 static Lisp_Object Vcondition_handlers; |
405 | |
853 | 406 /* I think we should keep this enabled all the time, not just when |
407 error checking is enabled, because if one of these puppies pops up, | |
408 it will trash the stack if not caught, making it that much harder to | |
409 debug. It doesn't cause speed loss. */ | |
442 | 410 #define DEFEND_AGAINST_THROW_RECURSION |
411 | |
412 #ifdef DEFEND_AGAINST_THROW_RECURSION | |
428 | 413 /* Used for error catching purposes by throw_or_bomb_out */ |
414 static int throw_level; | |
442 | 415 #endif |
416 | |
1123 | 417 static int warning_will_be_discarded (Lisp_Object level); |
2532 | 418 static Lisp_Object maybe_get_trapping_problems_backtrace (void); |
1123 | 419 |
428 | 420 |
421 /************************************************************************/ | |
422 /* The subr object type */ | |
423 /************************************************************************/ | |
424 | |
425 static void | |
2286 | 426 print_subr (Lisp_Object obj, Lisp_Object printcharfun, int UNUSED (escapeflag)) |
428 | 427 { |
428 Lisp_Subr *subr = XSUBR (obj); | |
867 | 429 const CIbyte *header = |
428 | 430 (subr->max_args == UNEVALLED) ? "#<special-form " : "#<subr "; |
867 | 431 const CIbyte *name = subr_name (subr); |
432 const CIbyte *trailer = subr->prompt ? " (interactive)>" : ">"; | |
428 | 433 |
434 if (print_readably) | |
563 | 435 printing_unreadable_object ("%s%s%s", header, name, trailer); |
428 | 436 |
826 | 437 write_c_string (printcharfun, header); |
438 write_c_string (printcharfun, name); | |
439 write_c_string (printcharfun, trailer); | |
428 | 440 } |
441 | |
1204 | 442 static const struct memory_description subr_description[] = { |
2551 | 443 { XD_DOC_STRING, offsetof (Lisp_Subr, doc), 0, { 0 }, XD_FLAG_NO_KKCC }, |
428 | 444 { XD_END } |
445 }; | |
446 | |
938 | 447 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("subr", subr, |
448 1, /*dumpable-flag*/ | |
449 0, print_subr, 0, 0, 0, | |
450 subr_description, | |
451 Lisp_Subr); | |
428 | 452 |
453 /************************************************************************/ | |
454 /* Entering the debugger */ | |
455 /************************************************************************/ | |
456 | |
853 | 457 static Lisp_Object |
458 current_warning_level (void) | |
459 { | |
460 if (inhibit_flags & ISSUE_WARNINGS_AT_DEBUG_LEVEL) | |
461 return Qdebug; | |
462 else | |
463 return Qwarning; | |
464 } | |
465 | |
428 | 466 /* Actually call the debugger. ARG is a list of args that will be |
467 passed to the debugger function, as follows; | |
468 | |
469 If due to frame exit, args are `exit' and the value being returned; | |
470 this function's value will be returned instead of that. | |
471 If due to error, args are `error' and a list of the args to `signal'. | |
472 If due to `apply' or `funcall' entry, one arg, `lambda'. | |
473 If due to `eval' entry, one arg, t. | |
474 | |
475 */ | |
476 | |
477 static Lisp_Object | |
478 call_debugger_259 (Lisp_Object arg) | |
479 { | |
480 return apply1 (Vdebugger, arg); | |
481 } | |
482 | |
483 /* Call the debugger, doing some encapsulation. We make sure we have | |
484 some room on the eval and specpdl stacks, and bind entering_debugger | |
485 to 1 during this call. This is used to trap errors that may occur | |
486 when entering the debugger (e.g. the value of `debugger' is invalid), | |
487 so that the debugger will not be recursively entered if debug-on-error | |
488 is set. (Otherwise, XEmacs would infinitely recurse, attempting to | |
489 enter the debugger.) entering_debugger gets reset to 0 as soon | |
490 as a backtrace is displayed, so that further errors can indeed be | |
491 handled normally. | |
492 | |
3025 | 493 We also establish a catch for `debugger'. If the debugger function |
428 | 494 throws to this instead of returning a value, it means that the user |
495 pressed 'c' (pretend like the debugger was never entered). The | |
496 function then returns Qunbound. (If the user pressed 'r', for | |
497 return a value, then the debugger function returns normally with | |
498 this value.) | |
499 | |
500 The difference between 'c' and 'r' is as follows: | |
501 | |
502 debug-on-call: | |
503 No difference. The call proceeds as normal. | |
504 debug-on-exit: | |
505 With 'r', the specified value is returned as the function's | |
506 return value. With 'c', the value that would normally be | |
507 returned is returned. | |
508 signal: | |
509 With 'r', the specified value is returned as the return | |
510 value of `signal'. (This is the only time that `signal' | |
511 can return, instead of making a non-local exit.) With `c', | |
512 `signal' will continue looking for handlers as if the | |
513 debugger was never entered, and will probably end up | |
514 throwing to a handler or to top-level. | |
515 */ | |
516 | |
517 static Lisp_Object | |
518 call_debugger (Lisp_Object arg) | |
519 { | |
520 int threw; | |
521 Lisp_Object val; | |
522 int speccount; | |
523 | |
853 | 524 debug_on_next_call = 0; |
525 | |
526 if (inhibit_flags & INHIBIT_ENTERING_DEBUGGER) | |
527 { | |
528 if (!(inhibit_flags & INHIBIT_WARNING_ISSUE)) | |
529 warn_when_safe | |
530 (Qdebugger, current_warning_level (), | |
531 "Unable to enter debugger within critical section"); | |
532 return Qunbound; | |
533 } | |
534 | |
428 | 535 if (lisp_eval_depth + 20 > max_lisp_eval_depth) |
536 max_lisp_eval_depth = lisp_eval_depth + 20; | |
537 if (specpdl_size + 40 > max_specpdl_size) | |
538 max_specpdl_size = specpdl_size + 40; | |
853 | 539 |
540 speccount = internal_bind_int (&entering_debugger, 1); | |
2532 | 541 val = internal_catch (Qdebugger, call_debugger_259, arg, &threw, 0, 0); |
428 | 542 |
771 | 543 return unbind_to_1 (speccount, ((threw) |
428 | 544 ? Qunbound /* Not returning a value */ |
545 : val)); | |
546 } | |
547 | |
548 /* Called when debug-on-exit behavior is called for. Enter the debugger | |
549 with the appropriate args for this. VAL is the exit value that is | |
550 about to be returned. */ | |
551 | |
552 static Lisp_Object | |
553 do_debug_on_exit (Lisp_Object val) | |
554 { | |
555 /* This is falsified by call_debugger */ | |
556 Lisp_Object v = call_debugger (list2 (Qexit, val)); | |
557 | |
558 return !UNBOUNDP (v) ? v : val; | |
559 } | |
560 | |
561 /* Called when debug-on-call behavior is called for. Enter the debugger | |
562 with the appropriate args for this. VAL is either t for a call | |
3025 | 563 through `eval' or `lambda' for a call through `funcall'. |
428 | 564 |
565 #### The differentiation here between EVAL and FUNCALL is bogus. | |
566 FUNCALL can be defined as | |
567 | |
568 (defmacro func (fun &rest args) | |
569 (cons (eval fun) args)) | |
570 | |
571 and should be treated as such. | |
572 */ | |
573 | |
574 static void | |
575 do_debug_on_call (Lisp_Object code) | |
576 { | |
577 debug_on_next_call = 0; | |
578 backtrace_list->debug_on_exit = 1; | |
579 call_debugger (list1 (code)); | |
580 } | |
581 | |
582 /* LIST is the value of one of the variables `debug-on-error', | |
583 `debug-on-signal', `stack-trace-on-error', or `stack-trace-on-signal', | |
584 and CONDITIONS is the list of error conditions associated with | |
585 the error being signalled. This returns non-nil if LIST | |
586 matches CONDITIONS. (A nil value for LIST does not match | |
587 CONDITIONS. A non-list value for LIST does match CONDITIONS. | |
588 A list matches CONDITIONS when one of the symbols in LIST is the | |
589 same as one of the symbols in CONDITIONS.) */ | |
590 | |
591 static int | |
592 wants_debugger (Lisp_Object list, Lisp_Object conditions) | |
593 { | |
594 if (NILP (list)) | |
595 return 0; | |
596 if (! CONSP (list)) | |
597 return 1; | |
598 | |
599 while (CONSP (conditions)) | |
600 { | |
2552 | 601 Lisp_Object curr, tail; |
602 curr = XCAR (conditions); | |
428 | 603 for (tail = list; CONSP (tail); tail = XCDR (tail)) |
2552 | 604 if (EQ (XCAR (tail), curr)) |
428 | 605 return 1; |
606 conditions = XCDR (conditions); | |
607 } | |
608 return 0; | |
609 } | |
610 | |
611 | |
612 /* Return 1 if an error with condition-symbols CONDITIONS, | |
613 and described by SIGNAL-DATA, should skip the debugger | |
4624
9dd42cb187ed
Fix typo in comment on skip_debugger.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4535
diff
changeset
|
614 according to debug-ignored-errors. */ |
428 | 615 |
616 static int | |
617 skip_debugger (Lisp_Object conditions, Lisp_Object data) | |
618 { | |
619 /* This function can GC */ | |
620 Lisp_Object tail; | |
621 int first_string = 1; | |
622 Lisp_Object error_message = Qnil; | |
623 | |
624 for (tail = Vdebug_ignored_errors; CONSP (tail); tail = XCDR (tail)) | |
625 { | |
626 if (STRINGP (XCAR (tail))) | |
627 { | |
628 if (first_string) | |
629 { | |
630 error_message = Ferror_message_string (data); | |
631 first_string = 0; | |
632 } | |
633 if (fast_lisp_string_match (XCAR (tail), error_message) >= 0) | |
634 return 1; | |
635 } | |
636 else | |
637 { | |
638 Lisp_Object contail; | |
639 | |
640 for (contail = conditions; CONSP (contail); contail = XCDR (contail)) | |
641 if (EQ (XCAR (tail), XCAR (contail))) | |
642 return 1; | |
643 } | |
644 } | |
645 | |
646 return 0; | |
647 } | |
648 | |
649 /* Actually generate a backtrace on STREAM. */ | |
650 | |
651 static Lisp_Object | |
652 backtrace_259 (Lisp_Object stream) | |
653 { | |
654 return Fbacktrace (stream, Qt); | |
655 } | |
656 | |
1130 | 657 #ifdef DEBUG_XEMACS |
658 | |
659 static void | |
660 trace_out_and_die (Lisp_Object err) | |
661 { | |
662 Fdisplay_error (err, Qt); | |
663 backtrace_259 (Qnil); | |
664 stderr_out ("XEmacs exiting to debugger.\n"); | |
665 Fforce_debugging_signal (Qt); | |
666 /* Unlikely to be reached */ | |
667 } | |
668 | |
669 #endif | |
670 | |
428 | 671 /* An error was signaled. Maybe call the debugger, if the `debug-on-error' |
672 etc. variables call for this. CONDITIONS is the list of conditions | |
673 associated with the error being signalled. SIG is the actual error | |
674 being signalled, and DATA is the associated data (these are exactly | |
675 the same as the arguments to `signal'). ACTIVE_HANDLERS is the | |
676 list of error handlers that are to be put in place while the debugger | |
677 is called. This is generally the remaining handlers that are | |
678 outside of the innermost handler trapping this error. This way, | |
679 if the same error occurs inside of the debugger, you usually don't get | |
680 the debugger entered recursively. | |
681 | |
682 This function returns Qunbound if it didn't call the debugger or if | |
683 the user asked (through 'c') that XEmacs should pretend like the | |
684 debugger was never entered. Otherwise, it returns the value | |
685 that the user specified with `r'. (Note that much of the time, | |
686 the user will abort with C-], and we will never have a chance to | |
687 return anything at all.) | |
688 | |
689 SIGNAL_VARS_ONLY means we should only look at debug-on-signal | |
690 and stack-trace-on-signal to control whether we do anything. | |
691 This is so that debug-on-error doesn't make handled errors | |
692 cause the debugger to get invoked. | |
693 | |
694 STACK_TRACE_DISPLAYED and DEBUGGER_ENTERED are used so that | |
695 those functions aren't done more than once in a single `signal' | |
696 session. */ | |
697 | |
698 static Lisp_Object | |
699 signal_call_debugger (Lisp_Object conditions, | |
700 Lisp_Object sig, Lisp_Object data, | |
701 Lisp_Object active_handlers, | |
702 int signal_vars_only, | |
703 int *stack_trace_displayed, | |
704 int *debugger_entered) | |
705 { | |
853 | 706 #ifdef PIGS_FLY_AND_ALL_C_CODE_CAN_HANDLE_GC_OCCURRING_ALMOST_ANYWHERE |
428 | 707 /* This function can GC */ |
853 | 708 #else /* reality check */ |
709 /* This function cannot GC because it inhibits GC during its operation */ | |
710 #endif | |
711 | |
428 | 712 Lisp_Object val = Qunbound; |
713 Lisp_Object all_handlers = Vcondition_handlers; | |
714 Lisp_Object temp_data = Qnil; | |
853 | 715 int outer_speccount = specpdl_depth(); |
716 int speccount; | |
717 | |
718 #ifdef PIGS_FLY_AND_ALL_C_CODE_CAN_HANDLE_GC_OCCURRING_ALMOST_ANYWHERE | |
428 | 719 struct gcpro gcpro1, gcpro2; |
720 GCPRO2 (all_handlers, temp_data); | |
853 | 721 #else |
722 begin_gc_forbidden (); | |
723 #endif | |
724 | |
725 speccount = specpdl_depth(); | |
428 | 726 |
727 Vcondition_handlers = active_handlers; | |
728 | |
729 temp_data = Fcons (sig, data); /* needed for skip_debugger */ | |
730 | |
731 if (!entering_debugger && !*stack_trace_displayed && !signal_vars_only | |
732 && wants_debugger (Vstack_trace_on_error, conditions) | |
733 && !skip_debugger (conditions, temp_data)) | |
734 { | |
735 specbind (Qdebug_on_error, Qnil); | |
736 specbind (Qstack_trace_on_error, Qnil); | |
737 specbind (Qdebug_on_signal, Qnil); | |
738 specbind (Qstack_trace_on_signal, Qnil); | |
739 | |
442 | 740 if (!noninteractive) |
741 internal_with_output_to_temp_buffer (build_string ("*Backtrace*"), | |
742 backtrace_259, | |
743 Qnil, | |
744 Qnil); | |
745 else /* in batch mode, we want this going to stderr. */ | |
746 backtrace_259 (Qnil); | |
771 | 747 unbind_to (speccount); |
428 | 748 *stack_trace_displayed = 1; |
749 } | |
750 | |
751 if (!entering_debugger && !*debugger_entered && !signal_vars_only | |
752 && (EQ (sig, Qquit) | |
753 ? debug_on_quit | |
754 : wants_debugger (Vdebug_on_error, conditions)) | |
755 && !skip_debugger (conditions, temp_data)) | |
756 { | |
757 debug_on_quit &= ~2; /* reset critical bit */ | |
1123 | 758 |
428 | 759 specbind (Qdebug_on_error, Qnil); |
760 specbind (Qstack_trace_on_error, Qnil); | |
761 specbind (Qdebug_on_signal, Qnil); | |
762 specbind (Qstack_trace_on_signal, Qnil); | |
763 | |
1130 | 764 #ifdef DEBUG_XEMACS |
765 if (noninteractive) | |
766 trace_out_and_die (Fcons (sig, data)); | |
767 #endif | |
768 | |
428 | 769 val = call_debugger (list2 (Qerror, (Fcons (sig, data)))); |
853 | 770 unbind_to (speccount); |
428 | 771 *debugger_entered = 1; |
772 } | |
773 | |
774 if (!entering_debugger && !*stack_trace_displayed | |
775 && wants_debugger (Vstack_trace_on_signal, conditions)) | |
776 { | |
777 specbind (Qdebug_on_error, Qnil); | |
778 specbind (Qstack_trace_on_error, Qnil); | |
779 specbind (Qdebug_on_signal, Qnil); | |
780 specbind (Qstack_trace_on_signal, Qnil); | |
781 | |
442 | 782 if (!noninteractive) |
783 internal_with_output_to_temp_buffer (build_string ("*Backtrace*"), | |
784 backtrace_259, | |
785 Qnil, | |
786 Qnil); | |
787 else /* in batch mode, we want this going to stderr. */ | |
788 backtrace_259 (Qnil); | |
771 | 789 unbind_to (speccount); |
428 | 790 *stack_trace_displayed = 1; |
791 } | |
792 | |
793 if (!entering_debugger && !*debugger_entered | |
794 && (EQ (sig, Qquit) | |
795 ? debug_on_quit | |
796 : wants_debugger (Vdebug_on_signal, conditions))) | |
797 { | |
798 debug_on_quit &= ~2; /* reset critical bit */ | |
1123 | 799 |
428 | 800 specbind (Qdebug_on_error, Qnil); |
801 specbind (Qstack_trace_on_error, Qnil); | |
802 specbind (Qdebug_on_signal, Qnil); | |
803 specbind (Qstack_trace_on_signal, Qnil); | |
804 | |
1130 | 805 #ifdef DEBUG_XEMACS |
806 if (noninteractive) | |
807 trace_out_and_die (Fcons (sig, data)); | |
808 #endif | |
809 | |
428 | 810 val = call_debugger (list2 (Qerror, (Fcons (sig, data)))); |
811 *debugger_entered = 1; | |
812 } | |
813 | |
853 | 814 #ifdef PIGS_FLY_AND_ALL_C_CODE_CAN_HANDLE_GC_OCCURRING_ALMOST_ANYWHERE |
428 | 815 UNGCPRO; |
853 | 816 #endif |
428 | 817 Vcondition_handlers = all_handlers; |
853 | 818 return unbind_to_1 (outer_speccount, val); |
428 | 819 } |
820 | |
821 | |
822 /************************************************************************/ | |
823 /* The basic special forms */ | |
824 /************************************************************************/ | |
825 | |
826 /* Except for Fprogn(), the basic special forms below are only called | |
827 from interpreted code. The byte compiler turns them into bytecodes. */ | |
828 | |
829 DEFUN ("or", For, 0, UNEVALLED, 0, /* | |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
830 Eval ARGS until one of them yields non-nil, then return that value. |
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
831 The remaining ARGS are not evalled at all. |
428 | 832 If all args return nil, return nil. |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
833 |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
834 Any multiple values from the last form, and only from the last form, are |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
835 passed back. See `values' and `multiple-value-bind'. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
836 |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
837 arguments: (&rest ARGS) |
428 | 838 */ |
839 (args)) | |
840 { | |
841 /* This function can GC */ | |
4686
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
842 Lisp_Object val = Qnil; |
428 | 843 |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
844 LIST_LOOP_3 (arg, args, tail) |
428 | 845 { |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
846 if (!NILP (IGNORE_MULTIPLE_VALUES (val = Feval (arg)))) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
847 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
848 if (NILP (XCDR (tail))) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
849 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
850 /* Pass back multiple values if this is the last one: */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
851 return val; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
852 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
853 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
854 return IGNORE_MULTIPLE_VALUES (val); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
855 } |
428 | 856 } |
857 | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
858 return val; |
428 | 859 } |
860 | |
861 DEFUN ("and", Fand, 0, UNEVALLED, 0, /* | |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
862 Eval ARGS until one of them yields nil, then return nil. |
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
863 The remaining ARGS are not evalled at all. |
428 | 864 If no arg yields nil, return the last arg's value. |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
865 |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
866 Any multiple values from the last form, and only from the last form, are |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
867 passed back. See `values' and `multiple-value-bind'. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
868 |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
869 arguments: (&rest ARGS) |
428 | 870 */ |
871 (args)) | |
872 { | |
873 /* This function can GC */ | |
4686
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
874 Lisp_Object val = Qt; |
428 | 875 |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
876 LIST_LOOP_3 (arg, args, tail) |
428 | 877 { |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
878 if (NILP (IGNORE_MULTIPLE_VALUES (val = Feval (arg)))) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
879 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
880 if (NILP (XCDR (tail))) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
881 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
882 /* Pass back any multiple values for the last form: */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
883 return val; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
884 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
885 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
886 return Qnil; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
887 } |
428 | 888 } |
889 | |
890 return val; | |
891 } | |
892 | |
893 DEFUN ("if", Fif, 2, UNEVALLED, 0, /* | |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
894 If COND yields non-nil, do THEN, else do ELSE. |
428 | 895 Returns the value of THEN or the value of the last of the ELSE's. |
896 THEN must be one expression, but ELSE... can be zero or more expressions. | |
897 If COND yields nil, and there are no ELSE's, the value is nil. | |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
898 |
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
899 arguments: (COND THEN &rest ELSE) |
428 | 900 */ |
901 (args)) | |
902 { | |
903 /* This function can GC */ | |
904 Lisp_Object condition = XCAR (args); | |
905 Lisp_Object then_form = XCAR (XCDR (args)); | |
906 Lisp_Object else_forms = XCDR (XCDR (args)); | |
907 | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
908 if (!NILP (IGNORE_MULTIPLE_VALUES (Feval (condition)))) |
428 | 909 return Feval (then_form); |
910 else | |
911 return Fprogn (else_forms); | |
912 } | |
913 | |
914 /* Macros `when' and `unless' are trivially defined in Lisp, | |
915 but it helps for bootstrapping to have them ALWAYS defined. */ | |
916 | |
917 DEFUN ("when", Fwhen, 1, MANY, 0, /* | |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
918 If COND yields non-nil, do BODY, else return nil. |
428 | 919 BODY can be zero or more expressions. If BODY is nil, return nil. |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
920 |
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
921 arguments: (COND &rest BODY) |
428 | 922 */ |
923 (int nargs, Lisp_Object *args)) | |
924 { | |
925 Lisp_Object cond = args[0]; | |
926 Lisp_Object body; | |
853 | 927 |
428 | 928 switch (nargs) |
929 { | |
930 case 1: body = Qnil; break; | |
931 case 2: body = args[1]; break; | |
932 default: body = Fcons (Qprogn, Flist (nargs-1, args+1)); break; | |
933 } | |
934 | |
935 return list3 (Qif, cond, body); | |
936 } | |
937 | |
938 DEFUN ("unless", Funless, 1, MANY, 0, /* | |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
939 If COND yields nil, do BODY, else return nil. |
428 | 940 BODY can be zero or more expressions. If BODY is nil, return nil. |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
941 |
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
942 arguments: (COND &rest BODY) |
428 | 943 */ |
944 (int nargs, Lisp_Object *args)) | |
945 { | |
946 Lisp_Object cond = args[0]; | |
947 Lisp_Object body = Flist (nargs-1, args+1); | |
948 return Fcons (Qif, Fcons (cond, Fcons (Qnil, body))); | |
949 } | |
950 | |
951 DEFUN ("cond", Fcond, 0, UNEVALLED, 0, /* | |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
952 Try each clause until one succeeds. |
428 | 953 Each clause looks like (CONDITION BODY...). CONDITION is evaluated |
954 and, if the value is non-nil, this clause succeeds: | |
955 then the expressions in BODY are evaluated and the last one's | |
956 value is the value of the cond-form. | |
957 If no clause succeeds, cond returns nil. | |
958 If a clause has one element, as in (CONDITION), | |
959 CONDITION's value if non-nil is returned from the cond-form. | |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
960 |
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
961 arguments: (&rest CLAUSES) |
428 | 962 */ |
963 (args)) | |
964 { | |
965 /* This function can GC */ | |
442 | 966 REGISTER Lisp_Object val; |
428 | 967 |
968 LIST_LOOP_2 (clause, args) | |
969 { | |
970 CHECK_CONS (clause); | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
971 if (!NILP (val = IGNORE_MULTIPLE_VALUES (Feval (XCAR (clause))))) |
428 | 972 { |
973 if (!NILP (clause = XCDR (clause))) | |
974 { | |
975 CHECK_TRUE_LIST (clause); | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
976 /* Pass back any multiple values here: */ |
428 | 977 val = Fprogn (clause); |
978 } | |
979 return val; | |
980 } | |
981 } | |
982 | |
983 return Qnil; | |
984 } | |
985 | |
986 DEFUN ("progn", Fprogn, 0, UNEVALLED, 0, /* | |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
987 Eval BODY forms sequentially and return value of last one. |
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
988 |
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
989 arguments: (&rest BODY) |
428 | 990 */ |
991 (args)) | |
992 { | |
993 /* This function can GC */ | |
994 /* Caller must provide a true list in ARGS */ | |
442 | 995 REGISTER Lisp_Object val = Qnil; |
428 | 996 struct gcpro gcpro1; |
997 | |
998 GCPRO1 (args); | |
999 | |
1000 { | |
1001 LIST_LOOP_2 (form, args) | |
1002 val = Feval (form); | |
1003 } | |
1004 | |
1005 UNGCPRO; | |
1006 return val; | |
1007 } | |
1008 | |
1009 /* Fprog1() is the canonical example of a function that must GCPRO a | |
1010 Lisp_Object across calls to Feval(). */ | |
1011 | |
1012 DEFUN ("prog1", Fprog1, 1, UNEVALLED, 0, /* | |
1013 Similar to `progn', but the value of the first form is returned. | |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
1014 |
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
1015 All the arguments are evaluated sequentially. The value of FIRST is saved |
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
1016 during evaluation of the remaining args, whose values are discarded. |
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
1017 |
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
1018 arguments: (FIRST &rest BODY) |
428 | 1019 */ |
1020 (args)) | |
1021 { | |
1849 | 1022 Lisp_Object val; |
428 | 1023 struct gcpro gcpro1; |
1024 | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1025 val = IGNORE_MULTIPLE_VALUES (Feval (Fcar (args))); |
428 | 1026 |
1027 GCPRO1 (val); | |
1028 | |
1029 { | |
1030 LIST_LOOP_2 (form, XCDR (args)) | |
1031 Feval (form); | |
1032 } | |
1033 | |
1034 UNGCPRO; | |
1035 return val; | |
1036 } | |
1037 | |
1038 DEFUN ("prog2", Fprog2, 2, UNEVALLED, 0, /* | |
1039 Similar to `progn', but the value of the second form is returned. | |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
1040 |
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
1041 All the arguments are evaluated sequentially. The value of SECOND is saved |
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
1042 during evaluation of the remaining args, whose values are discarded. |
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
1043 |
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
1044 arguments: (FIRST SECOND &rest BODY) |
428 | 1045 */ |
1046 (args)) | |
1047 { | |
1048 /* This function can GC */ | |
1849 | 1049 Lisp_Object val; |
428 | 1050 struct gcpro gcpro1; |
1051 | |
1052 Feval (XCAR (args)); | |
1053 args = XCDR (args); | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1054 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1055 val = IGNORE_MULTIPLE_VALUES (Feval (XCAR (args))); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1056 |
428 | 1057 args = XCDR (args); |
1058 | |
1059 GCPRO1 (val); | |
1060 | |
442 | 1061 { |
1062 LIST_LOOP_2 (form, args) | |
1063 Feval (form); | |
1064 } | |
428 | 1065 |
1066 UNGCPRO; | |
1067 return val; | |
1068 } | |
1069 | |
1070 DEFUN ("let*", FletX, 1, UNEVALLED, 0, /* | |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
1071 Bind variables according to VARLIST then eval BODY. |
428 | 1072 The value of the last form in BODY is returned. |
1073 Each element of VARLIST is a symbol (which is bound to nil) | |
1074 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM). | |
1075 Each VALUEFORM can refer to the symbols already bound by this VARLIST. | |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
1076 |
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
1077 arguments: (VARLIST &rest BODY) |
428 | 1078 */ |
1079 (args)) | |
1080 { | |
1081 /* This function can GC */ | |
1082 Lisp_Object varlist = XCAR (args); | |
1083 Lisp_Object body = XCDR (args); | |
1084 int speccount = specpdl_depth(); | |
1085 | |
1086 EXTERNAL_LIST_LOOP_3 (var, varlist, tail) | |
1087 { | |
1088 Lisp_Object symbol, value, tem; | |
1089 if (SYMBOLP (var)) | |
1090 symbol = var, value = Qnil; | |
1091 else | |
1092 { | |
1093 CHECK_CONS (var); | |
1094 symbol = XCAR (var); | |
1095 tem = XCDR (var); | |
1096 if (NILP (tem)) | |
1097 value = Qnil; | |
1098 else | |
1099 { | |
1100 CHECK_CONS (tem); | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1101 value = IGNORE_MULTIPLE_VALUES (Feval (XCAR (tem))); |
428 | 1102 if (!NILP (XCDR (tem))) |
563 | 1103 sferror |
428 | 1104 ("`let' bindings can have only one value-form", var); |
1105 } | |
1106 } | |
1107 specbind (symbol, value); | |
1108 } | |
771 | 1109 return unbind_to_1 (speccount, Fprogn (body)); |
428 | 1110 } |
1111 | |
1112 DEFUN ("let", Flet, 1, UNEVALLED, 0, /* | |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
1113 Bind variables according to VARLIST then eval BODY. |
428 | 1114 The value of the last form in BODY is returned. |
1115 Each element of VARLIST is a symbol (which is bound to nil) | |
1116 or a list (SYMBOL VALUEFORM) (which binds SYMBOL to the value of VALUEFORM). | |
1117 All the VALUEFORMs are evalled before any symbols are bound. | |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
1118 |
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
1119 arguments: (VARLIST &rest BODY) |
428 | 1120 */ |
1121 (args)) | |
1122 { | |
1123 /* This function can GC */ | |
1124 Lisp_Object varlist = XCAR (args); | |
1125 Lisp_Object body = XCDR (args); | |
1126 int speccount = specpdl_depth(); | |
1127 Lisp_Object *temps; | |
1128 int idx; | |
1129 struct gcpro gcpro1; | |
1130 | |
1131 /* Make space to hold the values to give the bound variables. */ | |
1132 { | |
1133 int varcount; | |
1134 GET_EXTERNAL_LIST_LENGTH (varlist, varcount); | |
1135 temps = alloca_array (Lisp_Object, varcount); | |
1136 } | |
1137 | |
1138 /* Compute the values and store them in `temps' */ | |
1139 GCPRO1 (*temps); | |
1140 gcpro1.nvars = 0; | |
1141 | |
1142 idx = 0; | |
442 | 1143 { |
1144 LIST_LOOP_2 (var, varlist) | |
1145 { | |
1146 Lisp_Object *value = &temps[idx++]; | |
1147 if (SYMBOLP (var)) | |
1148 *value = Qnil; | |
1149 else | |
1150 { | |
1151 Lisp_Object tem; | |
1152 CHECK_CONS (var); | |
1153 tem = XCDR (var); | |
1154 if (NILP (tem)) | |
1155 *value = Qnil; | |
1156 else | |
1157 { | |
1158 CHECK_CONS (tem); | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1159 *value = IGNORE_MULTIPLE_VALUES (Feval (XCAR (tem))); |
442 | 1160 gcpro1.nvars = idx; |
1161 | |
1162 if (!NILP (XCDR (tem))) | |
563 | 1163 sferror |
442 | 1164 ("`let' bindings can have only one value-form", var); |
1165 } | |
1166 } | |
1167 } | |
1168 } | |
428 | 1169 |
1170 idx = 0; | |
442 | 1171 { |
1172 LIST_LOOP_2 (var, varlist) | |
1173 { | |
1174 specbind (SYMBOLP (var) ? var : XCAR (var), temps[idx++]); | |
1175 } | |
1176 } | |
428 | 1177 |
1178 UNGCPRO; | |
1179 | |
771 | 1180 return unbind_to_1 (speccount, Fprogn (body)); |
428 | 1181 } |
1182 | |
1183 DEFUN ("while", Fwhile, 1, UNEVALLED, 0, /* | |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
1184 If TEST yields non-nil, eval BODY... and repeat. |
428 | 1185 The order of execution is thus TEST, BODY, TEST, BODY and so on |
1186 until TEST returns nil. | |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
1187 |
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
1188 arguments: (TEST &rest BODY) |
428 | 1189 */ |
1190 (args)) | |
1191 { | |
1192 /* This function can GC */ | |
1193 Lisp_Object test = XCAR (args); | |
1194 Lisp_Object body = XCDR (args); | |
1195 | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1196 while (!NILP (IGNORE_MULTIPLE_VALUES (Feval (test)))) |
428 | 1197 { |
1198 QUIT; | |
1199 Fprogn (body); | |
1200 } | |
1201 | |
1202 return Qnil; | |
1203 } | |
1204 | |
1205 DEFUN ("setq", Fsetq, 0, UNEVALLED, 0, /* | |
1206 \(setq SYM VAL SYM VAL ...): set each SYM to the value of its VAL. | |
1207 The symbols SYM are variables; they are literal (not evaluated). | |
1208 The values VAL are expressions; they are evaluated. | |
1209 Thus, (setq x (1+ y)) sets `x' to the value of `(1+ y)'. | |
1210 The second VAL is not computed until after the first SYM is set, and so on; | |
1211 each VAL can use the new value of variables set earlier in the `setq'. | |
1212 The return value of the `setq' form is the value of the last VAL. | |
1213 */ | |
1214 (args)) | |
1215 { | |
1216 /* This function can GC */ | |
1217 int nargs; | |
2421 | 1218 Lisp_Object retval = Qnil; |
428 | 1219 |
1220 GET_LIST_LENGTH (args, nargs); | |
1221 | |
1222 if (nargs & 1) /* Odd number of arguments? */ | |
1223 Fsignal (Qwrong_number_of_arguments, list2 (Qsetq, make_int (nargs))); | |
1224 | |
2421 | 1225 GC_PROPERTY_LIST_LOOP_3 (symbol, val, args) |
428 | 1226 { |
1227 val = Feval (val); | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1228 val = IGNORE_MULTIPLE_VALUES (val); |
428 | 1229 Fset (symbol, val); |
2421 | 1230 retval = val; |
428 | 1231 } |
1232 | |
2421 | 1233 END_GC_PROPERTY_LIST_LOOP (symbol); |
1234 | |
1235 return retval; | |
428 | 1236 } |
1237 | |
1238 DEFUN ("quote", Fquote, 1, UNEVALLED, 0, /* | |
1239 Return the argument, without evaluating it. `(quote x)' yields `x'. | |
3794 | 1240 |
3842 | 1241 `quote' differs from `function' in that it is a hint that an expression is |
1242 data, not a function. In particular, under some circumstances the byte | |
1243 compiler will compile an expression quoted with `function', but it will | |
1244 never do so for an expression quoted with `quote'. These issues are most | |
1245 important for lambda expressions (see `lambda'). | |
1246 | |
1247 There is an alternative, more readable, reader syntax for `quote': a Lisp | |
1248 object preceded by `''. Thus, `'x' is equivalent to `(quote x)', in all | |
1249 contexts. A print function may use either. Internally the expression is | |
1250 represented as `(quote x)'). | |
428 | 1251 */ |
1252 (args)) | |
1253 { | |
1254 return XCAR (args); | |
1255 } | |
1256 | |
1257 DEFUN ("function", Ffunction, 1, UNEVALLED, 0, /* | |
3842 | 1258 Return the argument, without evaluating it. `(function x)' yields `x'. |
1259 | |
1260 `function' differs from `quote' in that it is a hint that an expression is | |
1261 a function, not data. In particular, under some circumstances the byte | |
1262 compiler will compile an expression quoted with `function', but it will | |
1263 never do so for an expression quoted with `quote'. However, the byte | |
1264 compiler will not compile an expression buried in a data structure such as | |
1265 a vector or a list which is not syntactically a function. These issues are | |
1266 most important for lambda expressions (see `lambda'). | |
1267 | |
1268 There is an alternative, more readable, reader syntax for `function': a Lisp | |
1269 object preceded by `#''. Thus, #'x is equivalent to (function x), in all | |
1270 contexts. A print function may use either. Internally the expression is | |
1271 represented as `(function x)'). | |
428 | 1272 */ |
1273 (args)) | |
1274 { | |
1275 return XCAR (args); | |
1276 } | |
1277 | |
1278 | |
1279 /************************************************************************/ | |
1280 /* Defining functions/variables */ | |
1281 /************************************************************************/ | |
1282 static Lisp_Object | |
1283 define_function (Lisp_Object name, Lisp_Object defn) | |
1284 { | |
1285 Ffset (name, defn); | |
4535
69a1eda3da06
Distinguish vars and functions in #'symbol-file, #'describe-{function,variable}
Aidan Kehoe <kehoea@parhasard.net>
parents:
4502
diff
changeset
|
1286 LOADHIST_ATTACH (Fcons (Qdefun, name)); |
428 | 1287 return name; |
1288 } | |
1289 | |
1290 DEFUN ("defun", Fdefun, 2, UNEVALLED, 0, /* | |
1291 \(defun NAME ARGLIST [DOCSTRING] BODY...): define NAME as a function. | |
1292 The definition is (lambda ARGLIST [DOCSTRING] BODY...). | |
1293 See also the function `interactive'. | |
1294 */ | |
1295 (args)) | |
1296 { | |
1297 /* This function can GC */ | |
1298 return define_function (XCAR (args), | |
1299 Fcons (Qlambda, XCDR (args))); | |
1300 } | |
1301 | |
1302 DEFUN ("defmacro", Fdefmacro, 2, UNEVALLED, 0, /* | |
1303 \(defmacro NAME ARGLIST [DOCSTRING] BODY...): define NAME as a macro. | |
1304 The definition is (macro lambda ARGLIST [DOCSTRING] BODY...). | |
1305 When the macro is called, as in (NAME ARGS...), | |
1306 the function (lambda ARGLIST BODY...) is applied to | |
1307 the list ARGS... as it appears in the expression, | |
1308 and the result should be a form to be evaluated instead of the original. | |
1309 */ | |
1310 (args)) | |
1311 { | |
1312 /* This function can GC */ | |
1313 return define_function (XCAR (args), | |
1314 Fcons (Qmacro, Fcons (Qlambda, XCDR (args)))); | |
1315 } | |
1316 | |
1317 DEFUN ("defvar", Fdefvar, 1, UNEVALLED, 0, /* | |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
1318 Define SYMBOL as a variable. |
428 | 1319 You are not required to define a variable in order to use it, |
1320 but the definition can supply documentation and an initial value | |
1321 in a way that tags can recognize. | |
1322 | |
1323 INITVALUE is evaluated, and used to set SYMBOL, only if SYMBOL's value is | |
1324 void. (However, when you evaluate a defvar interactively, it acts like a | |
1325 defconst: SYMBOL's value is always set regardless of whether it's currently | |
1326 void.) | |
1327 If SYMBOL is buffer-local, its default value is what is set; | |
1328 buffer-local values are not affected. | |
1329 INITVALUE and DOCSTRING are optional. | |
1330 If DOCSTRING starts with *, this variable is identified as a user option. | |
442 | 1331 This means that M-x set-variable recognizes it. |
428 | 1332 If INITVALUE is missing, SYMBOL's value is not set. |
1333 | |
1334 In lisp-interaction-mode defvar is treated as defconst. | |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
1335 |
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
1336 arguments: (SYMBOL &optional INITVALUE DOCSTRING) |
428 | 1337 */ |
1338 (args)) | |
1339 { | |
1340 /* This function can GC */ | |
1341 Lisp_Object sym = XCAR (args); | |
1342 | |
1343 if (!NILP (args = XCDR (args))) | |
1344 { | |
1345 Lisp_Object val = XCAR (args); | |
1346 | |
1347 if (NILP (Fdefault_boundp (sym))) | |
1348 { | |
1349 struct gcpro gcpro1; | |
1350 GCPRO1 (val); | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1351 val = IGNORE_MULTIPLE_VALUES (Feval (val)); |
428 | 1352 Fset_default (sym, val); |
1353 UNGCPRO; | |
1354 } | |
1355 | |
1356 if (!NILP (args = XCDR (args))) | |
1357 { | |
1358 Lisp_Object doc = XCAR (args); | |
1359 Fput (sym, Qvariable_documentation, doc); | |
1360 if (!NILP (args = XCDR (args))) | |
563 | 1361 signal_error (Qwrong_number_of_arguments, "too many arguments", Qunbound); |
428 | 1362 } |
1363 } | |
1364 | |
1365 #ifdef I18N3 | |
1366 if (!NILP (Vfile_domain)) | |
1367 Fput (sym, Qvariable_domain, Vfile_domain); | |
1368 #endif | |
1369 | |
1370 LOADHIST_ATTACH (sym); | |
1371 return sym; | |
1372 } | |
1373 | |
1374 DEFUN ("defconst", Fdefconst, 2, UNEVALLED, 0, /* | |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
1375 Define SYMBOL as a constant variable. |
428 | 1376 The intent is that programs do not change this value, but users may. |
1377 Always sets the value of SYMBOL to the result of evalling INITVALUE. | |
1378 If SYMBOL is buffer-local, its default value is what is set; | |
1379 buffer-local values are not affected. | |
1380 DOCSTRING is optional. | |
1381 If DOCSTRING starts with *, this variable is identified as a user option. | |
442 | 1382 This means that M-x set-variable recognizes it. |
428 | 1383 |
1384 Note: do not use `defconst' for user options in libraries that are not | |
1385 normally loaded, since it is useful for users to be able to specify | |
1386 their own values for such variables before loading the library. | |
1387 Since `defconst' unconditionally assigns the variable, | |
1388 it would override the user's choice. | |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
1389 |
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
1390 arguments: (SYMBOL &optional INITVALUE DOCSTRING) |
428 | 1391 */ |
1392 (args)) | |
1393 { | |
1394 /* This function can GC */ | |
1395 Lisp_Object sym = XCAR (args); | |
1396 Lisp_Object val = Feval (XCAR (args = XCDR (args))); | |
1397 struct gcpro gcpro1; | |
1398 | |
1399 GCPRO1 (val); | |
1400 | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1401 val = IGNORE_MULTIPLE_VALUES (val); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1402 |
428 | 1403 Fset_default (sym, val); |
1404 | |
1405 UNGCPRO; | |
1406 | |
1407 if (!NILP (args = XCDR (args))) | |
1408 { | |
1409 Lisp_Object doc = XCAR (args); | |
1410 Fput (sym, Qvariable_documentation, doc); | |
1411 if (!NILP (args = XCDR (args))) | |
563 | 1412 signal_error (Qwrong_number_of_arguments, "too many arguments", Qunbound); |
428 | 1413 } |
1414 | |
1415 #ifdef I18N3 | |
1416 if (!NILP (Vfile_domain)) | |
1417 Fput (sym, Qvariable_domain, Vfile_domain); | |
1418 #endif | |
1419 | |
1420 LOADHIST_ATTACH (sym); | |
1421 return sym; | |
1422 } | |
1423 | |
4502
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4162
diff
changeset
|
1424 /* XEmacs: user-variable-p is in symbols.c, since it needs to mess around |
8748a3f7ceb4
Handle varalias chains, custom variables in #'user-variable-p.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4162
diff
changeset
|
1425 with the symbol variable aliases. */ |
428 | 1426 |
1427 DEFUN ("macroexpand-internal", Fmacroexpand_internal, 1, 2, 0, /* | |
1428 Return result of expanding macros at top level of FORM. | |
1429 If FORM is not a macro call, it is returned unchanged. | |
1430 Otherwise, the macro is expanded and the expansion is considered | |
1431 in place of FORM. When a non-macro-call results, it is returned. | |
1432 | |
442 | 1433 The second optional arg ENVIRONMENT specifies an environment of macro |
428 | 1434 definitions to shadow the loaded ones for use in file byte-compilation. |
1435 */ | |
442 | 1436 (form, environment)) |
428 | 1437 { |
1438 /* This function can GC */ | |
1439 /* With cleanups from Hallvard Furuseth. */ | |
1440 REGISTER Lisp_Object expander, sym, def, tem; | |
1441 | |
1442 while (1) | |
1443 { | |
1444 /* Come back here each time we expand a macro call, | |
1445 in case it expands into another macro call. */ | |
1446 if (!CONSP (form)) | |
1447 break; | |
1448 /* Set SYM, give DEF and TEM right values in case SYM is not a symbol. */ | |
1449 def = sym = XCAR (form); | |
1450 tem = Qnil; | |
1451 /* Trace symbols aliases to other symbols | |
1452 until we get a symbol that is not an alias. */ | |
1453 while (SYMBOLP (def)) | |
1454 { | |
1455 QUIT; | |
1456 sym = def; | |
442 | 1457 tem = Fassq (sym, environment); |
428 | 1458 if (NILP (tem)) |
1459 { | |
1460 def = XSYMBOL (sym)->function; | |
1461 if (!UNBOUNDP (def)) | |
1462 continue; | |
1463 } | |
1464 break; | |
1465 } | |
442 | 1466 /* Right now TEM is the result from SYM in ENVIRONMENT, |
428 | 1467 and if TEM is nil then DEF is SYM's function definition. */ |
1468 if (NILP (tem)) | |
1469 { | |
442 | 1470 /* SYM is not mentioned in ENVIRONMENT. |
428 | 1471 Look at its function definition. */ |
1472 if (UNBOUNDP (def) | |
1473 || !CONSP (def)) | |
1474 /* Not defined or definition not suitable */ | |
1475 break; | |
1476 if (EQ (XCAR (def), Qautoload)) | |
1477 { | |
1478 /* Autoloading function: will it be a macro when loaded? */ | |
1479 tem = Felt (def, make_int (4)); | |
1480 if (EQ (tem, Qt) || EQ (tem, Qmacro)) | |
1481 { | |
1482 /* Yes, load it and try again. */ | |
970 | 1483 /* do_autoload GCPROs both arguments */ |
428 | 1484 do_autoload (def, sym); |
1485 continue; | |
1486 } | |
1487 else | |
1488 break; | |
1489 } | |
1490 else if (!EQ (XCAR (def), Qmacro)) | |
1491 break; | |
1492 else expander = XCDR (def); | |
1493 } | |
1494 else | |
1495 { | |
1496 expander = XCDR (tem); | |
1497 if (NILP (expander)) | |
1498 break; | |
1499 } | |
1500 form = apply1 (expander, XCDR (form)); | |
1501 } | |
1502 return form; | |
1503 } | |
1504 | |
1505 | |
1506 /************************************************************************/ | |
1507 /* Non-local exits */ | |
1508 /************************************************************************/ | |
1509 | |
1318 | 1510 #ifdef ERROR_CHECK_TRAPPING_PROBLEMS |
1511 | |
1512 int | |
1513 proper_redisplay_wrapping_in_place (void) | |
1514 { | |
1515 return !in_display | |
1516 || ((get_inhibit_flags () & INTERNAL_INHIBIT_ERRORS) | |
1517 && (get_inhibit_flags () & INTERNAL_INHIBIT_THROWS)); | |
1518 } | |
1519 | |
1520 static void | |
1521 check_proper_critical_section_nonlocal_exit_protection (void) | |
1522 { | |
1523 assert_with_message | |
1524 (proper_redisplay_wrapping_in_place (), | |
1525 "Attempted non-local exit from within redisplay without being properly wrapped"); | |
1526 } | |
1527 | |
1528 static void | |
1529 check_proper_critical_section_lisp_protection (void) | |
1530 { | |
1531 assert_with_message | |
1532 (proper_redisplay_wrapping_in_place (), | |
1533 "Attempt to call Lisp code from within redisplay without being properly wrapped"); | |
1534 } | |
1535 | |
1536 #endif /* ERROR_CHECK_TRAPPING_PROBLEMS */ | |
1537 | |
428 | 1538 DEFUN ("catch", Fcatch, 1, UNEVALLED, 0, /* |
1539 \(catch TAG BODY...): eval BODY allowing nonlocal exits using `throw'. | |
1540 TAG is evalled to get the tag to use. Then the BODY is executed. | |
3577 | 1541 Within BODY, (throw TAG VAL) with same (`eq') tag exits BODY and this `catch'. |
428 | 1542 If no throw happens, `catch' returns the value of the last BODY form. |
1543 If a throw happens, it specifies the value to return from `catch'. | |
1544 */ | |
1545 (args)) | |
1546 { | |
1547 /* This function can GC */ | |
1548 Lisp_Object tag = Feval (XCAR (args)); | |
1549 Lisp_Object body = XCDR (args); | |
2532 | 1550 return internal_catch (tag, Fprogn, body, 0, 0, 0); |
428 | 1551 } |
1552 | |
1553 /* Set up a catch, then call C function FUNC on argument ARG. | |
1554 FUNC should return a Lisp_Object. | |
1555 This is how catches are done from within C code. */ | |
1556 | |
1557 Lisp_Object | |
1558 internal_catch (Lisp_Object tag, | |
1559 Lisp_Object (*func) (Lisp_Object arg), | |
1560 Lisp_Object arg, | |
853 | 1561 int * volatile threw, |
2532 | 1562 Lisp_Object * volatile thrown_tag, |
1563 Lisp_Object * volatile backtrace_before_throw) | |
428 | 1564 { |
1565 /* This structure is made part of the chain `catchlist'. */ | |
1566 struct catchtag c; | |
1567 | |
1568 /* Fill in the components of c, and put it on the list. */ | |
1569 c.next = catchlist; | |
1570 c.tag = tag; | |
853 | 1571 c.actual_tag = Qnil; |
2532 | 1572 c.backtrace = Qnil; |
428 | 1573 c.val = Qnil; |
1574 c.backlist = backtrace_list; | |
1575 #if 0 /* FSFmacs */ | |
1576 /* #### */ | |
1577 c.handlerlist = handlerlist; | |
1578 #endif | |
1579 c.lisp_eval_depth = lisp_eval_depth; | |
1580 c.pdlcount = specpdl_depth(); | |
1581 #if 0 /* FSFmacs */ | |
1582 c.poll_suppress_count = async_timer_suppress_count; | |
1583 #endif | |
1584 c.gcpro = gcprolist; | |
1585 catchlist = &c; | |
1586 | |
1587 /* Call FUNC. */ | |
1588 if (SETJMP (c.jmp)) | |
1589 { | |
1590 /* Throw works by a longjmp that comes right here. */ | |
1591 if (threw) *threw = 1; | |
853 | 1592 if (thrown_tag) *thrown_tag = c.actual_tag; |
2532 | 1593 if (backtrace_before_throw) *backtrace_before_throw = c.backtrace; |
428 | 1594 return c.val; |
1595 } | |
1596 c.val = (*func) (arg); | |
1597 if (threw) *threw = 0; | |
853 | 1598 if (thrown_tag) *thrown_tag = Qnil; |
428 | 1599 catchlist = c.next; |
853 | 1600 check_catchlist_sanity (); |
428 | 1601 return c.val; |
1602 } | |
1603 | |
1604 | |
1605 /* Unwind the specbind, catch, and handler stacks back to CATCH, and | |
1606 jump to that CATCH, returning VALUE as the value of that catch. | |
1607 | |
2297 | 1608 This is the guts of Fthrow and Fsignal; they differ only in the |
1609 way they choose the catch tag to throw to. A catch tag for a | |
428 | 1610 condition-case form has a TAG of Qnil. |
1611 | |
1612 Before each catch is discarded, unbind all special bindings and | |
1613 execute all unwind-protect clauses made above that catch. Unwind | |
1614 the handler stack as we go, so that the proper handlers are in | |
1615 effect for each unwind-protect clause we run. At the end, restore | |
1616 some static info saved in CATCH, and longjmp to the location | |
1617 specified in the | |
1618 | |
1619 This is used for correct unwinding in Fthrow and Fsignal. */ | |
1620 | |
2268 | 1621 static DECLARE_DOESNT_RETURN (unwind_to_catch (struct catchtag *, Lisp_Object, |
1622 Lisp_Object)); | |
1623 | |
1624 static DOESNT_RETURN | |
853 | 1625 unwind_to_catch (struct catchtag *c, Lisp_Object val, Lisp_Object tag) |
428 | 1626 { |
1627 REGISTER int last_time; | |
1628 | |
1629 /* Unwind the specbind, catch, and handler stacks back to CATCH | |
1630 Before each catch is discarded, unbind all special bindings | |
1631 and execute all unwind-protect clauses made above that catch. | |
1632 At the end, restore some static info saved in CATCH, | |
1633 and longjmp to the location specified. | |
1634 */ | |
1635 | |
1636 /* Save the value somewhere it will be GC'ed. | |
1637 (Can't overwrite tag slot because an unwind-protect may | |
1638 want to throw to this same tag, which isn't yet invalid.) */ | |
1639 c->val = val; | |
853 | 1640 c->actual_tag = tag; |
428 | 1641 |
1642 #if 0 /* FSFmacs */ | |
1643 /* Restore the polling-suppression count. */ | |
1644 set_poll_suppress_count (catch->poll_suppress_count); | |
1645 #endif | |
1646 | |
617 | 1647 #if 1 |
428 | 1648 do |
1649 { | |
1650 last_time = catchlist == c; | |
1651 | |
1652 /* Unwind the specpdl stack, and then restore the proper set of | |
1653 handlers. */ | |
771 | 1654 unbind_to (catchlist->pdlcount); |
428 | 1655 catchlist = catchlist->next; |
853 | 1656 check_catchlist_sanity (); |
428 | 1657 } |
1658 while (! last_time); | |
617 | 1659 #else |
1660 /* Former XEmacs code. This is definitely not as correct because | |
1661 there may be a number of catches we're unwinding, and a number | |
1662 of unwind-protects in the process. By not undoing the catches till | |
1663 the end, there may be invalid catches still current. (This would | |
1664 be a particular problem with code like this: | |
1665 | |
1666 (catch 'foo | |
1667 (call-some-code-which-does... | |
1668 (catch 'bar | |
1669 (unwind-protect | |
1670 (call-some-code-which-does... | |
1671 (catch 'bar | |
1672 (call-some-code-which-does... | |
1673 (throw 'foo nil)))) | |
1674 (throw 'bar nil))))) | |
1675 | |
1676 This would try to throw to the inner (catch 'bar)! | |
1677 | |
1678 --ben | |
1679 */ | |
428 | 1680 /* Unwind the specpdl stack */ |
771 | 1681 unbind_to (c->pdlcount); |
428 | 1682 catchlist = c->next; |
853 | 1683 check_catchlist_sanity (); |
617 | 1684 #endif /* Former code */ |
428 | 1685 |
1204 | 1686 UNWIND_GCPRO_TO (c->gcpro); |
1292 | 1687 if (profiling_active) |
1688 { | |
1689 while (backtrace_list != c->backlist) | |
1690 { | |
1691 profile_record_unwind (backtrace_list); | |
1692 backtrace_list = backtrace_list->next; | |
1693 } | |
1694 } | |
1695 else | |
1696 backtrace_list = c->backlist; | |
428 | 1697 lisp_eval_depth = c->lisp_eval_depth; |
1698 | |
442 | 1699 #ifdef DEFEND_AGAINST_THROW_RECURSION |
428 | 1700 throw_level = 0; |
1701 #endif | |
1702 LONGJMP (c->jmp, 1); | |
1703 } | |
1704 | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1705 DECLARE_DOESNT_RETURN (throw_or_bomb_out (Lisp_Object, Lisp_Object, int, |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1706 Lisp_Object, Lisp_Object)); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1707 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1708 DOESNT_RETURN |
428 | 1709 throw_or_bomb_out (Lisp_Object tag, Lisp_Object val, int bomb_out_p, |
1710 Lisp_Object sig, Lisp_Object data) | |
1711 { | |
442 | 1712 #ifdef DEFEND_AGAINST_THROW_RECURSION |
428 | 1713 /* die if we recurse more than is reasonable */ |
1714 if (++throw_level > 20) | |
2500 | 1715 ABORT (); |
428 | 1716 #endif |
1717 | |
1318 | 1718 #ifdef ERROR_CHECK_TRAPPING_PROBLEMS |
1123 | 1719 check_proper_critical_section_nonlocal_exit_protection (); |
1318 | 1720 #endif |
1123 | 1721 |
428 | 1722 /* If bomb_out_p is t, this is being called from Fsignal as a |
1723 "last resort" when there is no handler for this error and | |
1724 the debugger couldn't be invoked, so we are throwing to | |
3025 | 1725 `top-level'. If this tag doesn't exist (happens during the |
428 | 1726 initialization stages) we would get in an infinite recursive |
1727 Fsignal/Fthrow loop, so instead we bomb out to the | |
1728 really-early-error-handler. | |
1729 | |
1730 Note that in fact the only time that the "last resort" | |
3025 | 1731 occurs is when there's no catch for `top-level' -- the |
1732 `top-level' catch and the catch-all error handler are | |
428 | 1733 established at the same time, in initial_command_loop/ |
1734 top_level_1. | |
1735 | |
853 | 1736 [[#### Fix this horrifitude!]] |
1737 | |
1738 I don't think this is horrifitude, just defensive programming. --ben | |
428 | 1739 */ |
1740 | |
1741 while (1) | |
1742 { | |
1743 REGISTER struct catchtag *c; | |
1744 | |
1745 #if 0 /* FSFmacs */ | |
1746 if (!NILP (tag)) /* #### */ | |
1747 #endif | |
1748 for (c = catchlist; c; c = c->next) | |
1749 { | |
2532 | 1750 if (EQ (c->tag, Vcatch_everything_tag)) |
1751 c->backtrace = maybe_get_trapping_problems_backtrace (); | |
853 | 1752 if (EQ (c->tag, tag) || EQ (c->tag, Vcatch_everything_tag)) |
1753 unwind_to_catch (c, val, tag); | |
428 | 1754 } |
1755 if (!bomb_out_p) | |
1756 tag = Fsignal (Qno_catch, list2 (tag, val)); | |
1757 else | |
1758 call1 (Qreally_early_error_handler, Fcons (sig, data)); | |
1759 } | |
1760 } | |
1761 | |
1762 /* See above, where CATCHLIST is defined, for a description of how | |
1763 Fthrow() works. | |
1764 | |
1765 Fthrow() is also called by Fsignal(), to do a non-local jump | |
1766 back to the appropriate condition-case handler after (maybe) | |
1767 the debugger is entered. In that case, TAG is the value | |
1768 of Vcondition_handlers that was in place just after the | |
1769 condition-case handler was set up. The car of this will be | |
1770 some data referring to the handler: Its car will be Qunbound | |
1771 (thus, this tag can never be generated by Lisp code), and | |
1772 its CDR will be the HANDLERS argument to condition_case_1() | |
1773 (either Qerror, Qt, or a list of handlers as in `condition-case'). | |
1774 This works fine because Fthrow() does not care what TAG was | |
1775 passed to it: it just looks up the catch list for something | |
1776 that is EQ() to TAG. When it finds it, it will longjmp() | |
1777 back to the place that established the catch (in this case, | |
1778 condition_case_1). See below for more info. | |
1779 */ | |
1780 | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1781 DEFUN_NORETURN ("throw", Fthrow, 2, UNEVALLED, 0, /* |
444 | 1782 Throw to the catch for TAG and return VALUE from it. |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1783 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1784 Both TAG and VALUE are evalled, and multiple values in VALUE will be passed |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1785 back. Tags are the same if and only if they are `eq'. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1786 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1787 arguments: (TAG VALUE) |
428 | 1788 */ |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1789 (args)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1790 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1791 int nargs; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1792 Lisp_Object tag, value; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1793 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1794 GET_LIST_LENGTH (args, nargs); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1795 if (nargs != 2) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1796 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1797 Fsignal (Qwrong_number_of_arguments, list2 (Qthrow, make_int (nargs))); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1798 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1799 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1800 tag = IGNORE_MULTIPLE_VALUES (Feval (XCAR(args))); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1801 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1802 value = Feval (XCAR (XCDR (args))); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
1803 |
444 | 1804 throw_or_bomb_out (tag, value, 0, Qnil, Qnil); /* Doesn't return */ |
2268 | 1805 RETURN_NOT_REACHED (Qnil); |
428 | 1806 } |
1807 | |
1808 DEFUN ("unwind-protect", Funwind_protect, 1, UNEVALLED, 0, /* | |
1809 Do BODYFORM, protecting with UNWINDFORMS. | |
1810 Usage looks like (unwind-protect BODYFORM UNWINDFORMS...). | |
1811 If BODYFORM completes normally, its value is returned | |
1812 after executing the UNWINDFORMS. | |
1813 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway. | |
1814 */ | |
1815 (args)) | |
1816 { | |
1817 /* This function can GC */ | |
1818 int speccount = specpdl_depth(); | |
1819 | |
1820 record_unwind_protect (Fprogn, XCDR (args)); | |
771 | 1821 return unbind_to_1 (speccount, Feval (XCAR (args))); |
428 | 1822 } |
1823 | |
1824 | |
1825 /************************************************************************/ | |
1292 | 1826 /* Trapping errors */ |
428 | 1827 /************************************************************************/ |
1828 | |
1829 static Lisp_Object | |
1830 condition_bind_unwind (Lisp_Object loser) | |
1831 { | |
617 | 1832 /* There is no problem freeing stuff here like there is in |
1833 condition_case_unwind(), because there are no outside pointers | |
1834 (like the tag below in the catchlist) pointing to the objects. */ | |
853 | 1835 |
428 | 1836 /* ((handler-fun . handler-args) ... other handlers) */ |
1837 Lisp_Object tem = XCAR (loser); | |
853 | 1838 int first = 1; |
428 | 1839 |
1840 while (CONSP (tem)) | |
1841 { | |
853 | 1842 Lisp_Object victim = tem; |
1843 if (first && OPAQUE_PTRP (XCAR (victim))) | |
1844 free_opaque_ptr (XCAR (victim)); | |
1845 first = 0; | |
1846 tem = XCDR (victim); | |
428 | 1847 free_cons (victim); |
1848 } | |
1849 | |
1850 if (EQ (loser, Vcondition_handlers)) /* may have been rebound to some tail */ | |
853 | 1851 Vcondition_handlers = XCDR (loser); |
1852 | |
1853 free_cons (loser); | |
428 | 1854 return Qnil; |
1855 } | |
1856 | |
1857 static Lisp_Object | |
1858 condition_case_unwind (Lisp_Object loser) | |
1859 { | |
1860 /* ((<unbound> . clauses) ... other handlers */ | |
617 | 1861 /* NO! Doing this now leaves the tag deleted in a still-active |
1862 catch. With the recent changes to unwind_to_catch(), the | |
1863 evil situation might not happen any more; it certainly could | |
1864 happen before because it did. But it's very precarious to rely | |
1865 on something like this. #### Instead we should rewrite, adopting | |
1866 the FSF's mechanism with a struct handler instead of | |
1867 Vcondition_handlers; then we have NO Lisp-object structures used | |
1868 to hold all of the values, and there's no possibility either of | |
1869 crashes from freeing objects too quickly, or objects not getting | |
1870 freed and hanging around till the next GC. | |
1871 | |
1872 In practice, the extra consing here should not matter because | |
1873 it only happens when we throw past the condition-case, which almost | |
1874 always is the result of an error. Most of the time, there will be | |
1875 no error, and we will free the objects below in the main function. | |
1876 | |
1877 --ben | |
1878 | |
1879 DO NOT DO: free_cons (XCAR (loser)); | |
1880 */ | |
1881 | |
428 | 1882 if (EQ (loser, Vcondition_handlers)) /* may have been rebound to some tail */ |
617 | 1883 Vcondition_handlers = XCDR (loser); |
1884 | |
1885 /* DO NOT DO: free_cons (loser); */ | |
428 | 1886 return Qnil; |
1887 } | |
1888 | |
1889 /* Split out from condition_case_3 so that primitive C callers | |
1890 don't have to cons up a lisp handler form to be evaluated. */ | |
1891 | |
1892 /* Call a function BFUN of one argument BARG, trapping errors as | |
1893 specified by HANDLERS. If no error occurs that is indicated by | |
1894 HANDLERS as something to be caught, the return value of this | |
1895 function is the return value from BFUN. If such an error does | |
1896 occur, HFUN is called, and its return value becomes the | |
1897 return value of condition_case_1(). The second argument passed | |
1898 to HFUN will always be HARG. The first argument depends on | |
1899 HANDLERS: | |
1900 | |
1901 If HANDLERS is Qt, all errors (this includes QUIT, but not | |
1902 non-local exits with `throw') cause HFUN to be invoked, and VAL | |
1903 (the first argument to HFUN) is a cons (SIG . DATA) of the | |
1904 arguments passed to `signal'. The debugger is not invoked even if | |
1905 `debug-on-error' was set. | |
1906 | |
1907 A HANDLERS value of Qerror is the same as Qt except that the | |
1908 debugger is invoked if `debug-on-error' was set. | |
1909 | |
1910 Otherwise, HANDLERS should be a list of lists (CONDITION-NAME BODY ...) | |
1911 exactly as in `condition-case', and errors will be trapped | |
1912 as indicated in HANDLERS. VAL (the first argument to HFUN) will | |
1913 be a cons whose car is the cons (SIG . DATA) and whose CDR is the | |
1914 list (BODY ...) from the appropriate slot in HANDLERS. | |
1915 | |
1916 This function pushes HANDLERS onto the front of Vcondition_handlers | |
1917 (actually with a Qunbound marker as well -- see Fthrow() above | |
1918 for why), establishes a catch whose tag is this new value of | |
1919 Vcondition_handlers, and calls BFUN. When Fsignal() is called, | |
1920 it calls Fthrow(), setting TAG to this same new value of | |
1921 Vcondition_handlers and setting VAL to the same thing that will | |
1922 be passed to HFUN, as above. Fthrow() longjmp()s back to the | |
1923 jump point we just established, and we in turn just call the | |
1924 HFUN and return its value. | |
1925 | |
1926 For a real condition-case, HFUN will always be | |
1927 run_condition_case_handlers() and HARG is the argument VAR | |
1928 to condition-case. That function just binds VAR to the cons | |
1929 (SIG . DATA) that is the CAR of VAL, and calls the handler | |
1930 (BODY ...) that is the CDR of VAL. Note that before calling | |
1931 Fthrow(), Fsignal() restored Vcondition_handlers to the value | |
1932 it had *before* condition_case_1() was called. This maintains | |
1933 consistency (so that the state of things at exit of | |
1934 condition_case_1() is the same as at entry), and implies | |
1935 that the handler can signal the same error again (possibly | |
1936 after processing of its own), without getting in an infinite | |
1937 loop. */ | |
1938 | |
1939 Lisp_Object | |
1940 condition_case_1 (Lisp_Object handlers, | |
1941 Lisp_Object (*bfun) (Lisp_Object barg), | |
1942 Lisp_Object barg, | |
1943 Lisp_Object (*hfun) (Lisp_Object val, Lisp_Object harg), | |
1944 Lisp_Object harg) | |
1945 { | |
1946 int speccount = specpdl_depth(); | |
1947 struct catchtag c; | |
617 | 1948 struct gcpro gcpro1, gcpro2, gcpro3; |
428 | 1949 |
1950 #if 0 /* FSFmacs */ | |
1951 c.tag = Qnil; | |
1952 #else | |
1953 /* Do consing now so out-of-memory error happens up front */ | |
1954 /* (unbound . stuff) is a special condition-case kludge marker | |
1955 which is known specially by Fsignal. | |
617 | 1956 [[ This is an abomination, but to fix it would require either |
428 | 1957 making condition_case cons (a union of the conditions of the clauses) |
617 | 1958 or changing the byte-compiler output (no thanks).]] |
1959 | |
1960 The above comment is clearly wrong. FSF does not do it this way | |
1961 and did not change the byte-compiler output. Instead they use a | |
1962 `struct handler' to hold the various values (in place of our | |
1963 Vcondition_handlers) and chain them together, with pointers from | |
1964 the `struct catchtag' to the `struct handler'. We should perhaps | |
1965 consider moving to something similar, but not before I merge my | |
1966 stderr-proc workspace, which contains changes to these | |
1967 functions. --ben */ | |
428 | 1968 c.tag = noseeum_cons (noseeum_cons (Qunbound, handlers), |
1969 Vcondition_handlers); | |
1970 #endif | |
1971 c.val = Qnil; | |
853 | 1972 c.actual_tag = Qnil; |
2532 | 1973 c.backtrace = Qnil; |
428 | 1974 c.backlist = backtrace_list; |
1975 #if 0 /* FSFmacs */ | |
1976 /* #### */ | |
1977 c.handlerlist = handlerlist; | |
1978 #endif | |
1979 c.lisp_eval_depth = lisp_eval_depth; | |
1980 c.pdlcount = specpdl_depth(); | |
1981 #if 0 /* FSFmacs */ | |
1982 c.poll_suppress_count = async_timer_suppress_count; | |
1983 #endif | |
1984 c.gcpro = gcprolist; | |
1985 /* #### FSFmacs does the following statement *after* the setjmp(). */ | |
1986 c.next = catchlist; | |
1987 | |
1988 if (SETJMP (c.jmp)) | |
1989 { | |
1990 /* throw does ungcpro, etc */ | |
1991 return (*hfun) (c.val, harg); | |
1992 } | |
1993 | |
1994 record_unwind_protect (condition_case_unwind, c.tag); | |
1995 | |
1996 catchlist = &c; | |
1997 #if 0 /* FSFmacs */ | |
1998 h.handler = handlers; | |
1999 h.var = Qnil; | |
2000 h.next = handlerlist; | |
2001 h.tag = &c; | |
2002 handlerlist = &h; | |
2003 #else | |
2004 Vcondition_handlers = c.tag; | |
2005 #endif | |
2006 GCPRO1 (harg); /* Somebody has to gc-protect */ | |
2007 c.val = ((*bfun) (barg)); | |
2008 UNGCPRO; | |
617 | 2009 |
2010 /* Once we change `catchlist' below, the stuff in c will not be GCPRO'd. */ | |
2011 GCPRO3 (harg, c.val, c.tag); | |
2012 | |
428 | 2013 catchlist = c.next; |
853 | 2014 check_catchlist_sanity (); |
617 | 2015 /* Note: The unbind also resets Vcondition_handlers. Maybe we should |
2016 delete this here. */ | |
428 | 2017 Vcondition_handlers = XCDR (c.tag); |
771 | 2018 unbind_to (speccount); |
617 | 2019 |
2020 UNGCPRO; | |
2021 /* free the conses *after* the unbind, because the unbind will run | |
2022 condition_case_unwind above. */ | |
853 | 2023 free_cons (XCAR (c.tag)); |
2024 free_cons (c.tag); | |
617 | 2025 return c.val; |
428 | 2026 } |
2027 | |
2028 static Lisp_Object | |
2029 run_condition_case_handlers (Lisp_Object val, Lisp_Object var) | |
2030 { | |
2031 /* This function can GC */ | |
2032 #if 0 /* FSFmacs */ | |
2033 if (!NILP (h.var)) | |
2034 specbind (h.var, c.val); | |
2035 val = Fprogn (Fcdr (h.chosen_clause)); | |
2036 | |
2037 /* Note that this just undoes the binding of h.var; whoever | |
2038 longjmp()ed to us unwound the stack to c.pdlcount before | |
2039 throwing. */ | |
771 | 2040 unbind_to (c.pdlcount); |
428 | 2041 return val; |
2042 #else | |
2043 int speccount; | |
2044 | |
2045 CHECK_TRUE_LIST (val); | |
2046 if (NILP (var)) | |
2047 return Fprogn (Fcdr (val)); /* tail call */ | |
2048 | |
2049 speccount = specpdl_depth(); | |
2050 specbind (var, Fcar (val)); | |
2051 val = Fprogn (Fcdr (val)); | |
771 | 2052 return unbind_to_1 (speccount, val); |
428 | 2053 #endif |
2054 } | |
2055 | |
2056 /* Here for bytecode to call non-consfully. This is exactly like | |
2057 condition-case except that it takes three arguments rather | |
2058 than a single list of arguments. */ | |
2059 Lisp_Object | |
2060 condition_case_3 (Lisp_Object bodyform, Lisp_Object var, Lisp_Object handlers) | |
2061 { | |
2062 /* This function can GC */ | |
2063 EXTERNAL_LIST_LOOP_2 (handler, handlers) | |
2064 { | |
2065 if (NILP (handler)) | |
2066 ; | |
2067 else if (CONSP (handler)) | |
2068 { | |
2069 Lisp_Object conditions = XCAR (handler); | |
2070 /* CONDITIONS must a condition name or a list of condition names */ | |
2071 if (SYMBOLP (conditions)) | |
2072 ; | |
2073 else | |
2074 { | |
2075 EXTERNAL_LIST_LOOP_2 (condition, conditions) | |
2076 if (!SYMBOLP (condition)) | |
2077 goto invalid_condition_handler; | |
2078 } | |
2079 } | |
2080 else | |
2081 { | |
2082 invalid_condition_handler: | |
563 | 2083 sferror ("Invalid condition handler", handler); |
428 | 2084 } |
2085 } | |
2086 | |
2087 CHECK_SYMBOL (var); | |
2088 | |
2089 return condition_case_1 (handlers, | |
2090 Feval, bodyform, | |
2091 run_condition_case_handlers, | |
2092 var); | |
2093 } | |
2094 | |
2095 DEFUN ("condition-case", Fcondition_case, 2, UNEVALLED, 0, /* | |
2096 Regain control when an error is signalled. | |
2097 Usage looks like (condition-case VAR BODYFORM HANDLERS...). | |
2098 Executes BODYFORM and returns its value if no error happens. | |
2099 Each element of HANDLERS looks like (CONDITION-NAME BODY...) | |
2100 where the BODY is made of Lisp expressions. | |
2101 | |
771 | 2102 A typical usage of `condition-case' looks like this: |
2103 | |
2104 (condition-case nil | |
2105 ;; you need a progn here if you want more than one statement ... | |
2106 (progn | |
2107 (do-something) | |
2108 (do-something-else)) | |
2109 (error | |
2110 (issue-warning-or) | |
2111 ;; but strangely, you don't need one here. | |
2112 (return-a-value-etc) | |
2113 )) | |
2114 | |
428 | 2115 A handler is applicable to an error if CONDITION-NAME is one of the |
2116 error's condition names. If an error happens, the first applicable | |
2117 handler is run. As a special case, a CONDITION-NAME of t matches | |
2118 all errors, even those without the `error' condition name on them | |
2119 \(e.g. `quit'). | |
2120 | |
2121 The car of a handler may be a list of condition names | |
2122 instead of a single condition name. | |
2123 | |
2124 When a handler handles an error, | |
2125 control returns to the condition-case and the handler BODY... is executed | |
2126 with VAR bound to (SIGNALED-CONDITIONS . SIGNAL-DATA). | |
2127 VAR may be nil; then you do not get access to the signal information. | |
2128 | |
2129 The value of the last BODY form is returned from the condition-case. | |
2130 See also the function `signal' for more info. | |
2131 | |
2132 Note that at the time the condition handler is invoked, the Lisp stack | |
2133 and the current catches, condition-cases, and bindings have all been | |
2134 popped back to the state they were in just before the call to | |
2135 `condition-case'. This means that resignalling the error from | |
2136 within the handler will not result in an infinite loop. | |
2137 | |
2138 If you want to establish an error handler that is called with the | |
2139 Lisp stack, bindings, etc. as they were when `signal' was called, | |
2140 rather than when the handler was set, use `call-with-condition-handler'. | |
2141 */ | |
2142 (args)) | |
2143 { | |
2144 /* This function can GC */ | |
2145 Lisp_Object var = XCAR (args); | |
2146 Lisp_Object bodyform = XCAR (XCDR (args)); | |
2147 Lisp_Object handlers = XCDR (XCDR (args)); | |
2148 return condition_case_3 (bodyform, var, handlers); | |
2149 } | |
2150 | |
2151 DEFUN ("call-with-condition-handler", Fcall_with_condition_handler, 2, MANY, 0, /* | |
2152 Regain control when an error is signalled, without popping the stack. | |
2153 Usage looks like (call-with-condition-handler HANDLER FUNCTION &rest ARGS). | |
2154 This function is similar to `condition-case', but the handler is invoked | |
2155 with the same environment (Lisp stack, bindings, catches, condition-cases) | |
2156 that was current when `signal' was called, rather than when the handler | |
2157 was established. | |
2158 | |
2159 HANDLER should be a function of one argument, which is a cons of the args | |
2160 \(SIG . DATA) that were passed to `signal'. It is invoked whenever | |
2161 `signal' is called (this differs from `condition-case', which allows | |
2162 you to specify which errors are trapped). If the handler function | |
2163 returns, `signal' continues as if the handler were never invoked. | |
2164 \(It continues to look for handlers established earlier than this one, | |
2165 and invokes the standard error-handler if none is found.) | |
2166 */ | |
2167 (int nargs, Lisp_Object *args)) /* Note! Args side-effected! */ | |
2168 { | |
2169 /* This function can GC */ | |
2170 int speccount = specpdl_depth(); | |
2171 Lisp_Object tem; | |
2172 | |
853 | 2173 tem = Ffunction_max_args (args[0]); |
2174 if (! (XINT (Ffunction_min_args (args[0])) <= 1 | |
2175 && (NILP (tem) || 1 <= XINT (tem)))) | |
2176 invalid_argument ("Must be function of one argument", args[0]); | |
2177 | |
2178 /* (handler-fun . handler-args) but currently there are no handler-args */ | |
428 | 2179 tem = noseeum_cons (list1 (args[0]), Vcondition_handlers); |
2180 record_unwind_protect (condition_bind_unwind, tem); | |
2181 Vcondition_handlers = tem; | |
2182 | |
2183 /* Caller should have GC-protected args */ | |
771 | 2184 return unbind_to_1 (speccount, Ffuncall (nargs - 1, args + 1)); |
428 | 2185 } |
2186 | |
853 | 2187 /* This is the C version of the above function. It calls FUN, passing it |
2188 ARG, first setting up HANDLER to catch signals in the environment in | |
2189 which they were signalled. (HANDLER is only invoked if there was no | |
2190 handler (either from condition-case or call-with-condition-handler) set | |
2191 later on that handled the signal; therefore, this is a real error. | |
2192 | |
2193 HANDLER is invoked with three arguments: the ERROR-SYMBOL and DATA as | |
2194 passed to `signal', and HANDLER_ARG. Originally I made HANDLER_ARG and | |
2195 ARG be void * to facilitate passing structures, but I changed to | |
2196 Lisp_Objects because all the other C interfaces to catch/condition-case/etc. | |
2197 take Lisp_Objects, and it is easy enough to use make_opaque_ptr() et al. | |
2198 to convert between Lisp_Objects and structure pointers. */ | |
2199 | |
2200 Lisp_Object | |
2201 call_with_condition_handler (Lisp_Object (*handler) (Lisp_Object, Lisp_Object, | |
2202 Lisp_Object), | |
2203 Lisp_Object handler_arg, | |
2204 Lisp_Object (*fun) (Lisp_Object), | |
2205 Lisp_Object arg) | |
2206 { | |
2207 /* This function can GC */ | |
1111 | 2208 int speccount = specpdl_depth (); |
853 | 2209 Lisp_Object tem; |
2210 | |
2211 /* ((handler-fun . (handler-arg . nil)) ... ) */ | |
1111 | 2212 tem = noseeum_cons (noseeum_cons (make_opaque_ptr ((void *) handler), |
853 | 2213 noseeum_cons (handler_arg, Qnil)), |
2214 Vcondition_handlers); | |
2215 record_unwind_protect (condition_bind_unwind, tem); | |
2216 Vcondition_handlers = tem; | |
2217 | |
2218 return unbind_to_1 (speccount, (*fun) (arg)); | |
2219 } | |
2220 | |
428 | 2221 static int |
2222 condition_type_p (Lisp_Object type, Lisp_Object conditions) | |
2223 { | |
2224 if (EQ (type, Qt)) | |
2225 /* (condition-case c # (t c)) catches -all- signals | |
2226 * Use with caution! */ | |
2227 return 1; | |
2228 | |
2229 if (SYMBOLP (type)) | |
2230 return !NILP (Fmemq (type, conditions)); | |
2231 | |
2232 for (; CONSP (type); type = XCDR (type)) | |
2233 if (!NILP (Fmemq (XCAR (type), conditions))) | |
2234 return 1; | |
2235 | |
2236 return 0; | |
2237 } | |
2238 | |
2239 static Lisp_Object | |
2240 return_from_signal (Lisp_Object value) | |
2241 { | |
2242 #if 1 | |
2243 /* Most callers are not prepared to handle gc if this | |
2244 returns. So, since this feature is not very useful, | |
2245 take it out. */ | |
2246 /* Have called debugger; return value to signaller */ | |
2247 return value; | |
2248 #else /* But the reality is that that stinks, because: */ | |
2249 /* GACK!!! Really want some way for debug-on-quit errors | |
2250 to be continuable!! */ | |
563 | 2251 signal_error (Qunimplemented, |
2252 "Returning a value from an error is no longer supported", | |
2253 Qunbound); | |
428 | 2254 #endif |
2255 } | |
2256 | |
2257 | |
2258 /************************************************************************/ | |
2259 /* the workhorse error-signaling function */ | |
2260 /************************************************************************/ | |
2261 | |
853 | 2262 /* This exists only for debugging purposes, as a place to put a breakpoint |
2263 that won't get signalled for errors occurring when | |
2264 call_with_suspended_errors() was invoked. */ | |
2265 | |
872 | 2266 /* Don't make static or it might be compiled away */ |
2267 void signal_1 (void); | |
2268 | |
2269 void | |
853 | 2270 signal_1 (void) |
2271 { | |
2272 } | |
2273 | |
428 | 2274 /* #### This function has not been synched with FSF. It diverges |
2275 significantly. */ | |
2276 | |
853 | 2277 /* The simplest external error function: it would be called |
2278 signal_continuable_error() in the terminology below, but it's | |
2279 Lisp-callable. */ | |
2280 | |
2281 DEFUN ("signal", Fsignal, 2, 2, 0, /* | |
2282 Signal a continuable error. Args are ERROR-SYMBOL, and associated DATA. | |
2283 An error symbol is a symbol defined using `define-error'. | |
2284 DATA should be a list. Its elements are printed as part of the error message. | |
2285 If the signal is handled, DATA is made available to the handler. | |
2286 See also the function `signal-error', and the functions to handle errors: | |
2287 `condition-case' and `call-with-condition-handler'. | |
2288 | |
2289 Note that this function can return, if the debugger is invoked and the | |
2290 user invokes the "return from signal" option. | |
2291 */ | |
2292 (error_symbol, data)) | |
428 | 2293 { |
2294 /* This function can GC */ | |
853 | 2295 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; |
2296 Lisp_Object conditions = Qnil; | |
2297 Lisp_Object handlers = Qnil; | |
428 | 2298 /* signal_call_debugger() could get called more than once |
2299 (once when a call-with-condition-handler is about to | |
2300 be dealt with, and another when a condition-case handler | |
2301 is about to be invoked). So make sure the debugger and/or | |
2302 stack trace aren't done more than once. */ | |
2303 int stack_trace_displayed = 0; | |
2304 int debugger_entered = 0; | |
853 | 2305 |
2306 /* Fsignal() is one of these functions that's called all the time | |
2307 with newly-created Lisp objects. We allow this; but we must GC- | |
2308 protect the objects because all sorts of weird stuff could | |
2309 happen. */ | |
2310 | |
2311 GCPRO4 (conditions, handlers, error_symbol, data); | |
2312 | |
2313 if (!(inhibit_flags & CALL_WITH_SUSPENDED_ERRORS)) | |
2314 signal_1 (); | |
428 | 2315 |
2316 if (!initialized) | |
2317 { | |
2318 /* who knows how much has been initialized? Safest bet is | |
2319 just to bomb out immediately. */ | |
771 | 2320 stderr_out ("Error before initialization is complete!\n"); |
2500 | 2321 ABORT (); |
428 | 2322 } |
2323 | |
3092 | 2324 #ifndef NEW_GC |
1123 | 2325 assert (!gc_in_progress); |
3092 | 2326 #endif /* not NEW_GC */ |
1123 | 2327 |
2328 /* We abort if in_display and we are not protected, as garbage | |
2329 collections and non-local exits will invariably be fatal, but in | |
2330 messy, difficult-to-debug ways. See enter_redisplay_critical_section(). | |
2331 */ | |
2332 | |
1318 | 2333 #ifdef ERROR_CHECK_TRAPPING_PROBLEMS |
1123 | 2334 check_proper_critical_section_nonlocal_exit_protection (); |
1318 | 2335 #endif |
428 | 2336 |
853 | 2337 conditions = Fget (error_symbol, Qerror_conditions, Qnil); |
428 | 2338 |
2339 for (handlers = Vcondition_handlers; | |
2340 CONSP (handlers); | |
2341 handlers = XCDR (handlers)) | |
2342 { | |
2343 Lisp_Object handler_fun = XCAR (XCAR (handlers)); | |
2344 Lisp_Object handler_data = XCDR (XCAR (handlers)); | |
2345 Lisp_Object outer_handlers = XCDR (handlers); | |
2346 | |
2347 if (!UNBOUNDP (handler_fun)) | |
2348 { | |
2349 /* call-with-condition-handler */ | |
2350 Lisp_Object tem; | |
2351 Lisp_Object all_handlers = Vcondition_handlers; | |
2352 struct gcpro ngcpro1; | |
2353 NGCPRO1 (all_handlers); | |
2354 Vcondition_handlers = outer_handlers; | |
2355 | |
853 | 2356 tem = signal_call_debugger (conditions, error_symbol, data, |
428 | 2357 outer_handlers, 1, |
2358 &stack_trace_displayed, | |
2359 &debugger_entered); | |
2360 if (!UNBOUNDP (tem)) | |
2361 RETURN_NUNGCPRO (return_from_signal (tem)); | |
2362 | |
853 | 2363 if (OPAQUE_PTRP (handler_fun)) |
2364 { | |
2365 if (NILP (handler_data)) | |
2366 { | |
2367 Lisp_Object (*hfun) (Lisp_Object, Lisp_Object) = | |
2368 (Lisp_Object (*) (Lisp_Object, Lisp_Object)) | |
2369 (get_opaque_ptr (handler_fun)); | |
2370 | |
2371 tem = (*hfun) (error_symbol, data); | |
2372 } | |
2373 else | |
2374 { | |
2375 Lisp_Object (*hfun) (Lisp_Object, Lisp_Object, Lisp_Object) = | |
2376 (Lisp_Object (*) (Lisp_Object, Lisp_Object, Lisp_Object)) | |
2377 (get_opaque_ptr (handler_fun)); | |
2378 | |
2379 assert (NILP (XCDR (handler_data))); | |
2380 tem = (*hfun) (error_symbol, data, XCAR (handler_data)); | |
2381 } | |
2382 } | |
2383 else | |
2384 { | |
2385 tem = Fcons (error_symbol, data); | |
2386 if (NILP (handler_data)) | |
2387 tem = call1 (handler_fun, tem); | |
2388 else | |
2389 { | |
2390 /* (This code won't be used (for now?).) */ | |
2391 struct gcpro nngcpro1; | |
2392 Lisp_Object args[3]; | |
2393 NNGCPRO1 (args[0]); | |
2394 nngcpro1.nvars = 3; | |
2395 args[0] = handler_fun; | |
2396 args[1] = tem; | |
2397 args[2] = handler_data; | |
2398 nngcpro1.var = args; | |
2399 tem = Fapply (3, args); | |
2400 NNUNGCPRO; | |
2401 } | |
2402 } | |
428 | 2403 NUNGCPRO; |
2404 #if 0 | |
2405 if (!EQ (tem, Qsignal)) | |
2406 return return_from_signal (tem); | |
2407 #endif | |
2408 /* If handler didn't throw, try another handler */ | |
2409 Vcondition_handlers = all_handlers; | |
2410 } | |
2411 | |
2412 /* It's a condition-case handler */ | |
2413 | |
2414 /* t is used by handlers for all conditions, set up by C code. | |
2415 * debugger is not called even if debug_on_error */ | |
2416 else if (EQ (handler_data, Qt)) | |
2417 { | |
2418 UNGCPRO; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
2419 throw_or_bomb_out (handlers, Fcons (error_symbol, data), |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
2420 0, Qnil, Qnil); |
428 | 2421 } |
2422 /* `error' is used similarly to the way `t' is used, but in | |
2423 addition it invokes the debugger if debug_on_error. | |
2424 This is normally used for the outer command-loop error | |
2425 handler. */ | |
2426 else if (EQ (handler_data, Qerror)) | |
2427 { | |
853 | 2428 Lisp_Object tem = signal_call_debugger (conditions, error_symbol, |
2429 data, | |
428 | 2430 outer_handlers, 0, |
2431 &stack_trace_displayed, | |
2432 &debugger_entered); | |
2433 | |
2434 UNGCPRO; | |
2435 if (!UNBOUNDP (tem)) | |
2436 return return_from_signal (tem); | |
2437 | |
853 | 2438 tem = Fcons (error_symbol, data); |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
2439 throw_or_bomb_out (handlers, tem, 0, Qnil, Qnil); |
428 | 2440 } |
2441 else | |
2442 { | |
2443 /* handler established by real (Lisp) condition-case */ | |
2444 Lisp_Object h; | |
2445 | |
2446 for (h = handler_data; CONSP (h); h = Fcdr (h)) | |
2447 { | |
2448 Lisp_Object clause = Fcar (h); | |
2449 Lisp_Object tem = Fcar (clause); | |
2450 | |
2451 if (condition_type_p (tem, conditions)) | |
2452 { | |
853 | 2453 tem = signal_call_debugger (conditions, error_symbol, data, |
428 | 2454 outer_handlers, 1, |
2455 &stack_trace_displayed, | |
2456 &debugger_entered); | |
2457 UNGCPRO; | |
2458 if (!UNBOUNDP (tem)) | |
2459 return return_from_signal (tem); | |
2460 | |
2461 /* Doesn't return */ | |
853 | 2462 tem = Fcons (Fcons (error_symbol, data), Fcdr (clause)); |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
2463 throw_or_bomb_out (handlers, tem, 0, Qnil, Qnil); |
428 | 2464 } |
2465 } | |
2466 } | |
2467 } | |
2468 | |
2469 /* If no handler is present now, try to run the debugger, | |
2470 and if that fails, throw to top level. | |
2471 | |
2472 #### The only time that no handler is present is during | |
2473 temacs or perhaps very early in XEmacs. In both cases, | |
3025 | 2474 there is no `top-level' catch. (That's why the |
428 | 2475 "bomb-out" hack was added.) |
2476 | |
853 | 2477 [[#### Fix this horrifitude!]] |
2478 | |
2479 I don't think this is horrifitude, but just defensive coding. --ben */ | |
2480 | |
2481 signal_call_debugger (conditions, error_symbol, data, Qnil, 0, | |
428 | 2482 &stack_trace_displayed, |
2483 &debugger_entered); | |
2484 UNGCPRO; | |
853 | 2485 throw_or_bomb_out (Qtop_level, Qt, 1, error_symbol, |
2486 data); /* Doesn't return */ | |
2268 | 2487 RETURN_NOT_REACHED (Qnil); |
428 | 2488 } |
2489 | |
2490 /****************** Error functions class 1 ******************/ | |
2491 | |
2492 /* Class 1: General functions that signal an error. | |
2493 These functions take an error type and a list of associated error | |
2494 data. */ | |
2495 | |
853 | 2496 /* No signal_continuable_error_1(); it's called Fsignal(). */ |
428 | 2497 |
2498 /* Signal a non-continuable error. */ | |
2499 | |
2500 DOESNT_RETURN | |
563 | 2501 signal_error_1 (Lisp_Object sig, Lisp_Object data) |
428 | 2502 { |
2503 for (;;) | |
2504 Fsignal (sig, data); | |
2505 } | |
853 | 2506 |
2507 #ifdef ERROR_CHECK_CATCH | |
2508 | |
2509 void | |
2510 check_catchlist_sanity (void) | |
2511 { | |
2512 #if 0 | |
2513 /* vou me tomar no cu! i just masked andy's missing-unbind | |
2514 bug! */ | |
442 | 2515 struct catchtag *c; |
2516 int found_error_tag = 0; | |
2517 | |
2518 for (c = catchlist; c; c = c->next) | |
2519 { | |
2520 if (EQ (c->tag, Qunbound_suspended_errors_tag)) | |
2521 { | |
2522 found_error_tag = 1; | |
2523 break; | |
2524 } | |
2525 } | |
2526 | |
2527 assert (found_error_tag || NILP (Vcurrent_error_state)); | |
853 | 2528 #endif /* vou me tomar no cul */ |
2529 } | |
2530 | |
2531 void | |
2532 check_specbind_stack_sanity (void) | |
2533 { | |
2534 } | |
2535 | |
2536 #endif /* ERROR_CHECK_CATCH */ | |
428 | 2537 |
2538 /* Signal a non-continuable error or display a warning or do nothing, | |
2539 according to ERRB. CLASS is the class of warning and should | |
2540 refer to what sort of operation is being done (e.g. Qtoolbar, | |
2541 Qresource, etc.). */ | |
2542 | |
2543 void | |
1204 | 2544 maybe_signal_error_1 (Lisp_Object sig, Lisp_Object data, Lisp_Object class_, |
578 | 2545 Error_Behavior errb) |
428 | 2546 { |
2547 if (ERRB_EQ (errb, ERROR_ME_NOT)) | |
2548 return; | |
793 | 2549 else if (ERRB_EQ (errb, ERROR_ME_DEBUG_WARN)) |
1204 | 2550 warn_when_safe_lispobj (class_, Qdebug, Fcons (sig, data)); |
428 | 2551 else if (ERRB_EQ (errb, ERROR_ME_WARN)) |
1204 | 2552 warn_when_safe_lispobj (class_, Qwarning, Fcons (sig, data)); |
428 | 2553 else |
2554 for (;;) | |
2555 Fsignal (sig, data); | |
2556 } | |
2557 | |
2558 /* Signal a continuable error or display a warning or do nothing, | |
2559 according to ERRB. */ | |
2560 | |
2561 Lisp_Object | |
563 | 2562 maybe_signal_continuable_error_1 (Lisp_Object sig, Lisp_Object data, |
1204 | 2563 Lisp_Object class_, Error_Behavior errb) |
428 | 2564 { |
2565 if (ERRB_EQ (errb, ERROR_ME_NOT)) | |
2566 return Qnil; | |
793 | 2567 else if (ERRB_EQ (errb, ERROR_ME_DEBUG_WARN)) |
2568 { | |
1204 | 2569 warn_when_safe_lispobj (class_, Qdebug, Fcons (sig, data)); |
793 | 2570 return Qnil; |
2571 } | |
428 | 2572 else if (ERRB_EQ (errb, ERROR_ME_WARN)) |
2573 { | |
1204 | 2574 warn_when_safe_lispobj (class_, Qwarning, Fcons (sig, data)); |
428 | 2575 return Qnil; |
2576 } | |
2577 else | |
2578 return Fsignal (sig, data); | |
2579 } | |
2580 | |
2581 | |
2582 /****************** Error functions class 2 ******************/ | |
2583 | |
563 | 2584 /* Class 2: Signal an error with a string and an associated object. |
2585 Normally these functions are used to attach one associated object, | |
2586 but to attach no objects, specify Qunbound for FROB, and for more | |
2587 than one object, make a list of the objects with Qunbound as the | |
2588 first element. (If you have specifically two objects to attach, | |
2589 consider using the function in class 3 below.) These functions | |
2590 signal an error of a specified type, whose data is one or more | |
2591 objects (usually two), a string the related Lisp object(s) | |
2592 specified as FROB. */ | |
2593 | |
2594 /* Out of REASON and FROB, return a list of elements suitable for passing | |
2595 to signal_error_1(). */ | |
2596 | |
2597 Lisp_Object | |
867 | 2598 build_error_data (const CIbyte *reason, Lisp_Object frob) |
563 | 2599 { |
2600 if (EQ (frob, Qunbound)) | |
2601 frob = Qnil; | |
2602 else if (CONSP (frob) && EQ (XCAR (frob), Qunbound)) | |
2603 frob = XCDR (frob); | |
2604 else | |
2605 frob = list1 (frob); | |
2606 if (!reason) | |
2607 return frob; | |
2608 else | |
771 | 2609 return Fcons (build_msg_string (reason), frob); |
563 | 2610 } |
2611 | |
2612 DOESNT_RETURN | |
867 | 2613 signal_error (Lisp_Object type, const CIbyte *reason, Lisp_Object frob) |
563 | 2614 { |
2615 signal_error_1 (type, build_error_data (reason, frob)); | |
2616 } | |
2617 | |
2618 void | |
867 | 2619 maybe_signal_error (Lisp_Object type, const CIbyte *reason, |
1204 | 2620 Lisp_Object frob, Lisp_Object class_, |
578 | 2621 Error_Behavior errb) |
563 | 2622 { |
2623 /* Optimization: */ | |
2624 if (ERRB_EQ (errb, ERROR_ME_NOT)) | |
2625 return; | |
1204 | 2626 maybe_signal_error_1 (type, build_error_data (reason, frob), class_, errb); |
563 | 2627 } |
2628 | |
2629 Lisp_Object | |
867 | 2630 signal_continuable_error (Lisp_Object type, const CIbyte *reason, |
563 | 2631 Lisp_Object frob) |
2632 { | |
2633 return Fsignal (type, build_error_data (reason, frob)); | |
2634 } | |
2635 | |
2636 Lisp_Object | |
867 | 2637 maybe_signal_continuable_error (Lisp_Object type, const CIbyte *reason, |
1204 | 2638 Lisp_Object frob, Lisp_Object class_, |
578 | 2639 Error_Behavior errb) |
563 | 2640 { |
2641 /* Optimization: */ | |
2642 if (ERRB_EQ (errb, ERROR_ME_NOT)) | |
2643 return Qnil; | |
2644 return maybe_signal_continuable_error_1 (type, | |
2645 build_error_data (reason, frob), | |
1204 | 2646 class_, errb); |
563 | 2647 } |
2648 | |
2649 | |
2650 /****************** Error functions class 3 ******************/ | |
2651 | |
2652 /* Class 3: Signal an error with a string and two associated objects. | |
2653 These functions signal an error of a specified type, whose data | |
2654 is three objects, a string and two related Lisp objects. | |
2655 (The equivalent could be accomplished using the class 2 functions, | |
2656 but these are more convenient in this particular case.) */ | |
2657 | |
2658 DOESNT_RETURN | |
867 | 2659 signal_error_2 (Lisp_Object type, const CIbyte *reason, |
563 | 2660 Lisp_Object frob0, Lisp_Object frob1) |
2661 { | |
771 | 2662 signal_error_1 (type, list3 (build_msg_string (reason), frob0, |
563 | 2663 frob1)); |
2664 } | |
2665 | |
2666 void | |
867 | 2667 maybe_signal_error_2 (Lisp_Object type, const CIbyte *reason, |
563 | 2668 Lisp_Object frob0, Lisp_Object frob1, |
1204 | 2669 Lisp_Object class_, Error_Behavior errb) |
563 | 2670 { |
2671 /* Optimization: */ | |
2672 if (ERRB_EQ (errb, ERROR_ME_NOT)) | |
2673 return; | |
771 | 2674 maybe_signal_error_1 (type, list3 (build_msg_string (reason), frob0, |
1204 | 2675 frob1), class_, errb); |
563 | 2676 } |
2677 | |
2678 Lisp_Object | |
867 | 2679 signal_continuable_error_2 (Lisp_Object type, const CIbyte *reason, |
563 | 2680 Lisp_Object frob0, Lisp_Object frob1) |
2681 { | |
771 | 2682 return Fsignal (type, list3 (build_msg_string (reason), frob0, |
563 | 2683 frob1)); |
2684 } | |
2685 | |
2686 Lisp_Object | |
867 | 2687 maybe_signal_continuable_error_2 (Lisp_Object type, const CIbyte *reason, |
563 | 2688 Lisp_Object frob0, Lisp_Object frob1, |
1204 | 2689 Lisp_Object class_, Error_Behavior errb) |
563 | 2690 { |
2691 /* Optimization: */ | |
2692 if (ERRB_EQ (errb, ERROR_ME_NOT)) | |
2693 return Qnil; | |
2694 return maybe_signal_continuable_error_1 | |
771 | 2695 (type, list3 (build_msg_string (reason), frob0, frob1), |
1204 | 2696 class_, errb); |
563 | 2697 } |
2698 | |
2699 | |
2700 /****************** Error functions class 4 ******************/ | |
2701 | |
2702 /* Class 4: Printf-like functions that signal an error. | |
442 | 2703 These functions signal an error of a specified type, whose data |
428 | 2704 is a single string, created using the arguments. */ |
2705 | |
2706 DOESNT_RETURN | |
867 | 2707 signal_ferror (Lisp_Object type, const CIbyte *fmt, ...) |
442 | 2708 { |
2709 Lisp_Object obj; | |
2710 va_list args; | |
2711 | |
2712 va_start (args, fmt); | |
771 | 2713 obj = emacs_vsprintf_string (CGETTEXT (fmt), args); |
442 | 2714 va_end (args); |
2715 | |
2716 /* Fsignal GC-protects its args */ | |
563 | 2717 signal_error (type, 0, obj); |
442 | 2718 } |
2719 | |
2720 void | |
1204 | 2721 maybe_signal_ferror (Lisp_Object type, Lisp_Object class_, Error_Behavior errb, |
867 | 2722 const CIbyte *fmt, ...) |
442 | 2723 { |
2724 Lisp_Object obj; | |
2725 va_list args; | |
2726 | |
2727 /* Optimization: */ | |
2728 if (ERRB_EQ (errb, ERROR_ME_NOT)) | |
2729 return; | |
2730 | |
2731 va_start (args, fmt); | |
771 | 2732 obj = emacs_vsprintf_string (CGETTEXT (fmt), args); |
442 | 2733 va_end (args); |
2734 | |
2735 /* Fsignal GC-protects its args */ | |
1204 | 2736 maybe_signal_error (type, 0, obj, class_, errb); |
442 | 2737 } |
2738 | |
2739 Lisp_Object | |
867 | 2740 signal_continuable_ferror (Lisp_Object type, const CIbyte *fmt, ...) |
428 | 2741 { |
2742 Lisp_Object obj; | |
2743 va_list args; | |
2744 | |
2745 va_start (args, fmt); | |
771 | 2746 obj = emacs_vsprintf_string (CGETTEXT (fmt), args); |
442 | 2747 va_end (args); |
2748 | |
2749 /* Fsignal GC-protects its args */ | |
2750 return Fsignal (type, list1 (obj)); | |
2751 } | |
2752 | |
2753 Lisp_Object | |
1204 | 2754 maybe_signal_continuable_ferror (Lisp_Object type, Lisp_Object class_, |
867 | 2755 Error_Behavior errb, const CIbyte *fmt, ...) |
442 | 2756 { |
2757 Lisp_Object obj; | |
2758 va_list args; | |
2759 | |
2760 /* Optimization: */ | |
2761 if (ERRB_EQ (errb, ERROR_ME_NOT)) | |
2762 return Qnil; | |
2763 | |
2764 va_start (args, fmt); | |
771 | 2765 obj = emacs_vsprintf_string (CGETTEXT (fmt), args); |
442 | 2766 va_end (args); |
2767 | |
2768 /* Fsignal GC-protects its args */ | |
1204 | 2769 return maybe_signal_continuable_error (type, 0, obj, class_, errb); |
442 | 2770 } |
2771 | |
2772 | |
2773 /****************** Error functions class 5 ******************/ | |
2774 | |
563 | 2775 /* Class 5: Printf-like functions that signal an error. |
442 | 2776 These functions signal an error of a specified type, whose data |
563 | 2777 is a one or more objects, a string (created using the arguments) |
2778 and additional Lisp objects specified in FROB. (The syntax of FROB | |
2779 is the same as for class 2.) | |
2780 | |
2781 There is no need for a class 6 because you can always attach 2 | |
2782 objects using class 5 (for FROB, specify a list with three | |
2783 elements, the first of which is Qunbound), and these functions are | |
2784 not commonly used. | |
2785 */ | |
442 | 2786 |
2787 DOESNT_RETURN | |
867 | 2788 signal_ferror_with_frob (Lisp_Object type, Lisp_Object frob, const CIbyte *fmt, |
563 | 2789 ...) |
442 | 2790 { |
2791 Lisp_Object obj; | |
2792 va_list args; | |
2793 | |
2794 va_start (args, fmt); | |
771 | 2795 obj = emacs_vsprintf_string (CGETTEXT (fmt), args); |
442 | 2796 va_end (args); |
2797 | |
2798 /* Fsignal GC-protects its args */ | |
563 | 2799 signal_error_1 (type, Fcons (obj, build_error_data (0, frob))); |
442 | 2800 } |
2801 | |
2802 void | |
563 | 2803 maybe_signal_ferror_with_frob (Lisp_Object type, Lisp_Object frob, |
1204 | 2804 Lisp_Object class_, Error_Behavior errb, |
867 | 2805 const CIbyte *fmt, ...) |
442 | 2806 { |
2807 Lisp_Object obj; | |
2808 va_list args; | |
2809 | |
2810 /* Optimization: */ | |
2811 if (ERRB_EQ (errb, ERROR_ME_NOT)) | |
2812 return; | |
2813 | |
2814 va_start (args, fmt); | |
771 | 2815 obj = emacs_vsprintf_string (CGETTEXT (fmt), args); |
428 | 2816 va_end (args); |
2817 | |
2818 /* Fsignal GC-protects its args */ | |
1204 | 2819 maybe_signal_error_1 (type, Fcons (obj, build_error_data (0, frob)), class_, |
563 | 2820 errb); |
428 | 2821 } |
2822 | |
2823 Lisp_Object | |
563 | 2824 signal_continuable_ferror_with_frob (Lisp_Object type, Lisp_Object frob, |
867 | 2825 const CIbyte *fmt, ...) |
428 | 2826 { |
2827 Lisp_Object obj; | |
2828 va_list args; | |
2829 | |
2830 va_start (args, fmt); | |
771 | 2831 obj = emacs_vsprintf_string (CGETTEXT (fmt), args); |
428 | 2832 va_end (args); |
2833 | |
2834 /* Fsignal GC-protects its args */ | |
563 | 2835 return Fsignal (type, Fcons (obj, build_error_data (0, frob))); |
428 | 2836 } |
2837 | |
2838 Lisp_Object | |
563 | 2839 maybe_signal_continuable_ferror_with_frob (Lisp_Object type, Lisp_Object frob, |
1204 | 2840 Lisp_Object class_, |
578 | 2841 Error_Behavior errb, |
867 | 2842 const CIbyte *fmt, ...) |
428 | 2843 { |
2844 Lisp_Object obj; | |
2845 va_list args; | |
2846 | |
2847 /* Optimization: */ | |
2848 if (ERRB_EQ (errb, ERROR_ME_NOT)) | |
2849 return Qnil; | |
2850 | |
2851 va_start (args, fmt); | |
771 | 2852 obj = emacs_vsprintf_string (CGETTEXT (fmt), args); |
428 | 2853 va_end (args); |
2854 | |
2855 /* Fsignal GC-protects its args */ | |
563 | 2856 return maybe_signal_continuable_error_1 (type, |
2857 Fcons (obj, | |
2858 build_error_data (0, frob)), | |
1204 | 2859 class_, errb); |
428 | 2860 } |
2861 | |
2862 | |
2863 /* This is what the QUIT macro calls to signal a quit */ | |
2864 void | |
2865 signal_quit (void) | |
2866 { | |
853 | 2867 /* This function cannot GC. GC is prohibited because most callers do |
2868 not expect GC occurring in QUIT. Remove this if/when that gets fixed. | |
2869 --ben */ | |
2870 | |
2871 int count; | |
2872 | |
428 | 2873 if (EQ (Vquit_flag, Qcritical)) |
2874 debug_on_quit |= 2; /* set critical bit. */ | |
2875 Vquit_flag = Qnil; | |
853 | 2876 count = begin_gc_forbidden (); |
428 | 2877 /* note that this is continuable. */ |
2878 Fsignal (Qquit, Qnil); | |
853 | 2879 unbind_to (count); |
428 | 2880 } |
2881 | |
2882 | |
563 | 2883 /************************ convenience error functions ***********************/ |
2884 | |
436 | 2885 Lisp_Object |
428 | 2886 signal_void_function_error (Lisp_Object function) |
2887 { | |
436 | 2888 return Fsignal (Qvoid_function, list1 (function)); |
428 | 2889 } |
2890 | |
436 | 2891 Lisp_Object |
428 | 2892 signal_invalid_function_error (Lisp_Object function) |
2893 { | |
436 | 2894 return Fsignal (Qinvalid_function, list1 (function)); |
428 | 2895 } |
2896 | |
436 | 2897 Lisp_Object |
428 | 2898 signal_wrong_number_of_arguments_error (Lisp_Object function, int nargs) |
2899 { | |
436 | 2900 return Fsignal (Qwrong_number_of_arguments, |
2901 list2 (function, make_int (nargs))); | |
428 | 2902 } |
2903 | |
2904 /* Used in list traversal macros for efficiency. */ | |
436 | 2905 DOESNT_RETURN |
428 | 2906 signal_malformed_list_error (Lisp_Object list) |
2907 { | |
563 | 2908 signal_error (Qmalformed_list, 0, list); |
428 | 2909 } |
2910 | |
436 | 2911 DOESNT_RETURN |
428 | 2912 signal_malformed_property_list_error (Lisp_Object list) |
2913 { | |
563 | 2914 signal_error (Qmalformed_property_list, 0, list); |
428 | 2915 } |
2916 | |
436 | 2917 DOESNT_RETURN |
428 | 2918 signal_circular_list_error (Lisp_Object list) |
2919 { | |
563 | 2920 signal_error (Qcircular_list, 0, list); |
428 | 2921 } |
2922 | |
436 | 2923 DOESNT_RETURN |
428 | 2924 signal_circular_property_list_error (Lisp_Object list) |
2925 { | |
563 | 2926 signal_error (Qcircular_property_list, 0, list); |
428 | 2927 } |
442 | 2928 |
2267 | 2929 /* Called from within emacs_doprnt_1, so REASON is not formatted. */ |
442 | 2930 DOESNT_RETURN |
867 | 2931 syntax_error (const CIbyte *reason, Lisp_Object frob) |
442 | 2932 { |
563 | 2933 signal_error (Qsyntax_error, reason, frob); |
442 | 2934 } |
2935 | |
2936 DOESNT_RETURN | |
867 | 2937 syntax_error_2 (const CIbyte *reason, Lisp_Object frob1, Lisp_Object frob2) |
442 | 2938 { |
563 | 2939 signal_error_2 (Qsyntax_error, reason, frob1, frob2); |
2940 } | |
2941 | |
2942 void | |
867 | 2943 maybe_syntax_error (const CIbyte *reason, Lisp_Object frob, |
1204 | 2944 Lisp_Object class_, Error_Behavior errb) |
2945 { | |
2946 maybe_signal_error (Qsyntax_error, reason, frob, class_, errb); | |
563 | 2947 } |
2948 | |
2949 DOESNT_RETURN | |
867 | 2950 sferror (const CIbyte *reason, Lisp_Object frob) |
563 | 2951 { |
2952 signal_error (Qstructure_formation_error, reason, frob); | |
2953 } | |
2954 | |
2955 DOESNT_RETURN | |
867 | 2956 sferror_2 (const CIbyte *reason, Lisp_Object frob1, Lisp_Object frob2) |
563 | 2957 { |
2958 signal_error_2 (Qstructure_formation_error, reason, frob1, frob2); | |
2959 } | |
2960 | |
2961 void | |
867 | 2962 maybe_sferror (const CIbyte *reason, Lisp_Object frob, |
1204 | 2963 Lisp_Object class_, Error_Behavior errb) |
2964 { | |
2965 maybe_signal_error (Qstructure_formation_error, reason, frob, class_, errb); | |
442 | 2966 } |
2967 | |
2968 DOESNT_RETURN | |
867 | 2969 invalid_argument (const CIbyte *reason, Lisp_Object frob) |
442 | 2970 { |
563 | 2971 signal_error (Qinvalid_argument, reason, frob); |
442 | 2972 } |
2973 | |
2974 DOESNT_RETURN | |
867 | 2975 invalid_argument_2 (const CIbyte *reason, Lisp_Object frob1, |
609 | 2976 Lisp_Object frob2) |
442 | 2977 { |
563 | 2978 signal_error_2 (Qinvalid_argument, reason, frob1, frob2); |
2979 } | |
2980 | |
2981 void | |
867 | 2982 maybe_invalid_argument (const CIbyte *reason, Lisp_Object frob, |
1204 | 2983 Lisp_Object class_, Error_Behavior errb) |
2984 { | |
2985 maybe_signal_error (Qinvalid_argument, reason, frob, class_, errb); | |
563 | 2986 } |
2987 | |
2988 DOESNT_RETURN | |
867 | 2989 invalid_constant (const CIbyte *reason, Lisp_Object frob) |
563 | 2990 { |
2991 signal_error (Qinvalid_constant, reason, frob); | |
2992 } | |
2993 | |
2994 DOESNT_RETURN | |
867 | 2995 invalid_constant_2 (const CIbyte *reason, Lisp_Object frob1, |
609 | 2996 Lisp_Object frob2) |
563 | 2997 { |
2998 signal_error_2 (Qinvalid_constant, reason, frob1, frob2); | |
2999 } | |
3000 | |
3001 void | |
867 | 3002 maybe_invalid_constant (const CIbyte *reason, Lisp_Object frob, |
1204 | 3003 Lisp_Object class_, Error_Behavior errb) |
3004 { | |
3005 maybe_signal_error (Qinvalid_constant, reason, frob, class_, errb); | |
442 | 3006 } |
3007 | |
3008 DOESNT_RETURN | |
867 | 3009 invalid_operation (const CIbyte *reason, Lisp_Object frob) |
442 | 3010 { |
563 | 3011 signal_error (Qinvalid_operation, reason, frob); |
442 | 3012 } |
3013 | |
3014 DOESNT_RETURN | |
867 | 3015 invalid_operation_2 (const CIbyte *reason, Lisp_Object frob1, |
609 | 3016 Lisp_Object frob2) |
442 | 3017 { |
563 | 3018 signal_error_2 (Qinvalid_operation, reason, frob1, frob2); |
3019 } | |
3020 | |
3021 void | |
867 | 3022 maybe_invalid_operation (const CIbyte *reason, Lisp_Object frob, |
1204 | 3023 Lisp_Object class_, Error_Behavior errb) |
3024 { | |
3025 maybe_signal_error (Qinvalid_operation, reason, frob, class_, errb); | |
442 | 3026 } |
3027 | |
3028 DOESNT_RETURN | |
867 | 3029 invalid_change (const CIbyte *reason, Lisp_Object frob) |
442 | 3030 { |
563 | 3031 signal_error (Qinvalid_change, reason, frob); |
442 | 3032 } |
3033 | |
3034 DOESNT_RETURN | |
867 | 3035 invalid_change_2 (const CIbyte *reason, Lisp_Object frob1, Lisp_Object frob2) |
442 | 3036 { |
563 | 3037 signal_error_2 (Qinvalid_change, reason, frob1, frob2); |
3038 } | |
3039 | |
3040 void | |
867 | 3041 maybe_invalid_change (const CIbyte *reason, Lisp_Object frob, |
1204 | 3042 Lisp_Object class_, Error_Behavior errb) |
3043 { | |
3044 maybe_signal_error (Qinvalid_change, reason, frob, class_, errb); | |
563 | 3045 } |
3046 | |
3047 DOESNT_RETURN | |
867 | 3048 invalid_state (const CIbyte *reason, Lisp_Object frob) |
563 | 3049 { |
3050 signal_error (Qinvalid_state, reason, frob); | |
3051 } | |
3052 | |
3053 DOESNT_RETURN | |
867 | 3054 invalid_state_2 (const CIbyte *reason, Lisp_Object frob1, Lisp_Object frob2) |
563 | 3055 { |
3056 signal_error_2 (Qinvalid_state, reason, frob1, frob2); | |
3057 } | |
3058 | |
3059 void | |
867 | 3060 maybe_invalid_state (const CIbyte *reason, Lisp_Object frob, |
1204 | 3061 Lisp_Object class_, Error_Behavior errb) |
3062 { | |
3063 maybe_signal_error (Qinvalid_state, reason, frob, class_, errb); | |
563 | 3064 } |
3065 | |
3066 DOESNT_RETURN | |
867 | 3067 wtaerror (const CIbyte *reason, Lisp_Object frob) |
563 | 3068 { |
3069 signal_error (Qwrong_type_argument, reason, frob); | |
3070 } | |
3071 | |
3072 DOESNT_RETURN | |
867 | 3073 stack_overflow (const CIbyte *reason, Lisp_Object frob) |
563 | 3074 { |
3075 signal_error (Qstack_overflow, reason, frob); | |
3076 } | |
3077 | |
3078 DOESNT_RETURN | |
867 | 3079 out_of_memory (const CIbyte *reason, Lisp_Object frob) |
563 | 3080 { |
3081 signal_error (Qout_of_memory, reason, frob); | |
3082 } | |
3083 | |
3084 DOESNT_RETURN | |
867 | 3085 printing_unreadable_object (const CIbyte *fmt, ...) |
563 | 3086 { |
3087 Lisp_Object obj; | |
3088 va_list args; | |
3089 | |
3090 va_start (args, fmt); | |
771 | 3091 obj = emacs_vsprintf_string (CGETTEXT (fmt), args); |
563 | 3092 va_end (args); |
3093 | |
3094 /* Fsignal GC-protects its args */ | |
3095 signal_error (Qprinting_unreadable_object, 0, obj); | |
442 | 3096 } |
3097 | |
428 | 3098 |
3099 /************************************************************************/ | |
3100 /* User commands */ | |
3101 /************************************************************************/ | |
3102 | |
3103 DEFUN ("commandp", Fcommandp, 1, 1, 0, /* | |
3104 Return t if FUNCTION makes provisions for interactive calling. | |
3105 This means it contains a description for how to read arguments to give it. | |
3106 The value is nil for an invalid function or a symbol with no function | |
3107 definition. | |
3108 | |
3109 Interactively callable functions include | |
3110 | |
3111 -- strings and vectors (treated as keyboard macros) | |
3112 -- lambda-expressions that contain a top-level call to `interactive' | |
3113 -- autoload definitions made by `autoload' with non-nil fourth argument | |
3114 (i.e. the interactive flag) | |
3115 -- compiled-function objects with a non-nil `compiled-function-interactive' | |
3116 value | |
3117 -- subrs (built-in functions) that are interactively callable | |
3118 | |
3119 Also, a symbol satisfies `commandp' if its function definition does so. | |
3120 */ | |
3121 (function)) | |
3122 { | |
3123 Lisp_Object fun = indirect_function (function, 0); | |
3124 | |
3125 if (COMPILED_FUNCTIONP (fun)) | |
3126 return XCOMPILED_FUNCTION (fun)->flags.interactivep ? Qt : Qnil; | |
3127 | |
3128 /* Lists may represent commands. */ | |
3129 if (CONSP (fun)) | |
3130 { | |
3131 Lisp_Object funcar = XCAR (fun); | |
3132 if (EQ (funcar, Qlambda)) | |
3133 return Fassq (Qinteractive, Fcdr (Fcdr (fun))); | |
3134 if (EQ (funcar, Qautoload)) | |
3135 return Fcar (Fcdr (Fcdr (Fcdr (fun)))); | |
3136 else | |
3137 return Qnil; | |
3138 } | |
3139 | |
3140 /* Emacs primitives are interactive if their DEFUN specifies an | |
3141 interactive spec. */ | |
3142 if (SUBRP (fun)) | |
3143 return XSUBR (fun)->prompt ? Qt : Qnil; | |
3144 | |
3145 /* Strings and vectors are keyboard macros. */ | |
3146 if (VECTORP (fun) || STRINGP (fun)) | |
3147 return Qt; | |
3148 | |
3149 /* Everything else (including Qunbound) is not a command. */ | |
3150 return Qnil; | |
3151 } | |
3152 | |
3153 DEFUN ("command-execute", Fcommand_execute, 1, 3, 0, /* | |
3154 Execute CMD as an editor command. | |
3155 CMD must be an object that satisfies the `commandp' predicate. | |
3156 Optional second arg RECORD-FLAG is as in `call-interactively'. | |
3157 The argument KEYS specifies the value to use instead of (this-command-keys) | |
3158 when reading the arguments. | |
3159 */ | |
444 | 3160 (cmd, record_flag, keys)) |
428 | 3161 { |
3162 /* This function can GC */ | |
3163 Lisp_Object prefixarg; | |
3164 Lisp_Object final = cmd; | |
4162 | 3165 PROFILE_DECLARE(); |
428 | 3166 struct console *con = XCONSOLE (Vselected_console); |
3167 | |
3168 prefixarg = con->prefix_arg; | |
3169 con->prefix_arg = Qnil; | |
3170 Vcurrent_prefix_arg = prefixarg; | |
3171 debug_on_next_call = 0; /* #### from FSFmacs; correct? */ | |
3172 | |
3173 if (SYMBOLP (cmd) && !NILP (Fget (cmd, Qdisabled, Qnil))) | |
733 | 3174 return run_hook (Qdisabled_command_hook); |
428 | 3175 |
3176 for (;;) | |
3177 { | |
3178 final = indirect_function (cmd, 1); | |
3179 if (CONSP (final) && EQ (Fcar (final), Qautoload)) | |
970 | 3180 { |
3181 /* do_autoload GCPROs both arguments */ | |
3182 do_autoload (final, cmd); | |
3183 } | |
428 | 3184 else |
3185 break; | |
3186 } | |
3187 | |
3188 if (CONSP (final) || SUBRP (final) || COMPILED_FUNCTIONP (final)) | |
3189 { | |
3190 backtrace.function = &Qcall_interactively; | |
3191 backtrace.args = &cmd; | |
3192 backtrace.nargs = 1; | |
3193 backtrace.evalargs = 0; | |
1292 | 3194 backtrace.pdlcount = specpdl_depth (); |
428 | 3195 backtrace.debug_on_exit = 0; |
1292 | 3196 backtrace.function_being_called = 0; |
428 | 3197 PUSH_BACKTRACE (backtrace); |
3198 | |
1292 | 3199 PROFILE_ENTER_FUNCTION (); |
444 | 3200 final = Fcall_interactively (cmd, record_flag, keys); |
1292 | 3201 PROFILE_EXIT_FUNCTION (); |
428 | 3202 |
3203 POP_BACKTRACE (backtrace); | |
3204 return final; | |
3205 } | |
3206 else if (STRINGP (final) || VECTORP (final)) | |
3207 { | |
3208 return Fexecute_kbd_macro (final, prefixarg); | |
3209 } | |
3210 else | |
3211 { | |
3212 Fsignal (Qwrong_type_argument, | |
3213 Fcons (Qcommandp, | |
3214 (EQ (cmd, final) | |
3215 ? list1 (cmd) | |
3216 : list2 (cmd, final)))); | |
3217 return Qnil; | |
3218 } | |
3219 } | |
3220 | |
3221 DEFUN ("interactive-p", Finteractive_p, 0, 0, 0, /* | |
3222 Return t if function in which this appears was called interactively. | |
3223 This means that the function was called with call-interactively (which | |
3224 includes being called as the binding of a key) | |
3225 and input is currently coming from the keyboard (not in keyboard macro). | |
3226 */ | |
3227 ()) | |
3228 { | |
3229 REGISTER struct backtrace *btp; | |
3230 REGISTER Lisp_Object fun; | |
3231 | |
3232 if (!INTERACTIVE) | |
3233 return Qnil; | |
3234 | |
3235 /* Unless the object was compiled, skip the frame of interactive-p itself | |
3236 (if interpreted) or the frame of byte-code (if called from a compiled | |
3237 function). Note that *btp->function may be a symbol pointing at a | |
3238 compiled function. */ | |
3239 btp = backtrace_list; | |
3240 | |
3241 #if 0 /* FSFmacs */ | |
3242 | |
3243 /* #### FSFmacs does the following instead. I can't figure | |
3244 out which one is more correct. */ | |
3245 /* If this isn't a byte-compiled function, there may be a frame at | |
3246 the top for Finteractive_p itself. If so, skip it. */ | |
3247 fun = Findirect_function (*btp->function); | |
3248 if (SUBRP (fun) && XSUBR (fun) == &Sinteractive_p) | |
3249 btp = btp->next; | |
3250 | |
3251 /* If we're running an Emacs 18-style byte-compiled function, there | |
3252 may be a frame for Fbyte_code. Now, given the strictest | |
3253 definition, this function isn't really being called | |
3254 interactively, but because that's the way Emacs 18 always builds | |
3255 byte-compiled functions, we'll accept it for now. */ | |
3256 if (EQ (*btp->function, Qbyte_code)) | |
3257 btp = btp->next; | |
3258 | |
3259 /* If this isn't a byte-compiled function, then we may now be | |
3260 looking at several frames for special forms. Skip past them. */ | |
3261 while (btp && | |
3262 btp->nargs == UNEVALLED) | |
3263 btp = btp->next; | |
3264 | |
3265 #else | |
3266 | |
3267 if (! (COMPILED_FUNCTIONP (Findirect_function (*btp->function)))) | |
3268 btp = btp->next; | |
3269 for (; | |
3270 btp && (btp->nargs == UNEVALLED | |
3271 || EQ (*btp->function, Qbyte_code)); | |
3272 btp = btp->next) | |
3273 {} | |
3274 /* btp now points at the frame of the innermost function | |
3275 that DOES eval its args. | |
3276 If it is a built-in function (such as load or eval-region) | |
3277 return nil. */ | |
3278 /* Beats me why this is necessary, but it is */ | |
3279 if (btp && EQ (*btp->function, Qcall_interactively)) | |
3280 return Qt; | |
3281 | |
3282 #endif | |
3283 | |
3284 fun = Findirect_function (*btp->function); | |
3285 if (SUBRP (fun)) | |
3286 return Qnil; | |
3287 /* btp points to the frame of a Lisp function that called interactive-p. | |
3288 Return t if that function was called interactively. */ | |
3289 if (btp && btp->next && EQ (*btp->next->function, Qcall_interactively)) | |
3290 return Qt; | |
3291 return Qnil; | |
3292 } | |
3293 | |
3294 | |
3295 /************************************************************************/ | |
3296 /* Autoloading */ | |
3297 /************************************************************************/ | |
3298 | |
3299 DEFUN ("autoload", Fautoload, 2, 5, 0, /* | |
444 | 3300 Define FUNCTION to autoload from FILENAME. |
3301 FUNCTION is a symbol; FILENAME is a file name string to pass to `load'. | |
3302 The remaining optional arguments provide additional info about the | |
3303 real definition. | |
3304 DOCSTRING is documentation for FUNCTION. | |
3305 INTERACTIVE, if non-nil, says FUNCTION can be called interactively. | |
3306 TYPE indicates the type of the object: | |
428 | 3307 nil or omitted says FUNCTION is a function, |
3308 `keymap' says FUNCTION is really a keymap, and | |
3309 `macro' or t says FUNCTION is really a macro. | |
444 | 3310 If FUNCTION already has a non-void function definition that is not an |
3311 autoload object, this function does nothing and returns nil. | |
428 | 3312 */ |
444 | 3313 (function, filename, docstring, interactive, type)) |
428 | 3314 { |
3315 /* This function can GC */ | |
3316 CHECK_SYMBOL (function); | |
444 | 3317 CHECK_STRING (filename); |
428 | 3318 |
3319 /* If function is defined and not as an autoload, don't override */ | |
3320 { | |
3321 Lisp_Object f = XSYMBOL (function)->function; | |
3322 if (!UNBOUNDP (f) && !(CONSP (f) && EQ (XCAR (f), Qautoload))) | |
3323 return Qnil; | |
3324 } | |
3325 | |
3326 if (purify_flag) | |
3327 { | |
3328 /* Attempt to avoid consing identical (string=) pure strings. */ | |
444 | 3329 filename = Fsymbol_name (Fintern (filename, Qnil)); |
428 | 3330 } |
440 | 3331 |
444 | 3332 return Ffset (function, Fcons (Qautoload, list4 (filename, |
428 | 3333 docstring, |
3334 interactive, | |
3335 type))); | |
3336 } | |
3337 | |
3338 Lisp_Object | |
3339 un_autoload (Lisp_Object oldqueue) | |
3340 { | |
3341 /* This function can GC */ | |
3342 REGISTER Lisp_Object queue, first, second; | |
3343 | |
3344 /* Queue to unwind is current value of Vautoload_queue. | |
3345 oldqueue is the shadowed value to leave in Vautoload_queue. */ | |
3346 queue = Vautoload_queue; | |
3347 Vautoload_queue = oldqueue; | |
3348 while (CONSP (queue)) | |
3349 { | |
3350 first = XCAR (queue); | |
3351 second = Fcdr (first); | |
3352 first = Fcar (first); | |
3353 if (NILP (second)) | |
3354 Vfeatures = first; | |
3355 else | |
3356 Ffset (first, second); | |
3357 queue = Fcdr (queue); | |
3358 } | |
3359 return Qnil; | |
3360 } | |
3361 | |
970 | 3362 /* do_autoload GCPROs both arguments */ |
428 | 3363 void |
3364 do_autoload (Lisp_Object fundef, | |
3365 Lisp_Object funname) | |
3366 { | |
3367 /* This function can GC */ | |
3368 int speccount = specpdl_depth(); | |
3369 Lisp_Object fun = funname; | |
970 | 3370 struct gcpro gcpro1, gcpro2, gcpro3; |
428 | 3371 |
3372 CHECK_SYMBOL (funname); | |
970 | 3373 GCPRO3 (fundef, funname, fun); |
428 | 3374 |
3375 /* Value saved here is to be restored into Vautoload_queue */ | |
3376 record_unwind_protect (un_autoload, Vautoload_queue); | |
3377 Vautoload_queue = Qt; | |
3378 call4 (Qload, Fcar (Fcdr (fundef)), Qnil, noninteractive ? Qt : Qnil, Qnil); | |
3379 | |
3380 { | |
3381 Lisp_Object queue; | |
3382 | |
3383 /* Save the old autoloads, in case we ever do an unload. */ | |
3384 for (queue = Vautoload_queue; CONSP (queue); queue = XCDR (queue)) | |
3385 { | |
3386 Lisp_Object first = XCAR (queue); | |
3387 Lisp_Object second = Fcdr (first); | |
3388 | |
3389 first = Fcar (first); | |
3390 | |
3391 /* Note: This test is subtle. The cdr of an autoload-queue entry | |
3392 may be an atom if the autoload entry was generated by a defalias | |
3393 or fset. */ | |
3394 if (CONSP (second)) | |
3395 Fput (first, Qautoload, (XCDR (second))); | |
3396 } | |
3397 } | |
3398 | |
3399 /* Once loading finishes, don't undo it. */ | |
3400 Vautoload_queue = Qt; | |
771 | 3401 unbind_to (speccount); |
428 | 3402 |
3403 fun = indirect_function (fun, 0); | |
3404 | |
3405 #if 0 /* FSFmacs */ | |
3406 if (!NILP (Fequal (fun, fundef))) | |
3407 #else | |
3408 if (UNBOUNDP (fun) | |
3409 || (CONSP (fun) | |
3410 && EQ (XCAR (fun), Qautoload))) | |
3411 #endif | |
563 | 3412 invalid_state ("Autoloading failed to define function", funname); |
428 | 3413 UNGCPRO; |
3414 } | |
3415 | |
3416 | |
3417 /************************************************************************/ | |
3418 /* eval, funcall, apply */ | |
3419 /************************************************************************/ | |
3420 | |
814 | 3421 /* NOTE: If you are hearing the endless complaint that function calls in |
3422 elisp are extremely slow, it just isn't true any more! The stuff below | |
3423 -- in particular, the calling of subrs and compiled functions, the most | |
3424 common cases -- has been highly optimized. There isn't a whole lot left | |
3425 to do to squeeze more speed out except by switching to lexical | |
3426 variables, which would eliminate the specbind loop. (But the real gain | |
3427 from lexical variables would come from better optimization -- with | |
3428 dynamic binding, you have the constant problem that any function call | |
3429 that you haven't explicitly proven to be side-effect-free might | |
3430 potentially side effect your local variables, which makes optimization | |
3431 extremely difficult when there are function calls anywhere in a chunk of | |
3432 code to be optimized. Even worse, you don't know that *your* local | |
3433 variables aren't side-effecting an outer function's local variables, so | |
3434 it's impossible to optimize away almost *any* variable assignment.) */ | |
3435 | |
428 | 3436 static Lisp_Object funcall_lambda (Lisp_Object fun, |
442 | 3437 int nargs, Lisp_Object args[]); |
428 | 3438 static int in_warnings; |
3439 | |
3440 | |
814 | 3441 void handle_compiled_function_with_and_rest (Lisp_Compiled_Function *f, |
3442 int nargs, | |
3443 Lisp_Object args[]); | |
3444 | |
3445 /* The theory behind making this a separate function is to shrink | |
3446 funcall_compiled_function() so as to increase the likelihood of a cache | |
3447 hit in the L1 cache -- &rest processing is not going to be fast anyway. | |
3448 The idea is the same as with execute_rare_opcode() in bytecode.c. We | |
3449 make this non-static to ensure the compiler doesn't inline it. */ | |
3450 | |
3451 void | |
3452 handle_compiled_function_with_and_rest (Lisp_Compiled_Function *f, int nargs, | |
3453 Lisp_Object args[]) | |
3454 { | |
3455 REGISTER int i = 0; | |
3456 int max_non_rest_args = f->args_in_array - 1; | |
3457 int bindargs = min (nargs, max_non_rest_args); | |
3458 | |
3459 for (i = 0; i < bindargs; i++) | |
3092 | 3460 #ifdef NEW_GC |
3461 SPECBIND_FAST_UNSAFE (XCOMPILED_FUNCTION_ARGS_DATA (f->arguments)[i], | |
3462 args[i]); | |
3463 #else /* not NEW_GC */ | |
814 | 3464 SPECBIND_FAST_UNSAFE (f->args[i], args[i]); |
3092 | 3465 #endif /* not NEW_GC */ |
814 | 3466 for (i = bindargs; i < max_non_rest_args; i++) |
3092 | 3467 #ifdef NEW_GC |
3468 SPECBIND_FAST_UNSAFE (XCOMPILED_FUNCTION_ARGS_DATA (f->arguments)[i], | |
3469 Qnil); | |
3470 #else /* not NEW_GC */ | |
814 | 3471 SPECBIND_FAST_UNSAFE (f->args[i], Qnil); |
3092 | 3472 #endif /* not NEW_GC */ |
3473 #ifdef NEW_GC | |
3474 SPECBIND_FAST_UNSAFE | |
3475 (XCOMPILED_FUNCTION_ARGS_DATA (f->arguments)[max_non_rest_args], | |
3476 nargs > max_non_rest_args ? | |
3477 Flist (nargs - max_non_rest_args, &args[max_non_rest_args]) : | |
3478 Qnil); | |
3479 #else /* not NEW_GC */ | |
814 | 3480 SPECBIND_FAST_UNSAFE |
3481 (f->args[max_non_rest_args], | |
3482 nargs > max_non_rest_args ? | |
3483 Flist (nargs - max_non_rest_args, &args[max_non_rest_args]) : | |
3484 Qnil); | |
3092 | 3485 #endif /* not NEW_GC */ |
814 | 3486 } |
3487 | |
3488 /* Apply compiled-function object FUN to the NARGS evaluated arguments | |
3489 in ARGS, and return the result of evaluation. */ | |
3490 inline static Lisp_Object | |
3491 funcall_compiled_function (Lisp_Object fun, int nargs, Lisp_Object args[]) | |
3492 { | |
3493 /* This function can GC */ | |
3494 int speccount = specpdl_depth(); | |
3495 REGISTER int i = 0; | |
3496 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (fun); | |
3497 | |
3498 if (!OPAQUEP (f->instructions)) | |
3499 /* Lazily munge the instructions into a more efficient form */ | |
3500 optimize_compiled_function (fun); | |
3501 | |
3502 /* optimize_compiled_function() guaranteed that f->specpdl_depth is | |
3503 the required space on the specbinding stack for binding the args | |
3504 and local variables of fun. So just reserve it once. */ | |
3505 SPECPDL_RESERVE (f->specpdl_depth); | |
3506 | |
3507 if (nargs == f->max_args) /* Optimize for the common case -- no unspecified | |
3508 optional arguments. */ | |
3509 { | |
3510 #if 1 | |
3511 for (i = 0; i < nargs; i++) | |
3092 | 3512 #ifdef NEW_GC |
3513 SPECBIND_FAST_UNSAFE (XCOMPILED_FUNCTION_ARGS_DATA (f->arguments)[i], | |
3514 args[i]); | |
3515 #else /* not NEW_GC */ | |
814 | 3516 SPECBIND_FAST_UNSAFE (f->args[i], args[i]); |
3092 | 3517 #endif /* not NEW_GC */ |
814 | 3518 #else |
3519 /* Here's an alternate way to write the loop that tries to further | |
3520 optimize funcalls for functions with few arguments by partially | |
3521 unrolling the loop. It's not clear whether this is a win since it | |
3522 increases the size of the function and the possibility of L1 cache | |
3523 misses. (Microsoft VC++ 6 with /O2 /G5 generates 0x90 == 144 bytes | |
3524 per SPECBIND_FAST_UNSAFE().) Tests under VC++ 6, running the byte | |
3525 compiler repeatedly and looking at the total time, show very | |
3526 little difference between the simple loop above, the unrolled code | |
3527 below, and a "partly unrolled" solution with only cases 0-2 below | |
3528 instead of 0-4. Therefore, I'm keeping it at the simple loop | |
3529 because it's smaller. */ | |
3530 switch (nargs) | |
3531 { | |
3532 default: | |
3533 for (i = nargs - 1; i >= 4; i--) | |
3534 SPECBIND_FAST_UNSAFE (f->args[i], args[i]); | |
3535 case 4: SPECBIND_FAST_UNSAFE (f->args[3], args[3]); | |
3536 case 3: SPECBIND_FAST_UNSAFE (f->args[2], args[2]); | |
3537 case 2: SPECBIND_FAST_UNSAFE (f->args[1], args[1]); | |
3538 case 1: SPECBIND_FAST_UNSAFE (f->args[0], args[0]); | |
3539 case 0: break; | |
3540 } | |
3541 #endif | |
3542 } | |
3543 else if (nargs < f->min_args) | |
3544 goto wrong_number_of_arguments; | |
3545 else if (nargs < f->max_args) | |
3546 { | |
3547 for (i = 0; i < nargs; i++) | |
3092 | 3548 #ifdef NEW_GC |
3549 SPECBIND_FAST_UNSAFE (XCOMPILED_FUNCTION_ARGS_DATA (f->arguments)[i], | |
3550 args[i]); | |
3551 #else /* not NEW_GC */ | |
814 | 3552 SPECBIND_FAST_UNSAFE (f->args[i], args[i]); |
3092 | 3553 #endif /* not NEW_GC */ |
814 | 3554 for (i = nargs; i < f->max_args; i++) |
3092 | 3555 #ifdef NEW_GC |
3556 SPECBIND_FAST_UNSAFE (XCOMPILED_FUNCTION_ARGS_DATA (f->arguments)[i], | |
3557 Qnil); | |
3558 #else /* not NEW_GC */ | |
814 | 3559 SPECBIND_FAST_UNSAFE (f->args[i], Qnil); |
3092 | 3560 #endif /* not NEW_GC */ |
814 | 3561 } |
3562 else if (f->max_args == MANY) | |
3563 handle_compiled_function_with_and_rest (f, nargs, args); | |
3564 else | |
3565 { | |
3566 wrong_number_of_arguments: | |
3567 /* The actual printed compiled_function object is incomprehensible. | |
3568 Check the backtrace to see if we can get a more meaningful symbol. */ | |
3569 if (EQ (fun, indirect_function (*backtrace_list->function, 0))) | |
3570 fun = *backtrace_list->function; | |
3571 return Fsignal (Qwrong_number_of_arguments, | |
3572 list2 (fun, make_int (nargs))); | |
3573 } | |
3574 | |
3575 { | |
3576 Lisp_Object value = | |
3577 execute_optimized_program ((Opbyte *) XOPAQUE_DATA (f->instructions), | |
3578 f->stack_depth, | |
3579 XVECTOR_DATA (f->constants)); | |
3580 | |
3581 /* The attempt to optimize this by only unbinding variables failed | |
3582 because using buffer-local variables as function parameters | |
3583 leads to specpdl_ptr->func != 0 */ | |
3584 /* UNBIND_TO_GCPRO_VARIABLES_ONLY (speccount, value); */ | |
3585 UNBIND_TO_GCPRO (speccount, value); | |
3586 return value; | |
3587 } | |
3588 } | |
3589 | |
428 | 3590 DEFUN ("eval", Feval, 1, 1, 0, /* |
3591 Evaluate FORM and return its value. | |
3592 */ | |
3593 (form)) | |
3594 { | |
3595 /* This function can GC */ | |
3596 Lisp_Object fun, val, original_fun, original_args; | |
3597 int nargs; | |
4162 | 3598 PROFILE_DECLARE(); |
428 | 3599 |
1318 | 3600 #ifdef ERROR_CHECK_TRAPPING_PROBLEMS |
3601 check_proper_critical_section_lisp_protection (); | |
3602 #endif | |
3603 | |
3989 | 3604 if (!CONSP (form)) |
3605 { | |
3606 if (SYMBOLP (form)) | |
3607 { | |
3608 return Fsymbol_value (form); | |
3609 } | |
3610 | |
3611 return form; | |
3612 } | |
3613 | |
428 | 3614 /* I think this is a pretty safe place to call Lisp code, don't you? */ |
853 | 3615 while (!in_warnings && !NILP (Vpending_warnings) |
3616 /* well, perhaps not so safe after all! */ | |
3617 && !(inhibit_flags & INHIBIT_ANY_CHANGE_AFFECTING_REDISPLAY)) | |
428 | 3618 { |
3619 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; | |
1204 | 3620 Lisp_Object this_warning_cons, this_warning, class_, level, messij; |
853 | 3621 int speccount = internal_bind_int (&in_warnings, 1); |
3622 | |
428 | 3623 this_warning_cons = Vpending_warnings; |
3624 this_warning = XCAR (this_warning_cons); | |
3625 /* in case an error occurs in the warn function, at least | |
3626 it won't happen infinitely */ | |
3627 Vpending_warnings = XCDR (Vpending_warnings); | |
853 | 3628 free_cons (this_warning_cons); |
1204 | 3629 class_ = XCAR (this_warning); |
428 | 3630 level = XCAR (XCDR (this_warning)); |
3631 messij = XCAR (XCDR (XCDR (this_warning))); | |
3632 free_list (this_warning); | |
3633 | |
3634 if (NILP (Vpending_warnings)) | |
3635 Vpending_warnings_tail = Qnil; /* perhaps not strictly necessary, | |
3636 but safer */ | |
3637 | |
1204 | 3638 GCPRO4 (form, class_, level, messij); |
428 | 3639 if (!STRINGP (messij)) |
3640 messij = Fprin1_to_string (messij, Qnil); | |
1204 | 3641 call3 (Qdisplay_warning, class_, messij, level); |
428 | 3642 UNGCPRO; |
771 | 3643 unbind_to (speccount); |
428 | 3644 } |
3645 | |
3646 QUIT; | |
814 | 3647 if (need_to_garbage_collect) |
428 | 3648 { |
3649 struct gcpro gcpro1; | |
3650 GCPRO1 (form); | |
3092 | 3651 #ifdef NEW_GC |
3652 gc_incremental (); | |
3653 #else /* not NEW_GC */ | |
428 | 3654 garbage_collect_1 (); |
3092 | 3655 #endif /* not NEW_GC */ |
428 | 3656 UNGCPRO; |
3657 } | |
3658 | |
3659 if (++lisp_eval_depth > max_lisp_eval_depth) | |
3660 { | |
3661 if (max_lisp_eval_depth < 100) | |
3662 max_lisp_eval_depth = 100; | |
3663 if (lisp_eval_depth > max_lisp_eval_depth) | |
563 | 3664 stack_overflow ("Lisp nesting exceeds `max-lisp-eval-depth'", |
3665 Qunbound); | |
428 | 3666 } |
3667 | |
3668 /* We guaranteed CONSP (form) above */ | |
3669 original_fun = XCAR (form); | |
3670 original_args = XCDR (form); | |
3671 | |
3672 GET_EXTERNAL_LIST_LENGTH (original_args, nargs); | |
3673 | |
3674 backtrace.pdlcount = specpdl_depth(); | |
3675 backtrace.function = &original_fun; /* This also protects them from gc */ | |
3676 backtrace.args = &original_args; | |
3677 backtrace.nargs = UNEVALLED; | |
3678 backtrace.evalargs = 1; | |
3679 backtrace.debug_on_exit = 0; | |
1292 | 3680 backtrace.function_being_called = 0; |
428 | 3681 PUSH_BACKTRACE (backtrace); |
3682 | |
3683 if (debug_on_next_call) | |
3684 do_debug_on_call (Qt); | |
3685 | |
3686 /* At this point, only original_fun and original_args | |
3687 have values that will be used below. */ | |
3688 retry: | |
3989 | 3689 /* Optimise for no indirection. */ |
3690 fun = original_fun; | |
3691 if (SYMBOLP (fun) && !EQ (fun, Qunbound) | |
3692 && (fun = XSYMBOL (fun)->function, SYMBOLP (fun))) | |
3693 { | |
3694 fun = indirect_function(original_fun, 1); | |
3695 } | |
428 | 3696 |
3697 if (SUBRP (fun)) | |
3698 { | |
3699 Lisp_Subr *subr = XSUBR (fun); | |
3700 int max_args = subr->max_args; | |
3701 | |
3702 if (nargs < subr->min_args) | |
3703 goto wrong_number_of_arguments; | |
3704 | |
3705 if (max_args == UNEVALLED) /* Optimize for the common case */ | |
3706 { | |
3707 backtrace.evalargs = 0; | |
1292 | 3708 PROFILE_ENTER_FUNCTION (); |
428 | 3709 val = (((Lisp_Object (*) (Lisp_Object)) subr_function (subr)) |
3710 (original_args)); | |
1292 | 3711 PROFILE_EXIT_FUNCTION (); |
428 | 3712 } |
3713 else if (nargs <= max_args) | |
3714 { | |
3715 struct gcpro gcpro1; | |
3716 Lisp_Object args[SUBR_MAX_ARGS]; | |
3717 REGISTER Lisp_Object *p = args; | |
3718 | |
3719 GCPRO1 (args[0]); | |
3720 gcpro1.nvars = 0; | |
3721 | |
3722 { | |
3723 LIST_LOOP_2 (arg, original_args) | |
3724 { | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
3725 *p++ = IGNORE_MULTIPLE_VALUES (Feval (arg)); |
428 | 3726 gcpro1.nvars++; |
3727 } | |
3728 } | |
3729 | |
3730 /* &optional args default to nil. */ | |
3731 while (p - args < max_args) | |
3732 *p++ = Qnil; | |
3733 | |
3734 backtrace.args = args; | |
3735 backtrace.nargs = nargs; | |
3736 | |
1292 | 3737 PROFILE_ENTER_FUNCTION (); |
428 | 3738 FUNCALL_SUBR (val, subr, args, max_args); |
1292 | 3739 PROFILE_EXIT_FUNCTION (); |
428 | 3740 |
3741 UNGCPRO; | |
3742 } | |
3743 else if (max_args == MANY) | |
3744 { | |
3745 /* Pass a vector of evaluated arguments */ | |
3746 struct gcpro gcpro1; | |
3747 Lisp_Object *args = alloca_array (Lisp_Object, nargs); | |
3748 REGISTER Lisp_Object *p = args; | |
3749 | |
3750 GCPRO1 (args[0]); | |
3751 gcpro1.nvars = 0; | |
3752 | |
3753 { | |
3754 LIST_LOOP_2 (arg, original_args) | |
3755 { | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
3756 *p++ = IGNORE_MULTIPLE_VALUES (Feval (arg)); |
428 | 3757 gcpro1.nvars++; |
3758 } | |
3759 } | |
3760 | |
3761 backtrace.args = args; | |
3762 backtrace.nargs = nargs; | |
3763 | |
1292 | 3764 PROFILE_ENTER_FUNCTION (); |
428 | 3765 val = (((Lisp_Object (*) (int, Lisp_Object *)) subr_function (subr)) |
3766 (nargs, args)); | |
1292 | 3767 PROFILE_EXIT_FUNCTION (); |
428 | 3768 |
3769 UNGCPRO; | |
3770 } | |
3771 else | |
3772 { | |
3773 wrong_number_of_arguments: | |
440 | 3774 val = signal_wrong_number_of_arguments_error (original_fun, nargs); |
428 | 3775 } |
3776 } | |
3777 else if (COMPILED_FUNCTIONP (fun)) | |
3778 { | |
3779 struct gcpro gcpro1; | |
3780 Lisp_Object *args = alloca_array (Lisp_Object, nargs); | |
3781 REGISTER Lisp_Object *p = args; | |
3782 | |
3783 GCPRO1 (args[0]); | |
3784 gcpro1.nvars = 0; | |
3785 | |
3786 { | |
3787 LIST_LOOP_2 (arg, original_args) | |
3788 { | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
3789 *p++ = IGNORE_MULTIPLE_VALUES (Feval (arg)); |
428 | 3790 gcpro1.nvars++; |
3791 } | |
3792 } | |
3793 | |
3794 backtrace.args = args; | |
3795 backtrace.nargs = nargs; | |
3796 backtrace.evalargs = 0; | |
3797 | |
1292 | 3798 PROFILE_ENTER_FUNCTION (); |
428 | 3799 val = funcall_compiled_function (fun, nargs, args); |
1292 | 3800 PROFILE_EXIT_FUNCTION (); |
428 | 3801 |
3802 /* Do the debug-on-exit now, while args is still GCPROed. */ | |
3803 if (backtrace.debug_on_exit) | |
3804 val = do_debug_on_exit (val); | |
3805 /* Don't do it again when we return to eval. */ | |
3806 backtrace.debug_on_exit = 0; | |
3807 | |
3808 UNGCPRO; | |
3809 } | |
3810 else if (CONSP (fun)) | |
3811 { | |
3812 Lisp_Object funcar = XCAR (fun); | |
3813 | |
3814 if (EQ (funcar, Qautoload)) | |
3815 { | |
970 | 3816 /* do_autoload GCPROs both arguments */ |
428 | 3817 do_autoload (fun, original_fun); |
3818 goto retry; | |
3819 } | |
3820 else if (EQ (funcar, Qmacro)) | |
3821 { | |
1292 | 3822 PROFILE_ENTER_FUNCTION (); |
428 | 3823 val = Feval (apply1 (XCDR (fun), original_args)); |
1292 | 3824 PROFILE_EXIT_FUNCTION (); |
428 | 3825 } |
3826 else if (EQ (funcar, Qlambda)) | |
3827 { | |
3828 struct gcpro gcpro1; | |
3829 Lisp_Object *args = alloca_array (Lisp_Object, nargs); | |
3830 REGISTER Lisp_Object *p = args; | |
3831 | |
3832 GCPRO1 (args[0]); | |
3833 gcpro1.nvars = 0; | |
3834 | |
3835 { | |
3836 LIST_LOOP_2 (arg, original_args) | |
3837 { | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
3838 *p++ = IGNORE_MULTIPLE_VALUES (Feval (arg)); |
428 | 3839 gcpro1.nvars++; |
3840 } | |
3841 } | |
3842 | |
3843 UNGCPRO; | |
3844 | |
3845 backtrace.args = args; /* this also GCPROs `args' */ | |
3846 backtrace.nargs = nargs; | |
3847 backtrace.evalargs = 0; | |
3848 | |
1292 | 3849 PROFILE_ENTER_FUNCTION (); |
428 | 3850 val = funcall_lambda (fun, nargs, args); |
1292 | 3851 PROFILE_EXIT_FUNCTION (); |
428 | 3852 |
3853 /* Do the debug-on-exit now, while args is still GCPROed. */ | |
3854 if (backtrace.debug_on_exit) | |
3855 val = do_debug_on_exit (val); | |
3856 /* Don't do it again when we return to eval. */ | |
3857 backtrace.debug_on_exit = 0; | |
3858 } | |
3859 else | |
3860 { | |
3861 goto invalid_function; | |
3862 } | |
3863 } | |
4104 | 3864 else if (UNBOUNDP (fun)) |
3865 { | |
3866 val = signal_void_function_error (original_fun); | |
3867 } | |
3868 else /* ! (SUBRP (fun) || COMPILED_FUNCTIONP (fun) || CONSP (fun) | |
3869 UNBOUNDP (fun)) */ | |
428 | 3870 { |
3871 invalid_function: | |
436 | 3872 val = signal_invalid_function_error (fun); |
428 | 3873 } |
3874 | |
3875 lisp_eval_depth--; | |
3876 if (backtrace.debug_on_exit) | |
3877 val = do_debug_on_exit (val); | |
3878 POP_BACKTRACE (backtrace); | |
3879 return val; | |
3880 } | |
3881 | |
3882 | |
1111 | 3883 |
3884 static void | |
3885 run_post_gc_hook (void) | |
3886 { | |
3887 Lisp_Object args[2]; | |
3888 | |
3889 args[0] = Qpost_gc_hook; | |
3890 args[1] = Fcons (Fcons (Qfinalize_list, zap_finalize_list ()), Qnil); | |
3891 | |
3892 run_hook_with_args_trapping_problems | |
1333 | 3893 (Qgarbage_collecting, 2, args, RUN_HOOKS_TO_COMPLETION, |
1111 | 3894 INHIBIT_QUIT | NO_INHIBIT_ERRORS); |
3895 } | |
3896 | |
428 | 3897 DEFUN ("funcall", Ffuncall, 1, MANY, 0, /* |
3898 Call first argument as a function, passing the remaining arguments to it. | |
3899 Thus, (funcall 'cons 'x 'y) returns (x . y). | |
3900 */ | |
3901 (int nargs, Lisp_Object *args)) | |
3902 { | |
3903 /* This function can GC */ | |
3904 Lisp_Object fun; | |
3905 Lisp_Object val; | |
4162 | 3906 PROFILE_DECLARE(); |
428 | 3907 int fun_nargs = nargs - 1; |
3908 Lisp_Object *fun_args = args + 1; | |
3909 | |
1318 | 3910 /* QUIT will check for proper redisplay wrapping */ |
3911 | |
428 | 3912 QUIT; |
851 | 3913 |
3914 if (funcall_allocation_flag) | |
3915 { | |
3916 if (need_to_garbage_collect) | |
3917 /* Callers should gcpro lexpr args */ | |
3092 | 3918 #ifdef NEW_GC |
3919 gc_incremental (); | |
3920 #else /* not NEW_GC */ | |
851 | 3921 garbage_collect_1 (); |
3092 | 3922 #endif /* not NEW_GC */ |
851 | 3923 if (need_to_check_c_alloca) |
3924 { | |
3925 if (++funcall_alloca_count >= MAX_FUNCALLS_BETWEEN_ALLOCA_CLEANUP) | |
3926 { | |
3927 xemacs_c_alloca (0); | |
3928 funcall_alloca_count = 0; | |
3929 } | |
3930 } | |
887 | 3931 if (need_to_signal_post_gc) |
3932 { | |
3933 need_to_signal_post_gc = 0; | |
1111 | 3934 recompute_funcall_allocation_flag (); |
3263 | 3935 #ifdef NEW_GC |
3936 run_finalizers (); | |
3937 #endif /* NEW_GC */ | |
1111 | 3938 run_post_gc_hook (); |
887 | 3939 } |
851 | 3940 } |
428 | 3941 |
3942 if (++lisp_eval_depth > max_lisp_eval_depth) | |
3943 { | |
3944 if (max_lisp_eval_depth < 100) | |
3945 max_lisp_eval_depth = 100; | |
3946 if (lisp_eval_depth > max_lisp_eval_depth) | |
563 | 3947 stack_overflow ("Lisp nesting exceeds `max-lisp-eval-depth'", |
3948 Qunbound); | |
428 | 3949 } |
3950 | |
1292 | 3951 backtrace.pdlcount = specpdl_depth (); |
428 | 3952 backtrace.function = &args[0]; |
3953 backtrace.args = fun_args; | |
3954 backtrace.nargs = fun_nargs; | |
3955 backtrace.evalargs = 0; | |
3956 backtrace.debug_on_exit = 0; | |
1292 | 3957 backtrace.function_being_called = 0; |
428 | 3958 PUSH_BACKTRACE (backtrace); |
3959 | |
3960 if (debug_on_next_call) | |
3961 do_debug_on_call (Qlambda); | |
3962 | |
3963 retry: | |
3964 | |
3965 fun = args[0]; | |
3966 | |
3967 /* We could call indirect_function directly, but profiling shows | |
3968 this is worth optimizing by partially unrolling the loop. */ | |
3969 if (SYMBOLP (fun)) | |
3970 { | |
3971 fun = XSYMBOL (fun)->function; | |
3972 if (SYMBOLP (fun)) | |
3973 { | |
3974 fun = XSYMBOL (fun)->function; | |
3975 if (SYMBOLP (fun)) | |
3976 fun = indirect_function (fun, 1); | |
3977 } | |
3978 } | |
3979 | |
3980 if (SUBRP (fun)) | |
3981 { | |
3982 Lisp_Subr *subr = XSUBR (fun); | |
3983 int max_args = subr->max_args; | |
3984 Lisp_Object spacious_args[SUBR_MAX_ARGS]; | |
3985 | |
3986 if (fun_nargs == max_args) /* Optimize for the common case */ | |
3987 { | |
3988 funcall_subr: | |
1292 | 3989 PROFILE_ENTER_FUNCTION (); |
428 | 3990 FUNCALL_SUBR (val, subr, fun_args, max_args); |
1292 | 3991 PROFILE_EXIT_FUNCTION (); |
428 | 3992 } |
436 | 3993 else if (fun_nargs < subr->min_args) |
3994 { | |
3995 goto wrong_number_of_arguments; | |
3996 } | |
428 | 3997 else if (fun_nargs < max_args) |
3998 { | |
3999 Lisp_Object *p = spacious_args; | |
4000 | |
4001 /* Default optionals to nil */ | |
4002 while (fun_nargs--) | |
4003 *p++ = *fun_args++; | |
4004 while (p - spacious_args < max_args) | |
4005 *p++ = Qnil; | |
4006 | |
4007 fun_args = spacious_args; | |
4008 goto funcall_subr; | |
4009 } | |
4010 else if (max_args == MANY) | |
4011 { | |
1292 | 4012 PROFILE_ENTER_FUNCTION (); |
436 | 4013 val = SUBR_FUNCTION (subr, MANY) (fun_nargs, fun_args); |
1292 | 4014 PROFILE_EXIT_FUNCTION (); |
428 | 4015 } |
4016 else if (max_args == UNEVALLED) /* Can't funcall a special form */ | |
4017 { | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4018 /* Ugh, ugh, ugh. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4019 if (EQ (fun, XSYMBOL_FUNCTION (Qthrow))) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4020 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4021 args[0] = Qobsolete_throw; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4022 goto retry; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4023 } |
428 | 4024 goto invalid_function; |
4025 } | |
4026 else | |
4027 { | |
4028 wrong_number_of_arguments: | |
436 | 4029 val = signal_wrong_number_of_arguments_error (fun, fun_nargs); |
428 | 4030 } |
4031 } | |
4032 else if (COMPILED_FUNCTIONP (fun)) | |
4033 { | |
1292 | 4034 PROFILE_ENTER_FUNCTION (); |
428 | 4035 val = funcall_compiled_function (fun, fun_nargs, fun_args); |
1292 | 4036 PROFILE_EXIT_FUNCTION (); |
428 | 4037 } |
4038 else if (CONSP (fun)) | |
4039 { | |
4040 Lisp_Object funcar = XCAR (fun); | |
4041 | |
4042 if (EQ (funcar, Qlambda)) | |
4043 { | |
1292 | 4044 PROFILE_ENTER_FUNCTION (); |
428 | 4045 val = funcall_lambda (fun, fun_nargs, fun_args); |
1292 | 4046 PROFILE_EXIT_FUNCTION (); |
428 | 4047 } |
4048 else if (EQ (funcar, Qautoload)) | |
4049 { | |
970 | 4050 /* do_autoload GCPROs both arguments */ |
428 | 4051 do_autoload (fun, args[0]); |
4052 goto retry; | |
4053 } | |
4054 else /* Can't funcall a macro */ | |
4055 { | |
4056 goto invalid_function; | |
4057 } | |
4058 } | |
4059 else if (UNBOUNDP (fun)) | |
4060 { | |
436 | 4061 val = signal_void_function_error (args[0]); |
428 | 4062 } |
4063 else | |
4064 { | |
4065 invalid_function: | |
436 | 4066 val = signal_invalid_function_error (fun); |
428 | 4067 } |
4068 | |
4069 lisp_eval_depth--; | |
4070 if (backtrace.debug_on_exit) | |
4071 val = do_debug_on_exit (val); | |
4072 POP_BACKTRACE (backtrace); | |
4073 return val; | |
4074 } | |
4075 | |
4076 DEFUN ("functionp", Ffunctionp, 1, 1, 0, /* | |
4077 Return t if OBJECT can be called as a function, else nil. | |
4078 A function is an object that can be applied to arguments, | |
4079 using for example `funcall' or `apply'. | |
4080 */ | |
4081 (object)) | |
4082 { | |
4083 if (SYMBOLP (object)) | |
4084 object = indirect_function (object, 0); | |
4085 | |
919 | 4086 if (COMPILED_FUNCTIONP (object) || SUBRP (object)) |
4087 return Qt; | |
4088 if (CONSP (object)) | |
4089 { | |
4090 Lisp_Object car = XCAR (object); | |
4091 if (EQ (car, Qlambda)) | |
4092 return Qt; | |
4093 if (EQ (car, Qautoload) | |
4094 && NILP (Fcar_safe (Fcdr_safe (Fcdr_safe (Fcdr_safe (XCDR (object))))))) | |
4095 return Qt; | |
4096 } | |
4097 return Qnil; | |
428 | 4098 } |
4099 | |
4100 static Lisp_Object | |
4101 function_argcount (Lisp_Object function, int function_min_args_p) | |
4102 { | |
4103 Lisp_Object orig_function = function; | |
4104 Lisp_Object arglist; | |
4105 | |
4106 retry: | |
4107 | |
4108 if (SYMBOLP (function)) | |
4109 function = indirect_function (function, 1); | |
4110 | |
4111 if (SUBRP (function)) | |
4112 { | |
442 | 4113 /* Using return with the ?: operator tickles a DEC CC compiler bug. */ |
4114 if (function_min_args_p) | |
4115 return Fsubr_min_args (function); | |
4116 else | |
4117 return Fsubr_max_args (function); | |
428 | 4118 } |
4119 else if (COMPILED_FUNCTIONP (function)) | |
4120 { | |
814 | 4121 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (function); |
4122 | |
1737 | 4123 if (!OPAQUEP (f->instructions)) |
4124 /* Lazily munge the instructions into a more efficient form */ | |
4125 /* Needed to set max_args */ | |
4126 optimize_compiled_function (function); | |
4127 | |
814 | 4128 if (function_min_args_p) |
4129 return make_int (f->min_args); | |
4130 else if (f->max_args == MANY) | |
4131 return Qnil; | |
4132 else | |
4133 return make_int (f->max_args); | |
428 | 4134 } |
4135 else if (CONSP (function)) | |
4136 { | |
4137 Lisp_Object funcar = XCAR (function); | |
4138 | |
4139 if (EQ (funcar, Qmacro)) | |
4140 { | |
4141 function = XCDR (function); | |
4142 goto retry; | |
4143 } | |
4144 else if (EQ (funcar, Qautoload)) | |
4145 { | |
970 | 4146 /* do_autoload GCPROs both arguments */ |
428 | 4147 do_autoload (function, orig_function); |
442 | 4148 function = orig_function; |
428 | 4149 goto retry; |
4150 } | |
4151 else if (EQ (funcar, Qlambda)) | |
4152 { | |
4153 arglist = Fcar (XCDR (function)); | |
4154 } | |
4155 else | |
4156 { | |
4157 goto invalid_function; | |
4158 } | |
4159 } | |
4160 else | |
4161 { | |
4162 invalid_function: | |
442 | 4163 return signal_invalid_function_error (orig_function); |
428 | 4164 } |
4165 | |
4166 { | |
4167 int argcount = 0; | |
4168 | |
4169 EXTERNAL_LIST_LOOP_2 (arg, arglist) | |
4170 { | |
4171 if (EQ (arg, Qand_optional)) | |
4172 { | |
4173 if (function_min_args_p) | |
4174 break; | |
4175 } | |
4176 else if (EQ (arg, Qand_rest)) | |
4177 { | |
4178 if (function_min_args_p) | |
4179 break; | |
4180 else | |
4181 return Qnil; | |
4182 } | |
4183 else | |
4184 { | |
4185 argcount++; | |
4186 } | |
4187 } | |
4188 | |
4189 return make_int (argcount); | |
4190 } | |
4191 } | |
4192 | |
4193 DEFUN ("function-min-args", Ffunction_min_args, 1, 1, 0, /* | |
617 | 4194 Return the minimum number of arguments a function may be called with. |
428 | 4195 The function may be any form that can be passed to `funcall', |
4196 any special form, or any macro. | |
853 | 4197 |
4198 To check if a function can be called with a specified number of | |
4199 arguments, use `function-allows-args'. | |
428 | 4200 */ |
4201 (function)) | |
4202 { | |
4203 return function_argcount (function, 1); | |
4204 } | |
4205 | |
4206 DEFUN ("function-max-args", Ffunction_max_args, 1, 1, 0, /* | |
617 | 4207 Return the maximum number of arguments a function may be called with. |
428 | 4208 The function may be any form that can be passed to `funcall', |
4209 any special form, or any macro. | |
4210 If the function takes an arbitrary number of arguments or is | |
4211 a built-in special form, nil is returned. | |
853 | 4212 |
4213 To check if a function can be called with a specified number of | |
4214 arguments, use `function-allows-args'. | |
428 | 4215 */ |
4216 (function)) | |
4217 { | |
4218 return function_argcount (function, 0); | |
4219 } | |
4220 | |
4221 | |
4222 DEFUN ("apply", Fapply, 2, MANY, 0, /* | |
4223 Call FUNCTION with the remaining args, using the last arg as a list of args. | |
4224 Thus, (apply '+ 1 2 '(3 4)) returns 10. | |
4225 */ | |
4226 (int nargs, Lisp_Object *args)) | |
4227 { | |
4228 /* This function can GC */ | |
4229 Lisp_Object fun = args[0]; | |
4230 Lisp_Object spread_arg = args [nargs - 1]; | |
4231 int numargs; | |
4232 int funcall_nargs; | |
4233 | |
4234 GET_EXTERNAL_LIST_LENGTH (spread_arg, numargs); | |
4235 | |
4236 if (numargs == 0) | |
4237 /* (apply foo 0 1 '()) */ | |
4238 return Ffuncall (nargs - 1, args); | |
4239 else if (numargs == 1) | |
4240 { | |
4241 /* (apply foo 0 1 '(2)) */ | |
4242 args [nargs - 1] = XCAR (spread_arg); | |
4243 return Ffuncall (nargs, args); | |
4244 } | |
4245 | |
4246 /* -1 for function, -1 for spread arg */ | |
4247 numargs = nargs - 2 + numargs; | |
4248 /* +1 for function */ | |
4249 funcall_nargs = 1 + numargs; | |
4250 | |
4251 if (SYMBOLP (fun)) | |
4252 fun = indirect_function (fun, 0); | |
4253 | |
4254 if (SUBRP (fun)) | |
4255 { | |
4256 Lisp_Subr *subr = XSUBR (fun); | |
4257 int max_args = subr->max_args; | |
4258 | |
4259 if (numargs < subr->min_args | |
4260 || (max_args >= 0 && max_args < numargs)) | |
4261 { | |
4262 /* Let funcall get the error */ | |
4263 } | |
4264 else if (max_args > numargs) | |
4265 { | |
4266 /* Avoid having funcall cons up yet another new vector of arguments | |
4267 by explicitly supplying nil's for optional values */ | |
4268 funcall_nargs += (max_args - numargs); | |
4269 } | |
4270 } | |
4271 else if (UNBOUNDP (fun)) | |
4272 { | |
4273 /* Let funcall get the error */ | |
4274 fun = args[0]; | |
4275 } | |
4276 | |
4277 { | |
4278 REGISTER int i; | |
4279 Lisp_Object *funcall_args = alloca_array (Lisp_Object, funcall_nargs); | |
4280 struct gcpro gcpro1; | |
4281 | |
4282 GCPRO1 (*funcall_args); | |
4283 gcpro1.nvars = funcall_nargs; | |
4284 | |
4285 /* Copy in the unspread args */ | |
4286 memcpy (funcall_args, args, (nargs - 1) * sizeof (Lisp_Object)); | |
4287 /* Spread the last arg we got. Its first element goes in | |
4288 the slot that it used to occupy, hence this value of I. */ | |
4289 for (i = nargs - 1; | |
4290 !NILP (spread_arg); /* i < 1 + numargs */ | |
4291 i++, spread_arg = XCDR (spread_arg)) | |
4292 { | |
4293 funcall_args [i] = XCAR (spread_arg); | |
4294 } | |
4295 /* Supply nil for optional args (to subrs) */ | |
4296 for (; i < funcall_nargs; i++) | |
4297 funcall_args[i] = Qnil; | |
4298 | |
4299 | |
4300 RETURN_UNGCPRO (Ffuncall (funcall_nargs, funcall_args)); | |
4301 } | |
4302 } | |
4303 | |
4304 /* Apply lambda list FUN to the NARGS evaluated arguments in ARGS and | |
4305 return the result of evaluation. */ | |
4306 | |
4307 static Lisp_Object | |
4308 funcall_lambda (Lisp_Object fun, int nargs, Lisp_Object args[]) | |
4309 { | |
4310 /* This function can GC */ | |
442 | 4311 Lisp_Object arglist, body, tail; |
428 | 4312 int speccount = specpdl_depth(); |
4313 REGISTER int i = 0; | |
4314 | |
4315 tail = XCDR (fun); | |
4316 | |
4317 if (!CONSP (tail)) | |
4318 goto invalid_function; | |
4319 | |
4320 arglist = XCAR (tail); | |
4321 body = XCDR (tail); | |
4322 | |
4323 { | |
4324 int optional = 0, rest = 0; | |
4325 | |
442 | 4326 EXTERNAL_LIST_LOOP_2 (symbol, arglist) |
428 | 4327 { |
4328 if (!SYMBOLP (symbol)) | |
4329 goto invalid_function; | |
4330 if (EQ (symbol, Qand_rest)) | |
4331 rest = 1; | |
4332 else if (EQ (symbol, Qand_optional)) | |
4333 optional = 1; | |
4334 else if (rest) | |
4335 { | |
4336 specbind (symbol, Flist (nargs - i, &args[i])); | |
4337 i = nargs; | |
4338 } | |
4339 else if (i < nargs) | |
4340 specbind (symbol, args[i++]); | |
4341 else if (!optional) | |
4342 goto wrong_number_of_arguments; | |
4343 else | |
4344 specbind (symbol, Qnil); | |
4345 } | |
4346 } | |
4347 | |
4348 if (i < nargs) | |
4349 goto wrong_number_of_arguments; | |
4350 | |
771 | 4351 return unbind_to_1 (speccount, Fprogn (body)); |
428 | 4352 |
4353 wrong_number_of_arguments: | |
436 | 4354 return signal_wrong_number_of_arguments_error (fun, nargs); |
428 | 4355 |
4356 invalid_function: | |
436 | 4357 return signal_invalid_function_error (fun); |
428 | 4358 } |
4359 | |
4360 | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4361 /* Multiple values. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4362 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4363 A multiple value object is returned by #'values if: |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4364 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4365 -- The number of arguments to #'values is not one, and: |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4366 -- Some special form in the call stack is prepared to handle more than |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4367 one multiple value. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4368 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4369 The return value of #'values-list is analogous to that of #'values. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4370 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4371 Henry Baker, in https://eprints.kfupm.edu.sa/31898/1/31898.pdf ("CONS |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4372 Should not CONS its Arguments, or, a Lazy Alloc is a Smart Alloc", ACM |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4373 Sigplan Notices 27,3 (March 1992),24-34.) says it should be possible to |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4374 allocate Common Lisp multiple-value objects on the stack, but this |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4375 assumes that variable-length records can be allocated on the stack, |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4376 something not true for us. As far as I can tell, it also ignores the |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4377 contexts where multiple-values need to be thrown, or maybe it thinks such |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4378 objects should be converted to heap allocation at that point. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4379 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4380 The specific multiple values saved and returned depend on how many |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4381 multiple-values special forms in the stack are interested in; for |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4382 example, if #'multiple-value-call is somewhere in the call stack, all |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4383 values passed to #'values will be saved and returned. If an expansion of |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4384 #'multiple-value-setq with 10 SYMS is the only part of the call stack |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4385 interested in multiple values, then a maximum of ten multiple values will |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4386 be saved and returned. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4387 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4388 (#'throw passes back multiple values in its VALUE argument; this is why |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4389 we can't just take the details of the most immediate |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4390 #'multiple-value-{whatever} call to work out which values to save, we |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4391 need to look at the whole stack, or, equivalently, the dynamic variables |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4392 we set to reflect the whole stack.) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4393 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4394 The first value passed to #'values will always be saved, since that is |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4395 needed to convert a multiple value object into a single value object, |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4396 something that is normally necessary independent of how many functions in |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4397 the call stack are interested in multiple values. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4398 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4399 However many values (for values of "however many" that are not one) are |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4400 saved and restored, the multiple value object knows how many arguments it |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4401 would contain were none to have been discarded, and will indicate this |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4402 on being printed from within GDB. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4403 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4404 In lisp-interaction-mode, no multiple values should be discarded (unless |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4405 they need to be for the sake of the correctness of the program); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4406 #'eval-interactive-with-multiple-value-list in lisp-mode.el wraps its |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4407 #'eval calls with #'multiple-value-list calls to avoid this. This means |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4408 that there is a small performance and memory penalty for code evaluated |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4409 in *scratch*; use M-: EXPRESSION RET if you really need to avoid |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4410 this. Lisp code execution that is not ultimately from hitting C-j in |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4411 *scratch*--that is, the vast vast majority of Lisp code execution--does |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4412 not have this penalty. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4413 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4414 Probably the most important aspect of multiple values is stated with |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4415 admirable clarity by CLTL2: |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4416 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4417 "No matter how many values a form produces, if the form is an argument |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4418 form in a function call, then exactly one value (the first one) is |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4419 used." |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4420 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4421 This means that most contexts, most of the time, will never see multiple |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4422 values. There are important exceptions; search the web for that text in |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4423 quotation marks and read the related chapter. This code handles all of |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4424 them, to my knowledge. Aidan Kehoe, Mon Mar 16 00:17:39 GMT 2009. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4425 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4426 static Lisp_Object |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4427 make_multiple_value (Lisp_Object first_value, Elemcount count, |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4428 Elemcount first_desired, Elemcount upper_limit) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4429 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4430 Bytecount sizem; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4431 struct multiple_value *mv; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4432 Elemcount i, allocated_count; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4433 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4434 assert (count != 1); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4435 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4436 if (1 != upper_limit && (0 == first_desired)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4437 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4438 /* We always allocate element zero, and that's taken into account when |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4439 working out allocated_count: */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4440 first_desired = 1; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4441 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4442 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4443 if (first_desired >= count) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4444 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4445 /* We can't pass anything back that our caller is interested in. Only |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4446 allocate for the first argument. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4447 allocated_count = 1; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4448 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4449 else |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4450 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4451 allocated_count = 1 + ((upper_limit > count ? count : upper_limit) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4452 - first_desired); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4453 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4454 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4455 sizem = FLEXIBLE_ARRAY_STRUCT_SIZEOF (multiple_value, |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4456 Lisp_Object, |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4457 contents, allocated_count); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4458 mv = (multiple_value *) BASIC_ALLOC_LCRECORD (sizem, |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4459 &lrecord_multiple_value); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4460 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4461 mv->count = count; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4462 mv->first_desired = first_desired; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4463 mv->allocated_count = allocated_count; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4464 mv->contents[0] = first_value; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4465 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4466 for (i = first_desired; i < upper_limit && i < count; ++i) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4467 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4468 mv->contents[1 + (i - first_desired)] = Qunbound; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4469 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4470 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4471 return wrap_multiple_value (mv); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4472 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4473 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4474 void |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4475 multiple_value_aset (Lisp_Object obj, Elemcount index, Lisp_Object value) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4476 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4477 struct multiple_value *mv = XMULTIPLE_VALUE (obj); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4478 Elemcount first_desired = mv->first_desired; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4479 Elemcount allocated_count = mv->allocated_count; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4480 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4481 if (index != 0 && |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4482 (index < first_desired || index >= (first_desired + allocated_count))) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4483 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4484 args_out_of_range (make_int (first_desired), |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4485 make_int (first_desired + allocated_count)); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4486 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4487 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4488 mv->contents[index == 0 ? 0 : 1 + (index - first_desired)] = value; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4489 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4490 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4491 Lisp_Object |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4492 multiple_value_aref (Lisp_Object obj, Elemcount index) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4493 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4494 struct multiple_value *mv = XMULTIPLE_VALUE (obj); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4495 Elemcount first_desired = mv->first_desired; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4496 Elemcount allocated_count = mv->allocated_count; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4497 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4498 if (index != 0 && |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4499 (index < first_desired || index >= (first_desired + allocated_count))) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4500 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4501 args_out_of_range (make_int (first_desired), |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4502 make_int (first_desired + allocated_count)); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4503 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4504 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4505 return mv->contents[index == 0 ? 0 : 1 + (index - first_desired)]; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4506 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4507 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4508 static void |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4509 print_multiple_value (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4510 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4511 struct multiple_value *mv = XMULTIPLE_VALUE (obj); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4512 Elemcount first_desired = mv->first_desired; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4513 Elemcount allocated_count = mv->allocated_count; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4514 Elemcount count = mv->count, index; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4515 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4516 if (print_readably) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4517 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4518 printing_unreadable_object ("multiple values"); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4519 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4520 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4521 if (0 == count) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4522 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4523 write_c_string (printcharfun, "#<zero-length multiple value>"); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4524 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4525 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4526 for (index = 0; index < count;) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4527 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4528 if (index != 0 && |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4529 (index < first_desired || |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4530 index >= (first_desired + (allocated_count - 1)))) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4531 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4532 write_fmt_string (printcharfun, "#<discarded-multiple-value %d>", |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4533 index); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4534 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4535 else |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4536 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4537 print_internal (multiple_value_aref (obj, index), |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4538 printcharfun, escapeflag); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4539 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4540 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4541 ++index; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4542 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4543 if (count > 1 && index < count) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4544 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4545 write_c_string (printcharfun, " ;\n"); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4546 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4547 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4548 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4549 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4550 static Lisp_Object |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4551 mark_multiple_value (Lisp_Object obj) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4552 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4553 struct multiple_value *mv = XMULTIPLE_VALUE (obj); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4554 Elemcount index, allocated_count = mv->allocated_count; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4555 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4556 for (index = 0; index < allocated_count; ++index) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4557 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4558 mark_object (mv->contents[index]); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4559 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4560 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4561 return Qnil; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4562 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4563 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4564 static Bytecount |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4565 size_multiple_value (const void *lheader) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4566 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4567 return FLEXIBLE_ARRAY_STRUCT_SIZEOF (struct multiple_value, |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4568 Lisp_Object, contents, |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4569 ((struct multiple_value *) lheader)-> |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4570 allocated_count); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4571 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4572 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4573 static const struct memory_description multiple_value_description[] = { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4574 { XD_LONG, offsetof (struct multiple_value, count) }, |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4575 { XD_ELEMCOUNT, offsetof (struct multiple_value, allocated_count) }, |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4576 { XD_LONG, offsetof (struct multiple_value, first_desired) }, |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4577 { XD_LISP_OBJECT_ARRAY, offsetof (struct multiple_value, contents), |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4578 XD_INDIRECT (1, 0) }, |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4579 { XD_END } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4580 }; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4581 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4582 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION ("multiple-value", multiple_value, |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4583 1, /*dumpable-flag*/ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4584 mark_multiple_value, |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4585 print_multiple_value, 0, |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4586 0, /* No equal method. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4587 0, /* No hash method. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4588 multiple_value_description, |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4589 size_multiple_value, |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4590 struct multiple_value); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4591 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4592 /* Given that FIRST and UPPER are the inclusive lower and exclusive upper |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4593 bounds for the multiple values we're interested in, modify (or don't) the |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4594 special variables used to indicate this to #'values and #'values-list. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4595 Returns the specpdl_depth() value before any modification. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4596 int |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4597 bind_multiple_value_limits (int first, int upper) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4598 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4599 int result = specpdl_depth(); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4600 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4601 if (!(upper > first)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4602 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4603 invalid_argument ("MULTIPLE-VALUE-UPPER-LIMIT must be greater than " |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4604 " FIRST-DESIRED-MULTIPLE-VALUE", Qunbound); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4605 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4606 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4607 if (upper > Vmultiple_values_limit) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4608 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4609 args_out_of_range (make_int (upper), make_int (Vmultiple_values_limit)); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4610 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4611 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4612 /* In the event that something back up the stack wants more multiple |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4613 values than we do, we need to keep its figures for |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4614 first_desired_multiple_value or multiple_value_current_limit both. It |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4615 may be that the form will throw past us. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4616 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4617 If first_desired_multiple_value is zero, this means it hasn't ever been |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4618 bound, and any value we have for first is appropriate to use. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4619 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4620 Zeroth element is always saved, no need to note that: */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4621 if (0 == first) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4622 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4623 first = 1; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4624 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4625 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4626 if (0 == first_desired_multiple_value |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4627 || first < first_desired_multiple_value) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4628 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4629 internal_bind_int (&first_desired_multiple_value, first); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4630 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4631 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4632 if (upper > multiple_value_current_limit) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4633 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4634 internal_bind_int (&multiple_value_current_limit, upper); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4635 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4636 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4637 return result; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4638 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4639 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4640 Lisp_Object |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4641 multiple_value_call (int nargs, Lisp_Object *args) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4642 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4643 /* The argument order here is horrible: */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4644 int i, speccount = XINT (args[3]); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4645 Lisp_Object result = Qnil, head = Fcons (args[0], Qnil), list_offset; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4646 struct gcpro gcpro1, gcpro2; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4647 Lisp_Object apply_args[2]; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4648 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4649 GCPRO2 (head, result); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4650 list_offset = head; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4651 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4652 assert (!(MULTIPLE_VALUEP (args[0]))); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4653 CHECK_FUNCTION (args[0]); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4654 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4655 /* Start at 4, to ignore the function, the speccount, and the arguments to |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4656 multiple-values-limit (which we don't discard because |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4657 #'multiple-value-list-internal needs them): */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4658 for (i = 4; i < nargs; ++i) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4659 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4660 result = args[i]; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4661 if (MULTIPLE_VALUEP (result)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4662 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4663 Lisp_Object val; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4664 Elemcount i, count = XMULTIPLE_VALUE_COUNT (result); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4665 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4666 for (i = 0; i < count; i++) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4667 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4668 val = multiple_value_aref (result, i); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4669 assert (!UNBOUNDP (val)); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4670 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4671 XSETCDR (list_offset, Fcons (val, Qnil)); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4672 list_offset = XCDR (list_offset); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4673 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4674 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4675 else |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4676 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4677 XSETCDR (list_offset, Fcons (result, Qnil)); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4678 list_offset = XCDR (list_offset); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4679 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4680 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4681 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4682 apply_args [0] = XCAR (head); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4683 apply_args [1] = XCDR (head); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4684 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4685 unbind_to (speccount); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4686 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4687 RETURN_UNGCPRO (Fapply (countof(apply_args), apply_args)); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4688 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4689 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4690 DEFUN ("multiple-value-call", Fmultiple_value_call, 1, UNEVALLED, 0, /* |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4691 Call FUNCTION with arguments FORMS, using multiple values when returned. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4692 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4693 All of the (possibly multiple) values returned by each form in FORMS are |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4694 gathered together, and given as arguments to FUNCTION; conceptually, this |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4695 function is a version of `apply' that by-passes the multiple values |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4696 infrastructure, treating multiple values as intercalated lists. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4697 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4698 arguments: (FUNCTION &rest FORMS) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4699 */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4700 (args)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4701 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4702 int listcount, i = 0, speccount; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4703 Lisp_Object *constructed_args; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4704 struct gcpro gcpro1; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4705 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4706 GET_EXTERNAL_LIST_LENGTH (args, listcount); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4707 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4708 constructed_args = alloca_array (Lisp_Object, listcount + 3); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4709 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4710 /* Fcar so we error on non-cons: */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4711 constructed_args[i] = IGNORE_MULTIPLE_VALUES (Feval (Fcar (args))); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4712 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4713 GCPRO1 (*constructed_args); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4714 gcpro1.nvars = ++i; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4715 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4716 /* The argument order is horrible here. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4717 constructed_args[i] = make_int (0); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4718 gcpro1.nvars = ++i; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4719 constructed_args[i] = make_int (Vmultiple_values_limit); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4720 gcpro1.nvars = ++i; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4721 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4722 speccount = bind_multiple_value_limits (0, Vmultiple_values_limit); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4723 constructed_args[i] = make_int (speccount); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4724 gcpro1.nvars = ++i; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4725 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4726 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4727 LIST_LOOP_2 (elt, XCDR (args)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4728 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4729 constructed_args[i] = Feval (elt); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4730 gcpro1.nvars = ++i; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4731 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4732 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4733 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4734 RETURN_UNGCPRO (multiple_value_call (listcount + 3, constructed_args)); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4735 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4736 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4737 Lisp_Object |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4738 multiple_value_list_internal (int nargs, Lisp_Object *args) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4739 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4740 int first = XINT (args[0]), upper = XINT (args[1]), |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4741 speccount = XINT(args[2]); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4742 Lisp_Object result = Qnil; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4743 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4744 assert (nargs == 4); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4745 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4746 result = args[3]; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4747 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4748 unbind_to (speccount); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4749 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4750 if (MULTIPLE_VALUEP (result)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4751 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4752 Lisp_Object head = Fcons (Qnil, Qnil); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4753 Lisp_Object list_offset = head, val; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4754 Elemcount count = XMULTIPLE_VALUE_COUNT(result); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4755 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4756 for (; first < upper && first < count; ++first) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4757 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4758 val = multiple_value_aref (result, first); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4759 assert (!UNBOUNDP (val)); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4760 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4761 XSETCDR (list_offset, Fcons (val, Qnil)); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4762 list_offset = XCDR (list_offset); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4763 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4764 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4765 return XCDR (head); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4766 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4767 else |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4768 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4769 if (first == 0) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4770 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4771 return Fcons (result, Qnil); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4772 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4773 else |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4774 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4775 return Qnil; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4776 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4777 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4778 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4779 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4780 DEFUN ("multiple-value-list-internal", Fmultiple_value_list_internal, 3, |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4781 UNEVALLED, 0, /* |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4782 Evaluate FORM. Return a list of multiple vals reflecting the other two args. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4783 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4784 Don't use this. Use `multiple-value-list', the macro specified by Common |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4785 Lisp, instead. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4786 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4787 FIRST-DESIRED-MULTIPLE-VALUE is the first element in list of multiple values |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4788 to pass back. MULTIPLE-VALUE-UPPER-LIMIT is the exclusive upper limit on |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4789 the indexes within the values that may be passed back; this function will |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4790 never return a list longer than MULTIPLE-VALUE-UPPER-LIMIT - |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4791 FIRST-DESIRED-MULTIPLE-VALUE. It may return a list shorter than that, if |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4792 `values' or `values-list' do not supply enough elements. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4793 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4794 arguments: (FIRST-DESIRED-MULTIPLE-VALUE MULTIPLE-VALUE-UPPER-LIMIT FORM) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4795 */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4796 (args)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4797 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4798 Lisp_Object argv[4]; |
4686
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
4799 int first, upper, nargs; |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4800 struct gcpro gcpro1; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4801 |
4686
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
4802 GET_LIST_LENGTH (args, nargs); |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
4803 if (nargs != 3) |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
4804 { |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
4805 Fsignal (Qwrong_number_of_arguments, |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
4806 list2 (Qmultiple_value_list_internal, make_int (nargs))); |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
4807 } |
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
4808 |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4809 argv[0] = IGNORE_MULTIPLE_VALUES (Feval (XCAR (args))); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4810 CHECK_NATNUM (argv[0]); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4811 first = XINT (argv[0]); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4812 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4813 GCPRO1 (argv[0]); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4814 gcpro1.nvars = 1; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4815 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4816 args = XCDR (args); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4817 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4818 argv[1] = IGNORE_MULTIPLE_VALUES (Feval (XCAR (args))); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4819 CHECK_NATNUM (argv[1]); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4820 upper = XINT (argv[1]); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4821 gcpro1.nvars = 2; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4822 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4823 /* The unintuitive order of things here is for the sake of the bytecode; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4824 the alternative would be to encode the number of arguments in the |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4825 bytecode stream, which complicates things if we have more than 255 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4826 arguments. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4827 argv[2] = make_int (bind_multiple_value_limits (first, upper)); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4828 gcpro1.nvars = 3; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4829 args = XCDR (args); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4830 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4831 /* GCPROing in this function is not strictly necessary, this Feval is the |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4832 only point that may cons up data that is not immediately discarded, and |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4833 within it is the only point (in Fmultiple_value_list_internal and |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4834 multiple_value_list) that we can garbage collect. But I'm conservative, |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4835 and this function is called so rarely (only from interpreted code) that |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4836 it doesn't matter for performance. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4837 argv[3] = Feval (XCAR (args)); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4838 gcpro1.nvars = 4; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4839 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4840 RETURN_UNGCPRO (multiple_value_list_internal (countof (argv), argv)); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4841 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4842 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4843 DEFUN ("multiple-value-prog1", Fmultiple_value_prog1, 1, UNEVALLED, 0, /* |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4844 Similar to `prog1', but return any multiple values from the first form. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4845 `prog1' itself will never return multiple values. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4846 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4847 arguments: (FIRST &rest BODY) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4848 */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4849 (args)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4850 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4851 /* This function can GC */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4852 Lisp_Object val; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4853 struct gcpro gcpro1; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4854 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4855 val = Feval (XCAR (args)); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4856 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4857 GCPRO1 (val); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4858 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4859 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4860 LIST_LOOP_2 (form, XCDR (args)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4861 Feval (form); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4862 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4863 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4864 RETURN_UNGCPRO (val); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4865 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4866 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4867 DEFUN ("values", Fvalues, 0, MANY, 0, /* |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4868 Return all ARGS as multiple values. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4869 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4870 arguments: (&rest ARGS) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4871 */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4872 (int nargs, Lisp_Object *args)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4873 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4874 Lisp_Object result = Qnil; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4875 int counting = 1; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4876 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4877 /* Pathological cases, no need to cons up an object: */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4878 if (1 == nargs || 1 == multiple_value_current_limit) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4879 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4880 return nargs ? args[0] : Qnil; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4881 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4882 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4883 /* If nargs is zero, this code is correct and desirable. With |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4884 #'multiple-value-call, we want zero-length multiple values in the |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4885 argument list to be discarded entirely, and we can't do this if we |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4886 transform them to nil. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4887 result = make_multiple_value (nargs ? args[0] : Qnil, nargs, |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4888 first_desired_multiple_value, |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4889 multiple_value_current_limit); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4890 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4891 for (; counting < nargs; ++counting) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4892 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4893 if (counting >= first_desired_multiple_value && |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4894 counting < multiple_value_current_limit) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4895 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4896 multiple_value_aset (result, counting, args[counting]); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4897 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4898 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4899 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4900 return result; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4901 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4902 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4903 DEFUN ("values-list", Fvalues_list, 1, 1, 0, /* |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4904 Return all the elements of LIST as multiple values. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4905 */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4906 (list)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4907 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4908 Lisp_Object result = Qnil; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4909 int counting = 1, listcount; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4910 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4911 GET_EXTERNAL_LIST_LENGTH (list, listcount); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4912 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4913 /* Pathological cases, no need to cons up an object: */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4914 if (1 == listcount || 1 == multiple_value_current_limit) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4915 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4916 return Fcar_safe (list); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4917 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4918 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4919 result = make_multiple_value (Fcar_safe (list), listcount, |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4920 first_desired_multiple_value, |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4921 multiple_value_current_limit); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4922 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4923 list = Fcdr_safe (list); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4924 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4925 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4926 EXTERNAL_LIST_LOOP_2 (elt, list) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4927 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4928 if (counting >= first_desired_multiple_value && |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4929 counting < multiple_value_current_limit) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4930 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4931 multiple_value_aset (result, counting, elt); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4932 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4933 ++counting; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4934 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4935 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4936 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4937 return result; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4938 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4939 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4940 Lisp_Object |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4941 values2 (Lisp_Object first, Lisp_Object second) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4942 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4943 Lisp_Object argv[2]; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4944 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4945 argv[0] = first; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4946 argv[1] = second; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4947 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4948 return Fvalues (countof (argv), argv); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4949 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4950 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
4951 |
428 | 4952 /************************************************************************/ |
4953 /* Run hook variables in various ways. */ | |
4954 /************************************************************************/ | |
4955 | |
4956 DEFUN ("run-hooks", Frun_hooks, 1, MANY, 0, /* | |
4957 Run each hook in HOOKS. Major mode functions use this. | |
4958 Each argument should be a symbol, a hook variable. | |
4959 These symbols are processed in the order specified. | |
4960 If a hook symbol has a non-nil value, that value may be a function | |
4961 or a list of functions to be called to run the hook. | |
4962 If the value is a function, it is called with no arguments. | |
4963 If it is a list, the elements are called, in order, with no arguments. | |
4964 | |
4965 To make a hook variable buffer-local, use `make-local-hook', | |
4966 not `make-local-variable'. | |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
4967 |
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
4968 arguments: (&rest HOOKS) |
428 | 4969 */ |
4970 (int nargs, Lisp_Object *args)) | |
4971 { | |
4972 REGISTER int i; | |
4973 | |
4974 for (i = 0; i < nargs; i++) | |
4975 run_hook_with_args (1, args + i, RUN_HOOKS_TO_COMPLETION); | |
4976 | |
4977 return Qnil; | |
4978 } | |
4979 | |
4980 DEFUN ("run-hook-with-args", Frun_hook_with_args, 1, MANY, 0, /* | |
4981 Run HOOK with the specified arguments ARGS. | |
4982 HOOK should be a symbol, a hook variable. If HOOK has a non-nil | |
4983 value, that value may be a function or a list of functions to be | |
4984 called to run the hook. If the value is a function, it is called with | |
4985 the given arguments and its return value is returned. If it is a list | |
4986 of functions, those functions are called, in order, | |
4987 with the given arguments ARGS. | |
444 | 4988 It is best not to depend on the value returned by `run-hook-with-args', |
428 | 4989 as that may change. |
4990 | |
4991 To make a hook variable buffer-local, use `make-local-hook', | |
4992 not `make-local-variable'. | |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
4993 |
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
4994 arguments: (HOOK &rest ARGS) |
428 | 4995 */ |
4996 (int nargs, Lisp_Object *args)) | |
4997 { | |
4998 return run_hook_with_args (nargs, args, RUN_HOOKS_TO_COMPLETION); | |
4999 } | |
5000 | |
5001 DEFUN ("run-hook-with-args-until-success", Frun_hook_with_args_until_success, 1, MANY, 0, /* | |
5002 Run HOOK with the specified arguments ARGS. | |
5003 HOOK should be a symbol, a hook variable. Its value should | |
5004 be a list of functions. We call those functions, one by one, | |
5005 passing arguments ARGS to each of them, until one of them | |
5006 returns a non-nil value. Then we return that value. | |
5007 If all the functions return nil, we return nil. | |
5008 | |
5009 To make a hook variable buffer-local, use `make-local-hook', | |
5010 not `make-local-variable'. | |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
5011 |
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
5012 arguments: (HOOK &rest ARGS) |
428 | 5013 */ |
5014 (int nargs, Lisp_Object *args)) | |
5015 { | |
5016 return run_hook_with_args (nargs, args, RUN_HOOKS_UNTIL_SUCCESS); | |
5017 } | |
5018 | |
5019 DEFUN ("run-hook-with-args-until-failure", Frun_hook_with_args_until_failure, 1, MANY, 0, /* | |
5020 Run HOOK with the specified arguments ARGS. | |
5021 HOOK should be a symbol, a hook variable. Its value should | |
5022 be a list of functions. We call those functions, one by one, | |
5023 passing arguments ARGS to each of them, until one of them | |
5024 returns nil. Then we return nil. | |
5025 If all the functions return non-nil, we return non-nil. | |
5026 | |
5027 To make a hook variable buffer-local, use `make-local-hook', | |
5028 not `make-local-variable'. | |
4642
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
5029 |
48b45a606961
Support #'function-arglist with built-in special forms.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4624
diff
changeset
|
5030 arguments: (HOOK &rest ARGS) |
428 | 5031 */ |
5032 (int nargs, Lisp_Object *args)) | |
5033 { | |
5034 return run_hook_with_args (nargs, args, RUN_HOOKS_UNTIL_FAILURE); | |
5035 } | |
5036 | |
5037 /* ARGS[0] should be a hook symbol. | |
5038 Call each of the functions in the hook value, passing each of them | |
5039 as arguments all the rest of ARGS (all NARGS - 1 elements). | |
5040 COND specifies a condition to test after each call | |
5041 to decide whether to stop. | |
5042 The caller (or its caller, etc) must gcpro all of ARGS, | |
5043 except that it isn't necessary to gcpro ARGS[0]. */ | |
5044 | |
5045 Lisp_Object | |
5046 run_hook_with_args_in_buffer (struct buffer *buf, int nargs, Lisp_Object *args, | |
5047 enum run_hooks_condition cond) | |
5048 { | |
5049 Lisp_Object sym, val, ret; | |
5050 | |
5051 if (!initialized || preparing_for_armageddon) | |
5052 /* We need to bail out of here pronto. */ | |
5053 return Qnil; | |
5054 | |
3092 | 5055 #ifndef NEW_GC |
428 | 5056 /* Whenever gc_in_progress is true, preparing_for_armageddon |
5057 will also be true unless something is really hosed. */ | |
5058 assert (!gc_in_progress); | |
3092 | 5059 #endif /* not NEW_GC */ |
428 | 5060 |
5061 sym = args[0]; | |
771 | 5062 val = symbol_value_in_buffer (sym, wrap_buffer (buf)); |
428 | 5063 ret = (cond == RUN_HOOKS_UNTIL_FAILURE ? Qt : Qnil); |
5064 | |
5065 if (UNBOUNDP (val) || NILP (val)) | |
5066 return ret; | |
5067 else if (!CONSP (val) || EQ (XCAR (val), Qlambda)) | |
5068 { | |
5069 args[0] = val; | |
5070 return Ffuncall (nargs, args); | |
5071 } | |
5072 else | |
5073 { | |
5074 struct gcpro gcpro1, gcpro2, gcpro3; | |
5075 Lisp_Object globals = Qnil; | |
5076 GCPRO3 (sym, val, globals); | |
5077 | |
5078 for (; | |
5079 CONSP (val) && ((cond == RUN_HOOKS_TO_COMPLETION) | |
5080 || (cond == RUN_HOOKS_UNTIL_SUCCESS ? NILP (ret) | |
5081 : !NILP (ret))); | |
5082 val = XCDR (val)) | |
5083 { | |
5084 if (EQ (XCAR (val), Qt)) | |
5085 { | |
5086 /* t indicates this hook has a local binding; | |
5087 it means to run the global binding too. */ | |
5088 globals = Fdefault_value (sym); | |
5089 | |
5090 if ((! CONSP (globals) || EQ (XCAR (globals), Qlambda)) && | |
5091 ! NILP (globals)) | |
5092 { | |
5093 args[0] = globals; | |
5094 ret = Ffuncall (nargs, args); | |
5095 } | |
5096 else | |
5097 { | |
5098 for (; | |
5099 CONSP (globals) && ((cond == RUN_HOOKS_TO_COMPLETION) | |
5100 || (cond == RUN_HOOKS_UNTIL_SUCCESS | |
5101 ? NILP (ret) | |
5102 : !NILP (ret))); | |
5103 globals = XCDR (globals)) | |
5104 { | |
5105 args[0] = XCAR (globals); | |
5106 /* In a global value, t should not occur. If it does, we | |
5107 must ignore it to avoid an endless loop. */ | |
5108 if (!EQ (args[0], Qt)) | |
5109 ret = Ffuncall (nargs, args); | |
5110 } | |
5111 } | |
5112 } | |
5113 else | |
5114 { | |
5115 args[0] = XCAR (val); | |
5116 ret = Ffuncall (nargs, args); | |
5117 } | |
5118 } | |
5119 | |
5120 UNGCPRO; | |
5121 return ret; | |
5122 } | |
5123 } | |
5124 | |
5125 Lisp_Object | |
5126 run_hook_with_args (int nargs, Lisp_Object *args, | |
5127 enum run_hooks_condition cond) | |
5128 { | |
5129 return run_hook_with_args_in_buffer (current_buffer, nargs, args, cond); | |
5130 } | |
5131 | |
5132 #if 0 | |
5133 | |
853 | 5134 /* From FSF 19.30, not currently used; seems like a big kludge. */ |
428 | 5135 |
5136 /* Run a hook symbol ARGS[0], but use FUNLIST instead of the actual | |
5137 present value of that symbol. | |
5138 Call each element of FUNLIST, | |
5139 passing each of them the rest of ARGS. | |
5140 The caller (or its caller, etc) must gcpro all of ARGS, | |
5141 except that it isn't necessary to gcpro ARGS[0]. */ | |
5142 | |
5143 Lisp_Object | |
5144 run_hook_list_with_args (Lisp_Object funlist, int nargs, Lisp_Object *args) | |
5145 { | |
853 | 5146 omitted; |
428 | 5147 } |
5148 | |
5149 #endif /* 0 */ | |
5150 | |
5151 void | |
5152 va_run_hook_with_args (Lisp_Object hook_var, int nargs, ...) | |
5153 { | |
5154 /* This function can GC */ | |
5155 struct gcpro gcpro1; | |
5156 int i; | |
5157 va_list vargs; | |
5158 Lisp_Object *funcall_args = alloca_array (Lisp_Object, 1 + nargs); | |
5159 | |
5160 va_start (vargs, nargs); | |
5161 funcall_args[0] = hook_var; | |
5162 for (i = 0; i < nargs; i++) | |
5163 funcall_args[i + 1] = va_arg (vargs, Lisp_Object); | |
5164 va_end (vargs); | |
5165 | |
5166 GCPRO1 (*funcall_args); | |
5167 gcpro1.nvars = nargs + 1; | |
5168 run_hook_with_args (nargs + 1, funcall_args, RUN_HOOKS_TO_COMPLETION); | |
5169 UNGCPRO; | |
5170 } | |
5171 | |
5172 void | |
5173 va_run_hook_with_args_in_buffer (struct buffer *buf, Lisp_Object hook_var, | |
5174 int nargs, ...) | |
5175 { | |
5176 /* This function can GC */ | |
5177 struct gcpro gcpro1; | |
5178 int i; | |
5179 va_list vargs; | |
5180 Lisp_Object *funcall_args = alloca_array (Lisp_Object, 1 + nargs); | |
5181 | |
5182 va_start (vargs, nargs); | |
5183 funcall_args[0] = hook_var; | |
5184 for (i = 0; i < nargs; i++) | |
5185 funcall_args[i + 1] = va_arg (vargs, Lisp_Object); | |
5186 va_end (vargs); | |
5187 | |
5188 GCPRO1 (*funcall_args); | |
5189 gcpro1.nvars = nargs + 1; | |
5190 run_hook_with_args_in_buffer (buf, nargs + 1, funcall_args, | |
5191 RUN_HOOKS_TO_COMPLETION); | |
5192 UNGCPRO; | |
5193 } | |
5194 | |
5195 Lisp_Object | |
5196 run_hook (Lisp_Object hook) | |
5197 { | |
853 | 5198 return run_hook_with_args (1, &hook, RUN_HOOKS_TO_COMPLETION); |
428 | 5199 } |
5200 | |
5201 | |
5202 /************************************************************************/ | |
5203 /* Front-ends to eval, funcall, apply */ | |
5204 /************************************************************************/ | |
5205 | |
5206 /* Apply fn to arg */ | |
5207 Lisp_Object | |
5208 apply1 (Lisp_Object fn, Lisp_Object arg) | |
5209 { | |
5210 /* This function can GC */ | |
5211 struct gcpro gcpro1; | |
5212 Lisp_Object args[2]; | |
5213 | |
5214 if (NILP (arg)) | |
5215 return Ffuncall (1, &fn); | |
5216 GCPRO1 (args[0]); | |
5217 gcpro1.nvars = 2; | |
5218 args[0] = fn; | |
5219 args[1] = arg; | |
5220 RETURN_UNGCPRO (Fapply (2, args)); | |
5221 } | |
5222 | |
5223 /* Call function fn on no arguments */ | |
5224 Lisp_Object | |
5225 call0 (Lisp_Object fn) | |
5226 { | |
5227 /* This function can GC */ | |
5228 struct gcpro gcpro1; | |
5229 | |
5230 GCPRO1 (fn); | |
5231 RETURN_UNGCPRO (Ffuncall (1, &fn)); | |
5232 } | |
5233 | |
5234 /* Call function fn with argument arg0 */ | |
5235 Lisp_Object | |
5236 call1 (Lisp_Object fn, | |
5237 Lisp_Object arg0) | |
5238 { | |
5239 /* This function can GC */ | |
5240 struct gcpro gcpro1; | |
5241 Lisp_Object args[2]; | |
5242 args[0] = fn; | |
5243 args[1] = arg0; | |
5244 GCPRO1 (args[0]); | |
5245 gcpro1.nvars = 2; | |
5246 RETURN_UNGCPRO (Ffuncall (2, args)); | |
5247 } | |
5248 | |
5249 /* Call function fn with arguments arg0, arg1 */ | |
5250 Lisp_Object | |
5251 call2 (Lisp_Object fn, | |
5252 Lisp_Object arg0, Lisp_Object arg1) | |
5253 { | |
5254 /* This function can GC */ | |
5255 struct gcpro gcpro1; | |
5256 Lisp_Object args[3]; | |
5257 args[0] = fn; | |
5258 args[1] = arg0; | |
5259 args[2] = arg1; | |
5260 GCPRO1 (args[0]); | |
5261 gcpro1.nvars = 3; | |
5262 RETURN_UNGCPRO (Ffuncall (3, args)); | |
5263 } | |
5264 | |
5265 /* Call function fn with arguments arg0, arg1, arg2 */ | |
5266 Lisp_Object | |
5267 call3 (Lisp_Object fn, | |
5268 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2) | |
5269 { | |
5270 /* This function can GC */ | |
5271 struct gcpro gcpro1; | |
5272 Lisp_Object args[4]; | |
5273 args[0] = fn; | |
5274 args[1] = arg0; | |
5275 args[2] = arg1; | |
5276 args[3] = arg2; | |
5277 GCPRO1 (args[0]); | |
5278 gcpro1.nvars = 4; | |
5279 RETURN_UNGCPRO (Ffuncall (4, args)); | |
5280 } | |
5281 | |
5282 /* Call function fn with arguments arg0, arg1, arg2, arg3 */ | |
5283 Lisp_Object | |
5284 call4 (Lisp_Object fn, | |
5285 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2, | |
5286 Lisp_Object arg3) | |
5287 { | |
5288 /* This function can GC */ | |
5289 struct gcpro gcpro1; | |
5290 Lisp_Object args[5]; | |
5291 args[0] = fn; | |
5292 args[1] = arg0; | |
5293 args[2] = arg1; | |
5294 args[3] = arg2; | |
5295 args[4] = arg3; | |
5296 GCPRO1 (args[0]); | |
5297 gcpro1.nvars = 5; | |
5298 RETURN_UNGCPRO (Ffuncall (5, args)); | |
5299 } | |
5300 | |
5301 /* Call function fn with arguments arg0, arg1, arg2, arg3, arg4 */ | |
5302 Lisp_Object | |
5303 call5 (Lisp_Object fn, | |
5304 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2, | |
5305 Lisp_Object arg3, Lisp_Object arg4) | |
5306 { | |
5307 /* This function can GC */ | |
5308 struct gcpro gcpro1; | |
5309 Lisp_Object args[6]; | |
5310 args[0] = fn; | |
5311 args[1] = arg0; | |
5312 args[2] = arg1; | |
5313 args[3] = arg2; | |
5314 args[4] = arg3; | |
5315 args[5] = arg4; | |
5316 GCPRO1 (args[0]); | |
5317 gcpro1.nvars = 6; | |
5318 RETURN_UNGCPRO (Ffuncall (6, args)); | |
5319 } | |
5320 | |
5321 Lisp_Object | |
5322 call6 (Lisp_Object fn, | |
5323 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2, | |
5324 Lisp_Object arg3, Lisp_Object arg4, Lisp_Object arg5) | |
5325 { | |
5326 /* This function can GC */ | |
5327 struct gcpro gcpro1; | |
5328 Lisp_Object args[7]; | |
5329 args[0] = fn; | |
5330 args[1] = arg0; | |
5331 args[2] = arg1; | |
5332 args[3] = arg2; | |
5333 args[4] = arg3; | |
5334 args[5] = arg4; | |
5335 args[6] = arg5; | |
5336 GCPRO1 (args[0]); | |
5337 gcpro1.nvars = 7; | |
5338 RETURN_UNGCPRO (Ffuncall (7, args)); | |
5339 } | |
5340 | |
5341 Lisp_Object | |
5342 call7 (Lisp_Object fn, | |
5343 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2, | |
5344 Lisp_Object arg3, Lisp_Object arg4, Lisp_Object arg5, | |
5345 Lisp_Object arg6) | |
5346 { | |
5347 /* This function can GC */ | |
5348 struct gcpro gcpro1; | |
5349 Lisp_Object args[8]; | |
5350 args[0] = fn; | |
5351 args[1] = arg0; | |
5352 args[2] = arg1; | |
5353 args[3] = arg2; | |
5354 args[4] = arg3; | |
5355 args[5] = arg4; | |
5356 args[6] = arg5; | |
5357 args[7] = arg6; | |
5358 GCPRO1 (args[0]); | |
5359 gcpro1.nvars = 8; | |
5360 RETURN_UNGCPRO (Ffuncall (8, args)); | |
5361 } | |
5362 | |
5363 Lisp_Object | |
5364 call8 (Lisp_Object fn, | |
5365 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2, | |
5366 Lisp_Object arg3, Lisp_Object arg4, Lisp_Object arg5, | |
5367 Lisp_Object arg6, Lisp_Object arg7) | |
5368 { | |
5369 /* This function can GC */ | |
5370 struct gcpro gcpro1; | |
5371 Lisp_Object args[9]; | |
5372 args[0] = fn; | |
5373 args[1] = arg0; | |
5374 args[2] = arg1; | |
5375 args[3] = arg2; | |
5376 args[4] = arg3; | |
5377 args[5] = arg4; | |
5378 args[6] = arg5; | |
5379 args[7] = arg6; | |
5380 args[8] = arg7; | |
5381 GCPRO1 (args[0]); | |
5382 gcpro1.nvars = 9; | |
5383 RETURN_UNGCPRO (Ffuncall (9, args)); | |
5384 } | |
5385 | |
5386 Lisp_Object | |
5387 call0_in_buffer (struct buffer *buf, Lisp_Object fn) | |
5388 { | |
5389 if (current_buffer == buf) | |
5390 return call0 (fn); | |
5391 else | |
5392 { | |
5393 Lisp_Object val; | |
5394 int speccount = specpdl_depth(); | |
5395 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); | |
5396 set_buffer_internal (buf); | |
5397 val = call0 (fn); | |
771 | 5398 unbind_to (speccount); |
428 | 5399 return val; |
5400 } | |
5401 } | |
5402 | |
5403 Lisp_Object | |
5404 call1_in_buffer (struct buffer *buf, Lisp_Object fn, | |
5405 Lisp_Object arg0) | |
5406 { | |
5407 if (current_buffer == buf) | |
5408 return call1 (fn, arg0); | |
5409 else | |
5410 { | |
5411 Lisp_Object val; | |
5412 int speccount = specpdl_depth(); | |
5413 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); | |
5414 set_buffer_internal (buf); | |
5415 val = call1 (fn, arg0); | |
771 | 5416 unbind_to (speccount); |
428 | 5417 return val; |
5418 } | |
5419 } | |
5420 | |
5421 Lisp_Object | |
5422 call2_in_buffer (struct buffer *buf, Lisp_Object fn, | |
5423 Lisp_Object arg0, Lisp_Object arg1) | |
5424 { | |
5425 if (current_buffer == buf) | |
5426 return call2 (fn, arg0, arg1); | |
5427 else | |
5428 { | |
5429 Lisp_Object val; | |
5430 int speccount = specpdl_depth(); | |
5431 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); | |
5432 set_buffer_internal (buf); | |
5433 val = call2 (fn, arg0, arg1); | |
771 | 5434 unbind_to (speccount); |
428 | 5435 return val; |
5436 } | |
5437 } | |
5438 | |
5439 Lisp_Object | |
5440 call3_in_buffer (struct buffer *buf, Lisp_Object fn, | |
5441 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2) | |
5442 { | |
5443 if (current_buffer == buf) | |
5444 return call3 (fn, arg0, arg1, arg2); | |
5445 else | |
5446 { | |
5447 Lisp_Object val; | |
5448 int speccount = specpdl_depth(); | |
5449 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); | |
5450 set_buffer_internal (buf); | |
5451 val = call3 (fn, arg0, arg1, arg2); | |
771 | 5452 unbind_to (speccount); |
428 | 5453 return val; |
5454 } | |
5455 } | |
5456 | |
5457 Lisp_Object | |
5458 call4_in_buffer (struct buffer *buf, Lisp_Object fn, | |
5459 Lisp_Object arg0, Lisp_Object arg1, Lisp_Object arg2, | |
5460 Lisp_Object arg3) | |
5461 { | |
5462 if (current_buffer == buf) | |
5463 return call4 (fn, arg0, arg1, arg2, arg3); | |
5464 else | |
5465 { | |
5466 Lisp_Object val; | |
5467 int speccount = specpdl_depth(); | |
5468 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); | |
5469 set_buffer_internal (buf); | |
5470 val = call4 (fn, arg0, arg1, arg2, arg3); | |
771 | 5471 unbind_to (speccount); |
428 | 5472 return val; |
5473 } | |
5474 } | |
5475 | |
5476 Lisp_Object | |
5477 eval_in_buffer (struct buffer *buf, Lisp_Object form) | |
5478 { | |
5479 if (current_buffer == buf) | |
5480 return Feval (form); | |
5481 else | |
5482 { | |
5483 Lisp_Object val; | |
5484 int speccount = specpdl_depth(); | |
5485 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); | |
5486 set_buffer_internal (buf); | |
5487 val = Feval (form); | |
771 | 5488 unbind_to (speccount); |
428 | 5489 return val; |
5490 } | |
5491 } | |
5492 | |
5493 | |
5494 /************************************************************************/ | |
5495 /* Error-catching front-ends to eval, funcall, apply */ | |
5496 /************************************************************************/ | |
5497 | |
853 | 5498 int |
5499 get_inhibit_flags (void) | |
5500 { | |
5501 return inhibit_flags; | |
5502 } | |
5503 | |
5504 void | |
2286 | 5505 check_allowed_operation (int what, Lisp_Object obj, Lisp_Object UNUSED (prop)) |
853 | 5506 { |
5507 if (inhibit_flags & INHIBIT_EXISTING_BUFFER_TEXT_MODIFICATION) | |
5508 { | |
5509 if (what == OPERATION_MODIFY_BUFFER_TEXT && BUFFERP (obj) | |
5510 && NILP (memq_no_quit (obj, Vmodifiable_buffers))) | |
5511 invalid_change | |
5512 ("Modification of this buffer not currently permitted", obj); | |
5513 } | |
5514 if (inhibit_flags & INHIBIT_EXISTING_PERMANENT_DISPLAY_OBJECT_DELETION) | |
5515 { | |
5516 if (what == OPERATION_DELETE_OBJECT | |
5517 && (BUFFERP (obj) || WINDOWP (obj) || FRAMEP (obj) || DEVICEP (obj) | |
5518 || CONSOLEP (obj)) | |
5519 && NILP (memq_no_quit (obj, Vdeletable_permanent_display_objects))) | |
5520 invalid_change | |
5521 ("Deletion of this object not currently permitted", obj); | |
5522 } | |
5523 } | |
5524 | |
5525 void | |
5526 note_object_created (Lisp_Object obj) | |
5527 { | |
5528 if (inhibit_flags & INHIBIT_EXISTING_BUFFER_TEXT_MODIFICATION) | |
5529 { | |
5530 if (BUFFERP (obj)) | |
5531 Vmodifiable_buffers = Fcons (obj, Vmodifiable_buffers); | |
5532 } | |
5533 if (inhibit_flags & INHIBIT_EXISTING_PERMANENT_DISPLAY_OBJECT_DELETION) | |
5534 { | |
5535 if (BUFFERP (obj) || WINDOWP (obj) || FRAMEP (obj) || DEVICEP (obj) | |
5536 || CONSOLEP (obj)) | |
5537 Vdeletable_permanent_display_objects = | |
5538 Fcons (obj, Vdeletable_permanent_display_objects); | |
5539 } | |
5540 } | |
5541 | |
5542 void | |
5543 note_object_deleted (Lisp_Object obj) | |
5544 { | |
5545 if (inhibit_flags & INHIBIT_EXISTING_BUFFER_TEXT_MODIFICATION) | |
5546 { | |
5547 if (BUFFERP (obj)) | |
5548 Vmodifiable_buffers = delq_no_quit (obj, Vmodifiable_buffers); | |
5549 } | |
5550 if (inhibit_flags & INHIBIT_EXISTING_PERMANENT_DISPLAY_OBJECT_DELETION) | |
5551 { | |
5552 if (BUFFERP (obj) || WINDOWP (obj) || FRAMEP (obj) || DEVICEP (obj) | |
5553 || CONSOLEP (obj)) | |
5554 Vdeletable_permanent_display_objects = | |
5555 delq_no_quit (obj, Vdeletable_permanent_display_objects); | |
5556 } | |
5557 } | |
5558 | |
5559 struct call_trapping_problems | |
5560 { | |
5561 Lisp_Object catchtag; | |
5562 Lisp_Object error_conditions; | |
5563 Lisp_Object data; | |
5564 Lisp_Object backtrace; | |
5565 Lisp_Object warning_class; | |
5566 | |
867 | 5567 const CIbyte *warning_string; |
853 | 5568 Lisp_Object (*fun) (void *); |
5569 void *arg; | |
5570 }; | |
428 | 5571 |
2532 | 5572 static Lisp_Object |
5573 maybe_get_trapping_problems_backtrace (void) | |
5574 { | |
5575 Lisp_Object backtrace; | |
853 | 5576 |
1123 | 5577 if (!(inhibit_flags & INHIBIT_WARNING_ISSUE) |
2532 | 5578 && !warning_will_be_discarded (current_warning_level ())) |
428 | 5579 { |
1333 | 5580 struct gcpro gcpro1; |
5581 Lisp_Object lstream = Qnil; | |
5582 int speccount = specpdl_depth (); | |
5583 | |
853 | 5584 /* We're no longer protected against errors or quit here, so at |
5585 least let's temporarily inhibit quit. We definitely do not | |
5586 want to inhibit quit during the calling of the function | |
5587 itself!!!!!!!!!!! */ | |
5588 | |
5589 specbind (Qinhibit_quit, Qt); | |
5590 | |
5591 GCPRO1 (lstream); | |
5592 lstream = make_resizing_buffer_output_stream (); | |
5593 Fbacktrace (lstream, Qt); | |
5594 Lstream_flush (XLSTREAM (lstream)); | |
2532 | 5595 backtrace = resizing_buffer_to_lisp_string (XLSTREAM (lstream)); |
853 | 5596 Lstream_delete (XLSTREAM (lstream)); |
5597 UNGCPRO; | |
5598 | |
5599 unbind_to (speccount); | |
428 | 5600 } |
853 | 5601 else |
2532 | 5602 backtrace = Qnil; |
5603 | |
5604 return backtrace; | |
5605 } | |
5606 | |
5607 static DECLARE_DOESNT_RETURN_TYPE | |
5608 (Lisp_Object, flagged_a_squirmer (Lisp_Object, Lisp_Object, Lisp_Object)); | |
5609 | |
5610 static DOESNT_RETURN_TYPE (Lisp_Object) | |
5611 flagged_a_squirmer (Lisp_Object error_conditions, Lisp_Object data, | |
5612 Lisp_Object opaque) | |
5613 { | |
5614 struct call_trapping_problems *p = | |
5615 (struct call_trapping_problems *) get_opaque_ptr (opaque); | |
5616 | |
5617 if (!EQ (error_conditions, Qquit)) | |
5618 p->backtrace = maybe_get_trapping_problems_backtrace (); | |
5619 else | |
853 | 5620 p->backtrace = Qnil; |
5621 p->error_conditions = error_conditions; | |
5622 p->data = data; | |
5623 | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
5624 throw_or_bomb_out (p->catchtag, Qnil, 0, Qnil, Qnil); |
2268 | 5625 RETURN_NOT_REACHED (Qnil); |
853 | 5626 } |
5627 | |
5628 static Lisp_Object | |
5629 call_trapping_problems_2 (Lisp_Object opaque) | |
5630 { | |
5631 struct call_trapping_problems *p = | |
5632 (struct call_trapping_problems *) get_opaque_ptr (opaque); | |
5633 | |
5634 return (p->fun) (p->arg); | |
428 | 5635 } |
5636 | |
5637 static Lisp_Object | |
853 | 5638 call_trapping_problems_1 (Lisp_Object opaque) |
5639 { | |
5640 return call_with_condition_handler (flagged_a_squirmer, opaque, | |
5641 call_trapping_problems_2, opaque); | |
5642 } | |
5643 | |
1333 | 5644 static void |
5645 issue_call_trapping_problems_warning (Lisp_Object warning_class, | |
5646 const CIbyte *warning_string, | |
5647 struct call_trapping_problems_result *p) | |
5648 { | |
5649 if (!warning_will_be_discarded (current_warning_level ())) | |
5650 { | |
5651 int depth = specpdl_depth (); | |
5652 | |
5653 /* We're no longer protected against errors or quit here, so at | |
5654 least let's temporarily inhibit quit. */ | |
5655 specbind (Qinhibit_quit, Qt); | |
5656 | |
5657 if (p->caught_throw) | |
5658 { | |
5659 Lisp_Object errstr = | |
5660 emacs_sprintf_string_lisp | |
2532 | 5661 ("%s: Attempt to throw outside of function:" |
5662 "To catch `%s' with value `%s'\n\nBacktrace follows:\n\n%s", | |
2725 | 5663 Qnil, 4, |
1333 | 5664 build_msg_string (warning_string ? warning_string : "error"), |
2532 | 5665 p->thrown_tag, p->thrown_value, p->backtrace); |
1333 | 5666 warn_when_safe_lispobj (Qerror, current_warning_level (), errstr); |
5667 } | |
2421 | 5668 else if (p->caught_error && !EQ (p->error_conditions, Qquit)) |
1333 | 5669 { |
5670 Lisp_Object errstr; | |
5671 /* #### This should call | |
5672 (with-output-to-string (display-error (cons error_conditions | |
5673 data)) | |
5674 but that stuff is all in Lisp currently. */ | |
5675 errstr = | |
5676 emacs_sprintf_string_lisp | |
5677 ("%s: (%s %s)\n\nBacktrace follows:\n\n%s", | |
5678 Qnil, 4, | |
5679 build_msg_string (warning_string ? warning_string : "error"), | |
5680 p->error_conditions, p->data, p->backtrace); | |
5681 | |
5682 warn_when_safe_lispobj (warning_class, current_warning_level (), | |
5683 errstr); | |
5684 } | |
5685 | |
5686 unbind_to (depth); | |
5687 } | |
5688 } | |
5689 | |
1318 | 5690 /* Turn on the trapping flags in FLAGS -- see call_trapping_problems(). |
5691 This cannot handle INTERNAL_INHIBIT_THROWS() or INTERNAL_INHIBIT_ERRORS | |
5692 (because they ultimately boil down to a setjmp()!) -- you must directly | |
5693 use call_trapping_problems() for that. Turn the flags off with | |
5694 unbind_to(). Returns the "canonicalized" flags (particularly in the | |
5695 case of INHIBIT_ANY_CHANGE_AFFECTING_REDISPLAY, which is shorthand for | |
5696 various other flags). */ | |
5697 | |
5698 int | |
5699 set_trapping_problems_flags (int flags) | |
5700 { | |
5701 int new_inhibit_flags; | |
5702 | |
5703 if (flags & INHIBIT_ANY_CHANGE_AFFECTING_REDISPLAY) | |
5704 flags |= INHIBIT_EXISTING_PERMANENT_DISPLAY_OBJECT_DELETION | |
5705 | INHIBIT_EXISTING_BUFFER_TEXT_MODIFICATION | |
5706 | INHIBIT_ENTERING_DEBUGGER | |
5707 | INHIBIT_WARNING_ISSUE | |
5708 | INHIBIT_GC; | |
5709 | |
5710 new_inhibit_flags = inhibit_flags | flags; | |
5711 if (new_inhibit_flags != inhibit_flags) | |
5712 internal_bind_int (&inhibit_flags, new_inhibit_flags); | |
5713 | |
5714 if (flags & INHIBIT_QUIT) | |
5715 specbind (Qinhibit_quit, Qt); | |
5716 | |
5717 if (flags & UNINHIBIT_QUIT) | |
5718 begin_do_check_for_quit (); | |
5719 | |
5720 if (flags & INHIBIT_GC) | |
5721 begin_gc_forbidden (); | |
5722 | |
5723 /* #### If we have nested calls to call_trapping_problems(), and the | |
5724 inner one creates some buffers/etc., should the outer one be able | |
5725 to delete them? I think so, but it means we need to combine rather | |
5726 than just reset the value. */ | |
5727 if (flags & INHIBIT_EXISTING_PERMANENT_DISPLAY_OBJECT_DELETION) | |
5728 internal_bind_lisp_object (&Vdeletable_permanent_display_objects, Qnil); | |
5729 | |
5730 if (flags & INHIBIT_EXISTING_BUFFER_TEXT_MODIFICATION) | |
5731 internal_bind_lisp_object (&Vmodifiable_buffers, Qnil); | |
5732 | |
5733 return flags; | |
5734 } | |
5735 | |
853 | 5736 /* This is equivalent to (*fun) (arg), except that various conditions |
5737 can be trapped or inhibited, according to FLAGS. | |
5738 | |
5739 If FLAGS does not contain NO_INHIBIT_ERRORS, when an error occurs, | |
5740 the error is caught and a warning is issued, specifying the | |
5741 specific error that occurred and a backtrace. In that case, | |
5742 WARNING_STRING should be given, and will be printed at the | |
5743 beginning of the error to indicate where the error occurred. | |
5744 | |
5745 If FLAGS does not contain NO_INHIBIT_THROWS, all attempts to | |
5746 `throw' out of the function being called are trapped, and a warning | |
5747 issued. (Again, WARNING_STRING should be given.) | |
5748 | |
2367 | 5749 If FLAGS contains INHIBIT_WARNING_ISSUE, no warnings are issued; |
853 | 5750 this applies to recursive invocations of call_trapping_problems, too. |
5751 | |
1333 | 5752 If FLAGS contains POSTPONE_WARNING_ISSUE, no warnings are issued; |
5753 but values useful for generating a warning are still computed (in | |
5754 particular, the backtrace), so that the calling function can issue | |
5755 a warning. | |
5756 | |
853 | 5757 If FLAGS contains ISSUE_WARNINGS_AT_DEBUG_LEVEL, warnings will be |
5758 issued, but at level `debug', which normally is below the minimum | |
5759 specified by `log-warning-minimum-level', meaning such warnings will | |
5760 be ignored entirely. The user can change this variable, however, | |
5761 to see the warnings.) | |
5762 | |
5763 Note: If neither of NO_INHIBIT_THROWS or NO_INHIBIT_ERRORS is | |
5764 given, you are *guaranteed* that there will be no non-local exits | |
5765 out of this function. | |
5766 | |
5767 If FLAGS contains INHIBIT_QUIT, QUIT using C-g is inhibited. (This | |
5768 is *rarely* a good idea. Unless you use NO_INHIBIT_ERRORS, QUIT is | |
5769 automatically caught as well, and treated as an error; you can | |
5770 check for this using EQ (problems->error_conditions, Qquit). | |
5771 | |
5772 If FLAGS contains UNINHIBIT_QUIT, QUIT checking will be explicitly | |
5773 turned on. (It will abort the code being called, but will still be | |
5774 trapped and reported as an error, unless NO_INHIBIT_ERRORS is | |
5775 given.) This is useful when QUIT checking has been turned off by a | |
5776 higher-level caller. | |
5777 | |
5778 If FLAGS contains INHIBIT_GC, garbage collection is inhibited. | |
1123 | 5779 This is useful for Lisp called within redisplay, for example. |
853 | 5780 |
5781 If FLAGS contains INHIBIT_EXISTING_PERMANENT_DISPLAY_OBJECT_DELETION, | |
5782 Lisp code is not allowed to delete any window, buffers, frames, devices, | |
5783 or consoles that were already in existence at the time this function | |
5784 was called. (However, it's perfectly legal for code to create a new | |
5785 buffer and then delete it.) | |
5786 | |
5787 #### It might be useful to have a flag that inhibits deletion of a | |
5788 specific permanent display object and everything it's attached to | |
5789 (e.g. a window, and the buffer, frame, device, and console it's | |
5790 attached to. | |
5791 | |
5792 If FLAGS contains INHIBIT_EXISTING_BUFFER_TEXT_MODIFICATION, Lisp | |
5793 code is not allowed to modify the text of any buffers that were | |
5794 already in existence at the time this function was called. | |
5795 (However, it's perfectly legal for code to create a new buffer and | |
5796 then modify its text.) | |
5797 | |
5798 [These last two flags are implemented using global variables | |
5799 Vdeletable_permanent_display_objects and Vmodifiable_buffers, | |
5800 which keep track of a list of all buffers or permanent display | |
5801 objects created since the last time one of these flags was set. | |
5802 The code that deletes buffers, etc. and modifies buffers checks | |
5803 | |
5804 (1) if the corresponding flag is set (through the global variable | |
5805 inhibit_flags or its accessor function get_inhibit_flags()), and | |
5806 | |
5807 (2) if the object to be modified or deleted is not in the | |
5808 appropriate list. | |
5809 | |
5810 If so, it signals an error. | |
5811 | |
5812 Recursive calls to call_trapping_problems() are allowed. In | |
5813 the case of the two flags mentioned above, the current values | |
5814 of the global variables are stored in an unwind-protect, and | |
5815 they're reset to nil.] | |
5816 | |
5817 If FLAGS contains INHIBIT_ENTERING_DEBUGGER, the debugger will not | |
5818 be entered if an error occurs inside the Lisp code being called, | |
5819 even when the user has requested an error. In such case, a warning | |
5820 is issued stating that access to the debugger is denied, unless | |
5821 INHIBIT_WARNING_ISSUE has also been supplied. This is useful when | |
5822 calling Lisp code inside redisplay, in menu callbacks, etc. because | |
5823 in such cases either the display is in an inconsistent state or | |
5824 doing window operations is explicitly forbidden by the OS, and the | |
5825 debugger would causes visual changes on the screen and might create | |
5826 another frame. | |
5827 | |
5828 If FLAGS contains INHIBIT_ANY_CHANGE_AFFECTING_REDISPLAY, no | |
5829 changes of any sort to extents, faces, glyphs, buffer text, | |
5830 specifiers relating to display, other variables relating to | |
5831 display, splitting, deleting, or resizing windows or frames, | |
5832 deleting buffers, windows, frames, devices, or consoles, etc. is | |
5833 allowed. This is for things called absolutely in the middle of | |
5834 redisplay, which expects things to be *exactly* the same after the | |
5835 call as before. This isn't completely implemented and needs to be | |
5836 thought out some more to determine exactly what its semantics are. | |
5837 For the moment, turning on this flag also turns on | |
5838 | |
5839 INHIBIT_EXISTING_PERMANENT_DISPLAY_OBJECT_DELETION | |
5840 INHIBIT_EXISTING_BUFFER_TEXT_MODIFICATION | |
5841 INHIBIT_ENTERING_DEBUGGER | |
5842 INHIBIT_WARNING_ISSUE | |
5843 INHIBIT_GC | |
5844 | |
5845 #### The following five flags are defined, but unimplemented: | |
5846 | |
5847 #define INHIBIT_EXISTING_CODING_SYSTEM_DELETION (1<<6) | |
5848 #define INHIBIT_EXISTING_CHARSET_DELETION (1<<7) | |
5849 #define INHIBIT_PERMANENT_DISPLAY_OBJECT_CREATION (1<<8) | |
5850 #define INHIBIT_CODING_SYSTEM_CREATION (1<<9) | |
5851 #define INHIBIT_CHARSET_CREATION (1<<10) | |
5852 | |
5853 FLAGS containing CALL_WITH_SUSPENDED_ERRORS is a sign that | |
5854 call_with_suspended_errors() was invoked. This exists only for | |
5855 debugging purposes -- often we want to break when a signal happens, | |
5856 but ignore signals from call_with_suspended_errors(), because they | |
5857 occur often and for legitimate reasons. | |
5858 | |
5859 If PROBLEM is non-zero, it should be a pointer to a structure into | |
5860 which exact information about any occurring problems (either an | |
5861 error or an attempted throw past this boundary). | |
5862 | |
5863 If a problem occurred and aborted operation (error, quit, or | |
5864 invalid throw), Qunbound is returned. Otherwise the return value | |
5865 from the call to (*fun) (arg) is returned. */ | |
5866 | |
5867 Lisp_Object | |
5868 call_trapping_problems (Lisp_Object warning_class, | |
867 | 5869 const CIbyte *warning_string, |
853 | 5870 int flags, |
5871 struct call_trapping_problems_result *problem, | |
5872 Lisp_Object (*fun) (void *), | |
5873 void *arg) | |
5874 { | |
1318 | 5875 int speccount = specpdl_depth (); |
853 | 5876 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; |
5877 struct call_trapping_problems package; | |
1333 | 5878 struct call_trapping_problems_result real_problem; |
2532 | 5879 Lisp_Object opaque, thrown_tag, tem, thrown_backtrace; |
853 | 5880 int thrown = 0; |
5881 | |
5882 assert (SYMBOLP (warning_class)); /* sanity-check */ | |
5883 assert (!NILP (warning_class)); | |
5884 | |
5885 flags ^= INTERNAL_INHIBIT_ERRORS | INTERNAL_INHIBIT_THROWS; | |
5886 | |
5887 package.warning_class = warning_class; | |
5888 package.warning_string = warning_string; | |
5889 package.fun = fun; | |
5890 package.arg = arg; | |
5891 package.catchtag = | |
5892 flags & INTERNAL_INHIBIT_THROWS ? Vcatch_everything_tag : | |
5893 flags & INTERNAL_INHIBIT_ERRORS ? make_opaque_ptr (0) : | |
5894 Qnil; | |
5895 package.error_conditions = Qnil; | |
5896 package.data = Qnil; | |
5897 package.backtrace = Qnil; | |
5898 | |
1318 | 5899 flags = set_trapping_problems_flags (flags); |
853 | 5900 |
5901 if (flags & (INTERNAL_INHIBIT_THROWS | INTERNAL_INHIBIT_ERRORS)) | |
5902 opaque = make_opaque_ptr (&package); | |
5903 else | |
5904 opaque = Qnil; | |
5905 | |
5906 GCPRO5 (package.catchtag, package.error_conditions, package.data, | |
5907 package.backtrace, opaque); | |
5908 | |
5909 if (flags & INTERNAL_INHIBIT_ERRORS) | |
5910 /* We need a catch so that our condition-handler can throw back here | |
5911 after printing the warning. (We print the warning in the stack | |
5912 context of the error, so we can get a backtrace.) */ | |
5913 tem = internal_catch (package.catchtag, call_trapping_problems_1, opaque, | |
2532 | 5914 &thrown, &thrown_tag, &thrown_backtrace); |
853 | 5915 else if (flags & INTERNAL_INHIBIT_THROWS) |
5916 /* We skip over the first wrapper, which traps errors. */ | |
5917 tem = internal_catch (package.catchtag, call_trapping_problems_2, opaque, | |
2532 | 5918 &thrown, &thrown_tag, &thrown_backtrace); |
853 | 5919 else |
5920 /* Nothing special. */ | |
5921 tem = (fun) (arg); | |
5922 | |
1333 | 5923 if (!problem) |
5924 problem = &real_problem; | |
5925 | |
5926 if (!thrown) | |
853 | 5927 { |
1333 | 5928 problem->caught_error = 0; |
5929 problem->caught_throw = 0; | |
5930 problem->error_conditions = Qnil; | |
5931 problem->data = Qnil; | |
5932 problem->backtrace = Qnil; | |
5933 problem->thrown_tag = Qnil; | |
5934 problem->thrown_value = Qnil; | |
853 | 5935 } |
1333 | 5936 else if (EQ (thrown_tag, package.catchtag)) |
853 | 5937 { |
1333 | 5938 problem->caught_error = 1; |
5939 problem->caught_throw = 0; | |
5940 problem->error_conditions = package.error_conditions; | |
5941 problem->data = package.data; | |
5942 problem->backtrace = package.backtrace; | |
5943 problem->thrown_tag = Qnil; | |
5944 problem->thrown_value = Qnil; | |
853 | 5945 } |
1333 | 5946 else |
5947 { | |
5948 problem->caught_error = 0; | |
5949 problem->caught_throw = 1; | |
5950 problem->error_conditions = Qnil; | |
5951 problem->data = Qnil; | |
2532 | 5952 problem->backtrace = thrown_backtrace; |
1333 | 5953 problem->thrown_tag = thrown_tag; |
5954 problem->thrown_value = tem; | |
5955 } | |
5956 | |
5957 if (!(flags & INHIBIT_WARNING_ISSUE) && !(flags & POSTPONE_WARNING_ISSUE)) | |
5958 issue_call_trapping_problems_warning (warning_class, warning_string, | |
5959 problem); | |
853 | 5960 |
5961 if (!NILP (package.catchtag) && | |
5962 !EQ (package.catchtag, Vcatch_everything_tag)) | |
5963 free_opaque_ptr (package.catchtag); | |
5964 | |
5965 if (!NILP (opaque)) | |
5966 free_opaque_ptr (opaque); | |
5967 | |
5968 unbind_to (speccount); | |
5969 RETURN_UNGCPRO (thrown ? Qunbound : tem); | |
5970 } | |
5971 | |
5972 struct va_call_trapping_problems | |
5973 { | |
5974 lisp_fn_t fun; | |
5975 int nargs; | |
5976 Lisp_Object *args; | |
5977 }; | |
5978 | |
5979 static Lisp_Object | |
5980 va_call_trapping_problems_1 (void *ai_mi_madre) | |
5981 { | |
5982 struct va_call_trapping_problems *ai_no_corrida = | |
5983 (struct va_call_trapping_problems *) ai_mi_madre; | |
5984 Lisp_Object pegar_no_bumbum; | |
5985 | |
5986 PRIMITIVE_FUNCALL (pegar_no_bumbum, ai_no_corrida->fun, | |
5987 ai_no_corrida->args, ai_no_corrida->nargs); | |
5988 return pegar_no_bumbum; | |
5989 } | |
5990 | |
5991 /* #### document me. */ | |
5992 | |
5993 Lisp_Object | |
5994 va_call_trapping_problems (Lisp_Object warning_class, | |
867 | 5995 const CIbyte *warning_string, |
853 | 5996 int flags, |
5997 struct call_trapping_problems_result *problem, | |
5998 lisp_fn_t fun, int nargs, ...) | |
5999 { | |
6000 va_list vargs; | |
6001 Lisp_Object args[20]; | |
6002 int i; | |
6003 struct va_call_trapping_problems fazer_invocacao_atrapalhando_problemas; | |
6004 struct gcpro gcpro1; | |
6005 | |
6006 assert (nargs >= 0 && nargs < 20); | |
6007 | |
6008 va_start (vargs, nargs); | |
6009 for (i = 0; i < nargs; i++) | |
6010 args[i] = va_arg (vargs, Lisp_Object); | |
6011 va_end (vargs); | |
6012 | |
6013 fazer_invocacao_atrapalhando_problemas.fun = fun; | |
6014 fazer_invocacao_atrapalhando_problemas.nargs = nargs; | |
6015 fazer_invocacao_atrapalhando_problemas.args = args; | |
6016 | |
6017 GCPRO1_ARRAY (args, nargs); | |
6018 RETURN_UNGCPRO | |
6019 (call_trapping_problems | |
6020 (warning_class, warning_string, flags, problem, | |
6021 va_call_trapping_problems_1, &fazer_invocacao_atrapalhando_problemas)); | |
6022 } | |
6023 | |
6024 /* this is an older interface, barely different from | |
6025 va_call_trapping_problems. | |
6026 | |
6027 #### eliminate this or at least merge the ERROR_BEHAVIOR stuff into | |
6028 va_call_trapping_problems(). */ | |
6029 | |
6030 Lisp_Object | |
6031 call_with_suspended_errors (lisp_fn_t fun, Lisp_Object retval, | |
1204 | 6032 Lisp_Object class_, Error_Behavior errb, |
853 | 6033 int nargs, ...) |
6034 { | |
6035 va_list vargs; | |
6036 Lisp_Object args[20]; | |
6037 int i; | |
6038 struct va_call_trapping_problems fazer_invocacao_atrapalhando_problemas; | |
6039 int flags; | |
6040 struct gcpro gcpro1; | |
6041 | |
1204 | 6042 assert (SYMBOLP (class_)); /* sanity-check */ |
6043 assert (!NILP (class_)); | |
853 | 6044 assert (nargs >= 0 && nargs < 20); |
6045 | |
6046 va_start (vargs, nargs); | |
6047 for (i = 0; i < nargs; i++) | |
6048 args[i] = va_arg (vargs, Lisp_Object); | |
6049 va_end (vargs); | |
6050 | |
6051 /* If error-checking is not disabled, just call the function. */ | |
6052 | |
6053 if (ERRB_EQ (errb, ERROR_ME)) | |
6054 { | |
6055 Lisp_Object val; | |
6056 PRIMITIVE_FUNCALL (val, fun, args, nargs); | |
6057 return val; | |
6058 } | |
6059 | |
6060 if (ERRB_EQ (errb, ERROR_ME_NOT)) /* person wants no warnings */ | |
6061 flags = INHIBIT_WARNING_ISSUE | INHIBIT_ENTERING_DEBUGGER; | |
6062 else if (ERRB_EQ (errb, ERROR_ME_DEBUG_WARN)) | |
6063 flags = ISSUE_WARNINGS_AT_DEBUG_LEVEL | INHIBIT_ENTERING_DEBUGGER; | |
6064 else | |
6065 { | |
6066 assert (ERRB_EQ (errb, ERROR_ME_WARN)); | |
6067 flags = INHIBIT_ENTERING_DEBUGGER; | |
6068 } | |
6069 | |
6070 flags |= CALL_WITH_SUSPENDED_ERRORS; | |
6071 | |
6072 fazer_invocacao_atrapalhando_problemas.fun = fun; | |
6073 fazer_invocacao_atrapalhando_problemas.nargs = nargs; | |
6074 fazer_invocacao_atrapalhando_problemas.args = args; | |
6075 | |
6076 GCPRO1_ARRAY (args, nargs); | |
6077 { | |
6078 Lisp_Object its_way_too_goddamn_late = | |
6079 call_trapping_problems | |
1204 | 6080 (class_, 0, flags, 0, va_call_trapping_problems_1, |
853 | 6081 &fazer_invocacao_atrapalhando_problemas); |
6082 UNGCPRO; | |
6083 if (UNBOUNDP (its_way_too_goddamn_late)) | |
6084 return retval; | |
6085 else | |
6086 return its_way_too_goddamn_late; | |
6087 } | |
6088 } | |
6089 | |
6090 struct calln_trapping_problems | |
6091 { | |
6092 int nargs; | |
6093 Lisp_Object *args; | |
6094 }; | |
6095 | |
6096 static Lisp_Object | |
6097 calln_trapping_problems_1 (void *puta) | |
6098 { | |
6099 struct calln_trapping_problems *p = (struct calln_trapping_problems *) puta; | |
6100 | |
6101 return Ffuncall (p->nargs, p->args); | |
428 | 6102 } |
6103 | |
6104 static Lisp_Object | |
853 | 6105 calln_trapping_problems (Lisp_Object warning_class, |
867 | 6106 const CIbyte *warning_string, int flags, |
853 | 6107 struct call_trapping_problems_result *problem, |
6108 int nargs, Lisp_Object *args) | |
6109 { | |
6110 struct calln_trapping_problems foo; | |
6111 struct gcpro gcpro1; | |
6112 | |
6113 if (SYMBOLP (args[0])) | |
6114 { | |
6115 Lisp_Object tem = XSYMBOL (args[0])->function; | |
6116 if (NILP (tem) || UNBOUNDP (tem)) | |
6117 { | |
6118 if (problem) | |
6119 { | |
6120 problem->caught_error = 0; | |
6121 problem->caught_throw = 0; | |
6122 problem->error_conditions = Qnil; | |
6123 problem->data = Qnil; | |
6124 problem->backtrace = Qnil; | |
6125 problem->thrown_tag = Qnil; | |
6126 problem->thrown_value = Qnil; | |
6127 } | |
6128 return Qnil; | |
6129 } | |
6130 } | |
6131 | |
6132 foo.nargs = nargs; | |
6133 foo.args = args; | |
6134 | |
6135 GCPRO1_ARRAY (args, nargs); | |
6136 RETURN_UNGCPRO (call_trapping_problems (warning_class, warning_string, | |
6137 flags, problem, | |
6138 calln_trapping_problems_1, | |
6139 &foo)); | |
6140 } | |
6141 | |
6142 /* #### fix these functions to follow the calling convention of | |
6143 call_trapping_problems! */ | |
6144 | |
6145 Lisp_Object | |
867 | 6146 call0_trapping_problems (const CIbyte *warning_string, Lisp_Object function, |
853 | 6147 int flags) |
6148 { | |
6149 return calln_trapping_problems (Qerror, warning_string, flags, 0, 1, | |
6150 &function); | |
428 | 6151 } |
6152 | |
6153 Lisp_Object | |
867 | 6154 call1_trapping_problems (const CIbyte *warning_string, Lisp_Object function, |
853 | 6155 Lisp_Object object, int flags) |
6156 { | |
6157 Lisp_Object args[2]; | |
6158 | |
6159 args[0] = function; | |
6160 args[1] = object; | |
6161 | |
6162 return calln_trapping_problems (Qerror, warning_string, flags, 0, 2, | |
6163 args); | |
6164 } | |
6165 | |
6166 Lisp_Object | |
867 | 6167 call2_trapping_problems (const CIbyte *warning_string, Lisp_Object function, |
853 | 6168 Lisp_Object object1, Lisp_Object object2, |
6169 int flags) | |
6170 { | |
6171 Lisp_Object args[3]; | |
6172 | |
6173 args[0] = function; | |
6174 args[1] = object1; | |
6175 args[2] = object2; | |
6176 | |
6177 return calln_trapping_problems (Qerror, warning_string, flags, 0, 3, | |
6178 args); | |
6179 } | |
6180 | |
6181 Lisp_Object | |
867 | 6182 call3_trapping_problems (const CIbyte *warning_string, Lisp_Object function, |
853 | 6183 Lisp_Object object1, Lisp_Object object2, |
6184 Lisp_Object object3, int flags) | |
6185 { | |
6186 Lisp_Object args[4]; | |
6187 | |
6188 args[0] = function; | |
6189 args[1] = object1; | |
6190 args[2] = object2; | |
6191 args[3] = object3; | |
6192 | |
6193 return calln_trapping_problems (Qerror, warning_string, flags, 0, 4, | |
6194 args); | |
6195 } | |
6196 | |
6197 Lisp_Object | |
867 | 6198 call4_trapping_problems (const CIbyte *warning_string, Lisp_Object function, |
853 | 6199 Lisp_Object object1, Lisp_Object object2, |
6200 Lisp_Object object3, Lisp_Object object4, | |
6201 int flags) | |
6202 { | |
6203 Lisp_Object args[5]; | |
6204 | |
6205 args[0] = function; | |
6206 args[1] = object1; | |
6207 args[2] = object2; | |
6208 args[3] = object3; | |
6209 args[4] = object4; | |
6210 | |
6211 return calln_trapping_problems (Qerror, warning_string, flags, 0, 5, | |
6212 args); | |
6213 } | |
6214 | |
6215 Lisp_Object | |
867 | 6216 call5_trapping_problems (const CIbyte *warning_string, Lisp_Object function, |
853 | 6217 Lisp_Object object1, Lisp_Object object2, |
6218 Lisp_Object object3, Lisp_Object object4, | |
6219 Lisp_Object object5, int flags) | |
6220 { | |
6221 Lisp_Object args[6]; | |
6222 | |
6223 args[0] = function; | |
6224 args[1] = object1; | |
6225 args[2] = object2; | |
6226 args[3] = object3; | |
6227 args[4] = object4; | |
6228 args[5] = object5; | |
6229 | |
6230 return calln_trapping_problems (Qerror, warning_string, flags, 0, 6, | |
6231 args); | |
6232 } | |
6233 | |
6234 struct eval_in_buffer_trapping_problems | |
6235 { | |
6236 struct buffer *buf; | |
6237 Lisp_Object form; | |
6238 }; | |
6239 | |
6240 static Lisp_Object | |
6241 eval_in_buffer_trapping_problems_1 (void *arg) | |
6242 { | |
6243 struct eval_in_buffer_trapping_problems *p = | |
6244 (struct eval_in_buffer_trapping_problems *) arg; | |
6245 | |
6246 return eval_in_buffer (p->buf, p->form); | |
6247 } | |
6248 | |
6249 /* #### fix these functions to follow the calling convention of | |
6250 call_trapping_problems! */ | |
6251 | |
6252 Lisp_Object | |
867 | 6253 eval_in_buffer_trapping_problems (const CIbyte *warning_string, |
853 | 6254 struct buffer *buf, Lisp_Object form, |
6255 int flags) | |
6256 { | |
6257 struct eval_in_buffer_trapping_problems p; | |
6258 Lisp_Object buffer = wrap_buffer (buf); | |
428 | 6259 struct gcpro gcpro1, gcpro2; |
6260 | |
853 | 6261 GCPRO2 (buffer, form); |
6262 p.buf = buf; | |
6263 p.form = form; | |
6264 RETURN_UNGCPRO (call_trapping_problems (Qerror, warning_string, flags, 0, | |
6265 eval_in_buffer_trapping_problems_1, | |
6266 &p)); | |
6267 } | |
6268 | |
6269 Lisp_Object | |
1333 | 6270 run_hook_trapping_problems (Lisp_Object warning_class, |
853 | 6271 Lisp_Object hook_symbol, |
6272 int flags) | |
6273 { | |
1333 | 6274 return run_hook_with_args_trapping_problems (warning_class, 1, &hook_symbol, |
853 | 6275 RUN_HOOKS_TO_COMPLETION, |
6276 flags); | |
428 | 6277 } |
6278 | |
6279 static Lisp_Object | |
853 | 6280 safe_run_hook_trapping_problems_1 (void *puta) |
6281 { | |
6282 Lisp_Object hook = VOID_TO_LISP (puta); | |
6283 | |
6284 run_hook (hook); | |
428 | 6285 return Qnil; |
6286 } | |
6287 | |
853 | 6288 /* Same as run_hook_trapping_problems() but also set the hook to nil |
6289 if an error occurs (but not a quit). */ | |
6290 | |
428 | 6291 Lisp_Object |
1333 | 6292 safe_run_hook_trapping_problems (Lisp_Object warning_class, |
6293 Lisp_Object hook_symbol, int flags) | |
853 | 6294 { |
428 | 6295 Lisp_Object tem; |
853 | 6296 struct gcpro gcpro1, gcpro2; |
6297 struct call_trapping_problems_result prob; | |
428 | 6298 |
6299 if (!initialized || preparing_for_armageddon) | |
6300 return Qnil; | |
6301 tem = find_symbol_value (hook_symbol); | |
6302 if (NILP (tem) || UNBOUNDP (tem)) | |
6303 return Qnil; | |
6304 | |
853 | 6305 GCPRO2 (hook_symbol, tem); |
1333 | 6306 tem = call_trapping_problems (Qerror, NULL, |
6307 flags | POSTPONE_WARNING_ISSUE, | |
853 | 6308 &prob, |
6309 safe_run_hook_trapping_problems_1, | |
6310 LISP_TO_VOID (hook_symbol)); | |
1333 | 6311 { |
6312 Lisp_Object hook_name = XSYMBOL_NAME (hook_symbol); | |
6313 Ibyte *hook_str = XSTRING_DATA (hook_name); | |
6314 Ibyte *err = alloca_ibytes (XSTRING_LENGTH (hook_name) + 100); | |
6315 | |
6316 if (prob.caught_throw || (prob.caught_error && !EQ (prob.error_conditions, | |
6317 Qquit))) | |
6318 { | |
6319 Fset (hook_symbol, Qnil); | |
6320 qxesprintf (err, "Error in `%s' (resetting to nil)", hook_str); | |
6321 } | |
6322 else | |
6323 qxesprintf (err, "Quit in `%s'", hook_str); | |
6324 | |
6325 | |
6326 issue_call_trapping_problems_warning (warning_class, (CIbyte *) err, | |
6327 &prob); | |
6328 } | |
6329 | |
6330 UNGCPRO; | |
6331 return tem; | |
853 | 6332 } |
6333 | |
6334 struct run_hook_with_args_in_buffer_trapping_problems | |
6335 { | |
6336 struct buffer *buf; | |
6337 int nargs; | |
6338 Lisp_Object *args; | |
6339 enum run_hooks_condition cond; | |
6340 }; | |
6341 | |
6342 static Lisp_Object | |
6343 run_hook_with_args_in_buffer_trapping_problems_1 (void *puta) | |
6344 { | |
6345 struct run_hook_with_args_in_buffer_trapping_problems *porra = | |
6346 (struct run_hook_with_args_in_buffer_trapping_problems *) puta; | |
6347 | |
6348 return run_hook_with_args_in_buffer (porra->buf, porra->nargs, porra->args, | |
6349 porra->cond); | |
6350 } | |
6351 | |
6352 /* #### fix these functions to follow the calling convention of | |
6353 call_trapping_problems! */ | |
428 | 6354 |
6355 Lisp_Object | |
1333 | 6356 run_hook_with_args_in_buffer_trapping_problems (Lisp_Object warning_class, |
853 | 6357 struct buffer *buf, int nargs, |
6358 Lisp_Object *args, | |
6359 enum run_hooks_condition cond, | |
6360 int flags) | |
6361 { | |
6362 Lisp_Object sym, val, ret; | |
6363 struct run_hook_with_args_in_buffer_trapping_problems diversity_and_distrust; | |
428 | 6364 struct gcpro gcpro1; |
1333 | 6365 Lisp_Object hook_name; |
6366 Ibyte *hook_str; | |
6367 Ibyte *err; | |
428 | 6368 |
6369 if (!initialized || preparing_for_armageddon) | |
853 | 6370 /* We need to bail out of here pronto. */ |
428 | 6371 return Qnil; |
6372 | |
853 | 6373 GCPRO1_ARRAY (args, nargs); |
6374 | |
6375 sym = args[0]; | |
6376 val = symbol_value_in_buffer (sym, wrap_buffer (buf)); | |
6377 ret = (cond == RUN_HOOKS_UNTIL_FAILURE ? Qt : Qnil); | |
6378 | |
6379 if (UNBOUNDP (val) || NILP (val)) | |
6380 RETURN_UNGCPRO (ret); | |
6381 | |
6382 diversity_and_distrust.buf = buf; | |
6383 diversity_and_distrust.nargs = nargs; | |
6384 diversity_and_distrust.args = args; | |
6385 diversity_and_distrust.cond = cond; | |
6386 | |
1333 | 6387 hook_name = XSYMBOL_NAME (args[0]); |
6388 hook_str = XSTRING_DATA (hook_name); | |
6389 err = alloca_ibytes (XSTRING_LENGTH (hook_name) + 100); | |
6390 qxesprintf (err, "Error in `%s'", hook_str); | |
853 | 6391 RETURN_UNGCPRO |
6392 (call_trapping_problems | |
1333 | 6393 (warning_class, (CIbyte *) err, flags, 0, |
853 | 6394 run_hook_with_args_in_buffer_trapping_problems_1, |
6395 &diversity_and_distrust)); | |
428 | 6396 } |
6397 | |
6398 Lisp_Object | |
1333 | 6399 run_hook_with_args_trapping_problems (Lisp_Object warning_class, |
853 | 6400 int nargs, |
6401 Lisp_Object *args, | |
6402 enum run_hooks_condition cond, | |
6403 int flags) | |
6404 { | |
6405 return run_hook_with_args_in_buffer_trapping_problems | |
1333 | 6406 (warning_class, current_buffer, nargs, args, cond, flags); |
428 | 6407 } |
6408 | |
6409 Lisp_Object | |
1333 | 6410 va_run_hook_with_args_trapping_problems (Lisp_Object warning_class, |
853 | 6411 Lisp_Object hook_var, |
6412 int nargs, ...) | |
6413 { | |
6414 /* This function can GC */ | |
6415 struct gcpro gcpro1; | |
6416 int i; | |
6417 va_list vargs; | |
6418 Lisp_Object *funcall_args = alloca_array (Lisp_Object, 1 + nargs); | |
6419 int flags; | |
6420 | |
6421 va_start (vargs, nargs); | |
6422 funcall_args[0] = hook_var; | |
6423 for (i = 0; i < nargs; i++) | |
6424 funcall_args[i + 1] = va_arg (vargs, Lisp_Object); | |
6425 flags = va_arg (vargs, int); | |
6426 va_end (vargs); | |
6427 | |
6428 GCPRO1_ARRAY (funcall_args, nargs + 1); | |
6429 RETURN_UNGCPRO (run_hook_with_args_in_buffer_trapping_problems | |
1333 | 6430 (warning_class, current_buffer, nargs + 1, funcall_args, |
853 | 6431 RUN_HOOKS_TO_COMPLETION, flags)); |
428 | 6432 } |
6433 | |
6434 Lisp_Object | |
1333 | 6435 va_run_hook_with_args_in_buffer_trapping_problems (Lisp_Object warning_class, |
853 | 6436 struct buffer *buf, |
6437 Lisp_Object hook_var, | |
6438 int nargs, ...) | |
6439 { | |
6440 /* This function can GC */ | |
6441 struct gcpro gcpro1; | |
6442 int i; | |
6443 va_list vargs; | |
6444 Lisp_Object *funcall_args = alloca_array (Lisp_Object, 1 + nargs); | |
6445 int flags; | |
6446 | |
6447 va_start (vargs, nargs); | |
6448 funcall_args[0] = hook_var; | |
6449 for (i = 0; i < nargs; i++) | |
6450 funcall_args[i + 1] = va_arg (vargs, Lisp_Object); | |
6451 flags = va_arg (vargs, int); | |
6452 va_end (vargs); | |
6453 | |
6454 GCPRO1_ARRAY (funcall_args, nargs + 1); | |
6455 RETURN_UNGCPRO (run_hook_with_args_in_buffer_trapping_problems | |
1333 | 6456 (warning_class, buf, nargs + 1, funcall_args, |
853 | 6457 RUN_HOOKS_TO_COMPLETION, flags)); |
428 | 6458 } |
6459 | |
6460 | |
6461 /************************************************************************/ | |
6462 /* The special binding stack */ | |
771 | 6463 /* Most C code should simply use specbind() and unbind_to_1(). */ |
428 | 6464 /* When performance is critical, use the macros in backtrace.h. */ |
6465 /************************************************************************/ | |
6466 | |
6467 #define min_max_specpdl_size 400 | |
6468 | |
6469 void | |
647 | 6470 grow_specpdl (EMACS_INT reserved) |
6471 { | |
6472 EMACS_INT size_needed = specpdl_depth() + reserved; | |
428 | 6473 if (size_needed >= max_specpdl_size) |
6474 { | |
6475 if (max_specpdl_size < min_max_specpdl_size) | |
6476 max_specpdl_size = min_max_specpdl_size; | |
6477 if (size_needed >= max_specpdl_size) | |
6478 { | |
1951 | 6479 /* Leave room for some specpdl in the debugger. */ |
6480 max_specpdl_size = size_needed + 100; | |
6481 if (max_specpdl_size > specpdl_size) | |
6482 { | |
6483 specpdl_size = max_specpdl_size; | |
6484 XREALLOC_ARRAY (specpdl, struct specbinding, specpdl_size); | |
6485 specpdl_ptr = specpdl + specpdl_depth(); | |
6486 } | |
563 | 6487 signal_continuable_error |
6488 (Qstack_overflow, | |
6489 "Variable binding depth exceeds max-specpdl-size", Qunbound); | |
428 | 6490 } |
6491 } | |
6492 while (specpdl_size < size_needed) | |
6493 { | |
6494 specpdl_size *= 2; | |
6495 if (specpdl_size > max_specpdl_size) | |
6496 specpdl_size = max_specpdl_size; | |
6497 } | |
6498 XREALLOC_ARRAY (specpdl, struct specbinding, specpdl_size); | |
6499 specpdl_ptr = specpdl + specpdl_depth(); | |
853 | 6500 check_specbind_stack_sanity (); |
428 | 6501 } |
6502 | |
6503 | |
6504 /* Handle unbinding buffer-local variables */ | |
6505 static Lisp_Object | |
6506 specbind_unwind_local (Lisp_Object ovalue) | |
6507 { | |
6508 Lisp_Object current = Fcurrent_buffer (); | |
6509 Lisp_Object symbol = specpdl_ptr->symbol; | |
853 | 6510 Lisp_Object victim = ovalue; |
6511 Lisp_Object buf = get_buffer (XCAR (victim), 0); | |
6512 ovalue = XCDR (victim); | |
428 | 6513 |
6514 free_cons (victim); | |
6515 | |
6516 if (NILP (buf)) | |
6517 { | |
6518 /* Deleted buffer -- do nothing */ | |
6519 } | |
6520 else if (symbol_value_buffer_local_info (symbol, XBUFFER (buf)) == 0) | |
6521 { | |
6522 /* Was buffer-local when binding was made, now no longer is. | |
6523 * (kill-local-variable can do this.) | |
6524 * Do nothing in this case. | |
6525 */ | |
6526 } | |
6527 else if (EQ (buf, current)) | |
6528 Fset (symbol, ovalue); | |
6529 else | |
6530 { | |
6531 /* Urk! Somebody switched buffers */ | |
6532 struct gcpro gcpro1; | |
6533 GCPRO1 (current); | |
6534 Fset_buffer (buf); | |
6535 Fset (symbol, ovalue); | |
6536 Fset_buffer (current); | |
6537 UNGCPRO; | |
6538 } | |
6539 return symbol; | |
6540 } | |
6541 | |
6542 static Lisp_Object | |
6543 specbind_unwind_wasnt_local (Lisp_Object buffer) | |
6544 { | |
6545 Lisp_Object current = Fcurrent_buffer (); | |
6546 Lisp_Object symbol = specpdl_ptr->symbol; | |
6547 | |
6548 buffer = get_buffer (buffer, 0); | |
6549 if (NILP (buffer)) | |
6550 { | |
6551 /* Deleted buffer -- do nothing */ | |
6552 } | |
6553 else if (symbol_value_buffer_local_info (symbol, XBUFFER (buffer)) == 0) | |
6554 { | |
6555 /* Was buffer-local when binding was made, now no longer is. | |
6556 * (kill-local-variable can do this.) | |
6557 * Do nothing in this case. | |
6558 */ | |
6559 } | |
6560 else if (EQ (buffer, current)) | |
6561 Fkill_local_variable (symbol); | |
6562 else | |
6563 { | |
6564 /* Urk! Somebody switched buffers */ | |
6565 struct gcpro gcpro1; | |
6566 GCPRO1 (current); | |
6567 Fset_buffer (buffer); | |
6568 Fkill_local_variable (symbol); | |
6569 Fset_buffer (current); | |
6570 UNGCPRO; | |
6571 } | |
6572 return symbol; | |
6573 } | |
6574 | |
6575 | |
6576 void | |
6577 specbind (Lisp_Object symbol, Lisp_Object value) | |
6578 { | |
6579 SPECBIND (symbol, value); | |
853 | 6580 |
6581 check_specbind_stack_sanity (); | |
428 | 6582 } |
6583 | |
6584 void | |
6585 specbind_magic (Lisp_Object symbol, Lisp_Object value) | |
6586 { | |
6587 int buffer_local = | |
6588 symbol_value_buffer_local_info (symbol, current_buffer); | |
6589 | |
6590 if (buffer_local == 0) | |
6591 { | |
6592 specpdl_ptr->old_value = find_symbol_value (symbol); | |
771 | 6593 specpdl_ptr->func = 0; /* Handled specially by unbind_to_1 */ |
428 | 6594 } |
6595 else if (buffer_local > 0) | |
6596 { | |
6597 /* Already buffer-local */ | |
6598 specpdl_ptr->old_value = noseeum_cons (Fcurrent_buffer (), | |
6599 find_symbol_value (symbol)); | |
6600 specpdl_ptr->func = specbind_unwind_local; | |
6601 } | |
6602 else | |
6603 { | |
6604 /* About to become buffer-local */ | |
6605 specpdl_ptr->old_value = Fcurrent_buffer (); | |
6606 specpdl_ptr->func = specbind_unwind_wasnt_local; | |
6607 } | |
6608 | |
6609 specpdl_ptr->symbol = symbol; | |
6610 specpdl_ptr++; | |
6611 specpdl_depth_counter++; | |
6612 | |
6613 Fset (symbol, value); | |
853 | 6614 |
6615 check_specbind_stack_sanity (); | |
428 | 6616 } |
6617 | |
771 | 6618 /* Record an unwind-protect -- FUNCTION will be called with ARG no matter |
6619 whether a normal or non-local exit occurs. (You need to call unbind_to_1() | |
6620 before your function returns normally, passing in the integer returned | |
6621 by this function.) Note: As long as the unwind-protect exists, ARG is | |
6622 automatically GCPRO'd. The return value from FUNCTION is completely | |
6623 ignored. #### We should eliminate it entirely. */ | |
6624 | |
6625 int | |
428 | 6626 record_unwind_protect (Lisp_Object (*function) (Lisp_Object arg), |
6627 Lisp_Object arg) | |
6628 { | |
6629 SPECPDL_RESERVE (1); | |
6630 specpdl_ptr->func = function; | |
6631 specpdl_ptr->symbol = Qnil; | |
6632 specpdl_ptr->old_value = arg; | |
6633 specpdl_ptr++; | |
6634 specpdl_depth_counter++; | |
853 | 6635 check_specbind_stack_sanity (); |
771 | 6636 return specpdl_depth_counter - 1; |
6637 } | |
6638 | |
6639 static Lisp_Object | |
802 | 6640 restore_lisp_object (Lisp_Object cons) |
6641 { | |
6642 Lisp_Object opaque = XCAR (cons); | |
6643 Lisp_Object *addr = (Lisp_Object *) get_opaque_ptr (opaque); | |
6644 *addr = XCDR (cons); | |
6645 free_opaque_ptr (opaque); | |
853 | 6646 free_cons (cons); |
802 | 6647 return Qnil; |
6648 } | |
6649 | |
6650 /* Establish an unwind-protect which will restore the Lisp_Object pointed to | |
6651 by ADDR with the value VAL. */ | |
814 | 6652 static int |
802 | 6653 record_unwind_protect_restoring_lisp_object (Lisp_Object *addr, |
6654 Lisp_Object val) | |
6655 { | |
6656 Lisp_Object opaque = make_opaque_ptr (addr); | |
6657 return record_unwind_protect (restore_lisp_object, | |
6658 noseeum_cons (opaque, val)); | |
6659 } | |
6660 | |
6661 /* Similar to specbind() but for any C variable whose value is a | |
6662 Lisp_Object. Sets up an unwind-protect to restore the variable | |
6663 pointed to by ADDR to its existing value, and then changes its | |
6664 value to NEWVAL. Returns the previous value of specpdl_depth(); | |
6665 pass this to unbind_to() after you are done. */ | |
6666 int | |
6667 internal_bind_lisp_object (Lisp_Object *addr, Lisp_Object newval) | |
6668 { | |
6669 int count = specpdl_depth (); | |
6670 record_unwind_protect_restoring_lisp_object (addr, *addr); | |
6671 *addr = newval; | |
6672 return count; | |
6673 } | |
6674 | |
6675 static Lisp_Object | |
6676 restore_int (Lisp_Object cons) | |
6677 { | |
6678 Lisp_Object opaque = XCAR (cons); | |
6679 Lisp_Object lval = XCDR (cons); | |
6680 int *addr = (int *) get_opaque_ptr (opaque); | |
6681 int val; | |
6682 | |
4025 | 6683 /* In the event that a C integer will always fit in an Emacs int, we |
6684 haven't ever stored a C integer as an opaque pointer. This #ifdef | |
6685 eliminates a warning on AMD 64, where EMACS_INT has 63 value bits and C | |
6686 integers have 32 value bits. */ | |
6687 #if INT_VALBITS < INTBITS | |
802 | 6688 if (INTP (lval)) |
4025 | 6689 { |
6690 val = XINT (lval); | |
6691 } | |
802 | 6692 else |
6693 { | |
6694 val = (int) get_opaque_ptr (lval); | |
6695 free_opaque_ptr (lval); | |
6696 } | |
4025 | 6697 #else /* !(INT_VALBITS < INTBITS) */ |
6698 val = XINT(lval); | |
6699 #endif /* INT_VALBITS < INTBITS */ | |
802 | 6700 |
6701 *addr = val; | |
6702 free_opaque_ptr (opaque); | |
853 | 6703 free_cons (cons); |
802 | 6704 return Qnil; |
6705 } | |
6706 | |
6707 /* Establish an unwind-protect which will restore the int pointed to | |
6708 by ADDR with the value VAL. This function works correctly with | |
6709 all ints, even those that don't fit into a Lisp integer. */ | |
1333 | 6710 int |
802 | 6711 record_unwind_protect_restoring_int (int *addr, int val) |
6712 { | |
6713 Lisp_Object opaque = make_opaque_ptr (addr); | |
6714 Lisp_Object lval; | |
6715 | |
4025 | 6716 /* In the event that a C integer will always fit in an Emacs int, we don't |
6717 ever want to store a C integer as an opaque pointer. This #ifdef | |
6718 eliminates a warning on AMD 64, where EMACS_INT has 63 value bits and C | |
6719 integers have 32 value bits. */ | |
6720 #if INT_VALBITS <= INTBITS | |
802 | 6721 if (NUMBER_FITS_IN_AN_EMACS_INT (val)) |
6722 lval = make_int (val); | |
6723 else | |
6724 lval = make_opaque_ptr ((void *) val); | |
4025 | 6725 #else /* !(INT_VALBITS < INTBITS) */ |
6726 lval = make_int (val); | |
6727 #endif /* INT_VALBITS <= INTBITS */ | |
6728 | |
802 | 6729 return record_unwind_protect (restore_int, noseeum_cons (opaque, lval)); |
6730 } | |
6731 | |
6732 /* Similar to specbind() but for any C variable whose value is an int. | |
6733 Sets up an unwind-protect to restore the variable pointed to by | |
6734 ADDR to its existing value, and then changes its value to NEWVAL. | |
6735 Returns the previous value of specpdl_depth(); pass this to | |
6736 unbind_to() after you are done. This function works correctly with | |
6737 all ints, even those that don't fit into a Lisp integer. */ | |
6738 int | |
6739 internal_bind_int (int *addr, int newval) | |
6740 { | |
6741 int count = specpdl_depth (); | |
6742 record_unwind_protect_restoring_int (addr, *addr); | |
6743 *addr = newval; | |
6744 return count; | |
6745 } | |
6746 | |
6747 static Lisp_Object | |
771 | 6748 free_pointer (Lisp_Object opaque) |
6749 { | |
1726 | 6750 xfree (get_opaque_ptr (opaque), void *); |
771 | 6751 free_opaque_ptr (opaque); |
6752 return Qnil; | |
6753 } | |
6754 | |
6755 /* Establish an unwind-protect which will free the specified block. | |
6756 */ | |
6757 int | |
6758 record_unwind_protect_freeing (void *ptr) | |
6759 { | |
6760 Lisp_Object opaque = make_opaque_ptr (ptr); | |
6761 return record_unwind_protect (free_pointer, opaque); | |
6762 } | |
6763 | |
6764 static Lisp_Object | |
6765 free_dynarr (Lisp_Object opaque) | |
6766 { | |
6767 Dynarr_free (get_opaque_ptr (opaque)); | |
6768 free_opaque_ptr (opaque); | |
6769 return Qnil; | |
6770 } | |
6771 | |
6772 int | |
6773 record_unwind_protect_freeing_dynarr (void *ptr) | |
6774 { | |
6775 Lisp_Object opaque = make_opaque_ptr (ptr); | |
6776 return record_unwind_protect (free_dynarr, opaque); | |
6777 } | |
428 | 6778 |
6779 /* Unwind the stack till specpdl_depth() == COUNT. | |
6780 VALUE is not used, except that, purely as a convenience to the | |
771 | 6781 caller, it is protected from garbage-protection and returned. */ |
428 | 6782 Lisp_Object |
771 | 6783 unbind_to_1 (int count, Lisp_Object value) |
428 | 6784 { |
6785 UNBIND_TO_GCPRO (count, value); | |
853 | 6786 check_specbind_stack_sanity (); |
428 | 6787 return value; |
6788 } | |
6789 | |
6790 /* Don't call this directly. | |
6791 Only for use by UNBIND_TO* macros in backtrace.h */ | |
6792 void | |
6793 unbind_to_hairy (int count) | |
6794 { | |
442 | 6795 ++specpdl_ptr; |
6796 ++specpdl_depth_counter; | |
6797 | |
428 | 6798 while (specpdl_depth_counter != count) |
6799 { | |
1313 | 6800 Lisp_Object oquit = Qunbound; |
6801 | |
6802 /* Do this check BEFORE decrementing the values below, because once | |
6803 they're decremented, GC protection is lost on | |
6804 specpdl_ptr->old_value. */ | |
1322 | 6805 if (specpdl_ptr[-1].func == Fprogn) |
1313 | 6806 { |
6807 /* Allow QUIT within unwind-protect routines, but defer any | |
6808 existing QUIT until afterwards. Only do this, however, for | |
6809 unwind-protects established by Lisp code, not by C code | |
6810 (e.g. free_opaque_ptr() or something), because the act of | |
6811 checking for QUIT can cause all sorts of weird things to | |
6812 happen, since it churns the event loop -- redisplay, running | |
6813 Lisp, etc. Code should not have to worry about this just | |
6814 because of establishing an unwind-protect. */ | |
6815 check_quit (); /* make Vquit_flag accurate */ | |
6816 oquit = Vquit_flag; | |
6817 Vquit_flag = Qnil; | |
6818 } | |
6819 | |
428 | 6820 --specpdl_ptr; |
6821 --specpdl_depth_counter; | |
6822 | |
1313 | 6823 /* #### At this point, there is no GC protection on old_value. This |
6824 could be a real problem, depending on what unwind-protect function | |
6825 is called. It looks like it just so happens that the ones | |
6826 actually called don't have a problem with this, e.g. Fprogn. But | |
6827 we should look into fixing this. (Many unwind-protect functions | |
6828 free values. Is it a problem if freed values are | |
6829 GC-protected?) */ | |
428 | 6830 if (specpdl_ptr->func != 0) |
1313 | 6831 { |
6832 /* An unwind-protect */ | |
6833 (*specpdl_ptr->func) (specpdl_ptr->old_value); | |
6834 } | |
6835 | |
428 | 6836 else |
6837 { | |
6838 /* We checked symbol for validity when we specbound it, | |
6839 so only need to call Fset if symbol has magic value. */ | |
440 | 6840 Lisp_Symbol *sym = XSYMBOL (specpdl_ptr->symbol); |
428 | 6841 if (!SYMBOL_VALUE_MAGIC_P (sym->value)) |
6842 sym->value = specpdl_ptr->old_value; | |
6843 else | |
6844 Fset (specpdl_ptr->symbol, specpdl_ptr->old_value); | |
6845 } | |
6846 | |
6847 #if 0 /* martin */ | |
6848 #ifndef EXCEEDINGLY_QUESTIONABLE_CODE | |
6849 /* There should never be anything here for us to remove. | |
6850 If so, it indicates a logic error in Emacs. Catches | |
6851 should get removed when a throw or signal occurs, or | |
6852 when a catch or condition-case exits normally. But | |
6853 it's too dangerous to just remove this code. --ben */ | |
6854 | |
6855 /* Furthermore, this code is not in FSFmacs!!! | |
6856 Braino on mly's part? */ | |
6857 /* If we're unwound past the pdlcount of a catch frame, | |
6858 that catch can't possibly still be valid. */ | |
6859 while (catchlist && catchlist->pdlcount > specpdl_depth_counter) | |
6860 { | |
6861 catchlist = catchlist->next; | |
6862 /* Don't mess with gcprolist, backtrace_list here */ | |
6863 } | |
6864 #endif | |
6865 #endif | |
1313 | 6866 |
6867 if (!UNBOUNDP (oquit)) | |
6868 Vquit_flag = oquit; | |
428 | 6869 } |
853 | 6870 check_specbind_stack_sanity (); |
428 | 6871 } |
6872 | |
6873 | |
6874 | |
6875 /* Get the value of symbol's global binding, even if that binding is | |
6876 not now dynamically visible. May return Qunbound or magic values. */ | |
6877 | |
6878 Lisp_Object | |
6879 top_level_value (Lisp_Object symbol) | |
6880 { | |
6881 REGISTER struct specbinding *ptr = specpdl; | |
6882 | |
6883 CHECK_SYMBOL (symbol); | |
6884 for (; ptr != specpdl_ptr; ptr++) | |
6885 { | |
6886 if (EQ (ptr->symbol, symbol)) | |
6887 return ptr->old_value; | |
6888 } | |
6889 return XSYMBOL (symbol)->value; | |
6890 } | |
6891 | |
6892 #if 0 | |
6893 | |
6894 Lisp_Object | |
6895 top_level_set (Lisp_Object symbol, Lisp_Object newval) | |
6896 { | |
6897 REGISTER struct specbinding *ptr = specpdl; | |
6898 | |
6899 CHECK_SYMBOL (symbol); | |
6900 for (; ptr != specpdl_ptr; ptr++) | |
6901 { | |
6902 if (EQ (ptr->symbol, symbol)) | |
6903 { | |
6904 ptr->old_value = newval; | |
6905 return newval; | |
6906 } | |
6907 } | |
6908 return Fset (symbol, newval); | |
6909 } | |
6910 | |
6911 #endif /* 0 */ | |
6912 | |
6913 | |
6914 /************************************************************************/ | |
6915 /* Backtraces */ | |
6916 /************************************************************************/ | |
6917 | |
6918 DEFUN ("backtrace-debug", Fbacktrace_debug, 2, 2, 0, /* | |
6919 Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG. | |
6920 The debugger is entered when that frame exits, if the flag is non-nil. | |
6921 */ | |
6922 (level, flag)) | |
6923 { | |
6924 REGISTER struct backtrace *backlist = backtrace_list; | |
6925 REGISTER int i; | |
6926 | |
6927 CHECK_INT (level); | |
6928 | |
6929 for (i = 0; backlist && i < XINT (level); i++) | |
6930 { | |
6931 backlist = backlist->next; | |
6932 } | |
6933 | |
6934 if (backlist) | |
6935 backlist->debug_on_exit = !NILP (flag); | |
6936 | |
6937 return flag; | |
6938 } | |
6939 | |
6940 static void | |
6941 backtrace_specials (int speccount, int speclimit, Lisp_Object stream) | |
6942 { | |
6943 int printing_bindings = 0; | |
6944 | |
6945 for (; speccount > speclimit; speccount--) | |
6946 { | |
6947 if (specpdl[speccount - 1].func == 0 | |
6948 || specpdl[speccount - 1].func == specbind_unwind_local | |
6949 || specpdl[speccount - 1].func == specbind_unwind_wasnt_local) | |
6950 { | |
826 | 6951 write_c_string (stream, !printing_bindings ? " # bind (" : " "); |
428 | 6952 Fprin1 (specpdl[speccount - 1].symbol, stream); |
6953 printing_bindings = 1; | |
6954 } | |
6955 else | |
6956 { | |
826 | 6957 if (printing_bindings) write_c_string (stream, ")\n"); |
6958 write_c_string (stream, " # (unwind-protect ...)\n"); | |
428 | 6959 printing_bindings = 0; |
6960 } | |
6961 } | |
826 | 6962 if (printing_bindings) write_c_string (stream, ")\n"); |
428 | 6963 } |
6964 | |
1292 | 6965 static Lisp_Object |
6966 backtrace_unevalled_args (Lisp_Object *args) | |
6967 { | |
6968 if (args) | |
6969 return *args; | |
6970 else | |
6971 return list1 (build_string ("[internal]")); | |
6972 } | |
6973 | |
428 | 6974 DEFUN ("backtrace", Fbacktrace, 0, 2, "", /* |
6975 Print a trace of Lisp function calls currently active. | |
438 | 6976 Optional arg STREAM specifies the output stream to send the backtrace to, |
444 | 6977 and defaults to the value of `standard-output'. |
6978 Optional second arg DETAILED non-nil means show places where currently | |
6979 active variable bindings, catches, condition-cases, and | |
6980 unwind-protects, as well as function calls, were made. | |
428 | 6981 */ |
6982 (stream, detailed)) | |
6983 { | |
6984 /* This function can GC */ | |
6985 struct backtrace *backlist = backtrace_list; | |
6986 struct catchtag *catches = catchlist; | |
6987 int speccount = specpdl_depth(); | |
6988 | |
6989 int old_nl = print_escape_newlines; | |
6990 int old_pr = print_readably; | |
6991 Lisp_Object old_level = Vprint_level; | |
6992 Lisp_Object oiq = Vinhibit_quit; | |
6993 struct gcpro gcpro1, gcpro2; | |
6994 | |
6995 /* We can't allow quits in here because that could cause the values | |
6996 of print_readably and print_escape_newlines to get screwed up. | |
6997 Normally we would use a record_unwind_protect but that would | |
6998 screw up the functioning of this function. */ | |
6999 Vinhibit_quit = Qt; | |
7000 | |
7001 entering_debugger = 0; | |
7002 | |
872 | 7003 if (!NILP (detailed)) |
7004 Vprint_level = make_int (50); | |
7005 else | |
7006 Vprint_level = make_int (3); | |
428 | 7007 print_readably = 0; |
7008 print_escape_newlines = 1; | |
7009 | |
7010 GCPRO2 (stream, old_level); | |
7011 | |
1261 | 7012 stream = canonicalize_printcharfun (stream); |
428 | 7013 |
7014 for (;;) | |
7015 { | |
7016 if (!NILP (detailed) && catches && catches->backlist == backlist) | |
7017 { | |
7018 int catchpdl = catches->pdlcount; | |
438 | 7019 if (speccount > catchpdl |
7020 && specpdl[catchpdl].func == condition_case_unwind) | |
428 | 7021 /* This is a condition-case catchpoint */ |
7022 catchpdl = catchpdl + 1; | |
7023 | |
7024 backtrace_specials (speccount, catchpdl, stream); | |
7025 | |
7026 speccount = catches->pdlcount; | |
7027 if (catchpdl == speccount) | |
7028 { | |
826 | 7029 write_c_string (stream, " # (catch "); |
428 | 7030 Fprin1 (catches->tag, stream); |
826 | 7031 write_c_string (stream, " ...)\n"); |
428 | 7032 } |
7033 else | |
7034 { | |
826 | 7035 write_c_string (stream, " # (condition-case ... . "); |
428 | 7036 Fprin1 (Fcdr (Fcar (catches->tag)), stream); |
826 | 7037 write_c_string (stream, ")\n"); |
428 | 7038 } |
7039 catches = catches->next; | |
7040 } | |
7041 else if (!backlist) | |
7042 break; | |
7043 else | |
7044 { | |
7045 if (!NILP (detailed) && backlist->pdlcount < speccount) | |
7046 { | |
7047 backtrace_specials (speccount, backlist->pdlcount, stream); | |
7048 speccount = backlist->pdlcount; | |
7049 } | |
826 | 7050 write_c_string (stream, backlist->debug_on_exit ? "* " : " "); |
428 | 7051 if (backlist->nargs == UNEVALLED) |
7052 { | |
1292 | 7053 Fprin1 (Fcons (*backlist->function, |
7054 backtrace_unevalled_args (backlist->args)), | |
7055 stream); | |
826 | 7056 write_c_string (stream, "\n"); /* from FSFmacs 19.30 */ |
428 | 7057 } |
7058 else | |
7059 { | |
7060 Lisp_Object tem = *backlist->function; | |
7061 Fprin1 (tem, stream); /* This can QUIT */ | |
826 | 7062 write_c_string (stream, "("); |
428 | 7063 if (backlist->nargs == MANY) |
7064 { | |
7065 int i; | |
7066 Lisp_Object tail = Qnil; | |
7067 struct gcpro ngcpro1; | |
7068 | |
7069 NGCPRO1 (tail); | |
7070 for (tail = *backlist->args, i = 0; | |
7071 !NILP (tail); | |
7072 tail = Fcdr (tail), i++) | |
7073 { | |
826 | 7074 if (i != 0) write_c_string (stream, " "); |
428 | 7075 Fprin1 (Fcar (tail), stream); |
7076 } | |
7077 NUNGCPRO; | |
7078 } | |
7079 else | |
7080 { | |
7081 int i; | |
7082 for (i = 0; i < backlist->nargs; i++) | |
7083 { | |
826 | 7084 if (!i && EQ (tem, Qbyte_code)) |
7085 { | |
7086 write_c_string (stream, "\"...\""); | |
7087 continue; | |
7088 } | |
7089 if (i != 0) write_c_string (stream, " "); | |
428 | 7090 Fprin1 (backlist->args[i], stream); |
7091 } | |
7092 } | |
826 | 7093 write_c_string (stream, ")\n"); |
428 | 7094 } |
7095 backlist = backlist->next; | |
7096 } | |
7097 } | |
7098 Vprint_level = old_level; | |
7099 print_readably = old_pr; | |
7100 print_escape_newlines = old_nl; | |
7101 UNGCPRO; | |
7102 Vinhibit_quit = oiq; | |
7103 return Qnil; | |
7104 } | |
7105 | |
7106 | |
444 | 7107 DEFUN ("backtrace-frame", Fbacktrace_frame, 1, 1, 0, /* |
7108 Return the function and arguments NFRAMES up from current execution point. | |
428 | 7109 If that frame has not evaluated the arguments yet (or is a special form), |
7110 the value is (nil FUNCTION ARG-FORMS...). | |
7111 If that frame has evaluated its arguments and called its function already, | |
7112 the value is (t FUNCTION ARG-VALUES...). | |
7113 A &rest arg is represented as the tail of the list ARG-VALUES. | |
7114 FUNCTION is whatever was supplied as car of evaluated list, | |
7115 or a lambda expression for macro calls. | |
444 | 7116 If NFRAMES is more than the number of frames, the value is nil. |
428 | 7117 */ |
7118 (nframes)) | |
7119 { | |
7120 REGISTER struct backtrace *backlist = backtrace_list; | |
7121 REGISTER int i; | |
7122 Lisp_Object tem; | |
7123 | |
7124 CHECK_NATNUM (nframes); | |
7125 | |
7126 /* Find the frame requested. */ | |
7127 for (i = XINT (nframes); backlist && (i-- > 0);) | |
7128 backlist = backlist->next; | |
7129 | |
7130 if (!backlist) | |
7131 return Qnil; | |
7132 if (backlist->nargs == UNEVALLED) | |
1292 | 7133 return Fcons (Qnil, Fcons (*backlist->function, |
7134 backtrace_unevalled_args (backlist->args))); | |
428 | 7135 else |
7136 { | |
7137 if (backlist->nargs == MANY) | |
7138 tem = *backlist->args; | |
7139 else | |
7140 tem = Flist (backlist->nargs, backlist->args); | |
7141 | |
7142 return Fcons (Qt, Fcons (*backlist->function, tem)); | |
7143 } | |
7144 } | |
7145 | |
7146 | |
7147 /************************************************************************/ | |
7148 /* Warnings */ | |
7149 /************************************************************************/ | |
7150 | |
1123 | 7151 static int |
7152 warning_will_be_discarded (Lisp_Object level) | |
7153 { | |
7154 /* Don't even generate debug warnings if they're going to be discarded, | |
7155 to avoid excessive consing. */ | |
7156 return (EQ (level, Qdebug) && !NILP (Vlog_warning_minimum_level) && | |
7157 !EQ (Vlog_warning_minimum_level, Qdebug)); | |
7158 } | |
7159 | |
428 | 7160 void |
1204 | 7161 warn_when_safe_lispobj (Lisp_Object class_, Lisp_Object level, |
428 | 7162 Lisp_Object obj) |
7163 { | |
1123 | 7164 if (warning_will_be_discarded (level)) |
793 | 7165 return; |
1123 | 7166 |
1204 | 7167 obj = list1 (list3 (class_, level, obj)); |
428 | 7168 if (NILP (Vpending_warnings)) |
7169 Vpending_warnings = Vpending_warnings_tail = obj; | |
7170 else | |
7171 { | |
7172 Fsetcdr (Vpending_warnings_tail, obj); | |
7173 Vpending_warnings_tail = obj; | |
7174 } | |
7175 } | |
7176 | |
7177 /* #### This should probably accept Lisp objects; but then we have | |
7178 to make sure that Feval() isn't called, since it might not be safe. | |
7179 | |
7180 An alternative approach is to just pass some non-string type of | |
7181 Lisp_Object to warn_when_safe_lispobj(); `prin1-to-string' will | |
7182 automatically be called when it is safe to do so. */ | |
7183 | |
7184 void | |
1204 | 7185 warn_when_safe (Lisp_Object class_, Lisp_Object level, const CIbyte *fmt, ...) |
428 | 7186 { |
7187 Lisp_Object obj; | |
7188 va_list args; | |
7189 | |
1123 | 7190 if (warning_will_be_discarded (level)) |
793 | 7191 return; |
1123 | 7192 |
428 | 7193 va_start (args, fmt); |
771 | 7194 obj = emacs_vsprintf_string (CGETTEXT (fmt), args); |
428 | 7195 va_end (args); |
7196 | |
1204 | 7197 warn_when_safe_lispobj (class_, level, obj); |
428 | 7198 } |
7199 | |
7200 | |
7201 | |
7202 | |
7203 /************************************************************************/ | |
7204 /* Initialization */ | |
7205 /************************************************************************/ | |
7206 | |
7207 void | |
7208 syms_of_eval (void) | |
7209 { | |
442 | 7210 INIT_LRECORD_IMPLEMENTATION (subr); |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
7211 INIT_LRECORD_IMPLEMENTATION (multiple_value); |
442 | 7212 |
563 | 7213 DEFSYMBOL (Qinhibit_quit); |
7214 DEFSYMBOL (Qautoload); | |
7215 DEFSYMBOL (Qdebug_on_error); | |
7216 DEFSYMBOL (Qstack_trace_on_error); | |
7217 DEFSYMBOL (Qdebug_on_signal); | |
7218 DEFSYMBOL (Qstack_trace_on_signal); | |
7219 DEFSYMBOL (Qdebugger); | |
7220 DEFSYMBOL (Qmacro); | |
428 | 7221 defsymbol (&Qand_rest, "&rest"); |
7222 defsymbol (&Qand_optional, "&optional"); | |
7223 /* Note that the process code also uses Qexit */ | |
563 | 7224 DEFSYMBOL (Qexit); |
7225 DEFSYMBOL (Qsetq); | |
7226 DEFSYMBOL (Qinteractive); | |
7227 DEFSYMBOL (Qcommandp); | |
7228 DEFSYMBOL (Qdefun); | |
7229 DEFSYMBOL (Qprogn); | |
7230 DEFSYMBOL (Qvalues); | |
7231 DEFSYMBOL (Qdisplay_warning); | |
7232 DEFSYMBOL (Qrun_hooks); | |
887 | 7233 DEFSYMBOL (Qfinalize_list); |
563 | 7234 DEFSYMBOL (Qif); |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
7235 DEFSYMBOL (Qthrow); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
7236 DEFSYMBOL (Qobsolete_throw); |
4686
cdabd56ce1b5
Fix various small issues with the multiple-value implementation.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4677
diff
changeset
|
7237 DEFSYMBOL (Qmultiple_value_list_internal); |
428 | 7238 |
7239 DEFSUBR (For); | |
7240 DEFSUBR (Fand); | |
7241 DEFSUBR (Fif); | |
7242 DEFSUBR_MACRO (Fwhen); | |
7243 DEFSUBR_MACRO (Funless); | |
7244 DEFSUBR (Fcond); | |
7245 DEFSUBR (Fprogn); | |
7246 DEFSUBR (Fprog1); | |
7247 DEFSUBR (Fprog2); | |
7248 DEFSUBR (Fsetq); | |
7249 DEFSUBR (Fquote); | |
7250 DEFSUBR (Ffunction); | |
7251 DEFSUBR (Fdefun); | |
7252 DEFSUBR (Fdefmacro); | |
7253 DEFSUBR (Fdefvar); | |
7254 DEFSUBR (Fdefconst); | |
7255 DEFSUBR (Flet); | |
7256 DEFSUBR (FletX); | |
7257 DEFSUBR (Fwhile); | |
7258 DEFSUBR (Fmacroexpand_internal); | |
7259 DEFSUBR (Fcatch); | |
7260 DEFSUBR (Fthrow); | |
7261 DEFSUBR (Funwind_protect); | |
7262 DEFSUBR (Fcondition_case); | |
7263 DEFSUBR (Fcall_with_condition_handler); | |
7264 DEFSUBR (Fsignal); | |
7265 DEFSUBR (Finteractive_p); | |
7266 DEFSUBR (Fcommandp); | |
7267 DEFSUBR (Fcommand_execute); | |
7268 DEFSUBR (Fautoload); | |
7269 DEFSUBR (Feval); | |
7270 DEFSUBR (Fapply); | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
7271 DEFSUBR (Fmultiple_value_call); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
7272 DEFSUBR (Fmultiple_value_list_internal); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
7273 DEFSUBR (Fmultiple_value_prog1); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
7274 DEFSUBR (Fvalues); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
7275 DEFSUBR (Fvalues_list); |
428 | 7276 DEFSUBR (Ffuncall); |
7277 DEFSUBR (Ffunctionp); | |
7278 DEFSUBR (Ffunction_min_args); | |
7279 DEFSUBR (Ffunction_max_args); | |
7280 DEFSUBR (Frun_hooks); | |
7281 DEFSUBR (Frun_hook_with_args); | |
7282 DEFSUBR (Frun_hook_with_args_until_success); | |
7283 DEFSUBR (Frun_hook_with_args_until_failure); | |
7284 DEFSUBR (Fbacktrace_debug); | |
7285 DEFSUBR (Fbacktrace); | |
7286 DEFSUBR (Fbacktrace_frame); | |
7287 } | |
7288 | |
7289 void | |
814 | 7290 init_eval_semi_early (void) |
428 | 7291 { |
7292 specpdl_ptr = specpdl; | |
7293 specpdl_depth_counter = 0; | |
7294 catchlist = 0; | |
7295 Vcondition_handlers = Qnil; | |
7296 backtrace_list = 0; | |
7297 Vquit_flag = Qnil; | |
7298 debug_on_next_call = 0; | |
7299 lisp_eval_depth = 0; | |
7300 entering_debugger = 0; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
7301 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
7302 first_desired_multiple_value = 0; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
7303 multiple_value_current_limit = 1; |
428 | 7304 } |
7305 | |
7306 void | |
7307 reinit_vars_of_eval (void) | |
7308 { | |
7309 preparing_for_armageddon = 0; | |
7310 in_warnings = 0; | |
7311 specpdl_size = 50; | |
7312 specpdl = xnew_array (struct specbinding, specpdl_size); | |
7313 /* XEmacs change: increase these values. */ | |
7314 max_specpdl_size = 3000; | |
442 | 7315 max_lisp_eval_depth = 1000; |
7316 #ifdef DEFEND_AGAINST_THROW_RECURSION | |
428 | 7317 throw_level = 0; |
7318 #endif | |
2367 | 7319 init_eval_semi_early (); |
428 | 7320 } |
7321 | |
7322 void | |
7323 vars_of_eval (void) | |
7324 { | |
7325 DEFVAR_INT ("max-specpdl-size", &max_specpdl_size /* | |
7326 Limit on number of Lisp variable bindings & unwind-protects before error. | |
7327 */ ); | |
7328 | |
7329 DEFVAR_INT ("max-lisp-eval-depth", &max_lisp_eval_depth /* | |
7330 Limit on depth in `eval', `apply' and `funcall' before error. | |
7331 This limit is to catch infinite recursions for you before they cause | |
7332 actual stack overflow in C, which would be fatal for Emacs. | |
7333 You can safely make it considerably larger than its default value, | |
7334 if that proves inconveniently small. | |
7335 */ ); | |
7336 | |
7337 DEFVAR_LISP ("quit-flag", &Vquit_flag /* | |
853 | 7338 t causes running Lisp code to abort, unless `inhibit-quit' is non-nil. |
7339 `critical' causes running Lisp code to abort regardless of `inhibit-quit'. | |
7340 Normally, you do not need to set this value yourself. It is set to | |
7341 t each time a Control-G is detected, and to `critical' each time a | |
7342 Shift-Control-G is detected. The XEmacs core C code is littered with | |
7343 calls to the QUIT; macro, which check the values of `quit-flag' and | |
2500 | 7344 `inhibit-quit' and ABORT (or more accurately, call (signal 'quit)) if |
853 | 7345 it's correct to do so. |
428 | 7346 */ ); |
7347 Vquit_flag = Qnil; | |
7348 | |
7349 DEFVAR_LISP ("inhibit-quit", &Vinhibit_quit /* | |
7350 Non-nil inhibits C-g quitting from happening immediately. | |
7351 Note that `quit-flag' will still be set by typing C-g, | |
7352 so a quit will be signalled as soon as `inhibit-quit' is nil. | |
7353 To prevent this happening, set `quit-flag' to nil | |
853 | 7354 before making `inhibit-quit' nil. |
7355 | |
7356 The value of `inhibit-quit' is ignored if a critical quit is | |
7357 requested by typing control-shift-G in a window-system frame; | |
7358 this is explained in more detail in `quit-flag'. | |
428 | 7359 */ ); |
7360 Vinhibit_quit = Qnil; | |
7361 | |
7362 DEFVAR_LISP ("stack-trace-on-error", &Vstack_trace_on_error /* | |
7363 *Non-nil means automatically display a backtrace buffer | |
7364 after any error that is not handled by a `condition-case'. | |
7365 If the value is a list, an error only means to display a backtrace | |
7366 if one of its condition symbols appears in the list. | |
7367 See also variable `stack-trace-on-signal'. | |
7368 */ ); | |
7369 Vstack_trace_on_error = Qnil; | |
7370 | |
7371 DEFVAR_LISP ("stack-trace-on-signal", &Vstack_trace_on_signal /* | |
7372 *Non-nil means automatically display a backtrace buffer | |
7373 after any error that is signalled, whether or not it is handled by | |
7374 a `condition-case'. | |
7375 If the value is a list, an error only means to display a backtrace | |
7376 if one of its condition symbols appears in the list. | |
7377 See also variable `stack-trace-on-error'. | |
7378 */ ); | |
7379 Vstack_trace_on_signal = Qnil; | |
7380 | |
7381 DEFVAR_LISP ("debug-ignored-errors", &Vdebug_ignored_errors /* | |
7382 *List of errors for which the debugger should not be called. | |
7383 Each element may be a condition-name or a regexp that matches error messages. | |
7384 If any element applies to a given error, that error skips the debugger | |
7385 and just returns to top level. | |
7386 This overrides the variable `debug-on-error'. | |
7387 It does not apply to errors handled by `condition-case'. | |
7388 */ ); | |
7389 Vdebug_ignored_errors = Qnil; | |
7390 | |
7391 DEFVAR_LISP ("debug-on-error", &Vdebug_on_error /* | |
7392 *Non-nil means enter debugger if an unhandled error is signalled. | |
7393 The debugger will not be entered if the error is handled by | |
7394 a `condition-case'. | |
7395 If the value is a list, an error only means to enter the debugger | |
7396 if one of its condition symbols appears in the list. | |
7397 This variable is overridden by `debug-ignored-errors'. | |
7398 See also variables `debug-on-quit' and `debug-on-signal'. | |
1123 | 7399 |
4657
f8d7d8202635
imported patch accept-process-output-docstring
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4642
diff
changeset
|
7400 Process filters are considered to be outside of condition-case forms |
f8d7d8202635
imported patch accept-process-output-docstring
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4642
diff
changeset
|
7401 (unless contained in the process filter itself). To prevent the |
f8d7d8202635
imported patch accept-process-output-docstring
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4642
diff
changeset
|
7402 debugger from being called from a process filter, use a list value, or |
f8d7d8202635
imported patch accept-process-output-docstring
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4642
diff
changeset
|
7403 put the expected error\(s) in `debug-ignored-errors'. |
f8d7d8202635
imported patch accept-process-output-docstring
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4642
diff
changeset
|
7404 |
1123 | 7405 If this variable is set while XEmacs is running noninteractively (using |
7406 `-batch'), and XEmacs was configured with `--debug' (#define XEMACS_DEBUG | |
7407 in the C code), instead of trying to invoke the Lisp debugger (which | |
7408 obviously won't work), XEmacs will break out to a C debugger using | |
7409 \(force-debugging-signal t). This is useful because debugging | |
7410 noninteractive runs of XEmacs is often very difficult, since they typically | |
7411 happen as part of sometimes large and complex make suites (e.g. rebuilding | |
2500 | 7412 the XEmacs packages). NOTE: This runs ABORT()!!! (As well as and after |
1123 | 7413 executing INT 3 under MS Windows, which should invoke a debugger if it's |
7414 active.) This is guaranteed to kill XEmacs! (But in this situation, XEmacs | |
7415 is about to die anyway, and if no debugger is present, this will usefully | |
7416 dump core.) The most useful way to set this flag when debugging | |
7417 noninteractive runs, especially in makefiles, is using the environment | |
7418 variable XEMACSDEBUG, like this: | |
771 | 7419 |
7420 \(using csh) setenv XEMACSDEBUG '(setq debug-on-error t)' | |
7421 \(using bash) export XEMACSDEBUG='(setq debug-on-error t)' | |
428 | 7422 */ ); |
7423 Vdebug_on_error = Qnil; | |
7424 | |
7425 DEFVAR_LISP ("debug-on-signal", &Vdebug_on_signal /* | |
7426 *Non-nil means enter debugger if an error is signalled. | |
7427 The debugger will be entered whether or not the error is handled by | |
7428 a `condition-case'. | |
7429 If the value is a list, an error only means to enter the debugger | |
7430 if one of its condition symbols appears in the list. | |
7431 See also variable `debug-on-quit'. | |
1123 | 7432 |
7433 This will attempt to enter a C debugger when XEmacs is run noninteractively | |
7434 and under the same conditions as described in `debug-on-error'. | |
428 | 7435 */ ); |
7436 Vdebug_on_signal = Qnil; | |
7437 | |
7438 DEFVAR_BOOL ("debug-on-quit", &debug_on_quit /* | |
7439 *Non-nil means enter debugger if quit is signalled (C-G, for example). | |
7440 Does not apply if quit is handled by a `condition-case'. Entering the | |
7441 debugger can also be achieved at any time (for X11 console) by typing | |
7442 control-shift-G to signal a critical quit. | |
7443 */ ); | |
7444 debug_on_quit = 0; | |
7445 | |
7446 DEFVAR_BOOL ("debug-on-next-call", &debug_on_next_call /* | |
7447 Non-nil means enter debugger before next `eval', `apply' or `funcall'. | |
7448 */ ); | |
7449 | |
1292 | 7450 DEFVAR_BOOL ("backtrace-with-interal-sections", |
7451 &backtrace_with_internal_sections /* | |
7452 Non-nil means backtraces will contain additional information indicating | |
7453 when particular sections of the C code have been entered, e.g. redisplay(), | |
7454 byte-char conversion, internal-external conversion, etc. This can be | |
7455 particularly useful when XEmacs crashes, in helping to pinpoint the problem. | |
7456 */ ); | |
7457 #ifdef ERROR_CHECK_STRUCTURES | |
7458 backtrace_with_internal_sections = 1; | |
7459 #else | |
7460 backtrace_with_internal_sections = 0; | |
7461 #endif | |
7462 | |
428 | 7463 DEFVAR_LISP ("debugger", &Vdebugger /* |
7464 Function to call to invoke debugger. | |
7465 If due to frame exit, args are `exit' and the value being returned; | |
7466 this function's value will be returned instead of that. | |
7467 If due to error, args are `error' and a list of the args to `signal'. | |
7468 If due to `apply' or `funcall' entry, one arg, `lambda'. | |
7469 If due to `eval' entry, one arg, t. | |
7470 */ ); | |
7471 Vdebugger = Qnil; | |
7472 | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
7473 DEFVAR_CONST_INT ("multiple-values-limit", &Vmultiple_values_limit /* |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
7474 The exclusive upper bound on the number of multiple values. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
7475 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
7476 This applies to `values', `values-list', `multiple-value-bind' and related |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
7477 macros and special forms. |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
7478 */); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
7479 Vmultiple_values_limit = EMACS_INT_MAX > INT_MAX ? INT_MAX : EMACS_INT_MAX; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4657
diff
changeset
|
7480 |
853 | 7481 staticpro (&Vcatch_everything_tag); |
7482 Vcatch_everything_tag = make_opaque (OPAQUE_CLEAR, 0); | |
7483 | |
428 | 7484 staticpro (&Vpending_warnings); |
7485 Vpending_warnings = Qnil; | |
1204 | 7486 dump_add_root_lisp_object (&Vpending_warnings_tail); |
428 | 7487 Vpending_warnings_tail = Qnil; |
7488 | |
793 | 7489 DEFVAR_LISP ("log-warning-minimum-level", &Vlog_warning_minimum_level); |
7490 Vlog_warning_minimum_level = Qinfo; | |
7491 | |
428 | 7492 staticpro (&Vautoload_queue); |
7493 Vautoload_queue = Qnil; | |
7494 | |
7495 staticpro (&Vcondition_handlers); | |
7496 | |
853 | 7497 staticpro (&Vdeletable_permanent_display_objects); |
7498 Vdeletable_permanent_display_objects = Qnil; | |
7499 | |
7500 staticpro (&Vmodifiable_buffers); | |
7501 Vmodifiable_buffers = Qnil; | |
7502 | |
7503 inhibit_flags = 0; | |
7504 } |