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 pathinterp_Llambda.py
More file actions
Latest commit
61 lines (55 loc) · 1.86 KB
/
Copy pathinterp_Llambda.py
File metadata and controls
61 lines (55 loc) · 1.86 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
fromastimport*
frominterp_LfunimportInterpLfun, Function
fromutilsimport*
classClosureTuple(Value):
__match_args__= ("args", "arity")
def__init__(self, args, arity):
self.args=args
self.arity=arity
def__repr__(self):
return'ClosureTuple('+repr(self.args) +', '+repr(self.arity) +')'
# TODO: move the following into interp_getitem and interp_setitem
def__getitem__(self, item):
returnself.args[item]
def__setitem__(self, item, value):
self.args[item] =value
def__len__(self):
returnlen(self.args)
classInterpLlambda(InterpLfun):
defarity(self, v):
matchv:
caseFunction(name, params, body, env):
returnlen(params)
caseClosureTuple(args, arity):
returnarity
case _:
raiseException('Llambda arity unexpected '+repr(v))
definterp_exp(self, e, env):
matche:
caseCall(Name('arity'), [fun]):
f=self.interp_exp(fun, env)
returnself.arity(f)
caseUninitialized(ty):
returnNone
caseFunRef(id, arity):
returnenv[id]
caseLambda(params, body):
returnFunction('lambda', params, [Return(body)], env)
caseUncheckedCast(exp, ty):
returnself.interp_exp(exp, env)
caseClosure(arity, args):
returnClosureTuple([self.interp_exp(arg, env) forarginargs], arity)
caseAllocateClosure(length, typ, arity):
array= [None] *length
returnClosureTuple(array, arity)
case _:
returnsuper().interp_exp(e, env)
definterp_stmt(self, s, env, cont):
matchs:
caseAnnAssign(lhs, typ, value, simple):
env[lhs.id] =self.interp_exp(value, env)
returnself.interp_stmts(cont, env)
casePass():
returnself.interp_stmts(cont, env)
case _:
returnsuper().interp_stmt(s, env, cont)