|
74 | 74 | import com.oracle.graal.python.builtins.objects.cext.CExtNodesFactory.ToJavaNodeFactory.ToJavaCachedNodeGen;
|
75 | 75 | import com.oracle.graal.python.builtins.objects.cext.DynamicObjectNativeWrapper.PrimitiveNativeWrapper;
|
76 | 76 | import com.oracle.graal.python.builtins.objects.cext.DynamicObjectNativeWrapper.PythonObjectNativeWrapper;
|
| 77 | +import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes; |
77 | 78 | import com.oracle.graal.python.builtins.objects.floats.PFloat;
|
78 | 79 | import com.oracle.graal.python.builtins.objects.function.PFunction;
|
79 | 80 | import com.oracle.graal.python.builtins.objects.function.PKeyword;
|
|
83 | 84 | import com.oracle.graal.python.builtins.objects.type.PythonAbstractClass;
|
84 | 85 | import com.oracle.graal.python.builtins.objects.type.PythonManagedClass;
|
85 | 86 | import com.oracle.graal.python.builtins.objects.type.TypeNodes;
|
| 87 | +import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetMroStorageNode; |
86 | 88 | import com.oracle.graal.python.builtins.objects.type.TypeNodes.GetNameNode;
|
87 | 89 | import com.oracle.graal.python.nodes.PGuards;
|
88 | 90 | import com.oracle.graal.python.nodes.PNodeWithContext;
|
|
117 | 119 | import com.oracle.graal.python.runtime.exception.PException;
|
118 | 120 | import com.oracle.graal.python.runtime.exception.PythonErrorType;
|
119 | 121 | import com.oracle.graal.python.runtime.object.PythonObjectFactory;
|
| 122 | +import com.oracle.graal.python.runtime.sequence.storage.MroSequenceStorage; |
120 | 123 | import com.oracle.truffle.api.Assumption;
|
121 | 124 | import com.oracle.truffle.api.CompilerDirectives;
|
122 | 125 | import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
|
@@ -1893,4 +1896,51 @@ boolean doSingleContext(PythonAbstractNativeObject left, PythonAbstractNativeObj
|
1893 | 1896 | return pointerCompareNode.execute(SpecialMethodNames.__EQ__, left, right);
|
1894 | 1897 | }
|
1895 | 1898 | }
|
| 1899 | + |
| 1900 | + /** |
| 1901 | + * Use this node to lookup a native type member like {@code tp_alloc}.<br> |
| 1902 | + * <p> |
| 1903 | + * This node basically implements the native member inheritance that is done by |
| 1904 | + * {@code inherit_special} or other code in {@code PyType_Ready}. |
| 1905 | + * </p> |
| 1906 | + * <p> |
| 1907 | + * Since it may be that a managed types needs to emulate such members but there is no |
| 1908 | + * corresponding Python attribute (e.g. {@code tp_alloc}), such members are stored as hidden |
| 1909 | + * keys on the managed type. However, the MRO may contain native types and in this case, we need |
| 1910 | + * to access the native member. |
| 1911 | + * </p> |
| 1912 | + */ |
| 1913 | + @GenerateUncached |
| 1914 | + public abstract static class LookupNativeMemberInMRONode extends Node { |
| 1915 | + |
| 1916 | + public abstract Object execute(PythonAbstractClass cls, String nativeMemberName, Object managedMemberName); |
| 1917 | + |
| 1918 | + @Specialization |
| 1919 | + Object doSingleContext(PythonAbstractClass cls, String nativeMemberName, Object managedMemberName, |
| 1920 | + @Cached GetMroStorageNode getMroNode, |
| 1921 | + @Cached SequenceStorageNodes.LenNode lenNode, |
| 1922 | + @Cached SequenceStorageNodes.GetItemDynamicNode getItemNode, |
| 1923 | + @Cached("createForceType()") ReadAttributeFromObjectNode readAttrNode, |
| 1924 | + @Cached GetTypeMemberNode getTypeMemberNode) { |
| 1925 | + |
| 1926 | + MroSequenceStorage mroStorage = getMroNode.execute(cls); |
| 1927 | + int n = lenNode.execute(mroStorage); |
| 1928 | + |
| 1929 | + for (int i = 0; i < n; i++) { |
| 1930 | + PythonAbstractClass mroCls = (PythonAbstractClass) getItemNode.execute(mroStorage, i); |
| 1931 | + Object result = PNone.NO_VALUE; |
| 1932 | + if (PGuards.isManagedClass(mroCls)) { |
| 1933 | + result = readAttrNode.execute(mroCls, managedMemberName); |
| 1934 | + } else { |
| 1935 | + assert PGuards.isNativeClass(mroCls) : "invalid class inheritance structure; expected native class"; |
| 1936 | + result = getTypeMemberNode.execute(mroCls, nativeMemberName); |
| 1937 | + } |
| 1938 | + if (result != PNone.NO_VALUE) { |
| 1939 | + return result; |
| 1940 | + } |
| 1941 | + } |
| 1942 | + |
| 1943 | + return PNone.NO_VALUE; |
| 1944 | + } |
| 1945 | + } |
1896 | 1946 | }
|
0 commit comments