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

pedronis at codespeak.net pedronis at codespeak.net
Mon Apr 4 18:53:02 CEST 2005


Author: pedronis
Date: Mon Apr  4 18:53:02 2005
New Revision: 10299

Added:
   pypy/dist/pypy/translator/ann_override.py   (contents, props changed)
Modified:
   pypy/dist/goal/translate_pypy.py
   pypy/dist/pypy/annotation/builtin.py
   pypy/dist/pypy/interpreter/pyframe.py
   pypy/dist/pypy/translator/translator.py
Log:
use override mechanism instead of a wrong annotation for sys.exc_info, 

targetpypy0 annotation terminates without needing to tweak the codebase
for record_interpreter_traceback



Modified: pypy/dist/goal/translate_pypy.py
==============================================================================
--- pypy/dist/goal/translate_pypy.py	(original)
+++ pypy/dist/goal/translate_pypy.py	Mon Apr  4 18:53:02 2005
@@ -27,6 +27,7 @@
 import autopath, sys, threading, pdb, os
 
 from pypy.translator.translator import Translator
+from pypy.translator.ann_override import pypy_overrides
 from pypy.annotation import model as annmodel
 from pypy.tool.cache import Cache
 from pypy.annotation.model import SomeObject
@@ -53,7 +54,7 @@
     if listen_port:
         run_async_server()
     if not options['-no-a']:
-        a = t.annotate(inputtypes)
+        a = t.annotate(inputtypes, overrides=pypy_overrides)
         a.simplify()
         t.frozen = True   # cannot freeze if we don't have annotations
         if not options['-no-mark-some-objects']:
@@ -175,7 +176,7 @@
         except ValueError:
             if os.path.isfile(arg+'.py'):
                 targetspec = arg
-            elif arg.startwith('-huge='):
+            elif arg.startswith('-huge='):
                 huge = int(arg[6:])
             else:                
                 assert arg in options, "unknown option %r" % (arg,)

Modified: pypy/dist/pypy/annotation/builtin.py
==============================================================================
--- pypy/dist/pypy/annotation/builtin.py	(original)
+++ pypy/dist/pypy/annotation/builtin.py	Mon Apr  4 18:53:02 2005
@@ -200,9 +200,6 @@
 def math_floor(x):
     return SomeObject()
 
-def exc_info(): # XXX
-    return SomeTuple((immutablevalue(None),)*3)
-
 # collect all functions
 import __builtin__
 BUILTIN_ANALYZERS = {}
@@ -217,4 +214,3 @@
 BUILTIN_ANALYZERS[sys.getrefcount] = count
 BUILTIN_ANALYZERS[math.fmod] = math_fmod
 BUILTIN_ANALYZERS[math.floor] = math_floor
-BUILTIN_ANALYZERS[sys.exc_info] = exc_info # xxx

Modified: pypy/dist/pypy/interpreter/pyframe.py
==============================================================================
--- pypy/dist/pypy/interpreter/pyframe.py	(original)
+++ pypy/dist/pypy/interpreter/pyframe.py	Mon Apr  4 18:53:02 2005
@@ -20,6 +20,11 @@
     compiler_flags |= getattr(__future__, fname).compiler_flag
 
 
+def cpython_tb():
+   """NOT_RPYTHON"""
+   import sys
+   return sys.exc_info()[2]   
+
 class PyFrame(eval.Frame):
     """Represents a frame for a regular Python function
     that needs to be interpreted.
@@ -93,15 +98,15 @@
                         # catch asynchronous exceptions and turn them
                         # into OperationErrors
                         except KeyboardInterrupt:
-                            import sys; tb = sys.exc_info()[2]
+                            tb = cpython_tb()
                             raise OperationError, OperationError(self.space.w_KeyboardInterrupt,
                                                    self.space.w_None), tb
                         except MemoryError:
-                            import sys; tb = sys.exc_info()[2]
+                            tb = cpython_tb()
                             raise OperationError, OperationError(self.space.w_MemoryError,
                                                    self.space.w_None), tb
                         except RuntimeError, e:
-                            import sys; tb = sys.exc_info()[2]
+                            tb = cpython_tb()
                             raise OperationError, OperationError(self.space.w_RuntimeError,
                                 self.space.wrap("internal error: " + str(e))), tb
 

Added: pypy/dist/pypy/translator/ann_override.py
==============================================================================
--- (empty file)
+++ pypy/dist/pypy/translator/ann_override.py	Mon Apr  4 18:53:02 2005
@@ -0,0 +1,20 @@
+# overrides for annotation specific to PyPy codebase
+from pypy.annotation.bookkeeper import getbookkeeper
+from pypy.interpreter import error
+from pypy.interpreter import pyframe
+
+
+def ignore(*args):
+    bk = getbookkeeper()
+    return bk.immutablevalue(None)
+
+pypy_overrides = {}
+
+def install(tgt, override):
+    if hasattr(tgt, 'im_func'):
+        tgt = tgt.im_func
+    pypy_overrides[tgt] = override
+
+install(pyframe.cpython_tb, ignore)
+install(error.OperationError.record_interpreter_traceback, ignore)
+

Modified: pypy/dist/pypy/translator/translator.py
==============================================================================
--- pypy/dist/pypy/translator/translator.py	(original)
+++ pypy/dist/pypy/translator/translator.py	Mon Apr  4 18:53:02 2005
@@ -128,14 +128,14 @@
             graph = self.getflowgraph(func)
             simplify_graph(graph)
 
-    def annotate(self, input_args_types, func=None):
+    def annotate(self, input_args_types, func=None, overrides={}):
         """annotate(self, input_arg_types[, func]) -> Annotator
 
         Provides type information of arguments. Returns annotator.
         """
         func = func or self.entrypoint
         if self.annotator is None:
-            self.annotator = RPythonAnnotator(self)
+            self.annotator = RPythonAnnotator(self, overrides=overrides)
         graph = self.getflowgraph(func)
         self.annotator.build_types(graph, input_args_types, func)
         return self.annotator



More information about the Pypy-commit mailing list