Skip to content

Commit 70c69ee

Browse files
committed
Complete implementation of 'SSN.SetItemSliceNode' and add 'SSN.DeleteNode'.
1 parent b4797d9 commit 70c69ee

File tree

6 files changed

+334
-462
lines changed

6 files changed

+334
-462
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_bytes.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,8 @@ def test_setslice():
225225
# assert b == bytearray([5, 6, 7, 8, 9])
226226
b = bytearray([5, 6, 7, 8, 9])
227227

228-
# TODO: seq setSlice is broken ...
229-
# b[0:0] = bytearray([0, 1, 2, 3, 4])
230-
# assert b == bytearray(range(10))
228+
b[0:0] = bytearray([0, 1, 2, 3, 4])
229+
assert b == bytearray(range(10))
231230
b = bytearray(range(10))
232231

233232
b[-7:-3] = bytearray([100, 101])

graalpython/com.oracle.graal.python.test/src/tests/test_list.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,10 @@ def test_append(self):
615615
l.append("hello")
616616
self.assertEqual(l, [1, 0x1FF, 0x1FFFFFFFF, "hello"])
617617

618+
l = ["a", "b", "c"]
619+
l.append("d")
620+
self.assertEqual(l, ["a", "b", "c", "d"])
621+
618622

619623
class ListCompareTest(CompareTest):
620624

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/ByteArrayBuiltins.java

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,10 @@
5959
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.GetItemNode;
6060
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.NoGeneralizationNode;
6161
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.NormalizeIndexNode;
62-
import com.oracle.graal.python.builtins.objects.ints.PInt;
6362
import com.oracle.graal.python.builtins.objects.memoryview.PMemoryView;
6463
import com.oracle.graal.python.builtins.objects.range.PRange;
6564
import com.oracle.graal.python.builtins.objects.slice.PSlice;
6665
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
67-
import com.oracle.graal.python.nodes.PGuards;
6866
import com.oracle.graal.python.nodes.SpecialMethodNames;
6967
import com.oracle.graal.python.nodes.call.special.LookupAndCallUnaryNode;
7068
import com.oracle.graal.python.nodes.expression.BinaryComparisonNode;
@@ -115,68 +113,18 @@ public PNone init(Object self, Object args, Object kwargs) {
115113
@TypeSystemReference(PythonArithmeticTypes.class)
116114
@GenerateNodeFactory
117115
public abstract static class DelItemNode extends PythonBinaryBuiltinNode {
118-
@Child private SequenceStorageNodes.NormalizeIndexNode normalize = SequenceStorageNodes.NormalizeIndexNode.forArray();
119-
120-
@Specialization(guards = "isByteStorage(primary)")
121-
protected PNone doBytes(PByteArray primary, long idx) {
122-
ByteSequenceStorage storage = (ByteSequenceStorage) primary.getSequenceStorage();
123-
storage.delItemInBound(normalize.execute(idx, storage.length()));
124-
return PNone.NONE;
125-
}
126-
127-
@Specialization(guards = "isByteStorage(primary)")
128-
protected PNone doBytes(PByteArray primary, PInt idx) {
129-
ByteSequenceStorage storage = (ByteSequenceStorage) primary.getSequenceStorage();
130-
storage.delItemInBound(normalize.execute(idx, storage.length()));
131-
return PNone.NONE;
132-
}
133-
134-
@Specialization(guards = "isIntStorage(primary)")
135-
protected PNone doInt(PByteArray primary, long idx) {
136-
IntSequenceStorage storage = (IntSequenceStorage) primary.getSequenceStorage();
137-
storage.delItemInBound(normalize.execute(idx, storage.length()));
138-
return PNone.NONE;
139-
}
140-
141-
@Specialization(guards = "isIntStorage(primary)")
142-
protected PNone doInt(PByteArray primary, PInt idx) {
143-
IntSequenceStorage storage = (IntSequenceStorage) primary.getSequenceStorage();
144-
storage.delItemInBound(normalize.execute(idx, storage.length()));
145-
return PNone.NONE;
146-
}
147-
148-
@Specialization
149-
protected PNone doArray(PByteArray byteArray, long idx) {
150-
SequenceStorage storage = byteArray.getSequenceStorage();
151-
storage.delItemInBound(normalize.execute(idx, storage.length()));
152-
return PNone.NONE;
153-
}
154-
155-
@Specialization
156-
protected PNone doArray(PByteArray byteArray, PInt idx) {
157-
SequenceStorage storage = byteArray.getSequenceStorage();
158-
storage.delItemInBound(normalize.execute(idx, storage.length()));
159-
return PNone.NONE;
160-
}
161-
162116
@Specialization
163-
protected PNone doSlice(PByteArray self, PSlice slice) {
164-
self.delSlice(slice);
117+
protected PNone doGeneric(PByteArray self, Object key,
118+
@Cached("create()") SequenceStorageNodes.DeleteNode deleteNode) {
119+
deleteNode.execute(self.getSequenceStorage(), key);
165120
return PNone.NONE;
166121
}
167122

168123
@SuppressWarnings("unused")
169124
@Fallback
170125
protected Object doGeneric(Object self, Object idx) {
171-
if (!isValidIndexType(idx)) {
172-
throw raise(TypeError, "bytearray indices must be integers or slices, not %p", idx);
173-
}
174126
throw raise(TypeError, "descriptor '__delitem__' requires a 'bytearray' object but received a '%p'", idx);
175127
}
176-
177-
protected boolean isValidIndexType(Object idx) {
178-
return PGuards.isInteger(idx) || idx instanceof PSlice;
179-
}
180128
}
181129

182130
@Builtin(name = __EQ__, fixedNumOfPositionalArgs = 2)

0 commit comments

Comments
 (0)