[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pypy-svn
Subject:    [pypy-svn] rev 2272 - in pypy/trunk/src/pypy/annotation: . test
From:       hpk () codespeak ! net
Date:       2003-11-27 16:27:22
Message-ID: 20031127162722.D4B0F5ACB1 () thoth ! codespeak ! net
[Download RAW message or body]

Author: hpk
Date: Thu Nov 27 17:27:21 2003
New Revision: 2272

Modified:
   pypy/trunk/src/pypy/annotation/annset.py
   pypy/trunk/src/pypy/annotation/model.py
   pypy/trunk/src/pypy/annotation/test/test_annset.py
Log:

- got rid of the 'snuff' predicate

- some more more little renamings for the fun of it (and while i am
  waiting on armin :-) 



Modified: pypy/trunk/src/pypy/annotation/annset.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/annset.py	(original)
+++ pypy/trunk/src/pypy/annotation/annset.py	Thu Nov 27 17:27:21 2003
@@ -1,6 +1,6 @@
 from __future__ import generators
 import types
-from model import Annotation, SomeValue, ann
+from model import Annotation, SomeValue, ANN
 from model import immutable_types, blackholevalue, basicannotations
 
 class AnnotationSet:
@@ -53,14 +53,18 @@
     __iter__ = enumerate
 
     def query(self, *querylist):
-        return [match for depends, match in self.getmatches(*querylist)]
+        return [matchvalue for matchanns, matchvalue in self.match(*querylist)]
+
+    def match(self, query, *querylist):
+        """ yield (matchanns, matchvalue) tuples with 'matchanns'
+        beeing a list of matching annotations and 'matchvalue' beeing
+        the queried value. """
 
-    def getmatches(self, query, *querylist):
         # slightly limited implementation for ease of coding :-)
         assert query.args.count(Ellipsis) == 1, (
             "sorry, the algorithm is a bit too naive for this case")
         queryarg = query.args.index(Ellipsis)
-        for ann in self._annmatch(query):
+        for ann in self._annmatches(query):
             # does the returned match also agree with the other queries?
             match = ann.args[queryarg]
             depends = [ann]
@@ -73,9 +77,10 @@
             else:
                 yield depends, match
 
-    def _annmatch(self, queryann):
+    def _annmatches(self, queryann):
+        """ yield annotations matching the given queryannotation. """
         testindices = [i for i in range(queryann.predicate.arity)
-                         if queryann.args[i] is not Ellipsis]
+                             if queryann.args[i] is not Ellipsis]
         for ann in self.annlist:
             if ann.predicate == queryann.predicate:
                 for i in testindices:
@@ -90,7 +95,7 @@
         # annotations; e.g. killing an annotation will take care
         # that all matching annotations are removed, and thus also 
         # all dependencies listed on any of the duplicate annotation.
-        for ann in self._annmatch(checkann):
+        for ann in self._annmatches(checkann):
             return ann  # :-)
         else:
             return None
@@ -159,9 +164,9 @@
 
     def query(self, *querylist):
         results = []
-        for depends, match in self.annset.getmatches(*querylist):                
-            self.using(*depends)
-            results.append(match)
+        for matchanns, matchvalue in self.annset.match(*querylist):                
+            self.using(*matchanns)
+            results.append(matchvalue)
         return results
 
     def set(self, ann):
@@ -173,15 +178,15 @@
             deps.append(ann)
 
     def check_type(self, someval, checktype):
-        return self.query(ann.type[someval, ...],
-                          ann.constant(checktype)[...])
+        return self.query(ANN.type[someval, ...],
+                          ANN.constant(checktype)[...])
 
     def set_type(self, someval, knowntype):
         typeval = SomeValue()
-        self.set(ann.type[someval, typeval])
-        self.set(ann.constant(knowntype)[typeval])
+        self.set(ANN.type[someval, typeval])
+        self.set(ANN.constant(knowntype)[typeval])
         if knowntype in immutable_types:
-            self.set(ann.immutable[someval])
+            self.set(ANN.immutable[someval])
 
 '''
     def merge(self, oldcell, newcell):
@@ -235,9 +240,8 @@
                 # apply changes
                 self.simplify(kill=deleting)
                 return newcell
-'''
-
 
