Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathtype_check_Lproxy.py
More file actions
Latest commit
171 lines (166 loc) · 6.52 KB
/
Copy pathtype_check_Lproxy.py
File metadata and controls
171 lines (166 loc) · 6.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
importast
fromastimport*
fromtype_check_LanyimportTypeCheckLany
fromutilsimport*
importtyping
classTypeCheckLproxy(TypeCheckLany):
defcheck_type_equal(self, t1, t2, e):
ift1==Bottom() ort2==Bottom():
return
matcht1:
caseProxyOrListType(elt1):
matcht2:
caseProxyOrListType(elt2):
self.check_type_equal(elt1, elt2, e)
case _:
raiseException('error: '+repr(t1) +' != '+repr(t2) \
+' in '+repr(e))
caseProxyOrTupleType(ps1):
matcht2:
caseProxyOrTupleType(ps2):
for (p1,p2) inzip(ps1, ps2):
self.check_type_equal(p1, p2, e)
case _:
raiseException('error: '+repr(t1) +' != '+repr(t2) \
+' in '+repr(e))
case _:
super().check_type_equal(t1, t2, e)
defparse_type_annot(self, annot):
matchannot:
caseProxyOrTupleType(elt_types):
returnProxyOrTupleType([self.parse_type_annot(t) fortinelt_types])
caseProxyOrListType(elt_type):
returnProxyOrListType(self.parse_type_annot(elt_type))
case _:
returnsuper().parse_type_annot(annot)
deftype_check_exp(self, e, env):
matche:
# raw_tuple is just like Tuple
caseRawTuple(es):
ts= [self.type_check_exp(e, env) foreines]
e.has_type=TupleType(ts)
returne.has_type
caseTupleProxy(tup, reads, source, target):
self.check_exp(tup, source, env)
self.type_check_exp(reads, env)
# TODO: check the types of reads and writes
returntarget
caseListProxy(lst, read, write, source, target):
self.check_exp(lst, source, env)
self.type_check_exp(read, env)
self.type_check_exp(write, env)
# TODO: check the types of read and write
returntarget
caseInjectTuple(value):
tup_ty=self.type_check_exp(value, env)
matchtup_ty:
caseTupleType(ts):
returnProxyOrTupleType(ts)
case _:
raiseException('type_check error '+repr(e))
caseInjectTupleProxy(value, tup_ty):
self.type_check_exp(value, env)
# TODO: check the type of the value
matchtup_ty:
caseTupleType(ts):
returnProxyOrTupleType(ts)
case _:
raiseException('type_check error '+repr(e))
caseInjectList(value):
list_ty=self.type_check_exp(value, env)
matchlist_ty:
caseListType(elt_ty):
returnProxyOrListType(elt_ty)
case _:
raiseException('type_check error '+repr(e))
caseInjectListProxy(value, list_ty):
self.type_check_exp(value, env)
# TODO: check the type of the value
matchlist_ty:
caseListType(elt_ty):
returnProxyOrListType(elt_ty)
case _:
raiseException('type_check error '+repr(e))
caseCall(Name('is_tuple_proxy'), [arg]):
arg_ty=self.type_check_exp(arg, env)
matcharg_ty:
caseProxyOrTupleType(ts):
returnBoolType()
case _:
raiseException('type_check error: expected ProxyOrTupleType, not '+repr(arg_ty)
+' in '+repr(e))
caseCall(Name('is_array_proxy'), [arg]):
arg_ty=self.type_check_exp(arg, env)
matcharg_ty:
caseProxyOrListType(ts):
returnBoolType()
case _:
raiseException('type_check error: expected ProxyOrListType, not '+repr(arg_ty))
caseCall(Name('proxy_tuple_load'), [tup, Constant(index)]):
tup_ty=self.type_check_exp(tup, env)
matchtup_ty:
caseProxyOrTupleType(ts):
returnts[index]
case _:
raiseException('type_check error: expected ProxyOrTupleType, not '+repr(tup_ty))
caseCall(Name('project_tuple'), [arg]):
arg_ty=self.type_check_exp(arg, env)
matcharg_ty:
caseProxyOrTupleType(ts):
returnTupleType(ts)
case _:
raiseException('type_check error: expected ProxyOrTupleType, not '+repr(arg_ty))
caseCall(Name('proxy_tuple_len'), [tup]):
tup_ty=self.type_check_exp(tup, env)
matchtup_ty:
caseProxyOrTupleType(ts):
returnIntType()
case _:
raiseException('type_check error: expected ProxyOrListType, not '+repr(tup_ty))
caseCall(Name('project_array'), [arg]):
arg_ty=self.type_check_exp(arg, env)
matcharg_ty:
caseProxyOrListType(elt_ty):
returnListType(elt_ty)
case _:
raiseException('type_check error: expected ProxyOrListType, not '+repr(arg_ty))
caseCall(Name('proxy_array_len'), [tup]):
tup_ty=self.type_check_exp(tup, env)
matchtup_ty:
caseProxyOrListType(ts):
returnIntType()
case _:
raiseException('type_check error: expected ProxyOrListType, not '+repr(tup_ty))
caseCall(Name('proxy_array_load'), [lst, index]):
lst_ty=self.type_check_exp(lst, env)
index_ty=self.type_check_exp(index, env)
self.check_type_equal(index_ty, IntType(), index)
matchlst_ty:
caseProxyOrListType(ty):
returnty
case _:
raiseException('proxy_array_load expected a proxy-or-list, not '+repr(lst_ty))
caseCall(Name('proxy_array_store'), [tup, index, value]):
tup_t=self.type_check_exp(tup, env)
value_t=self.type_check_exp(value, env)
index_ty=self.type_check_exp(index, env)
self.check_type_equal(index_ty, IntType(), index)
matchtup_t:
caseProxyOrListType(ty):
self.check_type_equal(ty, value_t, e)
returnVoidType()
caseBottom():
returnVoidType()
case _:
raiseException('type_check_exp: in proxy_array_store unexpected '
+repr(tup_t))
caseCall(Name('any_store'), [tup, index, value]):
tup_t=self.type_check_exp(tup, env)
self.check_type_equal(tup_t, AnyType(), tup)
value_t=self.type_check_exp(value, env)
self.check_type_equal(value_t, AnyType(), value)
index_ty=self.type_check_exp(index, env)
self.check_type_equal(index_ty, IntType(), index)
returnVoidType()
case _:
returnsuper().type_check_exp(e, env)