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_Cfun.py
More file actions
Latest commit
54 lines (48 loc) · 1.66 KB
/
Copy pathinterp_Cfun.py
File metadata and controls
54 lines (48 loc) · 1.66 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
fromastimport*
frominterp_CarrayimportInterpCarray
fromutilsimport*
frominterp_LfunimportFunction
classInterpCfun(InterpCarray):
defapply_fun(self, fun, args, e):
matchfun:
caseFunction(name, xs, blocks, env):
old_blocks=self.blocks
self.blocks=blocks
new_env= {x: vfor (x,v) inenv.items()}
for (x,arg) inzip(xs, args):
new_env[x] =arg
ret=self.interp_stmts(blocks[name+'_start'], new_env)
self.blocks=old_blocks
returnret
case _:
raiseException('apply_fun: unexpected: '+repr(fun))
definterp_exp(self, e, env):
matche:
caseCall(Name(f), args) iffinbuiltin_functions:
returnsuper().interp_exp(e, env)
caseCall(func, args):
f=self.interp_exp(func, env)
vs= [self.interp_exp(arg, env) forarginargs]
returnself.apply_fun(f, vs, e)
caseFunRef(id, arity):
returnenv[id]
case _:
returnsuper().interp_exp(e, env)
definterp_tail(self, s, env):
matchs:
caseTailCall(func, args):
returnself.interp_exp(Call(func, args), env)
case _:
returnsuper().interp_tail(s, env)
definterp(self, p):
matchp:
caseCProgramDefs(defs):
env= {}
fordindefs:
matchd:
caseFunctionDef(name, params, blocks, dl, returns, comment):
env[name] =Function(name, [xfor (x,t) inparams], blocks, env)
self.blocks= {}
self.apply_fun(env['main'], [], None)
case _:
raiseException('interp: unexpected '+repr(p))