def compile(self, environment): newAmbito = Ambito(environment) pos = 0 for var in self.params: pos = ThreeAddressCode().stackCounter newAmbito.addVar(var.id, var.data_type, None, pos, var.line, var.column) lbl_exit = ThreeAddressCode().newLabel() self.body.compile(newAmbito) ThreeAddressCode().addCode(f"label .{lbl_exit}") #Agregando etiqueta ThreeAddressCode().addCode(f"print(\"GraciasDios, SALI\")")
def print(self, environment): if ThreeAddressCode().searchFunction(self.id): return None ThreeAddressCode().newFunction(self.id) newAmbito = Ambito(environment) pos = 0 var_array = [] for var in self.params: pos = ThreeAddressCode().stackCounter var_array.append(newAmbito.addVar(var.id, var.data_type, None, pos, var.line, var.column)) ThreeAddressCode().incStackCounter() pos = ThreeAddressCode().stackCounter #Generando etiqueta de salida para la funcion lbl_exit = ThreeAddressCode().newLabel() newAmbito.lbl_return = lbl_exit #Agregando cuerpo de la funcion self.body.compile(newAmbito) # Agregando etiqueta de salida ThreeAddressCode().addCode(f"label .{lbl_exit}") # Imprime primera variable declarada, NO parametro # ThreeAddressCode().addCode(f"print(Stack[{pos}])") ThreeAddressCode().createFunction(self.id, self.params, var_array) return var_array