Skip to content
This repository
Browse code

Removed bundled analyze

  • Loading branch information...
commit 9b5b424edcabe22bfa19326febb4a4d3ea02fc82 1 parent 84ae56c
Jonas Enlund authored

Showing 2 changed files with 0 additions and 679 deletions. Show diff stats Hide diff stats

  1. +0 646 src/analyze/core.clj
  2. +0 33 src/analyze/util.clj
646 src/analyze/core.clj
... ... @@ -1,646 +0,0 @@
1   -(set! *warn-on-reflection* false)
2   -
3   -(ns analyze.core
4   - "Interface to Compiler's analyze.
5   - Entry point `analyze-path` and `analyze-one`"
6   - (:import (java.io LineNumberReader InputStreamReader PushbackReader)
7   - (clojure.lang RT Compiler$DefExpr Compiler$LocalBinding Compiler$BindingInit Compiler$LetExpr
8   - Compiler$LetFnExpr Compiler$StaticMethodExpr Compiler$InstanceMethodExpr Compiler$StaticFieldExpr
9   - Compiler$NewExpr Compiler$LiteralExpr Compiler$EmptyExpr Compiler$VectorExpr Compiler$MonitorEnterExpr
10   - Compiler$MonitorExitExpr Compiler$ThrowExpr Compiler$InvokeExpr Compiler$TheVarExpr Compiler$VarExpr
11   - Compiler$UnresolvedVarExpr Compiler$ObjExpr Compiler$NewInstanceMethod Compiler$FnMethod Compiler$FnExpr
12   - Compiler$NewInstanceExpr Compiler$MetaExpr Compiler$BodyExpr Compiler$ImportExpr Compiler$AssignExpr
13   - Compiler$TryExpr$CatchClause Compiler$TryExpr Compiler$C Compiler$LocalBindingExpr Compiler$RecurExpr
14   - Compiler$MapExpr Compiler$IfExpr Compiler$KeywordInvokeExpr Compiler$InstanceFieldExpr Compiler$InstanceOfExpr
15   - Compiler$CaseExpr Compiler$Expr Compiler$SetExpr Compiler$MethodParamExpr))
16   - (:require [clojure.reflect :as reflect]
17   - [clojure.java.io :as io]
18   - [clojure.repl :as repl]
19   - [clojure.string :as string]))
20   -
21   -(defn- field-accessor [class-obj field obj]
22   - (let [field (.getDeclaredField class-obj (name field))]
23   - (.setAccessible field true)
24   - (let [ret (.get field obj)]
25   - (if (instance? Boolean ret)
26   - (boolean ret)
27   - ret))))
28   -
29   -(defn- method-accessor [class-obj method obj types & args]
30   - (let [method (.getDeclaredMethod class-obj (name method) (into-array Class types))]
31   - (.setAccessible method true)
32   - (.invoke method obj (object-array args))))
33   -
34   -(defmulti analysis->map
35   - "Recursively converts the output of the Compiler's analysis to a map"
36   - (fn [aobj env]
37   - (class aobj)))
38   -
39   -;; def
40   -
41   -(defmethod analysis->map Compiler$DefExpr
42   - [^Compiler$DefExpr expr env]
43   - (let [field (partial field-accessor Compiler$DefExpr)
44   - init (analysis->map (field 'init expr) env)
45   - meta (when-let [meta (field 'meta expr)]
46   - (analysis->map meta env))]
47   - {:op :def
48   - :env (assoc env
49   - :source (field 'source expr)
50   - :line (field 'line expr))
51   - :var (field 'var expr)
52   - :meta meta
53   - :init init
54   - :children [meta init]
55   - :init-provided (field 'initProvided expr)
56   - :is-dynamic (field 'isDynamic expr)
57   - :Expr-obj expr}))
58   -
59   -;; let
60   -
61   -(defmethod analysis->map Compiler$LocalBinding
62   - [^Compiler$LocalBinding lb env]
63   - (let [init (when-let [init (.init lb)]
64   - (analysis->map init env))]
65   - {:op :local-binding
66   - :env env
67   - :sym (.sym lb)
68   - :tag (.tag lb)
69   - :init init
70   - :children (when init [init])
71   - :LocalBinding-obj lb}))
72   -
73   -(defmethod analysis->map Compiler$BindingInit
74   - [^Compiler$BindingInit bi env]
75   - (let [local-binding (analysis->map (.binding bi) env)
76   - init (analysis->map (.init bi) env)]
77   - {:op :binding-init
78   - :local-binding local-binding
79   - :init init
80   - :children [local-binding init]
81   - :BindingInit-obj bi}))
82   -
83   -(defmethod analysis->map Compiler$LetExpr
84   - [^Compiler$LetExpr expr env]
85   - (let [body (analysis->map (.body expr) env)
86   - binding-inits (-> (doall (map analysis->map (.bindingInits expr) (repeat env)))
87   - vec)]
88   - {:op :let
89   - :env env
90   - :binding-inits binding-inits
91   - :body body
92   - :is-loop (.isLoop expr)
93   - :children (conj binding-inits body)
94   - :Expr-obj expr}))
95   -
96   -;; letfn
97   -
98   -(defmethod analysis->map Compiler$LetFnExpr
99   - [^Compiler$LetFnExpr expr env]
100   - (let [body (analysis->map (.body expr) env)
101   - binding-inits (-> (doall (map analysis->map (.bindingInits expr) (repeat env)))
102   - vec)]
103   - {:op :letfn
104   - :env env
105   - :body body
106   - :binding-inits binding-inits
107   - :children (conj binding-inits body)
108   - :Expr-obj expr}))
109   -
110   -;; LocalBindingExpr
111   -
112   -(defmethod analysis->map Compiler$LocalBindingExpr
113   - [^Compiler$LocalBindingExpr expr env]
114   - (let [local-binding (analysis->map (.b expr) env)]
115   - {:op :local-binding-expr
116   - :env env
117   - :local-binding local-binding
118   - :tag (.tag expr)
119   - :children [local-binding]
120   - :Expr-obj expr}))
121   -
122   -;; Methods
123   -
124   -(defmethod analysis->map Compiler$StaticMethodExpr
125   - [^Compiler$StaticMethodExpr expr env]
126   - (let [field (partial field-accessor Compiler$StaticMethodExpr)
127   - args (doall (map analysis->map (field 'args expr) (repeat env)))]
128   - {:op :static-method
129   - :env (assoc env
130   - :source (field 'source expr)
131   - :line (field 'line expr))
132   - :class (field 'c expr)
133   - :method-name (field 'methodName expr)
134   - :method (when-let [method (field 'method expr)]
135   - (@#'reflect/method->map method))
136   - :args args
137   - :tag (field 'tag expr)
138   - :children args
139   - :Expr-obj expr}))
140   -
141   -(defmethod analysis->map Compiler$InstanceMethodExpr
142   - [^Compiler$InstanceMethodExpr expr env]
143   - (let [field (partial field-accessor Compiler$InstanceMethodExpr)
144   - target (analysis->map (field 'target expr) env)
145   - args (doall (map analysis->map (field 'args expr) (repeat env)))]
146   - {:op :instance-method
147   - :env (assoc env
148   - :source (field 'source expr)
149   - :line (field 'line expr))
150   - :target target
151   - :method-name (field 'methodName expr)
152   - :method (when-let [method (field 'method expr)]
153   - (@#'reflect/method->map method))
154   - :args args
155   - :tag (field 'tag expr)
156   - :children (cons target args)
157   - :Expr-obj expr}))
158   -
159   -;; Fields
160   -
161   -(defmethod analysis->map Compiler$StaticFieldExpr
162   - [^Compiler$StaticFieldExpr expr env]
163   - (let [field (partial field-accessor Compiler$StaticFieldExpr)]
164   - {:op :static-field
165   - :env (assoc env
166   - :line (field 'line expr))
167   - :class (field 'c expr)
168   - :field-name (field 'fieldName expr)
169   - :field (when-let [field (field 'field expr)]
170   - (@#'reflect/field->map field))
171   - :tag (field 'tag expr)
172   - :Expr-obj expr}))
173   -
174   -(defmethod analysis->map Compiler$InstanceFieldExpr
175   - [^Compiler$InstanceFieldExpr expr env]
176   - (let [field (partial field-accessor Compiler$InstanceFieldExpr)
177   - target (analysis->map (field 'target expr) env)]
178   - {:op :instance-field
179   - :env (assoc env
180   - :line (field 'line expr))
181   - :target target
182   - :target-class (field 'targetClass expr)
183   - :field (when-let [field (field 'field expr)]
184   - (@#'reflect/field->map field))
185   - :field-name (field 'fieldName expr)
186   - :tag (field 'tag expr)
187   - :children [target]
188   - :Expr-obj expr}))
189   -
190   -(defmethod analysis->map Compiler$NewExpr
191   - [^Compiler$NewExpr expr env]
192   - (let [args (doall (map analysis->map (.args expr) (repeat env)))]
193   - {:op :new
194   - :env env
195   - :ctor (when-let [ctor (.ctor expr)]
196   - (@#'reflect/constructor->map ctor))
197   - :class (.c expr)
198   - :args args
199   - :children args
200   - :Expr-obj expr}))
201   -
202   -;; Literals
203   -
204   -(defmethod analysis->map Compiler$LiteralExpr
205   - [^Compiler$LiteralExpr expr env]
206   - (let [method (partial method-accessor Compiler$LiteralExpr)]
207   - {:op :literal
208   - :env env
209   - :val (method 'val expr [])
210   - :Expr-obj expr}))
211   -
212   -(defmethod analysis->map Compiler$EmptyExpr
213   - [^Compiler$EmptyExpr expr env]
214   - {:op :empty-expr
215   - :env env
216   - :coll (.coll expr)
217   - :Expr-obj expr})
218   -
219   -;; set literal
220   -
221   -(defmethod analysis->map Compiler$SetExpr
222   - [^Compiler$SetExpr expr env]
223   - (let [keys (doall (map analysis->map (.keys expr) (repeat env)))]
224   - {:op :set
225   - :env env
226   - :keys keys
227   - :children keys
228   - :Expr-obj expr}))
229   -
230   -;; vector literal
231   -
232   -(defmethod analysis->map Compiler$VectorExpr
233   - [^Compiler$VectorExpr expr env]
234   - (let [args (doall (map analysis->map (.args expr) (repeat env)))]
235   - {:op :vector
236   - :env env
237   - :args args
238   - :children args
239   - :Expr-obj expr}))
240   -
241   -;; map literal
242   -
243   -(defmethod analysis->map Compiler$MapExpr
244   - [^Compiler$MapExpr expr env]
245   - (let [keyvals (doall (map analysis->map (.keyvals expr) (repeat env)))]
246   - {:op :map
247   - :env env
248   - :keyvals keyvals
249   - :children keyvals
250   - :Expr-obj expr}))
251   -
252   -;; Untyped
253   -
254   -(defmethod analysis->map Compiler$MonitorEnterExpr
255   - [^Compiler$MonitorEnterExpr expr env]
256   - (let [field (partial field-accessor Compiler$MonitorEnterExpr)
257   - target (analysis->map (field 'target expr) env)]
258   - {:op :monitor-enter
259   - :env env
260   - :target target
261   - :children [target]
262   - :Expr-obj expr}))
263   -
264   -(defmethod analysis->map Compiler$MonitorExitExpr
265   - [^Compiler$MonitorExitExpr expr env]
266   - (let [field (partial field-accessor Compiler$MonitorExitExpr)
267   - target (analysis->map (field 'target expr) env)]
268   - {:op :monitor-exit
269   - :env env
270   - :target target
271   - :children [target]
272   - :Expr-obj expr}))
273   -
274   -(defmethod analysis->map Compiler$ThrowExpr
275   - [^Compiler$ThrowExpr expr env]
276   - (let [field (partial field-accessor Compiler$ThrowExpr)
277   - exception (analysis->map (field 'excExpr expr) env)]
278   - {:op :throw
279   - :env env
280   - :exception exception
281   - :children [exception]
282   - :Expr-obj expr}))
283   -
284   -;; Invokes
285   -
286   -(defmethod analysis->map Compiler$InvokeExpr
287   - [^Compiler$InvokeExpr expr env]
288   - (let [field (partial field-accessor Compiler$InvokeExpr)
289   - fexpr (analysis->map (field 'fexpr expr) env)
290   - args (doall (map analysis->map (field 'args expr) (repeat env)))]
291   - (merge
292   - {:op :invoke
293   - :env (assoc env
294   - :line (field 'line expr)
295   - :source (field 'source expr))
296   - :fexpr fexpr
297   - :tag (field 'tag expr)
298   - :args args
299   - :is-protocol (field 'isProtocol expr)
300   - :is-direct (field 'isDirect expr)
301   - :site-index (field 'siteIndex expr)
302   - :protocol-on (field 'protocolOn expr)
303   - :children (cons fexpr args)
304   - :Expr-obj expr}
305   - (when-let [m (field 'onMethod expr)]
306   - {:method (@#'reflect/method->map m)}))))
307   -
308   -(defmethod analysis->map Compiler$KeywordInvokeExpr
309   - [^Compiler$KeywordInvokeExpr expr env]
310   - (let [field (partial field-accessor Compiler$KeywordInvokeExpr)
311   - target (analysis->map (field 'target expr) env)]
312   - {:op :keyword-invoke
313   - :env (assoc env
314   - :line (field 'line expr)
315   - :source (field 'source expr))
316   - :kw (field 'kw expr)
317   - :tag (field 'tag expr)
318   - :target target
319   - :children [target]
320   - :Expr-obj expr}))
321   -
322   -;; TheVarExpr
323   -
324   -(defmethod analysis->map Compiler$TheVarExpr
325   - [^Compiler$TheVarExpr expr env]
326   - {:op :the-var
327   - :env env
328   - :var (.var expr)
329   - :Expr-obj expr})
330   -
331   -;; VarExpr
332   -
333   -(defmethod analysis->map Compiler$VarExpr
334   - [^Compiler$VarExpr expr env]
335   - {:op :var
336   - :env env
337   - :var (.var expr)
338   - :tag (.tag expr)
339   - :Expr-obj expr})
340   -
341   -;; UnresolvedVarExpr
342   -
343   -(defmethod analysis->map Compiler$UnresolvedVarExpr
344   - [^Compiler$UnresolvedVarExpr expr env]
345   - (let [field (partial field-accessor Compiler$UnresolvedVarExpr)]
346   - {:op :unresolved-var
347   - :env env
348   - :sym (field 'symbol expr)
349   - :Expr-obj expr}))
350   -
351   -;; ObjExprs
352   -
353   -(defmethod analysis->map Compiler$ObjExpr
354   - [^Compiler$ObjExpr expr env]
355   - {:op :obj-expr
356   - :env env
357   - :tag (.tag expr)
358   - :Expr-obj expr})
359   -
360   -;; FnExpr (extends ObjExpr)
361   -
362   -(defmethod analysis->map Compiler$NewInstanceMethod
363   - [^Compiler$NewInstanceMethod obm env]
364   - (let [body (analysis->map (.body obm) env)]
365   - {:op :new-instance-method
366   - :env env
367   - :body body
368   - :children [body]
369   - :ObjMethod-obj obm}))
370   -
371   -(defmethod analysis->map Compiler$FnMethod
372   - [^Compiler$FnMethod obm env]
373   - (let [body (analysis->map (.body obm) env)
374   - required-params (doall (map analysis->map (.reqParms obm) (repeat env)))]
375   - {:op :fn-method
376   - :env env
377   - :body body
378   - ;; Map LocalExpr@xx -> LocalExpr@xx
379   - ; :locals (map analysis->map (keys (.locals obm)) (repeat env))
380   - :required-params required-params
381   - :rest-param (let [rest-param (.restParm obm)]
382   - (if rest-param
383   - (analysis->map rest-param env)
384   - rest-param))
385   - :children [body]
386   - :ObjMethod-obj obm}))
387   -
388   -(defmethod analysis->map Compiler$FnExpr
389   - [^Compiler$FnExpr expr env]
390   - (let [methods (doall (map analysis->map (.methods expr) (repeat env)))]
391   - {:op :fn-expr
392   - :env env
393   - :methods methods
394   - :variadic-method (when-let [variadic-method (.variadicMethod expr)]
395   - (analysis->map variadic-method env))
396   - :tag (.tag expr)
397   - :children methods
398   - :Expr-obj expr}))
399   -
400   -;; NewInstanceExpr
401   -
402   -(defmethod analysis->map Compiler$NewInstanceExpr
403   - [^Compiler$NewInstanceExpr expr env]
404   - (let [field (partial field-accessor Compiler$NewInstanceExpr)
405   - methods (doall (map analysis->map (field 'methods expr) (repeat env)))]
406   - {:op :new-instance-expr
407   - :env env
408   - :methods methods
409   - :mmap (field 'mmap expr)
410   - :covariants (field 'covariants expr)
411   - :tag (.tag expr)
412   - :children methods
413   - :Expr-obj expr}))
414   -
415   -;; InstanceOfExpr
416   -
417   -(defmethod analysis->map Compiler$InstanceOfExpr
418   - [^Compiler$InstanceOfExpr expr env]
419   - (let [field (partial field-accessor Compiler$InstanceOfExpr)
420   - exp (analysis->map (field 'expr expr) env)]
421   - {:op :instance-of
422   - :class (field 'c expr)
423   - :the-expr exp
424   - :children [exp]
425   - :Expr-obj expr}))
426   -
427   -;; MetaExpr
428   -
429   -(defmethod analysis->map Compiler$MetaExpr
430   - [^Compiler$MetaExpr expr env]
431   - (let [meta (analysis->map (.meta expr) env)
432   - the-expr (analysis->map (.expr expr) env)]
433   - {:op :meta
434   - :env env
435   - :meta meta
436   - :expr the-expr
437   - :children [meta the-expr]
438   - :Expr-obj expr}))
439   -
440   -;; do
441   -
442   -(defmethod analysis->map Compiler$BodyExpr
443   - [^Compiler$BodyExpr expr env]
444   - (let [exprs (doall (map analysis->map (.exprs expr) (repeat env)))]
445   - {:op :do
446   - :env env
447   - :exprs exprs
448   - :children exprs
449   - :Expr-obj expr}))
450   -
451   -;; if
452   -
453   -(defmethod analysis->map Compiler$IfExpr
454   - [^Compiler$IfExpr expr env]
455   - (let [test (analysis->map (.testExpr expr) env)
456   - then (analysis->map (.thenExpr expr) env)
457   - else (analysis->map (.elseExpr expr) env)]
458   - {:op :if
459   - :env (assoc env
460   - :line (.line expr))
461   - :test test
462   - :then then
463   - :else else
464   - :children [test then else]
465   - :Expr-obj expr}))
466   -
467   -;; case
468   -
469   -(defmethod analysis->map Compiler$CaseExpr
470   - [^Compiler$CaseExpr expr env]
471   - (let [the-expr (analysis->map (.expr expr) env)
472   - tests (doall (map analysis->map (vals (.tests expr)) (repeat env)))
473   - thens (doall (map analysis->map (vals (.thens expr)) (repeat env)))
474   - default (analysis->map (.defaultExpr expr) env)]
475   - {:op :case*
476   - :the-expr the-expr
477   - :tests tests
478   - :thens thens
479   - :default default
480   - :children (concat [the-expr] tests thens [default])
481   - :Expr-obj expr}))
482   -
483   -
484   -;; ImportExpr
485   -
486   -(defmethod analysis->map Compiler$ImportExpr
487   - [^Compiler$ImportExpr expr env]
488   - {:op :import*
489   - :env env
490   - :class-str (.c expr)
491   - :Expr-obj expr})
492   -
493   -;; AssignExpr (set!)
494   -
495   -(defmethod analysis->map Compiler$AssignExpr
496   - [^Compiler$AssignExpr expr env]
497   - (let [target (analysis->map (.target expr) env)
498   - val (analysis->map (.val expr) env)]
499   - {:op :set!
500   - :env env
501   - :target target
502   - :val val
503   - :children [target val]
504   - :Expr-obj expr}))
505   -
506   -;; TryExpr
507   -
508   -(defmethod analysis->map Compiler$TryExpr$CatchClause
509   - [^Compiler$TryExpr$CatchClause ctch env]
510   - (let [local-binding (analysis->map (.lb ctch) env)
511   - handler (analysis->map (.handler ctch) env)]
512   - {:op :catch
513   - :env env
514   - :class (.c ctch)
515   - :local-binding local-binding
516   - :handler handler
517   - :children [local-binding handler]
518   - :CatchClause-obj ctch}))
519   -
520   -(defmethod analysis->map Compiler$TryExpr
521   - [^Compiler$TryExpr expr env]
522   - (let [try-expr (analysis->map (.tryExpr expr) env)
523   - finally-expr (when-let [finally-expr (.finallyExpr expr)]
524   - (analysis->map finally-expr env))
525   - catch-exprs (doall (map analysis->map (.catchExprs expr) (repeat env)))]
526   - {:op :try
527   - :env env
528   - :try-expr try-expr
529   - :finally-expr finally-expr
530   - :catch-exprs catch-exprs
531   - :ret-local (.retLocal expr)
532   - :finally-local (.finallyLocal expr)
533   - :children (concat [try-expr] (when finally-expr [finally-expr]) catch-exprs)
534   - :Expr-obj expr}))
535   -
536   -;; RecurExpr
537   -
538   -(defmethod analysis->map Compiler$RecurExpr
539   - [^Compiler$RecurExpr expr env]
540   - (let [field (partial field-accessor Compiler$RecurExpr)
541   - loop-locals (doall (map analysis->map (.loopLocals expr) (repeat env)))
542   - args (doall (map analysis->map (.args expr) (repeat env)))]
543   - {:op :recur
544   - :env (assoc env
545   - :line (field 'line expr)
546   - :source (field 'source expr))
547   - :loop-locals loop-locals
548   - :args args
549   - :children (concat loop-locals args)
550   - :Expr-obj expr}))
551   -
552   -(defmethod analysis->map Compiler$MethodParamExpr
553   - [expr env]
554   - (let [field (partial field-accessor Compiler$MethodParamExpr)
555   - method (partial method-accessor Compiler$MethodParamExpr)]
556   - {:op :method-param
557   - :env env
558   - :class (field 'c expr)
559   - :can-emit-primitive (method 'canEmitPrimitive expr [])
560   - :children []
561   - :Expr-obj expr}))
562   -
563   -
564   -(defn- analyze*
565   - "Don't call directly without rebinding *ns*"
566   - [env form]
567   - (letfn [(invoke-analyze [context form]
568   - (push-thread-bindings {Compiler/LOADER (RT/makeClassLoader)})
569   - (try
570   - (Compiler/analyze context form)
571   - (finally
572   - (pop-thread-bindings))))]
573   - (let [context (case (:context env)
574   - :statement Compiler$C/STATEMENT
575   - :expression Compiler$C/EXPRESSION
576   - :return Compiler$C/RETURN
577   - :eval Compiler$C/EVAL)
578   - exprs (try
579   - (invoke-analyze context form)
580   - (catch RuntimeException e
581   - (throw (repl/root-cause e))))]
582   - (analysis->map exprs (merge-with conj (dissoc env :context) {:locals {}})))))
583   -
584   -(defn analyze-one
585   - "Analyze a single form"
586   - [env form]
587   - (binding [*ns* (find-ns (-> env :ns :name))]
588   - (analyze* env form)))
589   -
590   -(defn forms-seq
591   - "Seq of forms in a Clojure or ClojureScript file."
592   - ([f]
593   - (forms-seq f (java.io.PushbackReader. (io/reader f))))
594   - ([f ^java.io.PushbackReader rdr]
595   - (if-let [form (read rdr nil nil)]
596   - (lazy-seq (cons form (forms-seq f rdr)))
597   - (.close rdr))))
598   -
599   -(defn analyze-path
600   - "Takes a path and a namespace symbol.
601   - Returns a seq of maps, with keys :op, :env. If expressions
602   - have children, will have :children entry."
603   - [source-path ns]
604   - (require ns)
605   - (let [strm (.getResourceAsStream (RT/baseLoader) source-path)]
606   - (with-open [rdr (PushbackReader. (InputStreamReader. strm))]
607   - (let [frms (forms-seq nil rdr)
608   - afn #(let [env {:ns {:name ns} :context :eval :locals {}}]
609   - (analyze* env %))]
610   - (binding [*ns* (find-ns ns)]
611   - (doall (map afn frms)))))))
612   -
613   -(comment
614   -(analyze-one {:ns {:name 'clojure.core} :context :eval} '(try (throw (Exception.)) (catch Exception e (throw e)) (finally 33)))
615   -(analyze-one {:ns {:name 'clojure.core} :context :eval} '(try ))
616   -
617   -;; Expecting more output from things like :fn-method
618   -(analyze-one {:ns {:name 'clojure.core} :context :eval} '(try (println 1 23) (throw (Exception.)) (catch Exception e (throw e)) ))
619   -
620   -(analyze-one {:ns {:name 'clojure.core} :context :eval} '(let [b 1] (fn [& a] 1)))
621   -
622   -(analyze-one {:ns {:name 'clojure.core} :context :eval} '(Integer. (+ 1 1)))
623   -(analyze-one {:ns {:name 'clojure.core} :context :eval} '(Integer. (+ 1 1)))
624   -
625   -(analyze-one {:ns {:name 'clojure.core} :context :eval} '(map io/file [1 2]))
626   -
627   - )
628   -
629   -(comment
630   -
631   -(def docm
632   - (analyze-one {:ns {:name 'clojure.repl} :context :eval}
633   - '(defn doc
634   - [name]
635   - "Prints documentation for a var or special form given its name"
636   - (+ 1 1))))
637   -
638   -
639   - (defn traverse [exp]
640   - (println "op" (:op exp))
641   - (when-let [children (seq (:children exp))]
642   - (doseq [c children]
643   - (traverse c))))
644   -
645   - (traverse docm)
646   - )
33 src/analyze/util.clj
... ... @@ -1,33 +0,0 @@
1   -(ns analyze.util
2   - (:require [clojure.pprint :as pp]))
3   -
4   -(defn- dissoc-rec [obj & keys]
5   - (cond
6   - (map? obj) (into {} (for [[key val] (apply dissoc obj keys)]
7   - [key (apply dissoc-rec val keys)]))
8   - (sequential? obj) (map #(apply dissoc-rec % keys) obj)
9   - :else obj))
10   -
11   -(defn print-expr
12   - "Pretty-prints expr, excluding supplied keys.
13   - Example: (print-expr expr :children :env)"
14   - [expr & exclusions]
15   - (pp/pprint (apply dissoc-rec expr exclusions)))
16   -
17   -(defn expr-seq
18   - "Given an expression, returns a lazy sequence of the expressions
19   - followed by its children (in a depth first manner)"
20   - [expr]
21   - (tree-seq #(-> % :children boolean)
22   - :children
23   - expr))
24   -
25   -(comment
26   -(use 'analyze.core)
27   -(print-expr
28   - (analyze-one {:ns {:name 'clojure.core} :context :eval}
29   - '(defn a
30   - ([^bytes b] ^Integer b)
31   - ([b c] c)))
32   - :children :Expr-obj :ObjMethod-obj :LocalBinding-obj :env :BindingInit-obj)
33   - )

0 comments on commit 9b5b424

Please sign in to comment.
Something went wrong with that request. Please try again.