Skip to content

Commit 2d6e2c0

Browse files
committed
wip [skip ci]
1 parent bb544b7 commit 2d6e2c0

File tree

3 files changed

+56
-10
lines changed

3 files changed

+56
-10
lines changed

reflector/src/sci/impl/Reflector.java

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,14 +142,27 @@ private static String noMethodReport(String methodName, Class contextClass, Obje
142142
+ (contextClass != null ? " for " + contextClass : "");
143143
}
144144

145-
private static Method matchMethod(List methods, Object[] args) {
145+
private static Method matchMethod(List methods, Object[] args) {
146+
return matchMethod(methods, args, null);
147+
}
148+
private static Method matchMethod(List methods, Object[] args, Class[] argTypes) {
146149
Method foundm = null;
147150
for(Iterator i = methods.iterator(); i.hasNext();) {
148151
Method m = (Method) i.next();
152+
System.err.println("Trying method: " + m);
149153
Class[] params = m.getParameterTypes();
150-
if(isCongruent(params, args) && (foundm == null || Compiler.subsumes(params, foundm.getParameterTypes())))
154+
System.err.print("param classes: ");
155+
for (int p = 0; p < params.length; p++) {
156+
System.err.print(params[p].toString());
157+
}
158+
System.err.println();
159+
System.err.println("isCongruent: " + isCongruent(params, args));
160+
if (foundm != null)
161+
System.err.println("subsumes: " + Compiler.subsumes(params, foundm.getParameterTypes()));
162+
if(isCongruent(params, args, argTypes) && (foundm == null || Compiler.subsumes(params, foundm.getParameterTypes())))
151163
foundm = m;
152164
}
165+
System.err.println("found method: " + foundm);
153166
return foundm;
154167
}
155168

@@ -175,7 +188,12 @@ public static Object invokeMatchingMethod(String methodName, List methods, Objec
175188
return invokeMatchingMethod(methodName, methods, target != null ? target.getClass() : null, target, args);
176189
}
177190

178-
static Object invokeMatchingMethod(String methodName, List methods, Class contextClass, Object target, Object[] args)
191+
static Object invokeMatchingMethod(String methodName, List methods, Class contextClass, Object target, Object[] args) {
192+
return invokeMatchingMethod(methodName, methods, contextClass, target, args, null);
193+
}
194+
195+
/* PATCH: made public, added argTypes */
196+
public static Object invokeMatchingMethod(String methodName, List methods, Class contextClass, Object target, Object[] args, Class[] argTypes)
179197
{
180198
Method m = null;
181199
if(methods.isEmpty())
@@ -192,7 +210,7 @@ else if(methods.size() == 1)
192210
if(m == null) // widen boxed args and re-try matchMethod
193211
{
194212
args = widenBoxedArgs(args);
195-
m = matchMethod(methods, args);
213+
m = matchMethod(methods, args, argTypes);
196214
}
197215
}
198216
if(m == null)
@@ -209,6 +227,10 @@ else if(methods.size() == 1)
209227
}
210228
try
211229
{
230+
System.err.println("retTYpe: " + m.getReturnType());
231+
System.err.println("ctxClass: " + contextClass);
232+
System.err.println("meth: " + m);
233+
System.err.println("boxedArgs " + boxArgs(m.getParameterTypes(), args));
212234
return prepRet(m.getReturnType(), m.invoke(target, boxArgs(m.getParameterTypes(), args)));
213235
}
214236
catch(Exception e)
@@ -690,7 +712,11 @@ else if(paramType == boolean.class)
690712
return false;
691713
}
692714

693-
static boolean isCongruent(Class[] params, Object[] args){
715+
static boolean isCongruent(Class[] params, Object[] args) {
716+
return isCongruent(params, args, null);
717+
}
718+
719+
static boolean isCongruent(Class[] params, Object[] args, Class[] argTypes){
694720
boolean ret = false;
695721
if(args == null)
696722
return params.length == 0;
@@ -699,8 +725,18 @@ static boolean isCongruent(Class[] params, Object[] args){
699725
ret = true;
700726
for(int i = 0; ret && i < params.length; i++)
701727
{
702-
Object arg = args[i];
703-
Class argType = (arg == null) ? null : arg.getClass();
728+
Class argType = null;
729+
Object arg = args[i];
730+
if (argTypes != null) {
731+
Object t = argTypes[i];
732+
if (t == null && arg != null) {
733+
argType = arg.getClass();
734+
} else {
735+
argType = argTypes[i];
736+
}
737+
} else {
738+
argType = (arg == null) ? null : arg.getClass();
739+
}
704740
Class paramType = params[i];
705741
ret = paramArgTypeMatch(paramType, argType);
706742
}

src/sci/impl/analyzer.cljc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,13 @@
596596
binding-name (if t (vary-meta binding-name
597597
assoc :tag t)
598598
binding-name)
599+
binding-meta (meta binding-name)
600+
t (when m (:tag binding-meta))
601+
binding-name (if t (vary-meta binding-name
602+
assoc :tag
603+
(or (interop/resolve-class ctx t)
604+
t))
605+
binding-name)
599606
v (analyze ctx binding-value)
600607
new-iden (gensym)
601608
cb (:closure-bindings ctx)

src/sci/impl/interop.cljc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,15 @@
4848
(meth-cache ctx target-class method arg-count #(Reflector/getMethods target-class arg-count method false) :instance-methods)]
4949
(if (and (zero? arg-count) (.isEmpty ^java.util.List methods))
5050
(invoke-instance-field obj target-class method)
51-
(do (let [args-array (object-array arg-count)]
51+
(do (let [args-array (object-array arg-count)
52+
;; TODO: not necessary when method count is 1
53+
types-array (object-array arg-count)]
5254
(areduce args idx _ret nil
53-
(aset args-array idx (sci.impl.types/eval (aget args idx) ctx bindings)))
55+
(do (aset args-array idx (sci.impl.types/eval (aget args idx) ctx bindings))
56+
(aset types-array idx (:tag (meta (aget args idx))))))
5457
;; Note: I also tried caching the method that invokeMatchingMethod looks up, but retrieving it from the cache was actually more expensive than just doing the invocation!
5558
;; See getMatchingMethod in Reflector
56-
(Reflector/invokeMatchingMethod method methods obj args-array)))))]))
59+
(Reflector/invokeMatchingMethod method methods obj target-class args-array types-array)))))]))
5760

5861
(defn get-static-field [^Class class field-name-sym]
5962
#?(:clj (Reflector/getStaticField class (str field-name-sym))

0 commit comments

Comments
 (0)