[pypy-svn] r25828 - in pypy/dist/pypy: rpython rpython/lltypesystem rpython/ootypesystem rpython/test translator/cli translator/cli/src translator/cli/test

antocuni at codespeak.net antocuni at codespeak.net
Fri Apr 14 13:42:55 CEST 2006


Author: antocuni
Date: Fri Apr 14 13:42:40 2006
New Revision: 25828

Modified:
   pypy/dist/pypy/rpython/lltypesystem/rlist.py
   pypy/dist/pypy/rpython/ootypesystem/ootype.py
   pypy/dist/pypy/rpython/ootypesystem/rlist.py
   pypy/dist/pypy/rpython/rlist.py
   pypy/dist/pypy/rpython/test/test_rlist.py
   pypy/dist/pypy/translator/cli/rte.py
   pypy/dist/pypy/translator/cli/src/pypylib.cs
   pypy/dist/pypy/translator/cli/test/compile.py
   pypy/dist/pypy/translator/cli/test/test_list.py
Log:
- Added support for deleting items and slices in ootypesystem rlist
- Added some ootypesystem tests in rpython/test/test_rlist.py
- Improved support for lists in the CLI backend.

At the moment two tests in test_rlist skip because they need to return
a tuple of lists and ootypesystem doesn't support that, yet. TODO:
Remove the skip as soon as ootypesystem is fixed.



Modified: pypy/dist/pypy/rpython/lltypesystem/rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/lltypesystem/rlist.py	(original)
+++ pypy/dist/pypy/rpython/lltypesystem/rlist.py	Fri Apr 14 13:42:40 2006
@@ -5,7 +5,7 @@
 from pypy.rpython.rmodel import Repr, IntegerRepr, inputconst
 from pypy.rpython.rmodel import externalvsinternal
 from pypy.rpython.rlist import AbstractBaseListRepr, AbstractListRepr, \
-        AbstractListIteratorRepr, rtype_newlist
+        AbstractFixedSizeListRepr, AbstractListIteratorRepr, rtype_newlist
 from pypy.rpython.rlist import dum_nocheck, dum_checkidx
 from pypy.rpython.lltypesystem.rslice import SliceRepr
 from pypy.rpython.lltypesystem.rslice import startstop_slice_repr, startonly_slice_repr
@@ -55,6 +55,8 @@
         self.ll_listslice = ll_listslice
         self.ll_listslice_minusone = ll_listslice_minusone
         self.ll_listsetslice = ll_listsetslice
+        self.ll_listdelslice_startonly = ll_listdelslice_startonly
+        self.ll_listdelslice = ll_listdelslice
         self.list_builder = ListBuilder()
 
     def _setup_repr_final(self):
@@ -267,7 +269,7 @@
         v_res = hop.gendirectcall(llfn, v_func, *args)
         return self.recast(hop.llops, v_res)
 
-class FixedSizeListRepr(AbstractListRepr, BaseListRepr):
+class FixedSizeListRepr(AbstractFixedSizeListRepr, BaseListRepr):
 
     def _setup_repr(self):
         if 'item_repr' not in self.__dict__:
@@ -356,19 +358,6 @@
         return hop.gendirectcall(ll_inplace_mul, v_lst, v_factor)
 
 
-class __extend__(pairtype(ListRepr, SliceRepr)):
-
-    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)
-            hop.gendirectcall(ll_listdelslice_startonly, v_lst, v_start)
-            return
-        if r_slic == startstop_slice_repr:
-            v_lst, v_slice = hop.inputargs(r_lst, startstop_slice_repr)
-            hop.gendirectcall(ll_listdelslice, v_lst, v_slice)
-            return
-        raise TyperError('delitem does not support slices with %r' % (r_slic,))
-
 class __extend__(pairtype(BaseListRepr, BaseListRepr)):
     def convert_from_to((r_lst1, r_lst2), v, llops):
         if r_lst1.listitem is None or r_lst2.listitem is None:

Modified: pypy/dist/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/ootype.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/ootype.py	Fri Apr 14 13:42:40 2006
@@ -206,10 +206,8 @@
             "append": Meth([self.ITEMTYPE_T], Void),
             "getitem_nonneg": Meth([Signed], self.ITEMTYPE_T),
             "setitem_nonneg": Meth([Signed, self.ITEMTYPE_T], Void),
