1.1 --- a/micropython/ast.py Tue Jul 14 00:37:04 2009 +0200
1.2 +++ b/micropython/ast.py Sun Jul 19 22:17:23 2009 +0200
1.3 @@ -603,7 +603,7 @@
1.4
1.5 # Check the number of parameters and defaults.
1.6
1.7 - self.new_op(CheckFrame((nparams, ndefaults, fn.has_star)))
1.8 + self.new_op(CheckFrame((nparams, ndefaults)))
1.9 if ndefaults > 0:
1.10 self.new_op(LoadFunction(fn))
1.11 self.new_op(FillDefaults((nparams, ndefaults)))
1.12 @@ -612,15 +612,19 @@
1.13
1.14 self.set_block(fn.body_block)
1.15
1.16 + extend = ExtendFrame()
1.17 + self.new_op(extend)
1.18 +
1.19 # For functions with star parameters, make a special list for the
1.20 # extra arguments and re-map the parameter.
1.21
1.22 if fn.has_star:
1.23 self.new_op(CopyExtra(nparams))
1.24 - self.new_op(StoreName(nparams - 1))
1.25 +
1.26 + # Ensure that the star parameter has a slot in the frame.
1.27
1.28 - extend = ExtendFrame()
1.29 - self.new_op(extend)
1.30 + self.new_op(CheckExtra(nparams))
1.31 + self.new_op(StoreTemp(nparams))
1.32
1.33 self.dispatch(node.code)
1.34
2.1 --- a/micropython/opt.py Tue Jul 14 00:37:04 2009 +0200
2.2 +++ b/micropython/opt.py Sun Jul 19 22:17:23 2009 +0200
2.3 @@ -184,21 +184,7 @@
2.4 to have the simple input registers as operands.
2.5 """
2.6
2.7 - return isinstance(instruction, (
2.8 - StoreTemp, StoreFrame, StoreResult, StoreException, # as the value being stored
2.9 - LoadAddressContext, LoadAddressContextCond, # as the object being referenced
2.10 - LoadAttr, LoadAttrIndex, # LoadAttrIndexContext, # as the object being referenced
2.11 - LoadAttrIndexContextCond, # as the object being referenced
2.12 - StoreAttr, StoreAttrIndex, StoreCallable, # as the object being referenced
2.13 - StoreFrameIndex, # as the object being referenced
2.14 - StoreAddressContext, # as the context
2.15 - LoadCallable,
2.16 - TestIdentity, TestIdentityAddress, CheckSelf, # as one of the operands
2.17 - CheckException, CheckFrame, FillDefaults,
2.18 - MakeInstance,
2.19 - CheckContext, CheckClass,
2.20 - LoadContext # as the object providing the result
2.21 - ))
2.22 + return isinstance(instruction, simple_input_user_instructions)
2.23
2.24 def is_resultant_no_operation(self, instruction):
2.25
3.1 --- a/micropython/rsvp.py Tue Jul 14 00:37:04 2009 +0200
3.2 +++ b/micropython/rsvp.py Sun Jul 19 22:17:23 2009 +0200
3.3 @@ -210,6 +210,7 @@
3.4 # Access to frames upon invocation.
3.5
3.6 class CheckFrame(Immediate): "Check the frame for the correct number of arguments."
3.7 +class CheckExtra(Immediate): "Ensure that the frame can provide extra arguments."
3.8 class FillDefaults(Immediate): "Fill frame positions with defaults, if appropriate."
3.9 class ExtendFrame(Immediate): "Extend the current frame for temporary storage use."
3.10 class CopyExtra(Immediate): "Copy extra arguments into a separate sequence, starting from the given position."
3.11 @@ -256,4 +257,22 @@
3.12 CopyExtra
3.13 )
3.14
3.15 +# Instructions which use the current value.
3.16 +
3.17 +simple_input_user_instructions = (
3.18 + StoreTemp, StoreFrame, StoreResult, StoreException, # as the value being stored
3.19 + LoadAddressContext, LoadAddressContextCond, # as the object being referenced
3.20 + LoadAttr, LoadAttrIndex, # LoadAttrIndexContext, # as the object being referenced
3.21 + LoadAttrIndexContextCond, # as the object being referenced
3.22 + StoreAttr, StoreAttrIndex, StoreCallable, # as the object being referenced
3.23 + StoreFrameIndex, # as the object being referenced
3.24 + StoreAddressContext, # as the context
3.25 + LoadCallable,
3.26 + TestIdentity, TestIdentityAddress, CheckSelf, # as one of the operands
3.27 + CheckException, CheckFrame, FillDefaults,
3.28 + MakeInstance,
3.29 + CheckContext, CheckClass,
3.30 + LoadContext # as the object providing the result
3.31 + )
3.32 +
3.33 # vim: tabstop=4 expandtab shiftwidth=4
4.1 --- a/rsvp.py Tue Jul 14 00:37:04 2009 +0200
4.2 +++ b/rsvp.py Sun Jul 19 22:17:23 2009 +0200
4.3 @@ -127,7 +127,7 @@
4.4 cls = self._get_class("__builtins__", "TypeError")
4.5 self.type_error = cls.location
4.6 self.type_error_instance = cls.instance_template_location
4.7 - cls = self.machine._get_class("__builtins__", "tuple")
4.8 + cls = self._get_class("__builtins__", "tuple")
4.9 self.tuple_class = cls.location
4.10 self.tuple_instance = cls.instance_template_location
4.11
4.12 @@ -581,7 +581,7 @@
4.13 self.status = data.attrcode is None # absent attrcode == class
4.14
4.15 def CheckFrame(self):
4.16 - (nargs, ndefaults, has_star) = self.operand
4.17 + (nargs, ndefaults) = self.operand
4.18
4.19 # The frame is actually installed as the locals.
4.20 # Retrieve the context from the first local.
4.21 @@ -589,14 +589,25 @@
4.22 frame = self.local_sp_stack[-1]
4.23 nlocals = len(self.frame_stack[frame:])
4.24
4.25 - # NOTE: Not testing (nlocals <= nargs or has_star) due to imprecise
4.26 - # NOTE: invocation frame removal (after frame adjustment).
4.27 -
4.28 if not ((nargs - ndefaults) <= nlocals):
4.29 raise Exception, "CheckFrame %r (%r <= %r <= %r)" % (self.operand, nargs - ndefaults, nlocals, nargs)
4.30 self.exception = self._MakeObject(2, self.type_error_instance)
4.31 return self.RaiseException()
4.32
4.33 + def CheckExtra(self):
4.34 + nargs = self.operand
4.35 +
4.36 + # The frame is actually installed as the locals.
4.37 + # Retrieve the context from the first local.
4.38 +
4.39 + frame = self.local_sp_stack[-1]
4.40 + nlocals = len(self.frame_stack[frame:])
4.41 +
4.42 + # Provide the extra star parameter if necessary.
4.43 +
4.44 + if nlocals == nargs:
4.45 + self.frame_stack.extend([None]) # ExtendFrame(1)
4.46 +
4.47 def FillDefaults(self):
4.48 context, ref = self.value
4.49 (nargs, ndefaults) = self.operand
5.1 --- a/tests/call_func_extra.py Tue Jul 14 00:37:04 2009 +0200
5.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
5.3 @@ -1,22 +0,0 @@
5.4 -#!/usr/bin/env python
5.5 -
5.6 -def f(a, b, *c):
5.7 - return c
5.8 -
5.9 -r1 = f(1, 2, 3)
5.10 -r2 = f(1, b=2)
5.11 -r3 = f(1, 2, 3, 4)
5.12 -
5.13 -g = f
5.14 -
5.15 -r4 = g(1, 2, 3)
5.16 -r5 = g(1, b=2)
5.17 -r6 = g(1, 2, 3, 4)
5.18 -
5.19 -def g(a, c, *b):
5.20 - return b
5.21 -
5.22 -r7 = g(1, c=2)
5.23 -r8 = g(1, 2, 3, 4)
5.24 -
5.25 -# vim: tabstop=4 expandtab shiftwidth=4
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
6.2 +++ b/tests/call_func_extra_known.py Sun Jul 19 22:17:23 2009 +0200
6.3 @@ -0,0 +1,16 @@
6.4 +#!/usr/bin/env python
6.5 +
6.6 +def f(a, b, *c):
6.7 + return c
6.8 +
6.9 +r1 = f(1, 2, 3)
6.10 +r2 = f(1, b=2)
6.11 +r3 = f(1, 2, 3, 4)
6.12 +
6.13 +result_0 = len(r2)
6.14 +result_1 = len(r1)
6.15 +result_2 = len(r3)
6.16 +result_3 = r1[0]
6.17 +result_4 = r3[1]
6.18 +
6.19 +# vim: tabstop=4 expandtab shiftwidth=4
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
7.2 +++ b/tests/call_func_extra_unknown.py Sun Jul 19 22:17:23 2009 +0200
7.3 @@ -0,0 +1,24 @@
7.4 +#!/usr/bin/env python
7.5 +
7.6 +def f(a, b, *c):
7.7 + return c
7.8 +
7.9 +g = f
7.10 +
7.11 +r4 = g(1, 2, 3)
7.12 +r5 = g(1, b=2)
7.13 +r6 = g(1, 2, 3, 4)
7.14 +
7.15 +def g(a, c, *b):
7.16 + return b
7.17 +
7.18 +r7 = g(1, c=2)
7.19 +r8 = g(1, 2, 3, 4)
7.20 +
7.21 +result_0 = len(r5)
7.22 +result_1 = len(r4)
7.23 +result_2 = len(r6)
7.24 +result2_0 = len(r7)
7.25 +result2_2 = len(r8)
7.26 +
7.27 +# vim: tabstop=4 expandtab shiftwidth=4