feat(debug): add debug func defn

This commit is contained in:
rcmerci
2022-01-07 14:32:37 +08:00
committed by Andelf
parent b4371ce8a4
commit 0ec9d01d61
2 changed files with 27 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
(ns frontend.debug
(:refer-clojure :rename {defn core-defn}))
(defmacro defn [name & fdecl]
(let [fdecl (if (string? (first fdecl))
(next fdecl)
fdecl)
fdecl (if (map? (first fdecl))
(next fdecl)
fdecl)
fdecl (if (vector? (first fdecl))
(list fdecl)
fdecl)
fdecl (if (map? (last fdecl))
(butlast fdecl)
fdecl)
fdecl (map (fn [decl]
(let [params (first decl)
body (next decl)]
`(~params
(let [start# (cljs.core/system-time)
ret# (do ~@body)
elapsed# (.toFixed (- (cljs.core/system-time) start#) 6)]
(println (str "[" '~name "] " elapsed# " msecs"))
ret#)))) fdecl)]
`(core-defn ~@(cons name fdecl))))