|
42 | 42 | import com.oracle.graal.python.builtins.objects.array.PArray;
|
43 | 43 | import com.oracle.graal.python.builtins.objects.bytes.PBytes;
|
44 | 44 | import com.oracle.graal.python.builtins.objects.bytes.PBytesLike;
|
| 45 | +import com.oracle.graal.python.builtins.objects.common.SequenceNodes; |
| 46 | +import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes; |
45 | 47 | import com.oracle.graal.python.builtins.objects.function.PKeyword;
|
46 | 48 | import com.oracle.graal.python.builtins.objects.module.PythonModule;
|
47 | 49 | import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
|
|
60 | 62 | import com.oracle.graal.python.runtime.PythonCore;
|
61 | 63 | import com.oracle.graal.python.runtime.exception.PException;
|
62 | 64 | import com.oracle.graal.python.runtime.object.PythonObjectFactory;
|
| 65 | +import com.oracle.graal.python.runtime.sequence.PSequence; |
| 66 | +import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage; |
63 | 67 | import com.oracle.graal.python.util.BufferFormat;
|
64 | 68 | import com.oracle.graal.python.util.OverflowException;
|
65 | 69 | import com.oracle.graal.python.util.PythonUtils;
|
@@ -188,7 +192,43 @@ PArray arrayWithBytesInitializer(VirtualFrame frame, Object cls, String typeCode
|
188 | 192 | return array;
|
189 | 193 | }
|
190 | 194 |
|
191 |
| - // TODO impl for PSequence and PArray or use lenght_hint |
| 195 | + @Specialization |
| 196 | + PArray arrayArrayInitializer(VirtualFrame frame, Object cls, String typeCode, PArray initializer, |
| 197 | + @Cached ArrayNodes.PutValueNode putValueNode, |
| 198 | + @Cached ArrayNodes.GetValueNode getValueNode) { |
| 199 | + BufferFormat format = getFormatChecked(typeCode); |
| 200 | + try { |
| 201 | + PArray array = getFactory().createArray(cls, typeCode, format, initializer.getLength()); |
| 202 | + for (int i = 0; i < initializer.getLength(); i++) { |
| 203 | + putValueNode.execute(frame, array, i, getValueNode.execute(initializer, i)); |
| 204 | + } |
| 205 | + return array; |
| 206 | + } catch (OverflowException e) { |
| 207 | + CompilerDirectives.transferToInterpreterAndInvalidate(); |
| 208 | + throw raise(MemoryError); |
| 209 | + } |
| 210 | + } |
| 211 | + |
| 212 | + @Specialization |
| 213 | + PArray arraySequenceInitializer(VirtualFrame frame, Object cls, String typeCode, PSequence initializer, |
| 214 | + @Cached ArrayNodes.PutValueNode putValueNode, |
| 215 | + @Cached SequenceNodes.GetSequenceStorageNode getSequenceStorageNode, |
| 216 | + @Cached SequenceStorageNodes.LenNode lenNode, |
| 217 | + @Cached SequenceStorageNodes.GetItemScalarNode getItemNode) { |
| 218 | + BufferFormat format = getFormatChecked(typeCode); |
| 219 | + SequenceStorage storage = getSequenceStorageNode.execute(initializer); |
| 220 | + int lenght = lenNode.execute(storage); |
| 221 | + try { |
| 222 | + PArray array = getFactory().createArray(cls, typeCode, format, lenght); |
| 223 | + for (int i = 0; i < lenght; i++) { |
| 224 | + putValueNode.execute(frame, array, i, getItemNode.execute(storage, i)); |
| 225 | + } |
| 226 | + return array; |
| 227 | + } catch (OverflowException e) { |
| 228 | + CompilerDirectives.transferToInterpreterAndInvalidate(); |
| 229 | + throw raise(MemoryError); |
| 230 | + } |
| 231 | + } |
192 | 232 |
|
193 | 233 | @Specialization(guards = "!isBytes(initializer)", limit = "3")
|
194 | 234 | PArray arrayIteratorInitializer(VirtualFrame frame, Object cls, String typeCode, Object initializer,
|
|
0 commit comments