[pypy-svn] r13017 - pypy/dist/pypy/translator/goal

pedronis at codespeak.net pedronis at codespeak.net
Thu Jun 2 22:26:32 CEST 2005


Author: pedronis
Date: Thu Jun  2 22:26:32 2005
New Revision: 13017

Modified:
   pypy/dist/pypy/translator/goal/query.py
Log:
pbccall, query about pbc call families



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  2 22:26:32 2005
@@ -83,3 +83,81 @@
     bk = translator.annotator.bookkeeper
     xs = bk.seen_mutable.keys()
     print len(xs), ' '.join(map(strfy,rep(xs)))
+
+def prettypatt(patts):
+    accum = []
+    wslf = False
+    woslf = False
+    patts.sort()
+    for slf, (sh_cnt, sh_ks, sh_st, sh_stst)  in patts:
+        arg = []
+        if slf is None:
+            woslf = True
+        else:
+            wslf = True
+            arg.append(slf)
+        arg.append("+%d" % sh_cnt)
+        for kw in sh_ks:
+            arg.append("%s=" % kw)
+        if sh_st:
+           arg.append('*')
+        if sh_stst:
+           arg.append('**')
+        accum.append("(%s)" % ', '.join(arg))
+    if wslf and woslf:
+        accum.append("!!!")
+    return ' '.join(accum)
+        
+
+def pbccall(translator):
+    fams = translator.annotator.getpbccallfamilies().root_info.itervalues()
+    one_pattern_fams = {}
+    rest = []
+    for fam in fams:
+        patts = {}
+        for clsdef, sh in fam.patterns:
+            if clsdef is None:
+                slf = None
+            else:
+                slf = 'self'
+            patts[(slf, sh)] = True
+        if len(patts) != 1:
+            rest.append((len(fam.objects), fam.objects, patts.keys()))
+        else:
+            cntrs = one_pattern_fams.setdefault(patts.keys()[0], [0,0])
+            cntrs[0] += 1
+            cntrs[1] += len(fam.objects)
+
+    def pretty_nfam(nfam):
+        if nfam == 1:
+            return "1 family"
+        else:
+            return "%d families" % nfam
+
+    def pretty_nels(nels):
+        if nels == 1:
+            return "one callable"
+        else:
+            return "in total %d callables" % nels
+
+    def pretty_els(objs):
+        accum = []
+        for obj in objs:
+            if isinstance(obj, types.FunctionType):
+                accum.append("%s:%s" % (obj.__module__ or '?',  obj.__name__))
+            else:
+                accum.append(str(obj))
+        return "{%s}" % ' '.join(accum)
+        
+    for patt, (nfam, nels) in one_pattern_fams.iteritems():
+        print pretty_nfam(nfam), "with", pretty_nels(nels), "with one call-pattern:",  prettypatt([patt])
+
+    print "- * -"
+
+    rest.sort(lambda a,b: cmp(a[0], b[0]))
+
+    for n, objs, patts in rest:
+        print "family of", pretty_els(objs), "with call-patterns:", prettypatt(patts)
+        
+        
+    



More information about the Pypy-commit mailing list