From 9ae1f0fd80f1fd45e242210a039ee12f11345f5b Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 26 Apr 2016 20:44:53 -0400 Subject: - Now using the actual class-names for arrays of primitives, instead of the #Array of "something" format. --- src/lux/analyser/host.clj | 31 +++++++++++++++++++------------ src/lux/host/generics.clj | 13 ++++++++----- src/lux/lexer.clj | 2 +- src/lux/type/host.clj | 35 +++++++++++++++++++++-------------- 4 files changed, 49 insertions(+), 32 deletions(-) diff --git a/src/lux/analyser/host.clj b/src/lux/analyser/host.clj index 20028441c..edd3babc4 100644 --- a/src/lux/analyser/host.clj +++ b/src/lux/analyser/host.clj @@ -381,9 +381,9 @@ (let [length-type &type/Int idx-type &type/Int] - (do-template [ ] - (let [elem-type (&/$DataT &/$Nil) - array-type (&/$DataT &host-type/array-data-tag (&/|list elem-type))] + (do-template [ ] + (let [elem-type (&/$DataT &/$Nil) + array-type (&/$DataT &/$Nil)] (defn [analyse exo-type length] (|do [=length (&&/analyse-1 analyse length-type length) _ (&type/check exo-type array-type) @@ -409,16 +409,23 @@ ( (&/T [=array =idx =elem]))))))) ) - "java.lang.Boolean" analyse-jvm-znewarray &&/$jvm-znewarray analyse-jvm-zaload &&/$jvm-zaload analyse-jvm-zastore &&/$jvm-zastore - "java.lang.Byte" analyse-jvm-bnewarray &&/$jvm-bnewarray analyse-jvm-baload &&/$jvm-baload analyse-jvm-bastore &&/$jvm-bastore - "java.lang.Short" analyse-jvm-snewarray &&/$jvm-snewarray analyse-jvm-saload &&/$jvm-saload analyse-jvm-sastore &&/$jvm-sastore - "java.lang.Integer" analyse-jvm-inewarray &&/$jvm-inewarray analyse-jvm-iaload &&/$jvm-iaload analyse-jvm-iastore &&/$jvm-iastore - "java.lang.Long" analyse-jvm-lnewarray &&/$jvm-lnewarray analyse-jvm-laload &&/$jvm-laload analyse-jvm-lastore &&/$jvm-lastore - "java.lang.Float" analyse-jvm-fnewarray &&/$jvm-fnewarray analyse-jvm-faload &&/$jvm-faload analyse-jvm-fastore &&/$jvm-fastore - "java.lang.Double" analyse-jvm-dnewarray &&/$jvm-dnewarray analyse-jvm-daload &&/$jvm-daload analyse-jvm-dastore &&/$jvm-dastore - "java.lang.Character" analyse-jvm-cnewarray &&/$jvm-cnewarray analyse-jvm-caload &&/$jvm-caload analyse-jvm-castore &&/$jvm-castore + "java.lang.Boolean" "[Z" analyse-jvm-znewarray &&/$jvm-znewarray analyse-jvm-zaload &&/$jvm-zaload analyse-jvm-zastore &&/$jvm-zastore + "java.lang.Byte" "[B" analyse-jvm-bnewarray &&/$jvm-bnewarray analyse-jvm-baload &&/$jvm-baload analyse-jvm-bastore &&/$jvm-bastore + "java.lang.Short" "[S" analyse-jvm-snewarray &&/$jvm-snewarray analyse-jvm-saload &&/$jvm-saload analyse-jvm-sastore &&/$jvm-sastore + "java.lang.Integer" "[I" analyse-jvm-inewarray &&/$jvm-inewarray analyse-jvm-iaload &&/$jvm-iaload analyse-jvm-iastore &&/$jvm-iastore + "java.lang.Long" "[J" analyse-jvm-lnewarray &&/$jvm-lnewarray analyse-jvm-laload &&/$jvm-laload analyse-jvm-lastore &&/$jvm-lastore + "java.lang.Float" "[F" analyse-jvm-fnewarray &&/$jvm-fnewarray analyse-jvm-faload &&/$jvm-faload analyse-jvm-fastore &&/$jvm-fastore + "java.lang.Double" "[D" analyse-jvm-dnewarray &&/$jvm-dnewarray analyse-jvm-daload &&/$jvm-daload analyse-jvm-dastore &&/$jvm-dastore + "java.lang.Character" "[C" analyse-jvm-cnewarray &&/$jvm-cnewarray analyse-jvm-caload &&/$jvm-caload analyse-jvm-castore &&/$jvm-castore )) +(defn array-class? [class-name] + (or (= &host-type/array-data-tag class-name) + (case class-name + ("[Z" "[B" "[S" "[I" "[J" "[F" "[D" "[C") true + ;; else + false))) + (let [length-type &type/Int idx-type &type/Int] (defn analyse-jvm-anewarray [analyse exo-type gclass length] @@ -458,7 +465,7 @@ (defn analyse-jvm-arraylength [analyse exo-type array] (|do [=array (&&/analyse-1+ analyse array) [arr-class arr-params] (ensure-object (&&/expr-type* =array)) - _ (&/assert! (= &host-type/array-data-tag arr-class) (str "[Analyser Error] Expected array. Instead got: " arr-class)) + _ (&/assert! (array-class? arr-class) (str "[Analyser Error] Expected array. Instead got: " arr-class)) _ (&type/check exo-type &type/Int) _cursor &/cursor] (return (&/|list (&&/|meta exo-type _cursor diff --git a/src/lux/host/generics.clj b/src/lux/host/generics.clj index 53cc98e6e..433b79d1c 100644 --- a/src/lux/host/generics.clj +++ b/src/lux/host/generics.clj @@ -81,7 +81,7 @@ (&/$GenericWildcard (&/$Some [(&/$LowerBound) ?bound])) (str "-" (gclass->signature ?bound)) - (&/$GenericClass name params) + (&/$GenericClass ^String name params) (case name "void" "V" "boolean" "Z" @@ -92,10 +92,13 @@ "float" "F" "double" "D" "char" "C" - (let [params* (if (&/|empty? params) - "" - (str "<" (->> params (&/|map gclass->signature) (&/|interpose " ") (&/fold str "")) ">"))] - (str "L" (->bytecode-class-name name) params* ";"))) + ;; else + (if (.startsWith name "[") + name + (let [params* (if (&/|empty? params) + "" + (str "<" (->> params (&/|map gclass->signature) (&/|interpose " ") (&/fold str "")) ">"))] + (str "L" (->bytecode-class-name name) params* ";")))) (&/$GenericArray param) (str "[" (gclass->signature param)))) diff --git a/src/lux/lexer.clj b/src/lux/lexer.clj index 27116af91..e30e08c19 100644 --- a/src/lux/lexer.clj +++ b/src/lux/lexer.clj @@ -89,7 +89,7 @@ (defn ^:private lex-text-body [multi-line? offset] (|do [[_ eol? ^String pre-quotes**] (&reader/read-regex #"^([^\"]*)") - pre-quotes* (if multi-line? + ^String pre-quotes* (if multi-line? (|do [:let [empty-line? (and eol? (= "" pre-quotes**))] _ (&/assert! (or empty-line? (>= (.length pre-quotes**) offset)) diff --git a/src/lux/type/host.clj b/src/lux/type/host.clj index b547a7052..0d1ee274e 100644 --- a/src/lux/type/host.clj +++ b/src/lux/type/host.clj @@ -76,18 +76,23 @@ "C" "char"))] (defn class->type [^Class class] "(-> Class Type)" - (if-let [[_ _ arr-obrackets arr-obase simple-base arr-pbrackets arr-pbase] (re-find class-name-re (.getName class))] - (let [base (or arr-obase simple-base (jprim->lprim arr-pbase))] - (if (.equals "void" base) - &/$UnitT - (reduce (fn [inner _] (&/$DataT array-data-tag (&/|list inner))) - (&/$DataT base (try (-> (Class/forName base) .getTypeParameters - seq count (repeat (&/$DataT "java.lang.Object" &/$Nil)) - &/->list) - (catch Exception e - (&/|list)))) - (range (count (or arr-obrackets arr-pbrackets ""))))) - )))) + (let [gclass-name (.getName class)] + (case gclass-name + ("[Z" "[B" "[S" "[I" "[J" "[F" "[D" "[C") + (&/$DataT gclass-name (&/|list)) + ;; else + (if-let [[_ _ arr-obrackets arr-obase simple-base arr-pbrackets arr-pbase] (re-find class-name-re gclass-name)] + (let [base (or arr-obase simple-base (jprim->lprim arr-pbase))] + (if (.equals "void" base) + &/$UnitT + (reduce (fn [inner _] (&/$DataT array-data-tag (&/|list inner))) + (&/$DataT base (try (-> (Class/forName base) .getTypeParameters + seq count (repeat (&/$DataT "java.lang.Object" &/$Nil)) + &/->list) + (catch Exception e + (&/|list)))) + (range (count (or arr-obrackets arr-pbrackets ""))))) + )))))) (defn instance-param [existential matchings refl-type] "(-> (Lux Type) (List (, Text Type)) (^ java.lang.reflect.Type) (Lux Type))" @@ -283,7 +288,7 @@ "(-> GenericClass Text)" (|case gclass (&/$GenericClass gclass-name (&/$Nil)) - (|case gclass-name + (case gclass-name "void" "V" "boolean" "Z" "byte" "B" @@ -293,7 +298,9 @@ "float" "F" "double" "D" "char" "C" - _ (str "L" (clojure.string/replace gclass-name #"\." "/") ";")) + ("[Z" "[B" "[S" "[I" "[J" "[F" "[D" "[C") gclass-name + ;; else + (str "L" (clojure.string/replace gclass-name #"\." "/") ";")) (&/$GenericArray inner-gtype) (str "[" (gclass->sig inner-gtype)) -- cgit v1.2.3