-##            "getslice_startonly": Meth([Signed], self.SELFTYPE_T),
-##            "getslice_startstop": Meth([Signed, Signed], self.SELFTYPE_T),
-##            "reverse": Meth([], self.SELFTYPE_T),
             "extend": Meth([self.SELFTYPE_T], Void),
+            "remove_range": Meth([Signed, Signed], Void), # remove_range(start, count)
         })
 
         self._setup_methods(generic_types)
@@ -560,6 +558,9 @@
         assert typeOf(other) == typeOf(self)
         self._list.extend(other._list)
 
+    def remove_range(self, start, count):
+        del self._list[start:start+count]
+
 class _null_list(_null_mixin(_list), _list):
 
     def __init__(self, LIST):

Modified: pypy/dist/pypy/rpython/ootypesystem/rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/rlist.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/rlist.py	Fri Apr 14 13:42:40 2006
@@ -30,7 +30,9 @@
         self.ll_listslice_startonly = ll_listslice_startonly
         self.ll_listslice = ll_listslice
         self.ll_listslice_minusone = ll_listslice_minusone
-        self.ll_listsetslice = ll_listsetslice        
+        self.ll_listsetslice = ll_listsetslice
+        self.ll_listdelslice_startonly = ll_listdelslice_startonly
+        self.ll_listdelslice = ll_listdelslice
         # setup() needs to be called to finish this initialization
 
     def _setup_repr(self):
@@ -87,6 +89,19 @@
             return hop.gendirectcall(ll_setitem, v_list, v_index, v_item)
 
 
+class __extend__(pairtype(ListRepr, IntegerRepr)):
+
+    def rtype_delitem((r_list, r_int), hop):
+        v_list, v_index = hop.inputargs(r_list, Signed)
+        if hop.args_s[1].nonneg:
+            v_count = hop.inputconst(Signed, 1)
+            return r_list.send_message(hop, "remove_range",can_raise=True,
+                                       v_args=[v_list, v_index, v_count])
+        else:
+            hop.exception_is_here()
+            return hop.gendirectcall(ll_delitem, v_list, v_index)
+
+
 def newlist(llops, r_list, items_v):
     c_1ist = inputconst(ootype.Void, r_list.lowleveltype)
     v_result = llops.genop("new", [c_1ist], resulttype=r_list.lowleveltype)
@@ -112,6 +127,11 @@
         index += lst.length()
     return lst.setitem_nonneg(index, item)
 
+def ll_delitem(lst, index):
+    if index < 0:
+        index += lst.length()
+    return lst.remove_range(index, 1)
+
 def ll_append(lst, item):
     lst.append(item)
 
@@ -184,6 +204,20 @@
         i += 1
         j += 1
 
+def ll_listdelslice_startonly(lst, start):
+    count = lst.length() - start
+    if count > 0:
+        lst.remove_range(start, count)
+
+def ll_listdelslice(lst, slice):
+    start = slice.start
+    stop = slice.stop
+    length = lst.length()
+    if stop > length:
+        stop = length
+    count = stop - start
+    if count > 0:
+        lst.remove_range(start, count)
 
 # ____________________________________________________________
 #

Modified: pypy/dist/pypy/rpython/rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/rlist.py	(original)
+++ pypy/dist/pypy/rpython/rlist.py	Fri Apr 14 13:42:40 2006
@@ -36,9 +36,12 @@
         return llops.convertvar(v, self.item_repr, self.external_item_repr)
 
 class AbstractListRepr(AbstractBaseListRepr):
-    
     pass
 
+class AbstractFixedSizeListRepr(AbstractBaseListRepr):
+    pass
+
+
 def rtype_newlist(hop):
     nb_args = hop.nb_args
     r_list = hop.r_result
@@ -75,7 +78,7 @@
         return v_lst1
 
 
-class __extend__(pairtype(AbstractListRepr, AbstractSliceRepr)):
+class __extend__(pairtype(AbstractBaseListRepr, AbstractSliceRepr)):
 
     def rtype_getitem((r_lst, r_slic), hop):
         rs = r_lst.rtyper.type_system.rslice
