# HG changeset patch # User Paul Boddie # Date 1242683772 -7200 # Node ID b8550c04e8074a1af6f3f487e0f42a76c0637409 # Parent 62219b8d6bafcadd9c3b46ac8ae20476776e8228 Fixed FillDefaults temporarily, but a proper get_operand method is required for the instruction. Enhanced test outputs and comments. diff -r 62219b8d6baf -r b8550c04e807 micropython/ast.py --- a/micropython/ast.py Sun May 17 23:50:20 2009 +0200 +++ b/micropython/ast.py Mon May 18 23:56:12 2009 +0200 @@ -608,7 +608,7 @@ ndefaults = len(fn.defaults) self.new_op(CheckFrame((nparams, ndefaults, fn.has_star))) - self.new_op(FillDefaults((nparams, ndefaults))) + self.new_op(FillDefaults((nparams, ndefaults, fn))) # Produce the body. @@ -677,7 +677,7 @@ ndefaults = len(fn.defaults) self.new_op(CheckFrame((nparams, ndefaults, fn.has_star))) - self.new_op(FillDefaults((nparams, ndefaults))) + self.new_op(FillDefaults((nparams, ndefaults, fn))) # Produce the body. diff -r 62219b8d6baf -r b8550c04e807 rsvp.py --- a/rsvp.py Sun May 17 23:50:20 2009 +0200 +++ b/rsvp.py Mon May 18 23:56:12 2009 +0200 @@ -484,7 +484,9 @@ def LoadContext(self): context, ref = self.value - self.value = None, context # context of context is not interesting + # NOTE: Omission of the context of the context would make things like + # NOTE: self() inside methods impossible. + self.value = context, context def CheckFrame(self): (nargs, ndefaults, has_star) = self.operand @@ -514,7 +516,9 @@ raise Exception, "CheckFrame %r (%r <= %r <= %r)" % (self.operand, nargs - ndefaults, nlocals, nargs) def FillDefaults(self): - (nargs, ndefaults) = self.operand + # NOTE: Make the get_operand method of the instruction provide the + # NOTE: function location. + (nargs, ndefaults, fn) = self.operand # The frame is actually installed as the locals. @@ -527,6 +531,7 @@ default = nlocals - (nargs - ndefaults) self.frame_stack.extend([None] * (nargs - nlocals)) pos = nlocals + ref = fn.location while pos < nargs: self.frame_stack[frame + pos] = self.load(ref + default + 1) # skip header diff -r 62219b8d6baf -r b8550c04e807 tests/call_func_default_keyword.py --- a/tests/call_func_default_keyword.py Sun May 17 23:50:20 2009 +0200 +++ b/tests/call_func_default_keyword.py Mon May 18 23:56:12 2009 +0200 @@ -1,11 +1,11 @@ #!/usr/bin/env python def f(a, b, c=4): - pass + return c -f(1, 2, 3) -f(1, b=2, c=3) -f(c=3, b=2, a=1) -f(1, 2) +p = f(1, 2, 3) +q = f(1, b=2, c=3) +r = f(c=3, b=2, a=1) +s = f(1, 2) # vim: tabstop=4 expandtab shiftwidth=4 diff -r 62219b8d6baf -r b8550c04e807 tests/call_func_default_redefine.py --- a/tests/call_func_default_redefine.py Sun May 17 23:50:20 2009 +0200 +++ b/tests/call_func_default_redefine.py Mon May 18 23:56:12 2009 +0200 @@ -4,13 +4,13 @@ return c g = f -r1 = g(1, c=3, b=2) -r2 = g(1, 2) +r1 = g(1, c=3, b=2) # -> 3 +r2 = g(1, 2) # -> 4 def g(a, c, b=5): return b -r3 = g(1, c=3, b=2) -r4 = g(1, 3) +r3 = g(1, c=3, b=2) # -> 2 +r4 = g(1, 3) # -> 5 # vim: tabstop=4 expandtab shiftwidth=4