-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(solver): add framework for solver module
- Loading branch information
Showing
3 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.