|
28 | 28 |
|
29 | 29 | import static com.oracle.graal.python.builtins.objects.slice.PSlice.MISSING_INDEX;
|
30 | 30 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__ADD__;
|
| 31 | +import static com.oracle.graal.python.nodes.SpecialMethodNames.__IADD__; |
31 | 32 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__BOOL__;
|
32 | 33 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__DELITEM__;
|
33 | 34 | import static com.oracle.graal.python.nodes.SpecialMethodNames.__EQ__;
|
@@ -265,6 +266,45 @@ public Object add(Object self, Object other) {
|
265 | 266 | }
|
266 | 267 | }
|
267 | 268 |
|
| 269 | + @Builtin(name = __IADD__, fixedNumOfPositionalArgs = 2) |
| 270 | + @GenerateNodeFactory |
| 271 | + public abstract static class IAddNode extends PythonBinaryBuiltinNode { |
| 272 | + @Specialization |
| 273 | + public PByteArray add(PByteArray self, PIBytesLike other, |
| 274 | + @Cached("create()") SequenceStorageNodes.ConcatNode concatNode) { |
| 275 | + SequenceStorage res = concatNode.execute(self.getSequenceStorage(), other.getSequenceStorage()); |
| 276 | + updateSequenceStorage(self, res); |
| 277 | + return self; |
| 278 | + } |
| 279 | + |
| 280 | + @Specialization |
| 281 | + public PByteArray add(PByteArray self, PMemoryView other, |
| 282 | + @Cached("create(TOBYTES)") LookupAndCallUnaryNode toBytesNode, |
| 283 | + @Cached("createBinaryProfile()") ConditionProfile isBytesProfile, |
| 284 | + @Cached("create()") SequenceStorageNodes.ConcatNode concatNode) { |
| 285 | + |
| 286 | + Object bytesObj = toBytesNode.executeObject(other); |
| 287 | + if (isBytesProfile.profile(bytesObj instanceof PBytes)) { |
| 288 | + SequenceStorage res = concatNode.execute(self.getSequenceStorage(), ((PBytes) bytesObj).getSequenceStorage()); |
| 289 | + updateSequenceStorage(self, res); |
| 290 | + return self; |
| 291 | + } |
| 292 | + throw raise(SystemError, "could not get bytes of memoryview"); |
| 293 | + } |
| 294 | + |
| 295 | + @SuppressWarnings("unused") |
| 296 | + @Fallback |
| 297 | + public Object add(Object self, Object other) { |
| 298 | + throw raise(TypeError, "can't concat bytearray to %p", other); |
| 299 | + } |
| 300 | + |
| 301 | + private static void updateSequenceStorage(PByteArray array, SequenceStorage s) { |
| 302 | + if (array.getSequenceStorage() != s) { |
| 303 | + array.setSequenceStorage(s); |
| 304 | + } |
| 305 | + } |
| 306 | + } |
| 307 | + |
268 | 308 | @Builtin(name = __MUL__, fixedNumOfPositionalArgs = 2)
|
269 | 309 | @GenerateNodeFactory
|
270 | 310 | public abstract static class MulNode extends PythonBuiltinNode {
|
|
0 commit comments