Skip to content

Commit

Permalink
roughly fixed find dependents
Browse files Browse the repository at this point in the history
  • Loading branch information
tiye committed Jun 17, 2017
1 parent 09bee18 commit fa22f64
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 84 deletions.
89 changes: 40 additions & 49 deletions ir.edn
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@
"helper-create-def"
"helper-put-path"
"make-path"
"drop-pkg"
"has-ns?"]]]],
"has-ns?"
"helper-put-list"]]]],
:defs {"collapse" ["defn"
"collapse"
["store" "op-data" "op-id"]
Expand Down Expand Up @@ -223,8 +223,7 @@
["println" "|Dependents:" "op-data"]
["let"
[["writer" [":writer" "store"]]
["stack" [":stack" "writer"]]
["pointer" [":pointer" "writer"]]
[["{}" ["stack" ":stack"] ["pointer" ":pointer"]] "writer"]
["code-path" ["get" "stack" "pointer"]]
[["{}" ["ns-part" ":ns"] ["kind" ":kind"] ["extra-name" ":extra"]]
"code-path"]
Expand Down Expand Up @@ -301,42 +300,14 @@
["filter" ["fn" ["xs"] ["not" ["empty?" "xs"]]]]
["apply" "concat"]]]]
["println" "|Got new paths:" "new-paths"]
["update"
"store"
":writer"
["fn"
["writer"]
["->"
"writer"
["assoc"
":stack"
["into" ["[]"] ["concat" "former-stack" "new-paths"]]]
["assoc"
":pointer"
["if" ["empty?" "new-paths"] "pointer" ["inc" "pointer"]]]]]]]]
["update" "store" ":writer" ["helper-put-list" "new-paths"]]]]
[":ns"
["let"
[["ns-list"
["list-dependent-ns"
"ns-part"
[":files" "sepal-ir"]
[":package" "sepal-ir"]]]
["list-dependent-ns" "ns-part" [":files" "sepal-ir"] "pkg"]]
["new-paths" ["map" ["fn" ["x"] ["[]" "x" ":ns"]] "ns-list"]]]
["--" "println" "former-stack" "new-paths" "pointer"]
["update"
"store"
":writer"
["fn"
["writer"]
["->"
"writer"
["assoc"
":stack"
["into" ["[]"] ["concat" "former-stack" "new-paths"]]]
["assoc"
":pointer"
["if" ["empty?" "ns-list"] "pointer" ["inc" "pointer"]]]
["assoc" ":focus" ["[]"]]]]]]]
["--" "println" "former-stack" "pointer" "new-paths"]
["update" "store" ":writer" ["helper-put-list" "new-paths"]]]]
"store"]]],
"point-to" ["defn"
"point-to"
Expand Down Expand Up @@ -481,7 +452,7 @@
"app.util.analyze"
[":require"
["[]" "clojure.string" ":as" "string"]
["[]" "app.util.detect" ":refer" ["[]" "contains-def?"]]]],
["[]" "app.util.detect" ":refer" ["[]" "contains-def?" "use-vector?"]]]],
:defs {"pick-rule" ["defn"
"pick-rule"
["ns-block" "ns-name" "pkg"]
Expand All @@ -494,11 +465,13 @@
["empty?" "left-rules"]
"nil"
["let"
[["cursor" ["first" "left-rules"]]]
[["cursor" ["first" "left-rules"]]
["import-rule"
["if" ["use-vector?" "cursor"] ["subvec" "cursor" "1"] "cursor"]]]
["--" "println" "|Picking" "cursor" "full-ns"]
["if"
["=" "full-ns" ["get" "cursor" "1"]]
"cursor"
["=" "full-ns" ["first" "import-rule"]]
["if" ["use-vector?" "cursor"] ["subvec" "cursor" "1"] "cursor"]
["recur" ["rest" "left-rules"]]]]]]]],
"pick-def-deps" ["defn"
"pick-def-deps"
Expand Down Expand Up @@ -647,19 +620,25 @@
"list-dependent-ns"
["ns-name" "files" "pkg"]
["let"
[["full-ns" ["str" "pkg" "|." "ns-name"]]]
[["full-ns" ["str" "pkg" "|." "ns-name"]]
["pick-ns"
["fn"
["xs"]
["if" ["use-vector?" "xs"] ["get" "xs" "1"] ["first" "xs"]]]]]
["->>"
"files"
["filter"
["fn"
["entry"]
["let"
[[["[]" "ns-part" "file"] "entry"]
["ns-expr" [":ns" "file"]]
["ns-rules"
["->>"
["get-in" "file" ["[]" ":ns" "2"]]
"rest"
["map" ["fn" ["xs"] ["get" "xs" "1"]]]
["subvec" "ns-expr" "2"]
["map" "rest"]
["apply" "concat"]
["map" "pick-ns"]
["into" ["#{}"]]]]]
["--" "println" "|Search:" "ns-name" "ns-rules"]
["contains?" "ns-rules" "full-ns"]]]]
Expand Down Expand Up @@ -763,10 +742,21 @@
["conj"
["into" ["[]"] ["subvec" "stack" "0" "next-pointer"]]
"code-path"]]]]]]]]]]],
"drop-pkg" ["defn"
"drop-pkg"
["x" "pkg"]
["if" ["string?" "x"] ["string/replace" "x" ["str" "pkg" "|."] "|"] "x"]],
"helper-put-list" ["defn"
"helper-put-list"
["new-paths"]
["fn"
["writer"]
["let"
[["stack" [":stack" "writer"]] ["pointer" [":pointer" "writer"]]]
["if"
["empty?" "new-paths"]
"writer"
["->"
"writer"
["assoc" ":stack" ["into" ["[]"] ["concat" "stack" "new-paths"]]]
["assoc" ":pointer" ["count" "stack"]]
["assoc" ":focus" ["[]" "1"]]]]]]],
"has-ns?" ["defn" "has-ns?" ["x"] ["string/includes?" "x" "|/"]],
"helper-notify" ["defn"
"helper-notify"
Expand Down Expand Up @@ -1234,7 +1224,7 @@
["comp-file-tree" [":file-tree" "states"] "store"]]]
["comp-text" "router" "nil"]]
["comp-notifications" [":notifications" "store"]]
["comp-debug" [":writer" "store"] ["{}" [":bottom" "0"]]]
["--" "comp-debug" [":writer" "store"] ["{}" [":bottom" "0"]]]
["if"
[":show-palette?" "router"]
["with-cursor"
Expand Down Expand Up @@ -2238,6 +2228,7 @@
["compare"
["str" [":ns" "x"] "|/" [":def" "x"]]
["str" [":ns" "y"] "|/" [":def" "y"]]]]]],
"use-vector?" ["defn" "use-vector?" ["xs"] ["=" "|[]" ["first" "xs"]]],
"=def?" ["defn"
"=def?"
["x" "y"]
Expand Down
2 changes: 1 addition & 1 deletion src/app/comp/container.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
:file-tree (with-cursor :file-tree (comp-file-tree (:file-tree states) store))
(comp-text router nil))
(comp-notifications (:notifications store))
(comp-debug (:writer store) {:bottom 0})
(comment comp-debug (:writer store) {:bottom 0})
(if (:show-palette? router)
(with-cursor :palette (comp-palette (:palette states) (:files (:collection store)))))
(comp-modal-stack states (:modal-stack store)))))
28 changes: 7 additions & 21 deletions src/app/updater/stack.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
helper-create-def
helper-put-path
make-path
drop-pkg
has-ns?]]))
has-ns?
helper-put-list]]))

