comparison src/eval.c @ 814:a634e3b7acc8

[xemacs-hg @ 2002-04-14 12:41:59 by ben] latest changes TODO.ben-mule-21-5: Update. make-docfile.c: Add basic support for handling ISO 2022 doc strings -- we parse the basic charset designation sequences so we know whether we're in ASCII and have to pay attention to end quotes and such. Reformat code according to coding standards. abbrev.el: Add `global-abbrev-mode', which turns on or off abbrev-mode in all buffers. Added `defining-abbrev-turns-on-abbrev-mode' -- if non-nil, defining an abbrev through an interactive function will automatically turn on abbrev-mode, either globally or locally depending on the command. This is the "what you'd expect" behavior. indent.el: general function for indenting a balanced expression in a mode-correct way. Works similar to indent-region in that a mode can specify a specific command to do the whole operation; if not, figure out the region using forward-sexp and indent each line using indent-according-to-mode. keydefs.el: Removed. Modify M-C-backslash to do indent-region-or-balanced-expression. Make S-Tab just insert a TAB char, like it's meant to do. make-docfile.el: Now that we're using the call-process-in-lisp, we need to load an extra file win32-native.el because we're running a bare temacs. menubar-items.el: Totally redo the Cmds menu so that most used commands appear directly on the menu and less used commands appear in submenus. The old way may have been very pretty, but rather impractical. process.el: Under Windows, don't ever use old-call-process-internal, even in batch mode. We can do processes in batch mode. subr.el: Someone recoded truncate-string-to-width, saying "the FSF version is too complicated and does lots of hard-to-understand stuff" but the resulting recoded version was *totally* wrong! it misunderstood the basic point of this function, which is work in *columns* not chars. i dumped ours and copied the version from FSF 21.1. Also added truncate-string-with-continuation-dots, since this idiom is used often. config.inc.samp, xemacs.mak: Separate out debug and optimize flags. Remove all vestiges of USE_MINIMAL_TAGBITS, USE_INDEXED_LRECORD_IMPLEMENTATION, and GUNG_HO, since those ifdefs have long been removed. Make error-checking support actually work. Some rearrangement of config.inc.samp to make it more logical. Remove callproc.c and ntproc.c from xemacs.mak, no longer used. Make pdump the default. lisp.h: Add support for strong type-checking of Bytecount, Bytebpos, Charcount, Charbpos, and others, by making them classes, overloading the operators to provide integer-like operation and carefully controlling what operations are allowed. Not currently enabled in C++ builds because there are still a number of compile errors, and it won't really work till we merge in my "8-bit-Mule" workspace, in which I make use of the new types Charxpos, Bytexpos, Memxpos, representing a "position" either in a buffer or a string. (This is especially important in the extent code.) abbrev.c, alloc.c, eval.c, buffer.c, buffer.h, editfns.c, fns.c, text.h: Warning fixes, some of them related to new C++ strict type checking of Bytecount, Charbpos, etc. dired.c: Caught an actual error due to strong type checking -- char len being passed when should be byte len. alloc.c, backtrace.h, bytecode.c, bytecode.h, eval.c, sysdep.c: Further optimize Ffuncall: -- process arg list at compiled-function creation time, converting into an array for extra-quick access at funcall time. -- rewrite funcall_compiled_function to use it, and inline this function. -- change the order of check for magic stuff in SPECBIND_FAST_UNSAFE to be faster. -- move the check for need to garbage collect into the allocation code, so only a single flag needs to be checked in funcall. buffer.c, symbols.c: add debug funs to check on mule optimization info in buffers and strings. eval.c, emacs.c, text.c, regex.c, scrollbar-msw.c, search.c: Fix evil crashes due to eistrings not properly reinitialized under pdump. Redo a bit some of the init routines; convert some complex_vars_of() into simple vars_of(), because they didn't need complex processing. callproc.c, emacs.c, event-stream.c, nt.c, process.c, process.h, sysdep.c, sysdep.h, syssignal.h, syswindows.h, ntproc.c: Delete. Hallelujah, praise the Lord, there is no god but Allah!!! fix so that processes can be invoked in bare temacs -- thereby eliminating any need for callproc.c. (currently only eliminated under NT.) remove all crufty and unnecessary old process code in ntproc.c and elsewhere. move non-callproc-specific stuff (mostly environment) into process.c, so callproc.c can be left out under NT. console-tty.c, doc.c, file-coding.c, file-coding.h, lstream.c, lstream.h: fix doc string handling so it works with Japanese, etc docs. change handling of "character mode" so callers don't have to manually set it (quite error-prone). event-msw.c: spacing fixes. lread.c: eliminate unused crufty vintage-19 "FSF defun hack" code. lrecord.h: improve pdump description docs. buffer.c, ntheap.c, unexnt.c, win32.c, emacs.c: Mule-ize some unexec and startup code. It was pseudo-Mule-ized before by simply always calling the ...A versions of functions, but that won't cut it -- eventually we want to be able to run properly even if XEmacs has been installed in a Japanese directory. (The current problem is the timing of the loading of the Unicode tables; this will eventually be fixed.) Go through and fix various other places where the code was not Mule-clean. Provide a function mswindows_get_module_file_name() to get our own name without resort to PATH_MAX and such. Add a big comment in main() about the problem with Unicode table load timing that I just alluded to. emacs.c: When error-checking is enabled (interpreted as "user is developing XEmacs"), don't ask user to "pause to read messages" when a fatal error has occurred, because it will wedge if we are in an inner modal loop (typically when a menu is popped up) and make us unable to get a useful stack trace in the debugger. text.c: Correct update_entirely_ascii_p_flag to actually work. lisp.h, symsinit.h: declarations for above changes.
author ben
date Sun, 14 Apr 2002 12:43:31 +0000
parents 19dfb459d51a
children 6728e641994e
comparison
equal deleted inserted replaced
813:9541922fb765 814:a634e3b7acc8
3143 3143
3144 /************************************************************************/ 3144 /************************************************************************/
3145 /* eval, funcall, apply */ 3145 /* eval, funcall, apply */
3146 /************************************************************************/ 3146 /************************************************************************/
3147 3147
3148 /* NOTE: If you are hearing the endless complaint that function calls in
3149 elisp are extremely slow, it just isn't true any more! The stuff below
3150 -- in particular, the calling of subrs and compiled functions, the most
3151 common cases -- has been highly optimized. There isn't a whole lot left
3152 to do to squeeze more speed out except by switching to lexical
3153 variables, which would eliminate the specbind loop. (But the real gain
3154 from lexical variables would come from better optimization -- with
3155 dynamic binding, you have the constant problem that any function call
3156 that you haven't explicitly proven to be side-effect-free might
3157 potentially side effect your local variables, which makes optimization
3158 extremely difficult when there are function calls anywhere in a chunk of
3159 code to be optimized. Even worse, you don't know that *your* local
3160 variables aren't side-effecting an outer function's local variables, so
3161 it's impossible to optimize away almost *any* variable assignment.) */
3162
3148 static Lisp_Object funcall_lambda (Lisp_Object fun, 3163 static Lisp_Object funcall_lambda (Lisp_Object fun,
3149 int nargs, Lisp_Object args[]); 3164 int nargs, Lisp_Object args[]);
3150 static int in_warnings; 3165 static int in_warnings;
3151 3166
3152 static Lisp_Object 3167 static Lisp_Object
3153 in_warnings_restore (Lisp_Object minimus) 3168 in_warnings_restore (Lisp_Object minimus)
3154 { 3169 {
3155 in_warnings = 0; 3170 in_warnings = 0;
3156 return Qnil; 3171 return Qnil;
3172 }
3173
3174 void handle_compiled_function_with_and_rest (Lisp_Compiled_Function *f,
3175 int nargs,
3176 Lisp_Object args[]);
3177
3178 /* The theory behind making this a separate function is to shrink
3179 funcall_compiled_function() so as to increase the likelihood of a cache
3180 hit in the L1 cache -- &rest processing is not going to be fast anyway.
3181 The idea is the same as with execute_rare_opcode() in bytecode.c. We
3182 make this non-static to ensure the compiler doesn't inline it. */
3183
3184 void
3185 handle_compiled_function_with_and_rest (Lisp_Compiled_Function *f, int nargs,
3186 Lisp_Object args[])
3187 {
3188 REGISTER int i = 0;
3189 int max_non_rest_args = f->args_in_array - 1;
3190 int bindargs = min (nargs, max_non_rest_args);
3191
3192 for (i = 0; i < bindargs; i++)
3193 SPECBIND_FAST_UNSAFE (f->args[i], args[i]);
3194 for (i = bindargs; i < max_non_rest_args; i++)
3195 SPECBIND_FAST_UNSAFE (f->args[i], Qnil);
3196 SPECBIND_FAST_UNSAFE
3197 (f->args[max_non_rest_args],
3198 nargs > max_non_rest_args ?
3199 Flist (nargs - max_non_rest_args, &args[max_non_rest_args]) :
3200 Qnil);
3201 }
3202
3203 /* Apply compiled-function object FUN to the NARGS evaluated arguments
3204 in ARGS, and return the result of evaluation. */
3205 inline static Lisp_Object
3206 funcall_compiled_function (Lisp_Object fun, int nargs, Lisp_Object args[])
3207 {
3208 /* This function can GC */
3209 int speccount = specpdl_depth();
3210 REGISTER int i = 0;
3211 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (fun);
3212
3213 if (!OPAQUEP (f->instructions))
3214 /* Lazily munge the instructions into a more efficient form */
3215 optimize_compiled_function (fun);
3216
3217 /* optimize_compiled_function() guaranteed that f->specpdl_depth is
3218 the required space on the specbinding stack for binding the args
3219 and local variables of fun. So just reserve it once. */
3220 SPECPDL_RESERVE (f->specpdl_depth);
3221
3222 if (nargs == f->max_args) /* Optimize for the common case -- no unspecified
3223 optional arguments. */
3224 {
3225 #if 1
3226 for (i = 0; i < nargs; i++)
3227 SPECBIND_FAST_UNSAFE (f->args[i], args[i]);
3228 #else
3229 /* Here's an alternate way to write the loop that tries to further
3230 optimize funcalls for functions with few arguments by partially
3231 unrolling the loop. It's not clear whether this is a win since it
3232 increases the size of the function and the possibility of L1 cache
3233 misses. (Microsoft VC++ 6 with /O2 /G5 generates 0x90 == 144 bytes
3234 per SPECBIND_FAST_UNSAFE().) Tests under VC++ 6, running the byte
3235 compiler repeatedly and looking at the total time, show very
3236 little difference between the simple loop above, the unrolled code
3237 below, and a "partly unrolled" solution with only cases 0-2 below
3238 instead of 0-4. Therefore, I'm keeping it at the simple loop
3239 because it's smaller. */
3240 switch (nargs)
3241 {
3242 default:
3243 for (i = nargs - 1; i >= 4; i--)
3244 SPECBIND_FAST_UNSAFE (f->args[i], args[i]);
3245 case 4: SPECBIND_FAST_UNSAFE (f->args[3], args[3]);
3246 case 3: SPECBIND_FAST_UNSAFE (f->args[2], args[2]);
3247 case 2: SPECBIND_FAST_UNSAFE (f->args[1], args[1]);
3248 case 1: SPECBIND_FAST_UNSAFE (f->args[0], args[0]);
3249 case 0: break;
3250 }
3251 #endif
3252 }
3253 else if (nargs < f->min_args)
3254 goto wrong_number_of_arguments;
3255 else if (nargs < f->max_args)
3256 {
3257 for (i = 0; i < nargs; i++)
3258 SPECBIND_FAST_UNSAFE (f->args[i], args[i]);
3259 for (i = nargs; i < f->max_args; i++)
3260 SPECBIND_FAST_UNSAFE (f->args[i], Qnil);
3261 }
3262 else if (f->max_args == MANY)
3263 handle_compiled_function_with_and_rest (f, nargs, args);
3264 else
3265 {
3266 wrong_number_of_arguments:
3267 /* The actual printed compiled_function object is incomprehensible.
3268 Check the backtrace to see if we can get a more meaningful symbol. */
3269 if (EQ (fun, indirect_function (*backtrace_list->function, 0)))
3270 fun = *backtrace_list->function;
3271 return Fsignal (Qwrong_number_of_arguments,
3272 list2 (fun, make_int (nargs)));
3273 }
3274
3275 {
3276 Lisp_Object value =
3277 execute_optimized_program ((Opbyte *) XOPAQUE_DATA (f->instructions),
3278 f->stack_depth,
3279 XVECTOR_DATA (f->constants));
3280
3281 /* The attempt to optimize this by only unbinding variables failed
3282 because using buffer-local variables as function parameters
3283 leads to specpdl_ptr->func != 0 */
3284 /* UNBIND_TO_GCPRO_VARIABLES_ONLY (speccount, value); */
3285 UNBIND_TO_GCPRO (speccount, value);
3286 return value;
3287 }
3157 } 3288 }
3158 3289
3159 DEFUN ("eval", Feval, 1, 1, 0, /* 3290 DEFUN ("eval", Feval, 1, 1, 0, /*
3160 Evaluate FORM and return its value. 3291 Evaluate FORM and return its value.
3161 */ 3292 */
3205 else 3336 else
3206 return form; 3337 return form;
3207 } 3338 }
3208 3339
3209 QUIT; 3340 QUIT;
3210 if (need_to_garbage_collect ()) 3341 if (need_to_garbage_collect)
3211 { 3342 {
3212 struct gcpro gcpro1; 3343 struct gcpro gcpro1;
3213 GCPRO1 (form); 3344 GCPRO1 (form);
3214 garbage_collect_1 (); 3345 garbage_collect_1 ();
3215 UNGCPRO; 3346 UNGCPRO;
3429 struct backtrace backtrace; 3560 struct backtrace backtrace;
3430 int fun_nargs = nargs - 1; 3561 int fun_nargs = nargs - 1;
3431 Lisp_Object *fun_args = args + 1; 3562 Lisp_Object *fun_args = args + 1;
3432 3563
3433 QUIT; 3564 QUIT;
3434 if (need_to_garbage_collect ()) 3565 if (need_to_garbage_collect)
3435 /* Callers should gcpro lexpr args */ 3566 /* Callers should gcpro lexpr args */
3436 garbage_collect_1 (); 3567 garbage_collect_1 ();
3437 3568
3438 if (++lisp_eval_depth > max_lisp_eval_depth) 3569 if (++lisp_eval_depth > max_lisp_eval_depth)
3439 { 3570 {
3595 else 3726 else
3596 return Fsubr_max_args (function); 3727 return Fsubr_max_args (function);
3597 } 3728 }
3598 else if (COMPILED_FUNCTIONP (function)) 3729 else if (COMPILED_FUNCTIONP (function))
3599 { 3730 {
3600 arglist = compiled_function_arglist (XCOMPILED_FUNCTION (function)); 3731 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (function);
3732
3733 if (function_min_args_p)
3734 return make_int (f->min_args);
3735 else if (f->max_args == MANY)
3736 return Qnil;
3737 else
3738 return make_int (f->max_args);
3601 } 3739 }
3602 else if (CONSP (function)) 3740 else if (CONSP (function))
3603 { 3741 {
3604 Lisp_Object funcar = XCAR (function); 3742 Lisp_Object funcar = XCAR (function);
3605 3743
4916 return Qnil; 5054 return Qnil;
4917 } 5055 }
4918 5056
4919 /* Establish an unwind-protect which will restore the Lisp_Object pointed to 5057 /* Establish an unwind-protect which will restore the Lisp_Object pointed to
4920 by ADDR with the value VAL. */ 5058 by ADDR with the value VAL. */
4921 int 5059 static int
4922 record_unwind_protect_restoring_lisp_object (Lisp_Object *addr, 5060 record_unwind_protect_restoring_lisp_object (Lisp_Object *addr,
4923 Lisp_Object val) 5061 Lisp_Object val)
4924 { 5062 {
4925 Lisp_Object opaque = make_opaque_ptr (addr); 5063 Lisp_Object opaque = make_opaque_ptr (addr);
4926 return record_unwind_protect (restore_lisp_object, 5064 return record_unwind_protect (restore_lisp_object,
4964 } 5102 }
4965 5103
4966 /* Establish an unwind-protect which will restore the int pointed to 5104 /* Establish an unwind-protect which will restore the int pointed to
4967 by ADDR with the value VAL. This function works correctly with 5105 by ADDR with the value VAL. This function works correctly with
4968 all ints, even those that don't fit into a Lisp integer. */ 5106 all ints, even those that don't fit into a Lisp integer. */
4969 int 5107 static int
4970 record_unwind_protect_restoring_int (int *addr, int val) 5108 record_unwind_protect_restoring_int (int *addr, int val)
4971 { 5109 {
4972 Lisp_Object opaque = make_opaque_ptr (addr); 5110 Lisp_Object opaque = make_opaque_ptr (addr);
4973 Lisp_Object lval; 5111 Lisp_Object lval;
4974 5112
5486 DEFSUBR (Fbacktrace); 5624 DEFSUBR (Fbacktrace);
5487 DEFSUBR (Fbacktrace_frame); 5625 DEFSUBR (Fbacktrace_frame);
5488 } 5626 }
5489 5627
5490 void 5628 void
5491 init_eval_early (void) 5629 init_eval_semi_early (void)
5492 { 5630 {
5493 specpdl_ptr = specpdl; 5631 specpdl_ptr = specpdl;
5494 specpdl_depth_counter = 0; 5632 specpdl_depth_counter = 0;
5495 catchlist = 0; 5633 catchlist = 0;
5496 Vcondition_handlers = Qnil; 5634 Vcondition_handlers = Qnil;