From 33f2b4a91a718a36c8d6118a39bae0c60f09f0bc Mon Sep 17 00:00:00 2001 From: "Brandon T. Willard" Date: Wed, 25 Jul 2018 17:11:32 -0500 Subject: [PATCH] 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. --- hy/contrib/walk.hy | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/hy/contrib/walk.hy b/hy/contrib/walk.hy index 6ee12b2..4d91721 100644 --- a/hy/contrib/walk.hy +++ b/hy/contrib/walk.hy @@ -43,7 +43,8 @@ (defn macroexpand-all [form &optional module-name] "Recursively performs all possible macroexpansions in form." (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] (walk expand identity form)) (defn expand [form] @@ -64,7 +65,10 @@ [True (traverse form)])] [(= (first form) 'quote) form] [(= (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) (traverse form) form))) @@ -325,4 +329,3 @@ as can nested let forms. expander))) ;; (defmacro macrolet []) -