1 | #!/usr/bin/env python2
|
2 | """target_lang_test.py: test out MyPy-compatible code we generated
|
3 |
|
4 | Similar to mycpp/demo/target_lang.cc
|
5 |
|
6 | List of types that could be containers:
|
7 |
|
8 | syntax.asdl:
|
9 |
|
10 | CompoundWord = (List[word_part] parts)
|
11 |
|
12 | word_part =
|
13 | ...
|
14 | | BracedTuple(List[CompoundWord] words)
|
15 |
|
16 | condition =
|
17 | Shell(List[command] commands) # if false; true; then echo hi; fi
|
18 |
|
19 | pat =
|
20 | Else
|
21 | | Words(List[word] words)
|
22 | | YshExprs(List[expr] exprs)
|
23 |
|
24 | command =
|
25 | | CommandList(List[command] children)
|
26 |
|
27 | re =
|
28 | | Seq(List[re] children)
|
29 | | Alt(List[re] children)
|
30 |
|
31 |
|
32 | runtime.asdl
|
33 |
|
34 | part_value =
|
35 | String %Piece
|
36 |
|
37 | # "$@" or "${a[@]}" # never globbed or split (though other shells
|
38 | # split them)
|
39 | | Array(List[str] strs)
|
40 | | ExtGlob(List[part_value] part_vals)
|
41 |
|
42 | wait_status =
|
43 | | Pipeline(List[int] codes)
|
44 |
|
45 | trace =
|
46 | External(List[str] argv) # sync, needs argv (command.Simple or 'command')
|
47 |
|
48 | value.asdl
|
49 |
|
50 | value =
|
51 | | Str(str s)
|
52 |
|
53 | # Maybe we can add global singletons value::Bool::true and
|
54 | # value::Bool::false or something? They are pointers.
|
55 | | Bool(bool b)
|
56 |
|
57 | # Not sure if we can do anything about these. Probably should for Int and
|
58 | # Float
|
59 | | Int(BigInt i)
|
60 | | Float(float f)
|
61 |
|
62 | | BashAssoc(Dict[str, str] d)
|
63 | | List(List[value] items)
|
64 | | Dict(Dict[str, value] d)
|
65 | | Frame(Dict[str, Cell] frame)
|
66 | """
|
67 |
|
68 | from typing import List, Dict
|
69 |
|
70 |
|
71 | class word_t(object):
|
72 | pass
|
73 |
|
74 | #class CompoundWord('List[int]'):
|
75 | #class CompoundWord(word_t, 'List[int]'):
|
76 |
|
77 | #class CompoundWord(List[int]):
|
78 | class CompoundWord(word_t, List[int]):
|
79 | pass
|
80 |
|
81 | class value_t(object):
|
82 | pass
|
83 |
|
84 | class Dict_(value_t, Dict[str, value_t]):
|
85 | pass
|
86 |
|
87 | class List_(value_t, List[value_t]):
|
88 | pass
|
89 |
|
90 |
|
91 | def main():
|
92 | # type: () -> None
|
93 |
|
94 | #print(dir(collections))
|
95 |
|
96 | # Wow this works
|
97 | c = CompoundWord()
|
98 |
|
99 | c.append(42)
|
100 | print(c)
|
101 | print('len %d' % len(c))
|
102 |
|
103 | d = Dict_()
|
104 |
|
105 | d['key'] = d
|
106 | print(d)
|
107 | print(len(d))
|
108 |
|
109 | mylist = List_()
|
110 | print(mylist)
|
111 | print(len(mylist))
|
112 |
|
113 |
|
114 | if __name__ == '__main__':
|
115 | main()
|