aboutsummaryrefslogtreecommitdiffstats
path: root/src/eval.c
diff options
context:
space:
mode:
authorJoakim Verona2012-09-03 17:30:17 +0200
committerJoakim Verona2012-09-03 17:30:17 +0200
commit4a37733c693d59a9b83a3fb2d0c7f9461d149f60 (patch)
treea33402e09342f748baebf0e4f5a1e40538e620f4 /src/eval.c
parent5436d1df5e2ba0b4d4f72b03a1cd09b20403654b (diff)
parentdcde497f27945c3ca4ce8c21f655ef6f627acdd2 (diff)
downloademacs-4a37733c693d59a9b83a3fb2d0c7f9461d149f60.tar.gz
emacs-4a37733c693d59a9b83a3fb2d0c7f9461d149f60.zip
upstream
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c126
1 files changed, 56 insertions, 70 deletions
diff --git a/src/eval.c b/src/eval.c
index 771cd7b160a..3a4953665e3 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -131,9 +131,23 @@ int handling_signal;
131Lisp_Object inhibit_lisp_code; 131Lisp_Object inhibit_lisp_code;
132 132
133static Lisp_Object funcall_lambda (Lisp_Object, ptrdiff_t, Lisp_Object *); 133static Lisp_Object funcall_lambda (Lisp_Object, ptrdiff_t, Lisp_Object *);
134static int interactive_p (int); 134static bool interactive_p (void);
135static Lisp_Object apply_lambda (Lisp_Object fun, Lisp_Object args); 135static Lisp_Object apply_lambda (Lisp_Object fun, Lisp_Object args);
136 136
137/* Functions to set Lisp_Object slots of struct specbinding. */
138
139static inline void
140set_specpdl_symbol (Lisp_Object symbol)
141{
142 specpdl_ptr->symbol = symbol;
143}
144
145static inline void
146set_specpdl_old_value (Lisp_Object oldval)
147{
148 specpdl_ptr->old_value = oldval;
149}
150
137void 151void
138init_eval_once (void) 152init_eval_once (void)
139{ 153{
@@ -180,7 +194,7 @@ restore_stack_limits (Lisp_Object data)
180static Lisp_Object 194static Lisp_Object
181call_debugger (Lisp_Object arg) 195call_debugger (Lisp_Object arg)
182{ 196{
183 int debug_while_redisplaying; 197 bool debug_while_redisplaying;
184 ptrdiff_t count = SPECPDL_INDEX (); 198 ptrdiff_t count = SPECPDL_INDEX ();
185 Lisp_Object val; 199 Lisp_Object val;
186 EMACS_INT old_max = max_specpdl_size; 200 EMACS_INT old_max = max_specpdl_size;
@@ -511,7 +525,7 @@ spec that specifies non-nil unconditionally (such as \"p\"); or (ii)
511use `called-interactively-p'. */) 525use `called-interactively-p'. */)
512 (void) 526 (void)
513{ 527{
514 return interactive_p (1) ? Qt : Qnil; 528 return interactive_p () ? Qt : Qnil;
515} 529}
516 530
517 531
@@ -530,26 +544,23 @@ thinking of using it for any other purpose, it is quite likely that
530you're making a mistake. Think: what do you want to do when the 544you're making a mistake. Think: what do you want to do when the
531command is called from a keyboard macro? 545command is called from a keyboard macro?
532 546
533This function is meant for implementing advice and other 547Instead of using this function, it is sometimes cleaner to give your
534function-modifying features. Instead of using this, it is sometimes 548function an extra optional argument whose `interactive' spec specifies
535cleaner to give your function an extra optional argument whose 549non-nil unconditionally (\"p\" is a good way to do this), or via
536`interactive' spec specifies non-nil unconditionally (\"p\" is a good 550\(not (or executing-kbd-macro noninteractive)). */)
537way to do this), or via (not (or executing-kbd-macro noninteractive)). */)
538 (Lisp_Object kind) 551 (Lisp_Object kind)
539{ 552{
540 return ((INTERACTIVE || !EQ (kind, intern ("interactive"))) 553 return (((INTERACTIVE || !EQ (kind, intern ("interactive")))
541 && interactive_p (1)) ? Qt : Qnil; 554 && interactive_p ())
555 ? Qt : Qnil);
542} 556}
543 557
544 558
545/* Return 1 if function in which this appears was called using 559/* Return true if function in which this appears was called using
546 call-interactively. 560 call-interactively and is not a built-in. */
547 561
548 EXCLUDE_SUBRS_P non-zero means always return 0 if the function 562static bool
549 called is a built-in. */ 563interactive_p (void)
550
551static int
552interactive_p (int exclude_subrs_p)
553{ 564{
554 struct backtrace *btp; 565 struct backtrace *btp;
555 Lisp_Object fun; 566 Lisp_Object fun;
@@ -578,9 +589,9 @@ interactive_p (int exclude_subrs_p)
578 /* `btp' now points at the frame of the innermost function that isn't 589 /* `btp' now points at the frame of the innermost function that isn't
579 a special form, ignoring frames for Finteractive_p and/or 590 a special form, ignoring frames for Finteractive_p and/or
580 Fbytecode at the top. If this frame is for a built-in function 591 Fbytecode at the top. If this frame is for a built-in function
581 (such as load or eval-region) return nil. */ 592 (such as load or eval-region) return false. */
582 fun = Findirect_function (*btp->function, Qnil); 593 fun = Findirect_function (*btp->function, Qnil);
583 if (exclude_subrs_p && SUBRP (fun)) 594 if (SUBRP (fun))
584 return 0; 595 return 0;
585 596
586 /* `btp' points to the frame of a Lisp function that called interactive-p. 597 /* `btp' points to the frame of a Lisp function that called interactive-p.
@@ -1088,7 +1099,7 @@ internal_catch (Lisp_Object tag, Lisp_Object (*func) (Lisp_Object), Lisp_Object
1088static _Noreturn void 1099static _Noreturn void
1089unwind_to_catch (struct catchtag *catch, Lisp_Object value) 1100unwind_to_catch (struct catchtag *catch, Lisp_Object value)
1090{ 1101{
1091 int last_time; 1102 bool last_time;
1092 1103
1093 /* Save the value in the tag. */ 1104 /* Save the value in the tag. */
1094 catch->val = value; 1105 catch->val = value;
@@ -1437,8 +1448,8 @@ internal_condition_case_n (Lisp_Object (*bfun) (ptrdiff_t, Lisp_Object *),
1437 1448
1438 1449
1439static Lisp_Object find_handler_clause (Lisp_Object, Lisp_Object); 1450static Lisp_Object find_handler_clause (Lisp_Object, Lisp_Object);
1440static int maybe_call_debugger (Lisp_Object conditions, Lisp_Object sig, 1451static bool maybe_call_debugger (Lisp_Object conditions, Lisp_Object sig,
1441 Lisp_Object data); 1452 Lisp_Object data);
1442 1453
1443void 1454void
1444process_quit_flag (void) 1455process_quit_flag (void)
@@ -1543,7 +1554,7 @@ See also the function `condition-case'. */)
1543 if requested". */ 1554 if requested". */
1544 || EQ (h->handler, Qerror))) 1555 || EQ (h->handler, Qerror)))
1545 { 1556 {
1546 int debugger_called 1557 bool debugger_called
1547 = maybe_call_debugger (conditions, error_symbol, data); 1558 = maybe_call_debugger (conditions, error_symbol, data);
1548 /* We can't return values to code which signaled an error, but we 1559 /* We can't return values to code which signaled an error, but we
1549 can continue code which has signaled a quit. */ 1560 can continue code which has signaled a quit. */
@@ -1637,10 +1648,10 @@ signal_error (const char *s, Lisp_Object arg)
1637} 1648}
1638 1649
1639 1650
1640/* Return nonzero if LIST is a non-nil atom or 1651/* Return true if LIST is a non-nil atom or
1641 a list containing one of CONDITIONS. */ 1652 a list containing one of CONDITIONS. */
1642 1653
1643static int 1654static bool
1644wants_debugger (Lisp_Object list, Lisp_Object conditions) 1655wants_debugger (Lisp_Object list, Lisp_Object conditions)
1645{ 1656{
1646 if (NILP (list)) 1657 if (NILP (list))
@@ -1660,15 +1671,15 @@ wants_debugger (Lisp_Object list, Lisp_Object conditions)
1660 return 0; 1671 return 0;
1661} 1672}
1662 1673
1663/* Return 1 if an error with condition-symbols CONDITIONS, 1674/* Return true if an error with condition-symbols CONDITIONS,
1664 and described by SIGNAL-DATA, should skip the debugger 1675 and described by SIGNAL-DATA, should skip the debugger
1665 according to debugger-ignored-errors. */ 1676 according to debugger-ignored-errors. */
1666 1677
1667static int 1678static bool
1668skip_debugger (Lisp_Object conditions, Lisp_Object data) 1679skip_debugger (Lisp_Object conditions, Lisp_Object data)
1669{ 1680{
1670 Lisp_Object tail; 1681 Lisp_Object tail;
1671 int first_string = 1; 1682 bool first_string = 1;
1672 Lisp_Object error_message; 1683 Lisp_Object error_message;
1673 1684
1674 error_message = Qnil; 1685 error_message = Qnil;
@@ -1703,7 +1714,7 @@ skip_debugger (Lisp_Object conditions, Lisp_Object data)
1703 = SIG is the error symbol, and DATA is the rest of the data. 1714 = SIG is the error symbol, and DATA is the rest of the data.
1704 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA). 1715 = SIG is nil, and DATA is (SYMBOL . REST-OF-DATA).
1705 This is for memory-full errors only. */ 1716 This is for memory-full errors only. */
1706static int 1717static bool
1707maybe_call_debugger (Lisp_Object conditions, Lisp_Object sig, Lisp_Object data) 1718maybe_call_debugger (Lisp_Object conditions, Lisp_Object sig, Lisp_Object data)
1708{ 1719{
1709 Lisp_Object combined_data; 1720 Lisp_Object combined_data;
@@ -2219,7 +2230,6 @@ eval_sub (Lisp_Object form)
2219 if (EQ (funcar, Qmacro)) 2230 if (EQ (funcar, Qmacro))
2220 { 2231 {
2221 ptrdiff_t count = SPECPDL_INDEX (); 2232 ptrdiff_t count = SPECPDL_INDEX ();
2222 extern Lisp_Object Qlexical_binding;
2223 Lisp_Object exp; 2233 Lisp_Object exp;
2224 /* Bind lexical-binding during expansion of the macro, so the 2234 /* Bind lexical-binding during expansion of the macro, so the
2225 macro can know reliably if the code it outputs will be 2235 macro can know reliably if the code it outputs will be
@@ -2708,33 +2718,9 @@ DEFUN ("functionp", Ffunctionp, Sfunctionp, 1, 1, 0,
2708 doc: /* Non-nil if OBJECT is a function. */) 2718 doc: /* Non-nil if OBJECT is a function. */)
2709 (Lisp_Object object) 2719 (Lisp_Object object)
2710{ 2720{
2711 if (SYMBOLP (object) && !NILP (Ffboundp (object))) 2721 if (FUNCTIONP (object))
2712 {
2713 object = Findirect_function (object, Qt);
2714
2715 if (CONSP (object) && EQ (XCAR (object), Qautoload))
2716 {
2717 /* Autoloaded symbols are functions, except if they load
2718 macros or keymaps. */
2719 int i;
2720 for (i = 0; i < 4 && CONSP (object); i++)
2721 object = XCDR (object);
2722
2723 return (CONSP (object) && !NILP (XCAR (object))) ? Qnil : Qt;
2724 }
2725 }
2726
2727 if (SUBRP (object))
2728 return (XSUBR (object)->max_args != UNEVALLED) ? Qt : Qnil;
2729 else if (COMPILEDP (object))
2730 return Qt; 2722 return Qt;
2731 else if (CONSP (object)) 2723 return Qnil;
2732 {
2733 Lisp_Object car = XCAR (object);
2734 return (EQ (car, Qlambda) || EQ (car, Qclosure)) ? Qt : Qnil;
2735 }
2736 else
2737 return Qnil;
2738} 2724}
2739 2725
2740DEFUN ("funcall", Ffuncall, Sfuncall, 1, MANY, 0, 2726DEFUN ("funcall", Ffuncall, Sfuncall, 1, MANY, 0,
@@ -2951,7 +2937,7 @@ funcall_lambda (Lisp_Object fun, ptrdiff_t nargs,
2951 Lisp_Object val, syms_left, next, lexenv; 2937 Lisp_Object val, syms_left, next, lexenv;
2952 ptrdiff_t count = SPECPDL_INDEX (); 2938 ptrdiff_t count = SPECPDL_INDEX ();
2953 ptrdiff_t i; 2939 ptrdiff_t i;
2954 int optional, rest; 2940 bool optional, rest;
2955 2941
2956 if (CONSP (fun)) 2942 if (CONSP (fun))
2957 { 2943 {
@@ -3136,8 +3122,8 @@ specbind (Lisp_Object symbol, Lisp_Object value)
3136 case SYMBOL_PLAINVAL: 3122 case SYMBOL_PLAINVAL:
3137 /* The most common case is that of a non-constant symbol with a 3123 /* The most common case is that of a non-constant symbol with a
3138 trivial value. Make that as fast as we can. */ 3124 trivial value. Make that as fast as we can. */
3139 specpdl_ptr->symbol = symbol; 3125 set_specpdl_symbol (symbol);
3140 specpdl_ptr->old_value = SYMBOL_VAL (sym); 3126 set_specpdl_old_value (SYMBOL_VAL (sym));
3141 specpdl_ptr->func = NULL; 3127 specpdl_ptr->func = NULL;
3142 ++specpdl_ptr; 3128 ++specpdl_ptr;
3143 if (!sym->constant) 3129 if (!sym->constant)
@@ -3152,7 +3138,7 @@ specbind (Lisp_Object symbol, Lisp_Object value)
3152 { 3138 {
3153 Lisp_Object ovalue = find_symbol_value (symbol); 3139 Lisp_Object ovalue = find_symbol_value (symbol);
3154 specpdl_ptr->func = 0; 3140 specpdl_ptr->func = 0;
3155 specpdl_ptr->old_value = ovalue; 3141 set_specpdl_old_value (ovalue);
3156 3142
3157 eassert (sym->redirect != SYMBOL_LOCALIZED 3143 eassert (sym->redirect != SYMBOL_LOCALIZED
3158 || (EQ (SYMBOL_BLV (sym)->where, 3144 || (EQ (SYMBOL_BLV (sym)->where,
@@ -3186,7 +3172,7 @@ specbind (Lisp_Object symbol, Lisp_Object value)
3186 let_shadows_buffer_binding_p which is itself only used 3172 let_shadows_buffer_binding_p which is itself only used
3187 in set_internal for local_if_set. */ 3173 in set_internal for local_if_set. */
3188 eassert (NILP (where) || EQ (where, cur_buf)); 3174 eassert (NILP (where) || EQ (where, cur_buf));
3189 specpdl_ptr->symbol = Fcons (symbol, Fcons (where, cur_buf)); 3175 set_specpdl_symbol (Fcons (symbol, Fcons (where, cur_buf)));
3190 3176
3191 /* If SYMBOL is a per-buffer variable which doesn't have a 3177 /* If SYMBOL is a per-buffer variable which doesn't have a
3192 buffer-local value here, make the `let' change the global 3178 buffer-local value here, make the `let' change the global
@@ -3203,7 +3189,7 @@ specbind (Lisp_Object symbol, Lisp_Object value)
3203 } 3189 }
3204 } 3190 }
3205 else 3191 else
3206 specpdl_ptr->symbol = symbol; 3192 set_specpdl_symbol (symbol);
3207 3193
3208 specpdl_ptr++; 3194 specpdl_ptr++;
3209 set_internal (symbol, value, Qnil, 1); 3195 set_internal (symbol, value, Qnil, 1);
@@ -3221,8 +3207,8 @@ record_unwind_protect (Lisp_Object (*function) (Lisp_Object), Lisp_Object arg)
3221 if (specpdl_ptr == specpdl + specpdl_size) 3207 if (specpdl_ptr == specpdl + specpdl_size)
3222 grow_specpdl (); 3208 grow_specpdl ();
3223 specpdl_ptr->func = function; 3209 specpdl_ptr->func = function;
3224 specpdl_ptr->symbol = Qnil; 3210 set_specpdl_symbol (Qnil);
3225 specpdl_ptr->old_value = arg; 3211 set_specpdl_old_value (arg);
3226 specpdl_ptr++; 3212 specpdl_ptr++;
3227} 3213}
3228 3214
@@ -3354,13 +3340,13 @@ Output stream used is value of `standard-output'. */)
3354 write_string ("(", -1); 3340 write_string ("(", -1);
3355 if (backlist->nargs == MANY) 3341 if (backlist->nargs == MANY)
3356 { /* FIXME: Can this happen? */ 3342 { /* FIXME: Can this happen? */
3357 int i; 3343 bool later_arg = 0;
3358 for (tail = *backlist->args, i = 0; 3344 for (tail = *backlist->args; !NILP (tail); tail = Fcdr (tail))
3359 !NILP (tail);
3360 tail = Fcdr (tail), i = 1)
3361 { 3345 {
3362 if (i) write_string (" ", -1); 3346 if (later_arg)
3347 write_string (" ", -1);
3363 Fprin1 (Fcar (tail), Qnil); 3348 Fprin1 (Fcar (tail), Qnil);
3349 later_arg = 1;
3364 } 3350 }
3365 } 3351 }
3366 else 3352 else