[pypy-svn] r13654 - in pypy/dist/pypy/rpython: . test

ale at codespeak.net ale at codespeak.net
Tue Jun 21 14:54:30 CEST 2005


Author: ale
Date: Tue Jun 21 14:54:29 2005
New Revision: 13654

Modified:
   pypy/dist/pypy/rpython/rlist.py
   pypy/dist/pypy/rpython/test/test_llinterp.py
Log:
added added .reverse and .pop

.pop is not finished yet ( and maybe not right - ll operations cant call each other, right ? )

Modified: pypy/dist/pypy/rpython/rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/rlist.py	(original)
+++ pypy/dist/pypy/rpython/rlist.py	Tue Jun 21 14:54:29 2005
@@ -84,7 +84,17 @@
     def rtype_method_extend(self, hop):
         v_lst1, v_lst2 = hop.inputargs(self, self)
         hop.gendirectcall(ll_extend, v_lst1, v_lst2)
-
+    
+    def rtype_method_reverse(self, hop):
+        v_lst, = hop.inputargs(self)
+        hop.gendirectcall(ll_reverse,v_lst)
+
+    def rtype_method_pop(self,hop):
+        v_list,v_index = hop.inputargs(self,Signed)
+        #v_index = hop.inputconst(Signed,-1)
+        assert hasattr(v_index,'concretetype')
+        return hop.gendirectcall(ll_pop,v_list,v_index)
+        
     def make_iterator_repr(self):
         return ListIteratorRepr(self)
 
@@ -98,7 +108,11 @@
         else:
             llfn = ll_getitem
         return hop.gendirectcall(llfn, v_lst, v_index)
-
+    
+##    def rtype_method_pop((r_list,r_int),hop):
+##        v_lst, v_index = hop.inputargs(r_lst, Signed)
+##        return hop.gendirectcall(ll_pop,v_list,v_index)
+    
     def rtype_setitem((r_lst, r_int), hop):
         v_lst, v_index, v_item = hop.inputargs(r_lst, Signed, r_lst.item_repr)
         if hop.args_s[1].nonneg:
@@ -173,6 +187,20 @@
     newitems[length] = newitem
     l.items = newitems
 
+def ll_pop(l,index):
+    res = ll_getitem(l,index)
+    ll_delitem(l,index)
+    return res
+
+def ll_reverse(l):
+    length = len(l.items)
+    i=0
+    while i<length/2:
+        tmp = l.items[i]
+        l.items[i] = l.items[length-1-i]
+        l.items[length-1-i] = tmp
+        i +=1
+        
 def ll_getitem_nonneg(l, i):
     return l.items[i]
 

Modified: pypy/dist/pypy/rpython/test/test_llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_llinterp.py	(original)
+++ pypy/dist/pypy/rpython/test/test_llinterp.py	Tue Jun 21 14:54:29 2005
@@ -1,10 +1,11 @@
 
 import py
-from pypy.rpython.lltype import typeOf
+from pypy.rpython.lltype import typeOf,pyobjectptr
 from pypy.rpython.rtyper import RPythonTyper
-from pypy.rpython.llinterp import LLInterpreter, LLException
+from pypy.rpython.llinterp import LLInterpreter, LLException,log
 from pypy.translator.translator import Translator
-from pypy.rpython.lltype import pyobjectptr
+from pypy.rpython.rlist import *
+from pypy.rpython.rint import signed_repr
 from pypy.annotation.model import lltype_to_annotation
 
 # switch on logging of interp to show more info on failing tests
@@ -174,6 +175,42 @@
     res = interpret(f, [3])
     assert res == 3
 
+def test_unicode():
+    def f():
+        return u'Hello world'
+    res = interpret(f,[])
+    
+    assert res._obj.value == u'Hello world'
+    
+##def test_unicode_split():
+##    def f():
+##        res = u'Hello world'.split()
+##        return u' '.join(res)
+##    res = interpret(f,[],True)
+##    
+##    assert res == u'Hello world'
+
+def test_list_reverse():
+    def f():
+        l = [1,2,3]
+        l.reverse()
+        return l
+    res = interpret(f,[])
+    assert len(res.items) == len([3,2,1])
+    print res
+    for i in range(3):
+        assert res.items[i] == 3-i
+        
+def test_list_pop():
+    def f():
+        l = [1,2,3]
+        l1 = l.pop(2)
+        l2 = l.pop(1)
+        l3 = l.pop(-1)
+        return [l1,l2,l3]
+    res = interpret(f,[])
+    assert len(res.items) == 3
+    
 #__________________________________________________________________
 #
 #  Test objects and instances



More information about the Pypy-commit mailing list