@@ -103,6 +106,21 @@
         raise TyperError('setitem does not support slices with %r' % (r_slic,))
 
 
+class __extend__(pairtype(AbstractListRepr, AbstractSliceRepr)):
+
+    def rtype_delitem((r_lst, r_slic), hop):
+        rs = r_lst.rtyper.type_system.rslice        
+        if r_slic == rs.startonly_slice_repr:
+            v_lst, v_start = hop.inputargs(r_lst, rs.startonly_slice_repr)
+            hop.gendirectcall(r_lst.ll_listdelslice_startonly, v_lst, v_start)
+            return
+        if r_slic == rs.startstop_slice_repr:
+            v_lst, v_slice = hop.inputargs(r_lst, rs.startstop_slice_repr)
+            hop.gendirectcall(r_lst.ll_listdelslice, v_lst, v_slice)
+            return
+        raise TyperError('delitem does not support slices with %r' % (r_slic,))
+
+
 # ____________________________________________________________
 #
 #  Iteration.

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 Apr 14 13:42:40 2006
@@ -251,79 +251,80 @@
         res = interpret(dummyfn, [], type_system=self.ts)
         assert self.ll_to_list(res) == [5, 6, 7, 8, 9]
 
-def test_slice():
-    def dummyfn():
-        l = [5, 6, 7, 8, 9]
-        return l[:2], l[1:4], l[3:]
-    res = interpret(dummyfn, [])
-    assert tolst(res.item0) == [5, 6]
-    assert tolst(res.item1) == [6, 7, 8]
-    assert tolst(res.item2) == [8, 9]
-
-    def dummyfn():
-        l = [5, 6, 7, 8]
-        l.append(9)
-        return l[:2], l[1:4], l[3:]
-    res = interpret(dummyfn, [])
-    assert tolst(res.item0) == [5, 6]
-    assert tolst(res.item1) == [6, 7, 8]
-    assert tolst(res.item2) == [8, 9]
-
-def test_set_del_item():
-    def dummyfn():
-        l = [5, 6, 7]
-        l[1] = 55
-        l[-1] = 66
-        return l
-    res = interpret(dummyfn, [])
-    assert tolst(res) == [5, 55, 66]
-
-    def dummyfn():
-        l = []
-        l.append(5)
-        l.append(6)
-        l.append(7)
-        l[1] = 55
-        l[-1] = 66
-        return l
-    res = interpret(dummyfn, [])
-    assert tolst(res) == [5, 55, 66]
-
-    def dummyfn():
-        l = [5, 6, 7]
-        l[1] = 55
-        l[-1] = 66
-        del l[0]
-        del l[-1]
-        del l[:]
-        return len(l)
-    res = interpret(dummyfn, [])
-    assert res == 0
+    def test_slice(self):
+        if self.ts == 'ootype':
+            py.test.skip("ootypesystem doesn't support returning tuples of lists, yet")
+        def dummyfn():
+            l = [5, 6, 7, 8, 9]
+            return l[:2], l[1:4], l[3:]
+        res = interpret(dummyfn, [], type_system=self.ts)
+        assert self.ll_to_list(res.item0) == [5, 6]
+        assert self.ll_to_list(res.item1) == [6, 7, 8]
+        assert self.ll_to_list(res.item2) == [8, 9]
+
+        def dummyfn():
+            l = [5, 6, 7, 8]
+            l.append(9)
+            return l[:2], l[1:4], l[3:]
+        res = interpret(dummyfn, [], type_system=self.ts)
+        assert self.ll_to_list(res.item0) == [5, 6]
+        assert self.ll_to_list(res.item1) == [6, 7, 8]
+        assert self.ll_to_list(res.item2) == [8, 9]
+
+    def test_set_del_item(self):
+        def dummyfn():
+            l = [5, 6, 7]
+            l[1] = 55
+            l[-1] = 66
+            return l
+        res = interpret(dummyfn, [], type_system=self.ts)
+        assert self.ll_to_list(res) == [5, 55, 66]
 
-def tolst(l):
-    return map(None, l.ll_items())[:l.ll_length()]
+        def dummyfn():
+            l = []
+            l.append(5)
+            l.append(6)
+            l.append(7)
+            l[1] = 55
+            l[-1] = 66
+            return l
+        res = interpret(dummyfn, [], type_system=self.ts)
+        assert self.ll_to_list(res) == [5, 55, 66]
 
-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 dummyfn():
+            l = [5, 6, 7]
+            l[1] = 55
+            l[-1] = 66
+            del l[0]
+            del l[-1]
+            del l[:]
+            return len(l)
+        res = interpret(dummyfn, [], type_system=self.ts)
+        assert res == 0
 
-    def dummyfn():
-        l = [10, 9, 8]
-        l.append(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_setslice(self):
+        if self.ts == 'ootype':
+            py.test.skip("ootypesystem doesn't support returning tuples of lists, yet")        
+        def dummyfn():
+            l = [10, 9, 8, 7]
+            l[:2] = [6, 5]
+            return l[0], l[1], l[2], l[3]
+        res = interpret(dummyfn, (), type_system=self.ts)
+        assert res.item0 == 6
+        assert res.item1 == 5
+        assert res.item2 == 8
+        assert res.item3 == 7
+
+        def dummyfn():
+            l = [10, 9, 8]
+            l.append(7)
+            l[:2] = [6, 5]
+            return l[0], l[1], l[2], l[3]
+        res = interpret(dummyfn, (), type_system=self.ts)
+        assert res.item0 == 6
+        assert res.item1 == 5
+        assert res.item2 == 8
+        assert res.item3 == 7
 
 def test_insert_pop():
     def dummyfn():

Modified: pypy/dist/pypy/translator/cli/rte.py
==============================================================================
--- pypy/dist/pypy/translator/cli/rte.py	(original)
+++ pypy/dist/pypy/translator/cli/rte.py	Fri Apr 14 13:42:40 2006
@@ -9,6 +9,12 @@
 
 from pypy.translator.cli.sdk import SDK
 
+from pypy.tool.ansi_print import ansi_log
+import py
+log = py.log.Producer("cli") 
+py.log.setconsumer("cli", ansi_log) 
+
+
 SRC = 'pypylib.cs'
 DLL = 'pypylib.dll'
 
@@ -35,6 +41,7 @@
     return dll
     
 def compile(source, dll):
+    log.red("Compiling pypylib.dll")
     csc = SDK.csc()
     compiler = subprocess.Popen([csc, '/t:library', '/out:%s' % dll, source],
                                 stdout=subprocess.PIPE, stderr=subprocess.PIPE)

Modified: pypy/dist/pypy/translator/cli/src/pypylib.cs
==============================================================================
--- pypy/dist/pypy/translator/cli/src/pypylib.cs	(original)
+++ pypy/dist/pypy/translator/cli/src/pypylib.cs	Fri Apr 14 13:42:40 2006
@@ -39,5 +39,10 @@
             this.AddRange(other);
         }
 
+        public void remove_range(int start, int count)
+        {
+            this.RemoveRange(start, count);
+        }
+
     }
 }

Modified: pypy/dist/pypy/translator/cli/test/compile.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/compile.py	(original)
+++ pypy/dist/pypy/translator/cli/test/compile.py	Fri Apr 14 13:42:40 2006
@@ -34,7 +34,8 @@
 
 def bar(x, y):
     lst = [1,2,3,x,y]
-    return sum_(lst[:-1])
+    del lst[:]
+    return sum_(lst)
 
 f = compile_function(bar, [int, int])
 

Modified: pypy/dist/pypy/translator/cli/test/test_list.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_list.py	(original)
+++ pypy/dist/pypy/translator/cli/test/test_list.py	Fri Apr 14 13:42:40 2006
@@ -9,7 +9,7 @@
 
 
 def create(x, y):
-    return [x, y, x+y, x*y]
+    return [1, 2, 3, x, y, x+y, x*y]
 
 def sum_(lst):
     total = 0
@@ -61,3 +61,11 @@
     lst = create(x, y)
     lst[1:3] = [1234, 5678]
     return sum_(lst)
+
+##def list_del_item_slice(x, y):
+##    lst = create(x, y)
+##    del lst[0]
+##    del lst[2:4]
+##    del lst[5:]
+##    return sum_(lst)
+



More information about the Pypy-commit mailing list