[pypy-svn] r10205 - in pypy/dist/pypy/translator: . test

pedronis at codespeak.net pedronis at codespeak.net
Thu Mar 31 20:20:47 CEST 2005


Author: pedronis
Date: Thu Mar 31 20:20:47 2005
New Revision: 10205

Modified:
   pypy/dist/pypy/translator/annrpython.py
   pypy/dist/pypy/translator/test/test_annrpython.py
Log:
simple way to specify annotation for functions we can't/want flow into



Modified: pypy/dist/pypy/translator/annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/annrpython.py	(original)
+++ pypy/dist/pypy/translator/annrpython.py	Thu Mar 31 20:20:47 2005
@@ -18,7 +18,7 @@
     """Block annotator for RPython.
     See description in doc/translation/annotation.txt."""
 
-    def __init__(self, translator=None):
+    def __init__(self, translator=None, overrides={}):
         self.translator = translator
         self.pendingblocks = {}  # map {block: function}
         self.bindings = {}       # map Variables to SomeValues
@@ -39,6 +39,8 @@
                 # history of binding_caused_by, kept in sync with
                 # bindingshistory
         self.return_bindings = {} # map return Variables to functions
+        # user-supplied annotation logic for functions we don't want to flow into
+        self.overrides = overrides
         # --- end of debugging information ---
         self.bookkeeper = Bookkeeper(self)
 
@@ -202,6 +204,9 @@
     #___ interface for annotator.factory _______
 
     def recursivecall(self, func, position_key, inputcells):
+        override = self.overrides.get(func, None)
+        if override is not None:
+            return override(*inputcells)
         parent_fn, parent_block, parent_index = position_key
         graph = self.getflowgraph(func, parent_fn, position_key)
         # self.notify[graph.returnblock] is a dictionary of call

Modified: pypy/dist/pypy/translator/test/test_annrpython.py
==============================================================================
--- pypy/dist/pypy/translator/test/test_annrpython.py	(original)
+++ pypy/dist/pypy/translator/test/test_annrpython.py	Thu Mar 31 20:20:47 2005
@@ -595,6 +595,25 @@
         assert isinstance(s, annmodel.SomeInstance)
         assert s.knowntype is snippet.Exc
 
+    def test_overrides(self):
+        import sys
+        excs = []
+        def record_exc(e):
+            """NOT_RPYTHON"""
+            excs.append(sys.exc_info)
+        def g():
+            pass
+        def f():
+            try:
+                g()
+            except Exception, e:
+                record_exc(e)
+        def ann_record_exc(s_e):
+            return a.bookkeeper.immutablevalue(None)
+        a = RPythonAnnotator(overrides={record_exc: ann_record_exc})
+        s = a.build_types(f, [])
+        assert s.const is None
+
     def test_freeze_protocol(self):
         class Stuff:
             def __init__(self, flag):



More information about the Pypy-commit mailing list