8000 opening Compiler helpers · clojure/clojure@9acdde0 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9acdde0

Browse files
committed
opening Compiler helpers
1 parent e01b2a7 commit 9acdde0

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

src/clj/clojure/genclass.clj

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -101,27 +101,20 @@
101101
'char Character/TYPE
102102
'chars (Class/forName "[C")})
103103

104-
(defn- array-class? [x]
105-
(and (symbol? x)
106-
(namespace x)
107-
(clojure.lang.Util/isPosDigit (name x))))
108-
109-
(defn- resolve-array-class [x]
104+
(defn- resolve-array-class [sym]
110105
(clojure.lang.RT/classForName
111-
(let [dim (-> x name (.charAt 0) int (- (int \0)))
112-
cn (namespace x)
113-
^Iterable dim-descr (repeat dim "[")]
114-
(if-let [^Class pc (clojure.lang.Compiler/primClass (symbol cn))]
115-
(str (String/join "" dim-descr) (-> pc Type/getType Type/.getDescriptor))
116-
(str (String/join "" dim-descr) "L"
117-
(if (some #{\.} cn) cn (str "java.lang." cn))
118-
";")))))
106+
(let [cn (namespace sym)]
107+
(clojure.lang.Compiler$HostExpr/buildArrayClassDescriptor
108+
(if (or (clojure.lang.Compiler/primClass (symbol cn)) (some #{\.} cn))
109+
sym
110+
(symbol (str "java.lang." cn) (name sym)))))))
119111

120112
(defn- ^Class the-class [x]
121113
(cond
122114
(class? x) x
123115
(symbol? x) (cond (contains? prim->class x) (prim->class x)
124-
(array-class? x) (resolve-array-class x)
116+
(clojure.lang.Compiler$HostExpr/looksLikeArrayClass x)
117+
(resolve-array-class x)
125118
:else (let [strx (str x)]
126119
(clojure.lang.RT/classForName
127120
(if (some #{\. \[} strx)

src/jvm/clojure/lang/Compiler.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,10 +1124,11 @@ static Class tagToClass(Object tag) {
11241124
throw new IllegalArgumentException("Unable to resolve classname: " + tag);
11251125
}
11261126

1127-
public static Class maybeArrayClass(Symbol sym) {
1128-
if(sym.ns == null || !Util.isPosDigit(sym.name))
1129-
return null;
1127+
public static boolean looksLikeArrayClass(Symbol sym) {
1128+
return sym.ns != null && Util.isPosDigit(sym.name);
1129+
}
11301130

1131+
public static String buildArrayClassDescriptor(Symbol sym) {
11311132
int dim = sym.name.charAt(0) - '0';
11321133
Symbol componentClassName = Symbol.intern(null, sym.ns);
11331134
Class componentClass = primClass(componentClassName);
@@ -1137,7 +1138,7 @@ public static Class maybeArrayClass(Symbol sym) {
11371138

11381139
if(componentClass == null)
11391140
throw Util.sneakyThrow(new ClassNotFoundException("Unable to resolve component classname: "
1140-
+ componentClassName));
1141+
+ componentClassName));
11411142

11421143
StringBuilder arrayDescriptor = new StringBuilder();
11431144

@@ -1149,7 +1150,14 @@ public static Class maybeArrayClass(Symbol sym) {
11491150
: "L" + componentClass.getName() + ";";
11501151

11511152
arrayDescriptor.append(ccDescr);
1152-
return maybeClass(arrayDescriptor.toString(), true);
1153+
return arrayDescriptor.toString();
1154+
}
1155+
1156+
public static Class maybeArrayClass(Symbol sym) {
1157+
if(!looksLikeArrayClass(sym))
1158+
return null;
1159+
1160+
return maybeClass(buildArrayClassDescriptor(sym), true);
11531161
}
11541162
}
11551163

0 commit comments

Comments
 (0)
0