[pypy-svn] r20455 - pypy/branch/somepbc-refactoring/pypy/annotation

arigo at codespeak.net arigo at codespeak.net
Wed Nov 30 21:15:59 CET 2005


Author: arigo
Date: Wed Nov 30 21:15:59 2005
New Revision: 20455

Modified:
   pypy/branch/somepbc-refactoring/pypy/annotation/specialize.py
Log:
Don't look.  Piled up hacks until the test pass.


Modified: pypy/branch/somepbc-refactoring/pypy/annotation/specialize.py
==============================================================================
--- pypy/branch/somepbc-refactoring/pypy/annotation/specialize.py	(original)
+++ pypy/branch/somepbc-refactoring/pypy/annotation/specialize.py	Wed Nov 30 21:15:59 2005
@@ -2,7 +2,7 @@
 import types
 from pypy.tool.uid import uid
 from pypy.objspace.flow.model import Block, Link, Variable, SpaceOperation
-from pypy.objspace.flow.model import checkgraph
+from pypy.objspace.flow.model import Constant, checkgraph
 
 def default_specialize(funcdesc, args_s):
     argnames, vararg, kwarg = funcdesc.signature
@@ -73,9 +73,18 @@
     if func is None:
         raise Exception("memo call: no Python function object to call (%r)" %
                         (funcdesc,))
+    return memo1(funcdesc, func, s)
+
+# XXX OBSCURE to support methodmemo()... needs to find something more 
+#     reasonable :-(
+KEY_NUMBERS = {}
+
+def memo1(funcdesc, func, s, key='memo1'):
+    from pypy.annotation.model import SomeImpossibleValue
     # compute the concrete results and store them directly on the descs,
     # using a strange attribute name
-    attrname = '$memo%d_%s' % (uid(funcdesc), funcdesc.name)
+    num = KEY_NUMBERS.setdefault(key, len(KEY_NUMBERS))
+    attrname = '$memo%d_%d_%s' % (uid(funcdesc), num, funcdesc.name)
     for desc in s.descriptions:
         s_result = desc.s_read_attribute(attrname)
         if isinstance(s_result, SomeImpossibleValue):
@@ -86,12 +95,12 @@
             result = func(desc.pyobj)
             desc.create_new_attribute(attrname, result)
     # get or build the graph of the function that reads this strange attr
-    def memoized(x):
+    def memoized(x, y=None):
         return getattr(x, attrname)
     def builder(translator, func):
         return translator.buildflowgraph(memoized)   # instead of 'func'
-    return funcdesc.cachedgraph('memo1', alt_name='memo_%s' % funcdesc.name, 
-                                         builder=builder)
+    return funcdesc.cachedgraph(key, alt_name='memo_%s' % funcdesc.name, 
+                                     builder=builder)
 
 def methodmemo(funcdesc, arglist_s):
     """NOT_RPYTHON"""
@@ -121,6 +130,9 @@
     # polymorphism.
     s1, s2 = arglist_s
     s1_type = s1.knowntype
+    if s2.is_constant():
+        return memo1(funcdesc, lambda val1: func(val1, s2.const),
+                    s1, ('memo1of2', s1_type, Constant(s2.const)))
     memosig = "%d_%d_%s" % (uid(funcdesc), uid(s1_type), funcdesc.name)
 
     attrname = '$memoreader%s' % memosig 



More information about the Pypy-commit mailing list