50
50
import com .oracle .graal .python .builtins .objects .cext .capi .transitions .CApiTransitions .PythonToNativeNewRefNode ;
51
51
import com .oracle .graal .python .builtins .objects .cext .common .CExtContext ;
52
52
import com .oracle .graal .python .builtins .objects .function .BuiltinMethodDescriptor ;
53
+ import com .oracle .graal .python .builtins .objects .function .BuiltinMethodDescriptor .BinaryBuiltinDescriptor ;
54
+ import com .oracle .graal .python .builtins .objects .function .BuiltinMethodDescriptor .UnaryBuiltinDescriptor ;
53
55
import com .oracle .graal .python .builtins .objects .function .PArguments ;
54
56
import com .oracle .graal .python .builtins .objects .function .PBuiltinFunction ;
55
57
import com .oracle .graal .python .builtins .objects .function .PKeyword ;
56
58
import com .oracle .graal .python .builtins .objects .function .Signature ;
57
59
import com .oracle .graal .python .nodes .argument .CreateArgumentsNode .CreateAndCheckArgumentsNode ;
58
60
import com .oracle .graal .python .nodes .argument .keywords .ExpandKeywordStarargsNode ;
59
61
import com .oracle .graal .python .nodes .argument .positional .ExecutePositionalStarargsNode ;
60
- import com .oracle .graal .python .nodes .call .CallNode ;
61
62
import com .oracle .graal .python .nodes .call .CallTargetInvokeNode ;
62
63
import com .oracle .graal .python .nodes .call .GenericInvokeNode ;
63
64
import com .oracle .graal .python .nodes .call .special .CallBinaryMethodNode ;
@@ -107,7 +108,6 @@ public abstract class PyCFunctionWrapper implements TruffleObject {
107
108
protected final TruffleString callTargetName ;
108
109
protected final BuiltinMethodDescriptor builtinMethodDescriptor ;
109
110
protected final CApiTiming timing ;
110
- private final boolean skipSelf ;
111
111
private long pointer ;
112
112
113
113
protected PyCFunctionWrapper (RootCallTarget callTarget , Signature signature ) {
@@ -119,7 +119,6 @@ protected PyCFunctionWrapper(RootCallTarget callTarget, Signature signature) {
119
119
this .callTargetName = PythonUtils .toTruffleStringUncached (ctName );
120
120
this .builtinMethodDescriptor = null ;
121
121
this .timing = CApiTiming .create (false , ctName );
122
- this .skipSelf = false ;
123
122
}
124
123
125
124
protected PyCFunctionWrapper (BuiltinMethodDescriptor builtinMethodDescriptor ) {
@@ -129,7 +128,6 @@ protected PyCFunctionWrapper(BuiltinMethodDescriptor builtinMethodDescriptor) {
129
128
this .callTargetName = null ;
130
129
this .builtinMethodDescriptor = builtinMethodDescriptor ;
131
130
this .timing = CApiTiming .create (false , builtinMethodDescriptor .getName ());
132
- this .skipSelf = builtinMethodDescriptor .getEnclosingType () == null && !builtinMethodDescriptor .getBuiltinAnnotation ().declaresExplicitSelf ();
133
131
}
134
132
135
133
public final RootCallTarget getCallTarget () {
@@ -144,10 +142,6 @@ public final Object getDelegate() {
144
142
return callTarget ;
145
143
}
146
144
147
- protected final boolean skipFirstArg () {
148
- return skipSelf ;
149
- }
150
-
151
145
abstract String getSignature ();
152
146
153
147
@ ExportMessage
@@ -212,12 +206,13 @@ public static PyCFunctionWrapper createFromBuiltinFunction(CApiContext cApiConte
212
206
* 'builtin_function_or_method' or 'method_descriptor' in which case we need to have the
213
207
* call target available.
214
208
*/
215
- if (CExtContext .isMethNoArgs (flags ) || CExtContext .isMethO (flags )) {
209
+ if (CExtContext .isMethNoArgs (flags ) && builtinMethodDescriptor instanceof UnaryBuiltinDescriptor ||
210
+ CExtContext .isMethO (flags ) && builtinMethodDescriptor instanceof BinaryBuiltinDescriptor ) {
216
211
cApiContext .getContext ().getLanguage ().registerBuiltinDescriptorCallTarget (builtinMethodDescriptor , builtinFunction .getCallTarget ());
217
212
}
218
- if (CExtContext .isMethNoArgs (flags )) {
213
+ if (CExtContext .isMethNoArgs (flags ) && builtinMethodDescriptor instanceof UnaryBuiltinDescriptor ) {
219
214
return cApiContext .getOrCreatePyCFunctionWrapper (builtinMethodDescriptor , PyCFunctionUnaryWrapper ::new );
220
- } else if (CExtContext .isMethO (flags )) {
215
+ } else if (CExtContext .isMethO (flags ) && builtinMethodDescriptor instanceof BinaryBuiltinDescriptor ) {
221
216
return cApiContext .getOrCreatePyCFunctionWrapper (builtinMethodDescriptor , PyCFunctionBinaryWrapper ::new );
222
217
}
223
218
}
@@ -282,7 +277,6 @@ private PyCFunctionUnaryWrapper(BuiltinMethodDescriptor builtinMethodDescriptor)
282
277
Object execute (Object [] arguments ,
283
278
@ Bind ("$node" ) Node inliningTarget ,
284
279
@ Cached PythonToNativeNewRefNode toNativeNode ,
285
- @ Cached CallNode callNode ,
286
280
@ Cached CallUnaryMethodNode callUnaryNode ,
287
281
@ Cached CreateAndCheckArgumentsNode createArgsNode ,
288
282
@ Cached CallTargetDispatchNode invokeNode ,
@@ -305,11 +299,7 @@ Object execute(Object[] arguments,
305
299
Object jArg0 = toJavaNode .execute (arguments [0 ]);
306
300
if (builtinMethodDescriptor != null ) {
307
301
assert callTarget == null ;
308
- if (skipFirstArg ()) {
309
- result = callNode .execute (builtinMethodDescriptor );
310
- } else {
311
- result = callUnaryNode .executeObject (null , builtinMethodDescriptor , jArg0 );
312
- }
302
+ result = callUnaryNode .executeObject (null , builtinMethodDescriptor , jArg0 );
313
303
} else {
314
304
assert callTarget != null ;
315
305
assert callTargetName != null ;
@@ -356,7 +346,6 @@ private PyCFunctionBinaryWrapper(BuiltinMethodDescriptor builtinMethodDescriptor
356
346
Object execute (Object [] arguments ,
357
347
@ Bind ("$node" ) Node inliningTarget ,
358
348
@ Cached PythonToNativeNewRefNode toNativeNode ,
359
- @ Cached CallUnaryMethodNode callUnaryMethodNode ,
360
349
@ Cached CallBinaryMethodNode callBinaryMethodNode ,
361
350
@ Cached CallTargetDispatchNode invokeNode ,
362
351
@ Cached CreateAndCheckArgumentsNode createArgsNode ,
@@ -376,11 +365,8 @@ Object execute(Object[] arguments,
376
365
Object jArg1 = toJavaNode .execute (arguments [1 ]);
377
366
if (builtinMethodDescriptor != null ) {
378
367
assert callTarget == null ;
379
- if (skipFirstArg ()) {
380
- result = callUnaryMethodNode .executeObject (builtinMethodDescriptor , jArg1 );
381
- } else {
382
- result = callBinaryMethodNode .executeObject (builtinMethodDescriptor , jArg0 , jArg1 );
383
- }
368
+ assert builtinMethodDescriptor instanceof BinaryBuiltinDescriptor ;
369
+ result = callBinaryMethodNode .executeObject (builtinMethodDescriptor , jArg0 , jArg1 );
384
370
} else {
385
371
assert callTarget != null ;
386
372
assert callTargetName != null ;
0 commit comments