[pypy-svn] r7532 - in pypy/trunk/src/pypy: objspace/flow objspace/flow/test translator
arigo at codespeak.net
arigo at codespeak.net
Sat Nov 20 19:57:41 CET 2004
Author: arigo
Date: Sat Nov 20 19:57:40 2004
New Revision: 7532
Modified:
pypy/trunk/src/pypy/objspace/flow/flowcontext.py
pypy/trunk/src/pypy/objspace/flow/test/test_objspace.py
pypy/trunk/src/pypy/translator/simplify.py
Log:
most probably maybe this should be tested, but time is running out.
Modified: pypy/trunk/src/pypy/objspace/flow/flowcontext.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/flow/flowcontext.py (original)
+++ pypy/trunk/src/pypy/objspace/flow/flowcontext.py Sat Nov 20 19:57:40 2004
@@ -148,7 +148,8 @@
newblock.patchframe(frame, self)
self.joinpoints[next_instr].insert(0, newblock)
- def guessbool(self, w_condition, cases=[False,True]):
+ def guessbool(self, w_condition, cases=[False,True],
+ ignore_last_variable_except_in_first_case = False):
if isinstance(self.crnt_ops, list):
block = self.crnt_block
vars = block.getvariables()
@@ -158,6 +159,9 @@
self.pendingblocks.append(egg)
link = Link(vars, egg, case)
links.append(link)
+ if ignore_last_variable_except_in_first_case:
+ vars.remove(block.operations[-1].result)
+ ignore_last_variable_except_in_first_case = False
block.exitswitch = w_condition
block.closeblock(*links)
# forked the graph. Note that False comes before True by default
@@ -176,7 +180,8 @@
def guessexception(self, *classes):
return self.guessbool(Constant(last_exception),
- cases = [None] + list(classes))
+ cases = [None] + list(classes),
+ ignore_last_variable_except_in_first_case = True)
def build_flow(self):
from pypy.objspace.flow.objspace import UnwrapException
Modified: pypy/trunk/src/pypy/objspace/flow/test/test_objspace.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/flow/test/test_objspace.py (original)
+++ pypy/trunk/src/pypy/objspace/flow/test/test_objspace.py Sat Nov 20 19:57:40 2004
@@ -291,7 +291,7 @@
def test_catch_simple_call(self):
x = self.codetest(self.catch_simple_call)
- self.show(x)
+ self.reallyshow(x)
#__________________________________________________________
def dellocal():
Modified: pypy/trunk/src/pypy/translator/simplify.py
==============================================================================
--- pypy/trunk/src/pypy/translator/simplify.py (original)
+++ pypy/trunk/src/pypy/translator/simplify.py Sat Nov 20 19:57:40 2004
@@ -67,26 +67,38 @@
function removes such exceptions entierely. This gets rid for example
of possible IndexErrors by 'getitem', assuming they cannot happen unless
there is an exception handler in the same function."""
+ def is_except_link(link):
+ return (link.args == [Constant(last_exception)] and
+ len(link.target.exits) == 0 and
+ hasattr(link.target, 'exc_type'))
def visit(link):
if isinstance(link, Link) and link in link.prevblock.exits:
if (isinstance(link.exitcase, type(Exception)) and
- issubclass(link.exitcase, Exception) and
- link.args == [Constant(last_exception)] and
- len(link.target.exits) == 0 and
- hasattr(link.target, 'exc_type')):
- # remove direct links to implicit exception return blocks
- lst = list(link.prevblock.exits)
- lst.remove(link)
- link.prevblock.exits = tuple(lst)
+ issubclass(link.exitcase, Exception)):
+ # two cases: a jump directly to an exception-raising end block,
+ # or a jump to a block containing only a 'type' operation
+ # and then jumping to such an exception-raising end block.
+ # Argh.
+ block = link.target
+ if (is_except_link(link) or
+ (len(block.operations) == 1 and
+ block.operations[0].opname == 'type' and
+ len(block.exits) == 1 and
+ is_except_link(block.exits[0]) and
+ block.operations[0].result not in block.exits[0].args)):
+ # remove the link
+ lst = list(link.prevblock.exits)
+ lst.remove(link)
+ link.prevblock.exits = tuple(lst)
traverse(visit, graph)
def simplify_graph(graph, rpython=True):
"""inplace-apply all the existing optimisations to the graph."""
checkgraph(graph)
eliminate_empty_blocks(graph)
+ join_blocks(graph)
if rpython:
remove_implicit_exceptions(graph)
- join_blocks(graph)
checkgraph(graph)
def remove_direct_loops(graph):
More information about the Pypy-commit
mailing list