1.1 --- a/micropython/trans.py Mon Aug 23 00:15:03 2010 +0200
1.2 +++ b/micropython/trans.py Sun Aug 29 02:03:24 2010 +0200
1.3 @@ -1072,6 +1072,10 @@
1.4 extend = ExtendFrame()
1.5 self.new_op(extend)
1.6
1.7 + # Perform tuple assignment for any tuple parameters.
1.8 +
1.9 + self._visitFunctionTupleParameters(fn, node)
1.10 +
1.11 # For functions with star parameters, make a special list for the
1.12 # extra arguments and re-map the parameter.
1.13
1.14 @@ -1109,6 +1113,48 @@
1.15
1.16 self.set_frame_usage(node, extend)
1.17
1.18 + def _visitFunctionTupleParameters(self, fn, node, parameters=None):
1.19 +
1.20 + """
1.21 + Visit the tuple parameters for function 'fn', obtaining the appropriate
1.22 + elements from each supplied argument and assigning them to the specified
1.23 + names for each parameter.
1.24 + """
1.25 +
1.26 + if parameters is not None:
1.27 + self._generateAttr(node, "__getitem__", self.attribute_load_instructions)
1.28 + temp_getitem = self.optimiser.optimise_temp_storage()
1.29 +
1.30 + for i, parameter in parameters or fn.tuple_parameters():
1.31 +
1.32 + # Either load the parameter from the frame.
1.33 +
1.34 + if parameters is None:
1.35 + self.new_op(LoadName(Attr(i, None, None)))
1.36 +
1.37 + # Or load a value from the current collection.
1.38 +
1.39 + else:
1.40 + self._startCallFunc()
1.41 + self.new_op(temp_getitem)
1.42 + temp_target, target, temp_context = self._generateCallFunc([compiler.ast.Const(i)], node)
1.43 + self._doCallFunc(temp_target, target)
1.44 + self._endCallFunc(temp_target, target, temp_context)
1.45 +
1.46 + # Where a tuple is the target, attempt to descend into the value
1.47 + # obtained.
1.48 +
1.49 + if isinstance(parameter, list):
1.50 + self._visitFunctionTupleParameters(fn, node, parameter)
1.51 +
1.52 + # Store the item in the namespace entry for the given name.
1.53 +
1.54 + else:
1.55 + self.new_op(StoreName(fn[parameter]))
1.56 +
1.57 + if parameters is not None:
1.58 + self.discard_temp(temp_getitem)
1.59 +
1.60 def _generateFunctionDefaults(self, function):
1.61
1.62 """