[pypy-svn] r20216 - in pypy/branch/somepbc-refactoring/pypy: annotation rpython

arigo at codespeak.net arigo at codespeak.net
Thu Nov 24 19:31:05 CET 2005


Author: arigo
Date: Thu Nov 24 19:31:04 2005
New Revision: 20216

Modified:
   pypy/branch/somepbc-refactoring/pypy/annotation/description.py
   pypy/branch/somepbc-refactoring/pypy/annotation/model.py
   pypy/branch/somepbc-refactoring/pypy/rpython/rpbc.py
Log:
(pedronis, mwh)

Two more fixes: don't create a FunctionsPBCRepr for a function that's
never called and be more aware of SomePBC.can_be_None.

One more test passes in test_rpbc.


Modified: pypy/branch/somepbc-refactoring/pypy/annotation/description.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/annotation/description.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/annotation/description.py	Thu Nov 24 19:31:04 2005
@@ -75,6 +75,15 @@
             return object.__repr__(self)
         return '<%s for %r>' % (self.__class__.__name__, pyobj)
 
+    def querycallfamily(self):
+        """Retrieve the CallFamily object if there is one, otherwise
+           return None."""
+        call_families = self.bookkeeper.pbc_maximal_call_families
+        try:
+            return call_families[self]
+        except KeyError:
+            return None
+
     def getcallfamily(self):
         """Get the CallFamily object. Possibly creates one."""
         call_families = self.bookkeeper.pbc_maximal_call_families

Modified: pypy/branch/somepbc-refactoring/pypy/annotation/model.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/annotation/model.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/annotation/model.py	Thu Nov 24 19:31:04 2005
@@ -314,7 +314,7 @@
                 knowntype = type
             if knowntype != object:
                 self.knowntype = knowntype
-            if len(descriptions) == 1:
+            if len(descriptions) == 1 and not can_be_None:
                 # hack for the convenience of direct callers to SomePBC():
                 # only if there is a single object in descriptions
                 desc, = descriptions

Modified: pypy/branch/somepbc-refactoring/pypy/rpython/rpbc.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/rpython/rpbc.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/rpython/rpbc.py	Thu Nov 24 19:31:04 2005
@@ -19,7 +19,10 @@
             return none_frozen_pbc_repr 
         kind = self.getKind()
         if issubclass(kind, description.FunctionDesc):
-            getRepr = FunctionsPBCRepr
+            if self.descriptions.keys()[0].querycallfamily():
+                getRepr = FunctionsPBCRepr
+            else:
+                getRepr = getFrozenPBCRepr
         elif issubclass(kind, description.ClassDesc):
             # user classes
             getRepr = rtyper.type_system.rpbc.ClassesPBCRepr
@@ -46,7 +49,7 @@
     def rtyper_makekey(self):
         lst = list(self.descriptions)
         lst.sort()
-        return tuple([self.__class__]+lst)
+        return tuple([self.__class__, self.can_be_None]+lst)
 
 builtin_descriptor_type = (
     type(len),                             # type 'builtin_function_or_method'
@@ -279,7 +282,7 @@
 def getFrozenPBCRepr(rtyper, s_pbc):
     descs = s_pbc.descriptions.keys()
     assert len(descs) >= 1
-    if len(descs) == 1:
+    if len(descs) == 1 and not s_pbc.can_be_None:
         return SingleFrozenPBCRepr(descs[0])
     else:
         access = descs[0].queryattrfamily()



More information about the Pypy-commit mailing list