[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/macrostep b449cd0 059/110: Restore compiler-macro expansio
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/macrostep b449cd0 059/110: Restore compiler-macro expansion under SLIME |
Date: |
Sat, 7 Aug 2021 09:18:02 -0400 (EDT) |
branch: elpa/macrostep
commit b449cd012a67c359886a51487ae275b59e6a3af2
Author: joddie <jonxfield@gmail.com>
Commit: joddie <jonxfield@gmail.com>
Restore compiler-macro expansion under SLIME
---
macrostep.el | 26 ++++++++-----
swank-macrostep.lisp | 108 ++++++++++++++++++++++++++++++++-------------------
2 files changed, 85 insertions(+), 49 deletions(-)
diff --git a/macrostep.el b/macrostep.el
index b0c4aab..379b351 100644
--- a/macrostep.el
+++ b/macrostep.el
@@ -913,7 +913,9 @@ expansion will not be fontified. See also
(add-hook 'slime-mode-hook #'macrostep-slime-mode-hook)
(defun macrostep-slime-expand-1 (string)
- (slime-eval `(swank-macrostep:macrostep-expand-1 ,string nil)))
+ (slime-eval
+ `(swank-macrostep:macrostep-expand-1
+ ,string nil ,macrostep-expand-compiler-macros)))
(defun macrostep-slime-insert (result)
"Insert RESULT at point, indenting to match the current column."
@@ -935,17 +937,23 @@ expansion will not be fontified. See also
(save-excursion
(goto-char start)
(while (search-forward-regexp regexp end t)
- (replace-match (assoc-default (match-string 2) substitutions)
- t t nil 2)
- (put-text-property (match-beginning 1) (match-end 1)
- 'macrostep-macro-start t)
- (put-text-property (match-beginning 2) (match-end 2)
- 'font-lock-face
- 'macrostep-macro-face))))))
+ (pcase (assoc (match-string 2) substitutions)
+ (`(,_ ,original-symbol ,type)
+ (setq end (+ end (- (length original-symbol)
+ (length (match-string 2)))))
+ (replace-match original-symbol t t nil 2)
+ (put-text-property (match-beginning 1) (match-end 1)
+ 'macrostep-macro-start t)
+ (put-text-property (match-beginning 2) (match-end 2)
+ 'font-lock-face
+ (if (eq type :macro)
+ 'macrostep-macro-face
+ 'macrostep-compiler-macro-face)))))))))
(defun macrostep-slime-macro-form-p (string)
(slime-eval
- `(swank-macrostep:macro-form-p ,string nil)))
+ `(swank-macrostep:macro-form-p
+ ,string nil ,macrostep-expand-compiler-macros)))
(defun macrostep-slime-environment-at-point ()
(save-excursion
diff --git a/swank-macrostep.lisp b/swank-macrostep.lisp
index e5b2310..b411051 100644
--- a/swank-macrostep.lisp
+++ b/swank-macrostep.lisp
@@ -4,7 +4,8 @@
(:import-from swank
#:with-buffer-syntax
#:to-string
- #:macroexpand-all)
+ #:macroexpand-all
+ #:compiler-macroexpand-1)
(:export #:macrostep-expand-1
#:macro-form-p))
@@ -14,20 +15,27 @@
(with-buffer-syntax ()
(let* ((form (read-from-string string))
(bindings (mapcar #'read-from-string binding-strings))
- (env (compute-environment bindings)))
- (case (macro-form-type form env compiler-macros?)
- (macro
- (multiple-value-bind (expansion substitutions)
- (substitute-macros (macroexpand-1 form env))
- (list
- (to-string expansion)
- (loop for (replacement . original) in substitutions
- collect (cons (to-string replacement)
- (to-string original))))))
- (compiler-macro
- (error "Not implemented"))
- (t
- (error "Not a macro form"))))))
+ (env (compute-environment bindings))
+ (expansion
+ (multiple-value-bind (expansion expanded?)
+ (macroexpand-1 form env)
+ (if expanded?
+ expansion
+ (if (not compiler-macros?)
+ (error "Not a macro form.")
+ (multiple-value-bind (expansion expanded?)
+ (compiler-macroexpand-1 form env)
+ (if expanded?
+ expansion
+ (error "Not a macro or compiler-macro form."))))))))
+ (multiple-value-bind (result substitutions)
+ (substitute-macros expansion)
+ (list
+ (to-string result)
+ (loop for (gensym original type) in substitutions
+ collect (list (to-string gensym)
+ (to-string original)
+ type)))))))
(defun macro-form-p (string binding-strings &optional compiler-macros?)
(with-buffer-syntax ()
@@ -42,10 +50,10 @@
(not (symbolp (car sexp))))
nil)
((macro-function (car sexp) environment)
- 'macro)
+ :macro)
((and compiler-macros?
(compiler-macro-function (car sexp) environment))
- 'compiler-macro)
+ :compiler-macro)
(t
nil)))
@@ -63,8 +71,9 @@
`(macrolet ,binding-list ,subexpression))))
(defun substitute-macros (form)
- (let ((forms (collect-macro-forms form)))
- (substitute-macro-forms form forms)))
+ (multiple-value-bind (macro-forms compiler-macro-forms)
+ (collect-macro-forms form)
+ (substitute-macro-forms form macro-forms compiler-macro-forms)))
(defun collect-macro-forms (form)
(let* ((real-macroexpand-hook *macroexpand-hook*)
@@ -73,26 +82,45 @@
(lambda (macro-function form environment)
(setq macro-forms
(cons form macro-forms))
+ (funcall real-macroexpand-hook macro-function form environment)))
+ (expansion (ignore-errors (macroexpand-all form)))
+ (compiler-macro-forms '())
+ (*macroexpand-hook*
+ (lambda (macro-function form environment)
+ (setq compiler-macro-forms
+ (cons form compiler-macro-forms))
(funcall real-macroexpand-hook macro-function form environment))))
- (macroexpand-all form)
- macro-forms))
+ (ignore-errors
+ (compile nil `(lambda () ,expansion)))
+ (values macro-forms compiler-macro-forms)))
-(defun substitute-macro-forms (form forms)
- (cond ((not (consp form))
- (values form nil))
- ((member form forms :test 'eq)
- (multiple-value-bind (rest replacements)
- (substitute-macro-forms (cdr form) forms)
- (let ((replacement (gensym)))
- (values
- (cons replacement rest)
- (cons (cons replacement (car form))
- replacements)))))
- (t
- (multiple-value-bind (car replacements-1)
- (substitute-macro-forms (car form) forms)
- (multiple-value-bind (cdr replacements-2)
- (substitute-macro-forms (cdr form) forms)
- (values
- (cons car cdr)
- (append replacements-1 replacements-2)))))))
+(defun substitute-macro-forms (form macro-forms compiler-macro-forms)
+ (labels
+ ((macro-form? (form)
+ (member form macro-forms :test 'eq))
+ (compiler-macro-form? (form)
+ (member form compiler-macro-forms :test 'eq))
+ (recur (form)
+ (let (macro? compiler-macro?)
+ (cond ((not (consp form))
+ (values form nil))
+ ((or
+ (setf macro? (macro-form? form))
+ (setf compiler-macro? (compiler-macro-form? form)))
+ (multiple-value-bind (rest replacements)
+ (recur (cdr form))
+ (let ((replacement (gensym)))
+ (values
+ (cons replacement rest)
+ (cons (list replacement (car form)
+ (if macro? :macro :compiler-macro))
+ replacements)))))
+ (t
+ (multiple-value-bind (car replacements-1)
+ (recur (car form))
+ (multiple-value-bind (cdr replacements-2)
+ (recur (cdr form))
+ (values
+ (cons car cdr)
+ (append replacements-1 replacements-2)))))))))
+ (recur form)))
- [nongnu] elpa/macrostep c5d1c5b 009/110: Autoload macro definitions if needed., (continued)
- [nongnu] elpa/macrostep c5d1c5b 009/110: Autoload macro definitions if needed., ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep 8b89694 012/110: Only enter macrostep-mode after successful macro expansion, ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep b060e1a 014/110: Add visible highlight of expanded section, ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep 4b0d96f 013/110: Remove incorrect use of :version in defgroup, ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep 0bcb143 019/110: Handle backquotes better, ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep 1c01145 039/110: Merge pull request #9 from xuchunyang/master, ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep c20152b 011/110: Handle aliases by using `indirect-function' instead of `symbol-function', ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep 99ac330 029/110: Make inner macrolet definitions correctly shadow outer, ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep 0c8b64c 051/110: Position macrostep-slime-macro-form-p in the correct package, ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep f34deb7 055/110: Specify text bounds when propertizing SLIME macros, ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep b449cd0 059/110: Restore compiler-macro expansion under SLIME,
ELPA Syncer <=
- [nongnu] elpa/macrostep 5e0c28f 068/110: Establish *macroexpand-printer-bindings* before pretty printing, ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep 80ae101 083/110: Fix SLIME functions for updated generic interface, ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep 8f74a4b 084/110: Toggle separate-buffer expansion with prefix (#8), ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep c594c09 092/110: `cl-macs' is no longer needed at run-time, ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep 94d40f2 093/110: Check that compiler-macros return a changed form, ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep d6aa67c 097/110: Be consistent about only using prefixed `cl-lib`, ELPA Syncer, 2021/08/07
- [nongnu] elpa/macrostep 1e25932 105/110: add lib/.nosearch, ELPA Syncer, 2021/08/07