Beispiel #1
0
 def from_initialize(self, operand):
     var_operand = None
     if operand in self.current_function.function_variables:
         var_operand = self.current_function.function_variables[operand]
     elif operand in self.functions_table.functions[
             "global"].function_variables:
         var_operand = self.functions_table.functions[
             "global"].function_variables[operand]
     # From variable was already declared locally or globally
     if var_operand:
         # Check if variable is INT to procede
         if (var_operand.variable_type == Types.INT):
             # Pop variable value and save
             from_variable_value = self.operands_stack.pop()
             self.types_stack.pop()
             self.quadruples.append("=", from_variable_value, None,
                                    var_operand.variable_address)
             self.current_function.function_variables[
                 'from_variable'] = Variable(Types.INT, 'from_variable',
                                             from_variable_value,
                                             var_operand.variable_address)
         else:
             print('ERROR: La variable ' + operand + 'no es un entero')
     else:
         print('ERROR: La variable ' + operand + ' no está declarada')
Beispiel #2
0
 def update_variables(self, type, name):
     if name not in self.function_variables:
         address = self.function_memory.get_address(type)
         self.function_variables[name] = Variable(type, name, None, address)
         self.variables_count += 1
     else:
         print(
             "ERROR: No se puede tener más de una variable con el mismo nombre"
         )
Beispiel #3
0
 def update_parameters(self, type, name):
     if name not in self.function_parameters:
         address = self.function_memory.get_address(type)
         self.function_parameters.append(Variable(type, name, None,
                                                  address))
         self.update_variables(type, name)
     else:
         print(
             "ERROR: No se puede tener más de un parámetro con el mismo nombre."
         )
Beispiel #4
0
    def visit_FunctionDef(self, node):
        if node.name == 'on_packet':
            for arg in node.args.args:
                variable = Variable(arg.arg)
                self.fp.add_variable(variable)

            gv = self.fp.new_guard_variable()
            var = self.visit(node.args.args[1].annotation)
            inst = Instruction(self.guardStack[-1],
                               [self.fp.new_variable('inport_label'), var],
                               [gv], 'eq')
            self.fp.add_instruction(inst)
            self.guardStack.append(gv)
            self.generic_visit(node)
            self.guardStack.pop()
Beispiel #5
0
 def add_constant_operand(self, operand, type):
     address = self.constant_memory.get_address(type)
     constant = Variable(type, operand, operand, address)
     self.constant_exec_memory.save_value(address, operand)
     self.operands_stack.append(constant.variable_address)
     self.types_stack.append(type)
Beispiel #6
0
 def new_guard_variable(self):
     name = self.__gen_variable_name('g')
     variable = Variable(name)
     self.variables.append(variable)
     return variable
Beispiel #7
0
 def new_variable(self, name=None):
     if name is None:
         name = self.__gen_variable_name()
     variable = Variable(name)
     self.variables.append(variable)
     return variable
Beispiel #8
0
 def visit_Attribute(self, node):
     return Variable(astunparse.unparse(node).strip())