Commits

remleduff committed a43783f

Add initial ns parsing

Comments (0)

Files changed (2)

src/clojure/analyzer.clj

 (ns clojure.analyzer
-  (:refer-clojure :exclude [*ns* *file* macroexpand-1])
+  (:refer-clojure :exclude [macroexpand-1])
   (:require [clojure.java.io :as io]
-   [clojure.string :as string])
+            [clojure.string :as string])
   (:use [clojure pprint]))
 
-(let [mappings (.getMappings (clojure.lang.Namespace/find 'clojure.core))]
-  (defonce namespaces (atom {'clojure.core {:name 'clojure.core :defs mappings}
-                             'user {:name 'user}}))
-  )
+;; TODO: This is for my convenience when developing, will need to replace this with a real boostrap
+(when-not (resolve 'clojure.core/namespaces)
+  (in-ns 'clojure.core) 
+  (load "core1") 
+  (in-ns 'clojure.analyzer) 
+  (refer 'clojure.core :only '[namespaces])) 
 
-(def ^:dynamic *ns* 'user)
-(def ^:dynamic *file* nil)
-(def ^:dynamic *warn-on-undeclared* false)
-
-(def specials '#{if def fn* do let* loop* recur new . reify quote})
+(def specials '#{quote def fn* if do let* loop* recur new . reify gen-interface})
 
 (def ^:dynamic *recur-frames* nil)
 
     (update-in [:args] (walk-coll f))
     (update-in [:ctor] f)))
 
+(defmethod parse 'ns
+  [_ env [_ name & args] _]
+  (let [excludes
+        (reduce (fn [s [k exclude xs]]
+                  (if (= k :refer-clojure)
+                    (do
+                      (assert (= exclude :exclude) "Only [:refer-clojure :exclude [names]] form supported")
+                      (into s xs))
+                    s))
+                #{} args)
+        {uses :use requires :require :as params}
+        (reduce (fn [m [k & libs]]
+                  (assert (#{:use :require} k)
+                          "Only :refer-clojure, :require, :use libspecs supported")
+                  (assoc m k 
+                    (into {}
+                          (mapcat
+                            (fn [[lib kw expr]]
+                                (case k
+                                  (:require)
+                                  (do (assert (and expr (= :as kw))
+                                              "Only (:require [lib.ns :as alias]*) form of :require is supported")
+                                    [[expr lib]])
+                                  (:use)
+                                  (do (assert (and expr (= :only kw))
+                                              "Only (:use [lib.ns :only [names]]*) form of :use is supported")
+                                    (map vector expr (repeat lib)))))
+                            libs))))
+                {} (remove (fn [[r]] (= r :refer-clojure)) args))]
+    (set! *ns* name)
+    (require 'clojure.core)
+    (swap! namespaces #(-> %
+                           (assoc-in [name :name] name)
+                           (assoc-in [name :excludes] excludes)
+                           (assoc-in [name :uses] uses)
+                           (assoc-in [name :requires] requires)))
+    {:env env :op :ns :name name :uses uses :requires requires :excludes excludes}))
+
+(defmethod children :ns
+  [form]
+  nil)
+
+(defmethod walk :ns
+  [form f]
+  form)
+
 ;; dot accessor code
 
 (def ^:private property-symbol? #(boolean (and (symbol? %) (re-matches #"^-.*" (name %)))))

src/clojure/java/compiler.clj

                         " (The protocol method may have been defined before and removed.)"))))
             meth-name (-> key name munge)
             arg-types (map expression-type (rest args))
-            meth (find-method protocol-on (ast/match meth-name arg-types convertible?)
+            meth (find-method protocol-on (match meth-name arg-types convertible?)
                                           (apply str "No single method: " meth-name " of class: " protocol-on
                                                                     " found with args: " arg-types))]
         (emit-typed-args (:parameter-types meth) (rest args))
 
 (defmethod emit :invoke [ast]
   (.visitLineNumber *gen* (-> ast :env :line ) (.mark *gen*))
-  (if (ast/protocol-node? ast)
+  (if (protocol-node? ast)
     (emit-invoke-proto ast)
     (emit-invoke-fn ast)))
 
 
 (defn- emit-field
   [env target field host-field box]
-  (if-let [host-field (or host-field (ast/compute-host-field env (expression-type target) field))]
+  (if-let [host-field (or host-field (compute-host-field env (expression-type target) field))]
     (let [class (-> target expression-type asm-type)
           {:keys [name type]} host-field]
       (.checkCast *gen* class)
                            (Method/getMethod "Object invokeNoArgInstanceMember(Object,String)")))))
 
 (defn- emit-method-call [env target method args host-method box]
-  (if-let [host-method (or host-method (ast/compute-host-method env (expression-type target) method (map expression-type args)))]
+  (if-let [host-method (or host-method (compute-host-method env (expression-type target) method (map expression-type args)))]
     (let [class (asm-type (expression-type target))
           {:keys [name parameter-types return-type declaring-class]} host-method
           meth (apply asm-method name return-type (map maybe-class parameter-types))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.