# HG changeset patch # User Paul Boddie # Date 1267057341 -3600 # Node ID 1686ed14e71328204797a2386df8fe8e4eca0e63 # Parent 213b40328a64087ea646e9c9482b8d1f0f7b4954 Fixed while loop test boolean evaluation. Updated and added tests around usage propagation. diff -r 213b40328a64 -r 1686ed14e713 TO_DO.txt --- a/TO_DO.txt Tue Feb 23 01:30:51 2010 +0100 +++ b/TO_DO.txt Thu Feb 25 01:22:21 2010 +0100 @@ -1,16 +1,5 @@ -Abandoned branches: should alternative type candidates be proposed by abandoned usage? -(This involves using both _attrnames and _attrnames_abandoned on user nodes to decide on whether guards are appropriate.) - -Usage should not be instantly fed back to users. -Branches should have an empty set of users and usage should only feed back to users defined on a branch or merged from sub-branches. - -Attribute users should be merged so that many users can be maintained for a name: - - def f(x): - if ...: - x = ... - x.a() # affects assignment node - x.b() # affects assignment and parameter nodes +Loop entry points should capture usage to update later assignments in the loop. +The continue and break statements should affect usage propagation. Constant attribute users need not maintain usage since they are already resolved. diff -r 213b40328a64 -r 1686ed14e713 micropython/ast.py --- a/micropython/ast.py Tue Feb 23 01:30:51 2010 +0100 +++ b/micropython/ast.py Thu Feb 25 01:22:21 2010 +0100 @@ -1045,6 +1045,10 @@ self.set_block(next_block) self.dispatch(node.test) + + temp = self.optimiser.optimise_temp_storage() + self._generateTestBoolean(node, temp) + if node.else_ is not None: self.new_op(JumpIfFalse(else_block)) else: diff -r 213b40328a64 -r 1686ed14e713 tests/attribute_access_type_restriction_all_new.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/attribute_access_type_restriction_all_new.py Thu Feb 25 01:22:21 2010 +0100 @@ -0,0 +1,41 @@ +#!/usr/bin/env python + +""" +This test illustrates the need for propagation of usage to assignments providing +active name definitions. +""" + +class C: + def f(self): + return 1 + +class D: + def f(self): + return 2 + + def g(self): + return 3 + +class E: + def f(self): + return 4 + + def h(self): # unused + return 5 + +def test_new(obj, obj2, obj3): + # obj should support f + if obj.f(): + obj = obj2 # should support f, g + obj.g() + else: + obj = obj3 # should support f, g + obj.g() + return obj.f() + +c = C() +d = D() +e = E() +result2_2 = test_new(c, d, d) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r 213b40328a64 -r 1686ed14e713 tests/attribute_access_type_restriction_loop.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/attribute_access_type_restriction_loop.py Thu Feb 25 01:22:21 2010 +0100 @@ -0,0 +1,32 @@ +#!/usr/bin/env python + +class C: + def f(self): + return 1 + +class D: + def f(self): + return 0 # stops the test loop + + def g(self): + return 3 + +class E: + def f(self): + return 4 + + def h(self): # unused + return 5 + +def test_loop(obj, obj2): + while obj.f(): + obj = obj2 + obj.g() + return obj.f() + +c = C() +d = D() +e = E() +result1_0 = test_loop(c, d) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r 213b40328a64 -r 1686ed14e713 tests/attribute_access_type_restriction_loop_accumulation.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/attribute_access_type_restriction_loop_accumulation.py Thu Feb 25 01:22:21 2010 +0100 @@ -0,0 +1,44 @@ +#!/usr/bin/env python + +""" +This test illustrates the need for usage to be propagated forward to the +assignment within the loop. +""" + +class C: + def e(self): # unused + return 1 + + def f(self): + return 1 + +class D: + def f(self): + return 2 + + def g(self): + return 3 + +class E: + def e(self): + return 4 + + def f(self): + return 0 # stops the test loop + + def g(self): + return 5 + +def test_loop(obj, obj2): + while obj.f(): + obj.g() + obj = obj2 # should support e, f, g + obj.e() + return obj.f() + +c = C() +d = D() +e = E() +result1_0 = test_loop(d, e) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r 213b40328a64 -r 1686ed14e713 tests/attribute_access_type_restriction_new.py --- a/tests/attribute_access_type_restriction_new.py Tue Feb 23 01:30:51 2010 +0100 +++ b/tests/attribute_access_type_restriction_new.py Thu Feb 25 01:22:21 2010 +0100 @@ -1,5 +1,10 @@ #!/usr/bin/env python +""" +This test illustrates the need for propagation of usage to assignments providing +active name definitions. +""" + class C: def f(self): return 1 @@ -19,15 +24,11 @@ return 5 def test_new(obj, obj2): - # obj: C, D, E (f) - # obj2: - if obj.f(): # C, D, E (f) - obj = obj2 # obj: D (g) - obj.g() # D (g) - # else: - # ... # obj: C, D, E (f) - # # (g) ^ (f) - return obj.f() # C, D, E (f) + # obj should provide f + if obj.f(): + obj = obj2 # should provide f, g + obj.g() + return obj.f() c = C() d = D()