Example #1
0
 def _o_addsub(self, other, builder, sub, invert=False):
     if isinstance(other, VFloat):
         a = self.o_getattr("numerator", builder)
         b = self.o_getattr("denominator", builder)
         if sub:
             if invert:
                 return operators.truediv(
                     operators.sub(operators.mul(other,
                                                 b,
                                                 builder),
                                   a,
                                   builder),
                     b,
                     builder)
             else:
                 return operators.truediv(
                     operators.sub(a,
                                   operators.mul(other,
                                                 b,
                                                 builder),
                                   builder),
                     b,
                     builder)
         else:
             return operators.truediv(
                 operators.add(operators.mul(other,
                                             b,
                                             builder),
                               a,
                               builder),
                 b,
                 builder)
     else:
         if not isinstance(other, (VFraction, VInt)):
             return NotImplemented
         r = VFraction()
         if builder is not None:
             if isinstance(other, VInt):
                 i = other.o_int64(builder).auto_load(builder)
                 x, rd = self._nd(builder)
                 y = builder.mul(rd, i)
             else:
                 a, b = self._nd(builder)
                 c, d = other._nd(builder)
                 rd = builder.mul(b, d)
                 x = builder.mul(a, d)
                 y = builder.mul(c, b)
             if sub:
                 if invert:
                     rn = builder.sub(y, x)
                 else:
                     rn = builder.sub(x, y)
             else:
                 rn = builder.add(x, y)
             rn, rd = _reduce(builder, rn, rd)  # rd is already > 0
             r.auto_store(builder, _make_ssa(builder, rn, rd))
         return r
Example #2
0
 def _o_addsub(self, other, builder, sub, invert=False):
     if isinstance(other, VFloat):
         a = self.o_getattr("numerator", builder)
         b = self.o_getattr("denominator", builder)
         if sub:
             if invert:
                 return operators.truediv(
                     operators.sub(operators.mul(other,
                                                 b,
                                                 builder),
                                   a,
                                   builder),
                     b,
                     builder)
             else:
                 return operators.truediv(
                     operators.sub(a,
                                   operators.mul(other,
                                                 b,
                                                 builder),
                                   builder),
                     b,
                     builder)
         else:
             return operators.truediv(
                 operators.add(operators.mul(other,
                                             b,
                                             builder),
                               a,
                               builder),
                 b,
                 builder)
     else:
         if not isinstance(other, (VFraction, VInt)):
             return NotImplemented
         r = VFraction()
         if builder is not None:
             if isinstance(other, VInt):
                 i = other.o_int64(builder).auto_load(builder)
                 x, rd = self._nd(builder)
                 y = builder.mul(rd, i)
             else:
                 a, b = self._nd(builder)
                 c, d = other._nd(builder)
                 rd = builder.mul(b, d)
                 x = builder.mul(a, d)
                 y = builder.mul(c, b)
             if sub:
                 if invert:
                     rn = builder.sub(y, x)
                 else:
                     rn = builder.sub(x, y)
             else:
                 rn = builder.add(x, y)
             rn, rd = _reduce(builder, rn, rd)  # rd is already > 0
             r.auto_store(builder, _make_ssa(builder, rn, rd))
         return r
Example #3
0
 def o_next(self, builder):
     self._counter.set_value(
         builder,
         operators.add(self._counter, self._step, builder))
     return operators.lt(self._counter, self._maximum, builder)
Example #4
0
 def o_next(self, builder):
     self._counter.set_value(
         builder, operators.add(self._counter, self._step, builder))
     return operators.lt(self._counter, self._maximum, builder)