Exemple #1
0
    def div_by(self, other):
        if isinstance(other, Number):
            if other.value == 0:
                return None, RTError(other.pos_start, other.pos_end,
                                     'Division by zero', self.context)

            return Number(self.value / other.value).set_context(
                self.context), None
        else:
            return None, Value.illegal_operation(self, other)
Exemple #2
0
 def anded_by(self, other):
     if isinstance(other, Number):
         return Number(int(self.value
                           and other.value)).set_context(self.context), None
     else:
         return None, Value.illegal_operation(self, other)
Exemple #3
0
 def get_comparison_gte(self, other):
     if isinstance(other, Number):
         return Number(int(self.value >= other.value)).set_context(
             self.context), None
     else:
         return None, Value.illegal_operation(self, other)
Exemple #4
0
 def power_op(self, other):
     if isinstance(other, Number):
         return Number(self.value**other.value).set_context(
             self.context), None
     else:
         return None, Value.illegal_operation(self, other)
Exemple #5
0
 def notted(self, other):
     if isinstance(other, Number):
         return Number(int(1 if self.value == 0 else 0)).set_context(
             self.context), None
     else:
         return None, Value.illegal_operation(self, other)