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

ale at codespeak.net ale at codespeak.net
Fri Jun 24 11:59:53 CEST 2005


Author: ale
Date: Fri Jun 24 11:59:52 2005
New Revision: 13767

Added:
   pypy/dist/pypy/rpython/test/test_rbuiltin.py
Modified:
   pypy/dist/pypy/rpython/rbuiltin.py
   pypy/dist/pypy/rpython/rlist.py
   pypy/dist/pypy/rpython/rtuple.py
Log:
Implement list builtin (ale, pedronis)

Modified: pypy/dist/pypy/rpython/rbuiltin.py
==============================================================================
--- pypy/dist/pypy/rpython/rbuiltin.py	(original)
+++ pypy/dist/pypy/rpython/rbuiltin.py	Fri Jun 24 11:59:52 2005
@@ -99,6 +99,9 @@
     assert hop.nb_args == 1
     return hop.args_r[0].rtype_chr(hop)
 
+def rtype_builtin_list(hop):
+    return hop.args_r[0].rtype_bltn_list(hop)
+
 def rtype_builtin_isinstance(hop):
     instance_repr = rclass.getinstancerepr(hop.rtyper, None)
     class_repr = rclass.get_type_repr(hop.rtyper)

Modified: pypy/dist/pypy/rpython/rlist.py
==============================================================================
--- pypy/dist/pypy/rpython/rlist.py	(original)
+++ pypy/dist/pypy/rpython/rlist.py	Fri Jun 24 11:59:52 2005
@@ -86,6 +86,10 @@
             raise TyperError, 'comparison not implemented for %r' % self
         return inputconst(Void, func)
 
+    def rtype_bltn_list(self,hop):
+        v_lst = hop.inputarg(self,0)
+        return hop.gendirectcall(ll_copy,v_lst)
+    
     def rtype_len(self, hop):
         v_lst, = hop.inputargs(self)
         return hop.gendirectcall(ll_len, v_lst)
@@ -228,6 +232,17 @@
 #  be direct_call'ed from rtyped flow graphs, which means that they will
 #  get flowed and annotated, mostly with SomePtr.
 
+def ll_copy(l):
+    items = l.items
+    length = len(items)
+    new_lst = ll_newlist(typeOf(l), length)
+    i = 0
+    new_items = new_lst.items
+    while i < length:
+        new_items[i] = items[i]
+        i += 1
+    return new_lst
+
 def ll_len(l):
     return len(l.items)
 

Modified: pypy/dist/pypy/rpython/rtuple.py
==============================================================================
--- pypy/dist/pypy/rpython/rtuple.py	(original)
+++ pypy/dist/pypy/rpython/rtuple.py	Fri Jun 24 11:59:52 2005
@@ -19,6 +19,7 @@
 class __extend__(annmodel.SomeTuple):
     def rtyper_makerepr(self, rtyper):
         return TupleRepr([rtyper.getrepr(s_item) for s_item in self.items])
+    
     def rtyper_makekey(self):
         keys = [s_item.rtyper_makekey() for s_item in self.items]
         return tuple(keys)
@@ -43,7 +44,23 @@
     def rtype_len(self, hop):
         return hop.inputconst(Signed, len(self.items_r))
 
-
+    def rtype_bltn_list(self, hop):
+        from pypy.rpython import rlist
+        nitems = len(self.items_r)
+        vtup = hop.inputarg(self, 0)
+        c1 = inputconst(Void, hop.r_result.lowleveltype)
+        c2 = inputconst(Signed, nitems)
+        vlist = hop.gendirectcall(rlist.ll_newlist, c1, c2)
+        for index in range(nitems):
+            name = self.fieldnames[index]
+            ritem = self.items_r[index]
+            cname = hop.inputconst(Void, name)
+            vitem = hop.genop('getfield', [vtup, cname], resulttype = ritem)
+            vitem = hop.llops.convertvar(vitem, ritem, hop.r_result.item_repr)
+            cindex = inputconst(Signed, index)
+            hop.gendirectcall(rlist.ll_setitem_nonneg, vlist, cindex, vitem)
+        return vlist
+           
 class __extend__(pairtype(TupleRepr, IntegerRepr)):
 
     def rtype_getitem((r_tup, r_int), hop):
@@ -113,3 +130,8 @@
             llops.gencapicall('PyTuple_SetItem_WithIncref', [v_result, ci,
                                                              v_converted])
         return v_result
+
+def ll_newlist(LISTPTR, length):
+    l = malloc(LISTPTR.TO)
+    l.items = malloc(LISTPTR.TO.items.TO, length)
+    return l

Added: pypy/dist/pypy/rpython/test/test_rbuiltin.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/rpython/test/test_rbuiltin.py	Fri Jun 24 11:59:52 2005
@@ -0,0 +1,21 @@
+from pypy.rpython.test.test_llinterp import interpret
+
+def test_rbuiltin_list():
+    def f(): 
+        l=list((1,2,3))
+        return l == [1,2,3]
+    def g():
+        l=list(('he','llo'))
+        return l == ['he','llo']
+    def r():
+        l = ['he','llo']
+        l1=list(l)
+        return l == l1 and l is not l1
+    result = interpret(f,[])
+    assert result
+    
+    result = interpret(g,[])
+    assert result
+    
+    result = interpret(r,[])
+    assert result    
\ No newline at end of file



More information about the Pypy-commit mailing list