|
89 | 89 | import com.oracle.graal.python.builtins.modules.ExternalFunctionNodes.SSizeObjArgProcRootNode;
|
90 | 90 | import com.oracle.graal.python.builtins.modules.ExternalFunctionNodes.SetAttrFuncRootNode;
|
91 | 91 | import com.oracle.graal.python.builtins.modules.PythonCextBuiltinsFactory.CheckIterNextResultNodeGen;
|
| 92 | +import com.oracle.graal.python.builtins.modules.PythonCextBuiltinsFactory.CreateFunctionNodeFactory; |
92 | 93 | import com.oracle.graal.python.builtins.modules.PythonCextBuiltinsFactory.DefaultCheckFunctionResultNodeGen;
|
93 | 94 | import com.oracle.graal.python.builtins.modules.PythonCextBuiltinsFactory.GetByteArrayNodeGen;
|
94 | 95 | import com.oracle.graal.python.builtins.objects.PNone;
|
|
118 | 119 | import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.DirectUpcallNode;
|
119 | 120 | import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.FastCallArgsToSulongNode;
|
120 | 121 | import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.FastCallWithKeywordsArgsToSulongNode;
|
| 122 | +import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.FromCharPointerNode; |
121 | 123 | import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.GetNativeNullNode;
|
122 | 124 | import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.MayRaiseNode;
|
123 | 125 | import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.ObjectUpcallNode;
|
|
250 | 252 | import com.oracle.truffle.api.RootCallTarget;
|
251 | 253 | import com.oracle.truffle.api.TruffleLanguage.ContextReference;
|
252 | 254 | import com.oracle.truffle.api.TruffleLogger;
|
| 255 | +import com.oracle.truffle.api.dsl.Bind; |
253 | 256 | import com.oracle.truffle.api.dsl.Cached;
|
254 | 257 | import com.oracle.truffle.api.dsl.Cached.Exclusive;
|
255 | 258 | import com.oracle.truffle.api.dsl.Cached.Shared;
|
@@ -475,6 +478,8 @@ Object runWithoutCWrapper(PBuiltinFunction descriptor, Object self) {
|
475 | 478 | @TypeSystemReference(PythonArithmeticTypes.class)
|
476 | 479 | abstract static class CreateFunctionNode extends PythonBuiltinNode {
|
477 | 480 |
|
| 481 | + abstract Object execute(String name, Object callable, Object wrapper, Object type); |
| 482 | + |
478 | 483 | @Specialization(guards = {"lib.isLazyPythonClass(type)", "isNoValue(wrapper)"}, limit = "3")
|
479 | 484 | static Object doPythonCallableWithoutWrapper(@SuppressWarnings("unused") String name, PythonNativeWrapper callable, @SuppressWarnings("unused") PNone wrapper,
|
480 | 485 | @SuppressWarnings("unused") Object type,
|
@@ -572,6 +577,11 @@ static boolean isNativeWrapper(Object obj) {
|
572 | 577 | static boolean isDecoratedManagedFunction(Object obj) {
|
573 | 578 | return obj instanceof PyCFunctionDecorator && CApiGuards.isNativeWrapper(((PyCFunctionDecorator) obj).getNativeFunction());
|
574 | 579 | }
|
| 580 | + |
| 581 | + public static CreateFunctionNode create() { |
| 582 | + return CreateFunctionNodeFactory.create(null); |
| 583 | + } |
| 584 | + |
575 | 585 | }
|
576 | 586 |
|
577 | 587 | @Builtin(name = "PyErr_Restore", minNumOfPositionalArgs = 3)
|
@@ -3657,7 +3667,42 @@ static long doIt(
|
3657 | 3667 | @CachedContext(PythonLanguage.class) PythonContext context) {
|
3658 | 3668 | CApiContext nativeContext = context.getCApiContext();
|
3659 | 3669 | return nativeContext.getAndIncMaxModuleNumber();
|
| 3670 | + } |
| 3671 | + } |
3660 | 3672 |
|
| 3673 | + // directly called without landing function |
| 3674 | + @Builtin(name = "PyDescr_NewClassMethod", minNumOfPositionalArgs = 3) |
| 3675 | + @GenerateNodeFactory |
| 3676 | + abstract static class PyDescrNewClassMethod extends PythonBuiltinNode { |
| 3677 | + |
| 3678 | + @Specialization(guards = "meth != null") |
| 3679 | + @SuppressWarnings("unused") |
| 3680 | + Object doPBuiltinFunction(Object typeObj, Object nameObj, Object methObj, |
| 3681 | + @Cached AsPythonObjectNode asPythonObjectNode, |
| 3682 | + @Bind("asBuiltinFunction(methObj, asPythonObjectNode)") PBuiltinFunction meth, |
| 3683 | + @Cached ToNewRefNode toNewRefNode) { |
| 3684 | + return toNewRefNode.execute(factory().createClassmethodFromCallableObj(meth)); |
| 3685 | + } |
| 3686 | + |
| 3687 | + @Specialization(guards = "meth != null") |
| 3688 | + Object doNativeCallable(Object type, Object nameObj, Object methObj, |
| 3689 | + @SuppressWarnings("unused") @Cached AsPythonObjectNode asPythonObjectNode, |
| 3690 | + @Bind("asBuiltinFunction(methObj, asPythonObjectNode)") @SuppressWarnings("unused") PBuiltinFunction meth, |
| 3691 | + @Cached FromCharPointerNode fromCharPointerNode, |
| 3692 | + @Cached CastToJavaStringNode castToJavaStringNode, |
| 3693 | + @Cached CreateFunctionNode createFunctionNode, |
| 3694 | + @Cached ToNewRefNode toNewRefNode) { |
| 3695 | + String name = castToJavaStringNode.execute(fromCharPointerNode.execute(nameObj)); |
| 3696 | + Object callable = createFunctionNode.execute(name, methObj, PNone.NONE, type); |
| 3697 | + return toNewRefNode.execute(factory().createClassmethodFromCallableObj(callable)); |
| 3698 | + } |
| 3699 | + |
| 3700 | + static PBuiltinFunction asBuiltinFunction(Object methObj, AsPythonObjectNode asPythonObjectNode) { |
| 3701 | + Object object = asPythonObjectNode.execute(methObj); |
| 3702 | + if (object instanceof PBuiltinFunction) { |
| 3703 | + return (PBuiltinFunction) object; |
| 3704 | + } |
| 3705 | + return null; |
3661 | 3706 | }
|
3662 | 3707 | }
|
3663 | 3708 | }
|
0 commit comments