[pypy-svn] r45524 - in pypy/dist/pypy/translator: cli cli/test test

antocuni at codespeak.net antocuni at codespeak.net
Mon Aug 6 17:12:39 CEST 2007


Author: antocuni
Date: Mon Aug  6 17:12:39 2007
New Revision: 45524

Modified:
   pypy/dist/pypy/translator/cli/function.py
   pypy/dist/pypy/translator/cli/gencli.py
   pypy/dist/pypy/translator/cli/prebuiltnodes.py
   pypy/dist/pypy/translator/cli/test/runtest.py
   pypy/dist/pypy/translator/test/test_exceptiontransform.py
Log:
some tweaks to gencli to make exception transformer working



Modified: pypy/dist/pypy/translator/cli/function.py
==============================================================================
--- pypy/dist/pypy/translator/cli/function.py	(original)
+++ pypy/dist/pypy/translator/cli/function.py	Mon Aug  6 17:12:39 2007
@@ -171,8 +171,6 @@
 
     def __init__(self, *args, **kwargs):
         OOFunction.__init__(self, *args, **kwargs)
-        self._set_args()
-        self._set_locals()
         namespace = getattr(self.graph.func, '_namespace_', None)
         str
         if namespace:
@@ -196,6 +194,9 @@
             OOFunction.record_ll_meta_exc(self, ll_meta_exc)
 
     def begin_render(self):
+        self._set_args()
+        self._set_locals()
+        
         returntype, returnvar = self.cts.llvar_to_cts(self.graph.getreturnvar())
         if self.is_method:
             args = self.args[1:] # self is implicit

Modified: pypy/dist/pypy/translator/cli/gencli.py
==============================================================================
--- pypy/dist/pypy/translator/cli/gencli.py	(original)
+++ pypy/dist/pypy/translator/cli/gencli.py	Mon Aug  6 17:12:39 2007
@@ -51,22 +51,25 @@
 
     def __init__(self, tmpdir, translator, entrypoint, config=None, exctrans=False):
         GenOO.__init__(self, tmpdir, translator, entrypoint, config)
+        if exctrans:
+            self.db.exceptiontransformer = translator.getexceptiontransformer()
+
         for node in get_prebuilt_nodes(translator, self.db):
             self.db.pending_node(node)
         self.assembly_name = entrypoint.get_name()
         self.tmpfile = tmpdir.join(self.assembly_name + '.il')
         self.const_stat = str(tmpdir.join('const_stat'))
 
+        if exctrans:
+            etrafo = self.db.exceptiontransformer
+            for graph in translator.graphs:
+                etrafo.create_exception_handling(graph)
+
         if translator.config.translation.backendopt.stack_optimization:
             for graph in translator.graphs:
                 SSI_to_SSA(graph)
                 build_trees(graph)
 
-        if exctrans:
-            etrafo = translator.getexceptiontransformer()
-            for graph in translator.graphs:
-                etrafo.create_exception_handling(graph)
-
     def generate_source(self):
         GenOO.generate_source(self)
         self.db.const_count.dump(self.const_stat)

Modified: pypy/dist/pypy/translator/cli/prebuiltnodes.py
==============================================================================
--- pypy/dist/pypy/translator/cli/prebuiltnodes.py	(original)
+++ pypy/dist/pypy/translator/cli/prebuiltnodes.py	Mon Aug  6 17:12:39 2007
@@ -50,4 +50,17 @@
     prebuilt_nodes = _build_helpers(translator, db)
     raise_OSError_graph = translator.rtyper.exceptiondata.fn_raise_OSError.graph
     prebuilt_nodes.append(Helper(db, raise_OSError_graph, 'raise_OSError'))
+
+    try:
+        etrafo = db.exceptiontransformer
+    except AttributeError:
+        pass
+    else:
+        for name in ('rpyexc_clear',
+                     'rpyexc_fetch_type',
+                     'rpyexc_fetch_value',
+                     'rpyexc_occured',
+                     'rpyexc_raise'):
+            sm = getattr(etrafo, name+'_ptr').value
+            prebuilt_nodes.append(Function(db, sm.graph, name))
     return prebuilt_nodes

Modified: pypy/dist/pypy/translator/cli/test/runtest.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/runtest.py	(original)
+++ pypy/dist/pypy/translator/cli/test/runtest.py	Mon Aug  6 17:12:39 2007
@@ -90,15 +90,28 @@
                     ilasm.leave('return')
                 ilasm.end_catch()
 
+            # check for USE_LAST exceptions
             ilasm.label('check_last_exception')
             ilasm.opcode('ldsfld', 'object last_exception')
-            ilasm.opcode('brnull', 'print_result')
+            ilasm.opcode('brnull', 'check_etrafo_exception')
             # there is a pending exception
             ilasm.opcode('ldsfld', 'object last_exception')
             ilasm.call('string class [pypylib]pypy.test.Result::FormatException(object)')
             ilasm.call('void class [mscorlib]System.Console::WriteLine(string)')
             ilasm.opcode('br', 'return')
 
+            # check for exception tranformer exceptions
+            ilasm.label('check_etrafo_exception')
+            if hasattr(self.db, 'exceptiontransformer'):
+                ilasm.opcode('call', 'bool rpyexc_occured()')
+                ilasm.opcode('brfalse', 'print_result') # no exceptions
+                ilasm.opcode('call', 'Object rpyexc_fetch_value()')
+                ilasm.call('string class [pypylib]pypy.test.Result::FormatException(object)')
+                ilasm.call('void class [mscorlib]System.Console::WriteLine(string)')
+                ilasm.opcode('br', 'return')
+            else:
+                ilasm.opcode('br', 'print_result')
+
         ilasm.label('print_result')
         if return_type != 'void':
             ilasm.opcode('ldloc', 'res')

Modified: pypy/dist/pypy/translator/test/test_exceptiontransform.py
==============================================================================
--- pypy/dist/pypy/translator/test/test_exceptiontransform.py	(original)
+++ pypy/dist/pypy/translator/test/test_exceptiontransform.py	Mon Aug  6 17:12:39 2007
@@ -220,5 +220,4 @@
 
     def compile(self, fn, inputargs):
         from pypy.translator.cli.test.runtest import compile_function
-        # XXX: set exctrans=True
-        return compile_function(fn, inputargs, auto_raise_exc=True, exctrans=False)
+        return compile_function(fn, inputargs, auto_raise_exc=True, exctrans=True)



More information about the Pypy-commit mailing list