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

antocuni at codespeak.net antocuni at codespeak.net
Mon Oct 23 11:48:05 CEST 2006


Author: antocuni
Date: Mon Oct 23 11:48:02 2006
New Revision: 33544

Modified:
   pypy/dist/pypy/annotation/unaryop.py
   pypy/dist/pypy/rpython/ootypesystem/ootype.py
   pypy/dist/pypy/rpython/ootypesystem/test/test_ooann.py
Log:
Move the annotation <--> lltype mapping needed by overloading
resolution from the annotator to ootype, because it's ootypesystem
specific.



Modified: pypy/dist/pypy/annotation/unaryop.py
==============================================================================
--- pypy/dist/pypy/annotation/unaryop.py	(original)
+++ pypy/dist/pypy/annotation/unaryop.py	Mon Oct 23 11:48:02 2006
@@ -706,20 +706,12 @@
         inst = m.ootype._example()
         _, meth = m.ootype._lookup(m.name)
         if isinstance(meth, ootype._overloaded_meth):
-            ARGS = tuple([m._annotation_to_lltype(arg_s) for arg_s in args_s])
+            ARGS = tuple([meth._annotation_to_lltype(arg_s) for arg_s in args_s])
             METH = meth._resolve_overloading(ARGS)._TYPE
+            return meth._lltype_to_annotation(METH.RESULT)
         else:
             METH = ootype.typeOf(meth)
-        RESULT = METH.RESULT
-        return lltype_to_annotation(RESULT)
-
-    def _annotation_to_lltype(self, ann):
-        if isinstance(ann, SomeChar):
-            return ootype.Char
-        elif isinstance(ann, SomeString):
-            return ootype.String
-        else:
-            return annotation_to_lltype(ann)
+            return lltype_to_annotation(METH.RESULT)
 
 class __extend__(SomeOOStaticMeth):
     def simple_call(m, *args_s):

Modified: pypy/dist/pypy/rpython/ootypesystem/ootype.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/ootype.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/ootype.py	Mon Oct 23 11:48:02 2006
@@ -898,6 +898,24 @@
                 return meth
         raise TypeError, 'No suitable overloading found for method'
 
+    def _annotation_to_lltype(self, ann):
+        from pypy.annotation import model as annmodel
+        if isinstance(ann, annmodel.SomeChar):
+            return Char
+        elif isinstance(ann, annmodel.SomeString):
+            return String
+        else:
+            return annmodel.annotation_to_lltype(ann)
+
+    def _lltype_to_annotation(self, TYPE):
+        from pypy.annotation import model as annmodel
+        if TYPE is Char:
+            return annmodel.SomeChar()
+        elif TYPE is String:
+            return annmodel.SomeString()
+        else:
+            return annmodel.lltype_to_annotation(TYPE)
+
 
 class _overloaded_meth(_meth, _overloaded_mixin):
     _bound_class = _overloaded_bound_meth

Modified: pypy/dist/pypy/rpython/ootypesystem/test/test_ooann.py
==============================================================================
--- pypy/dist/pypy/rpython/ootypesystem/test/test_ooann.py	(original)
+++ pypy/dist/pypy/rpython/ootypesystem/test/test_ooann.py	Mon Oct 23 11:48:02 2006
@@ -256,14 +256,20 @@
 def test_overloaded_meth_string():
     C = Instance("test", ROOT, {},
                  {'foo': overload(meth(Meth([Char], Signed)),
-                                  meth(Meth([String], Float)))})
+                                  meth(Meth([String], Float))),
+                  'bar': overload(meth(Meth([Signed], Char)),
+                                  meth(Meth([Float], String)))})
     def fn1():
         return new(C).foo('a')
     def fn2():
         return new(C).foo('aa')
+    def fn3(x):
+        return new(C).bar(x)
     a = RPythonAnnotator()
     assert isinstance(a.build_types(fn1, []), annmodel.SomeInteger)
     assert isinstance(a.build_types(fn2, []), annmodel.SomeFloat)
+    assert isinstance(a.build_types(fn3, [int]), annmodel.SomeChar)
+    assert isinstance(a.build_types(fn3, [float]), annmodel.SomeString)
 
 def test_bad_overload():
     def fn():



More information about the Pypy-commit mailing list