<commit_before>from abc import ABC
from _operations import NewStaticOp, ChangeStaticValueOp, RegToStackOp, NestedOp
from _mathoperations import AdditionOp, SubtractionOp


class InterfaceObj(ABC):
    """
    Abstract Base Class for the Interface Object. This contain the
    buffer list used by all the subclasses for the stocking of the
    operations producted by there. This buffer list is a trick for
    the compilation, use with caution.
    """
    # C'è da overloaddare __init__ per creare InterfaceObj
    buffer = []

    @classmethod
    def GetBuffer(cls):
        """
        Will return the shared buffer of all the InterfaceObj subclasses.
        :return: The InterfaceObj Buffer
        """
        tmp = cls.buffer
        cls.buffer = []
        return tmp


class NestedInterfaceObj(ABC):
    """
    Abstract Base Class for the Nested Interface Object. This is
    different from classic Interface Object. This contain the
    method and the attribute definition for the NestedInterface
    infrastructure for the Operations.
    """
    def __init__(self):
        """Initialization of protected Operation Object attribute for subclasses."""
        self._OPERATION = None

    def getOp(self):
        """Get the Operation Object generated by the command."""
        return self._OPERATION


# TODO: Rimuovere duplicati self.buffer
class VAR(InterfaceObj):
    """
    This command will create a new variable in the stack.
    This command can take as value a NestedInterfaceObj SubClass.
    """
    # TODO: Default Value
    def __init__(self, name, value):  # TODO: Typecoding
        """
        This command will create a new variable in the stack.
        :param name: Name of the new variable
        :param value: Value assigned at the variable
        """
        # PER ORA SOLO VALORI NUMERICI PURI
        if isinstance(value, NestedInterfaceObj):
            oplist = [NewStaticOp(name, 0), value.getOp(), RegToStackOp(name)]
            op = NestedOp(oplist)
            self.buffer.append(op)
        else:
            op = NewStaticOp(name, value)
            self.buffer.append(op)


class SET(InterfaceObj):
    """
    This command will edit the value into a already existing variable
    in the stack.
    This command can take as value a NestedInterfaceObj SubClass.
    """
    def __init__(self, name, value):
        """
        This command will edit the value into a already existing variable
        in the stack.
        This command can take as value a NestedInterfaceObj SubClass.
        :param name: Name of the variable to be changed.
        :param value: Value or NestedInterfaceObj to be inserted in the variable.
        """
        if isinstance(value, NestedInterfaceObj):
            oplist = [value.getOp(), RegToStackOp(name)]
            op = NestedOp(oplist)
            self.buffer.append(op)
        else:
            op = ChangeStaticValueOp(name, value)
            self.buffer.append(op)


class ADD(InterfaceObj, NestedInterfaceObj):
    """
    This command will sum two variable using a Registry as output.
    This command is a NestedInterfaceObj.
    """
    def __init__(self, name1, name2):
        """
        This command will sum two variable using a Registry as output.
        This command is a NestedInterfaceObj.
        :param name1: First member
        :param name2: Second member
        """
        super().__init__()
        self._OPERATION = AdditionOp(name1, name2)


class SUB(InterfaceObj, NestedInterfaceObj):
    """
    This command will subtract two variable using a Registry as output.
    The algorithm is classical progressive subtraction.<commit_msg>Some optimization in interfaceobjects VAR and SET<commit_after>from abc import ABC
from _operations import NewStaticOp, ChangeStaticValueOp, RegToStackOp, NestedOp
from _mathoperations import AdditionOp, SubtractionOp


class InterfaceObj(ABC):
    """
    Abstract Base Class for the Interface Object. This contain the
    buffer list used by all the subclasses for the stocking of the
    operations producted by there. This buffer list is a trick for
    the compilation, use with caution.
    """
    # C'è da overloaddare __init__ per creare InterfaceObj
    buffer = []

    @classmethod
    def GetBuffer(cls):
        """
        Will return the shared buffer of all the InterfaceObj subclasses.
        :return: The InterfaceObj Buffer
        """
        tmp = cls.buffer
        cls.buffer = []
        return tmp


class NestedInterfaceObj(ABC):
    """
    Abstract Base Class for the Nested Interface Object. This is
    different from classic Interface Object. This contain the
    method and the attribute definition for the NestedInterface
    infrastructure for the Operations.
    """
    def __init__(self):
        """Initialization of protected Operation Object attribute for subclasses."""
        self._OPERATION = None

    def getOp(self):
        """Get the Operation Object generated by the command."""
        return self._OPERATION


class VAR(InterfaceObj):
    """
    This command will create a new variable in the stack.
    This command can take as value a NestedInterfaceObj SubClass.
    """
    def __init__(self, name, value=0):  # TODO: Typecoding
        """
        This command will create a new variable in the stack.
        :param name: Name of the new variable
        :param value: Value assigned at the variable
        """
        # PER ORA SOLO VALORI NUMERICI PURI
        if isinstance(value, NestedInterfaceObj):
            oplist = [NewStaticOp(name, 0), value.getOp(), RegToStackOp(name)]
            op = NestedOp(oplist)
        else:
            op = NewStaticOp(name, value)
        self.buffer.append(op)


class SET(InterfaceObj):
    """
    This command will edit the value into a already existing variable
    in the stack.
    This command can take as value a NestedInterfaceObj SubClass.
    """
    def __init__(self, name, value = 0):
        """
        This command will edit the value into a already existing variable
        in the stack.
        This command can take as value a NestedInterfaceObj SubClass.
        :param name: Name of the variable to be changed.
        :param value: Value or NestedInterfaceObj to be inserted in the variable.
        """
        if isinstance(value, NestedInterfaceObj):
            oplist = [value.getOp(), RegToStackOp(name)]
            op = NestedOp(oplist)
        else:
            op = ChangeStaticValueOp(name, value)
        self.buffer.append(op)


class ADD(InterfaceObj, NestedInterfaceObj):
    """
    This command will sum two variable using a Registry as output.
    This command is a NestedInterfaceObj.
    """
    def __init__(self, name1, name2):
        """
        This command will sum two variable using a Registry as output.
        This command is a NestedInterfaceObj.
        :param name1: First member
        :param name2: Second member
        """
        super().__init__()
        self._OPERATION = AdditionOp(name1, name2)


class SUB(InterfaceObj, NestedInterfaceObj):
    """
    This command will subtract two variable using a Registry as output.
    The algorithm is classical progressive subtraction.
{'fraction_non_alphanumeric': 0.06897030252567304, 'fraction_numerical': 0.0022203719122953097, 'mean_word_length': 2.5695889053987124, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3057356', 'n_tokens_mistral': 1880, 'n_tokens_neox': 1822, 'n_words': 755}