-
Notifications
You must be signed in to change notification settings - Fork 2
/
core.clj
98 lines (84 loc) · 2.52 KB
/
core.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
(ns scape.core
(:require [datomic.api :refer [db q] :as d]
[scape.emitter :refer [emit-transaction-data]]
[scape.analyze :refer [analyze-file]]
[scape.schema :refer [schema]]
[clojure.pprint :refer [pprint]]))
(comment
(def uri "datomic:mem://ast")
(d/delete-database uri)
(d/create-database uri)
(def conn (d/connect uri))
(d/transact conn schema)
(doseq [ast (analyze-file "cljs/core.cljs")]
(let [tdata (emit-transaction-data ast)]
(d/transact conn tdata)))
;; how many transactions? i.e., top level forms
(count (analyze-file "cljs/core.cljs"))
;; 502
;; How many datoms is the above?
(->> (analyze-file "cljs/core.cljs")
(mapcat emit-transaction-data)
count)
;; 142955 facts about cljs.core!
;; How many ast nodes are there in core.cljs?
(count (q '[:find ?e
:where
[?e :ast/op]]
(db conn)))
;; On what lines is the test part of an if statement a constant, and
;; what is that constant?
(seq (q '[:find ?line ?form
:where
[?e :ast.if/test ?t]
[?t :ast/op :ast.op/constant]
[?t :ast/form ?form]
[?t :ast/line ?line]]
(db conn)))
;; What form is on line 291?
(q '[:find ?form
:where
[?op :ast/op]
[?op :ast/line 291]
[?op :ast/form ?form]]
(db conn))
;; Find documentation and line number
(q '[:find ?line ?doc
:in $ ?name
:where
[?def :ast/name ?name]
[?def :ast.def/doc ?doc]
[?def :ast/line ?line]]
(db conn) "cljs.core.filter")
;; On what lines is the function 'map' used?
(q '[:find ?line
:in $ ?sym
:where
[?var :ast/op :ast.op/var]
[?var :ast.var/local false]
[?var :ast/form ?sym]
[?var :ast/line ?line]]
(db conn) "map")
;; What are the most used local/var names?
(->> (q '[:find ?var ?sym
:in $ ?local
:where
[?var :ast.var/local ?local]
[?var :ast/form ?sym]]
(db conn) false)
(map second)
frequencies
(sort-by second)
reverse)
;; On what line is the return of a function method a constant and
;; what is the type of that constant?
(q '[:find ?line ?type
:where
;[?fn :ast/op :ast.op/fn]
[?_ :ast.fn/method ?fnm]
[?fnm :ast/ret ?ret]
[?ret :ast/op :ast.op/constant]
[?ret :ast.constant/type ?type]
[?ret :ast/line ?line]]
(db conn))
)