[pypy-svn] r48992 - in pypy/dist/pypy/translator: . c
rxe at codespeak.net
rxe at codespeak.net
Fri Nov 23 18:05:42 CET 2007
Author: rxe
Date: Fri Nov 23 18:05:42 2007
New Revision: 48992
Modified:
pypy/dist/pypy/translator/c/gc.py
pypy/dist/pypy/translator/exceptiontransform.py
Log:
(arigo, rxe) rewrite fetch/restore operations in exception transformer
Modified: pypy/dist/pypy/translator/c/gc.py
==============================================================================
--- pypy/dist/pypy/translator/c/gc.py (original)
+++ pypy/dist/pypy/translator/c/gc.py Fri Nov 23 18:05:42 2007
@@ -129,15 +129,6 @@
args = [funcgen.expr(v) for v in op.args]
return 'OP_FREE(%s);' % (args[0], )
- def OP_GC_FETCH_EXCEPTION(self, funcgen, op):
- result = funcgen.expr(op.result)
- return ('%s = RPyFetchExceptionValue();\n'
- 'RPyClearException();') % (result, )
-
- def OP_GC_RESTORE_EXCEPTION(self, funcgen, op):
- argh = funcgen.expr(op.args[0])
- return 'if (%s != NULL) RPyRaiseException(RPYTHON_TYPE_OF_EXC_INST(%s), %s);' % (argh, argh, argh)
-
def OP_GC__COLLECT(self, funcgen, op):
return ''
@@ -216,15 +207,6 @@
def convert_weakref_to(self, ptarget):
return boehm.convert_weakref_to(ptarget)
- def OP_GC_FETCH_EXCEPTION(self, funcgen, op):
- result = funcgen.expr(op.result)
- return ('%s = RPyFetchExceptionValue();\n'
- 'RPyClearException();') % (result, )
-
- def OP_GC_RESTORE_EXCEPTION(self, funcgen, op):
- argh = funcgen.expr(op.args[0])
- return 'if (%s != NULL) RPyRaiseException(RPYTHON_TYPE_OF_EXC_INST(%s), %s);' % (argh, argh, argh)
-
def OP_GC__COLLECT(self, funcgen, op):
return 'GC_gcollect(); GC_invoke_finalizers();'
Modified: pypy/dist/pypy/translator/exceptiontransform.py
==============================================================================
--- pypy/dist/pypy/translator/exceptiontransform.py (original)
+++ pypy/dist/pypy/translator/exceptiontransform.py Fri Nov 23 18:05:42 2007
@@ -86,6 +86,15 @@
exc_data.exc_type = etype
exc_data.exc_value = evalue
+ def rpyexc_fetch_exception():
+ evalue = rpyexc_fetch_value()
+ rpyexc_clear()
+ return evalue
+
+ def rpyexc_restore_exception(evalue):
+ if evalue:
+ rpyexc_raise(rclass.ll_inst_type(evalue), evalue)
+
def rpyexc_raise_runtime_error():
rpyexc_raise(runtime_error_ll_exc_type, runtime_error_ll_exc)
@@ -127,6 +136,16 @@
rpyexc_raise_runtime_error,
[], lltype.Void)
+ self.rpyexc_fetch_exception_ptr = self.build_func(
+ "RPyFetchException",
+ rpyexc_fetch_exception,
+ [], self.lltype_of_exception_value)
+
+ self.rpyexc_restore_exception_ptr = self.build_func(
+ "RPyRestoreException",
+ rpyexc_restore_exception,
+ [self.lltype_of_exception_value], lltype.Void)
+
self.mixlevelannotator.finish()
self.lltype_to_classdef = translator.rtyper.lltype_to_classdef_mapping()
@@ -162,6 +181,7 @@
n_gen_exc_checks = 0
for block in list(graph.iterblocks()):
self.replace_stack_unwind(block)
+ self.replace_fetch_restore_operations(block)
need_exc_matching, gen_exc_checks = self.transform_block(graph, block)
n_need_exc_matching_blocks += need_exc_matching
n_gen_exc_checks += gen_exc_checks
@@ -180,6 +200,16 @@
block.operations[i].opname = "direct_call"
block.operations[i].args = [self.rpyexc_raise_runtime_error_ptr]
+ def replace_fetch_restore_operations(self, block):
+ for i in range(len(block.operations)):
+ if block.operations[i].opname == 'gc_fetch_exception':
+ block.operations[i].opname = "direct_call"
+ block.operations[i].args = [self.rpyexc_fetch_exception_ptr]
+
+ if block.operations[i].opname == 'gc_restore_exception':
+ block.operations[i].opname = "direct_call"
+ block.operations[i].args.insert(0, self.rpyexc_restore_exception_ptr)
+
def transform_block(self, graph, block):
need_exc_matching = False
n_gen_exc_checks = 0
More information about the Pypy-commit
mailing list