emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

macroexpand and bytecomp.el


From: Troy Hinckley
Subject: macroexpand and bytecomp.el
Date: Fri, 9 Feb 2024 12:32:41 -0600

I have a question about how macro-expansion is handled in bytecomp.el. There are two variables byte-code-vector and byte-stack+-info in bytecomp.el. They are populated by calls to byte-defop which will store the values in the tmp-compile-time-value property. After this, the variables are populated by a call to the byte-extrude-byte-code-vectors macro:

(defmacro byte-extrude-byte-code-vectors ()
 (prog1 (list 'setq 'byte-code-vector
 (get 'byte-code-vector 'tmp-compile-time-value)
 'byte-stack+-info
 (get 'byte-stack+-info 'tmp-compile-time-value))
 (put 'byte-code-vector 'tmp-compile-time-value nil)
 (put 'byte-stack+-info 'tmp-compile-time-value nil)))

However I don’t see how this would work with macro expansion. Eager macro expansion is enabled once internal-macroexpand-for-load is defined in macroexp.el (which should be before bytecomp.el is loaded). In lread.c the function load will call readevalloop which calls readevalloop_eager_expand_eval. That function will call internal-macroexpand-for-load at least twice. First time it will only expand the top level form, and then if that is not a progn form it will call it again to expand all forms. However I don’t understand how this would work with byte-extrude-byte-code-vectors. When that macro is called it will set the tmp-compile-time-value properties to nil, meaning that when the macro is called again byte-code-vector and byte-stack+-info will be set to nil as well.

I can see that happen if I load this dummy file

(defvar tmp-var [1 2 3])
(defvar my-var nil)

(defmacro my-extrude ()
 (prog1 (list 'setq 'my-var 'tmp-var)
 (setq tmp-var nil)))

(my-extrude)


Here my-var is set to nil. I understand why that is happening. What I don’t understand is why does this work in bytecomp.el? Why doesn't it have the issue with double expanded macros?

-Troy

reply via email to

[Prev in Thread] Current Thread [Next in Thread]