Skip to content

Commit 62d88a1

Browse files
committed
simplify BuiltinFunctionRootNode
1 parent 99a9bdf commit 62d88a1

File tree

1 file changed

+17
-51
lines changed

1 file changed

+17
-51
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/function/BuiltinFunctionRootNode.java

Lines changed: 17 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -218,24 +218,22 @@ private static ReadArgumentNode[] createArgumentsList(Builtin builtin, boolean n
218218
assert parameterNames.length == 0 : "either give all parameter names explicitly, or define the max number: " + builtin.name();
219219
}
220220

221-
if (!needsExplicitSelf) {
222-
// if we don't declare the explicit self, we just read (and ignore) it
223-
maxNumPosArgs++;
224-
}
221+
// if we don't declare the explicit self, we just ignore it
222+
int skip = needsExplicitSelf ? 0 : 1;
225223

226224
// read those arguments that only come positionally
227225
for (int i = 0; i < maxNumPosArgs; i++) {
228-
args.add(ReadIndexedArgumentNode.create(i));
226+
args.add(ReadIndexedArgumentNode.create(i + skip));
229227
}
230228

231229
// read splat args if any
232230
if (builtin.takesVarArgs()) {
233-
args.add(ReadVarArgsNode.create(args.size(), true));
231+
args.add(ReadVarArgsNode.create(args.size() + skip, true));
234232
}
235233

236234
int keywordCount = builtin.keywordOnlyNames().length;
237235
for (int i = 0; i < keywordCount; i++) {
238-
args.add(ReadIndexedArgumentNode.create(i + maxNumPosArgs));
236+
args.add(ReadIndexedArgumentNode.create(i + maxNumPosArgs + skip));
239237
}
240238

