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