Merge branch 'master' into scratch/correct-warning-pos
This commit is contained in:
commit
2128cd8c08
3085 changed files with 131924 additions and 16779 deletions
|
@ -1,6 +1,6 @@
|
|||
;;; macroexp.el --- Additional macro-expansion support -*- lexical-binding: t -*-
|
||||
;;
|
||||
;; Copyright (C) 2004-2021 Free Software Foundation, Inc.
|
||||
;; Copyright (C) 2004-2022 Free Software Foundation, Inc.
|
||||
;;
|
||||
;; Author: Miles Bader <miles@gnu.org>
|
||||
;; Keywords: lisp, compiler, macros
|
||||
|
@ -209,9 +209,12 @@ Other uses risk returning non-nil value that point to the wrong file."
|
|||
(defvar macroexp--warned (make-hash-table :test #'equal :weakness 'key))
|
||||
|
||||
(defun macroexp--warn-wrap (arg msg form category)
|
||||
(let ((when-compiled (lambda ()
|
||||
(when (byte-compile-warning-enabled-p category)
|
||||
(byte-compile-warn-x arg "%s" msg)))))
|
||||
(let ((when-compiled
|
||||
(lambda ()
|
||||
(when (if (consp category)
|
||||
(apply #'byte-compile-warning-enabled-p category)
|
||||
(byte-compile-warning-enabled-p category))
|
||||
(byte-compile-warn-x arg "%s" msg)))))
|
||||
`(progn
|
||||
(macroexp--funcall-if-compiled ',when-compiled)
|
||||
,form)))
|
||||
|
@ -294,7 +297,7 @@ is executed without being compiled first."
|
|||
fun obsolete
|
||||
(if (symbolp (symbol-function fun))
|
||||
"alias" "macro"))
|
||||
new-form 'obsolete))
|
||||
new-form (list 'obsolete fun)))
|
||||
new-form)))
|
||||
|
||||
(defun macroexp--unfold-lambda (form &optional name)
|
||||
|
@ -361,6 +364,16 @@ is executed without being compiled first."
|
|||
`(let ,(nreverse bindings) . ,body)
|
||||
(macroexp-progn body)))))
|
||||
|
||||
(defun macroexp--dynamic-variable-p (var)
|
||||
"Whether the variable VAR is dynamically scoped.
|
||||
Only valid during macro-expansion."
|
||||
(defvar byte-compile-bound-variables)
|
||||
(or (not lexical-binding)
|
||||
(special-variable-p var)
|
||||
(memq var macroexp--dynvars)
|
||||
(and (boundp 'byte-compile-bound-variables)
|
||||
(memq var byte-compile-bound-variables))))
|
||||
|
||||
(defun macroexp--expand-all (form)
|
||||
"Expand all macros in FORM.
|
||||
This is an internal version of `macroexpand-all'.
|
||||
|
@ -388,29 +401,33 @@ Assumes the caller has bound `macroexpand-all-environment'."
|
|||
(cddr form))
|
||||
(cdr form))
|
||||
form))
|
||||
(`(,(or 'defvar 'defconst) . ,_) (macroexp--all-forms form 2))
|
||||
(`(,(or 'defvar 'defconst) ,(and name (pred symbolp)) . ,_)
|
||||
(push name macroexp--dynvars)
|
||||
(macroexp--all-forms form 2))
|
||||
(`(function ,(and f `(lambda . ,_)))
|
||||
(macroexp--cons 'function
|
||||
(macroexp--cons (macroexp--all-forms f 2)
|
||||
nil
|
||||
(cdr form))
|
||||
form))
|
||||
(let ((macroexp--dynvars macroexp--dynvars))
|
||||
(macroexp--cons 'function
|
||||
(macroexp--cons (macroexp--all-forms f 2)
|
||||
nil
|
||||
(cdr form))
|
||||
form)))
|
||||
(`(,(or 'function 'quote) . ,_) form)
|
||||
(`(,(and fun (or 'let 'let*)) . ,(or `(,bindings . ,body)
|
||||
pcase--dontcare))
|
||||
(macroexp--cons
|
||||
fun
|
||||
(macroexp--cons
|
||||
(macroexp--all-clauses bindings 1)
|
||||
(if (null body)
|
||||
(macroexp-unprogn
|
||||
(macroexp-warn-and-return
|
||||
fun
|
||||
(format "Empty %s body" fun)
|
||||
nil nil 'compile-only))
|
||||
(macroexp--all-forms body))
|
||||
(cdr form))
|
||||
form))
|
||||
(let ((macroexp--dynvars macroexp--dynvars))
|
||||
(macroexp--cons
|
||||
fun
|
||||
(macroexp--cons
|
||||
(macroexp--all-clauses bindings 1)
|
||||
(if (null body)
|
||||
(macroexp-unprogn
|
||||
(macroexp-warn-and-return
|
||||
fun
|
||||
(format "Empty %s body" fun)
|
||||
nil nil 'compile-only))
|
||||
(macroexp--all-forms body))
|
||||
(cdr form))
|
||||
form)))
|
||||
(`(,(and fun `(lambda . ,_)) . ,args)
|
||||
;; Embedded lambda in function position.
|
||||
;; If the byte-optimizer is loaded, try to unfold this,
|
||||
|
@ -495,6 +512,14 @@ Assumes the caller has bound `macroexpand-all-environment'."
|
|||
If no macros are expanded, FORM is returned unchanged.
|
||||
The second optional arg ENVIRONMENT specifies an environment of macro
|
||||
definitions to shadow the loaded ones for use in file byte-compilation."
|
||||
(let ((macroexpand-all-environment environment)
|
||||
(macroexp--dynvars macroexp--dynvars))
|
||||
(macroexp--expand-all form)))
|
||||
|
||||
;; This function is like `macroexpand-all' but for use with top-level
|
||||
;; forms. It does not dynbind `macroexp--dynvars' because we want
|
||||
;; top-level `defvar' declarations to be recorded in that variable.
|
||||
(defun macroexpand--all-toplevel (form &optional environment)
|
||||
(let ((macroexpand-all-environment environment))
|
||||
(macroexp--expand-all form)))
|
||||
|
||||
|
@ -781,7 +806,7 @@ test of free variables in the following ways:
|
|||
(let ((macroexp--pending-eager-loads
|
||||
(cons load-file-name macroexp--pending-eager-loads)))
|
||||
(if full-p
|
||||
(macroexpand-all form)
|
||||
(macroexpand--all-toplevel form)
|
||||
(macroexpand form)))
|
||||
(error
|
||||
;; Hopefully this shouldn't happen thanks to the cycle detection,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue