| 1 | #!/usr/bin/env python2
|
| 2 | """
|
| 3 | hoist.py
|
| 4 | """
|
| 5 | from __future__ import print_function
|
| 6 |
|
| 7 | import os
|
| 8 | import sys
|
| 9 |
|
| 10 | from mycpp.mylib import log
|
| 11 |
|
| 12 | # Note: To fix this,
|
| 13 |
|
| 14 | # - The self.decl pass in assignments can collect every var, and hoist it up.
|
| 15 | # - Or it has to detect USES as well as assignments.
|
| 16 | # Or maybe it's good enough if it's assigned in two different blogs to hoist it
|
| 17 | # up?
|
| 18 |
|
| 19 |
|
| 20 | def f(s):
|
| 21 | # type: (str) -> str
|
| 22 |
|
| 23 | x = 1
|
| 24 | if x > 0:
|
| 25 | s = 'greater'
|
| 26 | else:
|
| 27 | s = 'less'
|
| 28 | print(s)
|
| 29 | return s
|
| 30 |
|
| 31 |
|
| 32 | S = "global string"
|
| 33 |
|
| 34 |
|
| 35 | def g():
|
| 36 | # type: () -> None
|
| 37 | print(S)
|
| 38 |
|
| 39 |
|
| 40 | def strfunc(s):
|
| 41 | # type: (str) -> str
|
| 42 | return s + "."
|
| 43 |
|
| 44 |
|
| 45 | def run_tests():
|
| 46 | # type: () -> None
|
| 47 | f('foo')
|
| 48 | g()
|
| 49 |
|
| 50 |
|
| 51 | def run_benchmarks():
|
| 52 | # type: () -> None
|
| 53 | raise NotImplementedError()
|
| 54 |
|
| 55 |
|
| 56 | if __name__ == '__main__':
|
| 57 | if os.getenv('BENCHMARK'):
|
| 58 | log('Benchmarking...')
|
| 59 | run_benchmarks()
|
| 60 | else:
|
| 61 | run_tests()
|