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

arigo at codespeak.net arigo at codespeak.net
Mon Apr 3 17:35:27 CEST 2006


Author: arigo
Date: Mon Apr  3 17:35:26 2006
New Revision: 25262

Modified:
   pypy/dist/pypy/annotation/description.py
   pypy/dist/pypy/rpython/rpbc.py
   pypy/dist/pypy/rpython/test/test_rpbc.py
Log:
(pedronis, arigo)

Yet another obscure rpbc case, this time requiring some more
information from the annotator.



Modified: pypy/dist/pypy/annotation/description.py
==============================================================================
--- pypy/dist/pypy/annotation/description.py	(original)
+++ pypy/dist/pypy/annotation/description.py	Mon Apr  3 17:35:26 2006
@@ -628,10 +628,18 @@
         super(FrozenDesc, self).__init__(bookkeeper, pyobj)
         if read_attribute is None:
             read_attribute = lambda attr: getattr(pyobj, attr)
-        self.read_attribute = read_attribute
+        self._read_attribute = read_attribute
+        self.attrcache = {}
         self.knowntype = new_or_old_class(pyobj)
         assert bool(pyobj), "__nonzero__ unsupported on frozen PBC %r" %(pyobj,)
 
+    def read_attribute(self, attr):
+        try:
+            return self.attrcache[attr]
+        except KeyError:
+            result = self.attrcache[attr] = self._read_attribute(attr)
+            return result
+
     def s_read_attribute(self, attr):
         try:
             value = self.read_attribute(attr)
@@ -648,13 +656,7 @@
             pass
         else:
             raise AssertionError("name clash: %r" % (name,))
-        def extended_read_attribute(attr):
-            if attr == name:
-                return value
-            else:
-                return previous_read_attribute(attr)
-        previous_read_attribute = self.read_attribute
-        self.read_attribute = extended_read_attribute
+        self.attrcache[name] = value
 
 
 class MethodOfFrozenDesc(Desc):

Modified: pypy/dist/pypy/rpython/rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/rpbc.py	(original)
+++ pypy/dist/pypy/rpython/rpbc.py	Mon Apr  3 17:35:26 2006
@@ -446,8 +446,8 @@
                 if r_value.lowleveltype is Void:
                     continue
                 try:
-                    thisattrvalue = frozendesc.read_attribute(attr)
-                except AttributeError:
+                    thisattrvalue = frozendesc.attrcache[attr]
+                except KeyError:
                     warning("Desc %r has no attribute %r" % (frozendesc, attr))
                     continue
                 llvalue = r_value.convert_const(thisattrvalue)

Modified: pypy/dist/pypy/rpython/test/test_rpbc.py
==============================================================================
--- pypy/dist/pypy/rpython/test/test_rpbc.py	(original)
+++ pypy/dist/pypy/rpython/test/test_rpbc.py	Mon Apr  3 17:35:26 2006
@@ -967,6 +967,20 @@
             assert res.item0 == f(i)[0]
             assert res.item1 == f(i)[1]
 
+    def test_pbc_imprecise_attrfamily(self):
+        fr1 = Freezing(); fr1.x = 5; fr1.y = [8]
+        fr2 = Freezing(); fr2.x = 6; fr2.y = ["string"]
+        def head(fr):
+            return fr.y[0]
+        def f(n):
+            if n == 1:
+                fr = fr1
+            else:
+                fr = fr2
+            return head(fr1) + fr.x
+        res = interpret(f, [2], type_system=self.ts)
+        assert res == 8 + 6
+
     def test_multiple_specialized_functions(self):
         def myadder(x, y):   # int,int->int or str,str->str
             return x+y



More information about the Pypy-commit mailing list