Compile require
s in the body of a macro
This change enables further macro expansion for cases in which a macro `require`s other macros within its body.
This commit is contained in:
parent
5bfd4592f6
commit
33f2b4a91a
@ -43,7 +43,8 @@
|
|||||||
(defn macroexpand-all [form &optional module-name]
|
(defn macroexpand-all [form &optional module-name]
|
||||||
"Recursively performs all possible macroexpansions in form."
|
"Recursively performs all possible macroexpansions in form."
|
||||||
(setv module-name (or module-name (calling-module-name))
|
(setv module-name (or module-name (calling-module-name))
|
||||||
quote-level [0]) ; TODO: make nonlocal after dropping Python2
|
quote-level [0]
|
||||||
|
ast-compiler (HyASTCompiler module-name)) ; TODO: make nonlocal after dropping Python2
|
||||||
(defn traverse [form]
|
(defn traverse [form]
|
||||||
(walk expand identity form))
|
(walk expand identity form))
|
||||||
(defn expand [form]
|
(defn expand [form]
|
||||||
@ -64,7 +65,10 @@
|
|||||||
[True (traverse form)])]
|
[True (traverse form)])]
|
||||||
[(= (first form) 'quote) form]
|
[(= (first form) 'quote) form]
|
||||||
[(= (first form) 'quasiquote) (+quote)]
|
[(= (first form) 'quasiquote) (+quote)]
|
||||||
[True (traverse (mexpand form (HyASTCompiler module-name)))])
|
[(= (first form) (HySymbol "require"))
|
||||||
|
(ast-compiler.compile form)
|
||||||
|
(return)]
|
||||||
|
[True (traverse (mexpand form ast-compiler))])
|
||||||
(if (coll? form)
|
(if (coll? form)
|
||||||
(traverse form)
|
(traverse form)
|
||||||
form)))
|
form)))
|
||||||
@ -325,4 +329,3 @@ as can nested let forms.
|
|||||||
expander)))
|
expander)))
|
||||||
|
|
||||||
;; (defmacro macrolet [])
|
;; (defmacro macrolet [])
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user