>>>> "Y" == Yoshiki Hayashi
<yoshiki(a)xemacs.org> writes:
Y> When following form is eval'ed, it signals an error:
Y> Wrong type argument: number-char-or-marker-p, a
Y> (= 'a)
Y> However, if it's byte-compiled, it returns t.
Y> (disassemble (byte-compile (lambda () (= 'a))))
Y> shows:
Y> byte code:
Y> args: nil
Y> 0 constant t
Y> 1 return
Y> Martin?
`byte-compile-delete-errors' is a variable declared in Lisp.
-- loaded from "bytecomp"
Value: t
Documentation:
*If non-nil, the optimizer may delete forms that may signal an error.
This includes variable references and calls to functions such as `car'.
There is already this code in byte-plus that optimizes (+ x) ==> x
(case elt
(0 (when (not byte-compile-delete-errors)
(byte-compile-constant 0)
(byte-compile-out 'byte-plus 0)))
(+1 (byte-compile-out 'byte-add1 0))
(-1 (byte-compile-out 'byte-sub1 0))
(= x) should work the same way.
You can also argue that if the argument (or arguments) is/are CONSTANT,
then there should be compile-time evaluation. I haven't implemented
that in this patch.
Index: lisp/ChangeLog
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs/lisp/ChangeLog,v
retrieving revision 1.292
diff -u -w -U0 -r1.292 ChangeLog
--- lisp/ChangeLog 2001/05/20 01:17:07 1.292
+++ lisp/ChangeLog 2001/05/20 06:01:49
@@ -0,0 +1,5 @@
+2001-05-20 Martin Buchholz <martin(a)xemacs.org>
+
+ * bytecomp.el (byte-compile-arithcompare):
+ Only optimize (= x) ==> t if byte-compile-delete-errors is nil.
+
Index: lisp/bytecomp.el
===================================================================
RCS file: /usr/CVSroot/XEmacs/xemacs/lisp/bytecomp.el,v
retrieving revision 1.12
diff -u -w -r1.12 bytecomp.el
--- lisp/bytecomp.el 2001/05/04 22:41:59 1.12
+++ lisp/bytecomp.el 2001/05/20 06:02:18
@@ -3205,7 +3205,9 @@
(defun byte-compile-arithcompare (form)
(case (length (cdr form))
(0 (byte-compile-subr-wrong-args form "1 or more"))
- (1 (byte-compile-constant t))
+ (1 (if byte-compile-delete-errors
+ (byte-compile-constant t)
+ (byte-compile-normal-call form)))
(2 (byte-compile-two-args form))
(t (byte-compile-normal-call form))))