OILS / mycpp / examples / test_hoist.py View on Github | oilshell.org

61 lines, 28 significant
1#!/usr/bin/env python2
2"""
3hoist.py
4"""
5from __future__ import print_function
6
7import os
8import sys
9
10from 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
20def 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
32S = "global string"
33
34
35def g():
36 # type: () -> None
37 print(S)
38
39
40def strfunc(s):
41 # type: (str) -> str
42 return s + "."
43
44
45def run_tests():
46 # type: () -> None
47 f('foo')
48 g()
49
50
51def run_benchmarks():
52 # type: () -> None
53 raise NotImplementedError()
54
55
56if __name__ == '__main__':
57 if os.getenv('BENCHMARK'):
58 log('Benchmarking...')
59 run_benchmarks()
60 else:
61 run_tests()