[pypy-svn] r2984 - in pypy/trunk/src/pypy: annotation translator translator/tool

arigo at codespeak.net arigo at codespeak.net
Mon Feb 16 21:00:06 CET 2004


Author: arigo
Date: Mon Feb 16 21:00:04 2004
New Revision: 2984

Modified:
   pypy/trunk/src/pypy/annotation/annset.py
   pypy/trunk/src/pypy/annotation/model.py
   pypy/trunk/src/pypy/translator/annrpython.py
   pypy/trunk/src/pypy/translator/tool/traceann.py
Log:
Removed a few XXX in Samuele's getattr/setattr support for user-defined
classes.


Modified: pypy/trunk/src/pypy/annotation/annset.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/annset.py	(original)
+++ pypy/trunk/src/pypy/annotation/annset.py	Mon Feb 16 21:00:04 2004
@@ -119,6 +119,14 @@
             self.kill(predicate, subject)
             self.set(predicate, subject, newanswer)
 
+    def set_or_generalize(self, predicate, subject, otherpossibleanswer):
+        """This is a hack.  Do not use for SomeValues that could be merged."""
+        about = self._about(subject)
+        if predicate in about.annotations:
+            self.generalize(predicate, subject, otherpossibleanswer)
+        else:
+            self.set(predicate, subject, otherpossibleanswer)
+
     def merge(self, oldvalue, newvalue):
         """Update the heap to account for the merging of oldvalue and newvalue.
         Return the merged somevalue."""

Modified: pypy/trunk/src/pypy/annotation/model.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/model.py	(original)
+++ pypy/trunk/src/pypy/annotation/model.py	Mon Feb 16 21:00:04 2004
@@ -29,6 +29,7 @@
     const     = Predicate('const')
     type      = Predicate('type')
     immutable = Predicate('immutable')
+    instanceattr = PredicateFamily('instanceattr')
 
 
 def debugname(someval, prefix, _seen = {}):

Modified: pypy/trunk/src/pypy/translator/annrpython.py
==============================================================================
--- pypy/trunk/src/pypy/translator/annrpython.py	(original)
+++ pypy/trunk/src/pypy/translator/annrpython.py	Mon Feb 16 21:00:04 2004
@@ -29,8 +29,6 @@
         self.annotated = {}      # set of blocks already seen
         self.translator = translator
 
-        self.classes = {} # map classes to attr-name -> SomaValue dicts
-
     #___ convenience high-level interface __________________
 
     def build_types(self, flowgraph, input_arg_types):
@@ -217,39 +215,24 @@
     def consider_op_setattr(self,obj,attr,newval):
         objtype = self.heap.get(ANN.type,obj)
         if isinstance(objtype,type):
-            attrdict = self.classes.setdefault(objtype,{})
             attr = self.heap.get(ANN.const,attr)
-            if attr is not mostgeneralvalue:
-                oldval = attrdict.get(attr,impossiblevalue)
-                newval = self.heap.merge(oldval,newval)
-                # XXX
-                # if newval is not oldval (using isshared)
-                # we should reflow the places that depend on this
-                # we really need to make the attrdict an annotation
-                # on the type as const
-                # or invent a fake annotation
-                # that we get on getattr and kill and reset on setattr
-                # to trigger that
-                attrdict[attr] = newval
-            else:
-                raise ValueError,"setattr op with non-const attrname not expected"
+            if isinstance(attr, str):
+                # update the annotation 'instanceattr' about the class 'cls'
+                cls = self.constant(objtype)
+                self.heap.set_or_generalize(ANN.instanceattr[attr], cls, newval)
         return SomeValue()
 
     def consider_op_getattr(self,obj,attr):
         result = SomeValue()
         objtype = self.heap.get(ANN.type,obj)
         if isinstance(objtype,type):
-            attrdict = self.classes.setdefault(objtype,{})
             attr = self.heap.get(ANN.const,attr)
-            if attr is not mostgeneralvalue:
+            if isinstance(attr, str):
                 if hasattr(objtype,attr): # XXX shortcut to keep methods working
                     return result
-                oldval = attrdict.get(attr,impossiblevalue)
-                if oldval is impossiblevalue:
-                    return impossiblevalue
-                return oldval
-            else:
-                raise ValueError,"getattr op with non-const attrname not expected"
+                # return the current annotation for the class 'cls'
+                cls = self.constant(objtype)
+                return self.heap.get(ANN.instanceattr[attr], cls)
         return result
         
 

Modified: pypy/trunk/src/pypy/translator/tool/traceann.py
==============================================================================
--- pypy/trunk/src/pypy/translator/tool/traceann.py	(original)
+++ pypy/trunk/src/pypy/translator/tool/traceann.py	Mon Feb 16 21:00:04 2004
@@ -20,9 +20,9 @@
 from pypy.translator.translator import *
 from pypy.translator.test import snippet as test
 
-from pypy.translator.tool import tracer
-tracer.trace(AnnotationSet)
-tracer.trace(RPythonAnnotator)
+#from pypy.translator.tool import tracer
+#tracer.trace(AnnotationSet)
+#tracer.trace(RPythonAnnotator)
 
 try:
     snippet_name = sys.argv[1]
@@ -40,8 +40,8 @@
 lines = []
 for key, value in a.bindings.items():
     lines.append('%r: %r' % (key, value))
-for cl, attrdict in a.classes.items():
-    lines.append('%s: %r' % (cl.__name__,attrdict))
+#for cl, attrdict in a.classes.items():
+#    lines.append('%s: %r' % (cl.__name__,attrdict))
 lines.sort()
 for line in lines:
     print line


More information about the Pypy-commit mailing list