[pypy-svn] r14929 - in pypy/dist/pypy: annotation rpython rpython/test translator/goal
arigo at codespeak.net
arigo at codespeak.net
Fri Jul 22 18:48:14 CEST 2005
Author: arigo
Date: Fri Jul 22 18:48:11 2005
New Revision: 14929
Modified:
pypy/dist/pypy/annotation/binaryop.py
pypy/dist/pypy/rpython/rlist.py
pypy/dist/pypy/rpython/test/test_rlist.py
pypy/dist/pypy/translator/goal/ISSUES.txt
Log:
setslice on lists, only for non-resizing expressions like
lst1[x:y] = lst2
with y-x == len(lst2).
Modified: pypy/dist/pypy/annotation/binaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/binaryop.py (original)
+++ pypy/dist/pypy/annotation/binaryop.py Fri Jul 22 18:48:11 2005
@@ -434,9 +434,9 @@
return getbookkeeper().newlist(lst.listdef.read_item())
def setitem((lst, slic), s_iterable):
- lst.listdef.resize()
- s_iter = s_iterable.iter()
- pair(lst, SomeInteger()).setitem(s_iter.next())
+ # we need the same unifying effect as the extend() method for
+ # the case lst1[x:y] = lst2.
+ lst.method_extend(s_iterable)
def delitem((lst1, slic)):
lst1.listdef.resize()
Modified: pypy/dist/pypy/rpython/rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/rlist.py (original)
+++ pypy/dist/pypy/rpython/rlist.py Fri Jul 22 18:48:11 2005
@@ -220,6 +220,16 @@
return hop.gendirectcall(ll_listslice_minusone, v_lst)
raise TyperError(r_slic)
+ def rtype_setitem((r_lst, r_slic), hop):
+ #if r_slic == startonly_slice_repr:
+ # not implemented
+ if r_slic == startstop_slice_repr:
+ v_lst, v_slice, v_lst2 = hop.inputargs(r_lst, startstop_slice_repr,
+ r_lst)
+ hop.gendirectcall(ll_listsetslice, v_lst, v_slice, v_lst2)
+ return
+ raise TyperError(r_slic)
+
def rtype_delitem((r_lst, r_slic), hop):
if r_slic == startonly_slice_repr:
v_lst, v_start = hop.inputargs(r_lst, startonly_slice_repr)
@@ -493,6 +503,16 @@
j += 1
l1.items = newitems
+def ll_listsetslice(l1, slice, l2):
+ count = len(l2.items)
+ assert count == slice.stop - slice.start, (
+ "setslice cannot resize lists in RPython")
+ start = slice.start
+ j = 0
+ while j < count:
+ l1.items[start+j] = l2.items[j]
+ j += 1
+
# ____________________________________________________________
#
# Comparison.
Modified: pypy/dist/pypy/rpython/test/test_rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rlist.py (original)
+++ pypy/dist/pypy/rpython/test/test_rlist.py Fri Jul 22 18:48:11 2005
@@ -8,7 +8,7 @@
from pypy.rpython.test.test_llinterp import find_exception
-def sample_list():
+def sample_list(): # [42, 43, 44, 45]
rlist = ListRepr(signed_repr)
rlist.setup()
l = ll_newlist(rlist.lowleveltype, 3)
@@ -82,6 +82,22 @@
del expected[start:stop]
check_list(l, expected)
+def test_rlist_setslice():
+ n = 100
+ for start in range(5):
+ for stop in range(start, 5):
+ l1 = sample_list()
+ l2 = sample_list()
+ expected = [42, 43, 44, 45]
+ for i in range(start, stop):
+ expected[i] = n
+ ll_setitem(l2, i, n)
+ n += 1
+ s = ll_newslice(start, stop)
+ l2 = ll_listslice(l2, s)
+ ll_listsetslice(l1, s, l2)
+ check_list(l1, expected)
+
# ____________________________________________________________
def rtype(fn, argtypes=[]):
@@ -154,6 +170,17 @@
del l[:]
rtype(dummyfn)
+def test_setslice():
+ def dummyfn():
+ l = [10, 9, 8, 7]
+ l[:2] = [6, 5]
+ return l[0], l[1], l[2], l[3]
+ res = interpret(dummyfn, ())
+ assert res.item0 == 6
+ assert res.item1 == 5
+ assert res.item2 == 8
+ assert res.item3 == 7
+
def test_insert_pop():
def dummyfn():
l = [6, 7, 8]
Modified: pypy/dist/pypy/translator/goal/ISSUES.txt
==============================================================================
--- pypy/dist/pypy/translator/goal/ISSUES.txt (original)
+++ pypy/dist/pypy/translator/goal/ISSUES.txt Fri Jul 22 18:48:11 2005
@@ -63,11 +63,6 @@
.. block at 811 with 2 exits(v734217)
.. v734191 = call_specialcase(v734159, x_734142)
- TyperError-17: (pypy.objspace.std.longobject:_k_mul)
- unimplemented operation: 'setitem' on (<ListRepr * GcStruct list { items: * GcArray of Unsigned }>, <SliceRepr * GcStruct slice { start: Signed, stop: Signed }>)
- .. block at 546 with 2 exits(v368685)
- .. v368346 = setitem(v368281, v368345, v368259)
-
TyperError-18: (pypy.objspace.std.longobject:longval)
don't know about built-in function <type 'long'>
.. block at 50 with 1 exits
@@ -83,11 +78,6 @@
.. block at 66 with 1 exits
.. v702466 = simple_call((type tuple), v702461)
- TyperError-22: (pypy.objspace.std.longobject:_k_mul)
- unimplemented operation: 'setitem' on (<ListRepr * GcStruct list { items: * GcArray of Unsigned }>, <SliceRepr * GcStruct slice { start: Signed, stop: Signed }>)
- .. block at 435 with 2 exits(v368115)
- .. v368040 = setitem(v367904, v368039, v367883)
-
TyperError-23: (pypy.objspace.std.objspace:unwrap)
unimplemented operation: 'mod' on (<StringRepr * GcStruct rpy_string { hash: Signed, chars: Array of Char }>, <InstanceRepr for pypy.interpreter.baseobjspace.W_Root>)
.. block at 63 with 1 exits
@@ -168,11 +158,6 @@
.. block at -1 EH with 1 exits
.. v655549 = getitem((('\x00\x00\x00\x00\x...02\x02')), v655545)
- TyperError-40: (pypy.interpreter.pyframe:setfastscope)
- unimplemented operation: 'setitem' on (<ListRepr * GcStruct list { items: * GcArray of * GcStruct W_Root { super: GcStruct object { typeptr: * Struct object_vtable { parenttypeptr: * Struct object_vtable { ... }, rtti: * RuntimeTypeInfo (opaque), name: * Array of Char , instantiate: * Func ( ) -> * GcStruct object { ... } } } } }>, <SliceRepr * GcStruct slice { start: Signed, stop: Signed }>)
- .. block at 47 with 1 exits
- .. v31663 = setitem(v31641, v31662, scope_w_31634)
-
TyperError-41: (pypy.objspace.std.objspace:unwrap)
don't know how to convert from <InstanceRepr for pypy.interpreter.baseobjspace.W_Root> to <PyObjRepr * PyObject>
.. block at -1 EH with 2 exits(v585990)
More information about the Pypy-commit
mailing list