|
78 | 78 | import com.oracle.graal.python.builtins.objects.iterator.PSequenceIterator;
|
79 | 79 | import com.oracle.graal.python.builtins.objects.slice.PSlice;
|
80 | 80 | import com.oracle.graal.python.builtins.objects.tuple.TupleBuiltinsClinicProviders.IndexNodeClinicProviderGen;
|
| 81 | +import com.oracle.graal.python.lib.PyIndexCheckNode; |
81 | 82 | import com.oracle.graal.python.lib.PyNumberAsSizeNode;
|
82 | 83 | import com.oracle.graal.python.lib.PyObjectHashNode;
|
83 | 84 | import com.oracle.graal.python.lib.PyObjectReprAsTruffleStringNode;
|
84 | 85 | import com.oracle.graal.python.lib.PyObjectRichCompareBool;
|
85 | 86 | import com.oracle.graal.python.lib.PyTupleSizeNode;
|
86 | 87 | import com.oracle.graal.python.nodes.ErrorMessages;
|
87 | 88 | import com.oracle.graal.python.nodes.PGuards;
|
| 89 | +import com.oracle.graal.python.nodes.PRaiseNode; |
88 | 90 | import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
|
89 | 91 | import com.oracle.graal.python.nodes.function.PythonBuiltinNode;
|
90 | 92 | import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
|
@@ -257,41 +259,48 @@ public static TruffleString repr(VirtualFrame frame, PTuple self,
|
257 | 259 | @GenerateNodeFactory
|
258 | 260 | public abstract static class GetItemNode extends PythonBinaryBuiltinNode {
|
259 | 261 |
|
260 |
| - private static final TruffleString TYPE_ERROR_MESSAGE = cat(T_TUPLE, T_SPACE, ErrorMessages.OBJ_INDEX_MUST_BE_INT_OR_SLICES); |
261 |
| - |
262 | 262 | public abstract Object execute(VirtualFrame frame, PTuple tuple, Object index);
|
263 | 263 |
|
264 | 264 | @Specialization(guards = {"index >= 0", "index < tuple.getSequenceStorage().length()"})
|
265 |
| - protected Object doInBounds(PTuple tuple, int index, |
| 265 | + static Object doInBounds(PTuple tuple, int index, |
266 | 266 | @Cached SequenceStorageNodes.GetItemScalarNode getItemNode) {
|
267 | 267 | return getItemNode.execute(tuple.getSequenceStorage(), index);
|
268 | 268 | }
|
269 | 269 |
|
270 | 270 | @InliningCutoff
|
271 |
| - @Specialization(guards = "!isPSlice(key)") |
272 |
| - Object doPTuple(VirtualFrame frame, PTuple tuple, Object key, |
| 271 | + @Specialization(guards = "indexCheck.execute(key)", limit = "1") |
| 272 | + static Object doIndex(VirtualFrame frame, PTuple tuple, Object key, |
| 273 | + @SuppressWarnings("unused") @Cached PyIndexCheckNode indexCheck, |
273 | 274 | @Cached("createGetItemNode()") SequenceStorageNodes.GetItemNode getItemNode) {
|
274 | 275 | return getItemNode.execute(frame, tuple.getSequenceStorage(), key);
|
275 | 276 | }
|
276 | 277 |
|
277 | 278 | @InliningCutoff
|
278 | 279 | @Specialization
|
279 |
| - Object doPTuple(VirtualFrame frame, PTuple tuple, PSlice key, |
| 280 | + static Object doSlice(VirtualFrame frame, PTuple tuple, PSlice key, |
280 | 281 | @Cached("createGetItemNode()") SequenceStorageNodes.GetItemNode getItemNode) {
|
281 | 282 | return getItemNode.execute(frame, tuple.getSequenceStorage(), key);
|
282 | 283 | }
|
283 | 284 |
|
284 | 285 | @InliningCutoff
|
285 | 286 | @Specialization
|
286 |
| - Object doNative(PythonNativeObject tuple, long key, |
| 287 | + static Object doNative(PythonNativeObject tuple, long key, |
287 | 288 | @Cached PCallCapiFunction callSetItem,
|
288 | 289 | @Cached CExtNodes.ToSulongNode toSulongNode,
|
289 | 290 | @Cached CExtNodes.AsPythonObjectNode asPythonObjectNode) {
|
290 | 291 | return asPythonObjectNode.execute(callSetItem.call(NativeCAPISymbol.FUN_PY_TRUFFLE_TUPLE_GET_ITEM, toSulongNode.execute(tuple), key));
|
291 | 292 | }
|
292 | 293 |
|
| 294 | + @SuppressWarnings("unused") |
| 295 | + @InliningCutoff |
| 296 | + @Fallback |
| 297 | + static Object doError(VirtualFrame frame, Object tuple, Object key, |
| 298 | + @Cached PRaiseNode raiseNode) { |
| 299 | + throw raiseNode.raise(TypeError, ErrorMessages.OBJ_INDEX_MUST_BE_INT_OR_SLICES, "tuple", key); |
| 300 | + } |
| 301 | + |
293 | 302 | protected static SequenceStorageNodes.GetItemNode createGetItemNode() {
|
294 |
| - return SequenceStorageNodes.GetItemNode.create(NormalizeIndexNode.forTuple(), TYPE_ERROR_MESSAGE, (s, f) -> f.createTuple(s)); |
| 303 | + return SequenceStorageNodes.GetItemNode.create(NormalizeIndexNode.forTuple(), (s, f) -> f.createTuple(s)); |
295 | 304 | }
|
296 | 305 | }
|
297 | 306 |
|
|
0 commit comments