closure as callable method
This commit is contained in:
@@ -211,4 +211,10 @@ public class ClosureCodegen {
|
||||
signatureWriter.visitClassType(rawRetType.getInternalName());
|
||||
signatureWriter.visitEnd();
|
||||
}
|
||||
|
||||
public static CallableMethod asCallableMethod(FunctionDescriptor fd) {
|
||||
Method descriptor = erasedInvokeSignature(fd);
|
||||
String owner = getInternalClassName(fd);
|
||||
return new CallableMethod(owner, descriptor, Opcodes.INVOKEVIRTUAL, Arrays.asList(descriptor.getArgumentTypes()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -780,6 +780,8 @@ public class ExpressionCodegen extends JetVisitor {
|
||||
if (declarationPsiElement == null) {
|
||||
throw new UnsupportedOperationException("couldn't find declaration for " + funDescriptor);
|
||||
}
|
||||
|
||||
|
||||
Method methodDescriptor;
|
||||
if (declarationPsiElement instanceof PsiMethod) {
|
||||
final PsiMethod psiMethod = (PsiMethod) declarationPsiElement;
|
||||
@@ -814,15 +816,14 @@ public class ExpressionCodegen extends JetVisitor {
|
||||
gen(callee, Type.getObjectType(ClosureCodegen.getInternalClassName(fd)));
|
||||
|
||||
boolean isExtensionFunction = fd.getReceiverType() != null;
|
||||
int paramCount = fd.getValueParameters().size();
|
||||
if (isExtensionFunction) {
|
||||
ensureReceiverOnStack(expression, null);
|
||||
paramCount++;
|
||||
}
|
||||
|
||||
methodDescriptor = ClosureCodegen.erasedInvokeSignature(fd);
|
||||
pushMethodArguments(expression, methodDescriptor);
|
||||
v.invokevirtual(ClosureCodegen.getInternalClassName(fd), "invoke", methodDescriptor.getDescriptor());
|
||||
CallableMethod callableMethod = ClosureCodegen.asCallableMethod(fd);
|
||||
pushMethodArguments(expression, callableMethod.getValueParameterTypes());
|
||||
callableMethod.invoke(v);
|
||||
methodDescriptor = callableMethod.getSignature();
|
||||
}
|
||||
|
||||
if (methodDescriptor.getReturnType() != Type.VOID_TYPE) {
|
||||
|
||||
Reference in New Issue
Block a user