Created
February 27, 2014 16:39
-
-
Save frenchy64/9253795 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns analyze.clj | |
(:require [clojure.tools.analyzer :as ta] | |
[clojure.tools.analyzer.jvm :as taj] | |
[clojure.tools.analyzer.passes.jvm.emit-form :as emit-form] | |
[clojure.tools.reader :as tr] | |
[clojure.tools.reader.reader-types :as readers] | |
[clojure.string :as str] | |
[clojure.java.io :as io])) | |
(defn ^:private analyze1 [form env] | |
(let [a (taj/analyze form env) | |
frm (emit-form/emit-form a)] | |
(eval frm) | |
a)) | |
(defn analyze-ns [nsym] | |
(let [nsym (ns-name nsym) | |
res (munge nsym) | |
p (str (str/replace res #"\." "/") ".clj") | |
eof (reify) | |
p (if (.startsWith p "/") (subs p 1) p) | |
pres (io/resource p) | |
_ (assert pres (str "Cannot find file for " nsym ": " p)) | |
file (-> pres io/reader slurp) | |
reader (readers/indexing-push-back-reader file) | |
asts (binding [*ns* (or (find-ns nsym) | |
*ns*)] | |
(loop [asts []] | |
(let [form (tr/read reader false eof)] | |
(if (not= eof form) | |
(let [a (analyze1 form (taj/empty-env))] | |
(recur (conj asts a))) | |
asts))))] | |
asts)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns analyze.fail | |
(:require [analyze.clj :as ana])) | |
(deftype FooDT1 []) | |
(assert (cast FooDT1 (->FooDT1))) | |
;=> (ana/analyze-ns *ns*) | |
;ClassCastException Cannot cast clojure.core.typed.test.tools_analyzer.FooDT1 to clojure.core.typed.test.tools_analyzer.FooDT1 java.lang.Class.cast (Class.java:3097) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment