Mercurial > hg > xemacs-beta
diff 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 |
line wrap: on
line diff
--- a/src/eval.c Sat Apr 13 20:44:53 2002 +0000 +++ b/src/eval.c Sun Apr 14 12:43:31 2002 +0000 @@ -3145,6 +3145,21 @@ /* eval, funcall, apply */ /************************************************************************/ +/* NOTE: If you are hearing the endless complaint that function calls in + elisp are extremely slow, it just isn't true any more! The stuff below + -- in particular, the calling of subrs and compiled functions, the most + common cases -- has been highly optimized. There isn't a whole lot left + to do to squeeze more speed out except by switching to lexical + variables, which would eliminate the specbind loop. (But the real gain + from lexical variables would come from better optimization -- with + dynamic binding, you have the constant problem that any function call + that you haven't explicitly proven to be side-effect-free might + potentially side effect your local variables, which makes optimization + extremely difficult when there are function calls anywhere in a chunk of + code to be optimized. Even worse, you don't know that *your* local + variables aren't side-effecting an outer function's local variables, so + it's impossible to optimize away almost *any* variable assignment.) */ + static Lisp_Object funcall_lambda (Lisp_Object fun, int nargs, Lisp_Object args[]); static int in_warnings; @@ -3156,6 +3171,122 @@ return Qnil; } +void handle_compiled_function_with_and_rest (Lisp_Compiled_Function *f, + int nargs, + Lisp_Object args[]); + +/* The theory behind making this a separate function is to shrink + funcall_compiled_function() so as to increase the likelihood of a cache + hit in the L1 cache -- &rest processing is not going to be fast anyway. + The idea is the same as with execute_rare_opcode() in bytecode.c. We + make this non-static to ensure the compiler doesn't inline it. */ + +void +handle_compiled_function_with_and_rest (Lisp_Compiled_Function *f, int nargs, + Lisp_Object args[]) +{ + REGISTER int i = 0; + int max_non_rest_args = f->args_in_array - 1; + int bindargs = min (nargs, max_non_rest_args); + + for (i = 0; i < bindargs; i++) + SPECBIND_FAST_UNSAFE (f->args[i], args[i]); + for (i = bindargs; i < max_non_rest_args; i++) + SPECBIND_FAST_UNSAFE (f->args[i], Qnil); + SPECBIND_FAST_UNSAFE + (f->args[max_non_rest_args], + nargs > max_non_rest_args ? + Flist (nargs - max_non_rest_args, &args[max_non_rest_args]) : + Qnil); +} + +/* Apply compiled-function object FUN to the NARGS evaluated arguments + in ARGS, and return the result of evaluation. */ +inline static Lisp_Object +funcall_compiled_function (Lisp_Object fun, int nargs, Lisp_Object args[]) +{ + /* This function can GC */ + int speccount = specpdl_depth(); + REGISTER int i = 0; + Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (fun); + + if (!OPAQUEP (f->instructions)) + /* Lazily munge the instructions into a more efficient form */ + optimize_compiled_function (fun); + + /* optimize_compiled_function() guaranteed that f->specpdl_depth is + the required space on the specbinding stack for binding the args + and local variables of fun. So just reserve it once. */ + SPECPDL_RESERVE (f->specpdl_depth); + + if (nargs == f->max_args) /* Optimize for the common case -- no unspecified + optional arguments. */ + { +#if 1 + for (i = 0; i < nargs; i++) + SPECBIND_FAST_UNSAFE (f->args[i], args[i]); +#else + /* Here's an alternate way to write the loop that tries to further + optimize funcalls for functions with few arguments by partially + unrolling the loop. It's not clear whether this is a win since it + increases the size of the function and the possibility of L1 cache + misses. (Microsoft VC++ 6 with /O2 /G5 generates 0x90 == 144 bytes + per SPECBIND_FAST_UNSAFE().) Tests under VC++ 6, running the byte + compiler repeatedly and looking at the total time, show very + little difference between the simple loop above, the unrolled code + below, and a "partly unrolled" solution with only cases 0-2 below + instead of 0-4. Therefore, I'm keeping it at the simple loop + because it's smaller. */ + switch (nargs) + { + default: + for (i = nargs - 1; i >= 4; i--) + SPECBIND_FAST_UNSAFE (f->args[i], args[i]); + case 4: SPECBIND_FAST_UNSAFE (f->args[3], args[3]); + case 3: SPECBIND_FAST_UNSAFE (f->args[2], args[2]); + case 2: SPECBIND_FAST_UNSAFE (f->args[1], args[1]); + case 1: SPECBIND_FAST_UNSAFE (f->args[0], args[0]); + case 0: break; + } +#endif + } + else if (nargs < f->min_args) + goto wrong_number_of_arguments; + else if (nargs < f->max_args) + { + for (i = 0; i < nargs; i++) + SPECBIND_FAST_UNSAFE (f->args[i], args[i]); + for (i = nargs; i < f->max_args; i++) + SPECBIND_FAST_UNSAFE (f->args[i], Qnil); + } + else if (f->max_args == MANY) + handle_compiled_function_with_and_rest (f, nargs, args); + else + { + wrong_number_of_arguments: + /* The actual printed compiled_function object is incomprehensible. + Check the backtrace to see if we can get a more meaningful symbol. */ + if (EQ (fun, indirect_function (*backtrace_list->function, 0))) + fun = *backtrace_list->function; + return Fsignal (Qwrong_number_of_arguments, + list2 (fun, make_int (nargs))); + } + + { + Lisp_Object value = + execute_optimized_program ((Opbyte *) XOPAQUE_DATA (f->instructions), + f->stack_depth, + XVECTOR_DATA (f->constants)); + + /* The attempt to optimize this by only unbinding variables failed + because using buffer-local variables as function parameters + leads to specpdl_ptr->func != 0 */ + /* UNBIND_TO_GCPRO_VARIABLES_ONLY (speccount, value); */ + UNBIND_TO_GCPRO (speccount, value); + return value; + } +} + DEFUN ("eval", Feval, 1, 1, 0, /* Evaluate FORM and return its value. */ @@ -3207,7 +3338,7 @@ } QUIT; - if (need_to_garbage_collect ()) + if (need_to_garbage_collect) { struct gcpro gcpro1; GCPRO1 (form); @@ -3431,7 +3562,7 @@ Lisp_Object *fun_args = args + 1; QUIT; - if (need_to_garbage_collect ()) + if (need_to_garbage_collect) /* Callers should gcpro lexpr args */ garbage_collect_1 (); @@ -3597,7 +3728,14 @@ } else if (COMPILED_FUNCTIONP (function)) { - arglist = compiled_function_arglist (XCOMPILED_FUNCTION (function)); + Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (function); + + if (function_min_args_p) + return make_int (f->min_args); + else if (f->max_args == MANY) + return Qnil; + else + return make_int (f->max_args); } else if (CONSP (function)) { @@ -4918,7 +5056,7 @@ /* Establish an unwind-protect which will restore the Lisp_Object pointed to by ADDR with the value VAL. */ -int +static int record_unwind_protect_restoring_lisp_object (Lisp_Object *addr, Lisp_Object val) { @@ -4966,7 +5104,7 @@ /* Establish an unwind-protect which will restore the int pointed to by ADDR with the value VAL. This function works correctly with all ints, even those that don't fit into a Lisp integer. */ -int +static int record_unwind_protect_restoring_int (int *addr, int val) { Lisp_Object opaque = make_opaque_ptr (addr); @@ -5488,7 +5626,7 @@ } void -init_eval_early (void) +init_eval_semi_early (void) { specpdl_ptr = specpdl; specpdl_depth_counter = 0;