comparison src/eval.c @ 380:8626e4521993 r21-2-5

Import from CVS: tag r21-2-5
author cvs
date Mon, 13 Aug 2007 11:07:10 +0200
parents cc15677e0335
children 74fd4e045ea6
comparison
equal deleted inserted replaced
379:76b7d63099ad 380:8626e4521993
18 along with XEmacs; see the file COPYING. If not, write to 18 along with XEmacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */ 20 Boston, MA 02111-1307, USA. */
21 21
22 /* Synched up with: FSF 19.30 (except for Fsignal), Mule 2.0. */ 22 /* Synched up with: FSF 19.30 (except for Fsignal), Mule 2.0. */
23
24 /* Debugging hack */
25 int always_gc;
26
27 23
28 #include <config.h> 24 #include <config.h>
29 #include "lisp.h" 25 #include "lisp.h"
30 26
31 #include "commands.h" 27 #include "commands.h"
33 #include "bytecode.h" 29 #include "bytecode.h"
34 #include "buffer.h" 30 #include "buffer.h"
35 #include "console.h" 31 #include "console.h"
36 #include "opaque.h" 32 #include "opaque.h"
37 33
34 #ifdef ERROR_CHECK_GC
35 int always_gc; /* Debugging hack */
36 #else
37 #define always_gc 0
38 #endif
39
38 struct backtrace *backtrace_list; 40 struct backtrace *backtrace_list;
39 41
40 /* Note you must always fill all of the fields in a backtrace structure 42 /* Note: you must always fill in all of the fields in a backtrace structure
41 before pushing them on the backtrace_list. The profiling code depends 43 before pushing them on the backtrace_list. The profiling code depends
42 on this. */ 44 on this. */
43 45
44 #define PUSH_BACKTRACE(bt) \ 46 #define PUSH_BACKTRACE(bt) do { \
45 do { (bt).next = backtrace_list; backtrace_list = &(bt); } while (0) 47 (bt).next = backtrace_list; \
46 48 backtrace_list = &(bt); \
47 #define POP_BACKTRACE(bt) \ 49 } while (0)
48 do { backtrace_list = (bt).next; } while (0) 50
51 #define POP_BACKTRACE(bt) do { \
52 backtrace_list = (bt).next; \
53 } while (0)
54
55 /* Macros for calling subrs with an argument list whose length is only
56 known at runtime. See EXFUN and DEFUN for similar hackery. */
57
58 #define AV_0(av)
59 #define AV_1(av) av[0]
60 #define AV_2(av) AV_1(av), av[1]
61 #define AV_3(av) AV_2(av), av[2]
62 #define AV_4(av) AV_3(av), av[3]
63 #define AV_5(av) AV_4(av), av[4]
64 #define AV_6(av) AV_5(av), av[5]
65 #define AV_7(av) AV_6(av), av[6]
66 #define AV_8(av) AV_7(av), av[7]
67
68 #define PRIMITIVE_FUNCALL_1(fn, av, ac) \
69 (((Lisp_Object (*)(EXFUN_##ac)) (fn)) (AV_##ac (av)))
70
71 /* If subrs take more than 8 arguments, more cases need to be added
72 to this switch. (But wait - don't do it - if you really need
73 a SUBR with more than 8 arguments, use max_args == MANY.
74 See the DEFUN macro in lisp.h) */
75 #define PRIMITIVE_FUNCALL(rv, fn, av, ac) do { \
76 void (*PF_fn)() = (void (*)()) (fn); \
77 Lisp_Object *PF_av = (av); \
78 switch (ac) \
79 { \
80 default: abort(); \
81 case 0: rv = PRIMITIVE_FUNCALL_1(PF_fn, PF_av, 0); break; \
82 case 1: rv = PRIMITIVE_FUNCALL_1(PF_fn, PF_av, 1); break; \
83 case 2: rv = PRIMITIVE_FUNCALL_1(PF_fn, PF_av, 2); break; \
84 case 3: rv = PRIMITIVE_FUNCALL_1(PF_fn, PF_av, 3); break; \
85 case 4: rv = PRIMITIVE_FUNCALL_1(PF_fn, PF_av, 4); break; \
86 case 5: rv = PRIMITIVE_FUNCALL_1(PF_fn, PF_av, 5); break; \
87 case 6: rv = PRIMITIVE_FUNCALL_1(PF_fn, PF_av, 6); break; \
88 case 7: rv = PRIMITIVE_FUNCALL_1(PF_fn, PF_av, 7); break; \
89 case 8: rv = PRIMITIVE_FUNCALL_1(PF_fn, PF_av, 8); break; \
90 } \
91 } while (0)
92
93 #define FUNCALL_SUBR(rv, subr, av, ac) \
94 PRIMITIVE_FUNCALL (rv, subr_function (subr), av, ac);
95
49 96
50 /* This is the list of current catches (and also condition-cases). 97 /* This is the list of current catches (and also condition-cases).
51 This is a stack: the most recent catch is at the head of the 98 This is a stack: the most recent catch is at the head of the
52 list. Catches are created by declaring a 'struct catchtag' 99 list. Catches are created by declaring a 'struct catchtag'
53 locally, filling the .TAG field in with the tag, and doing 100 locally, filling the .TAG field in with the tag, and doing
78 Lisp_Object Qinhibit_quit; 125 Lisp_Object Qinhibit_quit;
79 Lisp_Object Qrun_hooks; 126 Lisp_Object Qrun_hooks;
80 Lisp_Object Qsetq; 127 Lisp_Object Qsetq;
81 Lisp_Object Qdisplay_warning; 128 Lisp_Object Qdisplay_warning;
82 Lisp_Object Vpending_warnings, Vpending_warnings_tail; 129 Lisp_Object Vpending_warnings, Vpending_warnings_tail;
130 Lisp_Object Qif;
83 131
84 /* Records whether we want errors to occur. This will be a boolean, 132 /* Records whether we want errors to occur. This will be a boolean,
85 nil (errors OK) or t (no errors). If t, an error will cause a 133 nil (errors OK) or t (no errors). If t, an error will cause a
86 throw to Qunbound_suspended_errors_tag. 134 throw to Qunbound_suspended_errors_tag.
87 135
102 150
103 /* Non-nil means record all fset's and provide's, to be undone 151 /* Non-nil means record all fset's and provide's, to be undone
104 if the file being autoloaded is not fully loaded. 152 if the file being autoloaded is not fully loaded.
105 They are recorded by being consed onto the front of Vautoload_queue: 153 They are recorded by being consed onto the front of Vautoload_queue:
106 (FUN . ODEF) for a defun, (OFEATURES . nil) for a provide. */ 154 (FUN . ODEF) for a defun, (OFEATURES . nil) for a provide. */
107
108 Lisp_Object Vautoload_queue; 155 Lisp_Object Vautoload_queue;
109 156
110 /* Current number of specbindings allocated in specpdl. */ 157 /* Current number of specbindings allocated in specpdl. */
111 static int specpdl_size; 158 int specpdl_size;
112 159
113 /* Pointer to beginning of specpdl. */ 160 /* Pointer to beginning of specpdl. */
114 struct specbinding *specpdl; 161 struct specbinding *specpdl;
115 162
116 /* Pointer to first unused element in specpdl. */ 163 /* Pointer to first unused element in specpdl. */
117 struct specbinding *specpdl_ptr; 164 struct specbinding *specpdl_ptr;
118 165
119 /* specpdl_ptr - specpdl. Callers outside this file should use 166 /* specpdl_ptr - specpdl */
120 * specpdl_depth () function-call */ 167 int specpdl_depth_counter;
121 static int specpdl_depth_counter;
122 168
123 /* Maximum size allowed for specpdl allocation */ 169 /* Maximum size allowed for specpdl allocation */
124 int max_specpdl_size; 170 int max_specpdl_size;
125 171
126 /* Depth in Lisp evaluations and function calls. */ 172 /* Depth in Lisp evaluations and function calls. */
219 invoked in the environment that `signal' was invoked 265 invoked in the environment that `signal' was invoked
220 in. 266 in.
221 */ 267 */
222 static Lisp_Object Vcondition_handlers; 268 static Lisp_Object Vcondition_handlers;
223 269
270
271 #if 0 /* no longer used */
224 /* Used for error catching purposes by throw_or_bomb_out */ 272 /* Used for error catching purposes by throw_or_bomb_out */
225 static int throw_level; 273 static int throw_level;
226 274 #endif /* unused */
227 static Lisp_Object primitive_funcall (lisp_fn_t fn, int nargs,
228 Lisp_Object args[]);
229 275
230 276
231 /**********************************************************************/ 277 /************************************************************************/
232 /* The subr and compiled-function types */ 278 /* The subr object type */
233 /**********************************************************************/ 279 /************************************************************************/
234 280
235 static void 281 static void
236 print_subr (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag) 282 print_subr (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
237 { 283 {
238 struct Lisp_Subr *subr = XSUBR (obj); 284 Lisp_Subr *subr = XSUBR (obj);
285 CONST char *header =
286 (subr->max_args == UNEVALLED) ? "#<special-form " : "#<subr ";
287 CONST char *name = subr_name (subr);
288 CONST char *trailer = subr->prompt ? " (interactive)>" : ">";
239 289
240 if (print_readably) 290 if (print_readably)
241 error ("printing unreadable object #<subr %s>", 291 error ("printing unreadable object %s%s%s", header, name, trailer);
242 subr_name (subr)); 292
243 293 write_c_string (header, printcharfun);
244 write_c_string (((subr->max_args == UNEVALLED) 294 write_c_string (name, printcharfun);
245 ? "#<special-form " 295 write_c_string (trailer, printcharfun);
246 : "#<subr "),
247 printcharfun);
248
249 write_c_string (subr_name (subr), printcharfun);
250 write_c_string (((subr->prompt) ? " (interactive)>" : ">"),
251 printcharfun);
252 } 296 }
253 297
254 DEFINE_LRECORD_IMPLEMENTATION ("subr", subr, 298 DEFINE_LRECORD_IMPLEMENTATION ("subr", subr,
255 this_one_is_unmarkable, print_subr, 0, 0, 0, 299 this_one_is_unmarkable, print_subr, 0, 0, 0,
256 struct Lisp_Subr); 300 Lisp_Subr);
257 301
258 static Lisp_Object 302 /************************************************************************/
259 mark_compiled_function (Lisp_Object obj, void (*markobj) (Lisp_Object)) 303 /* Entering the debugger */
260 { 304 /************************************************************************/
261 struct Lisp_Compiled_Function *b = XCOMPILED_FUNCTION (obj);
262
263 ((markobj) (b->bytecodes));
264 ((markobj) (b->arglist));
265 ((markobj) (b->doc_and_interactive));
266 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
267 ((markobj) (b->annotated));
268 #endif
269 /* tail-recurse on constants */
270 return b->constants;
271 }
272
273 static int
274 compiled_function_equal (Lisp_Object o1, Lisp_Object o2, int depth)
275 {
276 struct Lisp_Compiled_Function *b1 = XCOMPILED_FUNCTION (o1);
277 struct Lisp_Compiled_Function *b2 = XCOMPILED_FUNCTION (o2);
278 return
279 (b1->flags.documentationp == b2->flags.documentationp &&
280 b1->flags.interactivep == b2->flags.interactivep &&
281 b1->flags.domainp == b2->flags.domainp && /* I18N3 */
282 internal_equal (b1->bytecodes, b2->bytecodes, depth + 1) &&
283 internal_equal (b1->constants, b2->constants, depth + 1) &&
284 internal_equal (b1->arglist, b2->arglist, depth + 1) &&
285 internal_equal (b1->doc_and_interactive,
286 b2->doc_and_interactive, depth + 1));
287 }
288
289 static unsigned long
290 compiled_function_hash (Lisp_Object obj, int depth)
291 {
292 struct Lisp_Compiled_Function *b = XCOMPILED_FUNCTION (obj);
293 return HASH3 ((b->flags.documentationp << 2) +
294 (b->flags.interactivep << 1) +
295 b->flags.domainp,
296 internal_hash (b->bytecodes, depth + 1),
297 internal_hash (b->constants, depth + 1));
298 }
299
300 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("compiled-function", compiled_function,
301 mark_compiled_function,
302 print_compiled_function, 0,
303 compiled_function_equal,
304 compiled_function_hash,
305 struct Lisp_Compiled_Function);
306
307 /**********************************************************************/
308 /* Entering the debugger */
309 /**********************************************************************/
310 305
311 /* unwind-protect used by call_debugger() to restore the value of 306 /* unwind-protect used by call_debugger() to restore the value of
312 enterring_debugger. (We cannot use specbind() because the 307 entering_debugger. (We cannot use specbind() because the
313 variable is not Lisp-accessible.) */ 308 variable is not Lisp-accessible.) */
314 309
315 static Lisp_Object 310 static Lisp_Object
316 restore_entering_debugger (Lisp_Object arg) 311 restore_entering_debugger (Lisp_Object arg)
317 { 312 {
335 { 330 {
336 return apply1 (Vdebugger, arg); 331 return apply1 (Vdebugger, arg);
337 } 332 }
338 333
339 /* Call the debugger, doing some encapsulation. We make sure we have 334 /* Call the debugger, doing some encapsulation. We make sure we have
340 some room on the eval and specpdl stacks, and bind enterring_debugger 335 some room on the eval and specpdl stacks, and bind entering_debugger
341 to 1 during this call. This is used to trap errors that may occur 336 to 1 during this call. This is used to trap errors that may occur
342 when enterring the debugger (e.g. the value of `debugger' is invalid), 337 when entering the debugger (e.g. the value of `debugger' is invalid),
343 so that the debugger will not be recursively entered if debug-on-error 338 so that the debugger will not be recursively entered if debug-on-error
344 is set. (Otherwise, XEmacs would infinitely recurse, attempting to 339 is set. (Otherwise, XEmacs would infinitely recurse, attempting to
345 enter the debugger.) enterring_debugger gets reset to 0 as soon 340 enter the debugger.) entering_debugger gets reset to 0 as soon
346 as a backtrace is displayed, so that further errors can indeed be 341 as a backtrace is displayed, so that further errors can indeed be
347 handled normally. 342 handled normally.
348 343
349 We also establish a catch for 'debugger. If the debugger function 344 We also establish a catch for 'debugger. If the debugger function
350 throws to this instead of returning a value, it means that the user 345 throws to this instead of returning a value, it means that the user
381 max_lisp_eval_depth = lisp_eval_depth + 20; 376 max_lisp_eval_depth = lisp_eval_depth + 20;
382 if (specpdl_size + 40 > max_specpdl_size) 377 if (specpdl_size + 40 > max_specpdl_size)
383 max_specpdl_size = specpdl_size + 40; 378 max_specpdl_size = specpdl_size + 40;
384 debug_on_next_call = 0; 379 debug_on_next_call = 0;
385 380
386 speccount = specpdl_depth_counter; 381 speccount = specpdl_depth();
387 record_unwind_protect (restore_entering_debugger, 382 record_unwind_protect (restore_entering_debugger,
388 (entering_debugger ? Qt : Qnil)); 383 (entering_debugger ? Qt : Qnil));
389 entering_debugger = 1; 384 entering_debugger = 1;
390 val = internal_catch (Qdebugger, call_debugger_259, arg, &threw); 385 val = internal_catch (Qdebugger, call_debugger_259, arg, &threw);
391 386
540 { 535 {
541 /* This function can GC */ 536 /* This function can GC */
542 Lisp_Object val = Qunbound; 537 Lisp_Object val = Qunbound;
543 Lisp_Object all_handlers = Vcondition_handlers; 538 Lisp_Object all_handlers = Vcondition_handlers;
544 Lisp_Object temp_data = Qnil; 539 Lisp_Object temp_data = Qnil;
545 int speccount = specpdl_depth_counter; 540 int speccount = specpdl_depth();
546 struct gcpro gcpro1, gcpro2; 541 struct gcpro gcpro1, gcpro2;
547 GCPRO2 (all_handlers, temp_data); 542 GCPRO2 (all_handlers, temp_data);
548 543
549 Vcondition_handlers = active_handlers; 544 Vcondition_handlers = active_handlers;
550 545
552 547
553 if (!entering_debugger && !*stack_trace_displayed && !signal_vars_only 548 if (!entering_debugger && !*stack_trace_displayed && !signal_vars_only
554 && wants_debugger (Vstack_trace_on_error, conditions) 549 && wants_debugger (Vstack_trace_on_error, conditions)
555 && !skip_debugger (conditions, temp_data)) 550 && !skip_debugger (conditions, temp_data))
556 { 551 {
557 specbind (Qdebug_on_error, Qnil); 552 specbind (Qdebug_on_error, Qnil);
558 specbind (Qstack_trace_on_error, Qnil); 553 specbind (Qstack_trace_on_error, Qnil);
559 specbind (Qdebug_on_signal, Qnil); 554 specbind (Qdebug_on_signal, Qnil);
560 specbind (Qstack_trace_on_signal, Qnil); 555 specbind (Qstack_trace_on_signal, Qnil);
561 556
562 internal_with_output_to_temp_buffer ("*Backtrace*", 557 internal_with_output_to_temp_buffer (build_string ("*Backtrace*"),
563 backtrace_259, 558 backtrace_259,
564 Qnil, 559 Qnil,
565 Qnil); 560 Qnil);
566 unbind_to (speccount, Qnil); 561 unbind_to (speccount, Qnil);
567 *stack_trace_displayed = 1; 562 *stack_trace_displayed = 1;
572 ? debug_on_quit 567 ? debug_on_quit
573 : wants_debugger (Vdebug_on_error, conditions)) 568 : wants_debugger (Vdebug_on_error, conditions))
574 && !skip_debugger (conditions, temp_data)) 569 && !skip_debugger (conditions, temp_data))
575 { 570 {
576 debug_on_quit &= ~2; /* reset critical bit */ 571 debug_on_quit &= ~2; /* reset critical bit */
577 specbind (Qdebug_on_error, Qnil); 572 specbind (Qdebug_on_error, Qnil);
578 specbind (Qstack_trace_on_error, Qnil); 573 specbind (Qstack_trace_on_error, Qnil);
579 specbind (Qdebug_on_signal, Qnil); 574 specbind (Qdebug_on_signal, Qnil);
580 specbind (Qstack_trace_on_signal, Qnil); 575 specbind (Qstack_trace_on_signal, Qnil);
581 576
582 val = call_debugger (list2 (Qerror, (Fcons (sig, data)))); 577 val = call_debugger (list2 (Qerror, (Fcons (sig, data))));
583 *debugger_entered = 1; 578 *debugger_entered = 1;
584 } 579 }
585 580
586 if (!entering_debugger && !*stack_trace_displayed 581 if (!entering_debugger && !*stack_trace_displayed
587 && wants_debugger (Vstack_trace_on_signal, conditions)) 582 && wants_debugger (Vstack_trace_on_signal, conditions))
588 { 583 {
589 specbind (Qdebug_on_error, Qnil); 584 specbind (Qdebug_on_error, Qnil);
590 specbind (Qstack_trace_on_error, Qnil); 585 specbind (Qstack_trace_on_error, Qnil);
591 specbind (Qdebug_on_signal, Qnil); 586 specbind (Qdebug_on_signal, Qnil);
592 specbind (Qstack_trace_on_signal, Qnil); 587 specbind (Qstack_trace_on_signal, Qnil);
593 588
594 internal_with_output_to_temp_buffer ("*Backtrace*", 589 internal_with_output_to_temp_buffer (build_string ("*Backtrace*"),
595 backtrace_259, 590 backtrace_259,
596 Qnil, 591 Qnil,
597 Qnil); 592 Qnil);
598 unbind_to (speccount, Qnil); 593 unbind_to (speccount, Qnil);
599 *stack_trace_displayed = 1; 594 *stack_trace_displayed = 1;
603 && (EQ (sig, Qquit) 598 && (EQ (sig, Qquit)
604 ? debug_on_quit 599 ? debug_on_quit
605 : wants_debugger (Vdebug_on_signal, conditions))) 600 : wants_debugger (Vdebug_on_signal, conditions)))
606 { 601 {
607 debug_on_quit &= ~2; /* reset critical bit */ 602 debug_on_quit &= ~2; /* reset critical bit */
608 specbind (Qdebug_on_error, Qnil); 603 specbind (Qdebug_on_error, Qnil);
609 specbind (Qstack_trace_on_error, Qnil); 604 specbind (Qstack_trace_on_error, Qnil);
610 specbind (Qdebug_on_signal, Qnil); 605 specbind (Qdebug_on_signal, Qnil);
611 specbind (Qstack_trace_on_signal, Qnil); 606 specbind (Qstack_trace_on_signal, Qnil);
612 607
613 val = call_debugger (list2 (Qerror, (Fcons (sig, data)))); 608 val = call_debugger (list2 (Qerror, (Fcons (sig, data))));
614 *debugger_entered = 1; 609 *debugger_entered = 1;
615 } 610 }
618 Vcondition_handlers = all_handlers; 613 Vcondition_handlers = all_handlers;
619 return unbind_to (speccount, val); 614 return unbind_to (speccount, val);
620 } 615 }
621 616
622 617
623 /**********************************************************************/ 618 /************************************************************************/
624 /* The basic special forms */ 619 /* The basic special forms */
625 /**********************************************************************/ 620 /************************************************************************/
626 621
627 /* NOTE!!! Every function that can call EVAL must protect its args 622 /* Except for Fprogn(), the basic special forms below are only called
628 and temporaries from garbage collection while it needs them. 623 from interpreted code. The byte compiler turns them into bytecodes. */
629 The definition of `For' shows what you have to do. */
630 624
631 DEFUN ("or", For, 0, UNEVALLED, 0, /* 625 DEFUN ("or", For, 0, UNEVALLED, 0, /*
632 Eval args until one of them yields non-nil, then return that value. 626 Eval args until one of them yields non-nil, then return that value.
633 The remaining args are not evalled at all. 627 The remaining args are not evalled at all.
634 If all args return nil, return nil. 628 If all args return nil, return nil.
635 */ 629 */
636 (args)) 630 (args))
637 { 631 {
638 /* This function can GC */ 632 /* This function can GC */
639 REGISTER Lisp_Object tail; 633 REGISTER Lisp_Object arg, val;
640 struct gcpro gcpro1; 634
641 635 LIST_LOOP_2 (arg, args)
642 GCPRO1 (args); 636 {
643 637 if (!NILP (val = Feval (arg)))
644 LIST_LOOP (tail, args) 638 return val;
645 { 639 }
646 Lisp_Object val = Feval (XCAR (tail)); 640
647 if (!NILP (val))
648 {
649 UNGCPRO;
650 return val;
651 }
652 }
653
654 UNGCPRO;
655 return Qnil; 641 return Qnil;
656 } 642 }
657 643
658 DEFUN ("and", Fand, 0, UNEVALLED, 0, /* 644 DEFUN ("and", Fand, 0, UNEVALLED, 0, /*
659 Eval args until one of them yields nil, then return nil. 645 Eval args until one of them yields nil, then return nil.
661 If no arg yields nil, return the last arg's value. 647 If no arg yields nil, return the last arg's value.
662 */ 648 */
663 (args)) 649 (args))
664 { 650 {
665 /* This function can GC */ 651 /* This function can GC */
666 REGISTER Lisp_Object tail, val = Qt; 652 REGISTER Lisp_Object arg, val = Qt;
667 struct gcpro gcpro1; 653
668 654 LIST_LOOP_2 (arg, args)
669 GCPRO1 (args); 655 {
670 656 if (NILP (val = Feval (arg)))
671 LIST_LOOP (tail, args) 657 return val;
672 { 658 }
673 val = Feval (XCAR (tail)); 659
674 if (NILP (val))
675 break;
676 }
677
678 UNGCPRO;
679 return val; 660 return val;
680 } 661 }
681 662
682 DEFUN ("if", Fif, 2, UNEVALLED, 0, /* 663 DEFUN ("if", Fif, 2, UNEVALLED, 0, /*
683 \(if COND THEN ELSE...): if COND yields non-nil, do THEN, else do ELSE... 664 \(if COND THEN ELSE...): if COND yields non-nil, do THEN, else do ELSE...
686 If COND yields nil, and there are no ELSE's, the value is nil. 667 If COND yields nil, and there are no ELSE's, the value is nil.
687 */ 668 */
688 (args)) 669 (args))
689 { 670 {
690 /* This function can GC */ 671 /* This function can GC */
691 Lisp_Object val; 672 Lisp_Object condition = XCAR (args);
692 struct gcpro gcpro1; 673 Lisp_Object then_form = XCAR (XCDR (args));
693 674 Lisp_Object else_forms = XCDR (XCDR (args));
694 GCPRO1 (args); 675
695 676 if (!NILP (Feval (condition)))
696 if (!NILP (Feval (XCAR (args)))) 677 return Feval (then_form);
697 val = Feval (XCAR (XCDR ((args))));
698 else 678 else
699 val = Fprogn (XCDR (XCDR (args))); 679 return Fprogn (else_forms);
700 680 }
701 UNGCPRO; 681
702 return val; 682 /* Macros `when' and `unless' are trivially defined in Lisp,
683 but it helps for bootstrapping to have them ALWAYS defined. */
684
685 DEFUN ("when", Fwhen, 1, MANY, 0, /*
686 \(when COND BODY...): if COND yields non-nil, do BODY, else return nil.
687 BODY can be zero or more expressions. If BODY is nil, return nil.
688 */
689 (int nargs, Lisp_Object *args))
690 {
691 Lisp_Object cond = args[0];
692 Lisp_Object body;
693
694 switch (nargs)
695 {
696 case 1: body = Qnil; break;
697 case 2: body = args[1]; break;
698 default: body = Fcons (Qprogn, Flist (nargs-1, args+1)); break;
699 }
700
701 return list3 (Qif, cond, body);
702 }
703
704 DEFUN ("unless", Funless, 1, MANY, 0, /*
705 \(unless COND BODY...): if COND yields nil, do BODY, else return nil.
706 BODY can be zero or more expressions. If BODY is nil, return nil.
707 */
708 (int nargs, Lisp_Object *args))
709 {
710 Lisp_Object cond = args[0];
711 Lisp_Object body = Flist (nargs-1, args+1);
712 return Fcons (Qif, Fcons (cond, Fcons (Qnil, body)));
703 } 713 }
704 714
705 DEFUN ("cond", Fcond, 0, UNEVALLED, 0, /* 715 DEFUN ("cond", Fcond, 0, UNEVALLED, 0, /*
706 (cond CLAUSES...): try each clause until one succeeds. 716 (cond CLAUSES...): try each clause until one succeeds.
707 Each clause looks like (CONDITION BODY...). CONDITION is evaluated 717 Each clause looks like (CONDITION BODY...). CONDITION is evaluated
713 CONDITION's value if non-nil is returned from the cond-form. 723 CONDITION's value if non-nil is returned from the cond-form.
714 */ 724 */
715 (args)) 725 (args))
716 { 726 {
717 /* This function can GC */ 727 /* This function can GC */
718 REGISTER Lisp_Object tail; 728 REGISTER Lisp_Object val, clause;
719 struct gcpro gcpro1; 729
720 730 LIST_LOOP_2 (clause, args)
721 GCPRO1 (args); 731 {
722
723 LIST_LOOP (tail, args)
724 {
725 Lisp_Object val;
726 Lisp_Object clause = XCAR (tail);
727 CHECK_CONS (clause); 732 CHECK_CONS (clause);
728 val = Feval (XCAR (clause)); 733 if (!NILP (val = Feval (XCAR (clause))))
729 if (!NILP (val))
730 { 734 {
731 Lisp_Object clause_tail = XCDR (clause); 735 if (!NILP (clause = XCDR (clause)))
732 if (!NILP (clause_tail))
733 { 736 {
734 CHECK_TRUE_LIST (clause_tail); 737 CHECK_TRUE_LIST (clause);
735 val = Fprogn (clause_tail); 738 val = Fprogn (clause);
736 } 739 }
737 UNGCPRO;
738 return val; 740 return val;
739 } 741 }
740 } 742 }
741 UNGCPRO;
742 743
743 return Qnil; 744 return Qnil;
744 } 745 }
745 746
746 DEFUN ("progn", Fprogn, 0, UNEVALLED, 0, /* 747 DEFUN ("progn", Fprogn, 0, UNEVALLED, 0, /*
747 \(progn BODY...): eval BODY forms sequentially and return value of last one. 748 \(progn BODY...): eval BODY forms sequentially and return value of last one.
748 */ 749 */
749 (args)) 750 (args))
750 { 751 {
751 /* This function can GC */ 752 /* This function can GC */
752 REGISTER Lisp_Object tail, val = Qnil; 753 /* Caller must provide a true list in ARGS */
754 REGISTER Lisp_Object form, val = Qnil;
753 struct gcpro gcpro1; 755 struct gcpro gcpro1;
754 756
755 GCPRO1 (args); 757 GCPRO1 (args);
756 758
757 LIST_LOOP (tail, args) 759 {
758 val = Feval (XCAR (tail)); 760 LIST_LOOP_2 (form, args)
761 val = Feval (form);
762 }
759 763
760 UNGCPRO; 764 UNGCPRO;
761 return val; 765 return val;
762 } 766 }
763 767
768 /* Fprog1() is the canonical example of a function that must GCPRO a
769 Lisp_Object across calls to Feval(). */
770
764 DEFUN ("prog1", Fprog1, 1, UNEVALLED, 0, /* 771 DEFUN ("prog1", Fprog1, 1, UNEVALLED, 0, /*
765 \(prog1 FIRST BODY...): eval FIRST and BODY sequentially; value from FIRST. 772 Similar to `progn', but the value of the first form is returned.
766 The value of FIRST is saved during the evaluation of the remaining args, 773 \(prog1 FIRST BODY...): All the arguments are evaluated sequentially.
774 The value of FIRST is saved during evaluation of the remaining args,
767 whose values are discarded. 775 whose values are discarded.
768 */ 776 */
769 (args)) 777 (args))
770 { 778 {
771 /* This function can GC */ 779 /* This function can GC */
772 REGISTER Lisp_Object tail = args; 780 REGISTER Lisp_Object val, form;
773 Lisp_Object val = Qnil; 781 struct gcpro gcpro1;
774 struct gcpro gcpro1, gcpro2; 782
775 783 val = Feval (XCAR (args));
776 GCPRO2 (args, val); 784
777 785 GCPRO1 (val);
778 val = Feval (XCAR (tail)); 786
779 787 {
780 LIST_LOOP (tail, XCDR (tail)) 788 LIST_LOOP_2 (form, XCDR (args))
781 Feval (XCAR (tail)); 789 Feval (form);
790 }
782 791
783 UNGCPRO; 792 UNGCPRO;
784 return val; 793 return val;
785 } 794 }
786 795
787 DEFUN ("prog2", Fprog2, 2, UNEVALLED, 0, /* 796 DEFUN ("prog2", Fprog2, 2, UNEVALLED, 0, /*
788 \(prog2 X Y BODY...): eval X, Y and BODY sequentially; value from Y. 797 Similar to `progn', but the value of the second form is returned.
789 The value of Y is saved during the evaluation of the remaining args, 798 \(prog2 FIRST SECOND BODY...): All the arguments are evaluated sequentially.
799 The value of SECOND is saved during evaluation of the remaining args,
790 whose values are discarded. 800 whose values are discarded.
791 */ 801 */
792 (args)) 802 (args))
793 { 803 {
794 /* This function can GC */ 804 /* This function can GC */
795 REGISTER Lisp_Object tail = args; 805 REGISTER Lisp_Object val, form, tail;
796 Lisp_Object val = Qnil; 806 struct gcpro gcpro1;
797 struct gcpro gcpro1, gcpro2; 807
798 808 Feval (XCAR (args));
799 GCPRO2 (args, val); 809 args = XCDR (args);
800 810 val = Feval (XCAR (args));
801 Feval (XCAR (tail)); 811 args = XCDR (args);
802 tail = XCDR (tail); 812
803 val = Feval (XCAR (tail)); 813 GCPRO1 (val);
804 814
805 LIST_LOOP (tail, XCDR (tail)) 815 LIST_LOOP_3 (form, args, tail)
806 Feval (XCAR (tail)); 816 Feval (form);
807 817
808 UNGCPRO; 818 UNGCPRO;
809 return val; 819 return val;
810 } 820 }
811 821
817 Each VALUEFORM can refer to the symbols already bound by this VARLIST. 827 Each VALUEFORM can refer to the symbols already bound by this VARLIST.
818 */ 828 */
819 (args)) 829 (args))
820 { 830 {
821 /* This function can GC */ 831 /* This function can GC */
832 Lisp_Object var, tail;
822 Lisp_Object varlist = XCAR (args); 833 Lisp_Object varlist = XCAR (args);
823 Lisp_Object tail; 834 Lisp_Object body = XCDR (args);
824 int speccount = specpdl_depth_counter; 835 int speccount = specpdl_depth();
825 struct gcpro gcpro1; 836
826 837 EXTERNAL_LIST_LOOP_3 (var, varlist, tail)
827 GCPRO1 (args); 838 {
828 839 Lisp_Object symbol, value, tem;
829 EXTERNAL_LIST_LOOP (tail, varlist) 840 if (SYMBOLP (var))
830 { 841 symbol = var, value = Qnil;
831 Lisp_Object elt = XCAR (tail);
832 QUIT;
833 if (SYMBOLP (elt))
834 specbind (elt, Qnil);
835 else 842 else
836 { 843 {
837 Lisp_Object sym, form; 844 CHECK_CONS (var);
838 CHECK_CONS (elt); 845 symbol = XCAR (var);
839 sym = XCAR (elt); 846 tem = XCDR (var);
840 elt = XCDR (elt); 847 if (NILP (tem))
841 if (NILP (elt)) 848 value = Qnil;
842 form = Qnil;
843 else 849 else
844 { 850 {
845 CHECK_CONS (elt); 851 CHECK_CONS (tem);
846 form = XCAR (elt); 852 value = Feval (XCAR (tem));
847 elt = XCDR (elt); 853 if (!NILP (XCDR (tem)))
848 if (!NILP (elt))
849 signal_simple_error 854 signal_simple_error
850 ("`let' bindings can have only one value-form", 855 ("`let' bindings can have only one value-form", var);
851 XCAR (tail));
852 } 856 }
853 specbind (sym, Feval (form));
854 } 857 }
855 } 858 specbind (symbol, value);
856 UNGCPRO; 859 }
857 return unbind_to (speccount, Fprogn (XCDR (args))); 860 return unbind_to (speccount, Fprogn (body));
858 } 861 }
859 862
860 DEFUN ("let", Flet, 1, UNEVALLED, 0, /* 863 DEFUN ("let", Flet, 1, UNEVALLED, 0, /*
861 \(let VARLIST BODY...): bind variables according to VARLIST then eval BODY. 864 \(let VARLIST BODY...): bind variables according to VARLIST then eval BODY.
862 The value of the last form in BODY is returned. 865 The value of the last form in BODY is returned.
865 All the VALUEFORMs are evalled before any symbols are bound. 868 All the VALUEFORMs are evalled before any symbols are bound.
866 */ 869 */
867 (args)) 870 (args))
868 { 871 {
869 /* This function can GC */ 872 /* This function can GC */
873 Lisp_Object var, tail;
870 Lisp_Object varlist = XCAR (args); 874 Lisp_Object varlist = XCAR (args);
871 REGISTER Lisp_Object tail; 875 Lisp_Object body = XCDR (args);
876 int speccount = specpdl_depth();
872 Lisp_Object *temps; 877 Lisp_Object *temps;
873 int speccount = specpdl_depth_counter; 878 int idx;
874 REGISTER int argnum = 0; 879 struct gcpro gcpro1;
875 struct gcpro gcpro1, gcpro2;
876 880
877 /* Make space to hold the values to give the bound variables. */ 881 /* Make space to hold the values to give the bound variables. */
878 { 882 {
879 int varcount = 0; 883 int varcount;
880 EXTERNAL_LIST_LOOP (tail, varlist) 884 GET_EXTERNAL_LIST_LENGTH (varlist, varcount);
881 varcount++;
882 temps = alloca_array (Lisp_Object, varcount); 885 temps = alloca_array (Lisp_Object, varcount);
883 } 886 }
884 887
885 /* Compute the values and store them in `temps' */ 888 /* Compute the values and store them in `temps' */
886 889 GCPRO1 (*temps);
887 GCPRO2 (args, *temps); 890 gcpro1.nvars = 0;
888 gcpro2.nvars = 0; 891
889 892 idx = 0;
890 LIST_LOOP (tail, varlist) 893 LIST_LOOP_3 (var, varlist, tail)
891 { 894 {
892 Lisp_Object elt = XCAR (tail); 895 Lisp_Object *value = &temps[idx++];
893 QUIT; 896 if (SYMBOLP (var))
894 if (SYMBOLP (elt)) 897 *value = Qnil;
895 temps[argnum++] = Qnil;
896 else 898 else
897 { 899 {
898 CHECK_CONS (elt); 900 Lisp_Object tem;
899 elt = XCDR (elt); 901 CHECK_CONS (var);
900 if (NILP (elt)) 902 tem = XCDR (var);
901 temps[argnum++] = Qnil; 903 if (NILP (tem))
904 *value = Qnil;
902 else 905 else
903 { 906 {
904 CHECK_CONS (elt); 907 CHECK_CONS (tem);
905 temps[argnum++] = Feval (XCAR (elt)); 908 *value = Feval (XCAR (tem));
906 gcpro2.nvars = argnum; 909 gcpro1.nvars = idx;
907 910
908 if (!NILP (XCDR (elt))) 911 if (!NILP (XCDR (tem)))
909 signal_simple_error 912 signal_simple_error
910 ("`let' bindings can have only one value-form", 913 ("`let' bindings can have only one value-form", var);
911 XCAR (tail));
912 } 914 }
913 } 915 }
914 } 916 }
917
918 idx = 0;
919 LIST_LOOP_3 (var, varlist, tail)
920 {
921 specbind (SYMBOLP (var) ? var : XCAR (var), temps[idx++]);
922 }
923
915 UNGCPRO; 924 UNGCPRO;
916 925
917 argnum = 0; 926 return unbind_to (speccount, Fprogn (body));
918 LIST_LOOP (tail, varlist)
919 {
920 Lisp_Object elt = XCAR (tail);
921 specbind (SYMBOLP (elt) ? elt : XCAR (elt), temps[argnum++]);
922 }
923
924 return unbind_to (speccount, Fprogn (XCDR (args)));
925 } 927 }
926 928
927 DEFUN ("while", Fwhile, 1, UNEVALLED, 0, /* 929 DEFUN ("while", Fwhile, 1, UNEVALLED, 0, /*
928 \(while TEST BODY...): if TEST yields non-nil, eval BODY... and repeat. 930 \(while TEST BODY...): if TEST yields non-nil, eval BODY... and repeat.
929 The order of execution is thus TEST, BODY, TEST, BODY and so on 931 The order of execution is thus TEST, BODY, TEST, BODY and so on
930 until TEST returns nil. 932 until TEST returns nil.
931 */ 933 */
932 (args)) 934 (args))
933 { 935 {
934 /* This function can GC */ 936 /* This function can GC */
935 Lisp_Object tem;
936 Lisp_Object test = XCAR (args); 937 Lisp_Object test = XCAR (args);
937 Lisp_Object body = XCDR (args); 938 Lisp_Object body = XCDR (args);
938 struct gcpro gcpro1, gcpro2; 939
939 940 while (!NILP (Feval (test)))
940 GCPRO2 (test, body);
941
942 while (tem = Feval (test), !NILP (tem))
943 { 941 {
944 QUIT; 942 QUIT;
945 Fprogn (body); 943 Fprogn (body);
946 } 944 }
947 945
948 UNGCPRO;
949 return Qnil; 946 return Qnil;
950 } 947 }
951 948
952 DEFUN ("setq", Fsetq, 0, UNEVALLED, 0, /* 949 DEFUN ("setq", Fsetq, 0, UNEVALLED, 0, /*
953 \(setq SYM VAL SYM VAL ...): set each SYM to the value of its VAL. 950 \(setq SYM VAL SYM VAL ...): set each SYM to the value of its VAL.
959 The return value of the `setq' form is the value of the last VAL. 956 The return value of the `setq' form is the value of the last VAL.
960 */ 957 */
961 (args)) 958 (args))
962 { 959 {
963 /* This function can GC */ 960 /* This function can GC */
961 Lisp_Object symbol, tail, val = Qnil;
962 int nargs;
964 struct gcpro gcpro1; 963 struct gcpro gcpro1;
965 Lisp_Object val = Qnil; 964
966 965 GET_LIST_LENGTH (args, nargs);
967 GCPRO1 (args); 966
968 967 if (nargs & 1) /* Odd number of arguments? */
969 { 968 Fsignal (Qwrong_number_of_arguments, list2 (Qsetq, make_int (nargs)));
970 REGISTER int i = 0; 969
971 Lisp_Object args2; 970 GCPRO1 (val);
972 for (args2 = args; !NILP (args2); args2 = XCDR (args2)) 971
973 { 972 PROPERTY_LIST_LOOP (tail, symbol, val, args)
974 i++; 973 {
975 /* 974 val = Feval (val);
976 * uncomment the QUIT if there is some way a circular 975 Fset (symbol, val);
977 * arglist can get in here. I think Feval or Fapply would
978 * spin first and the list would never get here.
979 */
980 /* QUIT; */
981 }
982 if (i & 1) /* Odd number of arguments? */
983 Fsignal (Qwrong_number_of_arguments, list2 (Qsetq, make_int(i)));
984 }
985
986 while (!NILP (args))
987 {
988 Lisp_Object sym = XCAR (args);
989 val = Feval (XCAR (XCDR (args)));
990 Fset (sym, val);
991 args = XCDR (XCDR (args));
992 } 976 }
993 977
994 UNGCPRO; 978 UNGCPRO;
995 return val; 979 return val;
996 } 980 }
1012 { 996 {
1013 return XCAR (args); 997 return XCAR (args);
1014 } 998 }
1015 999
1016 1000
1017 /**********************************************************************/ 1001 /************************************************************************/
1018 /* Defining functions/variables */ 1002 /* Defining functions/variables */
1019 /**********************************************************************/ 1003 /************************************************************************/
1004 static Lisp_Object
1005 define_function (Lisp_Object name, Lisp_Object defn)
1006 {
1007 if (purify_flag)
1008 defn = Fpurecopy (defn);
1009 Ffset (name, defn);
1010 LOADHIST_ATTACH (name);
1011 return name;
1012 }
1020 1013
1021 DEFUN ("defun", Fdefun, 2, UNEVALLED, 0, /* 1014 DEFUN ("defun", Fdefun, 2, UNEVALLED, 0, /*
1022 \(defun NAME ARGLIST [DOCSTRING] BODY...): define NAME as a function. 1015 \(defun NAME ARGLIST [DOCSTRING] BODY...): define NAME as a function.
1023 The definition is (lambda ARGLIST [DOCSTRING] BODY...). 1016 The definition is (lambda ARGLIST [DOCSTRING] BODY...).
1024 See also the function `interactive'. 1017 See also the function `interactive'.
1025 */ 1018 */
1026 (args)) 1019 (args))
1027 { 1020 {
1028 /* This function can GC */ 1021 /* This function can GC */
1029 Lisp_Object fn_name = XCAR (args); 1022 return define_function (XCAR (args),
1030 Lisp_Object defn = Fcons (Qlambda, XCDR (args)); 1023 Fcons (Qlambda, XCDR (args)));
1031
1032 if (purify_flag)
1033 defn = Fpurecopy (defn);
1034 Ffset (fn_name, defn);
1035 LOADHIST_ATTACH (fn_name);
1036 return fn_name;
1037 } 1024 }
1038 1025
1039 DEFUN ("defmacro", Fdefmacro, 2, UNEVALLED, 0, /* 1026 DEFUN ("defmacro", Fdefmacro, 2, UNEVALLED, 0, /*
1040 \(defmacro NAME ARGLIST [DOCSTRING] BODY...): define NAME as a macro. 1027 \(defmacro NAME ARGLIST [DOCSTRING] BODY...): define NAME as a macro.
1041 The definition is (macro lambda ARGLIST [DOCSTRING] BODY...). 1028 The definition is (macro lambda ARGLIST [DOCSTRING] BODY...).
1045 and the result should be a form to be evaluated instead of the original. 1032 and the result should be a form to be evaluated instead of the original.
1046 */ 1033 */
1047 (args)) 1034 (args))
1048 { 1035 {
1049 /* This function can GC */ 1036 /* This function can GC */
1050 Lisp_Object fn_name = XCAR (args); 1037 return define_function (XCAR (args),
1051 Lisp_Object defn = Fcons (Qmacro, Fcons (Qlambda, XCDR (args))); 1038 Fcons (Qmacro, Fcons (Qlambda, XCDR (args))));
1052
1053 if (purify_flag)
1054 defn = Fpurecopy (defn);
1055 Ffset (fn_name, defn);
1056 LOADHIST_ATTACH (fn_name);
1057 return fn_name;
1058 } 1039 }
1059 1040
1060 DEFUN ("defvar", Fdefvar, 1, UNEVALLED, 0, /* 1041 DEFUN ("defvar", Fdefvar, 1, UNEVALLED, 0, /*
1061 \(defvar SYMBOL INITVALUE DOCSTRING): define SYMBOL as a variable. 1042 \(defvar SYMBOL INITVALUE DOCSTRING): define SYMBOL as a variable.
1062 You are not required to define a variable in order to use it, 1043 You are not required to define a variable in order to use it,
1084 if (!NILP (args = XCDR (args))) 1065 if (!NILP (args = XCDR (args)))
1085 { 1066 {
1086 Lisp_Object val = XCAR (args); 1067 Lisp_Object val = XCAR (args);
1087 1068
1088 if (NILP (Fdefault_boundp (sym))) 1069 if (NILP (Fdefault_boundp (sym)))
1089 Fset_default (sym, Feval (val)); 1070 {
1071 struct gcpro gcpro1;
1072 GCPRO1 (val);
1073 val = Feval (val);
1074 Fset_default (sym, val);
1075 UNGCPRO;
1076 }
1090 1077
1091 if (!NILP (args = XCDR (args))) 1078 if (!NILP (args = XCDR (args)))
1092 { 1079 {
1093 Lisp_Object doc = XCAR (args); 1080 Lisp_Object doc = XCAR (args);
1094 #if 0 /* FSFmacs */ 1081 #if 0 /* FSFmacs */
1132 */ 1119 */
1133 (args)) 1120 (args))
1134 { 1121 {
1135 /* This function can GC */ 1122 /* This function can GC */
1136 Lisp_Object sym = XCAR (args); 1123 Lisp_Object sym = XCAR (args);
1137 Lisp_Object val = XCAR (args = XCDR (args)); 1124 Lisp_Object val = Feval (XCAR (args = XCDR (args)));
1138 1125 struct gcpro gcpro1;
1139 Fset_default (sym, Feval (val)); 1126
1127 GCPRO1 (val);
1128
1129 Fset_default (sym, val);
1130
1131 UNGCPRO;
1140 1132
1141 if (!NILP (args = XCDR (args))) 1133 if (!NILP (args = XCDR (args)))
1142 { 1134 {
1143 Lisp_Object doc = XCAR (args); 1135 Lisp_Object doc = XCAR (args);
1144 #if 0 /* FSFmacs */ 1136 #if 0 /* FSFmacs */
1168 Determined by whether the first character of the documentation 1160 Determined by whether the first character of the documentation
1169 for the variable is `*'. 1161 for the variable is `*'.
1170 */ 1162 */
1171 (variable)) 1163 (variable))
1172 { 1164 {
1173 Lisp_Object documentation; 1165 Lisp_Object documentation = Fget (variable, Qvariable_documentation, Qnil);
1174 1166
1175 documentation = Fget (variable, Qvariable_documentation, Qnil); 1167 return
1176 if (INTP (documentation) && XINT (documentation) < 0) 1168 ((INTP (documentation) && XINT (documentation) < 0) ||
1177 return Qt; 1169
1178 if ((STRINGP (documentation)) && 1170 ((STRINGP (documentation)) &&
1179 (string_byte (XSTRING (documentation), 0) == '*')) 1171 (string_byte (XSTRING (documentation), 0) == '*')) ||
1180 return Qt; 1172
1181 /* If it is (STRING . INTEGER), a negative integer means a user variable. */ 1173 /* If (STRING . INTEGER), a negative integer means a user variable. */
1182 if (CONSP (documentation) 1174 (CONSP (documentation)
1183 && STRINGP (XCAR (documentation)) 1175 && STRINGP (XCAR (documentation))
1184 && INTP (XCDR (documentation)) 1176 && INTP (XCDR (documentation))
1185 && XINT (XCDR (documentation)) < 0) 1177 && XINT (XCDR (documentation)) < 0)) ?
1186 return Qt; 1178 Qt : Qnil;
1187 return Qnil;
1188 } 1179 }
1189 1180
1190 DEFUN ("macroexpand-internal", Fmacroexpand_internal, 1, 2, 0, /* 1181 DEFUN ("macroexpand-internal", Fmacroexpand_internal, 1, 2, 0, /*
1191 Return result of expanding macros at top level of FORM. 1182 Return result of expanding macros at top level of FORM.
1192 If FORM is not a macro call, it is returned unchanged. 1183 If FORM is not a macro call, it is returned unchanged.
1263 } 1254 }
1264 return form; 1255 return form;
1265 } 1256 }
1266 1257
1267 1258
1268 /**********************************************************************/ 1259 /************************************************************************/
1269 /* Non-local exits */ 1260 /* Non-local exits */
1270 /**********************************************************************/ 1261 /************************************************************************/
1271 1262
1272 DEFUN ("catch", Fcatch, 1, UNEVALLED, 0, /* 1263 DEFUN ("catch", Fcatch, 1, UNEVALLED, 0, /*
1273 \(catch TAG BODY...): eval BODY allowing nonlocal exits using `throw'. 1264 \(catch TAG BODY...): eval BODY allowing nonlocal exits using `throw'.
1274 TAG is evalled to get the tag to use. Then the BODY is executed. 1265 TAG is evalled to get the tag to use. Then the BODY is executed.
1275 Within BODY, (throw TAG) with same tag exits BODY and exits this `catch'. 1266 Within BODY, (throw TAG) with same tag exits BODY and exits this `catch'.
1277 If a throw happens, it specifies the value to return from `catch'. 1268 If a throw happens, it specifies the value to return from `catch'.
1278 */ 1269 */
1279 (args)) 1270 (args))
1280 { 1271 {
1281 /* This function can GC */ 1272 /* This function can GC */
1282 Lisp_Object tag; 1273 Lisp_Object tag = Feval (XCAR (args));
1283 struct gcpro gcpro1; 1274 Lisp_Object body = XCDR (args);
1284 1275 return internal_catch (tag, Fprogn, body, 0);
1285 GCPRO1 (args);
1286 tag = Feval (XCAR (args));
1287 UNGCPRO;
1288 return internal_catch (tag, Fprogn, XCDR (args), 0);
1289 } 1276 }
1290 1277
1291 /* Set up a catch, then call C function FUNC on argument ARG. 1278 /* Set up a catch, then call C function FUNC on argument ARG.
1292 FUNC should return a Lisp_Object. 1279 FUNC should return a Lisp_Object.
1293 This is how catches are done from within C code. */ 1280 This is how catches are done from within C code. */
1309 #if 0 /* FSFmacs */ 1296 #if 0 /* FSFmacs */
1310 /* #### */ 1297 /* #### */
1311 c.handlerlist = handlerlist; 1298 c.handlerlist = handlerlist;
1312 #endif 1299 #endif
1313 c.lisp_eval_depth = lisp_eval_depth; 1300 c.lisp_eval_depth = lisp_eval_depth;
1314 c.pdlcount = specpdl_depth_counter; 1301 c.pdlcount = specpdl_depth();
1315 #if 0 /* FSFmacs */ 1302 #if 0 /* FSFmacs */
1316 c.poll_suppress_count = async_timer_suppress_count; 1303 c.poll_suppress_count = async_timer_suppress_count;
1317 #endif 1304 #endif
1318 c.gcpro = gcprolist; 1305 c.gcpro = gcprolist;
1319 catchlist = &c; 1306 catchlist = &c;
1394 1381
1395 gcprolist = c->gcpro; 1382 gcprolist = c->gcpro;
1396 backtrace_list = c->backlist; 1383 backtrace_list = c->backlist;
1397 lisp_eval_depth = c->lisp_eval_depth; 1384 lisp_eval_depth = c->lisp_eval_depth;
1398 1385
1386 #if 0 /* no longer used */
1399 throw_level = 0; 1387 throw_level = 0;
1388 #endif
1400 LONGJMP (c->jmp, 1); 1389 LONGJMP (c->jmp, 1);
1401 } 1390 }
1402 1391
1403 static DOESNT_RETURN 1392 static DOESNT_RETURN
1404 throw_or_bomb_out (Lisp_Object tag, Lisp_Object val, int bomb_out_p, 1393 throw_or_bomb_out (Lisp_Object tag, Lisp_Object val, int bomb_out_p,
1488 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway. 1477 If BODYFORM exits nonlocally, the UNWINDFORMS are executed anyway.
1489 */ 1478 */
1490 (args)) 1479 (args))
1491 { 1480 {
1492 /* This function can GC */ 1481 /* This function can GC */
1493 Lisp_Object val; 1482 int speccount = specpdl_depth();
1494 int speccount = specpdl_depth_counter;
1495 1483
1496 record_unwind_protect (Fprogn, XCDR (args)); 1484 record_unwind_protect (Fprogn, XCDR (args));
1497 val = Feval (XCAR (args)); 1485 return unbind_to (speccount, Feval (XCAR (args)));
1498 return unbind_to (speccount, val);
1499 } 1486 }
1500 1487
1501 1488
1502 /**********************************************************************/ 1489 /************************************************************************/
1503 /* Signalling and trapping errors */ 1490 /* Signalling and trapping errors */
1504 /**********************************************************************/ 1491 /************************************************************************/
1505 1492
1506 static Lisp_Object 1493 static Lisp_Object
1507 condition_bind_unwind (Lisp_Object loser) 1494 condition_bind_unwind (Lisp_Object loser)
1508 { 1495 {
1509 struct Lisp_Cons *victim; 1496 struct Lisp_Cons *victim;
1597 Lisp_Object (*bfun) (Lisp_Object barg), 1584 Lisp_Object (*bfun) (Lisp_Object barg),
1598 Lisp_Object barg, 1585 Lisp_Object barg,
1599 Lisp_Object (*hfun) (Lisp_Object val, Lisp_Object harg), 1586 Lisp_Object (*hfun) (Lisp_Object val, Lisp_Object harg),
1600 Lisp_Object harg) 1587 Lisp_Object harg)
1601 { 1588 {
1602 int speccount = specpdl_depth_counter; 1589 int speccount = specpdl_depth();
1603 struct catchtag c; 1590 struct catchtag c;
1604 struct gcpro gcpro1; 1591 struct gcpro gcpro1;
1605 1592
1606 #if 0 /* FSFmacs */ 1593 #if 0 /* FSFmacs */
1607 c.tag = Qnil; 1594 c.tag = Qnil;
1620 #if 0 /* FSFmacs */ 1607 #if 0 /* FSFmacs */
1621 /* #### */ 1608 /* #### */
1622 c.handlerlist = handlerlist; 1609 c.handlerlist = handlerlist;
1623 #endif 1610 #endif
1624 c.lisp_eval_depth = lisp_eval_depth; 1611 c.lisp_eval_depth = lisp_eval_depth;
1625 c.pdlcount = specpdl_depth_counter; 1612 c.pdlcount = specpdl_depth();
1626 #if 0 /* FSFmacs */ 1613 #if 0 /* FSFmacs */
1627 c.poll_suppress_count = async_timer_suppress_count; 1614 c.poll_suppress_count = async_timer_suppress_count;
1628 #endif 1615 #endif
1629 c.gcpro = gcprolist; 1616 c.gcpro = gcprolist;
1630 /* #### FSFmacs does the following statement *after* the setjmp(). */ 1617 /* #### FSFmacs does the following statement *after* the setjmp(). */
1672 if (!NILP (h.var)) 1659 if (!NILP (h.var))
1673 specbind (h.var, c.val); 1660 specbind (h.var, c.val);
1674 val = Fprogn (Fcdr (h.chosen_clause)); 1661 val = Fprogn (Fcdr (h.chosen_clause));
1675 1662
1676 /* Note that this just undoes the binding of h.var; whoever 1663 /* Note that this just undoes the binding of h.var; whoever
1677 longjumped to us unwound the stack to c.pdlcount before 1664 longjmp()ed to us unwound the stack to c.pdlcount before
1678 throwing. */ 1665 throwing. */
1679 unbind_to (c.pdlcount, Qnil); 1666 unbind_to (c.pdlcount, Qnil);
1680 return val; 1667 return val;
1681 #else 1668 #else
1682 int speccount; 1669 int speccount;
1683 1670
1671 CHECK_TRUE_LIST (val);
1684 if (NILP (var)) 1672 if (NILP (var))
1685 return Fprogn (Fcdr (val)); /* tailcall */ 1673 return Fprogn (Fcdr (val)); /* tail call */
1686 1674
1687 speccount = specpdl_depth_counter; 1675 speccount = specpdl_depth();
1688 specbind (var, Fcar (val)); 1676 specbind (var, Fcar (val));
1689 val = Fprogn (Fcdr (val)); 1677 val = Fprogn (Fcdr (val));
1690 return unbind_to (speccount, val); 1678 return unbind_to (speccount, val);
1691 #endif 1679 #endif
1692 } 1680 }
1696 than a single list of arguments. */ 1684 than a single list of arguments. */
1697 Lisp_Object 1685 Lisp_Object
1698 condition_case_3 (Lisp_Object bodyform, Lisp_Object var, Lisp_Object handlers) 1686 condition_case_3 (Lisp_Object bodyform, Lisp_Object var, Lisp_Object handlers)
1699 { 1687 {
1700 /* This function can GC */ 1688 /* This function can GC */
1701 Lisp_Object val; 1689 Lisp_Object handler;
1690
1691 EXTERNAL_LIST_LOOP_2 (handler, handlers)
1692 {
1693 if (NILP (handler))
1694 ;
1695 else if (CONSP (handler))
1696 {
1697 Lisp_Object conditions = XCAR (handler);
1698 /* CONDITIONS must a condition name or a list of condition names */
1699 if (SYMBOLP (conditions))
1700 ;
1701 else
1702 {
1703 Lisp_Object condition;
1704 EXTERNAL_LIST_LOOP_2 (condition, conditions)
1705 if (!SYMBOLP (condition))
1706 goto invalid_condition_handler;
1707 }
1708 }
1709 else
1710 {
1711 invalid_condition_handler:
1712 signal_simple_error ("Invalid condition handler", handler);
1713 }
1714 }
1702 1715
1703 CHECK_SYMBOL (var); 1716 CHECK_SYMBOL (var);
1704 1717
1705 for (val = handlers; ! NILP (val); val = Fcdr (val))
1706 {
1707 Lisp_Object tem;
1708 tem = Fcar (val);
1709 if ((!NILP (tem))
1710 && (!CONSP (tem)
1711 || (!SYMBOLP (XCAR (tem)) && !CONSP (XCAR (tem)))))
1712 signal_simple_error ("Invalid condition handler", tem);
1713 }
1714
1715 return condition_case_1 (handlers, 1718 return condition_case_1 (handlers,
1716 Feval, bodyform, 1719 Feval, bodyform,
1717 run_condition_case_handlers, 1720 run_condition_case_handlers,
1718 var); 1721 var);
1719 } 1722 }
1720 1723
1721 DEFUN ("condition-case", Fcondition_case, 2, UNEVALLED, 0, /* 1724 DEFUN ("condition-case", Fcondition_case, 2, UNEVALLED, 0, /*
1722 Regain control when an error is signalled. 1725 Regain control when an error is signalled.
1723 Usage looks like (condition-case VAR BODYFORM HANDLERS...). 1726 Usage looks like (condition-case VAR BODYFORM HANDLERS...).
1724 executes BODYFORM and returns its value if no error happens. 1727 Executes BODYFORM and returns its value if no error happens.
1725 Each element of HANDLERS looks like (CONDITION-NAME BODY...) 1728 Each element of HANDLERS looks like (CONDITION-NAME BODY...)
1726 where the BODY is made of Lisp expressions. 1729 where the BODY is made of Lisp expressions.
1727 1730
1728 A handler is applicable to an error if CONDITION-NAME is one of the 1731 A handler is applicable to an error if CONDITION-NAME is one of the
1729 error's condition names. If an error happens, the first applicable 1732 error's condition names. If an error happens, the first applicable
1753 rather than when the handler was set, use `call-with-condition-handler'. 1756 rather than when the handler was set, use `call-with-condition-handler'.
1754 */ 1757 */
1755 (args)) 1758 (args))
1756 { 1759 {
1757 /* This function can GC */ 1760 /* This function can GC */
1758 return condition_case_3 (XCAR (XCDR (args)), 1761 Lisp_Object var = XCAR (args);
1759 XCAR (args), 1762 Lisp_Object bodyform = XCAR (XCDR (args));
1760 XCDR (XCDR (args))); 1763 Lisp_Object handlers = XCDR (XCDR (args));
1764 return condition_case_3 (bodyform, var, handlers);
1761 } 1765 }
1762 1766
1763 DEFUN ("call-with-condition-handler", Fcall_with_condition_handler, 2, MANY, 0, /* 1767 DEFUN ("call-with-condition-handler", Fcall_with_condition_handler, 2, MANY, 0, /*
1764 Regain control when an error is signalled, without popping the stack. 1768 Regain control when an error is signalled, without popping the stack.
1765 Usage looks like (call-with-condition-handler HANDLER FUNCTION &rest ARGS). 1769 Usage looks like (call-with-condition-handler HANDLER FUNCTION &rest ARGS).
1777 and invokes the standard error-handler if none is found.) 1781 and invokes the standard error-handler if none is found.)
1778 */ 1782 */
1779 (int nargs, Lisp_Object *args)) /* Note! Args side-effected! */ 1783 (int nargs, Lisp_Object *args)) /* Note! Args side-effected! */
1780 { 1784 {
1781 /* This function can GC */ 1785 /* This function can GC */
1782 int speccount = specpdl_depth_counter; 1786 int speccount = specpdl_depth();
1783 Lisp_Object tem; 1787 Lisp_Object tem;
1784 1788
1785 /* #### If there were a way to check that args[0] were a function 1789 /* #### If there were a way to check that args[0] were a function
1786 which accepted one arg, that should be done here ... */ 1790 which accepted one arg, that should be done here ... */
1787 1791
1788 /* (handler-fun . handler-args) */ 1792 /* (handler-fun . handler-args) */
1789 tem = noseeum_cons (list1 (args[0]), Vcondition_handlers); 1793 tem = noseeum_cons (list1 (args[0]), Vcondition_handlers);
1790 record_unwind_protect (condition_bind_unwind, tem); 1794 record_unwind_protect (condition_bind_unwind, tem);
1791 Vcondition_handlers = tem; 1795 Vcondition_handlers = tem;
1792 1796
1793 /* Caller should have GC-protected args */ 1797 /* Caller should have GC-protected args */
1794 tem = Ffuncall (nargs - 1, args + 1); 1798 return unbind_to (speccount, Ffuncall (nargs - 1, args + 1));
1795 return unbind_to (speccount, tem);
1796 } 1799 }
1797 1800
1798 static int 1801 static int
1799 condition_type_p (Lisp_Object type, Lisp_Object conditions) 1802 condition_type_p (Lisp_Object type, Lisp_Object conditions)
1800 { 1803 {
1801 if (EQ (type, Qt)) 1804 if (EQ (type, Qt))
1802 /* (condition-case c # (t c)) catches -all- signals 1805 /* (condition-case c # (t c)) catches -all- signals
1803 * Use with caution! */ 1806 * Use with caution! */
1804 return 1; 1807 return 1;
1805 else 1808
1806 { 1809 if (SYMBOLP (type))
1807 if (SYMBOLP (type)) 1810 return !NILP (Fmemq (type, conditions));
1808 { 1811
1809 return !NILP (Fmemq (type, conditions)); 1812 for (; CONSP (type); type = XCDR (type))
1810 } 1813 if (!NILP (Fmemq (XCAR (type), conditions)))
1811 else if (CONSP (type)) 1814 return 1;
1812 { 1815
1813 while (CONSP (type)) 1816 return 0;
1814 {
1815 if (!NILP (Fmemq (Fcar (type), conditions)))
1816 return 1;
1817 type = XCDR (type);
1818 }
1819 return 0;
1820 }
1821 else
1822 return 0;
1823 }
1824 } 1817 }
1825 1818
1826 static Lisp_Object 1819 static Lisp_Object
1827 return_from_signal (Lisp_Object value) 1820 return_from_signal (Lisp_Object value)
1828 { 1821 {
1840 } 1833 }
1841 1834
1842 extern int in_display; 1835 extern int in_display;
1843 1836
1844 1837
1845 /****************** the workhorse error-signaling function ******************/ 1838 /************************************************************************/
1839 /* the workhorse error-signaling function */
1840 /************************************************************************/
1846 1841
1847 /* #### This function has not been synched with FSF. It diverges 1842 /* #### This function has not been synched with FSF. It diverges
1848 significantly. */ 1843 significantly. */
1849 1844
1850 static Lisp_Object 1845 static Lisp_Object
2054 } 2049 }
2055 2050
2056 static Lisp_Object 2051 static Lisp_Object
2057 call_with_suspended_errors_1 (Lisp_Object opaque_arg) 2052 call_with_suspended_errors_1 (Lisp_Object opaque_arg)
2058 { 2053 {
2054 Lisp_Object val;
2059 Lisp_Object *kludgy_args = (Lisp_Object *) get_opaque_ptr (opaque_arg); 2055 Lisp_Object *kludgy_args = (Lisp_Object *) get_opaque_ptr (opaque_arg);
2060 return primitive_funcall ((lisp_fn_t) get_opaque_ptr (kludgy_args[0]), 2056 PRIMITIVE_FUNCALL (val, get_opaque_ptr (kludgy_args[0]),
2061 XINT (kludgy_args[1]), kludgy_args + 2); 2057 kludgy_args + 2, XINT (kludgy_args[1]));
2058 return val;
2062 } 2059 }
2063 2060
2064 static Lisp_Object 2061 static Lisp_Object
2065 restore_current_warning_class (Lisp_Object warning_class) 2062 restore_current_warning_class (Lisp_Object warning_class)
2066 { 2063 {
2132 /* If error-checking is not disabled, just call the function. 2129 /* If error-checking is not disabled, just call the function.
2133 It's important not to override disabled error-checking with 2130 It's important not to override disabled error-checking with
2134 enabled error-checking. */ 2131 enabled error-checking. */
2135 2132
2136 if (ERRB_EQ (errb, ERROR_ME)) 2133 if (ERRB_EQ (errb, ERROR_ME))
2137 return primitive_funcall (fun, nargs, args); 2134 {
2138 2135 Lisp_Object val;
2139 speccount = specpdl_depth_counter; 2136 PRIMITIVE_FUNCALL (val, fun, args, nargs);
2137 return val;
2138 }
2139
2140 speccount = specpdl_depth();
2140 if (NILP (class) || NILP (Vcurrent_warning_class)) 2141 if (NILP (class) || NILP (Vcurrent_warning_class))
2141 { 2142 {
2142 /* If we're currently calling for no warnings, then make it so. 2143 /* If we're currently calling for no warnings, then make it so.
2143 If we're currently calling for warnings and we weren't 2144 If we're currently calling for warnings and we weren't
2144 previously, then set our warning class; otherwise, leave 2145 previously, then set our warning class; otherwise, leave
2477 /* note that this is continuable. */ 2478 /* note that this is continuable. */
2478 Fsignal (Qquit, Qnil); 2479 Fsignal (Qquit, Qnil);
2479 } 2480 }
2480 2481
2481 2482
2482 /**********************************************************************/ 2483 /* Used in core lisp functions for efficiency */
2483 /* User commands */ 2484 void
2484 /**********************************************************************/ 2485 signal_void_function_error (Lisp_Object function)
2486 {
2487 Fsignal (Qvoid_function, list1 (function));
2488 }
2489
2490 static void
2491 signal_invalid_function_error (Lisp_Object function)
2492 {
2493 Fsignal (Qinvalid_function, list1 (function));
2494 }
2495
2496 static void
2497 signal_wrong_number_of_arguments_error (Lisp_Object function, int nargs)
2498 {
2499 Fsignal (Qwrong_number_of_arguments, list2 (function, make_int (nargs)));
2500 }
2501
2502 /* Used in list traversal macros for efficiency. */
2503 void
2504 signal_malformed_list_error (Lisp_Object list)
2505 {
2506 Fsignal (Qmalformed_list, list1 (list));
2507 }
2508
2509 void
2510 signal_malformed_property_list_error (Lisp_Object list)
2511 {
2512 Fsignal (Qmalformed_property_list, list1 (list));
2513 }
2514
2515 void
2516 signal_circular_list_error (Lisp_Object list)
2517 {
2518 Fsignal (Qcircular_list, list1 (list));
2519 }
2520
2521 void
2522 signal_circular_property_list_error (Lisp_Object list)
2523 {
2524 Fsignal (Qcircular_property_list, list1 (list));
2525 }
2526
2527 /************************************************************************/
2528 /* User commands */
2529 /************************************************************************/
2485 2530
2486 DEFUN ("commandp", Fcommandp, 1, 1, 0, /* 2531 DEFUN ("commandp", Fcommandp, 1, 1, 0, /*
2487 Return t if FUNCTION makes provisions for interactive calling. 2532 Return t if FUNCTION makes provisions for interactive calling.
2488 This means it contains a description for how to read arguments to give it. 2533 This means it contains a description for how to read arguments to give it.
2489 The value is nil for an invalid function or a symbol with no function 2534 The value is nil for an invalid function or a symbol with no function
2503 */ 2548 */
2504 (function)) 2549 (function))
2505 { 2550 {
2506 Lisp_Object fun = indirect_function (function, 0); 2551 Lisp_Object fun = indirect_function (function, 0);
2507 2552
2508 if (UNBOUNDP (fun)) 2553 if (COMPILED_FUNCTIONP (fun))
2509 return Qnil; 2554 return XCOMPILED_FUNCTION (fun)->flags.interactivep ? Qt : Qnil;
2555
2556 /* Lists may represent commands. */
2557 if (CONSP (fun))
2558 {
2559 Lisp_Object funcar = XCAR (fun);
2560 if (EQ (funcar, Qlambda))
2561 return Fassq (Qinteractive, Fcdr (Fcdr (fun)));
2562 if (EQ (funcar, Qautoload))
2563 return Fcar (Fcdr (Fcdr (Fcdr (fun))));
2564 else
2565 return Qnil;
2566 }
2510 2567
2511 /* Emacs primitives are interactive if their DEFUN specifies an 2568 /* Emacs primitives are interactive if their DEFUN specifies an
2512 interactive spec. */ 2569 interactive spec. */
2513 if (SUBRP (fun)) 2570 if (SUBRP (fun))
2514 return XSUBR (fun)->prompt ? Qt : Qnil; 2571 return XSUBR (fun)->prompt ? Qt : Qnil;
2515 2572
2516 if (COMPILED_FUNCTIONP (fun))
2517 return XCOMPILED_FUNCTION (fun)->flags.interactivep ? Qt : Qnil;
2518
2519 /* Strings and vectors are keyboard macros. */ 2573 /* Strings and vectors are keyboard macros. */
2520 if (VECTORP (fun) || STRINGP (fun)) 2574 if (VECTORP (fun) || STRINGP (fun))
2521 return Qt; 2575 return Qt;
2522 2576
2523 /* Lists may represent commands. */ 2577 /* Everything else (including Qunbound) is not a command. */
2524 if (!CONSP (fun)) 2578 return Qnil;
2525 return Qnil;
2526 {
2527 Lisp_Object funcar = XCAR (fun);
2528 if (!SYMBOLP (funcar))
2529 return Fsignal (Qinvalid_function, list1 (fun));
2530 if (EQ (funcar, Qlambda))
2531 return Fassq (Qinteractive, Fcdr (Fcdr (fun)));
2532 if (EQ (funcar, Qautoload))
2533 return Fcar (Fcdr (Fcdr (Fcdr (fun))));
2534 else
2535 return Qnil;
2536 }
2537 } 2579 }
2538 2580
2539 DEFUN ("command-execute", Fcommand_execute, 1, 3, 0, /* 2581 DEFUN ("command-execute", Fcommand_execute, 1, 3, 0, /*
2540 Execute CMD as an editor command. 2582 Execute CMD as an editor command.
2541 CMD must be an object that satisfies the `commandp' predicate. 2583 CMD must be an object that satisfies the `commandp' predicate.
2568 break; 2610 break;
2569 } 2611 }
2570 2612
2571 if (CONSP (final) || SUBRP (final) || COMPILED_FUNCTIONP (final)) 2613 if (CONSP (final) || SUBRP (final) || COMPILED_FUNCTIONP (final))
2572 { 2614 {
2573 #ifdef EMACS_BTL
2574 backtrace.id_number = 0;
2575 #endif
2576 backtrace.function = &Qcall_interactively; 2615 backtrace.function = &Qcall_interactively;
2577 backtrace.args = &cmd; 2616 backtrace.args = &cmd;
2578 backtrace.nargs = 1; 2617 backtrace.nargs = 1;
2579 backtrace.evalargs = 0; 2618 backtrace.evalargs = 0;
2580 backtrace.pdlcount = specpdl_depth_counter; 2619 backtrace.pdlcount = specpdl_depth();
2581 backtrace.debug_on_exit = 0; 2620 backtrace.debug_on_exit = 0;
2582 PUSH_BACKTRACE (backtrace); 2621 PUSH_BACKTRACE (backtrace);
2583 2622
2584 final = Fcall_interactively (cmd, record, keys); 2623 final = Fcall_interactively (cmd, record, keys);
2585 2624
2673 return Qt; 2712 return Qt;
2674 return Qnil; 2713 return Qnil;
2675 } 2714 }
2676 2715
2677 2716
2678 /**********************************************************************/ 2717 /************************************************************************/
2679 /* Autoloading */ 2718 /* Autoloading */
2680 /**********************************************************************/ 2719 /************************************************************************/
2681 2720
2682 DEFUN ("autoload", Fautoload, 2, 5, 0, /* 2721 DEFUN ("autoload", Fautoload, 2, 5, 0, /*
2683 Define FUNCTION to autoload from FILE. 2722 Define FUNCTION to autoload from FILE.
2684 FUNCTION is a symbol; FILE is a file name string to pass to `load'. 2723 FUNCTION is a symbol; FILE is a file name string to pass to `load'.
2685 Third arg DOCSTRING is documentation for the function. 2724 Third arg DOCSTRING is documentation for the function.
2698 /* This function can GC */ 2737 /* This function can GC */
2699 CHECK_SYMBOL (function); 2738 CHECK_SYMBOL (function);
2700 CHECK_STRING (file); 2739 CHECK_STRING (file);
2701 2740
2702 /* If function is defined and not as an autoload, don't override */ 2741 /* If function is defined and not as an autoload, don't override */
2703 if (!UNBOUNDP (XSYMBOL (function)->function) 2742 {
2704 && !(CONSP (XSYMBOL (function)->function) 2743 Lisp_Object f = XSYMBOL (function)->function;
2705 && EQ (XCAR (XSYMBOL (function)->function), Qautoload))) 2744 if (!UNBOUNDP (f) && !(CONSP (f) && EQ (XCAR (f), Qautoload)))
2706 return Qnil; 2745 return Qnil;
2746 }
2707 2747
2708 if (purify_flag) 2748 if (purify_flag)
2709 { 2749 {
2710 /* Attempt to avoid consing identical (string=) pure strings. */ 2750 /* Attempt to avoid consing identical (string=) pure strings. */
2711 file = Fsymbol_name (Fintern (file, Qnil)); 2751 file = Fsymbol_name (Fintern (file, Qnil));
2728 oldqueue is the shadowed value to leave in Vautoload_queue. */ 2768 oldqueue is the shadowed value to leave in Vautoload_queue. */
2729 queue = Vautoload_queue; 2769 queue = Vautoload_queue;
2730 Vautoload_queue = oldqueue; 2770 Vautoload_queue = oldqueue;
2731 while (CONSP (queue)) 2771 while (CONSP (queue))
2732 { 2772 {
2733 first = Fcar (queue); 2773 first = XCAR (queue);
2734 second = Fcdr (first); 2774 second = Fcdr (first);
2735 first = Fcar (first); 2775 first = Fcar (first);
2736 if (NILP (second)) 2776 if (NILP (second))
2737 Vfeatures = first; 2777 Vfeatures = first;
2738 else 2778 else
2745 void 2785 void
2746 do_autoload (Lisp_Object fundef, 2786 do_autoload (Lisp_Object fundef,
2747 Lisp_Object funname) 2787 Lisp_Object funname)
2748 { 2788 {
2749 /* This function can GC */ 2789 /* This function can GC */
2750 int speccount = specpdl_depth_counter; 2790 int speccount = specpdl_depth();
2751 Lisp_Object fun = funname; 2791 Lisp_Object fun = funname;
2752 struct gcpro gcpro1, gcpro2; 2792 struct gcpro gcpro1, gcpro2;
2753 2793
2754 CHECK_SYMBOL (funname); 2794 CHECK_SYMBOL (funname);
2755 GCPRO2 (fun, funname); 2795 GCPRO2 (fun, funname);
2756 2796
2757 /* Value saved here is to be restored into Vautoload_queue */ 2797 /* Value saved here is to be restored into Vautoload_queue */
2758 record_unwind_protect (un_autoload, Vautoload_queue); 2798 record_unwind_protect (un_autoload, Vautoload_queue);
2759 Vautoload_queue = Qt; 2799 Vautoload_queue = Qt;
2760 call4 (Qload, Fcar (Fcdr (fundef)), Qnil, noninteractive ? Qt : Qnil, 2800 call4 (Qload, Fcar (Fcdr (fundef)), Qnil, noninteractive ? Qt : Qnil, Qnil);
2761 Qnil);
2762 2801
2763 { 2802 {
2764 Lisp_Object queue = Vautoload_queue; 2803 Lisp_Object queue;
2765 2804
2766 /* Save the old autoloads, in case we ever do an unload. */ 2805 /* Save the old autoloads, in case we ever do an unload. */
2767 queue = Vautoload_queue; 2806 for (queue = Vautoload_queue; CONSP (queue); queue = XCDR (queue))
2768 while (CONSP (queue)) 2807 {
2769 { 2808 Lisp_Object first = XCAR (queue);
2770 Lisp_Object first = Fcar (queue); 2809 Lisp_Object second = Fcdr (first);
2771 Lisp_Object second = Fcdr (first); 2810
2772 2811 first = Fcar (first);
2773 first = Fcar (first); 2812
2774 2813 /* Note: This test is subtle. The cdr of an autoload-queue entry
2775 /* Note: This test is subtle. The cdr of an autoload-queue entry 2814 may be an atom if the autoload entry was generated by a defalias
2776 may be an atom if the autoload entry was generated by a defalias 2815 or fset. */
2777 or fset. */ 2816 if (CONSP (second))
2778 if (CONSP (second)) 2817 Fput (first, Qautoload, (XCDR (second)));
2779 Fput (first, Qautoload, (Fcdr (second))); 2818 }
2780
2781 queue = Fcdr (queue);
2782 }
2783 } 2819 }
2784 2820
2785 /* Once loading finishes, don't undo it. */ 2821 /* Once loading finishes, don't undo it. */
2786 Vautoload_queue = Qt; 2822 Vautoload_queue = Qt;
2787 unbind_to (speccount, Qnil); 2823 unbind_to (speccount, Qnil);
2799 string_data (XSYMBOL (funname)->name)); 2835 string_data (XSYMBOL (funname)->name));
2800 UNGCPRO; 2836 UNGCPRO;
2801 } 2837 }
2802 2838
2803 2839
2804 /**********************************************************************/ 2840 /************************************************************************/
2805 /* eval, funcall, apply */ 2841 /* eval, funcall, apply */
2806 /**********************************************************************/ 2842 /************************************************************************/
2807 2843
2808 static Lisp_Object funcall_lambda (Lisp_Object fun, 2844 static Lisp_Object funcall_lambda (Lisp_Object fun,
2809 int nargs, Lisp_Object args[]); 2845 int nargs, Lisp_Object args[]);
2810 static Lisp_Object apply_lambda (Lisp_Object fun,
2811 int nargs, Lisp_Object args);
2812 static int in_warnings; 2846 static int in_warnings;
2813 2847
2814 static Lisp_Object 2848 static Lisp_Object
2815 in_warnings_restore (Lisp_Object minimus) 2849 in_warnings_restore (Lisp_Object minimus)
2816 { 2850 {
2817 in_warnings = 0; 2851 in_warnings = 0;
2818 return Qnil; 2852 return Qnil;
2819 }
2820
2821 #define AV_0(av)
2822 #define AV_1(av) av[0]
2823 #define AV_2(av) AV_1(av), av[1]
2824 #define AV_3(av) AV_2(av), av[2]
2825 #define AV_4(av) AV_3(av), av[3]
2826 #define AV_5(av) AV_4(av), av[4]
2827 #define AV_6(av) AV_5(av), av[5]
2828 #define AV_7(av) AV_6(av), av[6]
2829 #define AV_8(av) AV_7(av), av[7]
2830
2831 #define PRIMITIVE_FUNCALL(fn, av, ac) \
2832 (((Lisp_Object (*)(EXFUN_##ac)) (fn)) (AV_##ac (av)))
2833
2834 /* If subr's take more than 8 arguments, more cases need to be added
2835 to this switch. (But don't do it - if you really need a SUBR with
2836 more than 8 arguments, use max_args == MANY.
2837 See the DEFUN macro in lisp.h) */
2838 #define inline_funcall_fn(rv, fn, av, ac) do { \
2839 switch (ac) { \
2840 case 0: rv = PRIMITIVE_FUNCALL(fn, av, 0); break; \
2841 case 1: rv = PRIMITIVE_FUNCALL(fn, av, 1); break; \
2842 case 2: rv = PRIMITIVE_FUNCALL(fn, av, 2); break; \
2843 case 3: rv = PRIMITIVE_FUNCALL(fn, av, 3); break; \
2844 case 4: rv = PRIMITIVE_FUNCALL(fn, av, 4); break; \
2845 case 5: rv = PRIMITIVE_FUNCALL(fn, av, 5); break; \
2846 case 6: rv = PRIMITIVE_FUNCALL(fn, av, 6); break; \
2847 case 7: rv = PRIMITIVE_FUNCALL(fn, av, 7); break; \
2848 case 8: rv = PRIMITIVE_FUNCALL(fn, av, 8); break; \
2849 default: abort(); rv = Qnil; break; \
2850 } \
2851 } while (0)
2852
2853 #define inline_funcall_subr(rv, subr, av) do { \
2854 void (*fn)() = (void (*)()) (subr_function(subr)); \
2855 inline_funcall_fn (rv, fn, av, subr->max_args); \
2856 } while (0)
2857
2858 static Lisp_Object
2859 primitive_funcall (lisp_fn_t fn, int nargs, Lisp_Object args[])
2860 {
2861 Lisp_Object rv;
2862 inline_funcall_fn (rv, fn, args, nargs);
2863 return rv;
2864 } 2853 }
2865 2854
2866 DEFUN ("eval", Feval, 1, 1, 0, /* 2855 DEFUN ("eval", Feval, 1, 1, 0, /*
2867 Evaluate FORM and return its value. 2856 Evaluate FORM and return its value.
2868 */ 2857 */
2875 2864
2876 /* I think this is a pretty safe place to call Lisp code, don't you? */ 2865 /* I think this is a pretty safe place to call Lisp code, don't you? */
2877 while (!in_warnings && !NILP (Vpending_warnings)) 2866 while (!in_warnings && !NILP (Vpending_warnings))
2878 { 2867 {
2879 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 2868 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
2880 int speccount = specpdl_depth_counter; 2869 int speccount = specpdl_depth();
2881 Lisp_Object this_warning_cons, this_warning, class, level, messij; 2870 Lisp_Object this_warning_cons, this_warning, class, level, messij;
2882 2871
2883 record_unwind_protect (in_warnings_restore, Qnil); 2872 record_unwind_protect (in_warnings_restore, Qnil);
2884 in_warnings = 1; 2873 in_warnings = 1;
2885 this_warning_cons = Vpending_warnings; 2874 this_warning_cons = Vpending_warnings;
2903 call3 (Qdisplay_warning, class, messij, level); 2892 call3 (Qdisplay_warning, class, messij, level);
2904 UNGCPRO; 2893 UNGCPRO;
2905 unbind_to (speccount, Qnil); 2894 unbind_to (speccount, Qnil);
2906 } 2895 }
2907 2896
2908 if (SYMBOLP (form))
2909 return Fsymbol_value (form);
2910
2911 if (!CONSP (form)) 2897 if (!CONSP (form))
2912 return form; 2898 {
2899 if (SYMBOLP (form))
2900 return Fsymbol_value (form);
2901 else
2902 return form;
2903 }
2913 2904
2914 QUIT; 2905 QUIT;
2915 if ((consing_since_gc > gc_cons_threshold) || always_gc) 2906 if ((consing_since_gc > gc_cons_threshold) || always_gc)
2916 { 2907 {
2917 struct gcpro gcpro1; 2908 struct gcpro gcpro1;
2926 max_lisp_eval_depth = 100; 2917 max_lisp_eval_depth = 100;
2927 if (lisp_eval_depth > max_lisp_eval_depth) 2918 if (lisp_eval_depth > max_lisp_eval_depth)
2928 error ("Lisp nesting exceeds `max-lisp-eval-depth'"); 2919 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
2929 } 2920 }
2930 2921
2931 /* 2922 /* We guaranteed CONSP (form) above */
2932 * At this point we know that `form' is a Lisp_Cons so we can safely 2923 original_fun = XCAR (form);
2933 * use XCAR and XCDR.
2934 */
2935 original_fun = XCAR (form);
2936 original_args = XCDR (form); 2924 original_args = XCDR (form);
2937 2925
2938 /* 2926 GET_EXTERNAL_LIST_LENGTH (original_args, nargs);
2939 * Formerly we used a call to Flength here, but that is slow and 2927
2940 * wasteful due to type checking, stack push/pop and initialization. 2928 backtrace.pdlcount = specpdl_depth();
2941 * We know we're dealing with a cons, so open code it for speed.
2942 *
2943 * We call QUIT in the loop so that a circular arg list won't lock
2944 * up the editor.
2945 */
2946 for (nargs = 0, val = original_args ; CONSP (val) ; val = XCDR (val))
2947 {
2948 nargs++;
2949 QUIT;
2950 }
2951 if (! NILP (val))
2952 signal_simple_error ("Argument list must be nil-terminated",
2953 original_args);
2954
2955 #ifdef EMACS_BTL
2956 backtrace.id_number = 0;
2957 #endif
2958 backtrace.pdlcount = specpdl_depth_counter;
2959 backtrace.function = &original_fun; /* This also protects them from gc */ 2929 backtrace.function = &original_fun; /* This also protects them from gc */
2960 backtrace.args = &original_args; 2930 backtrace.args = &original_args;
2961 backtrace.nargs = UNEVALLED; 2931 backtrace.nargs = UNEVALLED;
2962 backtrace.evalargs = 1; 2932 backtrace.evalargs = 1;
2963 backtrace.debug_on_exit = 0; 2933 backtrace.debug_on_exit = 0;
2968 2938
2969 if (profiling_active) 2939 if (profiling_active)
2970 profile_increase_call_count (original_fun); 2940 profile_increase_call_count (original_fun);
2971 2941
2972 /* At this point, only original_fun and original_args 2942 /* At this point, only original_fun and original_args
2973 have values that will be used below */ 2943 have values that will be used below. */
2974 retry: 2944 retry:
2975 fun = indirect_function (original_fun, 1); 2945 fun = indirect_function (original_fun, 1);
2976 2946
2977 if (SUBRP (fun)) 2947 if (SUBRP (fun))
2978 { 2948 {
2979 struct Lisp_Subr *subr = XSUBR (fun); 2949 Lisp_Subr *subr = XSUBR (fun);
2980 int max_args = subr->max_args; 2950 int max_args = subr->max_args;
2981 Lisp_Object argvals[SUBR_MAX_ARGS]; 2951
2982 Lisp_Object args_left; 2952 if (nargs < subr->min_args)
2983 REGISTER int i; 2953 goto wrong_number_of_arguments;
2984 2954
2985 args_left = original_args; 2955 if (max_args == UNEVALLED) /* Optimize for the common case */
2986
2987 if (nargs < subr->min_args
2988 || (max_args >= 0 && max_args < nargs))
2989 {
2990 return Fsignal (Qwrong_number_of_arguments,
2991 list2 (fun, make_int (nargs)));
2992 }
2993
2994 if (max_args == UNEVALLED)
2995 { 2956 {
2996 backtrace.evalargs = 0; 2957 backtrace.evalargs = 0;
2997 val = ((Lisp_Object (*) (Lisp_Object)) (subr_function (subr))) (args_left); 2958 val = (((Lisp_Object (*) (Lisp_Object)) (subr_function (subr)))
2959 (original_args));
2998 } 2960 }
2999 2961 else if (nargs <= max_args)
2962 {
2963 struct gcpro gcpro1;
2964 Lisp_Object args[SUBR_MAX_ARGS];
2965 REGISTER Lisp_Object *p = args;
2966
2967 GCPRO1 (args[0]);
2968 gcpro1.nvars = 0;
2969
2970 {
2971 REGISTER Lisp_Object arg;
2972 LIST_LOOP_2 (arg, original_args)
2973 {
2974 *p++ = Feval (arg);
2975 gcpro1.nvars++;
2976 }
2977 }
2978
2979 /* &optional args default to nil. */
2980 while (p - args < max_args)
2981 *p++ = Qnil;
2982
2983 backtrace.args = args;
2984 backtrace.nargs = nargs;
2985
2986 FUNCALL_SUBR (val, subr, args, max_args);
2987
2988 UNGCPRO;
2989 }
3000 else if (max_args == MANY) 2990 else if (max_args == MANY)
3001 { 2991 {
3002 /* Pass a vector of evaluated arguments */ 2992 /* Pass a vector of evaluated arguments */
3003 Lisp_Object *vals; 2993 struct gcpro gcpro1;
3004 REGISTER int argnum; 2994 Lisp_Object *args = alloca_array (Lisp_Object, nargs);
3005 struct gcpro gcpro1, gcpro2, gcpro3; 2995 REGISTER Lisp_Object *p = args;
3006 2996
3007 vals = alloca_array (Lisp_Object, nargs); 2997 GCPRO1 (args[0]);
3008 2998 gcpro1.nvars = 0;
3009 GCPRO3 (args_left, fun, vals[0]); 2999
3010 gcpro3.nvars = 0; 3000 {
3011 3001 REGISTER Lisp_Object arg;
3012 argnum = 0; 3002 LIST_LOOP_2 (arg, original_args)
3013 while (CONSP (args_left)) 3003 {
3014 { 3004 *p++ = Feval (arg);
3015 vals[argnum++] = Feval (XCAR (args_left)); 3005 gcpro1.nvars++;
3016 args_left = XCDR (args_left); 3006 }
3017 gcpro3.nvars = argnum; 3007 }
3018 } 3008
3019 3009 backtrace.args = args;
3020 backtrace.args = vals;
3021 backtrace.nargs = nargs; 3010 backtrace.nargs = nargs;
3022 3011
3023 val = ((Lisp_Object (*) (int, Lisp_Object *)) (subr_function (subr))) 3012 val = (((Lisp_Object (*) (int, Lisp_Object *)) (subr_function (subr)))
3024 (nargs, vals); 3013 (nargs, args));
3025 3014
3026 /* Have to duplicate this code because if the
3027 * debugger is called it must be in a scope in
3028 * which the `alloca'-ed data in vals is still valid.
3029 * (And GC-protected.)
3030 */
3031 lisp_eval_depth--;
3032 if (backtrace.debug_on_exit)
3033 val = do_debug_on_exit (val);
3034 POP_BACKTRACE (backtrace);
3035 UNGCPRO; 3015 UNGCPRO;
3036 return val;
3037 } 3016 }
3038
3039 else 3017 else
3040 { 3018 {
3041 struct gcpro gcpro1, gcpro2, gcpro3; 3019 wrong_number_of_arguments:
3042 3020 signal_wrong_number_of_arguments_error (fun, nargs);
3043 GCPRO3 (args_left, fun, fun); 3021 }
3044 gcpro3.var = argvals;
3045 gcpro3.nvars = 0;
3046
3047 for (i = 0; i < nargs; args_left = XCDR (args_left))
3048 {
3049 argvals[i] = Feval (XCAR (args_left));
3050 gcpro3.nvars = ++i;
3051 }
3052
3053 UNGCPRO;
3054
3055 /* i == nargs at this point */
3056 for (; i < max_args; i++)
3057 argvals[i] = Qnil;
3058
3059 backtrace.args = argvals;
3060 backtrace.nargs = nargs;
3061
3062 /* val = funcall_subr (subr, argvals); */
3063 inline_funcall_subr (val, subr, argvals);
3064 }
3065 } 3022 }
3066 else if (COMPILED_FUNCTIONP (fun)) 3023 else if (COMPILED_FUNCTIONP (fun))
3067 val = apply_lambda (fun, nargs, original_args); 3024 {
3068 else 3025 struct gcpro gcpro1;
3069 { 3026 Lisp_Object *args = alloca_array (Lisp_Object, nargs);
3070 Lisp_Object funcar; 3027 REGISTER Lisp_Object *p = args;
3071 3028
3072 if (!CONSP (fun)) 3029 GCPRO1 (args[0]);
3073 goto invalid_function; 3030 gcpro1.nvars = 0;
3074 funcar = XCAR (fun); 3031
3075 if (!SYMBOLP (funcar)) 3032 {
3076 goto invalid_function; 3033 REGISTER Lisp_Object arg;
3034 LIST_LOOP_2 (arg, original_args)
3035 {
3036 *p++ = Feval (arg);
3037 gcpro1.nvars++;
3038 }
3039 }
3040
3041 backtrace.args = args;
3042 backtrace.nargs = nargs;
3043 backtrace.evalargs = 0;
3044
3045 val = funcall_compiled_function (fun, nargs, args);
3046
3047 /* Do the debug-on-exit now, while args is still GCPROed. */
3048 if (backtrace.debug_on_exit)
3049 val = do_debug_on_exit (val);
3050 /* Don't do it again when we return to eval. */
3051 backtrace.debug_on_exit = 0;
3052
3053 UNGCPRO;
3054 }
3055 else if (CONSP (fun))
3056 {
3057 Lisp_Object funcar = XCAR (fun);
3058
3077 if (EQ (funcar, Qautoload)) 3059 if (EQ (funcar, Qautoload))
3078 { 3060 {
3079 do_autoload (fun, original_fun); 3061 do_autoload (fun, original_fun);
3080 goto retry; 3062 goto retry;
3081 } 3063 }
3082 if (EQ (funcar, Qmacro)) 3064 else if (EQ (funcar, Qmacro))
3083 val = Feval (apply1 (XCDR (fun), original_args)); 3065 {
3066 val = Feval (apply1 (XCDR (fun), original_args));
3067 }
3084 else if (EQ (funcar, Qlambda)) 3068 else if (EQ (funcar, Qlambda))
3085 val = apply_lambda (fun, nargs, original_args); 3069 {
3070 struct gcpro gcpro1;
3071 Lisp_Object *args = alloca_array (Lisp_Object, nargs);
3072 REGISTER Lisp_Object *p = args;
3073
3074 GCPRO1 (args[0]);
3075 gcpro1.nvars = 0;
3076
3077 {
3078 REGISTER Lisp_Object arg;
3079 LIST_LOOP_2 (arg, original_args)
3080 {
3081 *p++ = Feval (arg);
3082 gcpro1.nvars++;
3083 }
3084 }
3085
3086 UNGCPRO;
3087
3088 backtrace.args = args; /* this also GCPROs `args' */
3089 backtrace.nargs = nargs;
3090 backtrace.evalargs = 0;
3091
3092 val = funcall_lambda (fun, nargs, args);
3093
3094 /* Do the debug-on-exit now, while args is still GCPROed. */
3095 if (backtrace.debug_on_exit)
3096 val = do_debug_on_exit (val);
3097 /* Don't do it again when we return to eval. */
3098 backtrace.debug_on_exit = 0;
3099 }
3086 else 3100 else
3087 { 3101 {
3088 invalid_function: 3102 goto invalid_function;
3089 return Fsignal (Qinvalid_function, list1 (fun));
3090 } 3103 }
3104 }
3105 else /* ! (SUBRP (fun) || COMPILED_FUNCTIONP (fun) || CONSP (fun)) */
3106 {
3107 invalid_function:
3108 signal_invalid_function_error (fun);
3091 } 3109 }
3092 3110
3093 lisp_eval_depth--; 3111 lisp_eval_depth--;
3094 if (backtrace.debug_on_exit) 3112 if (backtrace.debug_on_exit)
3095 val = do_debug_on_exit (val); 3113 val = do_debug_on_exit (val);
3096 POP_BACKTRACE (backtrace); 3114 POP_BACKTRACE (backtrace);
3097 return val; 3115 return val;
3098 } 3116 }
3099 3117
3100 3118
3101 Lisp_Object 3119 DEFUN ("funcall", Ffuncall, 1, MANY, 0, /*
3102 funcall_recording_as (Lisp_Object recorded_as, int nargs, 3120 Call first argument as a function, passing the remaining arguments to it.
3103 Lisp_Object *args) 3121 Thus, (funcall 'cons 'x 'y) returns (x . y).
3122 */
3123 (int nargs, Lisp_Object *args))
3104 { 3124 {
3105 /* This function can GC */ 3125 /* This function can GC */
3106 Lisp_Object fun; 3126 Lisp_Object fun;
3107 Lisp_Object val; 3127 Lisp_Object val;
3108 struct backtrace backtrace; 3128 struct backtrace backtrace;
3109 REGISTER int i; 3129 int fun_nargs = nargs - 1;
3130 Lisp_Object *fun_args = args + 1;
3110 3131
3111 QUIT; 3132 QUIT;
3112 if ((consing_since_gc > gc_cons_threshold) || always_gc) 3133 if ((consing_since_gc > gc_cons_threshold) || always_gc)
3113 /* Callers should gcpro lexpr args */ 3134 /* Callers should gcpro lexpr args */
3114 garbage_collect_1 (); 3135 garbage_collect_1 ();
3119 max_lisp_eval_depth = 100; 3140 max_lisp_eval_depth = 100;
3120 if (lisp_eval_depth > max_lisp_eval_depth) 3141 if (lisp_eval_depth > max_lisp_eval_depth)
3121 error ("Lisp nesting exceeds `max-lisp-eval-depth'"); 3142 error ("Lisp nesting exceeds `max-lisp-eval-depth'");
3122 } 3143 }
3123 3144
3124 /* Count number of arguments to function */ 3145 backtrace.pdlcount = specpdl_depth();
3125 nargs = nargs - 1;
3126
3127 #ifdef EMACS_BTL
3128 backtrace.id_number = 0;
3129 #endif
3130 backtrace.pdlcount = specpdl_depth_counter;
3131 backtrace.function = &args[0]; 3146 backtrace.function = &args[0];
3132 backtrace.args = &args[1]; 3147 backtrace.args = fun_args;
3133 backtrace.nargs = nargs; 3148 backtrace.nargs = fun_nargs;
3134 backtrace.evalargs = 0; 3149 backtrace.evalargs = 0;
3135 backtrace.debug_on_exit = 0; 3150 backtrace.debug_on_exit = 0;
3136 PUSH_BACKTRACE (backtrace); 3151 PUSH_BACKTRACE (backtrace);
3137 3152
3138 if (debug_on_next_call) 3153 if (debug_on_next_call)
3140 3155
3141 retry: 3156 retry:
3142 3157
3143 fun = args[0]; 3158 fun = args[0];
3144 3159
3145 #ifdef EMACS_BTL
3146 {
3147 extern int emacs_btl_elisp_only_p;
3148 extern int btl_symbol_id_number ();
3149 if (emacs_btl_elisp_only_p)
3150 backtrace.id_number = btl_symbol_id_number (fun);
3151 }
3152 #endif
3153
3154 /* It might be useful to place this *after* all the checks. */ 3160 /* It might be useful to place this *after* all the checks. */
3155 if (profiling_active) 3161 if (profiling_active)
3156 profile_increase_call_count (fun); 3162 profile_increase_call_count (fun);
3157 3163
3164 /* We could call indirect_function directly, but profiling shows
3165 this is worth optimizing by partially unrolling the loop. */
3158 if (SYMBOLP (fun)) 3166 if (SYMBOLP (fun))
3159 fun = indirect_function (fun, 1); 3167 {
3168 fun = XSYMBOL (fun)->function;
3169 if (SYMBOLP (fun))
3170 {
3171 fun = XSYMBOL (fun)->function;
3172 if (SYMBOLP (fun))
3173 fun = indirect_function (fun, 1);
3174 }
3175 }
3160 3176
3161 if (SUBRP (fun)) 3177 if (SUBRP (fun))
3162 { 3178 {
3163 struct Lisp_Subr *subr = XSUBR (fun); 3179 Lisp_Subr *subr = XSUBR (fun);
3164 int max_args = subr->max_args; 3180 int max_args = subr->max_args;
3165 3181 Lisp_Object spacious_args[SUBR_MAX_ARGS];
3166 if (max_args == UNEVALLED) 3182
3167 return Fsignal (Qinvalid_function, list1 (fun)); 3183 if (fun_nargs < subr->min_args)
3168 3184 goto wrong_number_of_arguments;
3169 if (nargs < subr->min_args 3185
3170 || (max_args >= 0 && max_args < nargs)) 3186 if (fun_nargs == max_args) /* Optimize for the common case */
3171 { 3187 {
3172 return Fsignal (Qwrong_number_of_arguments, 3188 funcall_subr:
3173 list2 (fun, make_int (nargs))); 3189 FUNCALL_SUBR (val, subr, fun_args, max_args);
3174 } 3190 }
3175 3191 else if (fun_nargs < max_args)
3176 if (max_args == MANY) 3192 {
3193 Lisp_Object *p = spacious_args;
3194
3195 /* Default optionals to nil */
3196 while (fun_nargs--)
3197 *p++ = *fun_args++;
3198 while (p - spacious_args < max_args)
3199 *p++ = Qnil;
3200
3201 fun_args = spacious_args;
3202 goto funcall_subr;
3203 }
3204 else if (max_args == MANY)
3177 { 3205 {
3178 val = ((Lisp_Object (*) (int, Lisp_Object *)) (subr_function (subr))) 3206 val = ((Lisp_Object (*) (int, Lisp_Object *)) (subr_function (subr)))
3179 (nargs, args + 1); 3207 (fun_nargs, fun_args);
3180 } 3208 }
3181 3209 else if (max_args == UNEVALLED) /* Can't funcall a special form */
3182 else if (max_args > nargs)
3183 { 3210 {
3184 Lisp_Object argvals[SUBR_MAX_ARGS]; 3211 goto invalid_function;
3185
3186 /* Default optionals to nil */
3187 for (i = 0; i < nargs; i++)
3188 argvals[i] = args[i + 1];
3189 for (i = nargs; i < max_args; i++)
3190 argvals[i] = Qnil;
3191
3192 /* val = funcall_subr (subr, argvals); */
3193 inline_funcall_subr (val, subr, argvals);
3194 } 3212 }
3195 else 3213 else
3196 /* val = funcall_subr (subr, args + 1); */ 3214 {
3197 inline_funcall_subr (val, subr, (&args[1])); 3215 wrong_number_of_arguments:
3216 signal_wrong_number_of_arguments_error (fun, fun_nargs);
3217 }
3198 } 3218 }
3199 else if (COMPILED_FUNCTIONP (fun)) 3219 else if (COMPILED_FUNCTIONP (fun))
3200 val = funcall_lambda (fun, nargs, args + 1); 3220 {
3201 else if (!CONSP (fun)) 3221 val = funcall_compiled_function (fun, fun_nargs, fun_args);
3202 { 3222 }
3203 invalid_function: 3223 else if (CONSP (fun))
3204 return Fsignal (Qinvalid_function, list1 (fun)); 3224 {
3205 }
3206 else
3207 {
3208 /* `fun' is a Lisp_Cons so XCAR is safe */
3209 Lisp_Object funcar = XCAR (fun); 3225 Lisp_Object funcar = XCAR (fun);
3210 3226
3211 if (!SYMBOLP (funcar))
3212 goto invalid_function;
3213 if (EQ (funcar, Qlambda)) 3227 if (EQ (funcar, Qlambda))
3214 val = funcall_lambda (fun, nargs, args + 1); 3228 {
3229 val = funcall_lambda (fun, fun_nargs, fun_args);
3230 }
3215 else if (EQ (funcar, Qautoload)) 3231 else if (EQ (funcar, Qautoload))
3216 { 3232 {
3217 do_autoload (fun, args[0]); 3233 do_autoload (fun, args[0]);
3218 goto retry; 3234 goto retry;
3219 } 3235 }
3220 else 3236 else /* Can't funcall a macro */
3221 { 3237 {
3222 goto invalid_function; 3238 goto invalid_function;
3223 } 3239 }
3224 } 3240 }
3241 else if (UNBOUNDP (fun))
3242 {
3243 signal_void_function_error (args[0]);
3244 }
3245 else
3246 {
3247 invalid_function:
3248 signal_invalid_function_error (fun);
3249 }
3250
3225 lisp_eval_depth--; 3251 lisp_eval_depth--;
3226 if (backtrace.debug_on_exit) 3252 if (backtrace.debug_on_exit)
3227 val = do_debug_on_exit (val); 3253 val = do_debug_on_exit (val);
3228 POP_BACKTRACE (backtrace); 3254 POP_BACKTRACE (backtrace);
3229 return val; 3255 return val;
3230 } 3256 }
3231 3257
3232 DEFUN ("funcall", Ffuncall, 1, MANY, 0, /* 3258 DEFUN ("functionp", Ffunctionp, 1, 1, 0, /*
3233 Call first argument as a function, passing remaining arguments to it. 3259 Return t if OBJECT can be called as a function, else nil.
3234 Thus, (funcall 'cons 'x 'y) returns (x . y). 3260 A function is an object that can be applied to arguments,
3261 using for example `funcall' or `apply'.
3235 */ 3262 */
3236 (int nargs, Lisp_Object *args)) 3263 (object))
3237 { 3264 {
3238 return funcall_recording_as (args[0], nargs, args); 3265 if (SYMBOLP (object))
3239 } 3266 object = indirect_function (object, 0);
3240 3267
3241 DEFUN ("function-min-args", Ffunction_min_args, 1, 1, 0, /* 3268 return
3242 Return the number of arguments a function may be called with. The 3269 (SUBRP (object) ||
3243 function may be any form that can be passed to `funcall', any special 3270 COMPILED_FUNCTIONP (object) ||
3244 form, or any macro. 3271 (CONSP (object) &&
3245 */ 3272 (EQ (XCAR (object), Qlambda) ||
3246 (function)) 3273 EQ (XCAR (object), Qautoload))))
3274 ? Qt : Qnil;
3275 }
3276
3277 static Lisp_Object
3278 function_argcount (Lisp_Object function, int function_min_args_p)
3247 { 3279 {
3248 Lisp_Object orig_function = function; 3280 Lisp_Object orig_function = function;
3249 Lisp_Object arglist; 3281 Lisp_Object arglist;
3250 int argcount;
3251 3282
3252 retry: 3283 retry:
3253 3284
3254 if (SYMBOLP (function)) 3285 if (SYMBOLP (function))
3255 function = indirect_function (function, 1); 3286 function = indirect_function (function, 1);
3256 3287
3257 if (SUBRP (function)) 3288 if (SUBRP (function))
3258 return Fsubr_min_args (function); 3289 {
3259 else if (!COMPILED_FUNCTIONP (function) && !CONSP (function)) 3290 return function_min_args_p ?
3260 { 3291 Fsubr_min_args (function):
3261 invalid_function: 3292 Fsubr_max_args (function);
3262 return Fsignal (Qinvalid_function, list1 (function)); 3293 }
3263 } 3294 else if (COMPILED_FUNCTIONP (function))
3264 3295 {
3265 if (CONSP (function)) 3296 arglist = compiled_function_arglist (XCOMPILED_FUNCTION (function));
3297 }
3298 else if (CONSP (function))
3266 { 3299 {
3267 Lisp_Object funcar = XCAR (function); 3300 Lisp_Object funcar = XCAR (function);
3268 3301
3269 if (!SYMBOLP (funcar))
3270 goto invalid_function;
3271 if (EQ (funcar, Qmacro)) 3302 if (EQ (funcar, Qmacro))
3272 { 3303 {
3273 function = XCDR (function); 3304 function = XCDR (function);
3274 goto retry; 3305 goto retry;
3275 } 3306 }
3276 if (EQ (funcar, Qautoload)) 3307 else if (EQ (funcar, Qautoload))
3277 { 3308 {
3278 do_autoload (function, orig_function); 3309 do_autoload (function, orig_function);
3279 goto retry; 3310 goto retry;
3280 } 3311 }
3281 if (EQ (funcar, Qlambda)) 3312 else if (EQ (funcar, Qlambda))
3282 arglist = Fcar (XCDR (function)); 3313 {
3314 arglist = Fcar (XCDR (function));
3315 }
3283 else 3316 else
3284 goto invalid_function; 3317 {
3318 goto invalid_function;
3319 }
3285 } 3320 }
3286 else 3321 else
3287 arglist = XCOMPILED_FUNCTION (function)->arglist; 3322 {
3288 3323 invalid_function:
3289 argcount = 0; 3324 return Fsignal (Qinvalid_function, list1 (function));
3290 while (!NILP (arglist)) 3325 }
3291 { 3326
3292 QUIT; 3327 {
3293 if (EQ (Fcar (arglist), Qand_optional) 3328 int argcount = 0;
3294 || EQ (Fcar (arglist), Qand_rest)) 3329 Lisp_Object arg;
3295 break; 3330
3296 argcount++; 3331 EXTERNAL_LIST_LOOP_2 (arg, arglist)
3297 arglist = Fcdr (arglist); 3332 {
3298 } 3333 if (EQ (arg, Qand_optional))
3299 3334 {
3300 return make_int (argcount); 3335 if (function_min_args_p)
3301 } 3336 break;
3302 3337 }
3303 DEFUN ("function-max-args", Ffunction_max_args, 1, 1, 0, /* 3338 else if (EQ (arg, Qand_rest))
3304 Return the number of arguments a function may be called with. If the 3339 {
3305 function takes an arbitrary number of arguments or is a built-in 3340 if (function_min_args_p)
3306 special form, nil is returned. The function may be any form that can 3341 break;
3307 be passed to `funcall', any special form, or any macro. 3342 else
3343 return Qnil;
3344 }
3345 else
3346 {
3347 argcount++;
3348 }
3349 }
3350
3351 return make_int (argcount);
3352 }
3353 }
3354
3355 DEFUN ("function-min-args", Ffunction_min_args, 1, 1, 0, /*
3356 Return the number of arguments a function may be called with.
3357 The function may be any form that can be passed to `funcall',
3358 any special form, or any macro.
3308 */ 3359 */
3309 (function)) 3360 (function))
3310 { 3361 {
3311 Lisp_Object orig_function = function; 3362 return function_argcount (function, 1);
3312 Lisp_Object arglist; 3363 }
3313 int argcount; 3364
3314 3365 DEFUN ("function-max-args", Ffunction_max_args, 1, 1, 0, /*
3315 retry: 3366 Return the number of arguments a function may be called with.
3316 3367 The function may be any form that can be passed to `funcall',
3317 if (SYMBOLP (function)) 3368 any special form, or any macro.
3318 function = indirect_function (function, 1); 3369 If the function takes an arbitrary number of arguments or is
3319 3370 a built-in special form, nil is returned.
3320 if (SUBRP (function)) 3371 */
3321 return Fsubr_max_args (function); 3372 (function))
3322 else if (!COMPILED_FUNCTIONP (function) && !CONSP (function)) 3373 {
3323 { 3374 return function_argcount (function, 0);
3324 invalid_function:
3325 return Fsignal (Qinvalid_function, list1 (function));
3326 }
3327
3328 if (CONSP (function))
3329 {
3330 Lisp_Object funcar = XCAR (function);
3331
3332 if (!SYMBOLP (funcar))
3333 goto invalid_function;
3334 if (EQ (funcar, Qmacro))
3335 {
3336 function = XCDR (function);
3337 goto retry;
3338 }
3339 if (EQ (funcar, Qautoload))
3340 {
3341 do_autoload (function, orig_function);
3342 goto retry;
3343 }
3344 if (EQ (funcar, Qlambda))
3345 arglist = Fcar (XCDR (function));
3346 else
3347 goto invalid_function;
3348 }
3349 else
3350 arglist = XCOMPILED_FUNCTION (function)->arglist;
3351
3352 argcount = 0;
3353 while (!NILP (arglist))
3354 {
3355 QUIT;
3356 if (EQ (Fcar (arglist), Qand_optional))
3357 {
3358 arglist = Fcdr (arglist);
3359 continue;
3360 }
3361 if (EQ (Fcar (arglist), Qand_rest))
3362 return Qnil;
3363 argcount++;
3364 arglist = Fcdr (arglist);
3365 }
3366
3367 return make_int (argcount);
3368 } 3375 }
3369 3376
3370 3377
3371 DEFUN ("apply", Fapply, 2, MANY, 0, /* 3378 DEFUN ("apply", Fapply, 2, MANY, 0, /*
3372 Call FUNCTION with our remaining args, using our last arg as list of args. 3379 Call FUNCTION with the remaining args, using the last arg as a list of args.
3373 Thus, (apply '+ 1 2 '(3 4)) returns 10. 3380 Thus, (apply '+ 1 2 '(3 4)) returns 10.
3374 */ 3381 */
3375 (int nargs, Lisp_Object *args)) 3382 (int nargs, Lisp_Object *args))
3376 { 3383 {
3377 /* This function can GC */ 3384 /* This function can GC */
3378 Lisp_Object fun = args[0]; 3385 Lisp_Object fun = args[0];
3379 Lisp_Object spread_arg = args [nargs - 1], p; 3386 Lisp_Object spread_arg = args [nargs - 1];
3380 int numargs; 3387 int numargs;
3381 int funcall_nargs; 3388 int funcall_nargs;
3382 3389
3383 CHECK_LIST (spread_arg); 3390 GET_EXTERNAL_LIST_LENGTH (spread_arg, numargs);
3384
3385 /*
3386 * Formerly we used a call to Flength here, but that is slow and
3387 * wasteful due to type checking, stack push/pop and initialization.
3388 * We know we're dealing with a cons, so open code it for speed.
3389 *
3390 * We call QUIT in the loop so that a circular arg list won't lock
3391 * up the editor.
3392 */
3393 for (numargs = 0, p = spread_arg ; CONSP (p) ; p = XCDR (p))
3394 {
3395 numargs++;
3396 QUIT;
3397 }
3398 if (! NILP (p))
3399 signal_simple_error ("Argument list must be nil-terminated", spread_arg);
3400 3391
3401 if (numargs == 0) 3392 if (numargs == 0)
3402 /* (apply foo 0 1 '()) */ 3393 /* (apply foo 0 1 '()) */
3403 return Ffuncall (nargs - 1, args); 3394 return Ffuncall (nargs - 1, args);
3404 else if (numargs == 1) 3395 else if (numargs == 1)
3413 /* +1 for function */ 3404 /* +1 for function */
3414 funcall_nargs = 1 + numargs; 3405 funcall_nargs = 1 + numargs;
3415 3406
3416 if (SYMBOLP (fun)) 3407 if (SYMBOLP (fun))
3417 fun = indirect_function (fun, 0); 3408 fun = indirect_function (fun, 0);
3418 if (UNBOUNDP (fun)) 3409
3419 { 3410 if (SUBRP (fun))
3420 /* Let funcall get the error */ 3411 {
3421 fun = args[0]; 3412 Lisp_Subr *subr = XSUBR (fun);
3422 }
3423 else if (SUBRP (fun))
3424 {
3425 struct Lisp_Subr *subr = XSUBR (fun);
3426 int max_args = subr->max_args; 3413 int max_args = subr->max_args;
3427 3414
3428 if (numargs < subr->min_args 3415 if (numargs < subr->min_args
3429 || (max_args >= 0 && max_args < numargs)) 3416 || (max_args >= 0 && max_args < numargs))
3430 { 3417 {
3435 /* Avoid having funcall cons up yet another new vector of arguments 3422 /* Avoid having funcall cons up yet another new vector of arguments
3436 by explicitly supplying nil's for optional values */ 3423 by explicitly supplying nil's for optional values */
3437 funcall_nargs += (max_args - numargs); 3424 funcall_nargs += (max_args - numargs);
3438 } 3425 }
3439 } 3426 }
3427 else if (UNBOUNDP (fun))
3428 {
3429 /* Let funcall get the error */
3430 fun = args[0];
3431 }
3432
3440 { 3433 {
3441 REGISTER int i; 3434 REGISTER int i;
3442 Lisp_Object *funcall_args = alloca_array (Lisp_Object, funcall_nargs); 3435 Lisp_Object *funcall_args = alloca_array (Lisp_Object, funcall_nargs);
3443 struct gcpro gcpro1; 3436 struct gcpro gcpro1;
3444 3437
3463 RETURN_UNGCPRO (Ffuncall (funcall_nargs, funcall_args)); 3456 RETURN_UNGCPRO (Ffuncall (funcall_nargs, funcall_args));
3464 } 3457 }
3465 } 3458 }
3466 3459
3467 3460
3468 /* FSFmacs has an extra arg EVAL_FLAG. If false, some of 3461 /* Apply lambda list FUN to the NARGS evaluated arguments in ARGS and
3469 the statements below are not done. But it's always true 3462 return the result of evaluation. */
3470 in all the calls to apply_lambda(). */
3471 3463
3472 static Lisp_Object 3464 static Lisp_Object
3473 apply_lambda (Lisp_Object fun, int numargs, Lisp_Object unevalled_args) 3465 funcall_lambda (Lisp_Object fun, int nargs, Lisp_Object args[])
3474 { 3466 {
3475 /* This function can GC */ 3467 /* This function can GC */
3476 struct gcpro gcpro1, gcpro2, gcpro3; 3468 Lisp_Object symbol, arglist, body, tail;
3477 REGISTER int i; 3469 int speccount = specpdl_depth();
3478 REGISTER Lisp_Object tem; 3470 REGISTER int i = 0;
3479 REGISTER Lisp_Object *arg_vector = alloca_array (Lisp_Object, numargs); 3471
3480 3472 tail = XCDR (fun);
3481 GCPRO3 (*arg_vector, unevalled_args, fun); 3473
3482 gcpro1.nvars = 0; 3474 if (!CONSP (tail))
3483 3475 goto invalid_function;
3484 for (i = 0; i < numargs;) 3476
3485 { 3477 arglist = XCAR (tail);
3486 /* 3478 body = XCDR (tail);
3487 * unevalled_args is always a normal list, or Feval would have 3479
3488 * rejected it, so use XCAR and XCDR. 3480 {
3489 */ 3481 int optional = 0, rest = 0;
3490 tem = XCAR (unevalled_args), unevalled_args = XCDR (unevalled_args); 3482
3491 tem = Feval (tem); 3483 EXTERNAL_LIST_LOOP_3 (symbol, arglist, tail)
3492 arg_vector[i++] = tem; 3484 {
3493 gcpro1.nvars = i; 3485 if (!SYMBOLP (symbol))
3494 } 3486 goto invalid_function;
3495 3487 if (EQ (symbol, Qand_rest))
3496 UNGCPRO; 3488 rest = 1;
3497 3489 else if (EQ (symbol, Qand_optional))
3498 backtrace_list->args = arg_vector; 3490 optional = 1;
3499 backtrace_list->nargs = i; 3491 else if (rest)
3500 backtrace_list->evalargs = 0; 3492 {
3501 tem = funcall_lambda (fun, numargs, arg_vector); 3493 specbind (symbol, Flist (nargs - i, &args[i]));
3502 3494 i = nargs;
3503 /* Do the debug-on-exit now, while arg_vector still exists. */ 3495 }
3504 if (backtrace_list->debug_on_exit) 3496 else if (i < nargs)
3505 tem = do_debug_on_exit (tem); 3497 specbind (symbol, args[i++]);
3506 /* Don't do it again when we return to eval. */ 3498 else if (!optional)
3507 backtrace_list->debug_on_exit = 0; 3499 goto wrong_number_of_arguments;
3508 return tem; 3500 else
3509 } 3501 specbind (symbol, Qnil);
3510 3502 }
3511 DEFUN ("fetch-bytecode", Ffetch_bytecode, 1, 1, 0, /* 3503 }
3512 If byte-compiled OBJECT is lazy-loaded, fetch it now.
3513 */
3514 (object))
3515 {
3516 if (COMPILED_FUNCTIONP (object)
3517 && CONSP (XCOMPILED_FUNCTION (object)->bytecodes))
3518 {
3519 Lisp_Object tem =
3520 read_doc_string (XCOMPILED_FUNCTION (object)->bytecodes);
3521 if (!CONSP (tem))
3522 signal_simple_error ("invalid lazy-loaded byte code", tem);
3523 /* v18 or v19 bytecode file. Need to Ebolify. */
3524 if (XCOMPILED_FUNCTION (object)->flags.ebolified
3525 && VECTORP (XCDR (tem)))
3526 ebolify_bytecode_constants (XCDR (tem));
3527 /* VERY IMPORTANT to purecopy here!!!!!
3528 See load_force_doc_string_unwind. */
3529 XCOMPILED_FUNCTION (object)->bytecodes = Fpurecopy (XCAR (tem));
3530 XCOMPILED_FUNCTION (object)->constants = Fpurecopy (XCDR (tem));
3531 }
3532 return object;
3533 }
3534
3535 /* Apply a Lisp function FUN to the NARGS evaluated arguments in ARG_VECTOR
3536 and return the result of evaluation.
3537 FUN must be either a lambda-expression or a compiled-code object. */
3538
3539 static Lisp_Object
3540 funcall_lambda (Lisp_Object fun, int nargs, Lisp_Object arg_vector[])
3541 {
3542 /* This function can GC */
3543 Lisp_Object val, tem;
3544 REGISTER Lisp_Object syms_left;
3545 REGISTER Lisp_Object next;
3546 int speccount = specpdl_depth_counter;
3547 REGISTER int i;
3548 int optional = 0, rest = 0;
3549
3550 if (CONSP (fun))
3551 syms_left = Fcar (XCDR (fun));
3552 else if (COMPILED_FUNCTIONP (fun))
3553 syms_left = XCOMPILED_FUNCTION (fun)->arglist;
3554 else abort ();
3555
3556 i = 0;
3557 for (; CONSP (syms_left); syms_left = XCDR (syms_left))
3558 {
3559 QUIT;
3560 next = XCAR (syms_left);
3561 if (!SYMBOLP (next))
3562 signal_error (Qinvalid_function, list1 (fun));
3563 if (EQ (next, Qand_rest))
3564 rest = 1;
3565 else if (EQ (next, Qand_optional))
3566 optional = 1;
3567 else if (rest)
3568 {
3569 specbind (next, Flist (nargs - i, &arg_vector[i]));
3570 i = nargs;
3571 }
3572 else if (i < nargs)
3573 {
3574 tem = arg_vector[i++];
3575 specbind (next, tem);
3576 }
3577 else if (!optional)
3578 return Fsignal (Qwrong_number_of_arguments,
3579 list2 (fun, make_int (nargs)));
3580 else
3581 specbind (next, Qnil);
3582 }
3583 3504
3584 if (i < nargs) 3505 if (i < nargs)
3585 return Fsignal (Qwrong_number_of_arguments, 3506 goto wrong_number_of_arguments;
3586 list2 (fun, make_int (nargs))); 3507
3587 3508 return unbind_to (speccount, Fprogn (body));
3588 if (CONSP (fun)) 3509
3589 val = Fprogn (Fcdr (XCDR (fun))); 3510 wrong_number_of_arguments:
3590 else 3511 return Fsignal (Qwrong_number_of_arguments, list2 (fun, make_int (nargs)));
3591 { 3512
3592 struct Lisp_Compiled_Function *b = XCOMPILED_FUNCTION (fun); 3513 invalid_function:
3593 /* If we have not actually read the bytecode string 3514 return Fsignal (Qinvalid_function, list1 (fun));
3594 and constants vector yet, fetch them from the file. */ 3515 }
3595 if (CONSP (b->bytecodes)) 3516
3596 Ffetch_bytecode (fun);
3597 val = Fbyte_code (b->bytecodes,
3598 b->constants,
3599 make_int (b->maxdepth));
3600 }
3601 return unbind_to (speccount, val);
3602 }
3603 3517
3604 /**********************************************************************/ 3518 /************************************************************************/
3605 /* Run hook variables in various ways. */ 3519 /* Run hook variables in various ways. */
3606 /**********************************************************************/ 3520 /************************************************************************/
3607 3521
3608 DEFUN ("run-hooks", Frun_hooks, 1, MANY, 0, /* 3522 DEFUN ("run-hooks", Frun_hooks, 1, MANY, 0, /*
3609 Run each hook in HOOKS. Major mode functions use this. 3523 Run each hook in HOOKS. Major mode functions use this.
3610 Each argument should be a symbol, a hook variable. 3524 Each argument should be a symbol, a hook variable.
3611 These symbols are processed in the order specified. 3525 These symbols are processed in the order specified.
3689 Lisp_Object 3603 Lisp_Object
3690 run_hook_with_args_in_buffer (struct buffer *buf, int nargs, Lisp_Object *args, 3604 run_hook_with_args_in_buffer (struct buffer *buf, int nargs, Lisp_Object *args,
3691 enum run_hooks_condition cond) 3605 enum run_hooks_condition cond)
3692 { 3606 {
3693 Lisp_Object sym, val, ret; 3607 Lisp_Object sym, val, ret;
3694 struct gcpro gcpro1, gcpro2;
3695 3608
3696 if (!initialized || preparing_for_armageddon) 3609 if (!initialized || preparing_for_armageddon)
3697 /* We need to bail out of here pronto. */ 3610 /* We need to bail out of here pronto. */
3698 return Qnil; 3611 return Qnil;
3699 3612
3712 args[0] = val; 3625 args[0] = val;
3713 return Ffuncall (nargs, args); 3626 return Ffuncall (nargs, args);
3714 } 3627 }
3715 else 3628 else
3716 { 3629 {
3630 struct gcpro gcpro1, gcpro2;
3717 GCPRO2 (sym, val); 3631 GCPRO2 (sym, val);
3718 3632
3719 for (; 3633 for (;
3720 CONSP (val) && ((cond == RUN_HOOKS_TO_COMPLETION) 3634 CONSP (val) && ((cond == RUN_HOOKS_TO_COMPLETION)
3721 || (cond == RUN_HOOKS_UNTIL_SUCCESS ? NILP (ret) 3635 || (cond == RUN_HOOKS_UNTIL_SUCCESS ? NILP (ret)
3782 except that it isn't necessary to gcpro ARGS[0]. */ 3696 except that it isn't necessary to gcpro ARGS[0]. */
3783 3697
3784 Lisp_Object 3698 Lisp_Object
3785 run_hook_list_with_args (Lisp_Object funlist, int nargs, Lisp_Object *args) 3699 run_hook_list_with_args (Lisp_Object funlist, int nargs, Lisp_Object *args)
3786 { 3700 {
3787 Lisp_Object sym; 3701 Lisp_Object sym = args[0];
3788 Lisp_Object val; 3702 Lisp_Object val;
3789 struct gcpro gcpro1, gcpro2; 3703 struct gcpro gcpro1, gcpro2;
3790 3704
3791 sym = args[0];
3792 GCPRO2 (sym, val); 3705 GCPRO2 (sym, val);
3793 3706
3794 for (val = funlist; CONSP (val); val = XCDR (val)) 3707 for (val = funlist; CONSP (val); val = XCDR (val))
3795 { 3708 {
3796 if (EQ (XCAR (val), Qt)) 3709 if (EQ (XCAR (val), Qt))
3872 Frun_hooks (1, &hook); 3785 Frun_hooks (1, &hook);
3873 return Qnil; 3786 return Qnil;
3874 } 3787 }
3875 3788
3876 3789
3877 /**********************************************************************/ 3790 /************************************************************************/
3878 /* Front-ends to eval, funcall, apply */ 3791 /* Front-ends to eval, funcall, apply */
3879 /**********************************************************************/ 3792 /************************************************************************/
3880 3793
3881 /* Apply fn to arg */ 3794 /* Apply fn to arg */
3882 Lisp_Object 3795 Lisp_Object
3883 apply1 (Lisp_Object fn, Lisp_Object arg) 3796 apply1 (Lisp_Object fn, Lisp_Object arg)
3884 { 3797 {
4064 if (current_buffer == buf) 3977 if (current_buffer == buf)
4065 return call0 (fn); 3978 return call0 (fn);
4066 else 3979 else
4067 { 3980 {
4068 Lisp_Object val; 3981 Lisp_Object val;
4069 int speccount = specpdl_depth_counter; 3982 int speccount = specpdl_depth();
4070 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); 3983 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
4071 set_buffer_internal (buf); 3984 set_buffer_internal (buf);
4072 val = call0 (fn); 3985 val = call0 (fn);
4073 unbind_to (speccount, Qnil); 3986 unbind_to (speccount, Qnil);
4074 return val; 3987 return val;
4082 if (current_buffer == buf) 3995 if (current_buffer == buf)
4083 return call1 (fn, arg0); 3996 return call1 (fn, arg0);
4084 else 3997 else
4085 { 3998 {
4086 Lisp_Object val; 3999 Lisp_Object val;
4087 int speccount = specpdl_depth_counter; 4000 int speccount = specpdl_depth();
4088 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); 4001 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
4089 set_buffer_internal (buf); 4002 set_buffer_internal (buf);
4090 val = call1 (fn, arg0); 4003 val = call1 (fn, arg0);
4091 unbind_to (speccount, Qnil); 4004 unbind_to (speccount, Qnil);
4092 return val; 4005 return val;
4100 if (current_buffer == buf) 4013 if (current_buffer == buf)
4101 return call2 (fn, arg0, arg1); 4014 return call2 (fn, arg0, arg1);
4102 else 4015 else
4103 { 4016 {
4104 Lisp_Object val; 4017 Lisp_Object val;
4105 int speccount = specpdl_depth_counter; 4018 int speccount = specpdl_depth();
4106 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); 4019 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
4107 set_buffer_internal (buf); 4020 set_buffer_internal (buf);
4108 val = call2 (fn, arg0, arg1); 4021 val = call2 (fn, arg0, arg1);
4109 unbind_to (speccount, Qnil); 4022 unbind_to (speccount, Qnil);
4110 return val; 4023 return val;
4118 if (current_buffer == buf) 4031 if (current_buffer == buf)
4119 return call3 (fn, arg0, arg1, arg2); 4032 return call3 (fn, arg0, arg1, arg2);
4120 else 4033 else
4121 { 4034 {
4122 Lisp_Object val; 4035 Lisp_Object val;
4123 int speccount = specpdl_depth_counter; 4036 int speccount = specpdl_depth();
4124 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); 4037 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
4125 set_buffer_internal (buf); 4038 set_buffer_internal (buf);
4126 val = call3 (fn, arg0, arg1, arg2); 4039 val = call3 (fn, arg0, arg1, arg2);
4127 unbind_to (speccount, Qnil); 4040 unbind_to (speccount, Qnil);
4128 return val; 4041 return val;
4137 if (current_buffer == buf) 4050 if (current_buffer == buf)
4138 return call4 (fn, arg0, arg1, arg2, arg3); 4051 return call4 (fn, arg0, arg1, arg2, arg3);
4139 else 4052 else
4140 { 4053 {
4141 Lisp_Object val; 4054 Lisp_Object val;
4142 int speccount = specpdl_depth_counter; 4055 int speccount = specpdl_depth();
4143 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); 4056 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
4144 set_buffer_internal (buf); 4057 set_buffer_internal (buf);
4145 val = call4 (fn, arg0, arg1, arg2, arg3); 4058 val = call4 (fn, arg0, arg1, arg2, arg3);
4146 unbind_to (speccount, Qnil); 4059 unbind_to (speccount, Qnil);
4147 return val; 4060 return val;
4154 if (current_buffer == buf) 4067 if (current_buffer == buf)
4155 return Feval (form); 4068 return Feval (form);
4156 else 4069 else
4157 { 4070 {
4158 Lisp_Object val; 4071 Lisp_Object val;
4159 int speccount = specpdl_depth_counter; 4072 int speccount = specpdl_depth();
4160 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); 4073 record_unwind_protect (Fset_buffer, Fcurrent_buffer ());
4161 set_buffer_internal (buf); 4074 set_buffer_internal (buf);
4162 val = Feval (form); 4075 val = Feval (form);
4163 unbind_to (speccount, Qnil); 4076 unbind_to (speccount, Qnil);
4164 return val; 4077 return val;
4165 } 4078 }
4166 } 4079 }
4167 4080
4168 4081
4169 /***** Error-catching front-ends to eval, funcall, apply */ 4082 /************************************************************************/
4083 /* Error-catching front-ends to eval, funcall, apply */
4084 /************************************************************************/
4170 4085
4171 /* Call function fn on no arguments, with condition handler */ 4086 /* Call function fn on no arguments, with condition handler */
4172 Lisp_Object 4087 Lisp_Object
4173 call0_with_handler (Lisp_Object handler, Lisp_Object fn) 4088 call0_with_handler (Lisp_Object handler, Lisp_Object fn)
4174 { 4089 {
4277 4192
4278 Lisp_Object 4193 Lisp_Object
4279 eval_in_buffer_trapping_errors (CONST char *warning_string, 4194 eval_in_buffer_trapping_errors (CONST char *warning_string,
4280 struct buffer *buf, Lisp_Object form) 4195 struct buffer *buf, Lisp_Object form)
4281 { 4196 {
4282 int speccount = specpdl_depth_counter; 4197 int speccount = specpdl_depth();
4283 Lisp_Object tem; 4198 Lisp_Object tem;
4284 Lisp_Object buffer; 4199 Lisp_Object buffer;
4285 Lisp_Object cons; 4200 Lisp_Object cons;
4286 Lisp_Object opaque; 4201 Lisp_Object opaque;
4287 struct gcpro gcpro1, gcpro2; 4202 struct gcpro gcpro1, gcpro2;
4327 return Qnil; 4242 return Qnil;
4328 tem = find_symbol_value (hook_symbol); 4243 tem = find_symbol_value (hook_symbol);
4329 if (NILP (tem) || UNBOUNDP (tem)) 4244 if (NILP (tem) || UNBOUNDP (tem))
4330 return Qnil; 4245 return Qnil;
4331 4246
4332 speccount = specpdl_depth_counter; 4247 speccount = specpdl_depth();
4333 specbind (Qinhibit_quit, Qt); 4248 specbind (Qinhibit_quit, Qt);
4334 4249
4335 opaque = (warning_string ? make_opaque_ptr (warning_string) : Qnil); 4250 opaque = (warning_string ? make_opaque_ptr (warning_string) : Qnil);
4336 GCPRO1 (opaque); 4251 GCPRO1 (opaque);
4337 /* Qerror not Qt, so you can get a backtrace */ 4252 /* Qerror not Qt, so you can get a backtrace */
4351 Lisp_Object 4266 Lisp_Object
4352 safe_run_hook_trapping_errors (CONST char *warning_string, 4267 safe_run_hook_trapping_errors (CONST char *warning_string,
4353 Lisp_Object hook_symbol, 4268 Lisp_Object hook_symbol,
4354 int allow_quit) 4269 int allow_quit)
4355 { 4270 {
4356 int speccount = specpdl_depth_counter; 4271 int speccount = specpdl_depth();
4357 Lisp_Object tem; 4272 Lisp_Object tem;
4358 Lisp_Object cons = Qnil; 4273 Lisp_Object cons = Qnil;
4359 struct gcpro gcpro1; 4274 struct gcpro gcpro1;
4360 4275
4361 if (!initialized || preparing_for_armageddon) 4276 if (!initialized || preparing_for_armageddon)
4408 if (NILP (tem) || UNBOUNDP (tem)) 4323 if (NILP (tem) || UNBOUNDP (tem))
4409 return Qnil; 4324 return Qnil;
4410 } 4325 }
4411 4326
4412 GCPRO2 (opaque, function); 4327 GCPRO2 (opaque, function);
4413 speccount = specpdl_depth_counter; 4328 speccount = specpdl_depth();
4414 specbind (Qinhibit_quit, Qt); 4329 specbind (Qinhibit_quit, Qt);
4415 /* gc_currently_forbidden = 1; Currently no reason to do this; */ 4330 /* gc_currently_forbidden = 1; Currently no reason to do this; */
4416 4331
4417 opaque = (warning_string ? make_opaque_ptr (warning_string) : Qnil); 4332 opaque = (warning_string ? make_opaque_ptr (warning_string) : Qnil);
4418 /* Qerror not Qt, so you can get a backtrace */ 4333 /* Qerror not Qt, so you can get a backtrace */
4443 4358
4444 Lisp_Object 4359 Lisp_Object
4445 call1_trapping_errors (CONST char *warning_string, Lisp_Object function, 4360 call1_trapping_errors (CONST char *warning_string, Lisp_Object function,
4446 Lisp_Object object) 4361 Lisp_Object object)
4447 { 4362 {
4448 int speccount = specpdl_depth_counter; 4363 int speccount = specpdl_depth();
4449 Lisp_Object tem; 4364 Lisp_Object tem;
4450 Lisp_Object cons = Qnil; 4365 Lisp_Object cons = Qnil;
4451 Lisp_Object opaque = Qnil; 4366 Lisp_Object opaque = Qnil;
4452 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 4367 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
4453 4368
4480 4395
4481 Lisp_Object 4396 Lisp_Object
4482 call2_trapping_errors (CONST char *warning_string, Lisp_Object function, 4397 call2_trapping_errors (CONST char *warning_string, Lisp_Object function,
4483 Lisp_Object object1, Lisp_Object object2) 4398 Lisp_Object object1, Lisp_Object object2)
4484 { 4399 {
4485 int speccount = specpdl_depth_counter; 4400 int speccount = specpdl_depth();
4486 Lisp_Object tem; 4401 Lisp_Object tem;
4487 Lisp_Object cons = Qnil; 4402 Lisp_Object cons = Qnil;
4488 Lisp_Object opaque = Qnil; 4403 Lisp_Object opaque = Qnil;
4489 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; 4404 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
4490 4405
4513 /* gc_currently_forbidden = 0; */ 4428 /* gc_currently_forbidden = 0; */
4514 return unbind_to (speccount, tem); 4429 return unbind_to (speccount, tem);
4515 } 4430 }
4516 4431
4517 4432
4518 /**********************************************************************/ 4433 /************************************************************************/
4519 /* The special binding stack */ 4434 /* The special binding stack */
4520 /**********************************************************************/ 4435 /* Most C code should simply use specbind() and unbind_to(). */
4436 /* When performance is critical, use the macros in backtrace.h. */
4437 /************************************************************************/
4521 4438
4522 #define min_max_specpdl_size 400 4439 #define min_max_specpdl_size 400
4523 4440
4524 static void 4441 void
4525 grow_specpdl (void) 4442 grow_specpdl (size_t reserved)
4526 { 4443 {
4527 if (specpdl_size >= max_specpdl_size) 4444 size_t size_needed = specpdl_depth() + reserved;
4445 if (size_needed >= max_specpdl_size)
4528 { 4446 {
4529 if (max_specpdl_size < min_max_specpdl_size) 4447 if (max_specpdl_size < min_max_specpdl_size)
4530 max_specpdl_size = min_max_specpdl_size; 4448 max_specpdl_size = min_max_specpdl_size;
4531 if (specpdl_size >= max_specpdl_size) 4449 if (size_needed >= max_specpdl_size)
4532 { 4450 {
4533 if (!NILP (Vdebug_on_error) || !NILP (Vdebug_on_signal)) 4451 if (!NILP (Vdebug_on_error) ||
4452 !NILP (Vdebug_on_signal))
4534 /* Leave room for some specpdl in the debugger. */ 4453 /* Leave room for some specpdl in the debugger. */
4535 max_specpdl_size = specpdl_size + 100; 4454 max_specpdl_size = size_needed + 100;
4536 continuable_error 4455 continuable_error
4537 ("Variable binding depth exceeds max-specpdl-size"); 4456 ("Variable binding depth exceeds max-specpdl-size");
4538 } 4457 }
4539 } 4458 }
4540 specpdl_size *= 2; 4459 while (specpdl_size < size_needed)
4541 if (specpdl_size > max_specpdl_size) 4460 {
4542 specpdl_size = max_specpdl_size; 4461 specpdl_size *= 2;
4462 if (specpdl_size > max_specpdl_size)
4463 specpdl_size = max_specpdl_size;
4464 }
4543 XREALLOC_ARRAY (specpdl, struct specbinding, specpdl_size); 4465 XREALLOC_ARRAY (specpdl, struct specbinding, specpdl_size);
4544 specpdl_ptr = specpdl + specpdl_depth_counter; 4466 specpdl_ptr = specpdl + specpdl_depth();
4545 } 4467 }
4546 4468
4547 4469
4548 /* Handle unbinding buffer-local variables */ 4470 /* Handle unbinding buffer-local variables */
4549 static Lisp_Object 4471 static Lisp_Object
4618 4540
4619 4541
4620 void 4542 void
4621 specbind (Lisp_Object symbol, Lisp_Object value) 4543 specbind (Lisp_Object symbol, Lisp_Object value)
4622 { 4544 {
4623 int buffer_local; 4545 SPECBIND (symbol, value);
4624 4546 }
4625 CHECK_SYMBOL (symbol); 4547
4626 4548 void
4627 if (specpdl_depth_counter >= specpdl_size) 4549 specbind_magic (Lisp_Object symbol, Lisp_Object value)
4628 grow_specpdl (); 4550 {
4629 4551 int buffer_local =
4630 buffer_local = symbol_value_buffer_local_info (symbol, current_buffer); 4552 symbol_value_buffer_local_info (symbol, current_buffer);
4553
4631 if (buffer_local == 0) 4554 if (buffer_local == 0)
4632 { 4555 {
4633 specpdl_ptr->old_value = find_symbol_value (symbol); 4556 specpdl_ptr->old_value = find_symbol_value (symbol);
4634 specpdl_ptr->func = 0; /* Handled specially by unbind_to */ 4557 specpdl_ptr->func = 0; /* Handled specially by unbind_to */
4635 } 4558 }
4656 4579
4657 void 4580 void
4658 record_unwind_protect (Lisp_Object (*function) (Lisp_Object arg), 4581 record_unwind_protect (Lisp_Object (*function) (Lisp_Object arg),
4659 Lisp_Object arg) 4582 Lisp_Object arg)
4660 { 4583 {
4661 if (specpdl_depth_counter >= specpdl_size) 4584 SPECPDL_RESERVE (1);
4662 grow_specpdl ();
4663 specpdl_ptr->func = function; 4585 specpdl_ptr->func = function;
4664 specpdl_ptr->symbol = Qnil; 4586 specpdl_ptr->symbol = Qnil;
4665 specpdl_ptr->old_value = arg; 4587 specpdl_ptr->old_value = arg;
4666 specpdl_ptr++; 4588 specpdl_ptr++;
4667 specpdl_depth_counter++; 4589 specpdl_depth_counter++;
4668 } 4590 }
4669 4591
4670 extern int check_sigio (void); 4592 extern int check_sigio (void);
4671 4593
4594 /* Unwind the stack till specpdl_depth() == COUNT.
4595 VALUE is not used, except that, purely as a convenience to the
4596 caller, it is protected from garbage-protection. */
4672 Lisp_Object 4597 Lisp_Object
4673 unbind_to (int count, Lisp_Object value) 4598 unbind_to (int count, Lisp_Object value)
4674 { 4599 {
4600 UNBIND_TO_GCPRO (count, value);
4601 return value;
4602 }
4603
4604 /* Don't call this directly.
4605 Only for use by UNBIND_TO* macros in backtrace.h */
4606 void
4607 unbind_to_hairy (int count)
4608 {
4675 int quitf; 4609 int quitf;
4676 struct gcpro gcpro1;
4677
4678 GCPRO1 (value);
4679 4610
4680 check_quit (); /* make Vquit_flag accurate */ 4611 check_quit (); /* make Vquit_flag accurate */
4681 quitf = !NILP (Vquit_flag); 4612 quitf = !NILP (Vquit_flag);
4682 Vquit_flag = Qnil; 4613 Vquit_flag = Qnil;
4683 4614
4615 ++specpdl_ptr;
4616 ++specpdl_depth_counter;
4617
4684 while (specpdl_depth_counter != count) 4618 while (specpdl_depth_counter != count)
4685 { 4619 {
4686 Lisp_Object ovalue;
4687 --specpdl_ptr; 4620 --specpdl_ptr;
4688 --specpdl_depth_counter; 4621 --specpdl_depth_counter;
4689 4622
4690 ovalue = specpdl_ptr->old_value;
4691 if (specpdl_ptr->func != 0) 4623 if (specpdl_ptr->func != 0)
4692 /* An unwind-protect */ 4624 /* An unwind-protect */
4693 (*specpdl_ptr->func) (ovalue); 4625 (*specpdl_ptr->func) (specpdl_ptr->old_value);
4694 else 4626 else
4695 Fset (specpdl_ptr->symbol, ovalue); 4627 {
4696 4628 /* We checked symbol for validity when we specbound it,
4629 so only need to call Fset if symbol has magic value. */
4630 struct Lisp_Symbol *sym = XSYMBOL (specpdl_ptr->symbol);
4631 if (!SYMBOL_VALUE_MAGIC_P (sym->value))
4632 sym->value = specpdl_ptr->old_value;
4633 else
4634 Fset (specpdl_ptr->symbol, specpdl_ptr->old_value);
4635 }
4636
4637 #if 0 /* martin */
4697 #ifndef EXCEEDINGLY_QUESTIONABLE_CODE 4638 #ifndef EXCEEDINGLY_QUESTIONABLE_CODE
4698 /* There should never be anything here for us to remove. 4639 /* There should never be anything here for us to remove.
4699 If so, it indicates a logic error in Emacs. Catches 4640 If so, it indicates a logic error in Emacs. Catches
4700 should get removed when a throw or signal occurs, or 4641 should get removed when a throw or signal occurs, or
4701 when a catch or condition-case exits normally. But 4642 when a catch or condition-case exits normally. But
4709 { 4650 {
4710 catchlist = catchlist->next; 4651 catchlist = catchlist->next;
4711 /* Don't mess with gcprolist, backtrace_list here */ 4652 /* Don't mess with gcprolist, backtrace_list here */
4712 } 4653 }
4713 #endif 4654 #endif
4655 #endif
4714 } 4656 }
4715 if (quitf) 4657 if (quitf)
4716 Vquit_flag = Qt; 4658 Vquit_flag = Qt;
4717 4659 }
4718 UNGCPRO; 4660
4719
4720 return value;
4721 }
4722
4723
4724 int
4725 specpdl_depth (void)
4726 {
4727 return specpdl_depth_counter;
4728 }
4729 4661
4730 4662
4731 /* Get the value of symbol's global binding, even if that binding is 4663 /* Get the value of symbol's global binding, even if that binding is
4732 not now dynamically visible. May return Qunbound or magic values. */ 4664 not now dynamically visible. May return Qunbound or magic values. */
4733 4665
4765 } 4697 }
4766 4698
4767 #endif /* 0 */ 4699 #endif /* 0 */
4768 4700
4769 4701
4770 /**********************************************************************/ 4702 /************************************************************************/
4771 /* Backtraces */ 4703 /* Backtraces */
4772 /**********************************************************************/ 4704 /************************************************************************/
4773 4705
4774 DEFUN ("backtrace-debug", Fbacktrace_debug, 2, 2, 0, /* 4706 DEFUN ("backtrace-debug", Fbacktrace_debug, 2, 2, 0, /*
4775 Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG. 4707 Set the debug-on-exit flag of eval frame LEVEL levels down to FLAG.
4776 The debugger is entered when that frame exits, if the flag is non-nil. 4708 The debugger is entered when that frame exits, if the flag is non-nil.
4777 */ 4709 */
4830 (stream, detailed)) 4762 (stream, detailed))
4831 { 4763 {
4832 /* This function can GC */ 4764 /* This function can GC */
4833 struct backtrace *backlist = backtrace_list; 4765 struct backtrace *backlist = backtrace_list;
4834 struct catchtag *catches = catchlist; 4766 struct catchtag *catches = catchlist;
4835 int speccount = specpdl_depth_counter; 4767 int speccount = specpdl_depth();
4836 4768
4837 int old_nl = print_escape_newlines; 4769 int old_nl = print_escape_newlines;
4838 int old_pr = print_readably; 4770 int old_pr = print_readably;
4839 Lisp_Object old_level = Vprint_level; 4771 Lisp_Object old_level = Vprint_level;
4840 Lisp_Object oiq = Vinhibit_quit; 4772 Lisp_Object oiq = Vinhibit_quit;
4987 return Fcons (Qt, Fcons (*backlist->function, tem)); 4919 return Fcons (Qt, Fcons (*backlist->function, tem));
4988 } 4920 }
4989 } 4921 }
4990 4922
4991 4923
4992 /**********************************************************************/ 4924 /************************************************************************/
4993 /* Warnings */ 4925 /* Warnings */
4994 /**********************************************************************/ 4926 /************************************************************************/
4995 4927
4996 void 4928 void
4997 warn_when_safe_lispobj (Lisp_Object class, Lisp_Object level, 4929 warn_when_safe_lispobj (Lisp_Object class, Lisp_Object level,
4998 Lisp_Object obj) 4930 Lisp_Object obj)
4999 { 4931 {
5009 4941
5010 /* #### This should probably accept Lisp objects; but then we have 4942 /* #### This should probably accept Lisp objects; but then we have
5011 to make sure that Feval() isn't called, since it might not be safe. 4943 to make sure that Feval() isn't called, since it might not be safe.
5012 4944
5013 An alternative approach is to just pass some non-string type of 4945 An alternative approach is to just pass some non-string type of
5014 Lisp Object to warn_when_safe_lispobj(); `prin1-to-string' will 4946 Lisp_Object to warn_when_safe_lispobj(); `prin1-to-string' will
5015 automatically be called when it is safe to do so. */ 4947 automatically be called when it is safe to do so. */
5016 4948
5017 void 4949 void
5018 warn_when_safe (Lisp_Object class, Lisp_Object level, CONST char *fmt, ...) 4950 warn_when_safe (Lisp_Object class, Lisp_Object level, CONST char *fmt, ...)
5019 { 4951 {
5029 } 4961 }
5030 4962
5031 4963
5032 4964
5033 4965
5034 /**********************************************************************/ 4966 /************************************************************************/
5035 /* Initialization */ 4967 /* Initialization */
5036 /**********************************************************************/ 4968 /************************************************************************/
5037 4969
5038 void 4970 void
5039 syms_of_eval (void) 4971 syms_of_eval (void)
5040 { 4972 {
5041 defsymbol (&Qinhibit_quit, "inhibit-quit"); 4973 defsymbol (&Qinhibit_quit, "inhibit-quit");
5056 defsymbol (&Qdefun, "defun"); 4988 defsymbol (&Qdefun, "defun");
5057 defsymbol (&Qprogn, "progn"); 4989 defsymbol (&Qprogn, "progn");
5058 defsymbol (&Qvalues, "values"); 4990 defsymbol (&Qvalues, "values");
5059 defsymbol (&Qdisplay_warning, "display-warning"); 4991 defsymbol (&Qdisplay_warning, "display-warning");
5060 defsymbol (&Qrun_hooks, "run-hooks"); 4992 defsymbol (&Qrun_hooks, "run-hooks");
4993 defsymbol (&Qif, "if");
5061 4994
5062 DEFSUBR (For); 4995 DEFSUBR (For);
5063 DEFSUBR (Fand); 4996 DEFSUBR (Fand);
5064 DEFSUBR (Fif); 4997 DEFSUBR (Fif);
4998 DEFSUBR_MACRO (Fwhen);
4999 DEFSUBR_MACRO (Funless);
5065 DEFSUBR (Fcond); 5000 DEFSUBR (Fcond);
5066 DEFSUBR (Fprogn); 5001 DEFSUBR (Fprogn);
5067 DEFSUBR (Fprog1); 5002 DEFSUBR (Fprog1);
5068 DEFSUBR (Fprog2); 5003 DEFSUBR (Fprog2);
5069 DEFSUBR (Fsetq); 5004 DEFSUBR (Fsetq);
5089 DEFSUBR (Fcommand_execute); 5024 DEFSUBR (Fcommand_execute);
5090 DEFSUBR (Fautoload); 5025 DEFSUBR (Fautoload);
5091 DEFSUBR (Feval); 5026 DEFSUBR (Feval);
5092 DEFSUBR (Fapply); 5027 DEFSUBR (Fapply);
5093 DEFSUBR (Ffuncall); 5028 DEFSUBR (Ffuncall);
5029 DEFSUBR (Ffunctionp);
5094 DEFSUBR (Ffunction_min_args); 5030 DEFSUBR (Ffunction_min_args);
5095 DEFSUBR (Ffunction_max_args); 5031 DEFSUBR (Ffunction_max_args);
5096 DEFSUBR (Frun_hooks); 5032 DEFSUBR (Frun_hooks);
5097 DEFSUBR (Frun_hook_with_args); 5033 DEFSUBR (Frun_hook_with_args);
5098 DEFSUBR (Frun_hook_with_args_until_success); 5034 DEFSUBR (Frun_hook_with_args_until_success);
5099 DEFSUBR (Frun_hook_with_args_until_failure); 5035 DEFSUBR (Frun_hook_with_args_until_failure);
5100 DEFSUBR (Ffetch_bytecode);
5101 DEFSUBR (Fbacktrace_debug); 5036 DEFSUBR (Fbacktrace_debug);
5102 DEFSUBR (Fbacktrace); 5037 DEFSUBR (Fbacktrace);
5103 DEFSUBR (Fbacktrace_frame); 5038 DEFSUBR (Fbacktrace_frame);
5104 } 5039 }
5105 5040
5247 specpdl_depth_counter = 0; 5182 specpdl_depth_counter = 0;
5248 specpdl = xnew_array (struct specbinding, specpdl_size); 5183 specpdl = xnew_array (struct specbinding, specpdl_size);
5249 /* XEmacs change: increase these values. */ 5184 /* XEmacs change: increase these values. */
5250 max_specpdl_size = 3000; 5185 max_specpdl_size = 3000;
5251 max_lisp_eval_depth = 500; 5186 max_lisp_eval_depth = 500;
5187 #if 0 /* no longer used */
5252 throw_level = 0; 5188 throw_level = 0;
5189 #endif
5253 5190
5254 reinit_eval (); 5191 reinit_eval ();
5255 } 5192 }