Martin S, thanks for the report. I apologize for not getting to this
earlier, but I don't know all that much about the byte compiler yet.
And I didn't want to waste Martin Buchholz's time, although he's the
obvious consultant (and it turns out that he probably made the
relevant change); he's on leave from the project at the moment.
>>>> "Martin" == Martin Stjernholm
<mast(a)lysator.liu.se> writes:
Martin> Consider an elisp file containing this:
(eval-when-compile
(defvar x (cl-macroexpand-all '(eval-when-compile
(error "evaluated"))))
nil)
Martin> If this is byte compiled in XEmacs 21.4.6, the error
Martin> "evaluated" is signalled inside the byte compiler. It
Martin> turns out that the content of the `eval-when-compile' is
Martin> evaluated during the `cl-macroexpand-all' call. I did not
Martin> expect `error' to be evaluated at that point since it's a
Martin> function and not a macro.
Martin> This is a regression from (at least) XEmacs 20.4 and
Martin> 19.16, where x is simply assigned the quoted value (error
Martin> "evaluated") at compile time. FSF Emacs also works that
Martin> way.
As does XEmacs 21.1. This looks like it's due to a change by Martin
Buchholz:
2000-11-17 Martin Buchholz <martin(a)xemacs.org>
* bytecomp.el (byte-compile-eval): New.
(byte-compile-initial-macro-environment): Use byte-compile-eval.
Keeps this promise made in Lispref:
"If a file being compiled contains a `defmacro' form, the macro is
defined temporarily for the rest of the compilation of that file."
I've tried putting the call to byte-compile-top-level back in (see
partial diff 21.4 vs 21.1 below); that doesn't help. Changing
byte-compile-eval back to eval does help. Martin B, do you have any
idea what's going on here?
Also, I don't understand what byte-compile-eval is supposed to protect
against; I can't find anything---except the initialization and a
couple places that bind byte-compile-macro-environment to nil---that
actually changes byte-compile-macro-environment. I'm adding Martin
S's test case to the regression suite; do you have one that exercises
byte-compile-eval?
Index: lisp/bytecomp.el
===================================================================
RCS file: /pack/xemacscvs/XEmacs/xemacs/lisp/bytecomp.el,v
retrieving revision 1.10
retrieving revision 1.11.2.1
diff -u -r1.10 -r1.11.2.1
--- lisp/bytecomp.el 17 Nov 2000 03:21:22 -0000 1.10
+++ lisp/bytecomp.el 25 Jul 2001 07:44:22 -0000 1.11.2.1
@@ -443,16 +443,33 @@
(defvar byte-compiler-error-flag)
+;;; A form of eval that includes the currently defined macro definitions.
+;;; This helps implement the promise made in the Lispref:
+;;;
+;;; "If a file being compiled contains a `defmacro' form, the macro is
+;;; defined temporarily for the rest of the compilation of that file."
+(defun byte-compile-eval (form)
+ (let ((save-macro-environment nil))
+ (unwind-protect
+ (loop for (sym . def) in byte-compile-macro-environment do
+ (push
+ (if (fboundp sym) (cons sym (symbol-function sym)) sym)
+ save-macro-environment)
+ (fset sym (cons 'macro def))
+ finally return (eval form))
+ (dolist (elt save-macro-environment)
+ (if (symbolp elt)
+ (fmakunbound elt)
+ (fset (car elt) (cdr elt)))))))
+
(defconst byte-compile-initial-macro-environment
- (purecopy
- '((byte-compiler-options . (lambda (&rest forms)
- (apply 'byte-compiler-options-handler forms)))
- (eval-when-compile . (lambda (&rest body)
- (list 'quote (eval (byte-compile-top-level
- (cons 'progn body))))))
- (eval-and-compile . (lambda (&rest body)
- (eval (cons 'progn body))
- (cons 'progn body)))))
+ '((byte-compiler-options . (lambda (&rest forms)
+ (apply 'byte-compiler-options-handler forms)))
+ (eval-when-compile . (lambda (&rest body)
+ (list 'quote (byte-compile-eval (cons 'progn body)))))
+ (eval-and-compile . (lambda (&rest body)
+ (byte-compile-eval (cons 'progn body))
+ (cons 'progn body))))
"The default macro-environment passed to macroexpand by the compiler.
Placing a macro here will cause a macro to have different semantics when
expanded by the compiler as when expanded by the interpreter.")
--
Institute of Policy and Planning Sciences
http://turnbull.sk.tsukuba.ac.jp
University of Tsukuba Tennodai 1-1-1 Tsukuba 305-8573 JAPAN
My nostalgia for Icon makes me forget about any of the bad things. I don't
have much nostalgia for Perl, so its faults I remember. Scott Gilbert c.l.py