Commits

remleduff committed 7f0cf54

Fix some incidental *ns* problems, start trying to figure out bootstrap

  • Participants
  • Parent commits a43783f

Comments (0)

Files changed (3)

File src/clojure/analyzer.clj

 (ns clojure.analyzer
-  (:refer-clojure :exclude [macroexpand-1])
+  (:refer-clojure :exclude [macroexpand-1 *ns*])
   (:require [clojure.java.io :as io]
             [clojure.string :as string])
   (:use [clojure pprint]))
   (in-ns 'clojure.core) 
   (load "core1") 
   (in-ns 'clojure.analyzer) 
-  (refer 'clojure.core :only '[namespaces])) 
+  (def ^:dynamic *ns* 'user)
+  (refer 'clojure.core :only '[namespaces *warn-on-undeclared*])) 
 
 (def specials '#{quote def fn* if do let* loop* recur new . reify gen-interface})
 

File src/clojure/java/compiler.clj

 (ns clojure.java.compiler
-  (:refer-clojure :exclude [eval load munge *ns* type])
+  (:refer-clojure :exclude [eval load munge type *ns*])
   (:require [clojure.java.io :as io]
             [clojure.string :as string])
   (:use [clojure
-          [analyzer :only [analyze children resolve-var walk]]
-          [reflect :only [type-reflect]]
+          [analyzer :only [analyze children *ns* resolve-var walk]]
+          [reflect :only []]
           [set :only [select]]
           pprint repl]) ; for debugging
   (:import [org.objectweb.asm Type Opcodes ClassReader ClassWriter]
 (def ^:private prims
   {"byte" Byte/TYPE "bool" Boolean/TYPE "char" Character/TYPE "int" Integer/TYPE "long" Long/TYPE "float" Float/TYPE "double" Double/TYPE "void" Void/TYPE})
 
+(declare asm-type asm-method maybe-class)
+
 (defn array-class [element-type]
-  (RT/classForName (str "[" (.getDescriptor element-type) ";")))
+  (RT/classForName (str "[" (-> element-type maybe-class asm-type .getDescriptor (.replace \/ \.)))))
+
+(defn- asm-type [s]
+  (when s
+    (let [class (maybe-class s)]
+      (if class
+        (Type/getType class)
+        (Type/getType s)))))
+
+(defn- asm-method
+  ([{:keys [name return-types parameter-types]}]
+   (apply asm-method name return-types parameter-types))
+  ([name return-type & args]
+   (Method. (str name) (asm-type return-type) (into-array Type (map asm-type args)))))
 
 (defmulti maybe-class class)
 (defmethod maybe-class nil [_] nil)
       (not (or (nil? c) (= c Void/TYPE)))
       (.isPrimitive c))))
 
-(defn- asm-type [s]
-  (when s
-    (let [class (maybe-class s)]
-      (if class
-        (Type/getType class)
-        (Type/getType s)))))
-
-(defn- asm-method
-  ([{:keys [name return-types parameter-types]}]
-   (apply asm-method name return-types parameter-types))
-  ([name return-type & args]
-   (Method. (str name) (asm-type return-type) (into-array Type (map asm-type args)))))
-
-(load "compiler/ast")
+(clojure.core/load "compiler/ast")
 
 ; Frame members (maybe these should be separate variables?):
 ; :class - ASM type of current class being written

File src/clojure/java/compiler/ast.clj

+(in-ns 'clojure.reflect)
+(deftype BetterReflector []
+  Reflector
+  (do-reflect [_ typeref]
+           (let [cls (Class/forName (typename typeref) false (clojure.lang.RT/baseLoader))]
+             {:bases (not-empty (set (map typesym (bases cls))))
+              :flags (parse-flags (.getModifiers cls) :class)
+              :members (set/union (declared-fields cls)
+                                  (declared-methods cls)
+                                  (declared-constructors cls))})))
+
 (in-ns 'clojure.java.compiler)
 
+(let [reflector (clojure.reflect.BetterReflector.)]
+  (defn type-reflect [typeref & options]
+    (apply clojure.reflect/type-reflect typeref :reflector reflector options)))
+
 (declare compute-type)
 
 (defn expression-type [form]
 (defmethod compute-type :reify
   [{:as form :keys [name]}]
   (let [name (if name name (gensym "reify__"))]
-    (assoc form :name name :class (resolve name))))
+    (assoc form :name name :type (resolve name))))
 
 (defmethod compute-type :new
   [{:as form :keys [ctor]}]