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