|
36 | 36 | import com.oracle.graal.python.builtins.CoreFunctions; |
37 | 37 | import com.oracle.graal.python.builtins.PythonBuiltins; |
38 | 38 | import com.oracle.graal.python.builtins.objects.iterator.PRangeIterator.PRangeReverseIterator; |
| 39 | +import com.oracle.graal.python.builtins.objects.list.PList; |
39 | 40 | import com.oracle.graal.python.builtins.objects.object.PythonBuiltinObject; |
40 | 41 | import com.oracle.graal.python.nodes.call.special.LookupAndCallBinaryNode; |
41 | 42 | import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode; |
42 | 43 | import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode; |
43 | 44 | import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode; |
44 | 45 | import com.oracle.graal.python.runtime.exception.PException; |
45 | 46 | import com.oracle.graal.python.runtime.sequence.PSequence; |
| 47 | +import com.oracle.graal.python.runtime.sequence.SequenceUtil.NormalizeIndexNode; |
| 48 | +import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage; |
46 | 49 | import com.oracle.truffle.api.dsl.Cached; |
47 | 50 | import com.oracle.truffle.api.dsl.GenerateNodeFactory; |
48 | 51 | import com.oracle.truffle.api.dsl.NodeFactory; |
@@ -146,6 +149,20 @@ public Object next(PBaseSetIterator self) { |
146 | 149 | throw raise(StopIteration); |
147 | 150 | } |
148 | 151 |
|
| 152 | + @Specialization(guards = "self.isPList()") |
| 153 | + public Object nextList(PSequenceIterator self, |
| 154 | + @Cached("createClassProfile()") ValueProfile storageProfile, |
| 155 | + @Cached("create()") NormalizeIndexNode normalize) { |
| 156 | + SequenceStorage storage = storageProfile.profile(((PList) self.getPSequence()).getSequenceStorage()); |
| 157 | + int length = storage.length(); |
| 158 | + if (!self.stopIterationReached && self.index < length) { |
| 159 | + int index = normalize.execute(self.index++, length, "list index out of range"); |
| 160 | + return storage.getItemNormalized(index); |
| 161 | + } |
| 162 | + self.stopIterationReached = true; |
| 163 | + throw raise(StopIteration); |
| 164 | + } |
| 165 | + |
149 | 166 | @Specialization(guards = "self.isPSequence()") |
150 | 167 | public Object next(PSequenceIterator self, |
151 | 168 | @Cached("createClassProfile()") ValueProfile sequenceProfile) { |
|
0 commit comments