ITS GENERATING AN EXECUTABLE LETS GOOOO

This commit is contained in:
SpookyDervish
2025-09-01 18:00:49 +10:00
parent 62e95a24ed
commit 88cdcfa54f
7 changed files with 91 additions and 16 deletions

26
generators/generator.py Normal file
View File

@@ -0,0 +1,26 @@
from ground_ast import RootNode
class Generator:
def __init__(self, ast: RootNode, code: str, output_path: str):
self.ast = ast
self.lines: list[str] = []
self.code = code
self.output_path = output_path
def init(self):
pass
def generate_node(self, node):
self.lines.append(f"; {node}\n\t")
node_type = str(type(node))[19:-2]
if not hasattr(self, f"generate_{node_type}"):
raise Exception(f"Generator has no generate method for {node_type}.")
getattr(self, f"generate_{node_type}")(node)
def generate(self):
for statement in self.ast.statements:
self.generate_node(statement)
with open(self.output_path + ".asm", "w") as f:
f.writelines(self.lines)