[pypy-svn] r39664 - in pypy/dist/pypy/annotation: . test

fijal at codespeak.net fijal at codespeak.net
Fri Mar 2 13:09:00 CET 2007


Author: fijal
Date: Fri Mar  2 13:08:58 2007
New Revision: 39664

Modified:
   pypy/dist/pypy/annotation/binaryop.py
   pypy/dist/pypy/annotation/test/test_annrpython.py
Log:
(fijal, guido) - unionof for two BasicExternals


Modified: pypy/dist/pypy/annotation/binaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/binaryop.py	(original)
+++ pypy/dist/pypy/annotation/binaryop.py	Fri Mar  2 13:08:58 2007
@@ -20,6 +20,7 @@
 from pypy.annotation.model import add_knowntypedata, merge_knowntypedata
 from pypy.annotation.model import lltype_to_annotation
 from pypy.annotation.model import SomeGenericCallable
+from pypy.annotation.model import SomeExternalBuiltin
 from pypy.annotation.bookkeeper import getbookkeeper
 from pypy.objspace.flow.model import Variable
 from pypy.annotation.listdef import ListDef
@@ -747,6 +748,20 @@
             return SomeExternalObject(ext1.knowntype)
         return SomeObject()
 
+class __extend__(pairtype(SomeExternalBuiltin, SomeExternalBuiltin)):
+    def union((ext1, ext2)):
+        def commonsuperclass(cls1, cls2):
+            cls = cls2
+            while not issubclass(cls1, cls):
+                cls = cls.__bases__[0]
+            return cls
+        
+        from pypy.rpython.ootypesystem.bltregistry import BasicExternal, ExternalType
+        cls = commonsuperclass(ext1.knowntype._class_, ext2.knowntype._class_)
+        if cls is BasicExternal:
+            return SomeObject()
+        return SomeExternalBuiltin(ExternalType(cls))
+
 # ____________________________________________________________
 # annotation of low-level types
 from pypy.annotation.model import SomePtr, SomeOOInstance, SomeOOClass

Modified: pypy/dist/pypy/annotation/test/test_annrpython.py
==============================================================================
--- pypy/dist/pypy/annotation/test/test_annrpython.py	(original)
+++ pypy/dist/pypy/annotation/test/test_annrpython.py	Fri Mar  2 13:08:58 2007
@@ -2634,6 +2634,30 @@
         s = a.build_types(fun, [bool])
         assert isinstance(s, annmodel.SomeInteger)
 
+    def test_unionof_some_external_builtin(self):
+        from pypy.rpython.ootypesystem.bltregistry import BasicExternal
+        
+        class A(BasicExternal):
+            pass
+
+        class B(A):
+            pass
+
+        class C(A):
+            pass
+
+        def f(x):
+            if x:
+                return B()
+            else:
+                return C()
+
+        P = policy.AnnotatorPolicy()
+        P.allow_someobjects = False
+        a = self.RPythonAnnotator(policy=P)
+        s = a.build_types(f, [bool])
+        assert isinstance(s, annmodel.SomeExternalBuiltin)        
+
 def g(n):
     return [0,1,2,n]
 
@@ -2651,3 +2675,4 @@
 class Freezing:
     def _freeze_(self):
         return True
+



More information about the Pypy-commit mailing list