# HG changeset patch # User paulb@jeremy # Date 1153773227 -7200 # Node ID 41d4b988c94d91c0356566ef979207ac147956a9 # Parent be8dd5b882e40cec8c249fb5442d1a45ecc2cc81 Introduced subprograms for If node bodies so that local merging may be more obvious to the annotator. diff -r be8dd5b882e4 -r 41d4b988c94d simplify.py --- a/simplify.py Mon Jul 24 00:21:01 2006 +0200 +++ b/simplify.py Mon Jul 24 22:33:47 2006 +0200 @@ -170,6 +170,17 @@ def visitIf(self, if_): + """ + Convert If(tests=..., else_=...) to: + + Invoke -> Subprogram + Conditional (test) -> Invoke -> Subprogram (body) + Return + Conditional (test) -> Invoke -> Subprogram (body) + Return + ... + """ + # Make a subprogram for the statement and record it outside the main tree. subprogram = Subprogram(name=hex(id(if_)), acquire_locals=1, returns_value=0, params=[], star=None, dstar=None) @@ -185,13 +196,30 @@ test = Conditional(else_=[], test=Invoke( expr=LoadAttr(expr=self.dispatch(compare), name="__true__"), args=[], star=None, dstar=None)) - test.body = self.dispatch(stmt) + [Return()] + + body_subprogram = Subprogram(name=hex(id(stmt)), acquire_locals=1, returns_value=0, params=[], star=None, dstar=None) + self.current_subprograms.append(body_subprogram) + + body_subprogram.code = self.dispatch(stmt) + [Return()] + + self.current_subprograms.pop() + self.subprograms.append(body_subprogram) + + test.body = [Invoke(stmt, expr=LoadRef(ref=body_subprogram), same_frame=1, star=None, dstar=None, args=[]), Return()] nodes.append(test) # Add the compound statement from any else clause to the end. if if_.else_ is not None: - nodes += self.dispatch(if_.else_) + else_subprogram = Subprogram(name=hex(id(if_.else_)), acquire_locals=1, returns_value=0, params=[], star=None, dstar=None) + self.current_subprograms.append(else_subprogram) + + else_subprogram.code = self.dispatch(if_.else_) + [Return()] + + self.current_subprograms.pop() + self.subprograms.append(else_subprogram) + + nodes.append(Invoke(stmt, expr=LoadRef(ref=else_subprogram), same_frame=1, star=None, dstar=None, args=[])) subprogram.code = nodes