(defn collapse [store op-data op-id]
(let [cursor op-data]
Expand All @@ -33,8 +33,7 @@
(defn dependents [store op-data op-id]
(println "Dependents:" op-data)
(let [writer (:writer store)
stack (:stack writer)
pointer (:pointer writer)
{stack :stack, pointer :pointer} writer
code-path (get stack pointer)
{ns-part :ns, kind :kind, extra-name :extra} code-path
sepal-ir (:collection store)
Expand Down Expand Up @@ -96,25 +95,12 @@
(filter (fn [xs] (not (empty? xs))))
(apply concat))]
(println "Got new paths:" new-paths)
(update
store
:writer
(fn [writer]
(-> writer
(assoc :stack (into [] (concat former-stack new-paths)))
(assoc :pointer (if (empty? new-paths) pointer (inc pointer)))))))
(update store :writer (helper-put-list new-paths)))
:ns
(let [ns-list (list-dependent-ns ns-part (:files sepal-ir) (:package sepal-ir))
(let [ns-list (list-dependent-ns ns-part (:files sepal-ir) pkg)
new-paths (map (fn [x] [x :ns]) ns-list)]
(comment println former-stack new-paths pointer)
(update
store
:writer
(fn [writer]
(-> writer
(assoc :stack (into [] (concat former-stack new-paths)))
(assoc :pointer (if (empty? ns-list) pointer (inc pointer)))
(assoc :focus [])))))
(comment println former-stack pointer new-paths)
(update store :writer (helper-put-list new-paths)))
store)))

