def visit(self, node): self.code.append(LabelIL(self.cur_class, node.name, True)) #This has being push already before calling dispatch # El self se adiciona en el class node variables = Variables() variables.add_var('self') #Self its alway the first parameter for p in node.params: variables.add_var(p.name) variables.add_temp() # return address self.visit(node.body, variables) self.code.append(ReturnIL())
def visit(self, node, variables : Variables): self.code.append(PushIL()) p = variables.add_var(node.name.value) if node.expr != None: self.visit(node.expr, variables) r = variables.peek_last() self.code.append(VarToVarIL(variables.id(p), variables.id(r) )) variables.pop_var() self.code.append(PopIL(1))
def create_constructor(self, attrs): self.code.append(LabelIL(self.cur_class, 'Constructor', True)) variables = Variables() variables.add_var('self') variables.add_temp() # return address for node in attrs: if node.value == None: continue self.visit(node.value, variables) p = variables.peek_last() idx = self.vt.get_attr_id(self.cur_class, node.name.value) self.code.append(VarToMemoIL(variables.id('self'), variables.id(p), idx)) variables.pop_var() self.code.append(PopIL(1)) self.code.append(PushIL()) #No result, but needed in logic self.code.append(ReturnIL())