 (defn direct-nav? [o]
   (-> o meta :direct-nav))
 
-
-;; don't do coerce-nav here... save that for resolve-magic-code
+(defn all-static? [params]
+  (every? (complement dynamic-param?) params))
+
 (defn- magic-precompilation* [o]
   (cond (sequential? o)
         (flatten (map magic-precompilation* o))

            `(coerce-nav ~code)))

    (instance? DynamicFunction o)
    (let [op (resolve-dynamic-fn-arg (:op o))
          params (map resolve-dynamic-fn-arg (:params o))]
      (if (all-static? (conj params op))
        (coerce-nav (apply op params))
        (let [code `(~(-> op resolve-dynamic-fn-arg-code original-obj)
                      ~@(map resolve-dynamic-fn-arg-code params))]
          (if (direct-nav? op) code `(coerce-nav ~code)))))

    :else
    (coerce-nav o)))


(def ^:dynamic *DEBUG-INLINE-CACHING* false)


;; TODO: could have a global flag about whether or not to compile and cache static
;; portions, or whether to compile everything together on each invocation (so that
;; it can be redefined in repl
(defn magic-precompilation [path ns-str used-locals-list]
  (let [used-locals-set (set used-locals-list)
        magic-path (-> path magic-precompilation* static-combine)]
    (when *DEBUG-INLINE-CACHING*
      (println "Inline caching debug information")
      (println "--------------------------------")
      (println "Input path:" path "\n")
      (println "Processed path:" magic-path "\n"))
    (if (rich-nav? magic-path)
      (do
        (when *DEBUG-INLINE-CACHING*
          (println "Static result:" magic-path))
        (->CachedPathInfo false magic-path))
      (let [code `(fn [~@used-locals-list]
                    ~(resolve-nav-code (->DynamicPath magic-path)))
            ns (find-ns (symbol ns-str))
            maker (binding [*ns* ns] (eval+ code))]

        (when *DEBUG-INLINE-CACHING*
          (println "Produced code:" code))
        (->CachedPathInfo true maker)))))


; ;; one of the "possible params"
; (defrecord LocalParam [idx])
;
; ;; statically precomputed
; (defrecord StaticParam [val])
;
; ;; what if instead of doing dynamic binding for the params, it generates code
; ;; to construct the path
; ;; TODO: how to parameterize the static/local params?... that could be dynamic binding
; ;; or this makes a function that takes in static + local params, and it executes all arguments with those...
; ;; (fn-3 comp-navs (static-param 2) (static-param 3) (local-param 0))
;
; ;; TODO: redo code to:
; ;;   - do magic-precompilation* for initial resolve
; ;;   - compile static parameters together as much as possible
;
; (defn magic-precompilation-cljs [path ns-str used-locals-list possible-params])



(defn compiled-setval* [path val structure]
