-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfn_operations.py
37 lines (24 loc) · 940 Bytes
/
fn_operations.py
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
import command
import exceptions
from environment import Env
# TODO we may want to combine these operator/operations things in a different way
class FnCall(command.Command):
def execute(self, env):
fname = env.qframe.popleft()
subqframe = env.qframe.popleft()
body = env.fnqueue[fname].copy()
term = body.execute(Env(qframe=subqframe.statements, rqueue=None, fnqueue=env.fnqueue))
if term == command.LOOP_TERMINATE:
raise exceptions.QQError("Can't break from a function")
env.qframe.append(subqframe)
class FnDef(command.Command):
def execute(self, env):
fname = env.qframe.popleft()
f_body = env.qframe.popleft()
env.fnqueue[fname] = f_body
class Ret(command.Command):
def execute(self, env):
return command.FUNC_TERMINATE
class Exec(command.Command):
def execute(self, env):
env.qframe.popleft().execute(env)