[pypy-svn] r24832 - in pypy/branch/explicit-exceptions/translator/c: . src

cfbolz at codespeak.net cfbolz at codespeak.net
Thu Mar 23 00:00:59 CET 2006


Author: cfbolz
Date: Thu Mar 23 00:00:48 2006
New Revision: 24832

Modified:
   pypy/branch/explicit-exceptions/translator/c/exceptiontransform.py
   pypy/branch/explicit-exceptions/translator/c/funcgen.py
   pypy/branch/explicit-exceptions/translator/c/src/trace.h
   pypy/branch/explicit-exceptions/translator/c/wrapper.py
Log:
(cfbolz, mwh, pedronis around):

intermediate checkin (breaking more tests, yay!): ripping out exceptions from
funcgen. commenting out some set_name calls of doubtful value in wrapper.
changing the FAIL macro to do nothing.


Modified: pypy/branch/explicit-exceptions/translator/c/exceptiontransform.py
==============================================================================
--- pypy/branch/explicit-exceptions/translator/c/exceptiontransform.py	(original)
+++ pypy/branch/explicit-exceptions/translator/c/exceptiontransform.py	Thu Mar 23 00:00:48 2006
@@ -106,6 +106,7 @@
             last_operation -= 1
         else:
             need_exc_matching = False
+        afterblock = block
         for i in range(last_operation, -1, -1):
             op = block.operations[i]
             print "considering op", op, i
@@ -119,10 +120,10 @@
             #non-exception case
             block.exits[0].exitcase = block.exits[0].llexitcase = False
         if need_exc_matching:
-            if not self.raise_analyzer.can_raise(op):
-                print "XXX: operation %s cannot raise, but has exception guarding in graph %s" (op, graph)
-                block.exitswitch = None
-                block.exits = [block.exits[0]]
+            if not self.raise_analyzer.can_raise(block.operations[-1]):
+                print "XXX: operation %s cannot raise, but has exception guarding in graph %s" % (block.operations[-1], graph)
+                afterblock.exitswitch = None
+                afterblock.exits = [afterblock.exits[0]]
             else:
                 self.insert_matching(afterblock, graph)
 
@@ -172,7 +173,7 @@
         newop = SpaceOperation(op.opname, opargs, result)
         startblock = Block(inputargs)
         startblock.operations.append(newop) 
-        newgraph = FunctionGraph("dummy", startblock)
+        newgraph = FunctionGraph("dummy_exc1", startblock)
         startblock.closeblock(Link([result], newgraph.returnblock))
         startblock.exits = list(startblock.exits)
         newgraph.returnblock.inputargs[0].concretetype = op.result.concretetype
@@ -197,7 +198,7 @@
         block.exits[True].target = excblock
         block.exits[True].args = []
         FUNCTYPE = lltype.FuncType(ARGTYPES, op.result.concretetype)
