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_Cproxy.py
More file actions
Latest commit
81 lines (75 loc) · 2.7 KB
/
Copy pathtype_check_Cproxy.py
File metadata and controls
81 lines (75 loc) · 2.7 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
fromtype_check_CanyimportTypeCheckCany
fromutilsimport*
classTypeCheckCproxy(TypeCheckCany):
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)
deftype_check_exp(self, e, env):
matche:
caseInjectTupleProxy(value, tup_typ):
self.type_check_exp(value, env)
# TODO: check the type of the value
matchtup_typ:
caseTupleType(ts):
returnProxyOrTupleType(ts)
case _:
raiseException('type_check error '+repr(e))
caseInjectTuple(value):
tup_ty=self.type_check_exp(value, env)
matchtup_ty:
caseTupleType(ts):
returnProxyOrTupleType(ts)
case _:
raiseException('type_check error '+repr(e))
caseInjectListProxy(value, tup_typ):
self.type_check_exp(value, env)
# TODO: check the type of the value
matchtup_typ:
caseListType(ty):
returnProxyOrListType(ty)
case _:
raiseException('type_check error '+repr(e))
caseInjectList(value):
tup_ty=self.type_check_exp(value, env)
matchtup_ty:
caseListType(elt_ty):
returnProxyOrListType(elt_ty)
case _:
raiseException('type_check error '+repr(e))
case _:
returnsuper().type_check_exp(e, env)
deftype_check_stmt(self, s, env):
matchs:
caseAssign([Call(Name('proxy_array_load'), [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, s)
caseBottom():
pass
case _:
raiseException('type_check_stmts: expected a proxy-or-list, not ' \
+repr(tup_t))
case _:
super().type_check_stmt(s, env)