Skip to content

Commit b381297

Browse files
committed
added len to interp_Ctup and type_check_Ctup
1 parent c4caab8 commit b381297

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

interp_Ctup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ def interp_exp(self, e, env):
2020
return self.interp_exp(e, env)
2121
case GlobalValue(name):
2222
return 0 # bogus
23+
case Call(Name('len'), [tup]):
24+
t = self.interp_exp(tup, env)
25+
return len(t)
2326
case _:
2427
return super().interp_exp(e, env)
2528

type_check_Ctup.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,15 @@ def type_check_exp(self, e, env):
2020
return Bottom()
2121
case _:
2222
raise Exception('error, expected a tuple, not ' + repr(tup_t))
23+
case Call(Name('len'), [tup]):
24+
tup_t = self.type_check_atm(tup, env)
25+
match tup_t:
26+
case TupleType(ts):
27+
return int
28+
case Bottom():
29+
return Bottom()
30+
case _:
31+
raise Exception('error, expected a tuple, not ' + repr(tup_t))
2332
case _:
2433
return super().type_check_exp(e, env)
2534

0 commit comments

Comments
 (0)