+'''
 class XXXTransaction:
     """A transaction contains methods to look for annotations in the
     AnnotationHeap and create new annotations accordingly.  Each

Modified: pypy/trunk/src/pypy/annotation/model.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/model.py	(original)
+++ pypy/trunk/src/pypy/annotation/model.py	Thu Nov 27 17:27:21 2003
@@ -3,20 +3,6 @@
 class SomeValue:
     pass
 
-def debugname(someval, _seen = {}):
-    """ return a simple name for a SomeValue. """
-    try:
-        return _seen[id(someval)]
-    except KeyError:
-        if not _seen:
-            for name, value in globals().items():
-                if isinstance(value, SomeValue):
-                    _seen[id(value)] = name
-            return debugname(someval)
-        name = "V%d" % len(_seen)
-        _seen[id(someval)] = name
-        return name
-
 class Predicate:
     def __init__(self, debugname, arity):
         self.debugname = debugname
@@ -39,9 +25,8 @@
     def __hash__(self):
         return hash(self.value)
 
-class ann:
+class ANN:
     add = Predicate('add', 3)
-    snuff = Predicate('snuff', 2)   # for testing, to remove :-)
     constant = ConstPredicate
     type = Predicate('type', 2)
     immutable = Predicate('immutable', 1)
@@ -67,6 +52,19 @@
         return "Annotation(%s, %s)" % (
                 self.predicate, ", ".join(map(debugname, self.args)))
 
+def debugname(someval, _seen = {}):
+    """ return a simple name for a SomeValue. """
+    try:
+        return _seen[id(someval)]
+    except KeyError:
+        if not _seen:
+            for name, value in globals().items():
+                if isinstance(value, SomeValue):
+                    _seen[id(value)] = name
+            return debugname(someval)
+        name = "V%d" % len(_seen)
+        _seen[id(someval)] = name
+        return name
 
 immutable_types = {
     int: 'int',
@@ -86,6 +84,6 @@
 for _type, _name in immutable_types.items():
     _val = globals()['%svalue' % _name] = SomeValue()
     _tval = SomeValue()
-    basicannotations.append(ann.type[_val, _tval])
-    basicannotations.append(ann.constant(_type)[_tval])
-    basicannotations.append(ann.immutable[_val])
+    basicannotations.append(ANN.type[_val, _tval])
+    basicannotations.append(ANN.constant(_type)[_tval])
+    basicannotations.append(ANN.immutable[_val])

Modified: pypy/trunk/src/pypy/annotation/test/test_annset.py
==============================================================================
--- pypy/trunk/src/pypy/annotation/test/test_annset.py	(original)
+++ pypy/trunk/src/pypy/annotation/test/test_annset.py	Thu Nov 27 17:27:21 2003
@@ -2,7 +2,7 @@
 import autopath
 from pypy.tool import test
 
-from pypy.annotation.model import ann, SomeValue
+from pypy.annotation.model import ANN, SomeValue
 from pypy.annotation.annset import AnnotationSet
 
 
@@ -36,41 +36,41 @@
         c1,c2,c3,c4 = SomeValue(), SomeValue(), SomeValue(), SomeValue()
         a = AnnotationSet()
         a.setshared(c1,c4)
-        self.assert_(a.annequal(ann.add[c1,c2,c3],
-                                ann.add[c4,c2,c3]))
+        self.assert_(a.annequal(ANN.add[c1,c2,c3],
+                                ANN.add[c4,c2,c3]))
     
     def test_query_one_annotation_arg(self):
         c1,c2,c3 = SomeValue(), SomeValue(), SomeValue()
-        lst = [ann.add[c1, c3, c2]]
+        lst = [ANN.add[c1, c3, c2]]
         a = AnnotationSet(lst)
-        c = a.query(ann.add[c1, c3, ...])
+        c = a.query(ANN.add[c1, c3, ...])
         self.assertEquals(c, [c2])
-        c = a.query(ann.add[c1, ..., c2])
+        c = a.query(ANN.add[c1, ..., c2])
         self.assertEquals(c, [c3])
-        c = a.query(ann.add[..., c3, c2])
+        c = a.query(ANN.add[..., c3, c2])
         self.assertEquals(c, [c1])
 
-        c = a.query(ann.add[..., c1, c2])
+        c = a.query(ANN.add[..., c1, c2])
         self.assertEquals(c, [])
 
     def test_query_multiple_annotations(self):
         c1,c2,c3 = SomeValue(), SomeValue(), SomeValue()
         lst = [
-            ann.add[c1, c3, c2],
-            ann.snuff[c2, c3],
+            ANN.add[c1, c3, c2],
+            ANN.type[c2, c3],
         ]
         a = AnnotationSet(lst)
-        c = a.query(ann.add[c1, c3, ...],
-                    ann.snuff[..., c3])
+        c = a.query(ANN.add[c1, c3, ...],
+                    ANN.type[..., c3])
         self.assertEquals(c, [c2])
 
     def test_constant(self):
         c1,c2,c3 = SomeValue(), SomeValue(), SomeValue()
         lst = [
-            ann.constant(42)[c1],
+            ANN.constant(42)[c1],
         ]
         a = AnnotationSet(lst)
-        c = a.query(ann.constant(42)[...])
+        c = a.query(ANN.constant(42)[...])
         self.assertEquals(c, [c1])
 
 c1,c2,c3,c4 = SomeValue(), SomeValue(), SomeValue(), SomeValue()
@@ -79,9 +79,9 @@
 
     def setUp(self):
         self.lst = [
-            ann.add[c1, c3, c2],
-            ann.type[c1, c4],
-            ann.constant(int)[c4],
+            ANN.add[c1, c3, c2],
+            ANN.type[c1, c4],
+            ANN.constant(int)[c4],
         ]
         self.annset = AnnotationSet(self.lst)
 
@@ -102,10 +102,10 @@
     def test_simple(self):
         a = self.annset
         def f(rec):
-            if rec.query(ann.add[c1, c3, ...]):
-                rec.set(ann.snuff[c1, c3]) 
+            if rec.query(ANN.add[c1, c3, ...]):
+                rec.set(ANN.type[c1, c3]) 
         a.record(f)
-        self.assertSameSet(a, a, self.lst + [ann.snuff[c1, c3]])
+        self.assertSameSet(a, a, self.lst + [ANN.type[c1, c3]])
 
         a.kill(self.lst[0])
         self.assertSameSet(a, a, self.lst[1:])
@@ -116,8 +116,8 @@
             if rec.check_type(c1, int):
                 rec.set_type(c2, str)
         a.record(f)
-        self.assert_(a.query(ann.type[c2, ...],
-                             ann.constant(str)[...]))
+        self.assert_(a.query(ANN.type[c2, ...],
+                             ANN.constant(str)[...]))
 
 if __name__ == '__main__':
     test.main()

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic