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

hpk at codespeak.net hpk at codespeak.net
Fri Jun 17 20:40:28 CEST 2005


Author: hpk
Date: Fri Jun 17 20:40:26 2005
New Revision: 13553

Modified:
   pypy/dist/pypy/annotation/unaryop.py
   pypy/dist/pypy/rpython/test/test_llinterp.py
Log:
(cf+hpk+arigo) 

- added some list tests 
- list.extend now unifies the two listdefs



Modified: pypy/dist/pypy/annotation/unaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/unaryop.py	(original)
+++ pypy/dist/pypy/annotation/unaryop.py	Fri Jun 17 20:40:26 2005
@@ -212,8 +212,11 @@
 
     def method_extend(lst, s_iterable):
         lst.listdef.resize()
-        s_iter = s_iterable.iter()
-        pair(lst, SomeInteger()).setitem(s_iter.next())
+        if isinstance(s_iterable, SomeList):   # unify the two lists
+            lst.listdef.union(s_iterable.listdef)
+        else:
+            s_iter = s_iterable.iter()
+            pair(lst, SomeInteger()).setitem(s_iter.next())
 
     def method_reverse(lst):
         lst.listdef.mutate()
@@ -221,7 +224,7 @@
     def method_insert(lst, s_index, s_value):
         lst.listdef.resize()
         pair(lst, SomeInteger()).setitem(s_value)
-        
+
     def method_pop(lst, s_index=None):
         lst.listdef.resize()
         return lst.listdef.read_item()
@@ -254,7 +257,7 @@
             r.const = 0
             return r
         return SomeObject.len(dct)
-    
+
     def iter(dct):
         return SomeIterator(dct)
 
@@ -280,7 +283,7 @@
     def method_items(dct):
         return getbookkeeper().newlist(SomeTuple((dct.dictdef.read_key(),
                                                   dct.dictdef.read_value())))
-        
+
 
 class __extend__(SomeString):
 
@@ -375,14 +378,14 @@
             return bltn.analyser(bltn.s_self, *args)
         else:
             return bltn.analyser(*args)
-        
+
 
 class __extend__(SomePBC):
 
     def getattr(pbc, s_attr):
         bookkeeper = getbookkeeper()
         return bookkeeper.pbc_getattr(pbc, s_attr)
-        
+
     def setattr(pbc, s_attr, s_value):
         getbookkeeper().warning("setattr not wanted on %r" % (pbc,))
 
@@ -393,21 +396,21 @@
         #bookkeeper = getbookkeeper()
         #results = []
         #for func, classdef in pbc.prebuiltinstances.items():
-        #    if isclassdef(classdef): 
+        #    if isclassdef(classdef):
         #        s_self = SomeInstance(classdef)
         #        args1 = args.prepend(s_self)
         #    else:
         #        args1 = args
         #    results.append(bookkeeper.pycall(func, args1))
-        #return unionof(*results) 
+        #return unionof(*results)
 
-    def bindcallables(pbc, classdef):   
-        """ turn the callables in the given SomeCallable 'cal' 
+    def bindcallables(pbc, classdef):
+        """ turn the callables in the given SomeCallable 'cal'
             into bound versions.
         """
         d = {}
         for func, value in pbc.prebuiltinstances.items():
-            if isinstance(func, FunctionType): 
+            if isinstance(func, FunctionType):
                 if isclassdef(value):
                     getbookkeeper().warning("rebinding an already bound "
                                             "method %r with %r" % (func, value))
@@ -415,7 +418,7 @@
             elif isinstance(func, staticmethod):
                 d[func.__get__(43)] = value
             else:
-                d[func] = value 
+                d[func] = value
         return SomePBC(d)
 
     def is_true(pbc):
@@ -427,8 +430,8 @@
                 if outcome != bool(c):
                     return SomeBool()
         return immutablevalue(outcome)
-            
-            
+
+
 # annotation of low-level types
 from pypy.annotation.model import SomePtr, ll_to_annotation, annotation_to_lltype
 class __extend__(SomePtr):

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	Fri Jun 17 20:40:26 2005
@@ -28,6 +28,7 @@
 def gengraph(func, argtypes=[]):
     t = Translator(func)
     t.annotate(argtypes)
+    #t.view()
     global typer # we need it for find_exception
     typer = RPythonTyper(t.annotator)
     typer.specialize()
@@ -137,15 +138,39 @@
     for i in range(3):
         assert res.items[i] == i+1
 
-def test_list_operations():
+def test_list_itemops():
     def f(i):
         l = [1, i]
-        l[0] = len(l)
-        l += [i + 1, 9]
-#        l *= 2
-        return l[0] + l[1] + l[2]# + len(l)
+        l[0] = 0
+        del l[1]
+        return l[-1]
+    res = interpret(f, [3])
+    assert res == 0
+
+def test_list_append():
+    def f(i):
+        l = [1]
+        l.append(i)
+        return l[0] + l[1]
     res = interpret(f, [3])
-    assert res == 2 + 3 + 4# + 8
+    assert res == 4
+
+def test_list_extend():
+    def f(i):
+        l = [1]
+        l.extend([i])
+        return l[0] + l[1]
+    res = interpret(f, [3])
+    assert res == 4
+
+def test_list_multiply():
+    def f(i):
+        l = [i]
+        l = l * i  # uses alloc_and_set for len(l) == 1
+        return len(l)
+    res = interpret(f, [3])
+    assert res == 3
+
 #__________________________________________________________________
 # example functions for testing the LLInterpreter
 _snap = globals().copy()



More information about the Pypy-commit mailing list