# HG changeset patch # User Paul Boddie # Date 1243549120 -7200 # Node ID a179262ea7c4faa9e2ffd1b45c1db8fd9ca585aa # Parent db7d77cedddaf32163a9f28ada66a50197e0adbb Changed RecoverFrame to actually recover the locals as the invocation frame, rather than just discard the locals. Changed AdjustFrame to work on the locals. Switched the order of the above instructions in instantiator functions. Made various tests compatible with the simple testing framework. diff -r db7d77ceddda -r a179262ea7c4 micropython/ast.py --- a/micropython/ast.py Mon May 25 00:45:53 2009 +0200 +++ b/micropython/ast.py Fri May 29 00:18:40 2009 +0200 @@ -168,14 +168,14 @@ init_method = cls.get_init_method() + # Fix the current frame to include a new storage slot at the beginning. + + self.new_op(AdjustFrame(-1)) + # Convert this frame back to being an invocation frame. self.new_op(RecoverFrame()) - # Fix the current frame to include a new storage slot at the beginning. - - self.new_op(AdjustFrame(-1)) - # Make an object. self.make_object(cls, len(cls.instance_attributes())) diff -r db7d77ceddda -r a179262ea7c4 rsvp.py --- a/rsvp.py Mon May 25 00:45:53 2009 +0200 +++ b/rsvp.py Fri May 29 00:18:40 2009 +0200 @@ -280,21 +280,24 @@ self.run() success = 1 - for name in module.keys(): - if name.startswith("result"): - label, expected = name.split("_") - attr = module[name] + if self.exception is None: + for name in module.keys(): + if name.startswith("result"): + label, expected = name.split("_") + attr = module[name] - # NOTE: Assumptions about headers and content made. + # NOTE: Assumptions about headers and content made. - attr_location = module.location + 1 + attr.position - context, ref = self.load(attr_location) - content = self.load(ref + 1) - print label, expected, content + attr_location = module.location + 1 + attr.position + context, ref = self.load(attr_location) + content = self.load(ref + 1) + print label, expected, content - success = success and (int(expected) == content) + success = success and (int(expected) == content) - return success + return success + else: + return 0 def execute(self): @@ -509,7 +512,7 @@ self.frame_stack = self.frame_stack[:frame] # reset stack before call def RecoverFrame(self): - self.local_sp_stack.pop() + self.invocation_sp_stack[-1] = self.local_sp_stack.pop() def StoreFrame(self): frame = self.invocation_sp_stack[-1] # different from the current frame after MakeFrame @@ -618,7 +621,7 @@ self.frame_stack.extend([None] * self.operand) def AdjustFrame(self): - self.invocation_sp_stack[-1] += self.operand + self.local_sp_stack[-1] += self.operand def Return(self): return self.pull_pc() diff -r db7d77ceddda -r a179262ea7c4 tests/call_func.py --- a/tests/call_func.py Mon May 25 00:45:53 2009 +0200 +++ b/tests/call_func.py Fri May 29 00:18:40 2009 +0200 @@ -3,8 +3,8 @@ def f(a, b, c): return c -x = f(1, 2, 3) -y = f(1, b=2, c=3) -z = f(c=3, b=2, a=1) +result1_3 = f(1, 2, 3) +result2_3 = f(1, b=2, c=3) +result3_3 = f(c=3, b=2, a=1) # vim: tabstop=4 expandtab shiftwidth=4 diff -r db7d77ceddda -r a179262ea7c4 tests/call_func_default.py --- a/tests/call_func_default.py Mon May 25 00:45:53 2009 +0200 +++ b/tests/call_func_default.py Fri May 29 00:18:40 2009 +0200 @@ -3,7 +3,7 @@ def f(a, b, c=4): return c -r1 = f(1, 2, 3) -r2 = f(1, 2) +result_3 = f(1, 2, 3) +result_4 = f(1, 2) # vim: tabstop=4 expandtab shiftwidth=4 diff -r db7d77ceddda -r a179262ea7c4 tests/call_func_default_keyword.py --- a/tests/call_func_default_keyword.py Mon May 25 00:45:53 2009 +0200 +++ b/tests/call_func_default_keyword.py Fri May 29 00:18:40 2009 +0200 @@ -3,9 +3,9 @@ def f(a, b, c=4): return c -p = f(1, 2, 3) -q = f(1, b=2, c=3) -r = f(c=3, b=2, a=1) -s = f(1, 2) +result1_3 = f(1, 2, 3) +result2_3 = f(1, b=2, c=3) +result3_3 = f(c=3, b=2, a=1) +result_4 = f(1, 2) # vim: tabstop=4 expandtab shiftwidth=4 diff -r db7d77ceddda -r a179262ea7c4 tests/call_func_default_non_constant.py --- a/tests/call_func_default_non_constant.py Mon May 25 00:45:53 2009 +0200 +++ b/tests/call_func_default_non_constant.py Fri May 29 00:18:40 2009 +0200 @@ -6,7 +6,7 @@ def h(a, b, c=f(5, 4, 3)): return c -x = h(1, 2, 3) # -> 3 -y = h(1, 2) # -> 4 +result_3 = h(1, 2, 3) # h(c=3) -> 3 +result_4 = h(1, 2) # h(c=f(5, 4, 3)) -> h(c=f(b=4)) -> h(c=4) -> 4 # vim: tabstop=4 expandtab shiftwidth=4 diff -r db7d77ceddda -r a179262ea7c4 tests/call_func_default_redefine.py --- a/tests/call_func_default_redefine.py Mon May 25 00:45:53 2009 +0200 +++ b/tests/call_func_default_redefine.py Fri May 29 00:18:40 2009 +0200 @@ -4,13 +4,14 @@ return c g = f -r1 = g(1, c=3, b=2) # -> 3 -r2 = g(1, 2) # -> 4 + +result_3 = g(1, c=3, b=2) # f(c=3) -> 3 +result_4 = g(1, 2) # f(c=4) -> 4 def g(a, c, b=5): return b -r3 = g(1, c=3, b=2) # -> 2 -r4 = g(1, 3) # -> 5 +result_2 = g(1, c=3, b=2) # g(b=2) -> 2 +result_5 = g(1, 3) # g(b=5) -> 5 # vim: tabstop=4 expandtab shiftwidth=4 diff -r db7d77ceddda -r a179262ea7c4 tests/call_func_extra.py --- a/tests/call_func_extra.py Mon May 25 00:45:53 2009 +0200 +++ b/tests/call_func_extra.py Fri May 29 00:18:40 2009 +0200 @@ -1,21 +1,22 @@ #!/usr/bin/env python def f(a, b, *c): - pass + return c -f(1, 2, 3) -f(1, b=2) -f(1, 2, 3, 4) +r1 = f(1, 2, 3) +r2 = f(1, b=2) +r3 = f(1, 2, 3, 4) g = f -g(1, 2, 3) -g(1, b=2) -g(1, 2, 3, 4) + +r4 = g(1, 2, 3) +r5 = g(1, b=2) +r6 = g(1, 2, 3, 4) def g(a, c, *b): - pass + return b -g(1, c=2) -g(1, 2, 3, 4) +r7 = g(1, c=2) +r8 = g(1, 2, 3, 4) # vim: tabstop=4 expandtab shiftwidth=4 diff -r db7d77ceddda -r a179262ea7c4 tests/call_func_keyword.py --- a/tests/call_func_keyword.py Mon May 25 00:45:53 2009 +0200 +++ b/tests/call_func_keyword.py Fri May 29 00:18:40 2009 +0200 @@ -1,18 +1,14 @@ #!/usr/bin/env python def f(a, b, **c): - pass + return c -f(1, 2, 3) -f(1, b=2, c=3, d=4) -f(c=3, b=2, a=1, d=4) +r1 = f(1, 2, 3) +r2 = f(1, b=2, c=3, d=4) +r3 = f(c=3, b=2, a=1, d=4) g = f -g(1, c=3, b=2, d=4) -def g(a, c, b): - pass - -g(1, c=3, b=2, d=4) +r4 = g(1, c=3, b=2, d=4) # vim: tabstop=4 expandtab shiftwidth=4 diff -r db7d77ceddda -r a179262ea7c4 tests/call_func_star_parameter_unpack.py --- a/tests/call_func_star_parameter_unpack.py Mon May 25 00:45:53 2009 +0200 +++ b/tests/call_func_star_parameter_unpack.py Fri May 29 00:18:40 2009 +0200 @@ -4,6 +4,6 @@ a, b, c = args return c -x = f(1, 2, 3) +result_3 = f(1, 2, 3) # vim: tabstop=4 expandtab shiftwidth=4 diff -r db7d77ceddda -r a179262ea7c4 tests/call_func_uncertain.py --- a/tests/call_func_uncertain.py Mon May 25 00:45:53 2009 +0200 +++ b/tests/call_func_uncertain.py Fri May 29 00:18:40 2009 +0200 @@ -4,11 +4,12 @@ return c g = f -x = g(1, c=3, b=2) + +result1_3 = g(1, c=3, b=2) def g(a, c, b): return c -y = g(1, c=3, b=2) +result2_3 = g(1, c=3, b=2) # vim: tabstop=4 expandtab shiftwidth=4 diff -r db7d77ceddda -r a179262ea7c4 tests/call_instance.py --- a/tests/call_instance.py Mon May 25 00:45:53 2009 +0200 +++ b/tests/call_instance.py Fri May 29 00:18:40 2009 +0200 @@ -2,9 +2,9 @@ class C: def __call__(self): - return "called" + return 42 c = C() -result = c() +result_42 = c() # vim: tabstop=4 expandtab shiftwidth=4 diff -r db7d77ceddda -r a179262ea7c4 tests/call_instance_attribute.py --- a/tests/call_instance_attribute.py Mon May 25 00:45:53 2009 +0200 +++ b/tests/call_instance_attribute.py Fri May 29 00:18:40 2009 +0200 @@ -2,7 +2,7 @@ class C: def __call__(self): - return "called" + return 42 class D: def __init__(self, x): @@ -10,6 +10,6 @@ c = C() d = D(c) -result = d.x() +result_42 = d.x() # vim: tabstop=4 expandtab shiftwidth=4 diff -r db7d77ceddda -r a179262ea7c4 tests/failure/call_func_keyword_excess.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/failure/call_func_keyword_excess.py Fri May 29 00:18:40 2009 +0200 @@ -0,0 +1,8 @@ +#!/usr/bin/env python + +def g(a, c, b): + pass + +g(1, c=3, b=2, d=4) + +# vim: tabstop=4 expandtab shiftwidth=4