WE CAN RETURN VALUES FROM FUNCTIONS LESS GOOO
This commit is contained in:
@@ -11,10 +11,24 @@ class Generator:
|
||||
self.output_path = output_path
|
||||
self.variables = {}
|
||||
self.constants = {}
|
||||
self.structs = {}
|
||||
self.functions: dict[str, FunctionNode] = {}
|
||||
self.labels = []
|
||||
self.constants_reverse = {}
|
||||
self.constant_counter = 0
|
||||
|
||||
def ground_type_to_node(self, ground_type: str):
|
||||
if ground_type == "string":
|
||||
return StringNode
|
||||
elif ground_type == "int":
|
||||
return IntNode
|
||||
elif ground_type == "float":
|
||||
return FloatNode
|
||||
elif ground_type == "bool":
|
||||
return BoolNode
|
||||
else:
|
||||
return ground_type
|
||||
|
||||
def add_constant(self, value: Any, no_string: bool = False):
|
||||
existing_constant_name = self.constants_reverse.get(value, None)
|
||||
if existing_constant_name != None: return f"[.{existing_constant_name}]"
|
||||
@@ -23,6 +37,9 @@ class Generator:
|
||||
self.constant_counter += 1
|
||||
return "[.LC" + str(self.constant_counter-1) + "]"
|
||||
|
||||
def add_function(self, node: FunctionNode):
|
||||
self.functions[node.name] = node
|
||||
|
||||
def clamp_instruction_args(self, instruction: InstructionNode, min_args: int, max_args: int):
|
||||
if len(instruction.arguments) < min_args:
|
||||
traceback(self.code, "TypeError", f"{instruction.instruction} expects at least {min_args} arguments.")
|
||||
|
Reference in New Issue
Block a user