|
46 | 46 | import com.oracle.graal.python.builtins.objects.cext.ManagedMethodWrappers.MethVarargs;
|
47 | 47 | import com.oracle.graal.python.builtins.objects.cext.ManagedMethodWrappers.MethodWrapper;
|
48 | 48 | import com.oracle.graal.python.builtins.objects.function.PKeyword;
|
49 |
| -import com.oracle.graal.python.nodes.argument.ArityCheckNode; |
50 |
| -import com.oracle.graal.python.nodes.argument.CreateArgumentsNode; |
51 | 49 | import com.oracle.graal.python.nodes.argument.keywords.ExecuteKeywordStarargsNode;
|
52 | 50 | import com.oracle.graal.python.nodes.argument.positional.ExecutePositionalStarargsNode;
|
53 | 51 | import com.oracle.graal.python.nodes.argument.positional.PositionalArgumentsNode;
|
54 |
| -import com.oracle.graal.python.nodes.call.CallDispatchNode; |
| 52 | +import com.oracle.graal.python.nodes.call.CallNode; |
55 | 53 | import com.oracle.graal.python.runtime.interop.PythonMessageResolution;
|
56 | 54 | import com.oracle.truffle.api.CompilerDirectives;
|
57 | 55 | import com.oracle.truffle.api.interop.ArityException;
|
58 | 56 | import com.oracle.truffle.api.interop.MessageResolution;
|
59 | 57 | import com.oracle.truffle.api.interop.Resolve;
|
60 | 58 | import com.oracle.truffle.api.nodes.ExplodeLoop;
|
61 | 59 | import com.oracle.truffle.api.nodes.Node;
|
62 |
| -import com.oracle.truffle.api.profiles.ValueProfile; |
| 60 | +import com.oracle.truffle.api.profiles.PrimitiveValueProfile; |
63 | 61 |
|
64 | 62 | @MessageResolution(receiverType = MethodWrapper.class)
|
65 | 63 | public class ManagedMethodWrappersMR {
|
66 | 64 |
|
67 | 65 | @Resolve(message = "EXECUTE")
|
68 | 66 | abstract static class ExecuteNode extends Node {
|
69 |
| - @Child PythonMessageResolution.ExecuteNode executeNode; |
70 |
| - @Child private ToJavaNode toJavaNode; |
71 |
| - @Child private ToSulongNode toSulongNode; |
| 67 | + |
| 68 | + @Child private PythonMessageResolution.ExecuteNode executeNode; |
| 69 | + @Child private ToJavaNode toJavaNode = ToJavaNode.create(); |
| 70 | + @Child private ToSulongNode toSulongNode = ToSulongNode.create(); |
72 | 71 |
|
73 | 72 | @Child private ExecutePositionalStarargsNode posStarargsNode = ExecutePositionalStarargsNode.create();
|
74 |
| - @Child private PositionalArgumentsNode posArgsNode = PositionalArgumentsNode.create(); |
75 | 73 | @Child private ExecuteKeywordStarargsNode expandKwargsNode = ExecuteKeywordStarargsNode.create();
|
76 |
| - @Child private CallDispatchNode dispatch; |
77 |
| - @Child private CreateArgumentsNode createArgs = CreateArgumentsNode.create(); |
78 |
| - @Child private ArityCheckNode arityCheckNode = ArityCheckNode.create(); |
79 |
| - final ValueProfile classProfile = ValueProfile.createClassProfile(); |
| 74 | + @Child private CallNode dispatch; |
80 | 75 |
|
81 |
| - private CallDispatchNode getDispatchNode() { |
82 |
| - if (dispatch == null) { |
83 |
| - CompilerDirectives.transferToInterpreterAndInvalidate(); |
84 |
| - dispatch = insert(CallDispatchNode.create()); |
85 |
| - } |
86 |
| - return dispatch; |
87 |
| - } |
| 76 | + private final PrimitiveValueProfile starArgsLenProfile = PrimitiveValueProfile.createEqualityProfile(); |
88 | 77 |
|
89 |
| - @ExplodeLoop |
90 | 78 | public Object access(MethKeywords object, Object[] arguments) {
|
91 |
| - if (executeNode == null) { |
92 |
| - CompilerDirectives.transferToInterpreterAndInvalidate(); |
93 |
| - executeNode = insert(new PythonMessageResolution.ExecuteNode()); |
94 |
| - } |
95 | 79 | if (arguments.length != 3) {
|
96 | 80 | throw ArityException.raise(3, arguments.length);
|
97 | 81 | }
|
98 | 82 |
|
99 | 83 | // convert args
|
100 |
| - Object[] converted = new Object[arguments.length]; |
101 |
| - for (int i = 0; i < arguments.length; i++) { |
102 |
| - converted[i] = getToJavaNode().execute(arguments[i]); |
103 |
| - } |
104 | 84 |
|
105 |
| - Object[] userArgs = posArgsNode.executeWithArguments(converted[0], posStarargsNode.executeWith(converted[1])); |
106 |
| - Object[] pArgs = createArgs.execute(userArgs); |
107 |
| - PKeyword[] kwargs = expandKwargsNode.executeWith(converted[2]); |
108 |
| - return getToSulongNode().execute(getDispatchNode().executeCall(object.getDelegate(), pArgs, kwargs)); |
| 85 | + Object receiver = toJavaNode.execute(arguments[0]); |
| 86 | + Object starArgs = toJavaNode.execute(arguments[1]); |
| 87 | + Object kwArgs = toJavaNode.execute(arguments[2]); |
| 88 | + |
| 89 | + Object[] starArgsArray = posStarargsNode.executeWith(starArgs); |
| 90 | + int starArgsLen = starArgsLenProfile.profile(starArgsArray.length); |
| 91 | + Object[] pArgs = PositionalArgumentsNode.prependArgument(receiver, starArgsArray, starArgsLen); |
| 92 | + PKeyword[] kwArgsArray = expandKwargsNode.executeWith(kwArgs); |
| 93 | + |
| 94 | + // execute |
| 95 | + |
| 96 | + if (dispatch == null) { |
| 97 | + CompilerDirectives.transferToInterpreterAndInvalidate(); |
| 98 | + dispatch = insert(CallNode.create()); |
| 99 | + } |
| 100 | + return toSulongNode.execute(dispatch.execute(object.getDelegate(), pArgs, kwArgsArray)); |
109 | 101 | }
|
110 | 102 |
|
111 | 103 | @ExplodeLoop
|
112 | 104 | public Object access(MethVarargs object, Object[] arguments) {
|
113 |
| - if (executeNode == null) { |
114 |
| - CompilerDirectives.transferToInterpreterAndInvalidate(); |
115 |
| - executeNode = insert(new PythonMessageResolution.ExecuteNode()); |
116 |
| - } |
117 | 105 | if (arguments.length != 1) {
|
118 | 106 | throw ArityException.raise(1, arguments.length);
|
119 | 107 | }
|
120 | 108 |
|
121 | 109 | // convert args
|
122 |
| - return getToSulongNode().execute(executeNode.execute(object.getDelegate(), new Object[]{getToJavaNode().execute(arguments[0])})); |
123 |
| - } |
124 | 110 |
|
125 |
| - private ToJavaNode getToJavaNode() { |
126 |
| - if (toJavaNode == null) { |
127 |
| - CompilerDirectives.transferToInterpreterAndInvalidate(); |
128 |
| - toJavaNode = insert(ToJavaNode.create()); |
129 |
| - } |
130 |
| - return toJavaNode; |
131 |
| - } |
| 111 | + Object varArgs = toJavaNode.execute(arguments[0]); |
132 | 112 |
|
133 |
| - private ToSulongNode getToSulongNode() { |
134 |
| - if (toSulongNode == null) { |
| 113 | + // execute |
| 114 | + |
| 115 | + if (executeNode == null) { |
135 | 116 | CompilerDirectives.transferToInterpreterAndInvalidate();
|
136 |
| - toSulongNode = insert(ToSulongNode.create()); |
| 117 | + executeNode = insert(new PythonMessageResolution.ExecuteNode()); |
137 | 118 | }
|
138 |
| - return toSulongNode; |
| 119 | + return toSulongNode.execute(executeNode.execute(object.getDelegate(), new Object[]{varArgs})); |
139 | 120 | }
|
140 | 121 | }
|
141 | 122 | }
|
0 commit comments