1.1 --- a/TO_DO.txt Tue Feb 23 01:30:51 2010 +0100
1.2 +++ b/TO_DO.txt Thu Feb 25 01:22:21 2010 +0100
1.3 @@ -1,16 +1,5 @@
1.4 -Abandoned branches: should alternative type candidates be proposed by abandoned usage?
1.5 -(This involves using both _attrnames and _attrnames_abandoned on user nodes to decide on whether guards are appropriate.)
1.6 -
1.7 -Usage should not be instantly fed back to users.
1.8 -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.
1.9 -
1.10 -Attribute users should be merged so that many users can be maintained for a name:
1.11 -
1.12 - def f(x):
1.13 - if ...:
1.14 - x = ...
1.15 - x.a() # affects assignment node
1.16 - x.b() # affects assignment and parameter nodes
1.17 +Loop entry points should capture usage to update later assignments in the loop.
1.18 +The continue and break statements should affect usage propagation.
1.19
1.20 Constant attribute users need not maintain usage since they are already resolved.
1.21
2.1 --- a/micropython/ast.py Tue Feb 23 01:30:51 2010 +0100
2.2 +++ b/micropython/ast.py Thu Feb 25 01:22:21 2010 +0100
2.3 @@ -1045,6 +1045,10 @@
2.4
2.5 self.set_block(next_block)
2.6 self.dispatch(node.test)
2.7 +
2.8 + temp = self.optimiser.optimise_temp_storage()
2.9 + self._generateTestBoolean(node, temp)
2.10 +
2.11 if node.else_ is not None:
2.12 self.new_op(JumpIfFalse(else_block))
2.13 else:
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/tests/attribute_access_type_restriction_all_new.py Thu Feb 25 01:22:21 2010 +0100
3.3 @@ -0,0 +1,41 @@
3.4 +#!/usr/bin/env python
3.5 +
3.6 +"""
3.7 +This test illustrates the need for propagation of usage to assignments providing
3.8 +active name definitions.
3.9 +"""
3.10 +
3.11 +class C:
3.12 + def f(self):
3.13 + return 1
3.14 +
3.15 +class D:
3.16 + def f(self):
3.17 + return 2
3.18 +
3.19 + def g(self):
3.20 + return 3
3.21 +
3.22 +class E:
3.23 + def f(self):
3.24 + return 4
3.25 +
3.26 + def h(self): # unused
3.27 + return 5
3.28 +
3.29 +def test_new(obj, obj2, obj3):
3.30 + # obj should support f
3.31 + if obj.f():
3.32 + obj = obj2 # should support f, g
3.33 + obj.g()
3.34 + else:
3.35 + obj = obj3 # should support f, g
3.36 + obj.g()
3.37 + return obj.f()
3.38 +
3.39 +c = C()
3.40 +d = D()
3.41 +e = E()
3.42 +result2_2 = test_new(c, d, d)
3.43 +
3.44 +# vim: tabstop=4 expandtab shiftwidth=4
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/tests/attribute_access_type_restriction_loop.py Thu Feb 25 01:22:21 2010 +0100
4.3 @@ -0,0 +1,32 @@
4.4 +#!/usr/bin/env python
4.5 +
4.6 +class C:
4.7 + def f(self):
4.8 + return 1
4.9 +
4.10 +class D:
4.11 + def f(self):
4.12 + return 0 # stops the test loop
4.13 +
4.14 + def g(self):
4.15 + return 3
4.16 +
4.17 +class E:
4.18 + def f(self):
4.19 + return 4
4.20 +
4.21 + def h(self): # unused
4.22 + return 5
4.23 +
4.24 +def test_loop(obj, obj2):
4.25 + while obj.f():
4.26 + obj = obj2
4.27 + obj.g()
4.28 + return obj.f()
4.29 +
4.30 +c = C()
4.31 +d = D()
4.32 +e = E()
4.33 +result1_0 = test_loop(c, d)
4.34 +
4.35 +# vim: tabstop=4 expandtab shiftwidth=4
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/tests/attribute_access_type_restriction_loop_accumulation.py Thu Feb 25 01:22:21 2010 +0100
5.3 @@ -0,0 +1,44 @@
5.4 +#!/usr/bin/env python
5.5 +
5.6 +"""
5.7 +This test illustrates the need for usage to be propagated forward to the
5.8 +assignment within the loop.
5.9 +"""
5.10 +
5.11 +class C:
5.12 + def e(self): # unused
5.13 + return 1
5.14 +
5.15 + def f(self):
5.16 + return 1
5.17 +
5.18 +class D:
5.19 + def f(self):
5.20 + return 2
5.21 +
5.22 + def g(self):
5.23 + return 3
5.24 +
5.25 +class E:
5.26 + def e(self):
5.27 + return 4
5.28 +
5.29 + def f(self):
5.30 + return 0 # stops the test loop
5.31 +
5.32 + def g(self):
5.33 + return 5
5.34 +
5.35 +def test_loop(obj, obj2):
5.36 + while obj.f():
5.37 + obj.g()
5.38 + obj = obj2 # should support e, f, g
5.39 + obj.e()
5.40 + return obj.f()
5.41 +
5.42 +c = C()
5.43 +d = D()
5.44 +e = E()
5.45 +result1_0 = test_loop(d, e)
5.46 +
5.47 +# vim: tabstop=4 expandtab shiftwidth=4
6.1 --- a/tests/attribute_access_type_restriction_new.py Tue Feb 23 01:30:51 2010 +0100
6.2 +++ b/tests/attribute_access_type_restriction_new.py Thu Feb 25 01:22:21 2010 +0100
6.3 @@ -1,5 +1,10 @@
6.4 #!/usr/bin/env python
6.5
6.6 +"""
6.7 +This test illustrates the need for propagation of usage to assignments providing
6.8 +active name definitions.
6.9 +"""
6.10 +
6.11 class C:
6.12 def f(self):
6.13 return 1
6.14 @@ -19,15 +24,11 @@
6.15 return 5
6.16
6.17 def test_new(obj, obj2):
6.18 - # obj: C, D, E (f)
6.19 - # obj2:
6.20 - if obj.f(): # C, D, E (f)
6.21 - obj = obj2 # obj: D (g)
6.22 - obj.g() # D (g)
6.23 - # else:
6.24 - # ... # obj: C, D, E (f)
6.25 - # # (g) ^ (f)
6.26 - return obj.f() # C, D, E (f)
6.27 + # obj should provide f
6.28 + if obj.f():
6.29 + obj = obj2 # should provide f, g
6.30 + obj.g()
6.31 + return obj.f()
6.32
6.33 c = C()
6.34 d = D()