micropython

Changeset

726:dead7756e3d6
2013-10-27 Paul Boddie raw files shortlog changelog graph Added an example showing how assignment information is flow-sensitive. syspython-as-target
tests/loop_assignments.py (file)
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/tests/loop_assignments.py	Sun Oct 27 01:51:49 2013 +0200
     1.3 @@ -0,0 +1,24 @@
     1.4 +#!/usr/bin/env python
     1.5 +
     1.6 +class C:
     1.7 +    x = 123
     1.8 +
     1.9 +class D:
    1.10 +    x = 456
    1.11 +
    1.12 +a = C()
    1.13 +b = D()
    1.14 +i = 4
    1.15 +
    1.16 +while i > 0:
    1.17 +    i -= 1
    1.18 +    if i == 2:
    1.19 +        a = D()     # influences the loop
    1.20 +        continue
    1.21 +    if i == 3:
    1.22 +        b = a       # type of a is C or D (by flow analysis)
    1.23 +
    1.24 +result_123 = b.x
    1.25 +result_456 = a.x
    1.26 +
    1.27 +# vim: tabstop=4 expandtab shiftwidth=4