|
40 | 40 | */
|
41 | 41 | package com.oracle.graal.python.builtins.modules;
|
42 | 42 |
|
| 43 | +import static com.oracle.graal.python.builtins.PythonBuiltinClassType.IndexError; |
| 44 | +import static com.oracle.graal.python.builtins.PythonBuiltinClassType.SystemError; |
43 | 45 | import static com.oracle.graal.python.runtime.exception.PythonErrorType.OverflowError;
|
44 |
| -import static com.oracle.graal.python.runtime.exception.PythonErrorType.SystemError; |
45 | 46 | import static com.oracle.graal.python.runtime.exception.PythonErrorType.TypeError;
|
46 | 47 |
|
47 | 48 | import java.math.BigInteger;
|
|
143 | 144 | import com.oracle.graal.python.runtime.exception.PException;
|
144 | 145 | import com.oracle.graal.python.runtime.exception.PythonErrorType;
|
145 | 146 | import com.oracle.graal.python.runtime.object.PythonObjectFactory;
|
| 147 | +import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage; |
146 | 148 | import com.oracle.truffle.api.CallTarget;
|
147 | 149 | import com.oracle.truffle.api.CompilerDirectives;
|
148 | 150 | import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
|
@@ -2059,4 +2061,27 @@ int doI(PythonClass a, PythonClass b) {
|
2059 | 2061 | }
|
2060 | 2062 | }
|
2061 | 2063 |
|
| 2064 | + @Builtin(name = "PyTuple_GetItem", fixedNumOfPositionalArgs = 2) |
| 2065 | + @GenerateNodeFactory |
| 2066 | + abstract static class PyTuple_GetItem extends PythonBinaryBuiltinNode { |
| 2067 | + |
| 2068 | + @Specialization |
| 2069 | + Object doPTuple(PTuple tuple, long key, |
| 2070 | + @Cached("create()") SequenceStorageNodes.LenNode lenNode, |
| 2071 | + @Cached("createNotNormalized()") SequenceStorageNodes.GetItemNode getItemNode) { |
| 2072 | + SequenceStorage sequenceStorage = tuple.getSequenceStorage(); |
| 2073 | + // we must do a bounds-check but we must not normalize the index |
| 2074 | + if (key < 0 || key >= lenNode.execute(sequenceStorage)) { |
| 2075 | + throw raise(IndexError, NormalizeIndexNode.TUPLE_OUT_OF_BOUNDS); |
| 2076 | + } |
| 2077 | + return getItemNode.execute(sequenceStorage, key); |
| 2078 | + } |
| 2079 | + |
| 2080 | + @Fallback |
| 2081 | + Object doPTuple(Object tuple, @SuppressWarnings("unused") Object key) { |
| 2082 | + // TODO(fa) To be absolutely correct, we need to do a 'isinstance' check on the object. |
| 2083 | + throw raise(SystemError, "bad argument to internal function, was '%s' (type '%p')", tuple, tuple); |
| 2084 | + } |
| 2085 | + } |
| 2086 | + |
2062 | 2087 | }
|
0 commit comments