Skip to content

Commit aa67013

Browse files
committed
add len to Ltup interp and type check
1 parent b381297 commit aa67013

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

interp_Ltup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ def interp_exp(self, e, env):
1919
t = self.interp_exp(tup, env)
2020
n = self.interp_exp(index, env)
2121
return t[n]
22+
case Call(Name('len'), [tup]):
23+
t = self.interp_exp(tup, env)
24+
return len(t)
2225
case Allocate(length, typ):
2326
array = [None] * length
2427
return array

type_check_Ltup.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ def type_check_exp(self, e, env):
2626
return ts[index]
2727
case _:
2828
raise Exception('error: expected a tuple, not ' + repr(tup_ty))
29+
case Call(Name('len'), [tup]):
30+
tup_t = self.type_check_exp(tup, env)
31+
match tup_t:
32+
case TupleType(ts):
33+
return int
34+
case Bottom():
35+
return Bottom()
36+
case _:
37+
raise Exception('error, expected a tuple, not ' + repr(tup_t))
2938
case _:
3039
return super().type_check_exp(e, env)
3140

0 commit comments

Comments
 (0)