-        fptr = Constant(lltype.functionptr(FUNCTYPE, "dummy", graph=newgraph),
+        fptr = Constant(lltype.functionptr(FUNCTYPE, "dummy_exc2", graph=newgraph),
                         lltype.Ptr(FUNCTYPE))
         self.translator.graphs.append(newgraph)
         return newgraph, SpaceOperation("direct_call", [fptr] + callargs, op.result) 

Modified: pypy/branch/explicit-exceptions/translator/c/funcgen.py
==============================================================================
--- pypy/branch/explicit-exceptions/translator/c/funcgen.py	(original)
+++ pypy/branch/explicit-exceptions/translator/c/funcgen.py	Thu Mar 23 00:00:48 2006
@@ -57,11 +57,6 @@
             for op in block.operations:
                 mix.extend(op.args)
                 mix.append(op.result)
-                if getattr(op, "cleanup", None) is not None:
-                    cleanup_finally, cleanup_except = op.cleanup
-                    for cleanupop in cleanup_finally + cleanup_except:
-                        mix.extend(cleanupop.args)
-                        mix.append(cleanupop.result)
             for link in block.exits:
                 mix.extend(link.getextravars())
                 mix.extend(link.args)
@@ -188,31 +183,13 @@
             yield ''
             yield 'block%d:' % myblocknum
             for i, op in enumerate(block.operations):
-                err   = 'err%d_%d' % (myblocknum, i)
-                for line in self.gen_op(op, err):
+                for line in self.gen_op(op, "should_never_be_reached"):
                     yield line
-                # XXX hackish -- insert the finally code unless the operation
-                # already did
-                cleanup = getattr(op, 'cleanup', None)
-                if (cleanup is not None and
-                    op.opname not in ("direct_call", "indirect_call")):
-                    cleanup_finally, cleanup_except = cleanup
-                    for subop in cleanup_finally:
-                        for line in self.gen_op(subop, "should_never_be_jumped_to2"):
-                            yield line
-            fallthrough = False
             if len(block.exits) == 0:
-                if len(block.inputargs) == 2:   # exc_cls, exc_value
-                    # exceptional return block
-                    exc_cls   = self.expr(block.inputargs[0])
-                    exc_value = self.expr(block.inputargs[1])
-                    yield 'RPyRaiseException(%s, %s);' % (exc_cls, exc_value)
-                    for line in self.return_with_error():
-                        yield line 
-                else:
-                    # regular return block
-                    retval = self.expr(block.inputargs[0])
-                    yield 'return %s;' % retval
+                assert len(block.inputargs) == 1
+                # regular return block
+                retval = self.expr(block.inputargs[0])
+                yield 'return %s;' % retval
                 continue
             elif block.exitswitch is None:
                 # single-exit block
@@ -220,48 +197,8 @@
                 for op in self.gen_link(block.exits[0]):
                     yield op
                 yield ''
-            elif block.exitswitch == c_last_exception:
-                # block catching the exceptions raised by its last operation
-                # we handle the non-exceptional case first
-                link = block.exits[0]
-                assert link.exitcase is None
-                for op in self.gen_link(link):
-                    yield op
-                # we must catch the exception raised by the last operation,
-                # which goes to the last err%d_%d label written above.
-                yield ''
-                yield 'err%d_%d:' % (myblocknum, len(block.operations) - 1)
-                yield ''
-                for link in block.exits[1:]:
-                    assert issubclass(link.exitcase, Exception)
-                    try:
-                        etype = link.llexitcase
-                    except AttributeError:
-                        etype = pyobjectptr(link.exitcase)
-                        T1 = PyObjPtr
-                        T2 = PyObjPtr
-                    else:
-                        assert hasattr(link.last_exception, 'concretetype')
-                        assert hasattr(link.last_exc_value, 'concretetype')
-                        T1 = link.last_exception.concretetype
-                        T2 = link.last_exc_value.concretetype
-                    typ1 = self.db.gettype(T1)
-                    typ2 = self.db.gettype(T2)
-                    yield 'if (RPyMatchException(%s)) {' % (self.db.get(etype),)
-                    yield '\t%s;' % cdecl(typ1, 'exc_cls')
-                    yield '\t%s;' % cdecl(typ2, 'exc_value')
-                    yield '\tRPyFetchException(exc_cls, exc_value, %s);' % (
-                        cdecl(typ2, ''))
-                    d = {}
-                    if isinstance(link.last_exception, Variable):
-                        d[link.last_exception] = 'exc_cls'
-                    if isinstance(link.last_exc_value, Variable):
-                        d[link.last_exc_value] = 'exc_value'
-                    for op in self.gen_link(link, d):
-                        yield '\t' + op
-                    yield '}'
-                fallthrough = True
             else:
+                assert block.exitswitch != c_last_exception
                 # block ending in a switch on a value
                 TYPE = self.lltypemap(block.exitswitch)
                 if TYPE in (Bool, PyObjPtr):
@@ -315,32 +252,6 @@
                     raise TypeError("exitswitch type not supported"
                                     "  Got %r" % (TYPE,))
 
-            errorcases = {}
-            for i, op in list(enumerate(block.operations))[::-1]:
-                if getattr(op, 'cleanup', None) is None:
-                    continue
-                cleanup_finally, cleanup_except = op.cleanup
-                errorcases.setdefault(cleanup_except, []).append(i)
-
-            if fallthrough:
-                cleanup_finally, firstclean = block.operations[-1].cleanup
-                first = errorcases[firstclean]
-                del errorcases[firstclean]
-                first.remove(len(block.operations) - 1)
-                items = errorcases.items()
-                items.insert(0, (firstclean, first))
-            else:
-                items = errorcases.items()
-
-            for cleanupops, labels in items:
-                for label in labels:
-                    yield 'err%d_%d:' % (myblocknum, label)
-                for cleanupop in cleanupops:
-                    for line in self.gen_op(cleanupop, 'should_never_be_jumped_to'):
-                        yield line
-                for line in self.return_with_error():
-                    yield line
-
     def gen_link(self, link, linklocalvars=None):
         "Generate the code to jump across the given Link."
         is_alive = {}
@@ -430,21 +341,6 @@
             # skip assignment of 'void' return value
             r = self.expr(op.result)
             line = '%s = %s' % (r, line)
-        try:
-            cleanup = op.cleanup
-        except AttributeError:
-            raise AttributeError("%r without explicit .cleanup"
-                                 %  (op,))
-        if cleanup is not None:
-            # insert the 'finally' operations before the exception check
-            cleanup_finally, cleanup_except = op.cleanup
-            if cleanup_finally:
-                finally_lines = ['/* finally: */']
-                for cleanupop in cleanup_finally:
-                    finally_lines.extend(
-                        self.gen_op(cleanupop, 'should_never_be_jumped_to'))
-                line = '%s\n%s' % (line, '\n\t'.join(finally_lines))
-            line = '%s\n%s' % (line, self.check_directcall_result(op, err))
         return line
 
     # the following works since the extra arguments that indirect_call has

Modified: pypy/branch/explicit-exceptions/translator/c/src/trace.h
==============================================================================
--- pypy/branch/explicit-exceptions/translator/c/src/trace.h	(original)
+++ pypy/branch/explicit-exceptions/translator/c/src/trace.h	Thu Mar 23 00:00:48 2006
@@ -32,7 +32,9 @@
 
 #else /* !defined(USE_CALL_TRACE) */
 
-#define FAIL(err) goto err
+/* XXX we need to be more clever when exception handling actually checks for
+ * specific error values */
+#define FAIL(err) /*goto err */ 
 
 #endif /* defined(USE_CALL_TRACE) */
 

Modified: pypy/branch/explicit-exceptions/translator/c/wrapper.py
==============================================================================
--- pypy/branch/explicit-exceptions/translator/c/wrapper.py	(original)
+++ pypy/branch/explicit-exceptions/translator/c/wrapper.py	Thu Mar 23 00:00:48 2006
@@ -69,7 +69,7 @@
             vlist.append(Constant(default_value))
 
         v = newops.genop(opname, vlist, resulttype=Ptr(PyObject))
-        v.set_name('a', i)
+        #v.set_name('a', i)
         varguments.append(v)
 
     if vararg:
@@ -79,7 +79,7 @@
                  Constant(None),
                  ]
         vararg = newops.genop('getslice', vlist, resulttype=Ptr(PyObject))
-        vararg.set_name('vararg', 0)
+        #vararg.set_name('vararg', 0)
         varguments.append(vararg)
     else:
         # "check_no_more_arg(fname, n, vargs)"



More information about the Pypy-commit mailing list