241239
if (builtin.takesVarKeywordArgs()) {
@@ -267,57 +265,25 @@ public Object execute(VirtualFrame frame) {
267265
BuiltinCallNode newBody;
268266
ReadArgumentNode[] argumentsList = createArgumentsList(builtin, declaresExplicitSelf);
269267
if (PythonBuiltinNode.class.isAssignableFrom(factory.getNodeClass())) {
270-
if (!declaresExplicitSelf) {
271-
ReadArgumentNode[] argumentsListWithoutSelf = new ReadArgumentNode[argumentsList.length - 1];
272-
PythonUtils.arraycopy(argumentsList, 1, argumentsListWithoutSelf, 0, argumentsListWithoutSelf.length);
273-
newBody = new BuiltinAnyCallNode((PythonBuiltinNode) factory.createNode((Object) argumentsListWithoutSelf));
274-
} else {
275-
newBody = new BuiltinAnyCallNode((PythonBuiltinNode) factory.createNode((Object) argumentsList));
276-
}
268+
newBody = new BuiltinAnyCallNode((PythonBuiltinNode) factory.createNode((Object) argumentsList));
277269
} else {
278270
PythonBuiltinBaseNode node = factory.createNode();
279271
if (node instanceof PythonUnaryBuiltinNode) {
280-
if (!declaresExplicitSelf) {
281-
assert argumentsList.length == 2 : "mismatch in number of arguments for " + node.getClass().getName();
282-
newBody = new BuiltinUnaryCallNode((PythonUnaryBuiltinNode) node, argumentsList[1]);
283-
} else {
284-
assert argumentsList.length == 1 : "mismatch in number of arguments for " + node.getClass().getName();
285-
newBody = new BuiltinUnaryCallNode((PythonUnaryBuiltinNode) node, argumentsList[0]);
286-
}
272+
assert argumentsList.length == 1 : "mismatch in number of arguments for " + node.getClass().getName();
273+
newBody = new BuiltinUnaryCallNode((PythonUnaryBuiltinNode) node, argumentsList[0]);
287274
} else if (node instanceof PythonBinaryBuiltinNode) {
288-
if (!declaresExplicitSelf) {
289-
assert argumentsList.length == 3 : "mismatch in number of arguments for " + node.getClass().getName();
290-
newBody = new BuiltinBinaryCallNode((PythonBinaryBuiltinNode) node, argumentsList[1], argumentsList[2]);
291-
} else {
292-
assert argumentsList.length == 2 : "mismatch in number of arguments for " + node.getClass().getName();
293-
newBody = new BuiltinBinaryCallNode((PythonBinaryBuiltinNode) node, argumentsList[0], argumentsList[1]);
294-
}
275+
assert argumentsList.length == 2 : "mismatch in number of arguments for " + node.getClass().getName();
276+
newBody = new BuiltinBinaryCallNode((PythonBinaryBuiltinNode) node, argumentsList[0], argumentsList[1]);
295277
} else if (node instanceof PythonTernaryBuiltinNode) {
296-
if (!declaresExplicitSelf) {
297-
assert argumentsList.length == 4 : "mismatch in number of arguments for " + node.getClass().getName();
298-
newBody = new BuiltinTernaryCallNode((PythonTernaryBuiltinNode) node, argumentsList[1], argumentsList[2], argumentsList[3]);
299-
} else {
300-
assert argumentsList.length == 3 : "mismatch in number of arguments for " + node.getClass().getName();
301-
newBody = new BuiltinTernaryCallNode((PythonTernaryBuiltinNode) node, argumentsList[0], argumentsList[1], argumentsList[2]);
302-
}
278+
assert argumentsList.length == 3 : "mismatch in number of arguments for " + node.getClass().getName();
279+
newBody = new BuiltinTernaryCallNode((PythonTernaryBuiltinNode) node, argumentsList[0], argumentsList[1], argumentsList[2]);
303280
} else if (node instanceof PythonQuaternaryBuiltinNode) {
304-
if (!declaresExplicitSelf) {
305-
assert argumentsList.length == 5 : "mismatch in number of arguments for " + node.getClass().getName();
306-
newBody = new BuiltinQuaternaryCallNode((PythonQuaternaryBuiltinNode) node, argumentsList[1], argumentsList[2], argumentsList[3], argumentsList[4]);
307-
} else {
308-
assert argumentsList.length == 4 : "mismatch in number of arguments for " + node.getClass().getName();
309-
newBody = new BuiltinQuaternaryCallNode((PythonQuaternaryBuiltinNode) node, argumentsList[0], argumentsList[1], argumentsList[2], argumentsList[3]);
310-
}
281+
assert argumentsList.length == 4 : "mismatch in number of arguments for " + node.getClass().getName();
282+
newBody = new BuiltinQuaternaryCallNode((PythonQuaternaryBuiltinNode) node, argumentsList[0], argumentsList[1], argumentsList[2], argumentsList[3]);
311283
} else if (node instanceof PythonVarargsBuiltinNode) {
312-
if (!declaresExplicitSelf) {
313-
assert argumentsList.length == 4 : "mismatch in number of arguments for " + node.getClass().getName();
314-
assert argumentsList[0] != null && argumentsList[1] != null && argumentsList[2] != null && argumentsList[3] != null;
315-
newBody = new BuiltinVarArgsCallNode((PythonVarargsBuiltinNode) node, argumentsList[1], argumentsList[2], argumentsList[3]);
316-
} else {
317-
assert argumentsList.length == 3 : "mismatch in number of arguments for " + node.getClass().getName();
318-
assert argumentsList[0] != null && argumentsList[1] != null && argumentsList[2] != null;
319-
newBody = new BuiltinVarArgsCallNode((PythonVarargsBuiltinNode) node, argumentsList[0], argumentsList[1], argumentsList[2]);
320-
}
284+
assert argumentsList.length == 3 : "mismatch in number of arguments for " + node.getClass().getName();
285+
assert argumentsList[0] != null && argumentsList[1] != null && argumentsList[2] != null;
286+
newBody = new BuiltinVarArgsCallNode((PythonVarargsBuiltinNode) node, argumentsList[0], argumentsList[1], argumentsList[2]);
321287
} else {
322288
throw new RuntimeException("unexpected builtin node type: " + node.getClass());
323289
}

0 commit comments

Comments
 (0)