aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduardo Julian2015-12-31 17:19:03 -0400
committerEduardo Julian2015-12-31 17:19:03 -0400
commit8aebde76ee407b96db956e5d8bdea8e67dc6c6ad (patch)
tree8a3a5722f32b056960001715d5ed1a41f6983770
parent51fc12ae976f2106f549b4a8f07377c9185ebb68 (diff)
- [Refactor] Removed the (now unnecessary) lux.type.host/class-name->type function.
- When compiling definitions, their names now carry a hash code to avoid file-name collisions when generating files in case-insensitive file-systems.
Diffstat (limited to '')
-rw-r--r--src/lux/analyser/host.clj14
-rw-r--r--src/lux/analyser/module.clj2
-rw-r--r--src/lux/compiler/cache.clj6
-rw-r--r--src/lux/compiler/lux.clj4
-rw-r--r--src/lux/host.clj9
-rw-r--r--src/lux/type/host.clj21
6 files changed, 21 insertions, 35 deletions
diff --git a/src/lux/analyser/host.clj b/src/lux/analyser/host.clj
index fb4c3e55d..cf503f188 100644
--- a/src/lux/analyser/host.clj
+++ b/src/lux/analyser/host.clj
@@ -297,8 +297,7 @@
=object (&&/analyse-1+ analyse object)
[sub-class sub-params] (ensure-object (&&/expr-type* =object))
(&/$DataT super-class* super-params*) (&host-type/->super-type &type/existential class-loader class sub-class sub-params)
- :let [;; _ (prn '<name> sub-class '-> super-class* (&/|length parent-gvars) (&/|length super-params*))
- gtype-env (&/fold2 (fn [m ^TypeVariable g t] (&/Cons$ (&/T (.getName g) t) m))
+ :let [gtype-env (&/fold2 (fn [m ^TypeVariable g t] (&/Cons$ (&/T (.getName g) t) m))
(&/|table)
parent-gvars
super-params*)]
@@ -317,11 +316,12 @@
(|do [class-loader &/loader
[gret exceptions parent-gvars gvars gargs] (&host/lookup-static-method class-loader class method classes)
_ (ensure-catching exceptions)
- =args (&/map2% (fn [_class _arg]
- (&&/analyse-1 analyse (&host-type/class-name->type _class) _arg))
- classes
- args)
- output-type (&host-type/instance-param &type/existential (&/|table) gret)
+ gtype-env (&/fold% (fn [m ^TypeVariable g]
+ (|do [=var-type &type/existential]
+ (return (&/Cons$ (&/T (.getName g) =var-type) m))))
+ (&/|table)
+ parent-gvars)
+ [output-type =args] (analyse-method-call-helper analyse gret gtype-env gvars gargs args)
_ (&type/check exo-type (as-otype+ output-type))
_cursor &/cursor]
(return (&/|list (&&/|meta exo-type _cursor
diff --git a/src/lux/analyser/module.clj b/src/lux/analyser/module.clj
index d0ce0e9c1..75a62bf95 100644
--- a/src/lux/analyser/module.clj
+++ b/src/lux/analyser/module.clj
@@ -201,7 +201,7 @@
[exported? (&/$ValueD ?type _)]
((|do [_ (&type/check &type/Macro ?type)
^ClassLoader loader &/loader
- :let [macro (-> (.loadClass loader (str (&host-generics/->class-name module) "." (&/normalize-name name)))
+ :let [macro (-> (.loadClass loader (str (&host-generics/->class-name module) "." (&host/def-name name)))
(.getField &/datum-field)
(.get nil))]]
(fn [state*]
diff --git a/src/lux/compiler/cache.clj b/src/lux/compiler/cache.clj
index 2bb3a94f1..3337b9b76 100644
--- a/src/lux/compiler/cache.clj
+++ b/src/lux/compiler/cache.clj
@@ -123,14 +123,14 @@
_ (&/map% (fn [_def]
(let [[_exported? _name _ann] (string/split _def #" ")]
(|do [_ (case _ann
- "T" (let [def-class (&&/load-class! loader (str module* "." (&/normalize-name _name)))
+ "T" (let [def-class (&&/load-class! loader (str module* "." (&host/def-name _name)))
def-value (get-field &/datum-field def-class)]
(&a-module/define module _name (&/V &/$TypeD def-value) &type/Type))
- "M" (let [def-class (&&/load-class! loader (str module* "." (&/normalize-name _name)))
+ "M" (let [def-class (&&/load-class! loader (str module* "." (&host/def-name _name)))
def-value (get-field &/datum-field def-class)]
(|do [_ (&a-module/define module _name (&/V &/$ValueD (&/T &type/Macro def-value)) &type/Macro)]
(&a-module/declare-macro module _name)))
- "V" (let [def-class (&&/load-class! loader (str module* "." (&/normalize-name _name)))
+ "V" (let [def-class (&&/load-class! loader (str module* "." (&host/def-name _name)))
def-meta (get-field &/meta-field def-class)]
(|case def-meta
(&/$ValueD def-type _)
diff --git a/src/lux/compiler/lux.clj b/src/lux/compiler/lux.clj
index 21494908a..54c103c1d 100644
--- a/src/lux/compiler/lux.clj
+++ b/src/lux/compiler/lux.clj
@@ -104,7 +104,7 @@
(defn compile-global [compile ?owner-class ?name]
(|do [^MethodVisitor *writer* &/get-writer
- :let [_ (.visitFieldInsn *writer* Opcodes/GETSTATIC (str (&host/->module-class ?owner-class) "/" (&/normalize-name ?name)) &/datum-field "Ljava/lang/Object;")]]
+ :let [_ (.visitFieldInsn *writer* Opcodes/GETSTATIC (str (&host/->module-class ?owner-class) "/" (&host/def-name ?name)) &/datum-field "Ljava/lang/Object;")]]
(return nil)))
(defn compile-apply [compile ?fn ?args]
@@ -185,7 +185,7 @@
module-name &/get-module-name
[file-name _ _] &/cursor
:let [datum-sig "Ljava/lang/Object;"
- def-name (&/normalize-name ?name)
+ def-name (&host/def-name ?name)
current-class (str (&host/->module-class module-name) "/" def-name)
=class (doto (new ClassWriter ClassWriter/COMPUTE_MAXS)
(.visit &host/bytecode-version class-flags
diff --git a/src/lux/host.clj b/src/lux/host.clj
index 048051009..e32a60065 100644
--- a/src/lux/host.clj
+++ b/src/lux/host.clj
@@ -151,8 +151,15 @@
:when (Modifier/isAbstract (.getModifiers =method))]
(&/T (.getName =method) (&/|map #(.getName ^Class %) (&/->list (seq (.getParameterTypes =method))))))))))
+(defn def-name [name]
+ (str (&/normalize-name name) "_" (hash name)))
+
(defn location [scope]
- (->> scope (&/|map &/normalize-name) (&/|interpose "$") (&/fold str "")))
+ (let [scope (&/Cons$ (def-name (&/|head scope))
+ (&/|map &/normalize-name (&/|tail scope)))]
+ (->> scope
+ (&/|interpose "$")
+ (&/fold str ""))))
(defn primitive-jvm-type? [type]
(case type
diff --git a/src/lux/type/host.clj b/src/lux/type/host.clj
index 60c8aa51f..ddb40f21d 100644
--- a/src/lux/type/host.clj
+++ b/src/lux/type/host.clj
@@ -234,27 +234,6 @@
(catch Exception e
(fail (str "[Type Error] Unknown type: " class)))))))
-(defn class-name->type [class-name]
- (case class-name
- ;; "[Z" (&/V &/$DataT (&/T array-data-tag (&/|list (&/V &/$DataT (&/T "java.lang.Boolean" (&/|list))))))
- ;; "[B" (&/V &/$DataT (&/T array-data-tag (&/|list (&/V &/$DataT (&/T "java.lang.Byte" (&/|list))))))
- ;; "[S" (&/V &/$DataT (&/T array-data-tag (&/|list (&/V &/$DataT (&/T "java.lang.Short" (&/|list))))))
- ;; "[I" (&/V &/$DataT (&/T array-data-tag (&/|list (&/V &/$DataT (&/T "java.lang.Integer" (&/|list))))))
- ;; "[J" (&/V &/$DataT (&/T array-data-tag (&/|list (&/V &/$DataT (&/T "java.lang.Long" (&/|list))))))
- ;; "[F" (&/V &/$DataT (&/T array-data-tag (&/|list (&/V &/$DataT (&/T "java.lang.Float" (&/|list))))))
- ;; "[D" (&/V &/$DataT (&/T array-data-tag (&/|list (&/V &/$DataT (&/T "java.lang.Double" (&/|list))))))
- ;; "[C" (&/V &/$DataT (&/T array-data-tag (&/|list (&/V &/$DataT (&/T "java.lang.Character" (&/|list))))))
- "[Z" (&/V &/$DataT (&/T array-data-tag (&/|list (&/V &/$DataT (&/T "boolean" (&/|list))))))
- "[B" (&/V &/$DataT (&/T array-data-tag (&/|list (&/V &/$DataT (&/T "byte" (&/|list))))))
- "[S" (&/V &/$DataT (&/T array-data-tag (&/|list (&/V &/$DataT (&/T "short" (&/|list))))))
- "[I" (&/V &/$DataT (&/T array-data-tag (&/|list (&/V &/$DataT (&/T "int" (&/|list))))))
- "[J" (&/V &/$DataT (&/T array-data-tag (&/|list (&/V &/$DataT (&/T "long" (&/|list))))))
- "[F" (&/V &/$DataT (&/T array-data-tag (&/|list (&/V &/$DataT (&/T "float" (&/|list))))))
- "[D" (&/V &/$DataT (&/T array-data-tag (&/|list (&/V &/$DataT (&/T "double" (&/|list))))))
- "[C" (&/V &/$DataT (&/T array-data-tag (&/|list (&/V &/$DataT (&/T "char" (&/|list))))))
- ;; else
- (&/V &/$DataT (&/T class-name (&/|list)))))
-
(defn gtype->gclass [gtype]
"(-> GenericType GenericClass)"
(cond (instance? Class gtype)