(defn point-to [store op-data op-id]
Expand Down
10 changes: 9 additions & 1 deletion src/app/util.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@
stack
(conj (into [] (subvec stack 0 next-pointer)) code-path)))))))))))

(defn drop-pkg [x pkg] (if (string? x) (string/replace x (str pkg ".") "") x))
(defn helper-put-list [new-paths]
(fn [writer]
(let [stack (:stack writer), pointer (:pointer writer)]
(if (empty? new-paths)
writer
(-> writer
(assoc :stack (into [] (concat stack new-paths)))
(assoc :pointer (count stack))
(assoc :focus [1]))))))

(defn has-ns? [x] (string/includes? x "/"))

Expand Down
20 changes: 13 additions & 7 deletions src/app/util/analyze.cljs
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@

(ns app.util.analyze
(:require [clojure.string :as string] [app.util.detect :refer [contains-def?]]))
(:require [clojure.string :as string] [app.util.detect :refer [contains-def? use-vector?]]))

(defn pick-rule [ns-block ns-name pkg]
(let [full-ns (str pkg "." ns-name), rules (subvec (get ns-block 2) 1)]
(loop [left-rules rules]
(if (empty? left-rules)
nil
(let [cursor (first left-rules)]
(let [cursor (first left-rules)
import-rule (if (use-vector? cursor) (subvec cursor 1) cursor)]
(comment println "Picking" cursor full-ns)
(if (= full-ns (get cursor 1)) cursor (recur (rest left-rules))))))))
(if (= full-ns (first import-rule))
(if (use-vector? cursor) (subvec cursor 1) cursor)
(recur (rest left-rules))))))))

(defn parse-rule [dict rule]
(let [clean-rule (if (= "[]" (first rule)) (subvec rule 1) rule)
Expand Down Expand Up @@ -117,14 +120,17 @@
(into #{}))))))

(defn list-dependent-ns [ns-name files pkg]
(let [full-ns (str pkg "." ns-name)]
(let [full-ns (str pkg "." ns-name)
pick-ns (fn [xs] (if (use-vector? xs) (get xs 1) (first xs)))]
(->> files
(filter
(fn [entry]
(let [[ns-part file] entry
ns-rules (->> (get-in file [:ns 2])
rest
(map (fn [xs] (get xs 1)))
ns-expr (:ns file)
ns-rules (->> (subvec ns-expr 2)
(map rest)
(apply concat)
(map pick-ns)
(into #{}))]
(comment println "Search:" ns-name ns-rules)
(contains? ns-rules full-ns))))
Expand Down
2 changes: 2 additions & 0 deletions src/app/util/detect.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
(and (:external? y) (not (:external? x))) -1
:else (compare (str (:ns x) "/" (:def x)) (str (:ns y) "/" (:def y)))))

(defn use-vector? [xs] (= "[]" (first xs)))

(defn =def? [x y] (and (= (:ns x) (:ns y)) (= (:def x) (:def y))))

(defn strip-atom [token]
Expand Down
5 changes: 0 additions & 5 deletions webpack.dev.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ module.exports =
contentBase: resolve(__dirname, 'target')
publicPath: '/'
host: '0.0.0.0'
# devtool: 'source-map',
output:
filename: '[name].js'
module:
Expand All @@ -25,10 +24,6 @@ module.exports =
query:
limit: 100
name: 'fonts/[name].[ext]'
,
# test: /\.js$/
# loader: 'source-map-loader'
# options: { enforce: 'pre' }
]
plugins: [
new webpack.HotModuleReplacementPlugin(),
Expand Down

0 comments on commit fa22f64

Please sign in to comment.