Skip to content

Instantly share code, notes, and snippets.

@frenchy64 frenchy64/clj.clj
Created Feb 27, 2014

What would you like to do?
(ns analyze.clj
(:require [ :as ta]
[ :as taj]
[ :as emit-form]
[ :as tr]
[ :as readers]
[clojure.string :as str]
[ :as io]))
(defn ^:private analyze1 [form env]
(let [a (taj/analyze form env)
frm (emit-form/emit-form a)]
(eval frm)
(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)
(loop [asts []]
(let [form (tr/read reader false eof)]
(if (not= eof form)
(let [a (analyze1 form (taj/empty-env))]
(recur (conj asts a)))
(: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 (
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.