Skip to content

Commit

Permalink
Remove hy.disassemble
Browse files Browse the repository at this point in the history
It's not general enough (e.g., it doesn't allow choosing the set of macros to use) and it's of ambiguous value. `hy` and `hy2py` are probably enough for most cases. If in the future there's demand for programmatic user access to the compiler, maybe we'll add something then.
  • Loading branch information
Kodiologist committed Apr 28, 2024
1 parent 225017d commit 0ac9bd5
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 49 deletions.
1 change: 1 addition & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ Unreleased

Removals
------------------------------
* `hy.disassemble` has been removed.
* `(defn/a …)` is now `(defn :async …)`.
* `(fn/a …)` is now `(fn :async …)`.
* `(with/a […] …)` is now `(with [:async …] …)`.
Expand Down
2 changes: 0 additions & 2 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1392,8 +1392,6 @@ the following methods
.. hy:autofunction:: hy.unmangle
.. hy:autofunction:: hy.disassemble
.. hy:autofunction:: hy.macroexpand
.. hy:autofunction:: hy.macroexpand-1
Expand Down
31 changes: 0 additions & 31 deletions hy/core/util.hy
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,6 @@
(import collections.abc [Iterable])
(import hy.compiler [HyASTCompiler calling-module])

(defn disassemble [tree [codegen False]]
"Return the python AST for a quoted Hy `tree` as a string.
If the second argument `codegen` is true, generate python code instead.
Dump the Python AST for given Hy *tree* to standard output. If *codegen*
is ``True``, the function prints Python code instead.
Examples:
::
=> (hy.disassemble '(print \"Hello World!\"))
Module(
body=[
Expr(value=Call(func=Name(id='print'), args=[Str(s='Hello World!')], keywords=[], starargs=None, kwargs=None))])
::
=> (hy.disassemble '(print \"Hello World!\") True)
print('Hello World!')
"
(import ast hy.compiler)

(setv compiled (hy.compiler.hy-compile tree (_calling-module-name) :import-stdlib False))
(if
codegen
(ast.unparse compiled)
(if hy._compat.PY3_9
(ast.dump compiled :indent 1)
(ast.dump compiled))))

(import threading [Lock])
(setv _gensym_counter 0)
(setv _gensym_lock (Lock))
Expand Down
17 changes: 1 addition & 16 deletions tests/native_tests/hy_misc.hy
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
;; Tests of `hy.gensym`, `hy.macroexpand`, `hy.macroexpand-1`,
;; `hy.disassemble`, `hy.read`, `hy.I`, and `hy.R`
;; `hy.read`, `hy.I`, and `hy.R`

(import
pytest)
Expand Down Expand Up @@ -67,21 +67,6 @@
'(mac 5 (a b)))))


(defn test-disassemble []
(import re)
(defn nos [x] (re.sub r"\s" "" x))
(assert (= (nos (hy.disassemble '(do (leaky) (leaky) (macros))))
(nos
"Module(
body=[Expr(value=Call(func=Name(id='leaky', ctx=Load()), args=[], keywords=[])),
Expr(value=Call(func=Name(id='leaky', ctx=Load()), args=[], keywords=[])),
Expr(value=Call(func=Name(id='macros', ctx=Load()), args=[], keywords=[]))],type_ignores=[])")))
(assert (= (nos (hy.disassemble '(do (leaky) (leaky) (macros)) True))
"leaky()leaky()macros()"))
(assert (= (re.sub r"[()\n ]" "" (hy.disassemble `(+ ~(+ 1 1) 40) True))
"2+40")))


(defn test-read-file-object []
(import io [StringIO])

Expand Down

0 comments on commit 0ac9bd5

Please sign in to comment.