|
42 | 42 |
|
43 | 43 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.IndexError;
|
44 | 44 | import static com.oracle.graal.python.builtins.PythonBuiltinClassType.SystemError;
|
| 45 | +import static com.oracle.graal.python.nodes.SpecialMethodNames.__GETITEM__; |
45 | 46 | import static com.oracle.graal.python.runtime.exception.PythonErrorType.OverflowError;
|
46 | 47 | import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
|
47 | 48 |
|
|
108 | 109 | import com.oracle.graal.python.builtins.objects.function.PythonCallable;
|
109 | 110 | import com.oracle.graal.python.builtins.objects.ints.PInt;
|
110 | 111 | import com.oracle.graal.python.builtins.objects.iterator.PSequenceIterator;
|
| 112 | +import com.oracle.graal.python.builtins.objects.list.PList; |
111 | 113 | import com.oracle.graal.python.builtins.objects.module.PythonModule;
|
112 | 114 | import com.oracle.graal.python.builtins.objects.object.PythonObject;
|
113 | 115 | import com.oracle.graal.python.builtins.objects.slice.PSlice;
|
|
124 | 126 | import com.oracle.graal.python.nodes.argument.ReadIndexedArgumentNode;
|
125 | 127 | import com.oracle.graal.python.nodes.argument.ReadVarArgsNode;
|
126 | 128 | import com.oracle.graal.python.nodes.argument.ReadVarKeywordsNode;
|
| 129 | +import com.oracle.graal.python.nodes.attributes.HasInheritedAttributeNode; |
127 | 130 | import com.oracle.graal.python.nodes.attributes.ReadAttributeFromObjectNode;
|
128 | 131 | import com.oracle.graal.python.nodes.attributes.WriteAttributeToObjectNode;
|
129 | 132 | import com.oracle.graal.python.nodes.call.PythonCallNode;
|
@@ -2084,4 +2087,32 @@ Object doPTuple(Object tuple, @SuppressWarnings("unused") Object key) {
|
2084 | 2087 | }
|
2085 | 2088 | }
|
2086 | 2089 |
|
| 2090 | + @Builtin(name = "PySequence_Check", fixedNumOfPositionalArgs = 1) |
| 2091 | + @GenerateNodeFactory |
| 2092 | + abstract static class PySequence_Check extends PythonUnaryBuiltinNode { |
| 2093 | + @Child private HasInheritedAttributeNode hasInheritedAttrNode; |
| 2094 | + |
| 2095 | + @Specialization(guards = "isPSequence(object)") |
| 2096 | + int doSequence(@SuppressWarnings("unused") Object object) { |
| 2097 | + return 1; |
| 2098 | + } |
| 2099 | + |
| 2100 | + @Specialization |
| 2101 | + int doDict(@SuppressWarnings("unused") PDict object) { |
| 2102 | + return 0; |
| 2103 | + } |
| 2104 | + |
| 2105 | + @Fallback |
| 2106 | + int doGeneric(Object object) { |
| 2107 | + if (hasInheritedAttrNode == null) { |
| 2108 | + CompilerDirectives.transferToInterpreterAndInvalidate(); |
| 2109 | + hasInheritedAttrNode = insert(HasInheritedAttributeNode.create(__GETITEM__)); |
| 2110 | + } |
| 2111 | + return hasInheritedAttrNode.execute(object) ? 1 : 0; |
| 2112 | + } |
| 2113 | + |
| 2114 | + protected static boolean isPSequence(Object object) { |
| 2115 | + return object instanceof PList || object instanceof PTuple; |
| 2116 | + } |
| 2117 | + } |
2087 | 2118 | }
|
0 commit comments