[pypy-svn] r64778 - in pypy/branch/pyjitpl5/pypy: annotation rpython/test

antocuni at codespeak.net antocuni at codespeak.net
Tue Apr 28 16:15:05 CEST 2009


Author: antocuni
Date: Tue Apr 28 16:15:05 2009
New Revision: 64778

Modified:
   pypy/branch/pyjitpl5/pypy/annotation/binaryop.py
   pypy/branch/pyjitpl5/pypy/annotation/builtin.py
   pypy/branch/pyjitpl5/pypy/rpython/test/test_rclass.py
Log:
merge r54816 from oo-jit/:

        svn merge svn+ssh://codespeak.net/svn/pypy/branch/oo-jit/pypy/ -r54815:54816

        teach the annotator how to do union(SomeOOObject, SomeOOObject)




Modified: pypy/branch/pyjitpl5/pypy/annotation/binaryop.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/annotation/binaryop.py	(original)
+++ pypy/branch/pyjitpl5/pypy/annotation/binaryop.py	Tue Apr 28 16:15:05 2009
@@ -842,6 +842,7 @@
 # ____________________________________________________________
 # annotation of low-level types
 from pypy.annotation.model import SomePtr, SomeOOInstance, SomeOOClass
+from pypy.annotation.model import SomeOOObject
 from pypy.annotation.model import ll_to_annotation, annotation_to_lltype
 from pypy.rpython.ootypesystem import ootype
 
@@ -916,6 +917,10 @@
     def union((obj, r2)):
         return pair(r2, obj).union()
 
+class __extend__(pairtype(SomeOOObject, SomeOOObject)):
+    def union((r1, r2)):
+        assert r1.ootype is ootype.Object and r2.ootype is ootype.Object
+        return SomeOOObject()
 
 #_________________________________________
 # weakrefs

Modified: pypy/branch/pyjitpl5/pypy/annotation/builtin.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/annotation/builtin.py	(original)
+++ pypy/branch/pyjitpl5/pypy/annotation/builtin.py	Tue Apr 28 16:15:05 2009
@@ -573,7 +573,9 @@
 
 def cast_from_object(T, obj):
     TYPE = T.const
-    if isinstance(TYPE, ootype.Instance):
+    if TYPE is ootype.Object:
+        return T
+    elif isinstance(TYPE, ootype.Instance):
         return SomeOOInstance(TYPE)
     elif isinstance(TYPE, ootype.Record):
         return SomeOOInstance(TYPE) # XXX: SomeOORecord?

Modified: pypy/branch/pyjitpl5/pypy/rpython/test/test_rclass.py
==============================================================================
--- pypy/branch/pyjitpl5/pypy/rpython/test/test_rclass.py	(original)
+++ pypy/branch/pyjitpl5/pypy/rpython/test/test_rclass.py	Tue Apr 28 16:15:05 2009
@@ -839,9 +839,8 @@
         assert destrb is not None
         assert destra is not None
 
-    def test_cast_object(self):
+    def test_cast_object_instance(self):
         A = ootype.Instance("Foo", ootype.ROOT)
-        B = ootype.Record({'x': ootype.Signed}) 
 
         def fn_instance():
             a = ootype.new(A)
@@ -852,6 +851,9 @@
             assert a is a3
         self.interpret(fn_instance, [])
 
+    def test_cast_object_record(self):
+        B = ootype.Record({'x': ootype.Signed}) 
+
         def fn_record():
             b = ootype.new(B)
             b.x = 42
@@ -860,7 +862,11 @@
             assert b2.x == 42
             assert b is b2
         self.interpret(fn_record, [])
-       
+
+    def test_cast_object_null(self):
+        A = ootype.Instance("Foo", ootype.ROOT)
+        B = ootype.Record({'x': ootype.Signed}) 
+
         def fn_null():
             a = ootype.null(A)
             b = ootype.null(B)
@@ -871,6 +877,8 @@
             assert ootype.cast_from_object(B, obj2) == b
         self.interpret(fn_null, [])
 
+    def test_cast_object_is_true(self):
+        A = ootype.Instance("Foo", ootype.ROOT)
         def fn_is_true(flag):
             if flag:
                 a = ootype.new(A)
@@ -880,3 +888,15 @@
             return bool(obj)
         assert self.interpret(fn_is_true, [True]) is True
         assert self.interpret(fn_is_true, [False]) is False
+
+    def test_cast_object_mix_null(self):
+        A = ootype.Instance("Foo", ootype.ROOT)
+        def fn_mix_null(flag):
+            a = ootype.new(A)
+            obj = ootype.cast_to_object(a)
+            if flag:
+                return obj
+            else:
+                return ootype.NULL
+        res = self.interpret(fn_mix_null, [False])
+        assert res is ootype.NULL



More information about the Pypy-commit mailing list