-
Notifications
You must be signed in to change notification settings - Fork 0
/
Execution Engine with Thread Pool.py
48 lines (40 loc) · 1.48 KB
/
Execution Engine with Thread Pool.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
38
39
40
41
42
43
44
45
46
47
48
from concurrent.futures import ThreadPoolExecutor
class ExecutionEngine:
def __init__(self, ast):
self.ast = ast
def execute(self):
with ThreadPoolExecutor(max_workers=4) as executor:
futures = [executor.submit(self.execute_section, section) for section in self.ast]
for future in futures:
future.result()
def execute_section(self, section):
blocks = section['content']
for block in blocks:
action_type = block['type']
lines = block['content']
if action_type == '|*|':
self.execute_action(lines)
elif action_type == '|_|':
self.execute_statements(lines)
elif action_type == '|-|':
self.execute_request(lines)
elif action_type == '|(<::>^<::>)|':
self.execute_aot_scan(lines)
elif action_type == '|+|':
self.execute_simulation(lines)
# Add more cases as needed
def execute_action(self, lines):
for line in lines:
exec(line.strip())
def execute_statements(self, lines):
for line in lines:
exec(line.strip())
def execute_request(self, lines):
for line in lines:
exec(line.strip())
def execute_aot_scan(self, lines):
for line in lines:
exec(line.strip())
def execute_simulation(self, lines):
for line in lines:
exec(line.strip())