1.1 --- a/annotate.py Sat May 26 02:28:02 2007 +0200
1.2 +++ b/annotate.py Sun May 27 18:19:01 2007 +0200
1.3 @@ -743,6 +743,26 @@
1.4 raise AnnotationMessage, "Temporary store index '%s' not defined." % index
1.5 self.annotate(loadtemp)
1.6
1.7 + def visitMakeTuple(self, maketuple):
1.8 +
1.9 + """
1.10 + Process the 'maketuple' node and its contents.
1.11 + """
1.12 +
1.13 + # Get a tuple and populate it with type information for the contents.
1.14 +
1.15 + tuples = self.get_builtin_instances(maketuple, "tuple")
1.16 +
1.17 + # NOTE: This is dependent on the tuple definition in the builtins.
1.18 +
1.19 + for node in maketuple.nodes:
1.20 + self.dispatch(node)
1.21 + for t in tuples:
1.22 + t.type.namespace.add("value", self.namespace.types)
1.23 +
1.24 + self.namespace.set_types(tuples)
1.25 + self.annotate(maketuple)
1.26 +
1.27 def visitModule(self, module):
1.28
1.29 """
1.30 @@ -960,7 +980,7 @@
1.31 # Utility methods.
1.32
1.33 def get_builtin_instances(self, node, name):
1.34 - return [Attribute(None, self.new_instance(node, attr.type)) for attr in self.builtins.namespace[name]]
1.35 + return set([Attribute(None, self.new_instance(node, attr.type)) for attr in self.builtins.namespace[name]])
1.36
1.37 def new_instance(self, node, type):
1.38
1.39 @@ -1225,52 +1245,12 @@
1.40 if not invocation.stars.has_key(subprogram.full_name()):
1.41 instance = getattr(invocation, "instance", None)
1.42
1.43 - code=[
1.44 - StoreTemp(
1.45 - instance=instance,
1.46 - expr=InvokeFunction(
1.47 - invocation.original,
1.48 - instance=instance,
1.49 - expr=LoadAttr(
1.50 - instance=instance,
1.51 - expr=LoadRef(
1.52 - instance=instance,
1.53 - ref=self.builtins
1.54 - ),
1.55 - name="list",
1.56 - nstype="module",
1.57 - ),
1.58 - args=[],
1.59 - star=None,
1.60 - dstar=None
1.61 - )
1.62 - )
1.63 - ]
1.64 -
1.65 - for arg in star_args:
1.66 - code.append(
1.67 - InvokeFunction(
1.68 - invocation.original,
1.69 - instance=instance,
1.70 - expr=LoadAttr(
1.71 - instance=instance,
1.72 - expr=LoadTemp(
1.73 - instance=instance
1.74 - ),
1.75 - name="append"
1.76 - ),
1.77 - args=[arg],
1.78 - star=None,
1.79 - dstar=None
1.80 - )
1.81 - )
1.82 -
1.83 - code += [
1.84 + code = [
1.85 Return(
1.86 instance=instance,
1.87 - expr=LoadTemp(
1.88 + expr=MakeTuple(
1.89 instance=instance,
1.90 - release=1
1.91 + nodes=star_args
1.92 )
1.93 )
1.94 ]
1.95 @@ -1284,6 +1264,7 @@
1.96 dstar=None,
1.97 code=code
1.98 )
1.99 +
1.100 subprogram.module.simplifier.subnames[new_subprogram.full_name()] = new_subprogram
1.101
1.102 invocation.stars[subprogram.full_name()] = InvokeRef(
2.1 --- a/fixnames.py Sat May 26 02:28:02 2007 +0200
2.2 +++ b/fixnames.py Sun May 27 18:19:01 2007 +0200
2.3 @@ -236,7 +236,7 @@
2.4 value = getattr(node, attr, None)
2.5 if value is not None:
2.6 setattr(node, attr, self.dispatch(value))
2.7 - for attr in ("body", "else_", "handler", "finally_", "code", "choices"):
2.8 + for attr in ("body", "else_", "handler", "finally_", "code", "choices", "nodes"):
2.9 value = getattr(node, attr, None)
2.10 if value is not None:
2.11 setattr(node, attr, self.dispatches(value))
3.1 --- a/lib/builtins.py Sat May 26 02:28:02 2007 +0200
3.2 +++ b/lib/builtins.py Sun May 27 18:19:01 2007 +0200
3.3 @@ -797,7 +797,7 @@
3.4 class tuple:
3.5 def __init__(self, *args):
3.6 for arg in args:
3.7 - self.append(arg)
3.8 + self.value = value
3.9
3.10 def __getitem__(self, index):
3.11 if -len(self) <= index < len(self):
3.12 @@ -824,11 +824,6 @@
3.13 else:
3.14 raise IndexError, index
3.15
3.16 - # NOTE: The append method should be internal at most.
3.17 -
3.18 - def append(self, value):
3.19 - self.value = value
3.20 -
3.21 def __len__(self):
3.22 return int()
3.23
4.1 --- a/simplified/program.py Sat May 26 02:28:02 2007 +0200
4.2 +++ b/simplified/program.py Sun May 27 18:19:01 2007 +0200
4.3 @@ -52,6 +52,10 @@
4.4 args Any collection of argument nodes.
4.5 params Any collection of parameter nodes and defaults.
4.6
4.7 + Tuple construction attributes:
4.8 +
4.9 + nodes Any expressions used to initialise a tuple
4.10 +
4.11 Statement-grouping attributes:
4.12
4.13 body Any conditional code depending on the success of a test.
4.14 @@ -315,6 +319,7 @@
4.15 class CheckType(Node): "Check a value's type from a list of choices."
4.16 class Return(Node): "Return an evaluated expression."
4.17 class Invoke(Node): "An invocation."
4.18 +class MakeTuple(Node): "Make a tuple object."
4.19
4.20 # There are two types of return node: return from function and return from
4.21 # block.
5.1 --- a/simplify.py Sat May 26 02:28:02 2007 +0200
5.2 +++ b/simplify.py Sun May 27 18:19:01 2007 +0200
5.3 @@ -1652,7 +1652,13 @@
5.4 return result
5.5
5.6 def visitTuple(self, tuple):
5.7 - return self._visitBuiltin(tuple, "tuple")
5.8 +
5.9 + "Make a MakeTuple node containing the original 'tuple' contents."
5.10 +
5.11 + result = MakeTuple(tuple, 1,
5.12 + nodes=self.dispatches(tuple.nodes)
5.13 + )
5.14 + return result
5.15
5.16 def visitUnaryAdd(self, unaryadd):
5.17 return self._visitUnary(unaryadd, "__pos__")