Skip to content

Commit 2188681

Browse files
committed
fix specializations for method.__call__, when the function is not a primitive function, we need to prepend self and call that
1 parent 6f5ae81 commit 2188681

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/method/AbstractMethodBuiltins.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import com.oracle.graal.python.builtins.objects.function.PKeyword;
4646
import com.oracle.graal.python.builtins.objects.module.PythonModule;
4747
import com.oracle.graal.python.builtins.objects.object.PythonObject;
48+
import com.oracle.graal.python.nodes.argument.positional.PositionalArgumentsNode;
4849
import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
4950
import com.oracle.graal.python.nodes.attributes.WriteAttributeToObjectNode;
5051
import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode;
@@ -73,16 +74,26 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
7374
public abstract static class CallNode extends PythonVarargsBuiltinNode {
7475
@Child private com.oracle.graal.python.nodes.call.CallNode callNode = com.oracle.graal.python.nodes.call.CallNode.create();
7576

76-
@Specialization
77+
@Specialization(guards = "isFunction(self.getFunction())")
7778
protected Object doIt(VirtualFrame frame, PMethod self, Object[] arguments, PKeyword[] keywords) {
7879
return callNode.execute(frame, self, arguments, keywords);
7980
}
8081

81-
@Specialization
82+
@Specialization(guards = "isFunction(self.getFunction())")
8283
protected Object doIt(VirtualFrame frame, PBuiltinMethod self, Object[] arguments, PKeyword[] keywords) {
8384
return callNode.execute(frame, self, arguments, keywords);
8485
}
8586

87+
@Specialization(guards = "!isFunction(self.getFunction())")
88+
protected Object doItNonFunction(VirtualFrame frame, PMethod self, Object[] arguments, PKeyword[] keywords) {
89+
return callNode.execute(frame, self.getFunction(), PositionalArgumentsNode.prependArgument(self.getSelf(), arguments), keywords);
90+
}
91+
92+
@Specialization(guards = "!isFunction(self.getFunction())")
93+
protected Object doItNonFunction(VirtualFrame frame, PBuiltinMethod self, Object[] arguments, PKeyword[] keywords) {
94+
return callNode.execute(frame, self.getFunction(), PositionalArgumentsNode.prependArgument(self.getSelf(), arguments), keywords);
95+
}
96+
8697
@Override
8798
public Object varArgExecute(VirtualFrame frame, Object[] arguments, PKeyword[] keywords) throws VarargsBuiltinDirectInvocationNotSupported {
8899
Object[] argsWithoutSelf = new Object[arguments.length - 1];

0 commit comments

Comments
 (0)