aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2012-06-06 14:08:00 -0400
committerStefan Monnier2012-06-06 14:08:00 -0400
commitfa779ab0e22aa8206dd172a5e7610330856f1daf (patch)
treea01e37121bcbeea6677636f75767583c4ba72d11
parent628299e039e9b16f7daec2c7afe44e1b43c5753d (diff)
downloademacs-fa779ab0e22aa8206dd172a5e7610330856f1daf.tar.gz
emacs-fa779ab0e22aa8206dd172a5e7610330856f1daf.zip
* lisp/emacs-lisp/macroexp.el: Don't require CL since we don't use it.
(macroexp--cons): Rename from maybe-cons. (macroexp--accumulate): Rename from macroexp-accumulate. (macroexp--all-forms): Rename from macroexpand-all-forms. (macroexp--all-clauses): Rename from macroexpand-all-clauses. (macroexp--expand-all): Rename from macroexpand-all-1.
-rw-r--r--lisp/ChangeLog9
-rw-r--r--lisp/emacs-lisp/macroexp.el74
2 files changed, 45 insertions, 38 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index fff6a2295f5..db1a35d1cfc 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,12 @@
12012-06-06 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * emacs-lisp/macroexp.el: Don't require CL since we don't use it.
4 (macroexp--cons): Rename from maybe-cons.
5 (macroexp--accumulate): Rename from macroexp-accumulate.
6 (macroexp--all-forms): Rename from macroexpand-all-forms.
7 (macroexp--all-clauses): Rename from macroexpand-all-clauses.
8 (macroexp--expand-all): Rename from macroexpand-all-1.
9
12012-06-06 Sam Steingold <sds@gnu.org> 102012-06-06 Sam Steingold <sds@gnu.org>
2 11
3 * calendar/calendar.el (calendar-in-read-only-buffer): 12 * calendar/calendar.el (calendar-in-read-only-buffer):
diff --git a/lisp/emacs-lisp/macroexp.el b/lisp/emacs-lisp/macroexp.el
index 514824554d1..7c413c7366f 100644
--- a/lisp/emacs-lisp/macroexp.el
+++ b/lisp/emacs-lisp/macroexp.el
@@ -29,13 +29,11 @@
29 29
30;;; Code: 30;;; Code:
31 31
32(eval-when-compile (require 'cl))
33
34;; Bound by the top-level `macroexpand-all', and modified to include any 32;; Bound by the top-level `macroexpand-all', and modified to include any
35;; macros defined by `defmacro'. 33;; macros defined by `defmacro'.
36(defvar macroexpand-all-environment nil) 34(defvar macroexpand-all-environment nil)
37 35
38(defun maybe-cons (car cdr original-cons) 36(defun macroexp--cons (car cdr original-cons)
39 "Return (CAR . CDR), using ORIGINAL-CONS if possible." 37 "Return (CAR . CDR), using ORIGINAL-CONS if possible."
40 (if (and (eq car (car original-cons)) (eq cdr (cdr original-cons))) 38 (if (and (eq car (car original-cons)) (eq cdr (cdr original-cons)))
41 original-cons 39 original-cons
@@ -43,9 +41,9 @@
43 41
44;; We use this special macro to iteratively process forms and share list 42;; We use this special macro to iteratively process forms and share list
45;; structure of the result with the input. Doing so recursively using 43;; structure of the result with the input. Doing so recursively using
46;; `maybe-cons' results in excessively deep recursion for very long 44;; `macroexp--cons' results in excessively deep recursion for very long
47;; input forms. 45;; input forms.
48(defmacro macroexp-accumulate (var+list &rest body) 46(defmacro macroexp--accumulate (var+list &rest body)
49 "Return a list of the results of evaluating BODY for each element of LIST. 47 "Return a list of the results of evaluating BODY for each element of LIST.
50Evaluate BODY with VAR bound to each `car' from LIST, in turn. 48Evaluate BODY with VAR bound to each `car' from LIST, in turn.
51Return a list of the values of the final form in BODY. 49Return a list of the values of the final form in BODY.
@@ -76,27 +74,27 @@ result will be eq to LIST).
76 (setq ,tail (cdr ,tail))) 74 (setq ,tail (cdr ,tail)))
77 (nconc (nreverse ,unshared) ,shared)))) 75 (nconc (nreverse ,unshared) ,shared))))
78 76
79(defun macroexpand-all-forms (forms &optional skip) 77(defun macroexp--all-forms (forms &optional skip)
80 "Return FORMS with macros expanded. FORMS is a list of forms. 78 "Return FORMS with macros expanded. FORMS is a list of forms.
81If SKIP is non-nil, then don't expand that many elements at the start of 79If SKIP is non-nil, then don't expand that many elements at the start of
82FORMS." 80FORMS."
83 (macroexp-accumulate (form forms) 81 (macroexp--accumulate (form forms)
84 (if (or (null skip) (zerop skip)) 82 (if (or (null skip) (zerop skip))
85 (macroexpand-all-1 form) 83 (macroexp--expand-all form)
86 (setq skip (1- skip)) 84 (setq skip (1- skip))
87 form))) 85 form)))
88 86
89(defun macroexpand-all-clauses (clauses &optional skip) 87(defun macroexp--all-clauses (clauses &optional skip)
90 "Return CLAUSES with macros expanded. 88 "Return CLAUSES with macros expanded.
91CLAUSES is a list of lists of forms; any clause that's not a list is ignored. 89CLAUSES is a list of lists of forms; any clause that's not a list is ignored.
92If SKIP is non-nil, then don't expand that many elements at the start of 90If SKIP is non-nil, then don't expand that many elements at the start of
93each clause." 91each clause."
94 (macroexp-accumulate (clause clauses) 92 (macroexp--accumulate (clause clauses)
95 (if (listp clause) 93 (if (listp clause)
96 (macroexpand-all-forms clause skip) 94 (macroexp--all-forms clause skip)
97 clause))) 95 clause)))
98 96
99(defun macroexpand-all-1 (form) 97(defun macroexp--expand-all (form)
100 "Expand all macros in FORM. 98 "Expand all macros in FORM.
101This is an internal version of `macroexpand-all'. 99This is an internal version of `macroexpand-all'.
102Assumes the caller has bound `macroexpand-all-environment'." 100Assumes the caller has bound `macroexpand-all-environment'."
@@ -105,7 +103,7 @@ Assumes the caller has bound `macroexpand-all-environment'."
105 ;; generates exceedingly deep expansions from relatively shallow input 103 ;; generates exceedingly deep expansions from relatively shallow input
106 ;; forms. We just process it `in reverse' -- first we expand all the 104 ;; forms. We just process it `in reverse' -- first we expand all the
107 ;; arguments, _then_ we expand the top-level definition. 105 ;; arguments, _then_ we expand the top-level definition.
108 (macroexpand (macroexpand-all-forms form 1) 106 (macroexpand (macroexp--all-forms form 1)
109 macroexpand-all-environment) 107 macroexpand-all-environment)
110 ;; Normal form; get its expansion, and then expand arguments. 108 ;; Normal form; get its expansion, and then expand arguments.
111 (let ((new-form (macroexpand form macroexpand-all-environment))) 109 (let ((new-form (macroexpand form macroexpand-all-environment)))
@@ -118,34 +116,34 @@ Assumes the caller has bound `macroexpand-all-environment'."
118 (setq form new-form)) 116 (setq form new-form))
119 (pcase form 117 (pcase form
120 (`(cond . ,clauses) 118 (`(cond . ,clauses)
121 (maybe-cons 'cond (macroexpand-all-clauses clauses) form)) 119 (macroexp--cons 'cond (macroexp--all-clauses clauses) form))
122 (`(condition-case . ,(or `(,err ,body . ,handlers) dontcare)) 120 (`(condition-case . ,(or `(,err ,body . ,handlers) dontcare))
123 (maybe-cons 121 (macroexp--cons
124 'condition-case 122 'condition-case
125 (maybe-cons err 123 (macroexp--cons err
126 (maybe-cons (macroexpand-all-1 body) 124 (macroexp--cons (macroexp--expand-all body)
127 (macroexpand-all-clauses handlers 1) 125 (macroexp--all-clauses handlers 1)
128 (cddr form)) 126 (cddr form))
129 (cdr form)) 127 (cdr form))
130 form)) 128 form))
131 (`(,(or `defvar `defconst) . ,_) (macroexpand-all-forms form 2)) 129 (`(,(or `defvar `defconst) . ,_) (macroexp--all-forms form 2))
132 (`(function ,(and f `(lambda . ,_))) 130 (`(function ,(and f `(lambda . ,_)))
133 (maybe-cons 'function 131 (macroexp--cons 'function
134 (maybe-cons (macroexpand-all-forms f 2) 132 (macroexp--cons (macroexp--all-forms f 2)
135 nil 133 nil
136 (cdr form)) 134 (cdr form))
137 form)) 135 form))
138 (`(,(or `function `quote) . ,_) form) 136 (`(,(or `function `quote) . ,_) form)
139 (`(,(and fun (or `let `let*)) . ,(or `(,bindings . ,body) dontcare)) 137 (`(,(and fun (or `let `let*)) . ,(or `(,bindings . ,body) dontcare))
140 (maybe-cons fun 138 (macroexp--cons fun
141 (maybe-cons (macroexpand-all-clauses bindings 1) 139 (macroexp--cons (macroexp--all-clauses bindings 1)
142 (macroexpand-all-forms body) 140 (macroexp--all-forms body)
143 (cdr form)) 141 (cdr form))
144 form)) 142 form))
145 (`(,(and fun `(lambda . ,_)) . ,args) 143 (`(,(and fun `(lambda . ,_)) . ,args)
146 ;; Embedded lambda in function position. 144 ;; Embedded lambda in function position.
147 (maybe-cons (macroexpand-all-forms fun 2) 145 (macroexp--cons (macroexp--all-forms fun 2)
148 (macroexpand-all-forms args) 146 (macroexp--all-forms args)
149 form)) 147 form))
150 ;; The following few cases are for normal function calls that 148 ;; The following few cases are for normal function calls that
151 ;; are known to funcall one of their arguments. The byte 149 ;; are known to funcall one of their arguments. The byte
@@ -161,22 +159,22 @@ Assumes the caller has bound `macroexpand-all-environment'."
161 (format "%s quoted with ' rather than with #'" 159 (format "%s quoted with ' rather than with #'"
162 (list 'lambda (nth 1 f) '...)) 160 (list 'lambda (nth 1 f) '...))
163 t) 161 t)
164 ;; We don't use `maybe-cons' since there's clearly a change. 162 ;; We don't use `macroexp--cons' since there's clearly a change.
165 (cons fun 163 (cons fun
166 (cons (macroexpand-all-1 (list 'function f)) 164 (cons (macroexp--expand-all (list 'function f))
167 (macroexpand-all-forms args)))) 165 (macroexp--all-forms args))))
168 ;; Second arg is a function: 166 ;; Second arg is a function:
169 (`(,(and fun (or `sort)) ,arg1 ',(and f `(lambda . ,_)) . ,args) 167 (`(,(and fun (or `sort)) ,arg1 ',(and f `(lambda . ,_)) . ,args)
170 (byte-compile-log-warning 168 (byte-compile-log-warning
171 (format "%s quoted with ' rather than with #'" 169 (format "%s quoted with ' rather than with #'"
172 (list 'lambda (nth 1 f) '...)) 170 (list 'lambda (nth 1 f) '...))
173 t) 171 t)
174 ;; We don't use `maybe-cons' since there's clearly a change. 172 ;; We don't use `macroexp--cons' since there's clearly a change.
175 (cons fun 173 (cons fun
176 (cons (macroexpand-all-1 arg1) 174 (cons (macroexp--expand-all arg1)
177 (cons (macroexpand-all-1 175 (cons (macroexp--expand-all
178 (list 'function f)) 176 (list 'function f))
179 (macroexpand-all-forms args))))) 177 (macroexp--all-forms args)))))
180 (`(,func . ,_) 178 (`(,func . ,_)
181 ;; Macro expand compiler macros. This cannot be delayed to 179 ;; Macro expand compiler macros. This cannot be delayed to
182 ;; byte-optimize-form because the output of the compiler-macro can 180 ;; byte-optimize-form because the output of the compiler-macro can
@@ -196,14 +194,14 @@ Assumes the caller has bound `macroexpand-all-environment'."
196 ;; No compiler macro. We just expand each argument (for 194 ;; No compiler macro. We just expand each argument (for
197 ;; setq/setq-default this works alright because the variable names 195 ;; setq/setq-default this works alright because the variable names
198 ;; are symbols). 196 ;; are symbols).
199 (macroexpand-all-forms form 1) 197 (macroexp--all-forms form 1)
200 (let ((newform (condition-case err 198 (let ((newform (condition-case err
201 (apply handler form (cdr form)) 199 (apply handler form (cdr form))
202 (error (message "Compiler-macro error: %S" err) 200 (error (message "Compiler-macro error: %S" err)
203 form)))) 201 form))))
204 (if (eq form newform) 202 (if (eq form newform)
205 ;; The compiler macro did not find anything to do. 203 ;; The compiler macro did not find anything to do.
206 (if (equal form (setq newform (macroexpand-all-forms form 1))) 204 (if (equal form (setq newform (macroexp--all-forms form 1)))
207 form 205 form
208 ;; Maybe after processing the args, some new opportunities 206 ;; Maybe after processing the args, some new opportunities
209 ;; appeared, so let's try the compiler macro again. 207 ;; appeared, so let's try the compiler macro again.
@@ -213,8 +211,8 @@ Assumes the caller has bound `macroexpand-all-environment'."
213 newform))) 211 newform)))
214 (if (eq newform form) 212 (if (eq newform form)
215 newform 213 newform
216 (macroexpand-all-1 newform))) 214 (macroexp--expand-all newform)))
217 (macroexpand-all-1 newform)))))) 215 (macroexp--expand-all newform))))))
218 216
219 (t form)))) 217 (t form))))
220 218
@@ -225,7 +223,7 @@ If no macros are expanded, FORM is returned unchanged.
225The second optional arg ENVIRONMENT specifies an environment of macro 223The second optional arg ENVIRONMENT specifies an environment of macro
226definitions to shadow the loaded ones for use in file byte-compilation." 224definitions to shadow the loaded ones for use in file byte-compilation."
227 (let ((macroexpand-all-environment environment)) 225 (let ((macroexpand-all-environment environment))
228 (macroexpand-all-1 form))) 226 (macroexp--expand-all form)))
229 227
230(provide 'macroexp) 228(provide 'macroexp)
231 229