diff --git a/src/clj/com/rpl/specter/impl.cljx b/src/clj/com/rpl/specter/impl.cljx index 714fcb8..f4fcde3 100644 --- a/src/clj/com/rpl/specter/impl.cljx +++ b/src/clj/com/rpl/specter/impl.cljx @@ -91,16 +91,6 @@ (defn intern* [ns name val] (throw-illegal "intern not supported in ClojureScript")) -;; so that macros.clj compiles appropriately when -;; run in cljs (this code isn't called in that case) -#+cljs -(defn gen-uuid-str [] - (throw-illegal "Cannot get UUID in Javascript")) - -#+clj -(defn gen-uuid-str [] - (str (java.util.UUID/randomUUID))) - (defn benchmark [iters afn] (time (dotimes [_ iters] @@ -123,7 +113,7 @@ #+cljs (defn exec-rich-select* [this params params-idx vals structure next-fn] - (rich-select* this params params-idx vals structure next-fn)) + (rich-select* ^not-native this params params-idx vals structure next-fn)) #+clj (defmacro exec-rich-transform* [this & args] @@ -133,7 +123,7 @@ #+cljs (defn exec-rich-transform* [this params params-idx vals structure next-fn] - (rich-select* this params params-idx vals structure next-fn)) + (rich-transform* ^not-native this params params-idx vals structure next-fn)) #+clj (defmacro exec-select* [this & args] @@ -143,7 +133,7 @@ #+cljs (defn exec-select* [this structure next-fn] - (p/select* this structure next-fn)) + (p/select* ^not-native this structure next-fn)) #+clj (defmacro exec-transform* [this & args] @@ -153,7 +143,7 @@ #+cljs (defn exec-transform* [this structure next-fn] - (p/transform* this structure next-fn)) + (p/transform* ^not-native this structure next-fn)) (def RichPathExecutor (->ExecutorFunctions diff --git a/src/clj/com/rpl/specter/macros.clj b/src/clj/com/rpl/specter/macros.clj index 5e6c323..e5db363 100644 --- a/src/clj/com/rpl/specter/macros.clj +++ b/src/clj/com/rpl/specter/macros.clj @@ -303,49 +303,40 @@ ([name] `(declarepath ~name [])) ([name params] - (let [num-params (count params) + (let [platform (if (contains? &env :locals) :cljs :clj) + select-exec (if (= platform :clj) + `i/exec-rich-select* + `i/rich-select*) + transform-exec (if (= platform :clj) + `i/exec-rich-transform* + `i/rich-transform*) + num-params (count params) declared (declared-name name) rargs [(gensym "params") (gensym "pidx") (gensym "vals") (gensym "structure") (gensym "next-fn")]] `(do (declare ~declared) (def ~name - (if (= ~num-params 0) - (i/no-params-rich-compiled-path - (reify RichNavigator - (~'rich-select* [this# ~@rargs] - (let [inav# (i/compiled-path-rich-nav ~declared)] - (i/exec-rich-select* inav# ~@rargs) - )) - (~'rich-transform* [this# ~@rargs] - (let [inav# (i/compiled-path-rich-nav ~declared)] - (i/exec-rich-transform* inav# ~@rargs) - )))) - (i/->ParamsNeededPath - (reify RichNavigator - (~'rich-select* [this# ~@rargs] - (let [inav# (i/params-needed-nav ~declared)] - (i/exec-rich-select* inav# ~@rargs) - )) - (~'rich-transform* [this# ~@rargs] - (let [inav# (i/params-needed-nav ~declared)] - (i/exec-rich-transform* inav# ~@rargs) - ))) - ~num-params - ) - )))))) + (let [nav# (reify RichNavigator + (~'rich-select* [this# ~@rargs] + (~select-exec ~declared ~@rargs)) + (~'rich-transform* [this# ~@rargs] + (~transform-exec ~declared ~@rargs) + ))] + (if (= ~num-params 0) + (i/no-params-rich-compiled-path nav#) + (i/->ParamsNeededPath nav# ~num-params) + ))))))) -;;TODO: continue refactoring from here ******* -;;TODO: need to convert to use first-class navigators (defmacro providepath [name apath] - `(let [comped# (i/comp-paths* ~apath) + `(let [comped# (i/comp-paths-internalized ~apath) expected-params# (i/num-needed-params ~name) needed-params# (i/num-needed-params comped#)] (if-not (= needed-params# expected-params#) (i/throw-illegal "Invalid number of params in provided path, expected " expected-params# " but got " needed-params#)) (def ~(declared-name name) - (i/coerce-compiled->rich-nav comped#) + (i/extract-rich-nav (i/coerce-compiled->rich-nav comped#)) ))) (defmacro extend-protocolpath