# HG changeset patch # User paulb@localhost.localdomain # Date 1180282741 -7200 # Node ID dfd0634cfdb6f7e258b758ff75bfe83c986800fb # Parent 49b32970a4424fc2186740d398ea6f533ac681d9 Added a MakeTuple simplified node, replacing the previous tuple initialisation mechanism. diff -r 49b32970a442 -r dfd0634cfdb6 annotate.py --- a/annotate.py Sat May 26 02:28:02 2007 +0200 +++ b/annotate.py Sun May 27 18:19:01 2007 +0200 @@ -743,6 +743,26 @@ raise AnnotationMessage, "Temporary store index '%s' not defined." % index self.annotate(loadtemp) + def visitMakeTuple(self, maketuple): + + """ + Process the 'maketuple' node and its contents. + """ + + # Get a tuple and populate it with type information for the contents. + + tuples = self.get_builtin_instances(maketuple, "tuple") + + # NOTE: This is dependent on the tuple definition in the builtins. + + for node in maketuple.nodes: + self.dispatch(node) + for t in tuples: + t.type.namespace.add("value", self.namespace.types) + + self.namespace.set_types(tuples) + self.annotate(maketuple) + def visitModule(self, module): """ @@ -960,7 +980,7 @@ # Utility methods. def get_builtin_instances(self, node, name): - return [Attribute(None, self.new_instance(node, attr.type)) for attr in self.builtins.namespace[name]] + return set([Attribute(None, self.new_instance(node, attr.type)) for attr in self.builtins.namespace[name]]) def new_instance(self, node, type): @@ -1225,52 +1245,12 @@ if not invocation.stars.has_key(subprogram.full_name()): instance = getattr(invocation, "instance", None) - code=[ - StoreTemp( - instance=instance, - expr=InvokeFunction( - invocation.original, - instance=instance, - expr=LoadAttr( - instance=instance, - expr=LoadRef( - instance=instance, - ref=self.builtins - ), - name="list", - nstype="module", - ), - args=[], - star=None, - dstar=None - ) - ) - ] - - for arg in star_args: - code.append( - InvokeFunction( - invocation.original, - instance=instance, - expr=LoadAttr( - instance=instance, - expr=LoadTemp( - instance=instance - ), - name="append" - ), - args=[arg], - star=None, - dstar=None - ) - ) - - code += [ + code = [ Return( instance=instance, - expr=LoadTemp( + expr=MakeTuple( instance=instance, - release=1 + nodes=star_args ) ) ] @@ -1284,6 +1264,7 @@ dstar=None, code=code ) + subprogram.module.simplifier.subnames[new_subprogram.full_name()] = new_subprogram invocation.stars[subprogram.full_name()] = InvokeRef( diff -r 49b32970a442 -r dfd0634cfdb6 fixnames.py --- a/fixnames.py Sat May 26 02:28:02 2007 +0200 +++ b/fixnames.py Sun May 27 18:19:01 2007 +0200 @@ -236,7 +236,7 @@ value = getattr(node, attr, None) if value is not None: setattr(node, attr, self.dispatch(value)) - for attr in ("body", "else_", "handler", "finally_", "code", "choices"): + for attr in ("body", "else_", "handler", "finally_", "code", "choices", "nodes"): value = getattr(node, attr, None) if value is not None: setattr(node, attr, self.dispatches(value)) diff -r 49b32970a442 -r dfd0634cfdb6 lib/builtins.py --- a/lib/builtins.py Sat May 26 02:28:02 2007 +0200 +++ b/lib/builtins.py Sun May 27 18:19:01 2007 +0200 @@ -797,7 +797,7 @@ class tuple: def __init__(self, *args): for arg in args: - self.append(arg) + self.value = value def __getitem__(self, index): if -len(self) <= index < len(self): @@ -824,11 +824,6 @@ else: raise IndexError, index - # NOTE: The append method should be internal at most. - - def append(self, value): - self.value = value - def __len__(self): return int() diff -r 49b32970a442 -r dfd0634cfdb6 simplified/program.py --- a/simplified/program.py Sat May 26 02:28:02 2007 +0200 +++ b/simplified/program.py Sun May 27 18:19:01 2007 +0200 @@ -52,6 +52,10 @@ args Any collection of argument nodes. params Any collection of parameter nodes and defaults. + Tuple construction attributes: + + nodes Any expressions used to initialise a tuple + Statement-grouping attributes: body Any conditional code depending on the success of a test. @@ -315,6 +319,7 @@ class CheckType(Node): "Check a value's type from a list of choices." class Return(Node): "Return an evaluated expression." class Invoke(Node): "An invocation." +class MakeTuple(Node): "Make a tuple object." # There are two types of return node: return from function and return from # block. diff -r 49b32970a442 -r dfd0634cfdb6 simplify.py --- a/simplify.py Sat May 26 02:28:02 2007 +0200 +++ b/simplify.py Sun May 27 18:19:01 2007 +0200 @@ -1652,7 +1652,13 @@ return result def visitTuple(self, tuple): - return self._visitBuiltin(tuple, "tuple") + + "Make a MakeTuple node containing the original 'tuple' contents." + + result = MakeTuple(tuple, 1, + nodes=self.dispatches(tuple.nodes) + ) + return result def visitUnaryAdd(self, unaryadd): return self._visitUnary(unaryadd, "__pos__")