comparison lisp/bytecomp.el @ 4885:6772ce4d982b

Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums lisp/ChangeLog addition: 2010-01-24 Aidan Kehoe <kehoea@parhasard.net> Correct the semantics of #'member*, #'eql, #'assoc* in the presence of bignums; change the integerp byte code to fixnump semantics. * bytecomp.el (fixnump, integerp, byte-compile-integerp): Change the integerp byte code to fixnump; add a byte-compile method to integerp using fixnump and numberp and avoiding a funcall most of the time, since in the non-core contexts where integerp is used, it's mostly distinguishing between fixnums and things that are not numbers at all. * byte-optimize.el (side-effect-free-fns, byte-after-unbind-ops) (byte-compile-side-effect-and-error-free-ops): Replace the integerp bytecode with fixnump; add fixnump to the side-effect-free-fns. Add the other extended number type predicates to the list in passing. * obsolete.el (floatp-safe): Mark this as obsolete. * cl.el (eql): Go into more detail in the docstring here. Don't bother checking whether both arguments are numbers; one is enough, #'equal will fail correctly if they have distinct types. (subst): Replace a call to #'integerp (deciding whether to use #'memq or not) with one to #'fixnump. Delete most-positive-fixnum, most-negative-fixnum from this file; they're now always in C, so they can't be modified from Lisp. * cl-seq.el (member*, assoc*, rassoc*): Correct these functions in the presence of bignums. * cl-macs.el (cl-make-type-test): The type test for a fixnum is now fixnump. Ditch floatp-safe, use floatp instead. (eql): Correct this compiler macro in the presence of bignums. (assoc*): Correct this compiler macro in the presence of bignums. * simple.el (undo): Change #'integerp to #'fixnump here, since we use #'delq with the same value as ELT a few lines down. src/ChangeLog addition: 2010-01-24 Aidan Kehoe <kehoea@parhasard.net> Fix problems with #'eql, extended number types, and the hash table implementation; change the Bintegerp bytecode to fixnump semantics even on bignum builds, since #'integerp can have a fast implementation in terms of #'fixnump for most of its extant uses, but not vice-versa. * lisp.h: Always #include number.h; we want the macros provided in it, even if the various number types are not available. * number.h (NON_FIXNUM_NUMBER_P): New macro, giving 1 when its argument is of non-immediate number type. Equivalent to FLOATP if WITH_NUMBER_TYPES is not defined. * elhash.c (lisp_object_eql_equal, lisp_object_eql_hash): Use NON_FIXNUM_NUMBER_P in these functions, instead of FLOATP, giving more correct behaviour in the presence of the extended number types. * bytecode.c (Bfixnump, execute_optimized_program): Rename Bintegerp to Bfixnump; change its semantics to reflect the new name on builds with bignum support. * data.c (Ffixnump, Fintegerp, syms_of_data, vars_of_data): Always make #'fixnump available, even on non-BIGNUM builds; always implement #'integerp in this file, even on BIGNUM builds. Move most-positive-fixnum, most-negative-fixnum here from number.c, so they are Lisp constants even on builds without number types, and attempts to change or bind them error. Use the NUMBERP and INTEGERP macros even on builds without extended number types. * data.c (fixnum_char_or_marker_to_int): Rename this function from integer_char_or_marker_to_int, to better reflect the arguments it accepts. * number.c (Fevenp, Foddp, syms_of_number): Never provide #'integerp in this file. Remove #'oddp, #'evenp; their implementations are overridden by those in cl.el. * number.c (vars_of_number): most-positive-fixnum, most-negative-fixnum are no longer here. man/ChangeLog addition: 2010-01-23 Aidan Kehoe <kehoea@parhasard.net> Generally: be careful to say fixnum, not integer, when talking about fixed-precision integral types. I'm sure I've missed instances, both here and in the docstrings, but this is a decent start. * lispref/text.texi (Columns): Document where only fixnums, not integers generally, are accepted. (Registers): Remove some ancient char-int confoundance here. * lispref/strings.texi (Creating Strings, Creating Strings): Be more exact in describing where fixnums but not integers in general are accepted. (Creating Strings): Use a more contemporary example to illustrate how concat deals with lists including integers about #xFF. Delete some obsolete documentation on same. (Char Table Types): Document that only fixnums are accepted as values in syntax tables. * lispref/searching.texi (String Search, Search and Replace): Be exact in describing where fixnums but not integers in general are accepted. * lispref/range-tables.texi (Range Tables): Be exact in describing them; only fixnums are accepted to describe ranges. * lispref/os.texi (Killing XEmacs, User Identification) (Time of Day, Time Conversion): Be more exact about using fixnum where only fixed-precision integers are accepted. * lispref/objects.texi (Integer Type): Be more exact (and up-to-date) about the possible values for integers. Cross-reference to documentation of the bignum extension. (Equality Predicates): (Range Table Type): (Array Type): Use fixnum, not integer, to describe a fixed-precision integer. (Syntax Table Type): Correct some English syntax here. * lispref/numbers.texi (Numbers): Change the phrasing here to use fixnum to mean the fixed-precision integers normal in emacs. Document that our terminology deviates from that of Common Lisp, and that we're working on it. (Compatibility Issues): Reiterate the Common Lisp versus Emacs Lisp compatibility issues. (Comparison of Numbers, Arithmetic Operations): * lispref/commands.texi (Command Loop Info, Working With Events): * lispref/buffers.texi (Modification Time): Be more exact in describing where fixnums but not integers in general are accepted.
author Aidan Kehoe <kehoea@parhasard.net>
date Sun, 24 Jan 2010 15:21:27 +0000
parents e29fcfd8df5f
children 755ae5b97edb 8431b52e43b1
comparison
equal deleted inserted replaced
4869:e533a9912ef1 4885:6772ce4d982b
732 (byte-defop 163 0 byte-cdr-safe) 732 (byte-defop 163 0 byte-cdr-safe)
733 (byte-defop 164 -1 byte-nconc) 733 (byte-defop 164 -1 byte-nconc)
734 (byte-defop 165 -1 byte-quo) 734 (byte-defop 165 -1 byte-quo)
735 (byte-defop 166 -1 byte-rem) 735 (byte-defop 166 -1 byte-rem)
736 (byte-defop 167 0 byte-numberp) 736 (byte-defop 167 0 byte-numberp)
737 (byte-defop 168 0 byte-integerp) 737 (byte-defop 168 0 byte-fixnump)
738 738
739 ;; unused: 169 739 ;; unused: 169
740 740
741 ;; These are not present in FSF. 741 ;; These are not present in FSF.
742 ;; 742 ;;
3099 (byte-defop-compiler char-syntax 1+1) 3099 (byte-defop-compiler char-syntax 1+1)
3100 (byte-defop-compiler nreverse 1) 3100 (byte-defop-compiler nreverse 1)
3101 (byte-defop-compiler car-safe 1) 3101 (byte-defop-compiler car-safe 1)
3102 (byte-defop-compiler cdr-safe 1) 3102 (byte-defop-compiler cdr-safe 1)
3103 (byte-defop-compiler numberp 1) 3103 (byte-defop-compiler numberp 1)
3104 (byte-defop-compiler integerp 1) 3104 (byte-defop-compiler fixnump 1)
3105 (byte-defop-compiler skip-chars-forward 1-2+1) 3105 (byte-defop-compiler skip-chars-forward 1-2+1)
3106 (byte-defop-compiler skip-chars-backward 1-2+1) 3106 (byte-defop-compiler skip-chars-backward 1-2+1)
3107 (byte-defop-compiler (eql byte-eq) 2) 3107 (byte-defop-compiler (eql byte-eq) 2)
3108 (byte-defop-compiler20 old-eq 2) 3108 (byte-defop-compiler20 old-eq 2)
3109 (byte-defop-compiler20 old-memq 2) 3109 (byte-defop-compiler20 old-memq 2)
3815 (byte-defop-compiler-1 mapcar-extents byte-compile-funarg-1-2) 3815 (byte-defop-compiler-1 mapcar-extents byte-compile-funarg-1-2)
3816 3816
3817 (byte-defop-compiler-1 let) 3817 (byte-defop-compiler-1 let)
3818 (byte-defop-compiler-1 let*) 3818 (byte-defop-compiler-1 let*)
3819 3819
3820 (byte-defop-compiler-1 integerp)
3821
3820 (defun byte-compile-progn (form) 3822 (defun byte-compile-progn (form)
3821 (byte-compile-body-do-effect (cdr form))) 3823 (byte-compile-body-do-effect (cdr form)))
3822 3824
3823 (defun byte-compile-prog1 (form) 3825 (defun byte-compile-prog1 (form)
3824 (setq form (cdr form)) 3826 (setq form (cdr form))
3997 (if (memq 'unused-vars byte-compile-warnings) 3999 (if (memq 'unused-vars byte-compile-warnings)
3998 ;; done compiling in this scope, warn now. 4000 ;; done compiling in this scope, warn now.
3999 (byte-compile-warn-about-unused-variables)) 4001 (byte-compile-warn-about-unused-variables))
4000 (byte-compile-out 'byte-unbind (length (car (cdr form)))))) 4002 (byte-compile-out 'byte-unbind (length (car (cdr form))))))
4001 4003
4004 ;; We've renamed the integerp bytecode to fixnump, and changed its semantics
4005 ;; accordingly. This means #'integerp itself can't be as fast as it used to
4006 ;; be, since it no longer has a bytecode to itself. As it happens, though,
4007 ;; most of the non-core calls to #'integerp are in contexts where it is
4008 ;; either going to receive a fixnum, or something non-numeric entirely; the
4009 ;; contexts where it needs to distinguish between an integer and a float are
4010 ;; very rare. So, we can have (integerp X) compile to:
4011 ;;
4012 ;; (or (fixnump X) (and (numberp X) (funcall #'integerp X)))
4013 ;;
4014 ;; without the multiple evaluation of X, and where #'fixnump and #'numberp
4015 ;; both have bytecodes. We ignore for-effect, because byte-optimize.el will
4016 ;; delete this call in its presence.
4017 ;;
4018 ;; This approach is byte-code compatible with 21.4 and with earlier 21.5
4019 ;; (except that earlier 21.5 with bignum support will confuse Bfixnump and
4020 ;; Bintegerp; which it did in dealing with byte-compiled code from 21.4
4021 ;; anyway).
4022
4023 (defun byte-compile-integerp (form)
4024 (if (/= 2 (length form))
4025 (byte-compile-subr-wrong-args form 1)
4026 (let ((donetag (byte-compile-make-tag))
4027 (wintag (byte-compile-make-tag))
4028 (failtag (byte-compile-make-tag)))
4029 (byte-compile-constant 'integerp)
4030 (byte-compile-form (second form))
4031 (byte-compile-out 'byte-dup 0)
4032 (byte-compile-out 'byte-fixnump 0)
4033 (byte-compile-goto 'byte-goto-if-not-nil wintag)
4034 (byte-compile-out 'byte-dup 0)
4035 (byte-compile-out 'byte-numberp 0)
4036 (byte-compile-goto 'byte-goto-if-nil failtag)
4037 (byte-compile-out 'byte-call 1)
4038 ;; At this point, the only thing from this function remaining on the
4039 ;; stack is the return value of the called #'integerp, which reflects
4040 ;; exactly what we want. Go directly to donetag, do not discard
4041 ;; anything.
4042 (byte-compile-goto 'byte-goto donetag)
4043 (byte-compile-out-tag failtag)
4044 (byte-compile-discard)
4045 (byte-compile-discard)
4046 (byte-compile-constant nil)
4047 (byte-compile-goto 'byte-goto donetag)
4048 (byte-compile-out-tag wintag)
4049 (byte-compile-discard)
4050 (byte-compile-discard)
4051 (byte-compile-constant t)
4052 (byte-compile-out-tag donetag))))
4002 4053
4003 ;;(byte-defop-compiler-1 /= byte-compile-negated) 4054 ;;(byte-defop-compiler-1 /= byte-compile-negated)
4004 (byte-defop-compiler-1 atom byte-compile-negated) 4055 (byte-defop-compiler-1 atom byte-compile-negated)
4005 (byte-defop-compiler-1 nlistp byte-compile-negated) 4056 (byte-defop-compiler-1 nlistp byte-compile-negated)
4006 4057