* bug#26601: 26.0.50; Improvements to cl-symbol-macrolet
@ 2017-04-22 3:59 npostavs
2017-06-08 2:28 ` npostavs
0 siblings, 1 reply; 2+ messages in thread
From: npostavs @ 2017-04-22 3:59 UTC (permalink / raw)
To: 26601; +Cc: Stefan Monnier
[-- Attachment #1: Type: text/plain, Size: 191 bytes --]
Severity: wishlist
Tags: patch
I was looking at the recent fix for #26325 [1: 89898e43c7], and I think splitting the
variable bindings from the main macro environment will simplify things:
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 5411 bytes --]
From d0233406d88f712041f8307e837b9f4f95f17c4b Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Fri, 21 Apr 2017 23:37:05 -0400
Subject: [PATCH v1] Split variable macro env from function env
* lisp/emacs-lisp/cl-macs.el (cl--sm-macroexpand): Remove.
(cl-symbol-macrolet): Instead of adding each binding directly into the
main environment with a special key format, put all symbol macro
bindings into a single entry in the main environment under
`:cl-symbol-macros'.
(cl--sm-macroexpand): Look up symbol bindings in the
`:cl-symbol-macros' entry of the environment.
---
lisp/emacs-lisp/cl-macs.el | 64 ++++++++++++++++++++--------------------------
1 file changed, 28 insertions(+), 36 deletions(-)
diff --git a/lisp/emacs-lisp/cl-macs.el b/lisp/emacs-lisp/cl-macs.el
index db1518ce61..b1ada00f4a 100644
--- a/lisp/emacs-lisp/cl-macs.el
+++ b/lisp/emacs-lisp/cl-macs.el
@@ -2047,28 +2047,22 @@ cl--old-macroexpand
cl--old-macroexpand
(symbol-function 'macroexpand)))
-(defun cl--symbol-macro-key (sym)
- "Return the key used in `macroexpand-all-environment' for symbol macro SYM."
- ;; In the past we've used `symbol-name' instead, but that doesn't
- ;; preserve the `eq'uality between different symbols of the same name.
- `(:cl-symbol-macro . ,sym))
-
(defun cl--sm-macroexpand (exp &optional env)
"Special macro expander used inside `cl-symbol-macrolet'.
This function replaces `macroexpand' during macro expansion
of `cl-symbol-macrolet', and does the same thing as `macroexpand'
except that it additionally expands symbol macros."
- (let ((macroexpand-all-environment env))
+ (let ((macroexpand-all-environment env)
+ (venv (alist-get :cl-symbol-macros env)))
(while
(progn
(setq exp (funcall cl--old-macroexpand exp env))
(pcase exp
((pred symbolp)
;; Perform symbol-macro expansion.
- ;; FIXME: Calling `cl--symbol-macro-key' for every var reference
- ;; is a bit more costly than I'd like.
- (when (cdr (assoc (cl--symbol-macro-key exp) env))
- (setq exp (cadr (assoc (cl--symbol-macro-key exp) env)))))
+ (let ((symval (assq exp venv)))
+ (when symval
+ (setq exp (cadr symval)))))
(`(setq . ,_)
;; Convert setq to setf if required by symbol-macro expansion.
(let* ((args (mapcar (lambda (f) (cl--sm-macroexpand f env))
@@ -2086,7 +2080,7 @@ cl--sm-macroexpand
(let ((letf nil) (found nil) (nbs ()))
(dolist (binding bindings)
(let* ((var (if (symbolp binding) binding (car binding)))
- (sm (assoc (cl--symbol-macro-key var) env)))
+ (sm (assq var venv)))
(push (if (not (cdr sm))
binding
(let ((nexp (cadr sm)))
@@ -2144,30 +2138,28 @@ cl-symbol-macrolet
\(fn ((NAME EXPANSION) ...) FORM...)"
(declare (indent 1) (debug ((&rest (symbolp sexp)) cl-declarations body)))
- (cond
- ((cdr bindings)
- `(cl-symbol-macrolet (,(car bindings))
- (cl-symbol-macrolet ,(cdr bindings) ,@body)))
- ((null bindings) (macroexp-progn body))
- (t
- (let ((previous-macroexpand (symbol-function 'macroexpand)))
- (unwind-protect
- (progn
- (fset 'macroexpand #'cl--sm-macroexpand)
- (let ((expansion
- ;; FIXME: For N bindings, this will traverse `body' N times!
- (macroexpand-all (macroexp-progn body)
- (cons (list (cl--symbol-macro-key
- (caar bindings))
- (cl-cadar bindings))
- macroexpand-all-environment))))
- (if (or (null (cdar bindings)) (cl-cddar bindings))
- (macroexp--warn-and-return
- (format-message "Malformed `cl-symbol-macrolet' binding: %S"
- (car bindings))
- expansion)
- expansion)))
- (fset 'macroexpand previous-macroexpand))))))
+ (let ((previous-macroexpand (symbol-function 'macroexpand))
+ (malformed-bindings nil))
+ (dolist (binding bindings)
+ (unless (and (consp binding) (symbolp (car binding))
+ (consp (cdr binding)) (null (cddr binding)))
+ (push binding malformed-bindings)))
+ (unwind-protect
+ (progn
+ (fset 'macroexpand #'cl--sm-macroexpand)
+ (let* ((venv (cdr (assq :cl-symbol-macros macroexpand-all-environment)))
+ (expansion
+ (macroexpand-all (macroexp-progn body)
+ (cons (cons :cl-symbol-macros
+ (append bindings venv))
+ macroexpand-all-environment))))
+ (if malformed-bindings
+ (macroexp--warn-and-return
+ (format-message "Malformed `cl-symbol-macrolet' binding(s): %S"
+ (nreverse malformed-bindings))
+ expansion)
+ expansion)))
+ (fset 'macroexpand previous-macroexpand))))
;;; Multiple values.
--
2.11.1
[-- Attachment #3: Type: text/plain, Size: 193 bytes --]
[1: 89898e43c7]: 2017-04-21 12:12:42 -0400
* lisp/emacs-lisp/cl-macs.el: Fix symbol-macrolet
http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=89898e43c7ceef28bb3c2116b4d8a3ec96d9c8da
^ permalink raw reply related [flat|nested] 2+ messages in thread
* bug#26601: 26.0.50; Improvements to cl-symbol-macrolet
2017-04-22 3:59 bug#26601: 26.0.50; Improvements to cl-symbol-macrolet npostavs
@ 2017-06-08 2:28 ` npostavs
0 siblings, 0 replies; 2+ messages in thread
From: npostavs @ 2017-06-08 2:28 UTC (permalink / raw)
To: 26601; +Cc: Stefan Monnier
tags 26601 fixed
close 26601
quit
npostavs@users.sourceforge.net writes:
> Subject: [PATCH v1] Split variable macro env from function env
>
> * lisp/emacs-lisp/cl-macs.el (cl--sm-macroexpand): Remove.
> (cl-symbol-macrolet): Instead of adding each binding directly into the
> main environment with a special key format, put all symbol macro
> bindings into a single entry in the main environment under
> `:cl-symbol-macros'.
> (cl--sm-macroexpand): Look up symbol bindings in the
> `:cl-symbol-macros' entry of the environment.
Pushed to master [1: 0648edf3e0].
[1: 0648edf3e0]: 2017-06-07 20:03:31 -0400
Split variable macro env from function env
http://git.savannah.gnu.org/cgit/emacs.git/commit/?id=0648edf3e05e224ee8410ab244df7364f919dc58
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2017-06-08 2:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-04-22 3:59 bug#26601: 26.0.50; Improvements to cl-symbol-macrolet npostavs
2017-06-08 2:28 ` npostavs
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.