@@ -218,24 +218,22 @@ private static ReadArgumentNode[] createArgumentsList(Builtin builtin, boolean n
218
218
assert parameterNames .length == 0 : "either give all parameter names explicitly, or define the max number: " + builtin .name ();
219
219
}
220
220
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 ;
225
223
226
224
// read those arguments that only come positionally
227
225
for (int i = 0 ; i < maxNumPosArgs ; i ++) {
228
- args .add (ReadIndexedArgumentNode .create (i ));
226
+ args .add (ReadIndexedArgumentNode .create (i + skip ));
229
227
}
230
228
231
229
// read splat args if any
232
230
if (builtin .takesVarArgs ()) {
233
- args .add (ReadVarArgsNode .create (args .size (), true ));
231
+ args .add (ReadVarArgsNode .create (args .size () + skip , true ));
234
232
}
235
233
236
234
int keywordCount = builtin .keywordOnlyNames ().length ;
237
235
for (int i = 0 ; i < keywordCount ; i ++) {
238
- args .add (ReadIndexedArgumentNode .create (i + maxNumPosArgs ));
236
+ args .add (ReadIndexedArgumentNode .create (i + maxNumPosArgs + skip ));
239
237
}
240
238
241
239
if (builtin .takesVarKeywordArgs ()) {
@@ -267,57 +265,25 @@ public Object execute(VirtualFrame frame) {
267
265
BuiltinCallNode newBody ;
268
266
ReadArgumentNode [] argumentsList = createArgumentsList (builtin , declaresExplicitSelf );
269
267
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 ));
277
269
} else {
278
270
PythonBuiltinBaseNode node = factory .createNode ();
279
271
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 ]);
287
274
} 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 ]);
295
277
} 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 ]);
303
280
} 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 ]);
311
283
} 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 ]);
321
287
} else {
322
288
throw new RuntimeException ("unexpected builtin node type: " + node .getClass ());
323
289
}
0 commit comments