5151import com .oracle .graal .python .builtins .objects .cext .common .CExtCommonNodes .TransformExceptionToNativeNode ;
5252import com .oracle .graal .python .builtins .objects .function .PKeyword ;
5353import com .oracle .graal .python .builtins .objects .ints .PInt ;
54+ import com .oracle .graal .python .builtins .objects .type .TpSlots ;
5455import com .oracle .graal .python .builtins .objects .type .TpSlots .GetCachedTpSlotsNode ;
5556import com .oracle .graal .python .builtins .objects .type .TypeNodes .IsSameTypeNode ;
5657import com .oracle .graal .python .builtins .objects .type .slots .TpSlot ;
5758import com .oracle .graal .python .builtins .objects .type .slots .TpSlot .TpSlotManaged ;
5859import com .oracle .graal .python .builtins .objects .type .slots .TpSlotBinaryFunc .CallSlotBinaryFuncNode ;
59- import com .oracle .graal .python .builtins .objects .type .slots .TpSlotBinaryOp .BinaryOpSlot ;
6060import com .oracle .graal .python .builtins .objects .type .slots .TpSlotBinaryOp .CallSlotBinaryOpNode ;
61+ import com .oracle .graal .python .builtins .objects .type .slots .TpSlotBinaryOp .ReversibleSlot ;
6162import com .oracle .graal .python .builtins .objects .type .slots .TpSlotDescrGet .CallSlotDescrGet ;
6263import com .oracle .graal .python .builtins .objects .type .slots .TpSlotDescrSet .CallSlotDescrSet ;
6364import com .oracle .graal .python .builtins .objects .type .slots .TpSlotGetAttr .CallManagedSlotGetAttrNode ;
6465import com .oracle .graal .python .builtins .objects .type .slots .TpSlotInquiry .CallSlotNbBoolNode ;
6566import com .oracle .graal .python .builtins .objects .type .slots .TpSlotLen .CallSlotLenNode ;
6667import com .oracle .graal .python .builtins .objects .type .slots .TpSlotMpAssSubscript .CallSlotMpAssSubscriptNode ;
68+ import com .oracle .graal .python .builtins .objects .type .slots .TpSlotNbPower ;
6769import com .oracle .graal .python .builtins .objects .type .slots .TpSlotSetAttr .CallManagedSlotSetAttrNode ;
6870import com .oracle .graal .python .builtins .objects .type .slots .TpSlotSizeArgFun .CallSlotSizeArgFun ;
6971import com .oracle .graal .python .builtins .objects .type .slots .TpSlotSqAssItem .CallSlotSqAssItemNode ;
@@ -300,63 +302,63 @@ protected String getSignature() {
300302
301303 @ ExportLibrary (InteropLibrary .class )
302304 public static final class BinaryOpSlotFuncWrapper extends TpSlotWrapper {
303- private final BinaryOpSlot binaryOp ;
305+ private final ReversibleSlot binaryOp ;
304306
305- public BinaryOpSlotFuncWrapper (TpSlotManaged delegate , BinaryOpSlot binaryOp ) {
307+ public BinaryOpSlotFuncWrapper (TpSlotManaged delegate , ReversibleSlot binaryOp ) {
306308 super (delegate );
307309 this .binaryOp = binaryOp ;
308310 }
309311
310312 public static BinaryOpSlotFuncWrapper createAdd (TpSlotManaged delegate ) {
311- return new BinaryOpSlotFuncWrapper (delegate , BinaryOpSlot .NB_ADD );
313+ return new BinaryOpSlotFuncWrapper (delegate , ReversibleSlot .NB_ADD );
312314 }
313315
314316 public static BinaryOpSlotFuncWrapper createSubtract (TpSlotManaged delegate ) {
315- return new BinaryOpSlotFuncWrapper (delegate , BinaryOpSlot .NB_SUBTRACT );
317+ return new BinaryOpSlotFuncWrapper (delegate , ReversibleSlot .NB_SUBTRACT );
316318 }
317319
318320 public static BinaryOpSlotFuncWrapper createMultiply (TpSlotManaged delegate ) {
319- return new BinaryOpSlotFuncWrapper (delegate , BinaryOpSlot .NB_MULTIPLY );
321+ return new BinaryOpSlotFuncWrapper (delegate , ReversibleSlot .NB_MULTIPLY );
320322 }
321323
322324 public static BinaryOpSlotFuncWrapper createRemainder (TpSlotManaged delegate ) {
323- return new BinaryOpSlotFuncWrapper (delegate , BinaryOpSlot .NB_REMAINDER );
325+ return new BinaryOpSlotFuncWrapper (delegate , ReversibleSlot .NB_REMAINDER );
324326 }
325327
326328 public static BinaryOpSlotFuncWrapper createLShift (TpSlotManaged delegate ) {
327- return new BinaryOpSlotFuncWrapper (delegate , BinaryOpSlot .NB_LSHIFT );
329+ return new BinaryOpSlotFuncWrapper (delegate , ReversibleSlot .NB_LSHIFT );
328330 }
329331
330332 public static BinaryOpSlotFuncWrapper createRShift (TpSlotManaged delegate ) {
331- return new BinaryOpSlotFuncWrapper (delegate , BinaryOpSlot .NB_RSHIFT );
333+ return new BinaryOpSlotFuncWrapper (delegate , ReversibleSlot .NB_RSHIFT );
332334 }
333335
334336 public static BinaryOpSlotFuncWrapper createAnd (TpSlotManaged delegate ) {
335- return new BinaryOpSlotFuncWrapper (delegate , BinaryOpSlot .NB_AND );
337+ return new BinaryOpSlotFuncWrapper (delegate , ReversibleSlot .NB_AND );
336338 }
337339
338340 public static BinaryOpSlotFuncWrapper createXor (TpSlotManaged delegate ) {
339- return new BinaryOpSlotFuncWrapper (delegate , BinaryOpSlot .NB_XOR );
341+ return new BinaryOpSlotFuncWrapper (delegate , ReversibleSlot .NB_XOR );
340342 }
341343
342344 public static BinaryOpSlotFuncWrapper createOr (TpSlotManaged delegate ) {
343- return new BinaryOpSlotFuncWrapper (delegate , BinaryOpSlot .NB_OR );
345+ return new BinaryOpSlotFuncWrapper (delegate , ReversibleSlot .NB_OR );
344346 }
345347
346348 public static BinaryOpSlotFuncWrapper createFloorDivide (TpSlotManaged delegate ) {
347- return new BinaryOpSlotFuncWrapper (delegate , BinaryOpSlot .NB_FLOOR_DIVIDE );
349+ return new BinaryOpSlotFuncWrapper (delegate , ReversibleSlot .NB_FLOOR_DIVIDE );
348350 }
349351
350352 public static BinaryOpSlotFuncWrapper createTrueDivide (TpSlotManaged delegate ) {
351- return new BinaryOpSlotFuncWrapper (delegate , BinaryOpSlot .NB_TRUE_DIVIDE );
353+ return new BinaryOpSlotFuncWrapper (delegate , ReversibleSlot .NB_TRUE_DIVIDE );
352354 }
353355
354356 public static BinaryOpSlotFuncWrapper createDivMod (TpSlotManaged delegate ) {
355- return new BinaryOpSlotFuncWrapper (delegate , BinaryOpSlot .NB_DIVMOD );
357+ return new BinaryOpSlotFuncWrapper (delegate , ReversibleSlot .NB_DIVMOD );
356358 }
357359
358360 public static BinaryOpSlotFuncWrapper createMatrixMultiply (TpSlotManaged delegate ) {
359- return new BinaryOpSlotFuncWrapper (delegate , BinaryOpSlot .NB_MATRIX_MULTIPLY );
361+ return new BinaryOpSlotFuncWrapper (delegate , ReversibleSlot .NB_MATRIX_MULTIPLY );
360362 }
361363
362364 @ ExportMessage
@@ -745,17 +747,17 @@ protected String getSignature() {
745747 }
746748
747749 @ ExportLibrary (InteropLibrary .class )
748- public static final class TernaryFunctionWrapper extends PyProcsWrapper {
750+ public static final class CallFunctionWrapper extends PyProcsWrapper {
749751
750- public TernaryFunctionWrapper (Object delegate ) {
752+ public CallFunctionWrapper (Object delegate ) {
751753 super (delegate );
752754 }
753755
754756 @ ExportMessage (name = "execute" )
755757 static class Execute {
756758
757759 @ Specialization (guards = "arguments.length == 3" )
758- static Object call (TernaryFunctionWrapper self , Object [] arguments ,
760+ static Object call (CallFunctionWrapper self , Object [] arguments ,
759761 @ Bind ("this" ) Node inliningTarget ,
760762 @ Cached ExecutePositionalStarargsNode posStarargsNode ,
761763 @ Cached ExpandKeywordStarargsNode expandKwargsNode ,
@@ -779,7 +781,7 @@ static Object call(TernaryFunctionWrapper self, Object[] arguments,
779781 Object result = callNode .execute (null , self .getDelegate (), pArgs , kwArgsArray );
780782 return toNativeNode .execute (result );
781783 } catch (Throwable t ) {
782- throw checkThrowableBeforeNative (t , "TernaryFunctionWrapper " , self .getDelegate ());
784+ throw checkThrowableBeforeNative (t , "CallFunctionWrapper " , self .getDelegate ());
783785 }
784786 } catch (PException e ) {
785787 transformExceptionToNativeNode .execute (inliningTarget , e );
@@ -791,7 +793,7 @@ static Object call(TernaryFunctionWrapper self, Object[] arguments,
791793 }
792794
793795 @ Specialization (guards = "arguments.length != 3" )
794- static Object error (@ SuppressWarnings ("unused" ) TernaryFunctionWrapper self , Object [] arguments ) throws ArityException {
796+ static Object error (@ SuppressWarnings ("unused" ) CallFunctionWrapper self , Object [] arguments ) throws ArityException {
795797 CompilerDirectives .transferToInterpreterAndInvalidate ();
796798 throw ArityException .create (3 , 3 , arguments .length );
797799 }
@@ -803,6 +805,62 @@ protected String getSignature() {
803805 }
804806 }
805807
808+ @ ExportLibrary (InteropLibrary .class )
809+ public static final class NbPowerWrapper extends TpSlotWrapper {
810+
811+ public NbPowerWrapper (TpSlotManaged delegate ) {
812+ super (delegate );
813+ }
814+
815+ @ Override
816+ public TpSlotWrapper cloneWith (TpSlotManaged slot ) {
817+ return new NbPowerWrapper (slot );
818+ }
819+
820+ @ ExportMessage
821+ static Object execute (NbPowerWrapper self , Object [] arguments ,
822+ @ Bind ("$node" ) Node inliningTarget ,
823+ @ Cached NativeToPythonNode toJavaNode ,
824+ @ Cached PythonToNativeNewRefNode toNativeNode ,
825+ @ Cached TransformExceptionToNativeNode transformExceptionToNativeNode ,
826+ @ Cached GetClassNode vGetClassNode ,
827+ @ Cached GetClassNode wGetClassNode ,
828+ @ Cached IsSameTypeNode isSameTypeNode ,
829+ @ Cached GetCachedTpSlotsNode wGetSlots ,
830+ @ Cached TpSlotNbPower .CallSlotNbPowerNode callSlot ,
831+ @ Cached GilNode gil ) {
832+ boolean mustRelease = gil .acquire ();
833+ CApiTiming .enter ();
834+ try {
835+ try {
836+ // convert args
837+ Object v = toJavaNode .execute (arguments [0 ]);
838+ Object w = toJavaNode .execute (arguments [1 ]);
839+ Object z = toJavaNode .execute (arguments [2 ]);
840+ Object vType = vGetClassNode .execute (inliningTarget , v );
841+ Object wType = wGetClassNode .execute (inliningTarget , w );
842+ TpSlots wSlots = wGetSlots .execute (inliningTarget , wType );
843+ boolean sameTypes = isSameTypeNode .execute (inliningTarget , vType , wType );
844+ Object result = callSlot .execute (null , inliningTarget , self .getSlot (), v , vType , w , wSlots .nb_power (), wType , z , sameTypes );
845+ return toNativeNode .execute (result );
846+ } catch (Throwable t ) {
847+ throw checkThrowableBeforeNative (t , "NbPowerWrapper" , self .getDelegate ());
848+ }
849+ } catch (PException e ) {
850+ transformExceptionToNativeNode .execute (inliningTarget , e );
851+ return PythonContext .get (gil ).getNativeNull ();
852+ } finally {
853+ CApiTiming .exit (self .timing );
854+ gil .release (mustRelease );
855+ }
856+ }
857+
858+ @ Override
859+ protected String getSignature () {
860+ return "(POINTER,POINTER,POINTER):POINTER" ;
861+ }
862+ }
863+
806864 @ ExportLibrary (InteropLibrary .class )
807865 public static final class RichcmpFunctionWrapper extends PyProcsWrapper {
808866
0 commit comments