unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Troy Hinckley <troyhinckley@gmail.com>
To: emacs-devel@gnu.org
Subject: macroexpand and bytecomp.el
Date: Fri, 9 Feb 2024 12:32:41 -0600	[thread overview]
Message-ID: <723bc16c-a73c-45a7-9362-99056261d932@Spark> (raw)
In-Reply-To: <f6486604-8a50-4e56-bd88-78e23b50477a@Spark>

[-- Attachment #1: Type: text/plain, Size: 1886 bytes --]

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

[-- Attachment #2: Type: text/html, Size: 3174 bytes --]

       reply	other threads:[~2024-02-09 18:32 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <f6486604-8a50-4e56-bd88-78e23b50477a@Spark>
2024-02-09 18:32 ` Troy Hinckley [this message]
2024-02-12 21:24   ` macroexpand and bytecomp.el Stefan Monnier via Emacs development discussions.

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=723bc16c-a73c-45a7-9362-99056261d932@Spark \
    --to=troyhinckley@gmail.com \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).