[pypy-svn] r13467 - in pypy/dist/pypy: annotation translator translator/goal

pedronis at codespeak.net pedronis at codespeak.net
Thu Jun 16 05:26:57 CEST 2005


Author: pedronis
Date: Thu Jun 16 05:26:56 2005
New Revision: 13467

Modified:
   pypy/dist/pypy/annotation/bookkeeper.py
   pypy/dist/pypy/translator/annrpython.py
   pypy/dist/pypy/translator/goal/query.py
Log:

start of simple support for keeping statics and infos while annotating of for example violations to
additional constraints imposed by rtyper,

for example for newslice and the rules (slightly different form what rtyper right now supports):

        if ((s_start.is_constant() or (isinstance(s_start, SomeInteger) and s_start.nonneg)) and
            (s_stop.is_constant() or (isinstance(s_stop, SomeInteger) and s_stop.nonneg)) and
            (s_step.is_constant() and (s_step.const == 1 or s_step.const == None))):
            return 'proper'
        return 'inproper'

we get after translate_pypy annotation:

(Pdb) query.statsfor(t, 'newslice')
newslice total = 39
   proper | 30
 improper | 9



Modified: pypy/dist/pypy/annotation/bookkeeper.py
==============================================================================
--- pypy/dist/pypy/annotation/bookkeeper.py	(original)
+++ pypy/dist/pypy/annotation/bookkeeper.py	Thu Jun 16 05:26:56 2005
@@ -39,6 +39,26 @@
         self.objects.update(other.objects)
         self.patterns.update(other.patterns)
 
+class Stats:
+
+    def __init__(self, bookkeeper):
+        self.bookkeeper = bookkeeper
+        self.classify = {}
+
+    def count(self, category, *args):
+        for_category = self.classify.setdefault(category, {})
+        classifier = getattr(self, 'consider_%s' % category)
+        outcome = classifier(*args)
+        for_category[self.bookkeeper.position_key] = outcome
+
+    def consider_newslice(self, s_start, s_stop, s_step):
+        if ((s_start.is_constant() or (isinstance(s_start, SomeInteger) and s_start.nonneg)) and
+            (s_stop.is_constant() or (isinstance(s_stop, SomeInteger) and s_stop.nonneg)) and
+            (s_step.is_constant() and (s_step.const == 1 or s_step.const == None))):
+            return 'proper'
+        return 'improper'
+
+
 class Bookkeeper:
     """The log of choices that have been made while analysing the operations.
     It ensures that the same 'choice objects' will be returned if we ask
@@ -69,11 +89,15 @@
         
         self.pbc_call_sites = {}
 
-        
+        self.stats = Stats(self)
+
         # import ordering hack
         global BUILTIN_ANALYZERS
         from pypy.annotation.builtin import BUILTIN_ANALYZERS
 
+    def count(self, category, *args):
+        self.stats.count(category, *args)
+
     def enter(self, position_key):
         """Start of an operation.
         The operation is uniquely identified by the given key."""

Modified: pypy/dist/pypy/translator/annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/annrpython.py	(original)
+++ pypy/dist/pypy/translator/annrpython.py	Thu Jun 16 05:26:56 2005
@@ -611,6 +611,7 @@
         return self.bookkeeper.newdict(*items_s)
 
     def consider_op_newslice(self, start, stop, step):
+        self.bookkeeper.count('newslice', start, stop, step)
         return annmodel.SomeSlice(start, stop, step)
 
 

Modified: pypy/dist/pypy/translator/goal/query.py
==============================================================================
--- pypy/dist/pypy/translator/goal/query.py	(original)
+++ pypy/dist/pypy/translator/goal/query.py	Thu Jun 16 05:26:56 2005
@@ -311,6 +311,17 @@
             print " - many callables, many patterns -"
         print "family of", pretty_els(objs), "with call-patterns:", prettypatt(patts)
 
+def statsfor(t, category):
+    stats = t.annotator.bookkeeper.stats
+    for_category = stats.classify[category]
+    print "%s total = %d" % (category, len(for_category))
+    counters = {}
+    for pos, outcome in for_category.iteritems():
+        counters[outcome] = counters.get(outcome, 0) + 1
+    w = max([len(o) for o in counters.keys()])+1
+    for outcome, n in counters.iteritems():
+        print "%*s | %d" % (w, outcome, n)
+
 # debug helper
 def tryout(f, *args):
     try:



More information about the Pypy-commit mailing list