wip
This commit is contained in:
parent
cb11936026
commit
dc8741e8a8
2 changed files with 10 additions and 8 deletions
|
|
@ -1806,7 +1806,9 @@
|
||||||
(describe* [_] `(clojure.spec.alpha/fspec :args ~aform :ret ~rform :fn ~fform)))))
|
(describe* [_] `(clojure.spec.alpha/fspec :args ~aform :ret ~rform :fn ~fform)))))
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; non-primitives ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; non-primitives ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
(clojure.spec.alpha/def :clojure.spec.alpha/kvs->map (conformer #(zipmap (map :clojure.spec.alpha/k %) (map :clojure.spec.alpha/v %)) #(map (fn [[k v]] {:clojure.spec.alpha/k k :clojure.spec.alpha/v v}) %)))
|
(babashka.impl.clojure.spec.alpha/def
|
||||||
|
:clojure.spec.alpha/kvs->map
|
||||||
|
(conformer #(zipmap (map :clojure.spec.alpha/k %) (map :clojure.spec.alpha/v %)) #(map (fn [[k v]] {:clojure.spec.alpha/k k :clojure.spec.alpha/v v}) %)))
|
||||||
|
|
||||||
(defmacro keys*
|
(defmacro keys*
|
||||||
"takes the same arguments as spec/keys and returns a regex op that matches sequences of key/values,
|
"takes the same arguments as spec/keys and returns a regex op that matches sequences of key/values,
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@
|
||||||
[babashka.impl.clojure.spec.alpha :as s]
|
[babashka.impl.clojure.spec.alpha :as s]
|
||||||
[babashka.impl.clojure.spec.gen.alpha :as gen]
|
[babashka.impl.clojure.spec.gen.alpha :as gen]
|
||||||
[babashka.impl.pprint :as pp]
|
[babashka.impl.pprint :as pp]
|
||||||
|
[babashka.impl.common :refer [ctx]]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[sci.core :as sci]))
|
[sci.core :as sci]))
|
||||||
|
|
||||||
|
|
@ -141,9 +142,9 @@
|
||||||
(fn
|
(fn
|
||||||
[& args]
|
[& args]
|
||||||
(if @instrument-enabled-var
|
(if @instrument-enabled-var
|
||||||
(sci/binding [@instrument-enabled-var false]
|
(sci/binding [instrument-enabled-var false]
|
||||||
(when (:args fn-spec) (conform! v :args (:args fn-spec) args args))
|
(when (:args fn-spec) (conform! v :args (:args fn-spec) args args))
|
||||||
(sci/binding [@instrument-enabled-var true]
|
(sci/binding [instrument-enabled-var true]
|
||||||
(.applyTo ^clojure.lang.IFn f args)))
|
(.applyTo ^clojure.lang.IFn f args)))
|
||||||
(.applyTo ^clojure.lang.IFn f args)))))
|
(.applyTo ^clojure.lang.IFn f args)))))
|
||||||
|
|
||||||
|
|
@ -169,7 +170,7 @@
|
||||||
(defn- instrument-1
|
(defn- instrument-1
|
||||||
[s opts]
|
[s opts]
|
||||||
;; TODO: sci resolve
|
;; TODO: sci resolve
|
||||||
(when-let [v nil #_(resolve s)]
|
(when-let [v (sci/resolve @ctx s)]
|
||||||
(when-not (-> v meta :macro)
|
(when-not (-> v meta :macro)
|
||||||
(let [spec (s/get-spec v)
|
(let [spec (s/get-spec v)
|
||||||
{:keys [raw wrapped]} (get @instrumented-vars v)
|
{:keys [raw wrapped]} (get @instrumented-vars v)
|
||||||
|
|
@ -179,20 +180,19 @@
|
||||||
(throw (no-fspec v spec)))
|
(throw (no-fspec v spec)))
|
||||||
ofn (instrument-choose-fn to-wrap ospec s opts)
|
ofn (instrument-choose-fn to-wrap ospec s opts)
|
||||||
checked (spec-checking-fn v ofn ospec)]
|
checked (spec-checking-fn v ofn ospec)]
|
||||||
;; TODO: use sci alter-var-root
|
(sci/alter-var-root v (constantly checked))
|
||||||
(alter-var-root v (constantly checked))
|
|
||||||
(swap! instrumented-vars assoc v {:raw to-wrap :wrapped checked})
|
(swap! instrumented-vars assoc v {:raw to-wrap :wrapped checked})
|
||||||
(->sym v)))))
|
(->sym v)))))
|
||||||
|
|
||||||
(defn- unstrument-1
|
(defn- unstrument-1
|
||||||
[s]
|
[s]
|
||||||
(when-let [v nil #_(resolve s)]
|
(when-let [v (sci/resolve @ctx s)]
|
||||||
(when-let [{:keys [raw wrapped]} (get @instrumented-vars v)]
|
(when-let [{:keys [raw wrapped]} (get @instrumented-vars v)]
|
||||||
(swap! instrumented-vars dissoc v)
|
(swap! instrumented-vars dissoc v)
|
||||||
(let [current @v]
|
(let [current @v]
|
||||||
(when (= wrapped current)
|
(when (= wrapped current)
|
||||||
;; TODO: use sci-alter-var-root
|
;; TODO: use sci-alter-var-root
|
||||||
(alter-var-root v (constantly raw))
|
(sci/alter-var-root v (constantly raw))
|
||||||
(->sym v))))))
|
(->sym v))))))
|
||||||
|
|
||||||
#_(defn- opt-syms
|
#_(defn- opt-syms
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue