[pypy-svn] r34157 - in pypy/dist/pypy: annotation rpython rpython/test

mwh at codespeak.net mwh at codespeak.net
Sat Nov 4 11:36:05 CET 2006


Author: mwh
Date: Sat Nov  4 11:36:03 2006
New Revision: 34157

Modified:
   pypy/dist/pypy/annotation/unaryop.py
   pypy/dist/pypy/rpython/rlist.py
   pypy/dist/pypy/rpython/test/test_rlist.py
Log:
(niko,mwh)
implement list.remove for RPython


Modified: pypy/dist/pypy/annotation/unaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/unaryop.py	(original)
+++ pypy/dist/pypy/annotation/unaryop.py	Sat Nov  4 11:36:03 2006
@@ -290,6 +290,10 @@
     def method_insert(lst, s_index, s_value):
         lst.method_append(s_value)
 
+    def method_remove(lst, s_value):
+        lst.listdef.resize()
+        lst.listdef.generalize(s_value)
+
     def method_pop(lst, s_index=None):
         lst.listdef.resize()
         return lst.listdef.read_item()

Modified: pypy/dist/pypy/rpython/rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/rlist.py	(original)
+++ pypy/dist/pypy/rpython/rlist.py	Sat Nov  4 11:36:03 2006
@@ -103,6 +103,13 @@
         hop.exception_cannot_occur()
         hop.gendirectcall(ll_reverse,v_lst)
 
+    def rtype_method_remove(self, hop):
+        v_lst, v_value = hop.inputargs(self, self.item_repr)
+        hop.has_implicit_exception(ValueError)   # record that we know about it
+        hop.exception_is_here()
+        return hop.gendirectcall(ll_listremove, v_lst, v_value,
+                                 self.get_eqfunc())
+
     def rtype_method_index(self, hop):
         v_lst, v_value = hop.inputargs(self, self.item_repr)
         hop.has_implicit_exception(ValueError)   # record that we know about it
@@ -744,6 +751,11 @@
         j += 1
     raise ValueError # can't say 'list.index(x): x not in list'
 
+def ll_listremove(lst, obj, eqfn):
+    index = ll_listindex(lst, obj, eqfn) # raises ValueError if obj not in lst
+    ll_delitem_nonneg(dum_nocheck, lst, index)
+ll_listremove.oopspec = 'list.remove(obj)'
+
 def ll_inplace_mul(l, factor):
     length = l.ll_length()
     if factor < 0:

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	Sat Nov  4 11:36:03 2006
@@ -1023,6 +1023,13 @@
             assert lst in lst2
         self.interpret(dummyfn, [3])
 
+    def test_list_remove(self):
+        def dummyfn(n, p):
+            l = range(n)
+            l.remove(p)
+            return len(l)
+        res = self.interpret(dummyfn, [1, 0])
+        assert res == 0
 
 class TestLLtype(BaseTestRlist, LLRtypeMixin):
     rlist = ll_rlist



More information about the Pypy-commit mailing list