# HG changeset patch # User paulb@jeremy # Date 1161474233 -7200 # Node ID 747eeb273b45114abe0f61e0b1238744fa3f34e5 # Parent d5be469d8c12e0558ba21a92808de0211c972389 Removed redundant/confusing original node assignments. diff -r d5be469d8c12 -r 747eeb273b45 simplify.py --- a/simplify.py Sun Oct 22 00:23:03 2006 +0200 +++ b/simplify.py Sun Oct 22 01:43:53 2006 +0200 @@ -124,10 +124,10 @@ init_code = [] for value, constant in self.constants.items(): init_code.append( - StoreAttr(module, - lvalue=LoadRef(module, ref=constant), + StoreAttr( + lvalue=LoadRef(ref=constant), name="__class__", - expr=LoadName(module, name=constant.typename) + expr=LoadName(name=constant.typename) ) ) @@ -163,26 +163,26 @@ result = Assign(import_, 1) code = [] for path, alias in import_.names: - importer = Import(import_, name=path) + importer = Import(name=path) top = alias or path.split(".")[0] - code.append(StoreName(import_, expr=importer, name=top)) + code.append(StoreName(expr=importer, name=top)) result.code = code return result def visitFrom(self, from_): result = Assign(from_, 1) code = [] - code.append(StoreTemp(from_, expr=Import(from_, name=from_.modname))) + code.append(StoreTemp(expr=Import(name=from_.modname))) for name, alias in from_.names: code.append( - StoreName(from_, - expr=LoadAttr(from_, - expr=LoadTemp(from_), + StoreName( + expr=LoadAttr( + expr=LoadTemp(), name=name), name=(alias or name) ) ) - code.append(ReleaseTemp(from_)) + code.append(ReleaseTemp()) result.code = code return result @@ -192,7 +192,7 @@ def visitConst(self, const): if not self.constants.has_key(const.value): - self.constants[const.value] = Constant(const, name=repr(const.value), value=const.value) + self.constants[const.value] = Constant(name=repr(const.value), value=const.value) result = LoadRef(const, 1, ref=self.constants[const.value]) return result @@ -208,7 +208,7 @@ def visitContinue(self, continue_): result = InvokeBlock(continue_, 1, - expr=LoadRef(continue_, ref=self.current_subprograms[-1]) + expr=LoadRef(ref=self.current_subprograms[-1]) ) return result @@ -221,7 +221,7 @@ return result def _visitBuiltin(self, builtin, name): - result = InvokeFunction(builtin, 1, expr=LoadName(builtin, name=name), args=self.dispatches(builtin.nodes), star=None, dstar=None) + result = InvokeFunction(builtin, 1, expr=LoadName(name=name), args=self.dispatches(builtin.nodes), star=None, dstar=None) return result def visitTuple(self, tuple): @@ -231,10 +231,10 @@ return self._visitBuiltin(list, "list") def visitDict(self, dict): - result = InvokeFunction(dict, 1, expr=LoadName(dict, name="dict"), star=None, dstar=None) + result = InvokeFunction(dict, 1, expr=LoadName(name="dict"), star=None, dstar=None) args = [] for key, value in dict.items: - tuple = InvokeFunction(dict, expr=LoadName(dict, name="tuple"), star=None, dstar=None) + tuple = InvokeFunction(expr=LoadName(name="tuple"), star=None, dstar=None) tuple.set_args([self.dispatch(key), self.dispatch(value)]) args.append(tuple) result.set_args(args) @@ -275,8 +275,8 @@ # Set the first as the defining node. test = Conditional(if_, first, - test=InvokeFunction(if_, - expr=LoadAttr(if_, + test=InvokeFunction( + expr=LoadAttr( expr=self.dispatch(compare), name="__true__" ), @@ -340,10 +340,10 @@ else: new_spec = self.dispatch(spec) - test = Conditional(tryexcept, - test=InvokeFunction(tryexcept, - expr=LoadName(tryexcept, name="isinstance"), - args=[LoadExc(tryexcept), new_spec], + test = Conditional( + test=InvokeFunction( + expr=LoadName(name="isinstance"), + args=[LoadExc(), new_spec], star=None, dstar=None) ) @@ -351,26 +351,26 @@ if assign is not None: test.body.append( - Assign(tryexcept, + Assign( code=[ - StoreTemp(expr=LoadExc(tryexcept)), + StoreTemp(expr=LoadExc()), self.dispatch(assign), - ReleaseTemp(tryexcept) + ReleaseTemp() ] ) ) # Always return from conditional sections. - test.body += self.dispatch(stmt) + [Return(tryexcept)] + test.body += self.dispatch(stmt) + [Return()] nodes.append(test) nodes = test.else_ = [] # Add a raise operation to deal with unhandled exceptions. nodes.append( - Raise(tryexcept, - expr=LoadExc(tryexcept)) + Raise( + expr=LoadExc()) ) result.handler = results @@ -398,7 +398,7 @@ (else) -> ... """ - subprogram = Subprogram(compare, name=None, acquire_locals=1, returns_value=1, params=[], star=None, dstar=None) + subprogram = Subprogram(name=None, acquire_locals=1, returns_value=1, params=[], star=None, dstar=None) self.current_subprograms.append(subprogram) # In the subprogram, make instructions which invoke a method on the @@ -417,8 +417,8 @@ method_name = self.comparison_methods[op_name] if method_name: - invocation = InvokeFunction(compare, - expr=LoadAttr(compare, + invocation = InvokeFunction( + expr=LoadAttr( expr=previous, name=method_name), args=[expr], @@ -426,16 +426,16 @@ dstar=None) elif op_name == "is": - invocation = InvokeFunction(compare, - expr=LoadName(compare, name="__is__"), + invocation = InvokeFunction( + expr=LoadName(name="__is__"), args=[previous, expr], star=None, dstar=None) elif op_name == "is not": - invocation = Not(compare, - expr=InvokeFunction(compare, - expr=LoadName(compare, name="__is__"), + invocation = Not( + expr=InvokeFunction( + expr=LoadName(name="__is__"), args=[previous, expr], star=None, dstar=None) @@ -443,26 +443,26 @@ else: raise NotImplementedError, op_name - nodes.append(StoreTemp(compare, expr=invocation)) + nodes.append(StoreTemp(expr=invocation)) # Return from the subprogram where the test is not satisfied. if op is not last: nodes.append( - Conditional(compare, - test=Not(compare, expr=LoadTemp(compare)), - body=[Return(compare, expr=LoadTemp(compare))]) + Conditional( + test=Not(expr=LoadTemp()), + body=[Return(expr=LoadTemp())]) ) # Put subsequent operations in the else section of this conditional. - nodes = test.else_ = [ReleaseTemp(compare)] + nodes = test.else_ = [ReleaseTemp()] # For the last operation, return the result. else: nodes.append( - Return(compare, expr=LoadTemp(compare, release=1)) + Return(expr=LoadTemp(release=1)) ) previous = expr @@ -477,7 +477,7 @@ # Make an invocation of the subprogram. result = InvokeBlock(compare, 1, produces_result=1) - result.expr = LoadRef(compare, ref=subprogram) + result.expr = LoadRef(ref=subprogram) return result def visitAnd(self, and_): @@ -497,7 +497,7 @@ (else) -> ... """ - subprogram = Subprogram(and_, name=None, acquire_locals=1, returns_value=1, params=[], star=None, dstar=None) + subprogram = Subprogram(name=None, 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 @@ -513,19 +513,19 @@ # Return from the subprogram where the test is not satisfied. if node is not last: - nodes.append(StoreTemp(and_, expr=expr)) - invocation = InvokeFunction(and_, expr=LoadAttr(and_, expr=LoadTemp(and_), name="__true__"), args=[], star=None, dstar=None) - test = Conditional(and_, test=Not(and_, expr=invocation), body=[Return(and_, expr=LoadTemp(and_))]) + nodes.append(StoreTemp(expr=expr)) + invocation = InvokeFunction(expr=LoadAttr(expr=LoadTemp(), name="__true__"), args=[], star=None, dstar=None) + test = Conditional(test=Not(expr=invocation), body=[Return(expr=LoadTemp())]) nodes.append(test) # Put subsequent operations in the else section of this conditional. - nodes = test.else_ = [ReleaseTemp(and_)] + nodes = test.else_ = [ReleaseTemp()] # For the last operation, return the result. else: - nodes.append(Return(and_, expr=expr)) + nodes.append(Return(expr=expr)) # Finish the subprogram definition. @@ -537,7 +537,7 @@ # Make an invocation of the subprogram. result = InvokeBlock(and_, 1, produces_result=1) - result.expr = LoadRef(and_, ref=subprogram) + result.expr = LoadRef(ref=subprogram) return result def visitOr(self, or_): @@ -557,7 +557,7 @@ (else) -> ... """ - subprogram = Subprogram(or_, name=None, acquire_locals=1, returns_value=1, params=[], star=None, dstar=None) + subprogram = Subprogram(name=None, 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 @@ -573,20 +573,20 @@ # Return from the subprogram where the test is satisfied. if node is not last: - nodes.append(StoreTemp(or_, expr=expr)) - invocation = InvokeFunction(or_, expr=LoadAttr(or_, expr=LoadTemp(or_), name="__true__"), args=[], star=None, dstar=None) - test = Conditional(or_, test=invocation, body=[Return(or_, expr=LoadTemp(or_))]) + nodes.append(StoreTemp(expr=expr)) + invocation = InvokeFunction(expr=LoadAttr(expr=LoadTemp(), name="__true__"), args=[], star=None, dstar=None) + test = Conditional(test=invocation, body=[Return(expr=LoadTemp())]) nodes.append(test) # Put subsequent operations in the else section of this conditional. - nodes = test.else_ = [ReleaseTemp(or_)] + nodes = test.else_ = [ReleaseTemp()] # For the last operation, return the result. else: nodes.append( - Return(or_, expr=expr) + Return(expr=expr) ) # Finish the subprogram definition. @@ -599,13 +599,13 @@ # Make an invocation of the subprogram. result = InvokeBlock(or_, 1, produces_result=1) - result.expr = LoadRef(or_, ref=subprogram) + result.expr = LoadRef(ref=subprogram) return result def visitNot(self, not_): result = Not(not_, 1, - expr=InvokeFunction(not_, - expr=LoadAttr(not_, + expr=InvokeFunction( + expr=LoadAttr( expr=self.dispatch(not_.expr), name="__true__" ), @@ -620,7 +620,7 @@ def visitUnaryAdd(self, unaryadd): return InvokeFunction(unaryadd, 1, - expr=LoadAttr(unaryadd, + expr=LoadAttr( expr=self.dispatch(unaryadd.expr), name="__pos__" ), @@ -631,7 +631,7 @@ def visitUnarySub(self, unarysub): return InvokeFunction(unarysub, 1, - expr=LoadAttr(unarysub, + expr=LoadAttr( expr=self.dispatch(unarysub.expr), name="__neg__" ), @@ -642,7 +642,7 @@ def visitInvert(self, invert): return InvokeFunction(invert, 1, - expr=LoadAttr(invert, + expr=LoadAttr( expr=self.dispatch(invert.expr), name="__invert__" ), @@ -665,8 +665,8 @@ result = Try(add, 1, body=[ - InvokeFunction(add, - expr=LoadAttr(add, expr=self.dispatch(add.left), name="__add__"), + InvokeFunction( + expr=LoadAttr(expr=self.dispatch(add.left), name="__add__"), args=[self.dispatch(add.right)], star=None, dstar=None) @@ -674,15 +674,15 @@ else_=[], finally_=[], handler=[ - Conditional(add, - test=InvokeFunction(add, - expr=LoadName(add, name="isinstance"), - args=[LoadExc(add), LoadName(add, name="TypeError")], + Conditional( + test=InvokeFunction( + expr=LoadName(name="isinstance"), + args=[LoadExc(), LoadName(name="TypeError")], star=None, dstar=None), body=[ - InvokeFunction(add, - expr=LoadAttr(add, expr=self.dispatch(add.right), name="__radd__"), + InvokeFunction( + expr=LoadAttr(expr=self.dispatch(add.right), name="__radd__"), args=[self.dispatch(add.left)], star=None, dstar=None) @@ -727,21 +727,21 @@ if isinstance(augassign.node, compiler.ast.Name): result.code = [ - StoreTemp(augassign, - expr=InvokeFunction(augassign, + StoreTemp( + expr=InvokeFunction( args=[expr], star=None, dstar=None, - expr=LoadAttr(augassign, + expr=LoadAttr( expr=self.dispatch(augassign.node), name=self.augassign_methods[augassign.op] ) ) ), - StoreName(augassign, - expr=LoadTemp(augassign), + StoreName( + expr=LoadTemp(), name=augassign.node.name), - ReleaseTemp(augassign) + ReleaseTemp() ] # Complicated augmented assignment: lvalue.attr += expr @@ -751,29 +751,29 @@ # -> setattr(, getattr(, "attr").__xxx__(expr)) result.code = [ - StoreTemp(augassign, + StoreTemp( index="expr", expr=self.dispatch(augassign.node.expr) ), - StoreTemp(augassign, - expr=InvokeFunction(augassign, + StoreTemp( + expr=InvokeFunction( args=[expr], star=None, dstar=None, - expr=LoadAttr(augassign, + expr=LoadAttr( expr=LoadAttr(augassign.node, 1, - expr=LoadTemp(augassign, index="expr"), + expr=LoadTemp(index="expr"), name=augassign.node.attrname ), name=self.augassign_methods[augassign.op] ) ) ), - StoreAttr(augassign, - expr=LoadTemp(augassign), - lvalue=LoadTemp(augassign, index="expr"), + StoreAttr( + expr=LoadTemp(), + lvalue=LoadTemp(index="expr"), name=augassign.node.attrname ), - ReleaseTemp(augassign, index="expr"), - ReleaseTemp(augassign) + ReleaseTemp(index="expr"), + ReleaseTemp() ] # Complicated augassign using slices: lvalue[lower:upper] += expr @@ -783,27 +783,27 @@ # , , -> .__setslice__(, , .__getslice__(, ).__xxx__(expr)) result.code = [ - StoreTemp(augassign, + StoreTemp( index="expr", expr=self.dispatch(augassign.node.expr) ), - StoreTemp(augassign, + StoreTemp( index="lower", expr=self.dispatch_or_none(augassign.node.lower) ), - StoreTemp(augassign, + StoreTemp( index="upper", expr=self.dispatch_or_none(augassign.node.upper) ), - StoreTemp(augassign, - expr=InvokeFunction(augassign, + StoreTemp( + expr=InvokeFunction( args=[expr], star=None, dstar=None, - expr=LoadAttr(augassign, + expr=LoadAttr( expr=self._visitSlice( augassign.node, - LoadTemp(augassign, index="expr"), - LoadTemp(augassign, index="lower"), - LoadTemp(augassign, index="upper"), + LoadTemp(index="expr"), + LoadTemp(index="lower"), + LoadTemp(index="upper"), "OP_APPLY"), name=self.augassign_methods[augassign.op] ) @@ -811,16 +811,16 @@ ), self._visitSlice( augassign.node, - LoadTemp(augassign, index="expr"), - LoadTemp(augassign, index="lower"), - LoadTemp(augassign, index="upper"), + LoadTemp(index="expr"), + LoadTemp(index="lower"), + LoadTemp(index="upper"), "OP_ASSIGN", - LoadTemp(augassign) + LoadTemp() ), - ReleaseTemp(augassign, index="expr"), - ReleaseTemp(augassign, index="lower"), - ReleaseTemp(augassign, index="upper"), - ReleaseTemp(augassign) + ReleaseTemp(index="expr"), + ReleaseTemp(index="lower"), + ReleaseTemp(index="upper"), + ReleaseTemp() ] # Complicated augassign using subscripts: lvalue[subs] += expr @@ -830,16 +830,16 @@ # , -> .__setitem__(, .__getitem__().__xxx__(expr)) result.code = [ - StoreTemp(augassign, index="expr", expr=self.dispatch(augassign.node.expr)), - StoreTemp(augassign, index="subs", expr=self._visitSubscriptSubs(augassign.node, augassign.node.subs)), - StoreTemp(augassign, - expr=InvokeFunction(augassign, + StoreTemp(index="expr", expr=self.dispatch(augassign.node.expr)), + StoreTemp(index="subs", expr=self._visitSubscriptSubs(augassign.node, augassign.node.subs)), + StoreTemp( + expr=InvokeFunction( args=[expr], star=None, dstar=None, - expr=LoadAttr(augassign, + expr=LoadAttr( expr=self._visitSubscript( augassign.node, - LoadTemp(augassign, index="expr"), - LoadTemp(augassign, index="subs"), + LoadTemp(index="expr"), + LoadTemp(index="subs"), "OP_APPLY" ), name=self.augassign_methods[augassign.op] @@ -848,14 +848,14 @@ ), self._visitSubscript( augassign.node, - LoadTemp(augassign, index="expr"), - LoadTemp(augassign, index="subs"), + LoadTemp(index="expr"), + LoadTemp(index="subs"), "OP_ASSIGN", - LoadTemp(augassign) + LoadTemp() ), - ReleaseTemp(augassign, index="expr"), - ReleaseTemp(augassign, index="subs"), - ReleaseTemp(augassign) + ReleaseTemp(index="expr"), + ReleaseTemp(index="subs"), + ReleaseTemp() ] else: @@ -865,19 +865,19 @@ def visitAssign(self, assign): result = Assign(assign, 1) - store = StoreTemp(assign, expr=self.dispatch(assign.expr)) - release = ReleaseTemp(assign) + store = StoreTemp(expr=self.dispatch(assign.expr)) + release = ReleaseTemp() result.code = [store] + self.dispatches(assign.nodes, 0) + [release] return result def visitAssList(self, asslist, in_sequence=0): if not in_sequence: - expr = LoadTemp(asslist) + expr = LoadTemp() else: - expr = InvokeFunction(asslist, expr=LoadAttr(asslist, expr=LoadTemp(asslist), name="next"), star=None, dstar=None, args=[]) + expr = InvokeFunction(expr=LoadAttr(expr=LoadTemp(), name="next"), star=None, dstar=None, args=[]) result = Assign(asslist, 1) - store = StoreTemp(asslist, expr=InvokeFunction(asslist, expr=LoadAttr(asslist, name="__iter__", expr=expr), star=None, dstar=None, args=[])) - release = ReleaseTemp(asslist) + store = StoreTemp(expr=InvokeFunction(expr=LoadAttr(name="__iter__", expr=expr), star=None, dstar=None, args=[])) + release = ReleaseTemp() result.code = [store] + self.dispatches(asslist.nodes, 1) + [release] return result @@ -885,9 +885,9 @@ def _visitAssNameOrAttr(self, node, in_sequence): if not in_sequence: - return LoadTemp(node) + return LoadTemp() else: - return InvokeFunction(node, expr=LoadAttr(node, expr=LoadTemp(node), name="next"), star=None, dstar=None, args=[]) + return InvokeFunction(expr=LoadAttr(expr=LoadTemp(), name="next"), star=None, dstar=None, args=[]) def visitAssName(self, assname, in_sequence=0): expr = self._visitAssNameOrAttr(assname, in_sequence) @@ -903,7 +903,7 @@ def _visitSlice(self, slice, expr, lower, upper, flags, value=None): if flags == "OP_ASSIGN": result = InvokeFunction(slice, 1, - expr=LoadAttr(slice, + expr=LoadAttr( expr=expr, name="__setslice__" ), @@ -914,7 +914,7 @@ elif flags == "OP_APPLY": args = [] result = InvokeFunction(slice, 1, - expr=LoadAttr(slice, + expr=LoadAttr( expr=expr, name="__getslice__" ), @@ -925,7 +925,7 @@ elif flags == "OP_DELETE": args = [] result = InvokeFunction(slice, 1, - expr=LoadAttr(slice, + expr=LoadAttr( expr=expr, name="__delslice__" ), @@ -945,7 +945,7 @@ def _visitSubscript(self, subscript, expr, subs, flags, value=None): if flags == "OP_ASSIGN": result = InvokeFunction(subscript, 1, - expr=LoadAttr(subscript, + expr=LoadAttr( expr=expr, name="__setitem__" ), @@ -956,7 +956,7 @@ elif flags == "OP_APPLY": args = [] result = InvokeFunction(subscript, 1, - expr=LoadAttr(subscript, + expr=LoadAttr( expr=expr, name="__getitem__" ), @@ -967,7 +967,7 @@ elif flags == "OP_DELETE": args = [] result = InvokeFunction(subscript, 1, - expr=LoadAttr(subscript, + expr=LoadAttr( expr=expr, name="__delitem__" ), @@ -985,7 +985,7 @@ return self.dispatch(subs[0]) else: return InvokeFunction(node, 1, - expr=LoadName(node, name="tuple"), + expr=LoadName(name="tuple"), args=self.dispatches(subs), star=None, dstar=None @@ -1000,31 +1000,31 @@ # Invocation and subprogram transformations. def visitClass(self, class_): - structure = Class(class_, name=class_.name, bases=self.dispatches(class_.bases)) + structure = Class(name=class_.name, bases=self.dispatches(class_.bases)) self.structures.append(structure) # Make a subprogram which initialises the class structure. - subprogram = Subprogram(class_, name=None, structure=structure, params=[], star=None, dstar=None) + subprogram = Subprogram(name=None, structure=structure, params=[], star=None, dstar=None) self.current_subprograms.append(subprogram) # The class is initialised using the code found inside. - subprogram.code = self.dispatch(class_.code) + [Return(class_)] + subprogram.code = self.dispatch(class_.code) + [Return()] self.current_subprograms.pop() self.subprograms.append(subprogram); self.subnames[subprogram.full_name()] = subprogram # Make a definition of the class associating it with a name. - result = Assign(class_, + result = Assign( code=[ StoreName(class_, 1, # defines the class name=class_.name, - expr=LoadRef(class_, ref=structure) + expr=LoadRef(ref=structure) ), - InvokeBlock(class_, - expr=LoadRef(class_, ref=subprogram) + InvokeBlock( + expr=LoadRef(ref=subprogram) ) ] ) @@ -1058,14 +1058,14 @@ if has_star: star = ( function.argnames[npositional], - InvokeFunction(expr=LoadName(function, name="list"), args=[], star=None, dstar=None) + InvokeFunction(expr=LoadName(name="list"), args=[], star=None, dstar=None) ) else: star = None if has_dstar: dstar = ( function.argnames[npositional + has_star], - InvokeFunction(expr=LoadName(function, name="dict"), args=[], star=None, dstar=None) + InvokeFunction(expr=LoadName(name="dict"), args=[], star=None, dstar=None) ) else: dstar = None @@ -1100,15 +1100,15 @@ (dstar) """ - subprogram = Subprogram(function, name=function.name, acquire_locals=0, returns_value=1, star=None, dstar=None) + subprogram = Subprogram(name=function.name, acquire_locals=0, returns_value=1, star=None, dstar=None) self.current_subprograms.append(subprogram) - subprogram.code = self.dispatch(function.code) + [Return(function)] + subprogram.code = self.dispatch(function.code) + [Return()] self.current_subprograms.pop() self._visitFunction(function, subprogram) # Make a definition of the function associating it with a name. - result = StoreName(function, 1, name=function.name, expr=LoadRef(function, ref=subprogram)) + result = StoreName(function, 1, name=function.name, expr=LoadRef(ref=subprogram)) return result def visitLambda(self, lambda_): @@ -1116,9 +1116,9 @@ # Make a subprogram for the function and record it outside the main # tree. - subprogram = Subprogram(lambda_, name=None, acquire_locals=0, returns_value=1, star=None, dstar=None) + subprogram = Subprogram(name=None, acquire_locals=0, returns_value=1, star=None, dstar=None) self.current_subprograms.append(subprogram) - subprogram.code = [Return(lambda_, expr=self.dispatch(lambda_.code))] + subprogram.code = [Return(expr=self.dispatch(lambda_.code))] self.current_subprograms.pop() self._visitFunction(lambda_, subprogram) @@ -1151,28 +1151,28 @@ (else) -> ... """ - subprogram = Subprogram(while_, name=None, acquire_locals=1, returns_value=0, params=[], star=None, dstar=None) + subprogram = Subprogram(name=None, acquire_locals=1, returns_value=0, params=[], star=None, dstar=None) self.current_subprograms.append(subprogram) # Include a conditional statement in the subprogram. - test = Conditional(while_, else_=[]) - test.test = InvokeFunction(while_, expr=LoadAttr(while_, expr=self.dispatch(while_.test), name="__true__"), args=[], star=None, dstar=None) + test = Conditional(else_=[]) + test.test = InvokeFunction(expr=LoadAttr(expr=self.dispatch(while_.test), name="__true__"), args=[], star=None, dstar=None) # Inside the conditional, add a recursive invocation to the subprogram # if the test condition was satisfied. - continuation = InvokeBlock(while_) - continuation.expr = LoadRef(while_, ref=subprogram) + continuation = InvokeBlock() + continuation.expr = LoadRef(ref=subprogram) # Return within the main section of the loop. - test.body = self.dispatch(while_.body) + [continuation, Return(while_)] + test.body = self.dispatch(while_.body) + [continuation, Return()] # Provide the else section, if present, along with an explicit return. if while_.else_ is not None: - test.else_ = self.dispatch(while_.else_) + [Return(while_)] + test.else_ = self.dispatch(while_.else_) + [Return()] # Finish the subprogram definition. @@ -1184,7 +1184,7 @@ # Make an invocation of the subprogram. result = InvokeBlock(while_, 1) - result.expr = LoadRef(while_, ref=subprogram) + result.expr = LoadRef(ref=subprogram) return result def visitFor(self, for_): @@ -1207,43 +1207,43 @@ (else) -> ... """ - subprogram = Subprogram(for_, name=None, acquire_locals=1, returns_value=0, params=[], star=None, dstar=None) + subprogram = Subprogram(name=None, acquire_locals=1, returns_value=0, params=[], star=None, dstar=None) self.current_subprograms.append(subprogram) # Always return from conditional sections/subprograms. if for_.else_ is not None: - else_stmt = self.dispatch(for_.else_) + [Return(for_)] + else_stmt = self.dispatch(for_.else_) + [Return()] else: - else_stmt = [Return(for_)] + else_stmt = [Return()] # Wrap the assignment in a try...except statement. - try_except = Try(for_, body=[], else_=[], finally_=[]) - test = Conditional(for_, - test=InvokeFunction(for_, - expr=LoadName(for_, name="isinstance"), - args=[LoadExc(for_), LoadName(for_, name="StopIteration")], + try_except = Try(body=[], else_=[], finally_=[]) + test = Conditional( + test=InvokeFunction( + expr=LoadName(name="isinstance"), + args=[LoadExc(), LoadName(name="StopIteration")], star=None, dstar=None), body=else_stmt, - else_=[Raise(for_, expr=LoadExc(for_))]) + else_=[Raise(expr=LoadExc())]) try_except.handler = [test] - assign = Assign(for_, + assign = Assign( code=[ - StoreTemp(for_, expr=InvokeFunction(for_, expr=LoadAttr(for_, expr=LoadTemp(for_), name="next"), args=[], star=None, dstar=None)), + StoreTemp(expr=InvokeFunction(expr=LoadAttr(expr=LoadTemp(), name="next"), args=[], star=None, dstar=None)), self.dispatch(for_.assign), - ReleaseTemp(for_) + ReleaseTemp() ]) # Inside the conditional, add a recursive invocation to the subprogram # if the test condition was satisfied. - continuation = InvokeBlock(for_) - continuation.expr = LoadRef(for_, ref=subprogram) + continuation = InvokeBlock() + continuation.expr = LoadRef(ref=subprogram) try_except.body = [assign] + self.dispatch(for_.body) + [continuation] - subprogram.code = [try_except, Return(for_)] + subprogram.code = [try_except, Return()] # Finish the subprogram definition. @@ -1255,9 +1255,9 @@ result = Assign(for_, 1) result.code = [ - StoreTemp(for_, - expr=InvokeFunction(for_, - expr=LoadAttr(for_, + StoreTemp( + expr=InvokeFunction( + expr=LoadAttr( name="__iter__", expr=self.dispatch(for_.list) ), @@ -1266,8 +1266,8 @@ dstar=None ) ), - InvokeBlock(for_, expr=LoadRef(for_, ref=subprogram)), - ReleaseTemp(for_) + InvokeBlock(expr=LoadRef(ref=subprogram)), + ReleaseTemp() ] return result