0
"Returns the root directory path for a lib"
0
"Returns the root resource path for a lib"
0
- (let [d (root-directory lib)
0
- i (inc (.lastIndexOf d (int \/)))
0
- leaf (.substring d i)]
0
- (str d \/ leaf ".clj")))
0
+ (let [d (root-resource lib)]
0
+ (subs d 0 (.lastIndexOf d "/"))))
0
"cannot load '%s' again while it is loading"
0
(binding [*pending-paths* (conj *pending-paths* path)]
0
- (.loadResourceScript clojure.lang.RT (.substring path 1))))))
0
+ (clojure.lang.RT/load (.substring path 1))))))
0
+ (binding [*compile-files* true]
0
+ (load-one lib true true)))
0
;;;;;;;;;;;;; nested associative ops ;;;;;;;;;;;
0
@@ -3482,615 +3484,15 @@
0
"defs the supplied var names with no bindings, useful for making forward declarations."
0
[& names] `(do ~@(map #(list 'def %) names)))
0
- (clojure.lang.RT/compileLib (str libsym)))
0
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; printing ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
0
-(import '(java.io Writer))
0
- #^{:doc "*print-length* controls how many items of each collection the
0
- printer will print. If it is bound to logical false, there is no
0
- limit. Otherwise, it must be bound to an integer indicating the maximum
0
- number of items of each collection to print. If a collection contains
0
- more items, the printer will print items up to the limit followed by
0
- '...' to represent the remaining items. The root binding is nil
0
- indicating no limit."}
0
- #^{:doc "*print-level* controls how many levels deep the printer will
0
- print nested objects. If it is bound to logical false, there is no
0
- limit. Otherwise, it must be bound to an integer indicating the maximum
0
- level to print. Each argument to print is at level 0; if an argument is a
0
- collection, its items are at level 1; and so on. If an object is a
0
- collection and is at a level greater than or equal to the value bound to
0
- *print-level*, the printer prints '#' to represent it. The root binding
0
- is nil indicating no limit."}
0
-(defn- print-sequential [#^String begin, print-one, #^String sep, #^String end, sequence, #^Writer w]
0
- (binding [*print-level* (and (not *print-dup*) *print-level* (dec *print-level*))]
0
- (if (and *print-level* (neg? *print-level*))
0
- (when-let [xs (seq sequence)]
0
- (if (and (not *print-dup*) *print-length*)
0
- print-length *print-length*]
0
- (if (zero? print-length)
0
- (recur xs (dec print-length))))))
0
-(defn- print-meta [o, #^Writer w]
0
- (when-let [m (meta o)]
0
- (when (and (pos? (count m))
0
- (and *print-meta* *print-readably*)))
0
- (if (and (= (count m) 1) (:tag m))
0
-(defmethod print-method nil [o, #^Writer w]
0
-(defmethod print-dup nil [o w] (print-method o w))
0
-(defn print-ctor [o print-args #^Writer w]
0
- (.write w (.getName #^Class (class o)))
0
-(defmethod print-method :default [o, #^Writer w]
0
- (.write w (.getSimpleName (class o)))
0
-(defmethod print-method clojure.lang.Keyword [o, #^Writer w]
0
-(defmethod print-dup clojure.lang.Keyword [o w] (print-method o w))
0
-(defmethod print-method Number [o, #^Writer w]
0
-(defmethod print-dup Number [o, #^Writer w]
0
- (print-dup (str o) w))
0
-(defmethod print-dup clojure.lang.AFn [o, #^Writer w]
0
- (print-ctor o (fn [o w]) w))
0
-(prefer-method print-dup clojure.lang.IPersistentCollection clojure.lang.AFn)
0
-(prefer-method print-dup java.util.Map clojure.lang.AFn)
0
-(prefer-method print-dup java.util.Collection clojure.lang.AFn)
0
-(defmethod print-method Boolean [o, #^Writer w]
0
-(defmethod print-dup Boolean [o w] (print-method o w))
0
-(defn print-simple [o, #^Writer w]
0
-(defmethod print-method clojure.lang.Symbol [o, #^Writer w]
0
-(defmethod print-dup clojure.lang.Symbol [o w] (print-method o w))
0
-(defmethod print-method clojure.lang.Var [o, #^Writer w]
0
-(defmethod print-dup clojure.lang.Var [#^clojure.lang.Var o, #^Writer w]
0
- (.write w (str "#=(var " (.name (.ns o)) "/" (.sym o) ")")))
0
-(defmethod print-method clojure.lang.ISeq [o, #^Writer w]
0
- (print-sequential "(" pr-on " " ")" o w))
0
-(defmethod print-dup clojure.lang.ISeq [o w] (print-method o w))
0
-(defmethod print-method clojure.lang.IPersistentList [o, #^Writer w]
0
- (print-sequential "(" print-method " " ")" o w))
0
-(prefer-method print-method clojure.lang.IPersistentList clojure.lang.ISeq)
0
-(defmethod print-method java.util.Collection [o, #^Writer w]
0
- (print-ctor o #(print-sequential "[" print-method " " "]" %1 %2) w))
0
-(prefer-method print-method clojure.lang.IPersistentCollection java.util.Collection)
0
-(defmethod print-dup java.util.Collection [o, #^Writer w]
0
- (print-ctor o #(print-sequential "[" print-dup " " "]" %1 %2) w))
0
-(defmethod print-dup clojure.lang.IPersistentCollection [o, #^Writer w]
0
- (.write w (.getName #^Class (class o)))
0
- (print-sequential "[" print-dup " " "]" o w)
0
-(prefer-method print-dup clojure.lang.IPersistentCollection java.util.Collection)
0
- :doc "Returns escape string for char or nil if none"}
0
-(defmethod print-method String [#^String s, #^Writer w]
0
- (if (or *print-dup* *print-readably*)
0
- (dotimes [n (count s)]
0
- e (char-escape-string c)]
0
- (if e (.write w e) (.append w c))))
0
-(defmethod print-dup String [s w] (print-method s w))
0
-(defmethod print-method clojure.lang.IPersistentVector [v, #^Writer w]
0
- (print-sequential "[" pr-on " " "]" v w))
0
-(defn- print-map [m print-one w]
0
- (do (print-one (key e) w) (.append w \space) (print-one (val e) w)))
0
-(defmethod print-method clojure.lang.IPersistentMap [m, #^Writer w]
0
- (print-map m pr-on w))
0
-(defmethod print-method java.util.Map [m, #^Writer w]
0
- (print-ctor m #(print-map (seq %1) print-method %2) w))
0
-(prefer-method print-method clojure.lang.IPersistentMap java.util.Map)
0
-(defmethod print-dup java.util.Map [m, #^Writer w]
0
- (print-ctor m #(print-map (seq %1) print-dup %2) w))
0
-(defmethod print-dup clojure.lang.IPersistentMap [m, #^Writer w]
0
- (.write w (.getName (class m)))
0
- (print-map m print-dup w)
0
-(prefer-method print-dup clojure.lang.IPersistentCollection java.util.Map)
0
-(defmethod print-method clojure.lang.IPersistentSet [s, #^Writer w]
0
- (print-sequential "#{" pr-on " " "}" (seq s) w))
0
-(defmethod print-method java.util.Set [s, #^Writer w]
0
- #(print-sequential "#{" print-method " " "}" (seq %1) %2)
0
-;(prefer-method print-method clojure.lang.IPersistentSet java.util.Set)
0
- :doc "Returns name string for char or nil if none"}
0
- \backspace "backspace"
0
-(defmethod print-method java.lang.Character [#^Character c, #^Writer w]
0
- (if (or *print-dup* *print-readably*)
0
- (let [n (char-name-string c)]
0
- (if n (.write w n) (.append w c))))
0
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; helper files ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
0
-(defmethod print-dup java.lang.Character [c w] (print-method c w))
0
-(defmethod print-dup java.lang.Integer [o w] (print-method o w))
0
-(defmethod print-dup java.lang.Double [o w] (print-method o w))
0
-(defmethod print-dup clojure.lang.Ratio [o w] (print-method o w))
0
-(defmethod print-dup java.math.BigDecimal [o w] (print-method o w))
0
-(defmethod print-dup clojure.lang.PersistentHashMap [o w] (print-method o w))
0
-(defmethod print-dup clojure.lang.PersistentHashSet [o w] (print-method o w))
0
-(defmethod print-dup clojure.lang.PersistentVector [o w] (print-method o w))
0
-(def primitives-classnames
0
- {Float/TYPE "Float/TYPE"
0
- Integer/TYPE "Integer/TYPE"
0
- Boolean/TYPE "Boolean/TYPE"
0
- Character/TYPE "Character/TYPE"
0
- Double/TYPE "Double/TYPE"
0
- Short/TYPE "Short/TYPE"})
0
-(defmethod print-method Class [#^Class c, #^Writer w]
0
- (.write w (.getName c)))
0
-(defmethod print-dup Class [#^Class c, #^Writer w]
0
- (.write w "#=(identity ")
0
- (.write w #^String (primitives-classnames c))
0
- (.write w "#=(java.lang.Class/forName \"")
0
- (.write w (.getName c))
0
- (.write w (.getName c)))))
0
-(defmethod print-method java.math.BigDecimal [b, #^Writer w]
0
-(defmethod print-method java.util.regex.Pattern [p #^Writer w]
0
- (loop [[#^Character c & r :as s] (seq (.pattern #^java.util.regex.Pattern p))
0
- (= c \\) (let [[#^Character c2 & r2] r]
0
- (recur r2 (not= c2 \E))
0
- (recur r2 (= c2 \Q))))
0
- (.write w "\\E\\\"\\Q")
0
-(defmethod print-dup java.util.regex.Pattern [p #^Writer w] (print-method p w))
0
-(defmethod print-dup clojure.lang.Namespace [#^clojure.lang.Namespace n #^Writer w]
0
- (.write w "#=(find-ns ")
0
- (print-dup (.name n) w)
0
-(def #^{:private true} print-initialized true)
0
-;;;;;;;;;;;;;;;;;;;;;;;;;;;; proxy ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
0
- '(clojure.asm ClassWriter ClassVisitor Opcodes Type)
0
- '(java.lang.reflect Modifier Constructor)
0
- '(clojure.asm.commons Method GeneratorAdapter)
0
- '(clojure.lang IProxy Reflector DynamicClassLoader IPersistentMap PersistentHashMap RT))
0
-(def *proxy-classes* (ref {}))
0
-(defn method-sig [#^java.lang.reflect.Method meth]
0
- [(. meth (getName)) (seq (. meth (getParameterTypes))) (. meth getReturnType)])
0
- "Takes an optional single class followed by zero or more
0
- interfaces. If not supplied class defaults to Object. Creates an
0
- returns an instance of a proxy class derived from the supplied
0
- classes. The resulting value is cached and used for any subsequent
0
- requests for the same class set. Returns a Class object."
0
- (let [bases (if (. (first bases) (isInterface))
0
- [super & interfaces] bases]
0
- (or (get @*proxy-classes* bases)
0
- (let [cv (new ClassWriter (. ClassWriter COMPUTE_MAXS))
0
- cname (str "clojure/lang/" (gensym "Proxy__"))
0
- ctype (. Type (getObjectType cname))
0
- iname (fn [c] (.. Type (getType c) (getInternalName)))
0
- totype (fn [c] (. Type (getType c)))
0
- to-types (fn [cs] (if (pos? (count cs))
0
- (into-array (map totype cs))
0
- super-type (totype super)
0
- map-type (totype PersistentHashMap)
0
- ifn-type (totype clojure.lang.IFn)
0
- obj-type (totype Object)
0
- sym-type (totype clojure.lang.Symbol)
0
- rt-type (totype clojure.lang.RT)
0
- ex-type (totype java.lang.UnsupportedOperationException)
0
- (fn [#^java.lang.reflect.Method meth else-gen]
0
- (let [pclasses (. meth (getParameterTypes))
0
- ptypes (to-types pclasses)
0
- rtype (totype (. meth (getReturnType)))
0
- m (new Method (. meth (getName)) rtype ptypes)
0
- gen (new GeneratorAdapter (. Opcodes ACC_PUBLIC) m nil nil cv)
0
- else-label (. gen (newLabel))
0
- end-label (. gen (newLabel))
0
- decl-type (. Type (getType (. meth (getDeclaringClass))))]
0
- (. gen (getField ctype fmap map-type))
0
- ;get symbol corresponding to name
0
- (. gen (push (. meth (getName))))
0
- (. gen (invokeStatic sym-type (. Method (getMethod "clojure.lang.Symbol create(String)"))))
0
- (. gen (invokeStatic rt-type (. Method (getMethod "Object get(Object, Object)"))))
0
- (. gen (ifNull else-label))
0
- (dotimes [i (count ptypes)]
0
- (. clojure.lang.Compiler$HostExpr (emitBoxReturn nil gen (nth pclasses i))))
0
- (. gen (invokeInterface ifn-type (new Method "invoke" obj-type
0
- (into-array (cons obj-type
0
- (replicate (count ptypes) obj-type))))))
0
- (when (= (. rtype (getSort)) (. Type VOID))
0
- (. gen (goTo end-label))
0
- ;else call supplied alternative generator
0
- (. gen (mark else-label))
0
- (. gen (mark end-label))
0
- (. gen (endMethod))))]
0
- ;start class definition
0
- (. cv (visit (. Opcodes V1_5) (+ (. Opcodes ACC_PUBLIC) (. Opcodes ACC_SUPER))
0
- cname nil (iname super)
0
- (into-array (map iname (cons IProxy interfaces)))))
0
- ;add field for fn mappings
0
- (. cv (visitField (+ (. Opcodes ACC_PRIVATE) (. Opcodes ACC_VOLATILE))
0
- fmap (. map-type (getDescriptor)) nil nil))
0
- ;add ctors matching/calling super's
0
- (doseq [#^Constructor ctor (. super (getDeclaredConstructors))]
0
- (when-not (. Modifier (isPrivate (. ctor (getModifiers))))
0
- (let [ptypes (to-types (. ctor (getParameterTypes)))
0
- m (new Method "<init>" (. Type VOID_TYPE) ptypes)
0
- gen (new GeneratorAdapter (. Opcodes ACC_PUBLIC) m nil nil cv)]
0
- (. gen (invokeConstructor super-type m))
0
- (. gen (getStatic map-type "EMPTY" map-type))
0
- (. gen (putField ctype fmap map-type))
0
- (. gen (endMethod)))))
0
- (let [m (. Method (getMethod "void __updateClojureFnMappings(clojure.lang.IPersistentMap)"))
0
- gen (new GeneratorAdapter (. Opcodes ACC_PUBLIC) m nil nil cv)]
0
- (. gen (getField ctype fmap map-type))
0
- (. gen (invokeInterface (totype clojure.lang.IPersistentCollection)
0
- (. Method (getMethod "clojure.lang.IPersistentCollection cons(Object)"))))
0
- (. gen (checkCast map-type))
0
- (. gen (putField ctype fmap map-type))
0
- (let [m (. Method (getMethod "clojure.lang.IPersistentMap __getClojureFnMappings()"))
0
- gen (new GeneratorAdapter (. Opcodes ACC_PUBLIC) m nil nil cv)]
0
- (. gen (getField ctype fmap map-type))
0
- ;calc set of supers' non-private instance methods
0
- (let [mm (loop [mm {} considered #{} c super]
0
- (seq (. c (getDeclaredMethods)))
0
- (seq (. c (getMethods))))]
0
- (let [#^java.lang.reflect.Method meth (first meths)
0
- mods (. meth (getModifiers))
0
- (if (or (considered mk)
0
- (. Modifier (isPrivate mods))
0
- (. Modifier (isStatic mods))
0
- (. Modifier (isFinal mods))
0
- (= "finalize" (.getName meth)))
0
- (recur mm (conj considered mk) (rest meths))
0
- (recur (assoc mm mk meth) (conj considered mk) (rest meths))))
0
- (recur mm considered (. c (getSuperclass))))
0
- ;add methods matching supers', if no mapping -> call super
0
- (doseq [#^java.lang.reflect.Method meth (vals mm)]
0
- (. gen (visitMethodInsn (. Opcodes INVOKESPECIAL)
0
- (. super-type (getInternalName))
0
- (. m (getDescriptor)))))))
0
- ;add methods matching interfaces', if no mapping -> throw
0
- (doseq [#^Class iface interfaces]
0
- (doseq [#^java.lang.reflect.Method meth (. iface (getMethods))]
0
- (when-not (contains? mm (method-sig meth))
0
- (. gen (throwException ex-type (. m (getName))))))))))
0
- ;generate, cache and return class object
0
- (let [loader (. RT ROOT_CLASSLOADER)
0
- c (. loader (defineClass (. cname (replace "/" "."))
0
- (. cv (toByteArray))))]
0
- (sync nil (commute *proxy-classes* assoc bases c))
0
- "Takes a proxy class and any arguments for its superclass ctor and
0
- creates and returns an instance of the proxy."
0
- (. Reflector (invokeConstructor c (to-array ctor-args))))
0
- "Takes a proxy instance and a map of symbols (whose names must
0
- correspond to methods of the proxy superclass/superinterfaces) to
0
- fns (which must take arguments matching the corresponding method,
0
- plus an additional (explicit) first arg corresponding to this, and
0
- updates (via assoc) the proxy's fn map. nil can be passed instead of
0
- a fn, in which case the corresponding method will revert to the
0
- default behavior. Note that this function can be used to update the
0
- behavior of an existing instance without changing its identity."
0
- [#^IProxy proxy mappings]
0
- (. proxy (__updateClojureFnMappings mappings)))
0
- "Takes a proxy instance and returns the proxy's fn map."
0
- (. proxy (__getClojureFnMappings)))
0
- "class-and-interfaces - a vector of class names
0
- args - a (possibly empty) vector of arguments to the superclass
0
- f => (name [params*] body) or
0
- (name ([params*] body) ([params+] body) ...)
0
- Expands to code which creates a instance of a proxy class that
0
- implements the named class/interface(s) by calling the supplied
0
- fns. A single class, if provided, must be first. If not provided it
0
- The interfaces names must be valid interface types. If a method fn
0
- is not provided for a class method, the superclass methd will be
0
- called. If a method fn is not provided for an interface method, an
0
- UnsupportedOperationException will be thrown should it be
0
- called. Method fns are closures and can capture the environment in
0
- which proxy is called. Each method fn takes an additional implicit
0
- first arg, which is bound to 'this. Note that while method fns can
0
- be provided to override protected methods, they have no other access
0
- to protected members, nor to super, as these capabilities cannot be
0
- [class-and-interfaces args & fs]
0
- `(let [pc# (get-proxy-class ~@class-and-interfaces)
0
- p# (construct-proxy pc# ~@args)]
0
- ~(loop [fmap {} fs fs]
0
- (let [[sym & meths] (first fs)
0
- meths (if (vector? (first meths))
0
- meths (map (fn [[params & body]]
0
- (cons (apply vector 'this params) body))
0
- (recur (assoc fmap (list `quote (symbol (name sym))) (cons `fn meths)) (rest fs)))
0
-(defn proxy-call-with-super [call this meth]
0
- (let [m (proxy-mappings this)]
0
- (update-proxy this (assoc m meth nil))
0
- "Use to call a superclass method in the body of a proxy method.
0
- Note, expansion captures 'this"
0
- `(proxy-call-with-super (fn [] (. ~'this ~meth ~@args)) ~'this '~(symbol (name meth))))
0
- "Takes a Java object and returns a read-only implementation of the
0
- map abstraction based upon its JavaBean properties."
0
- (let [c (. x (getClass))
0
- pmap (reduce (fn [m #^java.beans.PropertyDescriptor pd]
0
- (let [name (. pd (getName))
0
- method (. pd (getReadMethod))]
0
- (if (and method (zero? (alength (. method (getParameterTypes)))))
0
- (assoc m (keyword name) (fn [] (. method (invoke x nil))))
0
- (seq (.. java.beans.Introspector
0
- (getPropertyDescriptors))))
0
- (assoc m (key e) ((val e))))
0
- (proxy [clojure.lang.APersistentMap]
0
- (containsKey [k] (contains? pmap k))
0
- (entryAt [k] (when (contains? pmap k) (new clojure.lang.MapEntry k (v k))))
0
- ([k default] (if (contains? pmap k) (v k) default)))
0
- (cons [m] (conj (snapshot) m))
0
- (count [] (count pmap))
0
- (assoc [k v] (assoc (snapshot) k v))
0
- (without [k] (dissoc (snapshot) k))
0
- (seq [] ((fn thisfn [pseq]
0
- (lazy-cons (new clojure.lang.MapEntry (first pseq) (v (first pseq)))
0
- (thisfn (rest pseq))))) (keys pmap))))))