RETURNING WORKSSSSS

This commit is contained in:
SpookyDervish
2025-09-10 18:56:45 +10:00
parent 3103d17026
commit 523ccecbc0
5 changed files with 103 additions and 19 deletions

View File

@@ -3,17 +3,37 @@ from typing import Any
from ground_ast import *
class SymbolTable:
def __init__(self, parent=None):
self.table = {} # variable name -> info (e.g., stack offset, type)
self.parent = parent
def define(self, name, value):
self.table[name] = value
def lookup(self, name):
scope = self
while scope:
if name in scope.table:
return scope.table[name]
scope = scope.parent
return None
#raise KeyError(f"Undefined variable: {name}")
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
self.variables = {}
self.global_scope = SymbolTable()
self.current_var_scope = self.global_scope
self.constants = {}
self.structs = {}
self.functions: dict[str, FunctionNode] = {}
self.labels = []
self.arg_list = []
self.constants_reverse = {}
self.constant_counter = 0