This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

switch to insertion sort; bump 0.1.10

  • Loading branch information...
jiyinyiyong committed Aug 26, 2016
1 parent 51c80da commit ba8765d88033974a993d6f7975f724eb967e260d
Showing with 25 additions and 15 deletions.
  1. +1 −1 README.md
  2. +1 −1 build.boot
  3. +4 −2 cirru/src/stack_server/analyze.clj.ir
  4. +19 −11 compiled/src/stack_server/analyze.clj
View
@@ -9,7 +9,7 @@ Server side toolchain for stack-editor.
[![Clojars Project](https://img.shields.io/clojars/v/cirru/stack-server.svg)](https://clojars.org/cirru/stack-server)
```clojure
[cirru/stack-server "0.1.9"]
[cirru/stack-server "0.1.10"]
```
```clojure
View
@@ -17,7 +17,7 @@
'[clojure.java.io :as io]
'[stack-server.core :refer [start-stack-editor! transform-stack]])
(def +version+ "0.1.9")
(def +version+ "0.1.10")
(task-options!
pom {:project 'cirru/stack-server
@@ -1,9 +1,11 @@
[
[ "ns" "stack-server.analyze" [ ":require" [ "[]" "clojure.string" ":as" "string" ] [ "[]" "cirru.sepal" ":as" "sepal" ] [ "[]" "clansi" ":refer" [ "[]" "style" ] ] ] ]
[ "defn" "depends-on?" [ "x" "y" "dict" "level" ] [ "if" [ "contains?" "dict" "x" ] [ "let" [ [ "deps" [ "get" "dict" "x" ] ] ] [ "if" [ "contains?" "deps" "y" ] "true" [ "if" [ ">" "level" "3" ] "false" [ "some" [ "fn" [ "child" ] [ "depends-on?" "child" "y" "dict" [ "inc" "level" ] ] ] "deps" ] ] ] ] "false" ] ]
[ "defn" "depends-on?" [ "x" "y" "dict" "level" ] [ "if" [ "contains?" "dict" "x" ] [ "let" [ [ "deps" [ "get" "dict" "x" ] ] ] [ "if" [ "contains?" "deps" "y" ] "true" [ "if" [ ">" "level" "4" ] "false" [ "some" [ "fn" [ "child" ] [ "depends-on?" "child" "y" "dict" [ "inc" "level" ] ] ] "deps" ] ] ] ] "false" ] ]
[ "defn" "ns->path" [ "namespace-name" ] [ "->" "namespace-name" [ "string/replace" [ "re-pattern" "|\\." ] "|/" ] [ "string/replace" [ "re-pattern" "|-" ] "|_" ] ] ]
[ "defn" "strip-atom" [ "token" ] [ "if" [ "string/starts-with?" "token" "|@" ] [ "subs" "token" "1" ] "token" ] ]
[ "defn" "generate-file" [ "ns-line" "definitions" "procedure-line" ] [ "let" [ [ "ns-name" [ "get" "ns-line" "1" ] ] [ "var-names" [ "->>" [ "keys" "definitions" ] [ "map" [ "fn" [ "var-name" ] [ "last" [ "string/split" "var-name" [ "re-pattern" "|/" ] ] ] ] ] [ "into" [ "hash-set" ] ] ] ] [ "deps-info" [ "->>" "definitions" [ "map" [ "fn" [ "entry" ] [ "let" [ [ "path" [ "key" "entry" ] ] [ "tree" [ "val" "entry" ] ] [ "var-name" [ "last" [ "string/split" "path" [ "re-pattern" "|/" ] ] ] ] [ "dep-tokens" [ "->>" [ "subvec" "tree" "2" ] [ "flatten" ] [ "distinct" ] [ "map" "strip-atom" ] [ "filter" [ "fn" [ "token" ] [ "and" [ "not=" "token" "var-name" ] [ "contains?" "var-names" "token" ] ] ] ] [ "into" [ "hash-set" ] ] ] ] ] [ "[]" "var-name" "dep-tokens" ] ] ] ] [ "into" [ "{}" ] ] ] ] [ "self-deps-names" [ "filter" [ "fn" [ "x" ] [ "depends-on?" "x" "x" "deps-info" "0" ] ] "var-names" ] ] [ "sorted-names" [ "sort" [ "fn" [ "x" "y" ] [ "cond" [ [ "depends-on?" "x" "y" "deps-info" "0" ] "1" ] [ [ "depends-on?" "y" "x" "deps-info" "0" ] "-1" ] [ ":else" [ "let" [ [ "xc" [ "count" [ "get" "deps-info" "x" ] ] ] [ "yc" [ "count" [ "get" "deps-info" "y" ] ] ] ] [ "compare" "xc" "yc" ] ] ] ] ] "var-names" ] ] [ "declarations" [ "->>" "self-deps-names" [ "map" [ "fn" [ "var-name" ] [ "[]" "|declare" "var-name" ] ] ] [ "into" [ "[]" ] ] ] ] [ "definition-lines" [ "map" [ "fn" [ "var-name" ] [ "get" "definitions" [ "str" "ns-name" "|/" "var-name" ] ] ] "sorted-names" ] ] [ "tree" [ "into" [ "[]" ] [ "concat" [ "[]" "ns-line" ] "declarations" "definition-lines" "procedure-line" ] ] ] [ "code" [ "sepal/make-code" "tree" ] ] ] [ "--" "println" "|generated file:" "code" ] "code" ] ]
[ "defn" "deps-insert" [ "acc" "new-item" "items" "deps-info" ] [ "if" [ "empty?" "items" ] [ "conj" "acc" "new-item" ] [ "let" [ [ "cursor" [ "first" "items" ] ] ] [ "if" [ "depends-on?" "cursor" "new-item" "deps-info" "0" ] [ "into" [ "[]" ] [ "concat" "acc" [ "[]" "new-item" ] "items" ] ] [ "recur" [ "conj" "acc" "cursor" ] "new-item" [ "rest" "items" ] "deps-info" ] ] ] ] ]
[ "defn" "deps-sort" [ "acc" "items" "deps-info" ] [ "if" [ "empty?" "items" ] "acc" [ "let" [ [ "cursor" [ "first" "items" ] ] [ "next-acc" [ "deps-insert" [ "[]" ] "cursor" "acc" "deps-info" ] ] ] [ "recur" "next-acc" [ "into" [ "[]" ] [ "rest" "items" ] ] "deps-info" ] ] ] ]
[ "defn" "generate-file" [ "ns-line" "definitions" "procedure-line" ] [ "let" [ [ "ns-name" [ "get" "ns-line" "1" ] ] [ "var-names" [ "->>" [ "keys" "definitions" ] [ "map" [ "fn" [ "var-name" ] [ "last" [ "string/split" "var-name" [ "re-pattern" "|/" ] ] ] ] ] [ "into" [ "hash-set" ] ] ] ] [ "deps-info" [ "->>" "definitions" [ "map" [ "fn" [ "entry" ] [ "let" [ [ "path" [ "key" "entry" ] ] [ "tree" [ "val" "entry" ] ] [ "var-name" [ "last" [ "string/split" "path" [ "re-pattern" "|/" ] ] ] ] [ "dep-tokens" [ "->>" [ "subvec" "tree" "2" ] [ "flatten" ] [ "distinct" ] [ "map" "strip-atom" ] [ "filter" [ "fn" [ "token" ] [ "and" [ "not=" "token" "var-name" ] [ "contains?" "var-names" "token" ] ] ] ] [ "into" [ "hash-set" ] ] ] ] ] [ "[]" "var-name" "dep-tokens" ] ] ] ] [ "into" [ "{}" ] ] ] ] [ "self-deps-names" [ "filter" [ "fn" [ "x" ] [ "depends-on?" "x" "x" "deps-info" "0" ] ] "var-names" ] ] [ "sorted-names" [ "deps-sort" [ "[]" ] [ "into" [ "[]" ] "var-names" ] "deps-info" ] ] [ "declarations" [ "->>" "self-deps-names" [ "map" [ "fn" [ "var-name" ] [ "[]" "|declare" "var-name" ] ] ] [ "into" [ "[]" ] ] ] ] [ "definition-lines" [ "map" [ "fn" [ "var-name" ] [ "get" "definitions" [ "str" "ns-name" "|/" "var-name" ] ] ] "sorted-names" ] ] [ "tree" [ "into" [ "[]" ] [ "concat" [ "[]" "ns-line" ] "declarations" "definition-lines" "procedure-line" ] ] ] [ "code" [ "sepal/make-code" "tree" ] ] ] [ "--" "println" "|before sort:" "var-names" ] [ "--" "println" "|after sort:" "sorted-names" ] [ "--" "println" "|generated file:" "code" ] "code" ] ]
[ "defn" "collect-files" [ "collection" ] [ "let" [ [ "namespace-names" [ "keys" [ ":namespaces" "collection" ] ] ] [ "namespace-names'" [ "distinct" [ "map" [ "fn" [ "definition-name" ] [ "first" [ "string/split" "definition-name" [ "re-pattern" "|/" ] ] ] ] [ "keys" [ ":definitions" "collection" ] ] ] ] ] ] [ "if" [ "=" [ "sort" "namespace-names" ] [ "sort" "namespace-names'" ] ] [ "doall" [ "->>" "namespace-names" [ "map" [ "fn" [ "ns-name" ] [ "[]" [ "ns->path" "ns-name" ] [ "generate-file" [ "get-in" "collection" [ "[]" ":namespaces" "ns-name" ] ] [ "->>" [ ":definitions" "collection" ] [ "filter" [ "fn" [ "entry" ] [ "string/starts-with?" [ "key" "entry" ] [ "str" "ns-name" "|/" ] ] ] ] [ "into" [ "{}" ] ] ] [ "or" [ "get-in" "collection" [ "[]" ":procedures" "ns-name" ] ] [ "[]" ] ] ] ] ] ] [ "into" [ "{}" ] ] ] ] [ "do" [ "println" [ "style" "|Error: namespaces not match!" ":red" ] ] [ "println" "| from definitions:" "namespace-names" ] [ "println" "| from namespaces: " "namespace-names'" ] [ "{}" ] ] ] ] ]
]
@@ -9,7 +9,7 @@
(let [deps (get dict x)]
(if (contains? deps y)
true
(if (> level 3)
(if (> level 4)
false
(some
(fn [child] (depends-on? child y dict (inc level)))
@@ -24,6 +24,21 @@
(defn strip-atom [token]
(if (string/starts-with? token "@") (subs token 1) token))
(defn deps-insert [acc new-item items deps-info]
(if (empty? items)
(conj acc new-item)
(let [cursor (first items)]
(if (depends-on? cursor new-item deps-info 0)
(into [] (concat acc [new-item] items))
(recur (conj acc cursor) new-item (rest items) deps-info)))))
(defn deps-sort [acc items deps-info]
(if (empty? items)
acc
(let [cursor (first items)
next-acc (deps-insert [] cursor acc deps-info)]
(recur next-acc (into [] (rest items)) deps-info))))
(defn generate-file [ns-line definitions procedure-line]
(let [ns-name (get ns-line 1)
var-names (->>
@@ -62,16 +77,7 @@
self-deps-names (filter
(fn [x] (depends-on? x x deps-info 0))
var-names)
sorted-names (sort
(fn [x y]
(cond
(depends-on? x y deps-info 0) 1
(depends-on? y x deps-info 0) -1
:else (let
[xc (count (get deps-info x))
yc (count (get deps-info y))]
(compare xc yc))))
var-names)
sorted-names (deps-sort [] (into [] var-names) deps-info)
declarations (->>
self-deps-names
(map (fn [var-name] ["declare" var-name]))
@@ -90,6 +96,8 @@
definition-lines
procedure-line))
code (sepal/make-code tree)]
(comment println "before sort:" var-names)
(comment println "after sort:" sorted-names)
(comment println "generated file:" code)
code))

0 comments on commit ba8765d

Please sign in to comment.