Skip to content

Commit

Permalink
Change macroexpand-all to use parameters like hy.macroexpand
Browse files Browse the repository at this point in the history
  • Loading branch information
Kodiologist committed Dec 13, 2024
1 parent 8843afc commit ad7d445
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
1 change: 1 addition & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Breaking Changes
------------------------------
* `recur` is now a real object that must be imported from Hyrule when
using `loop`.
* `macroexpand-all` now uses the same parameters as `hy.macroexpand`.

New Features
------------------------------
Expand Down
11 changes: 4 additions & 7 deletions hyrule/macrotools.hy
Original file line number Diff line number Diff line change
Expand Up @@ -199,12 +199,12 @@
(setv ~~gs ~~os)
~~res)))

(defn macroexpand-all [form [ast-compiler None]]
(defn macroexpand-all [model [module None] [macros None]]
"Recursively performs all possible macroexpansions in form, using the ``require`` context of ``module-name``.
`macroexpand-all` assumes the calling module's context if unspecified.
"
(setv quote-level 0
ast-compiler (or ast-compiler (HyASTCompiler (calling-module))))
module (or module (hy.compiler.calling-module)))
(defn traverse [form]
(walk expand (fn [x] x) form))
(defn expand [form]
Expand All @@ -227,16 +227,13 @@
True (traverse form))
(= (get form 0) 'quote) form
(= (get form 0) 'quasiquote) (+quote)
(= (get form 0) (hy.models.Symbol "require")) (do
(ast-compiler.compile form)
(return))
(in (get form 0) '[except unpack-mapping])
(hy.models.Expression [(get form 0) #* (traverse (cut form 1 None))])
True (traverse (hy.macros.macroexpand form ast-compiler.module ast-compiler :result-ok False)))
True (traverse (hy.macroexpand form module macros)))
(if (coll? form)
(traverse form)
form)))
(expand form))
(expand model))


(defn map-model [x f]
Expand Down

0 comments on commit ad7d445

Please sign in to comment.