Skip to content

Commit

Permalink
feat(solver): add framework for solver module
Browse files Browse the repository at this point in the history
  • Loading branch information
bliutech committed Jul 17, 2024
1 parent 239f215 commit 45ba026
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
24 changes: 24 additions & 0 deletions solver/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
MBA solver module applying strategies to simplify the AST.
The Solver takes on the approach of applying passes to the AST in a
pipeline fashion. A pass is a transformation that simplifies the AST
in some way. The passes are defined in the passes directory.
"""
import sys
from importlib import import_module


class Solver:
def __init__(self, passes: list[str]):
self.passes: list[str] = passes

# TODO: Add type annotation for AST once classes are finished.
def run(self, ast):
for m in map(import_module, f"passes.{self.passes}"):
try:
ast = m.run_pass(ast)
except Exception as e:
print(f"Error in {m.__name__}: {e}", file=sys.stderr)
raise e
return ast
6 changes: 6 additions & 0 deletions solver/passes/template_pass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
def run_pass(ast):
return ast


class Visitor:
pass
Empty file removed solver/synthesizer.py
Empty file.

0 comments on commit 45ba026

Please sign in to comment.