1.1 --- a/common.py Sun Feb 05 18:12:40 2017 +0100
1.2 +++ b/common.py Sun Feb 05 18:17:14 2017 +0100
1.3 @@ -626,12 +626,21 @@
1.4 Process the given slice node 'n' as an operator function invocation.
1.5 """
1.6
1.7 - op = n.flags == "OP_ASSIGN" and "setslice" or "getslice"
1.8 + if n.flags == "OP_ASSIGN": op = "setslice"
1.9 + elif n.flags == "OP_DELETE": op = "delslice"
1.10 + else: op = "getslice"
1.11 +
1.12 invocation = compiler.ast.CallFunc(
1.13 compiler.ast.Name("$op%s" % op),
1.14 [n.expr, n.lower or compiler.ast.Name("None"), n.upper or compiler.ast.Name("None")] +
1.15 (expr and [expr] or [])
1.16 )
1.17 +
1.18 + # Fix parse tree structure.
1.19 +
1.20 + if op == "delslice":
1.21 + invocation = compiler.ast.Discard(invocation)
1.22 +
1.23 return self.process_structure_node(invocation)
1.24
1.25 def process_sliceobj_node(self, n):
1.26 @@ -653,11 +662,20 @@
1.27 Process the given subscript node 'n' as an operator function invocation.
1.28 """
1.29
1.30 - op = n.flags == "OP_ASSIGN" and "setitem" or "getitem"
1.31 + if n.flags == "OP_ASSIGN": op = "setitem"
1.32 + elif n.flags == "OP_DELETE": op = "delitem"
1.33 + else: op = "getitem"
1.34 +
1.35 invocation = compiler.ast.CallFunc(
1.36 compiler.ast.Name("$op%s" % op),
1.37 [n.expr] + list(n.subs) + (expr and [expr] or [])
1.38 )
1.39 +
1.40 + # Fix parse tree structure.
1.41 +
1.42 + if op == "delitem":
1.43 + invocation = compiler.ast.Discard(invocation)
1.44 +
1.45 return self.process_structure_node(invocation)
1.46
1.47 def process_attribute_chain(self, n):
2.1 --- a/lib/__builtins__/list.py Sun Feb 05 18:12:40 2017 +0100
2.2 +++ b/lib/__builtins__/list.py Sun Feb 05 18:17:14 2017 +0100
2.3 @@ -20,7 +20,7 @@
2.4 """
2.5
2.6 from __builtins__.iteration.iterator import itemiterator
2.7 -from __builtins__.sequence import sequence
2.8 +from __builtins__.sequence import sequence, _get_absolute_index
2.9 from native import list_append, list_concat, list_element, list_init, \
2.10 list_len, list_nonempty, list_setelement, list_setsize
2.11
2.12 @@ -40,7 +40,22 @@
2.13 if args is not None:
2.14 self.extend(args)
2.15
2.16 - def __delitem__(self, index): pass
2.17 + def __delitem__(self, index):
2.18 +
2.19 + "Delete the item at 'index'."
2.20 +
2.21 + length = self.__len__()
2.22 + index = _get_absolute_index(index, length)
2.23 + last = length - 1
2.24 +
2.25 + while index < last:
2.26 + self[index] = self[index + 1]
2.27 + index += 1
2.28 +
2.29 + # NOTE: Should truncate the allocated list after several pops.
2.30 +
2.31 + list_setsize(self.__data__, last)
2.32 +
2.33 def __setslice__(self, start, end, slice): pass
2.34 def __delslice__(self, start, end): pass
2.35
3.1 --- a/lib/operator/__init__.py Sun Feb 05 18:12:40 2017 +0100
3.2 +++ b/lib/operator/__init__.py Sun Feb 05 18:17:14 2017 +0100
3.3 @@ -3,7 +3,7 @@
3.4 """
3.5 Operator support.
3.6
3.7 -Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>
3.8 +Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
3.9
3.10 This program is free software; you can redistribute it and/or modify it under
3.11 the terms of the GNU General Public License as published by the Free Software
3.12 @@ -67,8 +67,10 @@
3.13 )
3.14
3.15 from operator.sequence import (
3.16 + delitem,
3.17 getitem,
3.18 setitem,
3.19 + delslice,
3.20 getslice,
3.21 setslice,
3.22 )
4.1 --- a/lib/operator/sequence.py Sun Feb 05 18:12:40 2017 +0100
4.2 +++ b/lib/operator/sequence.py Sun Feb 05 18:17:14 2017 +0100
4.3 @@ -3,7 +3,7 @@
4.4 """
4.5 Operator support.
4.6
4.7 -Copyright (C) 2010, 2013, 2015, 2016 Paul Boddie <paul@boddie.org.uk>
4.8 +Copyright (C) 2010, 2013, 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
4.9
4.10 This program is free software; you can redistribute it and/or modify it under
4.11 the terms of the GNU General Public License as published by the Free Software
4.12 @@ -21,12 +21,18 @@
4.13
4.14 # Access and slicing functions.
4.15
4.16 +def delitem(a, b):
4.17 + a.__delitem__(b)
4.18 +
4.19 def getitem(a, b):
4.20 return a.__getitem__(b)
4.21
4.22 def setitem(a, b, c):
4.23 a.__setitem__(b, c)
4.24
4.25 +def delslice(a, b, c):
4.26 + a.__delitem__(slice(b, c))
4.27 +
4.28 def getslice(a, b, c):
4.29 return a.__getitem__(slice(b, c))
4.30