forked from finch-tensor/finch-tensor-lite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecutor.py
More file actions
27 lines (21 loc) · 742 Bytes
/
executor.py
File metadata and controls
27 lines (21 loc) · 742 Bytes
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
from .compiler import LogicCompiler
from ..symbolic import gensym
class LogicExecutor:
def __init__(self, ctx, verbose=False):
self.ctx: LogicCompiler = ctx
self.codes = {}
self.verbose = verbose
def __call__(self, prgm):
prgm_structure = prgm
if prgm_structure not in self.codes:
thunk = logic_executor_code(self.ctx, prgm)
self.codes[prgm_structure] = eval(thunk), thunk
f, code = self.codes[prgm_structure]
if self.verbose:
print(code)
return f(prgm)
def logic_executor_code(ctx, prgm):
# jc = JuliaContext()
code = ctx(prgm)
fname = gensym("compute")
return f""":(function {fname}(prgm) \n {code} \n end)"""