# HG changeset patch # User paulb@jeremy # Date 1152970166 -7200 # Node ID 15fb8711f23010139a38625ed49805c41eb075c1 # Parent a3f9003353c7aeba8c2ca0625538bcd88c73e66e Added comments and fixed temporary value storage and retrieval in And and Or. diff -r a3f9003353c7 -r 15fb8711f230 simplify.py --- a/simplify.py Sat Jul 15 15:26:54 2006 +0200 +++ b/simplify.py Sat Jul 15 15:29:26 2006 +0200 @@ -200,12 +200,17 @@ subprogram = Subprogram(name=hex(id(and_)), acquire_locals=1, returns_value=1, params=[], star=None, dstar=None) self.current_subprograms.append(subprogram) + # In the subprogram, make instructions which store each operand, test + # for each operand's truth status, and if appropriate return from the + # subprogram with the value of the operand. + nodes = [] last = and_.nodes[-1] for node in and_.nodes: expr = self.dispatch(node) if node is not last: - invocation = Not(expr=Invoke(expr=LoadAttr(expr=StoreTemp(expr=expr), name="__true__"), + nodes.append(StoreTemp(expr=expr)) + invocation = Not(expr=Invoke(expr=LoadAttr(expr=LoadTemp(), name="__true__"), params=[], star=None, dstar=None)) nodes.append(Conditional(test=invocation, body=[Return(expr=LoadTemp())])) nodes.append(ReleaseTemp()) @@ -229,12 +234,17 @@ subprogram = Subprogram(name=hex(id(or_)), acquire_locals=1, returns_value=1, params=[], star=None, dstar=None) self.current_subprograms.append(subprogram) + # In the subprogram, make instructions which store each operand, test + # for each operand's truth status, and if appropriate return from the + # subprogram with the value of the operand. + nodes = [] last = or_.nodes[-1] for node in or_.nodes: expr = self.dispatch(node) if node is not last: - invocation = Invoke(expr=LoadAttr(expr=StoreTemp(expr=expr), name="__true__"), + nodes.append(StoreTemp(expr=expr)) + invocation = Invoke(expr=LoadAttr(expr=LoadTemp(), name="__true__"), params=[], star=None, dstar=None) nodes.append(Conditional(test=invocation, body=[Return(expr=LoadTemp())])) nodes.append(ReleaseTemp())