1.1 --- a/TO_DO.txt Mon Aug 23 00:15:03 2010 +0200
1.2 +++ b/TO_DO.txt Sun Aug 29 02:03:24 2010 +0200
1.3 @@ -1,4 +1,9 @@
1.4 -Fix the attribute names in the report.
1.5 +Fix object table entries for attributes not provided by any known object, or provide an
1.6 +error, potentially overridden by options. For example, the augmented assignment methods
1.7 +are not supported by the built-in objects and thus the operator module functions cause
1.8 +the compilation to fail.
1.9 +
1.10 +Support tuple parameters.
1.11
1.12 Consider type deduction and its consequences where types belong to the same hierarchy
1.13 and where a guard could be generated for the most general type.
2.1 --- a/lib/builtins.py Mon Aug 23 00:15:03 2010 +0200
2.2 +++ b/lib/builtins.py Sun Aug 29 02:03:24 2010 +0200
2.3 @@ -4,7 +4,7 @@
2.4 Simple built-in classes and functions. Objects which provide code that shall
2.5 always be compiled should provide docstrings.
2.6
2.7 -Copyright (C) 2005, 2006, 2007, 2008, 2009 Paul Boddie <paul@boddie.org.uk>
2.8 +Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Paul Boddie <paul@boddie.org.uk>
2.9
2.10 This program is free software; you can redistribute it and/or modify it under
2.11 the terms of the GNU General Public License as published by the Free Software
3.1 --- a/micropython/ast.py Mon Aug 23 00:15:03 2010 +0200
3.2 +++ b/micropython/ast.py Sun Aug 29 02:03:24 2010 +0200
3.3 @@ -479,10 +479,13 @@
3.4 found within the given 'node'.
3.5 """
3.6
3.7 + self.new_op(self.expr_temp[-1])
3.8 + self._generateAttr(node, "__getitem__", self.attribute_load_instructions)
3.9 + temp_getitem = self.optimiser.optimise_temp_storage()
3.10 +
3.11 for i, n in enumerate(node.nodes):
3.12 self._startCallFunc()
3.13 - self.new_op(self.expr_temp[-1])
3.14 - self._generateAttr(node, "__getitem__", self.attribute_load_instructions)
3.15 + self.new_op(temp_getitem)
3.16 temp_target, target, temp_context = self._generateCallFunc([compiler.ast.Const(i)], node)
3.17 self._doCallFunc(temp_target, target)
3.18 self._endCallFunc(temp_target, target, temp_context)
3.19 @@ -496,6 +499,8 @@
3.20 self.dispatch(n)
3.21 self.discard_value()
3.22
3.23 + self.discard_temp(temp_getitem)
3.24 +
3.25 def visitAssName(self, node):
3.26
3.27 "Assign the assignment expression to the recipient 'node'."
4.1 --- a/micropython/data.py Mon Aug 23 00:15:03 2010 +0200
4.2 +++ b/micropython/data.py Sun Aug 29 02:03:24 2010 +0200
4.3 @@ -1405,11 +1405,24 @@
4.4 self.all_local_usage = 0
4.5
4.6 def _add_parameters(self, argnames):
4.7 +
4.8 + "Add 'argnames' to the namespace."
4.9 +
4.10 + for name in argnames:
4.11 + self.set(name, Instance())
4.12 +
4.13 + for name, top_level in self._flattened_parameters(argnames):
4.14 + if not top_level:
4.15 + self.set(name, Instance())
4.16 +
4.17 + def _flattened_parameters(self, argnames, top_level=1):
4.18 + l = []
4.19 for name in argnames:
4.20 if isinstance(name, tuple):
4.21 - self._add_parameters(name)
4.22 + l += self._flattened_parameters(name, 0)
4.23 else:
4.24 - self.set(name, Instance())
4.25 + l.append((name, top_level))
4.26 + return l
4.27
4.28 def __repr__(self):
4.29 if self.location is not None:
4.30 @@ -1495,6 +1508,24 @@
4.31 parameters[name] = i
4.32 return parameters
4.33
4.34 + def tuple_parameters(self, argnames=None):
4.35 +
4.36 + """
4.37 + Return a list of (position, parameter) entries corresponding to tuple
4.38 + parameters, where each parameter may either be a string or another such
4.39 + list of entries.
4.40 + """
4.41 +
4.42 + names = argnames or self.argnames
4.43 +
4.44 + l = []
4.45 + for i, name in enumerate(names):
4.46 + if isinstance(name, tuple):
4.47 + l.append((i, self.tuple_parameters(name)))
4.48 + elif argnames:
4.49 + l.append((i, name))
4.50 + return l
4.51 +
4.52 def all_locals(self):
4.53
4.54 "Return a dictionary mapping names to local and parameter details."
4.55 @@ -1556,17 +1587,17 @@
4.56 for i, default in enumerate(self.default_attrs):
4.57 default.position = i
4.58
4.59 - # Locals.
4.60 + # Parameters.
4.61
4.62 - i = None
4.63 - for i, name in enumerate(self.argnames):
4.64 - self[name].position = i
4.65 + i = self._finalise_parameters()
4.66
4.67 if i is not None:
4.68 nparams = i + 1
4.69 else:
4.70 nparams = 0
4.71
4.72 + # Locals (and tuple parameter names).
4.73 +
4.74 i = None
4.75 for i, attr in enumerate(self.locals().values()):
4.76 attr.position = i + nparams
4.77 @@ -1580,6 +1611,15 @@
4.78 self.all_local_usage = nparams + nothers
4.79 self.finalised = 1
4.80
4.81 + def _finalise_parameters(self):
4.82 + if not self.argnames:
4.83 + return None
4.84 +
4.85 + for i, name in enumerate(self.argnames):
4.86 + self[name].position = i
4.87 +
4.88 + return i
4.89 +
4.90 def as_instantiator(self):
4.91
4.92 "Make an instantiator function from a method, keeping all arguments."
5.1 --- a/micropython/inspect.py Mon Aug 23 00:15:03 2010 +0200
5.2 +++ b/micropython/inspect.py Sun Aug 29 02:03:24 2010 +0200
5.3 @@ -461,6 +461,13 @@
5.4 self.expr = self.dispatch(n)
5.5 function.store_default(self.expr)
5.6
5.7 + # Note attribute usage where tuple parameters are involved.
5.8 +
5.9 + if function.tuple_parameters():
5.10 + self.use_name("__getitem__", node)
5.11 +
5.12 + # Record the namespace context of the function for later processing.
5.13 +
5.14 self.functions.append((node, self.namespaces + [function]))
5.15
5.16 # Store the function.
6.1 --- a/micropython/opt.py Mon Aug 23 00:15:03 2010 +0200
6.2 +++ b/micropython/opt.py Sun Aug 29 02:03:24 2010 +0200
6.3 @@ -367,9 +367,9 @@
6.4
6.5 """
6.6 Where the next operation would involve storing a value into temporary
6.7 - storage at 'temp_position', record and remove any simple instruction
6.8 - which produced the value to be stored such that instead of subsequently
6.9 - accessing the temporary storage, that instruction is substituted.
6.10 + storage, record and remove any simple instruction which produced the
6.11 + value to be stored such that instead of subsequently accessing the
6.12 + temporary storage, that instruction is substituted.
6.13
6.14 If no optimisation can be achieved, a StoreTemp instruction is produced
6.15 and the appropriate LoadTemp instruction is returned.
7.1 --- a/micropython/trans.py Mon Aug 23 00:15:03 2010 +0200
7.2 +++ b/micropython/trans.py Sun Aug 29 02:03:24 2010 +0200
7.3 @@ -1072,6 +1072,10 @@
7.4 extend = ExtendFrame()
7.5 self.new_op(extend)
7.6
7.7 + # Perform tuple assignment for any tuple parameters.
7.8 +
7.9 + self._visitFunctionTupleParameters(fn, node)
7.10 +
7.11 # For functions with star parameters, make a special list for the
7.12 # extra arguments and re-map the parameter.
7.13
7.14 @@ -1109,6 +1113,48 @@
7.15
7.16 self.set_frame_usage(node, extend)
7.17
7.18 + def _visitFunctionTupleParameters(self, fn, node, parameters=None):
7.19 +
7.20 + """
7.21 + Visit the tuple parameters for function 'fn', obtaining the appropriate
7.22 + elements from each supplied argument and assigning them to the specified
7.23 + names for each parameter.
7.24 + """
7.25 +
7.26 + if parameters is not None:
7.27 + self._generateAttr(node, "__getitem__", self.attribute_load_instructions)
7.28 + temp_getitem = self.optimiser.optimise_temp_storage()
7.29 +
7.30 + for i, parameter in parameters or fn.tuple_parameters():
7.31 +
7.32 + # Either load the parameter from the frame.
7.33 +
7.34 + if parameters is None:
7.35 + self.new_op(LoadName(Attr(i, None, None)))
7.36 +
7.37 + # Or load a value from the current collection.
7.38 +
7.39 + else:
7.40 + self._startCallFunc()
7.41 + self.new_op(temp_getitem)
7.42 + temp_target, target, temp_context = self._generateCallFunc([compiler.ast.Const(i)], node)
7.43 + self._doCallFunc(temp_target, target)
7.44 + self._endCallFunc(temp_target, target, temp_context)
7.45 +
7.46 + # Where a tuple is the target, attempt to descend into the value
7.47 + # obtained.
7.48 +
7.49 + if isinstance(parameter, list):
7.50 + self._visitFunctionTupleParameters(fn, node, parameter)
7.51 +
7.52 + # Store the item in the namespace entry for the given name.
7.53 +
7.54 + else:
7.55 + self.new_op(StoreName(fn[parameter]))
7.56 +
7.57 + if parameters is not None:
7.58 + self.discard_temp(temp_getitem)
7.59 +
7.60 def _generateFunctionDefaults(self, function):
7.61
7.62 """
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/tests/call_func_tuple_parameters.py Sun Aug 29 02:03:24 2010 +0200
8.3 @@ -0,0 +1,14 @@
8.4 +#!/usr/bin/env python
8.5 +
8.6 +def f((a, b), c):
8.7 + return b
8.8 +
8.9 +def g((a, b), c):
8.10 + return c
8.11 +
8.12 +result_2 = f((1, 2), 3)
8.13 +result1_3 = g((1, 2), 3)
8.14 +result2_3 = f(((1, 2), 3), 4)
8.15 +result_4 = g(((1, 2), 3), 4)
8.16 +
8.17 +# vim: tabstop=4 expandtab shiftwidth=4