Fix disassembly, add butlast, profile
This commit is contained in:
parent
d388ee2fd5
commit
46d77f69e6
@ -32,6 +32,10 @@
|
|||||||
(if (not (numeric? x))
|
(if (not (numeric? x))
|
||||||
(raise (TypeError (.format "{0!r} is not a number" x)))))
|
(raise (TypeError (.format "{0!r} is not a number" x)))))
|
||||||
|
|
||||||
|
(defn butlast [coll]
|
||||||
|
"Returns coll except of last element."
|
||||||
|
(slice coll 0 (dec (len coll))))
|
||||||
|
|
||||||
(defn coll? [coll]
|
(defn coll? [coll]
|
||||||
"Checks whether item is a collection"
|
"Checks whether item is a collection"
|
||||||
(and (iterable? coll) (not (string? coll))))
|
(and (iterable? coll) (not (string? coll))))
|
||||||
@ -60,17 +64,24 @@
|
|||||||
(- n 1))
|
(- n 1))
|
||||||
|
|
||||||
(defn disassemble [tree &optional [codegen false]]
|
(defn disassemble [tree &optional [codegen false]]
|
||||||
"Dump the python AST for a given Hy tree to standard output
|
"Return the python AST for a quoted Hy tree as a string.
|
||||||
If the second argument is true, generate python code instead."
|
If the second argument is true, generate python code instead."
|
||||||
(import astor)
|
(import astor)
|
||||||
(import hy.compiler)
|
(import hy.compiler)
|
||||||
|
|
||||||
(fake-source-positions tree)
|
(fake-source-positions tree)
|
||||||
(setv compiled (hy.compiler.hy_compile tree (calling-module-name)))
|
(setv compiled (hy.compiler.hy_compile tree (calling-module-name)))
|
||||||
(print ((if codegen
|
((if codegen
|
||||||
astor.codegen.to_source
|
astor.codegen.to_source
|
||||||
astor.dump)
|
astor.dump)
|
||||||
compiled)))
|
compiled))
|
||||||
|
|
||||||
|
(defn profile [tree]
|
||||||
|
"Profile a quoted Hy tree."
|
||||||
|
(import cProfile)
|
||||||
|
(import re)
|
||||||
|
|
||||||
|
(.run cProfile (disassemble tree true)))
|
||||||
|
|
||||||
(defn distinct [coll]
|
(defn distinct [coll]
|
||||||
"Return a generator from the original collection with duplicates
|
"Return a generator from the original collection with duplicates
|
||||||
@ -351,10 +362,11 @@
|
|||||||
(import functools)
|
(import functools)
|
||||||
(map (functools.partial (fn [f args] (apply f args)) func) (apply zip lists))))
|
(map (functools.partial (fn [f args] (apply f args)) func) (apply zip lists))))
|
||||||
|
|
||||||
(def *exports* '[calling-module-name coll? cons cons? cycle dec distinct
|
(def *exports* '[butlast calling-module-name coll? cons cons? cycle dec
|
||||||
disassemble drop drop-while empty? even? every? first filter
|
distinct disassemble profile drop drop-while empty?
|
||||||
flatten float? gensym identity inc instance? integer
|
even? every? first filter flatten float? gensym
|
||||||
integer? integer-char? iterable? iterate iterator?
|
identity inc instance? integer integer? integer-char?
|
||||||
list* macroexpand macroexpand-1 neg? nil? none? nth
|
iterable? iterate iterator? list* macroexpand
|
||||||
numeric? odd? pos? remove repeat repeatedly rest second
|
macroexpand-1 neg? nil? none? nth numeric? odd? pos?
|
||||||
some string string? take take-nth take-while zero? zipwith])
|
remove repeat repeatedly rest second some string
|
||||||
|
string? take take-nth take-while zero? zipwith])
|
||||||
|
Loading…
Reference in New Issue
Block a user