Mercurial > emacs
comparison src/eval.c @ 109353:d43e7dfda4f1
merge trunk
| author | Kenichi Handa <handa@etlken> |
|---|---|
| date | Mon, 12 Jul 2010 11:28:50 +0900 |
| parents | e856a274549b |
| children | 3e07e13fe30a |
comparison
equal
deleted
inserted
replaced
| 109352:2803d726899d | 109353:d43e7dfda4f1 |
|---|---|
| 1 /* Evaluator for GNU Emacs Lisp interpreter. | 1 /* Evaluator for GNU Emacs Lisp interpreter. |
| 2 Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1999, 2000, 2001, | 2 Copyright (C) 1985, 1986, 1987, 1993, 1994, 1995, 1999, 2000, 2001, |
| 3 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 | 3 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 |
| 4 Free Software Foundation, Inc. | 4 Free Software Foundation, Inc. |
| 5 | 5 |
| 6 This file is part of GNU Emacs. | 6 This file is part of GNU Emacs. |
| 7 | 7 |
| 8 GNU Emacs is free software: you can redistribute it and/or modify | 8 GNU Emacs is free software: you can redistribute it and/or modify |
| 9 it under the terms of the GNU General Public License as published by | 9 it under the terms of the GNU General Public License as published by |
| 170 | 170 |
| 171 extern Lisp_Object Qfunction; | 171 extern Lisp_Object Qfunction; |
| 172 | 172 |
| 173 static Lisp_Object funcall_lambda (Lisp_Object, int, Lisp_Object*); | 173 static Lisp_Object funcall_lambda (Lisp_Object, int, Lisp_Object*); |
| 174 static void unwind_to_catch (struct catchtag *, Lisp_Object) NO_RETURN; | 174 static void unwind_to_catch (struct catchtag *, Lisp_Object) NO_RETURN; |
| 175 | |
| 176 #if __GNUC__ | |
| 177 /* "gcc -O3" enables automatic function inlining, which optimizes out | |
| 178 the arguments for the invocations of these functions, whereas they | |
| 179 expect these values on the stack. */ | |
| 180 Lisp_Object apply1 (Lisp_Object fn, Lisp_Object arg) __attribute__((noinline)); | |
| 181 Lisp_Object call2 (Lisp_Object fn, Lisp_Object arg1, Lisp_Object arg2) __attribute__((noinline)); | |
| 182 #endif | |
| 183 | 175 |
| 184 void | 176 void |
| 185 init_eval_once (void) | 177 init_eval_once (void) |
| 186 { | 178 { |
| 187 specpdl_size = 50; | 179 specpdl_size = 50; |
| 433 GCPRO2 (args, val); | 425 GCPRO2 (args, val); |
| 434 | 426 |
| 435 do | 427 do |
| 436 { | 428 { |
| 437 if (!(argnum++)) | 429 if (!(argnum++)) |
| 438 val = Feval (Fcar (args_left)); | 430 val = Feval (Fcar (args_left)); |
| 439 else | 431 else |
| 440 Feval (Fcar (args_left)); | 432 Feval (Fcar (args_left)); |
| 441 args_left = Fcdr (args_left); | 433 args_left = Fcdr (args_left); |
| 442 } | 434 } |
| 443 while (!NILP(args_left)); | 435 while (!NILP(args_left)); |
| 468 GCPRO2 (args, val); | 460 GCPRO2 (args, val); |
| 469 | 461 |
| 470 do | 462 do |
| 471 { | 463 { |
| 472 if (!(argnum++)) | 464 if (!(argnum++)) |
| 473 val = Feval (Fcar (args_left)); | 465 val = Feval (Fcar (args_left)); |
| 474 else | 466 else |
| 475 Feval (Fcar (args_left)); | 467 Feval (Fcar (args_left)); |
| 476 args_left = Fcdr (args_left); | 468 args_left = Fcdr (args_left); |
| 477 } | 469 } |
| 478 while (!NILP (args_left)); | 470 while (!NILP (args_left)); |
| 942 return Qnil; | 934 return Qnil; |
| 943 | 935 |
| 944 /* If indirect and there's an alias loop, don't check anything else. */ | 936 /* If indirect and there's an alias loop, don't check anything else. */ |
| 945 if (XSYMBOL (variable)->redirect == SYMBOL_VARALIAS | 937 if (XSYMBOL (variable)->redirect == SYMBOL_VARALIAS |
| 946 && NILP (internal_condition_case_1 (lisp_indirect_variable, variable, | 938 && NILP (internal_condition_case_1 (lisp_indirect_variable, variable, |
| 947 Qt, user_variable_p_eh))) | 939 Qt, user_variable_p_eh))) |
| 948 return Qnil; | 940 return Qnil; |
| 949 | 941 |
| 950 while (1) | 942 while (1) |
| 951 { | 943 { |
| 952 documentation = Fget (variable, Qvariable_documentation); | 944 documentation = Fget (variable, Qvariable_documentation); |
| 953 if (INTEGERP (documentation) && XINT (documentation) < 0) | 945 if (INTEGERP (documentation) && XINT (documentation) < 0) |
| 954 return Qt; | 946 return Qt; |
| 955 if (STRINGP (documentation) | 947 if (STRINGP (documentation) |
| 956 && ((unsigned char) SREF (documentation, 0) == '*')) | 948 && ((unsigned char) SREF (documentation, 0) == '*')) |
| 957 return Qt; | 949 return Qt; |
| 958 /* If it is (STRING . INTEGER), a negative integer means a user variable. */ | 950 /* If it is (STRING . INTEGER), a negative integer means a user variable. */ |
| 959 if (CONSP (documentation) | 951 if (CONSP (documentation) |
| 960 && STRINGP (XCAR (documentation)) | 952 && STRINGP (XCAR (documentation)) |
| 961 && INTEGERP (XCDR (documentation)) | 953 && INTEGERP (XCDR (documentation)) |
| 962 && XINT (XCDR (documentation)) < 0) | 954 && XINT (XCDR (documentation)) < 0) |
| 963 return Qt; | 955 return Qt; |
| 964 /* Customizable? See `custom-variable-p'. */ | 956 /* Customizable? See `custom-variable-p'. */ |
| 965 if ((!NILP (Fget (variable, intern ("standard-value")))) | 957 if ((!NILP (Fget (variable, intern ("standard-value")))) |
| 966 || (!NILP (Fget (variable, intern ("custom-autoload"))))) | 958 || (!NILP (Fget (variable, intern ("custom-autoload"))))) |
| 967 return Qt; | 959 return Qt; |
| 968 | 960 |
| 969 if (!(XSYMBOL (variable)->redirect == SYMBOL_VARALIAS)) | 961 if (!(XSYMBOL (variable)->redirect == SYMBOL_VARALIAS)) |
| 970 return Qnil; | 962 return Qnil; |
| 971 | 963 |
| 972 /* An indirect variable? Let's follow the chain. */ | 964 /* An indirect variable? Let's follow the chain. */ |
| 973 XSETSYMBOL (variable, SYMBOL_ALIAS (XSYMBOL (variable))); | 965 XSETSYMBOL (variable, SYMBOL_ALIAS (XSYMBOL (variable))); |
| 974 } | 966 } |
| 975 } | 967 } |
| 1252 do | 1244 do |
| 1253 { | 1245 { |
| 1254 last_time = catchlist == catch; | 1246 last_time = catchlist == catch; |
| 1255 | 1247 |
| 1256 /* Unwind the specpdl stack, and then restore the proper set of | 1248 /* Unwind the specpdl stack, and then restore the proper set of |
| 1257 handlers. */ | 1249 handlers. */ |
| 1258 unbind_to (catchlist->pdlcount, Qnil); | 1250 unbind_to (catchlist->pdlcount, Qnil); |
| 1259 handlerlist = catchlist->handlerlist; | 1251 handlerlist = catchlist->handlerlist; |
| 1260 catchlist = catchlist->next; | 1252 catchlist = catchlist->next; |
| 1261 } | 1253 } |
| 1262 while (! last_time); | 1254 while (! last_time); |
| 1263 | 1255 |
| 1264 #if HAVE_X_WINDOWS | 1256 #if HAVE_X_WINDOWS |
| 1265 /* If x_catch_errors was done, turn it off now. | 1257 /* If x_catch_errors was done, turn it off now. |
| 1266 (First we give unbind_to a chance to do that.) */ | 1258 (First we give unbind_to a chance to do that.) */ |
| 1267 #if 0 /* This would disable x_catch_errors after x_connection_closed. | 1259 #if 0 /* This would disable x_catch_errors after x_connection_closed. |
| 1268 * The catch must remain in effect during that delicate | 1260 The catch must remain in effect during that delicate |
| 1269 * state. --lorentey */ | 1261 state. --lorentey */ |
| 1270 x_fully_uncatch_errors (); | 1262 x_fully_uncatch_errors (); |
| 1271 #endif | 1263 #endif |
| 1272 #endif | 1264 #endif |
| 1273 | 1265 |
| 1274 byte_stack_list = catch->byte_stack; | 1266 byte_stack_list = catch->byte_stack; |
| 1340 instead of a single condition name. Then it handles all of them. | 1332 instead of a single condition name. Then it handles all of them. |
| 1341 | 1333 |
| 1342 When a handler handles an error, control returns to the `condition-case' | 1334 When a handler handles an error, control returns to the `condition-case' |
| 1343 and it executes the handler's BODY... | 1335 and it executes the handler's BODY... |
| 1344 with VAR bound to (ERROR-SYMBOL . SIGNAL-DATA) from the error. | 1336 with VAR bound to (ERROR-SYMBOL . SIGNAL-DATA) from the error. |
| 1345 (If VAR is nil, the handler can't access that information.) | 1337 \(If VAR is nil, the handler can't access that information.) |
| 1346 Then the value of the last BODY form is returned from the `condition-case' | 1338 Then the value of the last BODY form is returned from the `condition-case' |
| 1347 expression. | 1339 expression. |
| 1348 | 1340 |
| 1349 See also the function `signal' for more info. | 1341 See also the function `signal' for more info. |
| 1350 usage: (condition-case VAR BODYFORM &rest HANDLERS) */) | 1342 usage: (condition-case VAR BODYFORM &rest HANDLERS) */) |
| 1351 (Lisp_Object args) | 1343 (Lisp_Object args) |
| 1352 { | 1344 { |
| 1353 register Lisp_Object bodyform, handlers; | 1345 register Lisp_Object bodyform, handlers; |
| 1354 volatile Lisp_Object var; | 1346 volatile Lisp_Object var; |
| 1355 | 1347 |
| 1356 var = Fcar (args); | 1348 var = Fcar (args); |
| 1395 c.gcpro = gcprolist; | 1387 c.gcpro = gcprolist; |
| 1396 c.byte_stack = byte_stack_list; | 1388 c.byte_stack = byte_stack_list; |
| 1397 if (_setjmp (c.jmp)) | 1389 if (_setjmp (c.jmp)) |
| 1398 { | 1390 { |
| 1399 if (!NILP (h.var)) | 1391 if (!NILP (h.var)) |
| 1400 specbind (h.var, c.val); | 1392 specbind (h.var, c.val); |
| 1401 val = Fprogn (Fcdr (h.chosen_clause)); | 1393 val = Fprogn (Fcdr (h.chosen_clause)); |
| 1402 | 1394 |
| 1403 /* Note that this just undoes the binding of h.var; whoever | 1395 /* Note that this just undoes the binding of h.var; whoever |
| 1404 longjumped to us unwound the stack to c.pdlcount before | 1396 longjumped to us unwound the stack to c.pdlcount before |
| 1405 throwing. */ | 1397 throwing. */ |
| 1617 return val; | 1609 return val; |
| 1618 } | 1610 } |
| 1619 | 1611 |
| 1620 | 1612 |
| 1621 static Lisp_Object find_handler_clause (Lisp_Object, Lisp_Object, | 1613 static Lisp_Object find_handler_clause (Lisp_Object, Lisp_Object, |
| 1622 Lisp_Object, Lisp_Object); | 1614 Lisp_Object, Lisp_Object); |
| 1623 | 1615 |
| 1624 DEFUN ("signal", Fsignal, Ssignal, 2, 2, 0, | 1616 DEFUN ("signal", Fsignal, Ssignal, 2, 2, 0, |
| 1625 doc: /* Signal an error. Args are ERROR-SYMBOL and associated DATA. | 1617 doc: /* Signal an error. Args are ERROR-SYMBOL and associated DATA. |
| 1626 This function does not return. | 1618 This function does not return. |
| 1627 | 1619 |
| 1781 | 1773 |
| 1782 /* Signal `error' with message S, and additional arg ARG. | 1774 /* Signal `error' with message S, and additional arg ARG. |
| 1783 If ARG is not a genuine list, make it a one-element list. */ | 1775 If ARG is not a genuine list, make it a one-element list. */ |
| 1784 | 1776 |
| 1785 void | 1777 void |
| 1786 signal_error (char *s, Lisp_Object arg) | 1778 signal_error (const char *s, Lisp_Object arg) |
| 1787 { | 1779 { |
| 1788 Lisp_Object tortoise, hare; | 1780 Lisp_Object tortoise, hare; |
| 1789 | 1781 |
| 1790 hare = tortoise = arg; | 1782 hare = tortoise = arg; |
| 1791 while (CONSP (hare)) | 1783 while (CONSP (hare)) |
| 2001 | 1993 |
| 2002 /* dump an error message; called like printf */ | 1994 /* dump an error message; called like printf */ |
| 2003 | 1995 |
| 2004 /* VARARGS 1 */ | 1996 /* VARARGS 1 */ |
| 2005 void | 1997 void |
| 2006 error (m, a1, a2, a3) | 1998 error (const char *m, ...) |
| 2007 char *m; | |
| 2008 char *a1, *a2, *a3; | |
| 2009 { | 1999 { |
| 2010 char buf[200]; | 2000 char buf[200]; |
| 2011 int size = 200; | 2001 int size = 200; |
| 2012 int mlen; | 2002 int mlen; |
| 2013 char *buffer = buf; | 2003 char *buffer = buf; |
| 2014 char *args[3]; | 2004 char *args[3]; |
| 2015 int allocated = 0; | 2005 int allocated = 0; |
| 2016 Lisp_Object string; | 2006 Lisp_Object string; |
| 2017 | 2007 |
| 2018 args[0] = a1; | |
| 2019 args[1] = a2; | |
| 2020 args[2] = a3; | |
| 2021 | |
| 2022 mlen = strlen (m); | 2008 mlen = strlen (m); |
| 2023 | 2009 |
| 2024 while (1) | 2010 while (1) |
| 2025 { | 2011 { |
| 2026 int used = doprnt (buffer, size, m, m + mlen, 3, args); | 2012 va_list ap; |
| 2013 int used; | |
| 2014 | |
| 2015 /* A va_list can't be reused if we have to go around the loop | |
| 2016 again; we need to "reinitialize" it each time. */ | |
| 2017 va_start(ap, m); | |
| 2018 used = doprnt (buffer, size, m, m + mlen, ap); | |
| 2019 va_end(ap); | |
| 2027 if (used < size) | 2020 if (used < size) |
| 2028 break; | 2021 break; |
| 2029 size *= 2; | 2022 size *= 2; |
| 2030 if (allocated) | 2023 if (allocated) |
| 2031 buffer = (char *) xrealloc (buffer, size); | 2024 buffer = (char *) xrealloc (buffer, size); |
| 2513 | 2506 |
| 2514 /* Run hook variables in various ways. */ | 2507 /* Run hook variables in various ways. */ |
| 2515 | 2508 |
| 2516 enum run_hooks_condition {to_completion, until_success, until_failure}; | 2509 enum run_hooks_condition {to_completion, until_success, until_failure}; |
| 2517 static Lisp_Object run_hook_with_args (int, Lisp_Object *, | 2510 static Lisp_Object run_hook_with_args (int, Lisp_Object *, |
| 2518 enum run_hooks_condition); | 2511 enum run_hooks_condition); |
| 2519 | 2512 |
| 2520 DEFUN ("run-hooks", Frun_hooks, Srun_hooks, 0, MANY, 0, | 2513 DEFUN ("run-hooks", Frun_hooks, Srun_hooks, 0, MANY, 0, |
| 2521 doc: /* Run each hook in HOOKS. | 2514 doc: /* Run each hook in HOOKS. |
| 2522 Each argument should be a symbol, a hook variable. | 2515 Each argument should be a symbol, a hook variable. |
| 2523 These symbols are processed in the order specified. | 2516 These symbols are processed in the order specified. |
| 3251 switch (sym->redirect) | 3244 switch (sym->redirect) |
| 3252 { | 3245 { |
| 3253 case SYMBOL_VARALIAS: | 3246 case SYMBOL_VARALIAS: |
| 3254 sym = indirect_variable (sym); XSETSYMBOL (symbol, sym); goto start; | 3247 sym = indirect_variable (sym); XSETSYMBOL (symbol, sym); goto start; |
| 3255 case SYMBOL_PLAINVAL: | 3248 case SYMBOL_PLAINVAL: |
| 3256 { /* The most common case is that of a non-constant symbol with a | 3249 /* The most common case is that of a non-constant symbol with a |
| 3257 trivial value. Make that as fast as we can. */ | 3250 trivial value. Make that as fast as we can. */ |
| 3258 specpdl_ptr->symbol = symbol; | 3251 specpdl_ptr->symbol = symbol; |
| 3259 specpdl_ptr->old_value = SYMBOL_VAL (sym); | 3252 specpdl_ptr->old_value = SYMBOL_VAL (sym); |
| 3260 specpdl_ptr->func = NULL; | 3253 specpdl_ptr->func = NULL; |
| 3261 ++specpdl_ptr; | 3254 ++specpdl_ptr; |
| 3262 if (!sym->constant) | 3255 if (!sym->constant) |
| 3263 SET_SYMBOL_VAL (sym, value); | 3256 SET_SYMBOL_VAL (sym, value); |
| 3264 else | 3257 else |
| 3265 set_internal (symbol, value, Qnil, 1); | 3258 set_internal (symbol, value, Qnil, 1); |
| 3266 break; | 3259 break; |
| 3267 } | |
| 3268 case SYMBOL_LOCALIZED: | 3260 case SYMBOL_LOCALIZED: |
| 3269 if (SYMBOL_BLV (sym)->frame_local) | 3261 if (SYMBOL_BLV (sym)->frame_local) |
| 3270 error ("Frame-local vars cannot be let-bound"); | 3262 error ("Frame-local vars cannot be let-bound"); |
| 3271 case SYMBOL_FORWARDED: | 3263 case SYMBOL_FORWARDED: |
| 3272 { | 3264 { |
| 3372 . CURRENT-BUFFER) where WHERE is either nil, a buffer, or a | 3364 . CURRENT-BUFFER) where WHERE is either nil, a buffer, or a |
| 3373 frame. If WHERE is a buffer or frame, this indicates we | 3365 frame. If WHERE is a buffer or frame, this indicates we |
| 3374 bound a variable that had a buffer-local or frame-local | 3366 bound a variable that had a buffer-local or frame-local |
| 3375 binding. WHERE nil means that the variable had the default | 3367 binding. WHERE nil means that the variable had the default |
| 3376 value when it was bound. CURRENT-BUFFER is the buffer that | 3368 value when it was bound. CURRENT-BUFFER is the buffer that |
| 3377 was current when the variable was bound. */ | 3369 was current when the variable was bound. */ |
| 3378 else if (CONSP (this_binding.symbol)) | 3370 else if (CONSP (this_binding.symbol)) |
| 3379 { | 3371 { |
| 3380 Lisp_Object symbol, where; | 3372 Lisp_Object symbol, where; |
| 3381 | 3373 |
| 3382 symbol = XCAR (this_binding.symbol); | 3374 symbol = XCAR (this_binding.symbol); |
