1.1 --- a/docs/concepts.txt Sat May 09 03:21:15 2009 +0200
1.2 +++ b/docs/concepts.txt Mon May 11 02:17:12 2009 +0200
1.3 @@ -196,8 +196,9 @@
1.4 0 1 2 3 4 5 6 7 8
1.5 classcode attrcode/ invocation invocation funccode size __class__ attribute ...
1.6 instance reference #args, reference reference
1.7 - status defaults
1.8 - reference
1.9 + status defaults,
1.10 + * parameter
1.11 + details
1.12
1.13 Classcode
1.14 ---------
1.15 @@ -220,6 +221,24 @@
1.16 removed and the attrcode is not specified for classes: the presence of an
1.17 attrcode indicates that a given object is an instance.
1.18
1.19 +Invocation Reference
1.20 +--------------------
1.21 +
1.22 +Used when an object is called.
1.23 +
1.24 +This is the address of the code to be executed when an invocation is performed
1.25 +on the object.
1.26 +
1.27 +Invocation Arguments
1.28 +--------------------
1.29 +
1.30 +Used when an object is called.
1.31 +
1.32 +The argument details consist of the number of positional arguments involved in
1.33 +an invocation, the number of defaults available to compensate for missing
1.34 +arguments, and whether a star (*) parameter is available to accept superfluous
1.35 +arguments.
1.36 +
1.37 Attributes
1.38 ----------
1.39
1.40 @@ -236,24 +255,27 @@
1.41 0 1 2 3 4 5 6 7 8
1.42 classcode (unused) __new__ __new__ funccode size class type attribute ...
1.43 for C reference #args, for reference reference
1.44 - defaults instantiator
1.45 - reference
1.46 + defaults, instantiator
1.47 + * parameter
1.48 + details
1.49
1.50 Instance of C:
1.51
1.52 0 1 2 3 4 5 6 7 8
1.53 classcode attrcode C.__call__ C.__call__ funccode size class C attribute ...
1.54 for C for C reference #args, for reference reference
1.55 - (if exists) defaults C.__call__
1.56 - reference
1.57 + (if exists) defaults, C.__call__
1.58 + * parameter
1.59 + details
1.60
1.61 Function f:
1.62
1.63 0 1 2 3 4 5 6 7 8
1.64 classcode attrcode code code funccode size class attribute ...
1.65 for for reference #args, function (default)
1.66 - function function defaults reference reference
1.67 - reference
1.68 + function function defaults, reference reference
1.69 + * parameter
1.70 + details
1.71
1.72 Module m:
1.73
2.1 --- a/docs/invocation.txt Sat May 09 03:21:15 2009 +0200
2.2 +++ b/docs/invocation.txt Mon May 11 02:17:12 2009 +0200
2.3 @@ -17,7 +17,7 @@
2.4 f(1, 2, 3) # positional, f is appropriate function pointer
2.5 # ie. (*f)(A, B, C)
2.6
2.7 -Least expensive cases:
2.8 +Least expensive cases (positional plus defaults):
2.9
2.10 f(1, 2, 3) # put arguments in frame
2.11 # if f is not known, add arguments vs. parameters check
2.12 @@ -25,7 +25,7 @@
2.13 # not enough arguments are given
2.14 # if f is not known, this is obviously done at run-time
2.15
2.16 -More expensive cases:
2.17 +More expensive cases (keywords plus defaults):
2.18
2.19 f(1, 2, c=3) # prepare frame using parameter details
2.20 # (provided c is a known parameter)
2.21 @@ -37,9 +37,15 @@
2.22 # assigned (since their positions and thus the positions
2.23 # of missing parameters cannot be known)
2.24
2.25 -Awkward cases:
2.26 +Awkward cases (extra arguments):
2.27
2.28 - f(1, 2, 3, 4) # extra positional arguments
2.29 + f(1, 2, 3, 4) # put arguments in frame
2.30 + # if f is not known, add arguments vs. parameters check
2.31 + # target unpacks superfluous arguments from the end of the
2.32 + # frame
2.33 +
2.34 +Very awkward cases:
2.35 +
2.36 f(1, 2, 3, d=4) # extra keyword arguments
2.37 f(1, 2, *args) # positional bundles (possibly with defaults)
2.38 f(1, 2, **kw) # keyword bundles (possibly with defaults)
3.1 --- a/lib/builtins.py Sat May 09 03:21:15 2009 +0200
3.2 +++ b/lib/builtins.py Mon May 11 02:17:12 2009 +0200
3.3 @@ -295,7 +295,7 @@
3.4 def globals(): pass
3.5 def hasattr(obj, name): pass
3.6 def hash(obj): pass
3.7 -def help(*args, **kw): pass
3.8 +def help(*args): pass
3.9 def hex(number): pass
3.10 def id(obj): pass
3.11 def input(prompt=None): pass
3.12 @@ -305,8 +305,8 @@
3.13 def len(obj): pass
3.14 def locals(): pass
3.15 def map(function, *args): pass
3.16 -def max(*args, **kw): pass
3.17 -def min(*args, **kw): pass
3.18 +def max(*args): pass
3.19 +def min(*args): pass
3.20 def oct(number): pass
3.21 def open(name, mode=None, buffering=None): pass
3.22 def ord(c): pass
4.1 --- a/micropython/ast.py Sat May 09 03:21:15 2009 +0200
4.2 +++ b/micropython/ast.py Mon May 11 02:17:12 2009 +0200
4.3 @@ -596,6 +596,11 @@
4.4 extend = ExtendFrame()
4.5 self.new_op(extend)
4.6
4.7 + # Handle * parameters.
4.8 + # NOTE: Not handling ** parameters yet.
4.9 +
4.10 + # Make a tuple from the arguments corresponding to the * parameter.
4.11 +
4.12 self.dispatch(node.code)
4.13 if not isinstance(self.last_op(), Return):
4.14 self.dispatch(compiler.ast.Name("None"))
5.1 --- a/micropython/data.py Sat May 09 03:21:15 2009 +0200
5.2 +++ b/micropython/data.py Mon May 11 02:17:12 2009 +0200
5.3 @@ -581,6 +581,7 @@
5.4 (
5.5 call_method_value and len(call_method_value.positional_names),
5.6 call_method_value and len(call_method_value.defaults)
5.7 + # NOTE: Add * parameter availability.
5.8 ),
5.9 self.full_name(),
5.10 len(self.instance_attributes()) + 1, # size
5.11 @@ -596,6 +597,7 @@
5.12 (
5.13 len(self.get_instantiator().positional_names),
5.14 len(self.get_instantiator().defaults)
5.15 + # NOTE: Add * parameter availability.
5.16 ),
5.17 self.full_name(),
5.18 len(self.class_attributes()) + 1, # size
5.19 @@ -976,6 +978,7 @@
5.20 (
5.21 len(self.positional_names),
5.22 len(self.defaults)
5.23 + # NOTE: Add * parameter availability.
5.24 ),
5.25 "__builtins__.function",
5.26 len(self.defaults) + 1, # size
6.1 --- a/micropython/trans.py Sat May 09 03:21:15 2009 +0200
6.2 +++ b/micropython/trans.py Mon May 11 02:17:12 2009 +0200
6.3 @@ -701,6 +701,8 @@
6.4 ndefaults = len(target.defaults)
6.5 nargs_min = nargs_max - ndefaults
6.6
6.7 + # Visit each argument position and look for a supplied argument.
6.8 +
6.9 for i in range(ncontext, nargs_min):
6.10 if i not in employed_positions:
6.11 raise TranslateError(self.module.full_name(), node,
6.12 @@ -708,17 +710,32 @@
6.13
6.14 nargs = frame_pos
6.15
6.16 - if nargs > nargs_max and not target.has_star and not target.has_dstar:
6.17 + # Determine whether too many arguments have been given and how big
6.18 + # the frame should be.
6.19 +
6.20 + # For parameter lists with * or ** parameters, accept as many
6.21 + # arguments as are allowed or as many as we have.
6.22 +
6.23 + if target.has_star or target.has_dstar:
6.24 + frame_size = max(nargs, nargs_max)
6.25 +
6.26 + # For other parameter lists, only accept as many arguments as we are
6.27 + # allowed.
6.28 +
6.29 + elif nargs > nargs_max:
6.30 raise TranslateError(self.module.full_name(), node,
6.31 "Too many arguments for %r: need at most %d argument(s)." % (target.name, nargs_max))
6.32
6.33 + else:
6.34 + frame_size = nargs_max
6.35 +
6.36 # Where defaults are involved, put them into the frame.
6.37
6.38 self._generateCallFuncDefaultArgs(target, temp, nargs_min, nargs_max, employed_positions)
6.39
6.40 # Set the frame size.
6.41
6.42 - self._endCallFuncArgs(nargs_max)
6.43 + self._endCallFuncArgs(frame_size)
6.44
6.45 # Or generate instructions to do this at run-time.
6.46
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/tests/call_func_star_parameter.py Mon May 11 02:17:12 2009 +0200
7.3 @@ -0,0 +1,8 @@
7.4 +#!/usr/bin/env python
7.5 +
7.6 +def f(*args):
7.7 + return args
7.8 +
7.9 +x = f(1, 2, 3)
7.10 +
7.11 +# vim: tabstop=4 expandtab shiftwidth=4