def _impl_pow(space, iv, w_int2, iz=r_longlong(0)):
    iw = w_int2.intval
    if iw < 0:
        if iz != 0:
            raise OperationError(space.w_TypeError,
                             space.wrap("pow() 2nd argument "
                 "cannot be negative when 3rd argument specified"))
        ## bounce it, since it always returns float
        raise FailedToImplementArgs(space.w_ValueError,
                                space.wrap("integer exponentiation"))
    temp = iv
    ix = r_longlong(1)
    try:
        while iw > 0:
            if iw & 1:
                ix = llong_mul_ovf(ix, temp)
            iw >>= 1   #/* Shift exponent down by 1 bit */
            if iw==0:
                break
            temp = llong_mul_ovf(temp, temp) #/* Square the value of temp */
            if iz:
                #/* If we did a multiplication, perform a modulo */
                ix = ix % iz
                temp = temp % iz
        if iz:
            ix = ix % iz
    except OverflowError:
        raise FailedToImplementArgs(space.w_OverflowError,
                                space.wrap("integer exponentiation"))
    return W_SmallLongObject(ix)
Esempio n. 2
0
 def g(n, m, o):
     # This function should be completely marked as residual by
     # codewriter.py on 32-bit platforms.  On 64-bit platforms,
     # this function should be JITted and the test should pass too.
     n = r_longlong(n)
     m = r_longlong(m)
     return intmask((n*m) // o)
Esempio n. 3
0
 def g(n, m, o):
     # This function should be completely marked as residual by
     # codewriter.py on 32-bit platforms.  On 64-bit platforms,
     # this function should be JITted and the test should pass too.
     n = r_longlong(n)
     m = r_longlong(m)
     return intmask((n * m) // o)
Esempio n. 4
0
def _impl_pow(space, iv, w_int2, iz=r_longlong(0)):
    iw = w_int2.intval
    if iw < 0:
        if iz != 0:
            raise OperationError(
                space.w_TypeError,
                space.wrap("pow() 2nd argument "
                           "cannot be negative when 3rd argument specified"))
        ## bounce it, since it always returns float
        raise FailedToImplementArgs(space.w_ValueError,
                                    space.wrap("integer exponentiation"))
    temp = iv
    ix = r_longlong(1)
    try:
        while iw > 0:
            if iw & 1:
                ix = llong_mul_ovf(ix, temp)
            iw >>= 1  #/* Shift exponent down by 1 bit */
            if iw == 0:
                break
            temp = llong_mul_ovf(temp, temp)  #/* Square the value of temp */
            if iz:
                #/* If we did a multiplication, perform a modulo */
                ix = ix % iz
                temp = temp % iz
        if iz:
            ix = ix % iz
    except OverflowError:
        raise FailedToImplementArgs(space.w_OverflowError,
                                    space.wrap("integer exponentiation"))
    return W_SmallLongObject(ix)
Esempio n. 5
0
def test_cast_float_to_ulonglong():
    f = 12350000000000000000.0
    py.test.raises(OverflowError, r_longlong, f)
    r_longlong(f / 2)   # does not raise OverflowError
    #
    x = llop.cast_float_to_ulonglong(lltype.UnsignedLongLong, f)
    assert x == r_ulonglong(f)
Esempio n. 6
0
def test_direct():
    space = gettestobjspace(**{"objspace.std.withsmalllong": True})
    w5 = space.wrap(r_longlong(5))
    assert isinstance(w5, W_SmallLongObject)
    wlarge = space.wrap(r_longlong(0x123456789ABCDEFL))
    #
    assert space.int_w(w5) == 5
    if sys.maxint < 0x123456789ABCDEFL:
        py.test.raises(OperationError, space.int_w, wlarge)
    else:
        assert space.int_w(wlarge) == 0x123456789ABCDEF
    #
    assert space.pos(w5) is w5
    assert space.abs(w5) is w5
    wm5 = space.wrap(r_longlong(-5))
    assert space.int_w(space.abs(wm5)) == 5
    assert space.int_w(space.neg(w5)) == -5
    assert space.is_true(w5) is True
    assert space.is_true(wm5) is True
    w0 = space.wrap(r_longlong(0))
    assert space.is_true(w0) is False
    #
    w14000000000000 = space.wrap(r_longlong(0x14000000000000L))
    assert space.is_true(space.eq(
        space.lshift(w5, space.wrap(49)), w14000000000000)) is False
    assert space.is_true(space.eq(
        space.lshift(w5, space.wrap(50)), w14000000000000)) is True
    #
    w_huge = space.sub(space.lshift(w5, space.wrap(150)), space.wrap(1))
    wx = space.and_(w14000000000000, w_huge)
    assert space.is_true(space.eq(wx, w14000000000000))
Esempio n. 7
0
 def f(n1, n2):
     # n == -30000000000000
     n = (r_longlong(n1) << 32) | r_longlong(n2)
     compare(n < n,  0, 0)
     compare(n <= n, 0, 1)
     compare(n == n, 0, 1)
     compare(n != n, 0, 0)
     compare(n >  n, 0, 0)
     compare(n >= n, 0, 1)
     o = n + 2000000000
     compare(o, -6985, -1948404736)
     compare(n <  o, 0, 1)     # low word differs
     compare(n <= o, 0, 1)
     compare(o <  n, 0, 0)
     compare(o <= n, 0, 0)
     compare(n >  o, 0, 0)
     compare(n >= o, 0, 0)
     compare(o >  n, 0, 1)
     compare(o >= n, 0, 1)
     compare(n == o, 0, 0)
     compare(n != o, 0, 1)
     p = -o
     compare(n <  p, 0, 1)     # high word differs
     compare(n <= p, 0, 1)
     compare(p <  n, 0, 0)
     compare(p <= n, 0, 0)
     compare(n >  p, 0, 0)
     compare(n >= p, 0, 0)
     compare(p >  n, 0, 1)
     compare(p >= n, 0, 1)
     compare(n == p, 0, 0)
     compare(n != p, 0, 1)
     return 1
Esempio n. 8
0
def min_max_acc_method(size, signed):
    if signed:
        min = -(2 ** (8*size-1))
        max = (2 ** (8*size-1)) - 1
        if size <= native_int_size:
            accept_method = 'accept_int_arg'
            min = int(min)
            max = int(max)
        else:
            accept_method = 'accept_longlong_arg'
            min = r_longlong(min)
            max = r_longlong(max)
    else:
        min = 0
        max = (2 ** (8*size)) - 1
        if size < native_int_size:
            accept_method = 'accept_int_arg'
        elif size == native_int_size:
            accept_method = 'accept_uint_arg'
            min = r_uint(min)
            max = r_uint(max)
        else:
            accept_method = 'accept_ulonglong_arg'
            min = r_ulonglong(min)
            max = r_ulonglong(max)
    return min, max, accept_method
Esempio n. 9
0
 def f(n1, n2):
     # n == -30000000000000
     n = (r_longlong(n1) << 32) | r_longlong(n2)
     compare(n < n, 0, 0)
     compare(n <= n, 0, 1)
     compare(n == n, 0, 1)
     compare(n != n, 0, 0)
     compare(n > n, 0, 0)
     compare(n >= n, 0, 1)
     o = n + 2000000000
     compare(o, -6985, -1948404736)
     compare(n < o, 0, 1)  # low word differs
     compare(n <= o, 0, 1)
     compare(o < n, 0, 0)
     compare(o <= n, 0, 0)
     compare(n > o, 0, 0)
     compare(n >= o, 0, 0)
     compare(o > n, 0, 1)
     compare(o >= n, 0, 1)
     compare(n == o, 0, 0)
     compare(n != o, 0, 1)
     p = -o
     compare(n < p, 0, 1)  # high word differs
     compare(n <= p, 0, 1)
     compare(p < n, 0, 0)
     compare(p <= n, 0, 0)
     compare(n > p, 0, 0)
     compare(n >= p, 0, 0)
     compare(p > n, 0, 1)
     compare(p >= n, 0, 1)
     compare(n == p, 0, 0)
     compare(n != p, 0, 1)
     return 1
Esempio n. 10
0
def test_cast_float_to_ulonglong():
    f = 12350000000000000000.0
    py.test.raises(OverflowError, r_longlong, f)
    r_longlong(f / 2)  # does not raise OverflowError
    #
    x = llop.cast_float_to_ulonglong(lltype.UnsignedLongLong, f)
    assert x == r_ulonglong(f)
Esempio n. 11
0
def min_max_acc_method(size, signed):
    if signed:
        min = -(2**(8 * size - 1))
        max = (2**(8 * size - 1)) - 1
        if size <= native_int_size:
            accept_method = 'accept_int_arg'
            min = int(min)
            max = int(max)
        else:
            accept_method = 'accept_longlong_arg'
            min = r_longlong(min)
            max = r_longlong(max)
    else:
        min = 0
        max = (2**(8 * size)) - 1
        if size < native_int_size:
            accept_method = 'accept_int_arg'
        elif size == native_int_size:
            accept_method = 'accept_uint_arg'
            min = r_uint(min)
            max = r_uint(max)
        else:
            accept_method = 'accept_ulonglong_arg'
            min = r_ulonglong(min)
            max = r_ulonglong(max)
    return min, max, accept_method
Esempio n. 12
0
 def test_slonglong_args(self):
     """
         long long sum_xy_longlong(long long x, long long y)
         {
             return x+y;
         }
     """
     maxint32 = 2147483647 # we cannot really go above maxint on 64 bits
                           # (and we would not test anything, as there long
                           # is the same as long long)
     libfoo = self.get_libfoo()
     func = (libfoo, 'sum_xy_longlong', [types.slonglong, types.slonglong],
             types.slonglong)
     if IS_32_BIT:
         x = r_longlong(maxint32+1)
         y = r_longlong(maxint32+2)
         zero = longlong2float(r_longlong(0))
     else:
         x = maxint32+1
         y = maxint32+2
         zero = 0
     res = self.call(func, [x, y], rffi.LONGLONG, init_result=zero)
     if IS_32_BIT:
         # obscure, on 32bit it's really a long long, so it returns a
         # DOUBLE because of the JIT hack
         res = float2longlong(res)
     expected = maxint32*2 + 3
     assert res == expected
Esempio n. 13
0
 def f(x):
     if x == r_longlong(3):
         return 9
     elif x == r_longlong(9):
         return 27
     elif x == r_longlong(27):
         return 3
     return 0
Esempio n. 14
0
 def f(x):
     if x == r_longlong(3):
         return 9
     elif x == r_longlong(9):
         return 27
     elif x == r_longlong(27):
         return 3
     return 0
Esempio n. 15
0
def unmarshal_Int64(space, u, tc):
    lo = u.get_int()  # get the first 32 bits
    hi = u.get_int()  # get the next 32 bits
    if LONG_BIT >= 64:
        x = (hi << 32) | (lo & (2**32 - 1))  # result fits in an int
    else:
        x = (r_longlong(hi) << 32) | r_longlong(r_uint(lo))  # get a r_longlong
    return space.wrap(x)
Esempio n. 16
0
 def g(n, m, o, p):
     # On 64-bit platforms, long longs == longs.  On 32-bit platforms,
     # this function should be either completely marked as residual
     # (with supports_longlong==False), or be compiled as a
     # sequence of residual calls (with long long arguments).
     n = r_longlong(n)
     m = r_longlong(m)
     return intmask((n * m + p) // o)
Esempio n. 17
0
 def g(n, m, o, p):
     # On 64-bit platforms, long longs == longs.  On 32-bit platforms,
     # this function should be either completely marked as residual
     # (with supports_longlong==False), or be compiled as a
     # sequence of residual calls (with long long arguments).
     n = r_longlong(n)
     m = r_longlong(m)
     return intmask((n*m + p) // o)
Esempio n. 18
0
def unmarshal_Int64(space, u, tc):
    lo = u.get_int()    # get the first 32 bits
    hi = u.get_int()    # get the next 32 bits
    if LONG_BIT >= 64:
        x = (hi << 32) | (lo & (2**32-1))    # result fits in an int
    else:
        x = (r_longlong(hi) << 32) | r_longlong(r_uint(lo))  # get a r_longlong
    return space.wrap(x)
Esempio n. 19
0
 def test_float_conversion_implicit(self):
     def f(ii):
         return 1.0 + ii
     res = self.interpret(f, [r_longlong(100000000)])
     assert type(res) is float
     assert res == 100000001.
     res = self.interpret(f, [r_longlong(1234567890123456789)])
     assert type(res) is float
     assert self.float_eq(res, 1.2345678901234568e+18)
Esempio n. 20
0
def pack_float(result, number, size, bigendian):
    """Append to 'result' the 'size' characters of the 32-bit or 64-bit
    IEEE representation of the number.
    """
    if size == 4:
        bias = 127
        exp = 8
        prec = 23
    else:
        bias = 1023
        exp = 11
        prec = 52

    if isnan(number):
        sign = 0x80
        man, e = 1.5, bias + 1
    else:
        if number < 0:
            sign = 0x80
            number *= -1
        elif number == 0.0:
            for i in range(size):
                result.append('\x00')
            return
        else:
            sign = 0x00
        if isinf(number):
            man, e = 1.0, bias + 1
        else:
            man, e = math.frexp(number)

    if 0.5 <= man and man < 1.0:
        man *= 2
        e -= 1
    man -= 1
    e += bias
    power_of_two = r_longlong(1) << prec
    mantissa = r_longlong(power_of_two * man + 0.5)
    if mantissa >> prec:
        mantissa = 0
        e += 1

    for i in range(size - 2):
        result.append(chr(mantissa & 0xff))
        mantissa >>= 8
    x = (mantissa & ((1 << (15 - exp)) - 1)) | ((e & ((1 << (exp - 7)) - 1)) <<
                                                (15 - exp))
    result.append(chr(x))
    x = sign | e >> (exp - 7)
    result.append(chr(x))
    if bigendian:
        first = len(result) - size
        last = len(result) - 1
        for i in range(size // 2):
            (result[first + i], result[last - i]) = (result[last - i],
                                                     result[first + i])
Esempio n. 21
0
File: ieee.py Progetto: alkorzt/pypy
def pack_float(result, number, size, bigendian):
    """Append to 'result' the 'size' characters of the 32-bit or 64-bit
    IEEE representation of the number.
    """
    if size == 4:
        bias = 127
        exp = 8
        prec = 23
    else:
        bias = 1023
        exp = 11
        prec = 52

    if isnan(number):
        sign = 0x80
        man, e = 1.5, bias + 1
    else:
        if number < 0:
            sign = 0x80
            number *= -1
        elif number == 0.0:
            for i in range(size):
                result.append('\x00')
            return
        else:
            sign = 0x00
        if isinf(number):
            man, e = 1.0, bias + 1
        else:
            man, e = math.frexp(number)

    if 0.5 <= man and man < 1.0:
        man *= 2
        e -= 1
    man -= 1
    e += bias
    power_of_two = r_longlong(1) << prec
    mantissa = r_longlong(power_of_two * man + 0.5)
    if mantissa >> prec :
        mantissa = 0
        e += 1

    for i in range(size-2):
        result.append(chr(mantissa & 0xff))
        mantissa >>= 8
    x = (mantissa & ((1<<(15-exp))-1)) | ((e & ((1<<(exp-7))-1))<<(15-exp))
    result.append(chr(x))
    x = sign | e >> (exp - 7)
    result.append(chr(x))
    if bigendian:
        first = len(result) - size
        last = len(result) - 1
        for i in range(size // 2):
            (result[first + i], result[last - i]) = (
                result[last - i], result[first + i])
Esempio n. 22
0
 def f(n1, n2, m1, m2, ii):
     # n == -30000000000000, m == -20000000000, ii == 42
     n = (r_longlong(n1) << 32) | r_longlong(n2)
     m = (r_longlong(m1) << 32) | r_longlong(m2)
     compare(n & m, -6989, 346562560)
     compare(n | m, -1, 1474836480)
     compare(n ^ m, 6988, 1128273920)
     compare(n << 1, -13970, 693125120)
     compare(r_longlong(5) << ii, 5120, 0)
     compare(n >> 1, -3493, -1974202368)
     compare(n >> 42, -1, -7)
     return 1
Esempio n. 23
0
 def f(n1, n2, m1, m2, ii):
     # n == -30000000000000, m == -20000000000, ii == 42
     n = (r_longlong(n1) << 32) | r_longlong(n2)
     m = (r_longlong(m1) << 32) | r_longlong(m2)
     compare(n & m, -6989, 346562560)
     compare(n | m, -1, 1474836480)
     compare(n ^ m, 6988, 1128273920)
     compare(n << 1, -13970, 693125120)
     compare(r_longlong(5) << ii, 5120, 0)
     compare(n >> 1, -3493, -1974202368)
     compare(n >> 42, -1, -7)
     return 1
Esempio n. 24
0
def expose_value_as_rpython(value):
    if intmask(value) == value:
        return value
    if r_uint(value) == value:
        return r_uint(value)
    try:
        if r_longlong(value) == value:
            return r_longlong(value)
    except OverflowError:
        pass
    if r_ulonglong(value) == value:
        return r_ulonglong(value)
    raise OverflowError("value %d does not fit into any RPython integer type" % (value,))
Esempio n. 25
0
 def test_args_from_int(self):
     BASE = 1 << SHIFT
     MAX = int(BASE-1)
     assert rbigint.fromrarith_int(0).eq(bigint([0], 0))
     assert rbigint.fromrarith_int(17).eq(bigint([17], 1))
     assert rbigint.fromrarith_int(MAX).eq(bigint([MAX], 1))
     assert rbigint.fromrarith_int(r_longlong(BASE)).eq(bigint([0, 1], 1))
     assert rbigint.fromrarith_int(r_longlong(BASE**2)).eq(
         bigint([0, 0, 1], 1))
     assert rbigint.fromrarith_int(-17).eq(bigint([17], -1))
     assert rbigint.fromrarith_int(-MAX).eq(bigint([MAX], -1))
     assert rbigint.fromrarith_int(-MAX-1).eq(bigint([0, 1], -1))
     assert rbigint.fromrarith_int(r_longlong(-(BASE**2))).eq(
         bigint([0, 0, 1], -1))
Esempio n. 26
0
def expose_value_as_rpython(value):
    if intmask(value) == value:
        return value
    if r_uint(value) == value:
        return r_uint(value)
    try:
        if r_longlong(value) == value:
            return r_longlong(value)
    except OverflowError:
        pass
    if r_ulonglong(value) == value:
        return r_ulonglong(value)
    raise OverflowError("value %d does not fit into any RPython integer type"
                        % (value,))
Esempio n. 27
0
def dump_int(buf, x):
    # only use TYPE_INT on 32-bit platforms
    if LONG_BIT > 32:
        dump_longlong(buf, r_longlong(x))
    else:
        buf.append(TYPE_INT)
        w_long(buf, x)
Esempio n. 28
0
    def test_float_constant_conversions(self):
        DIV = r_longlong(10 ** 10)
        def fn():
            return 420000000000.0 / DIV

        res = self.interpret(fn, [])
        assert self.float_eq(res, 42.0)
Esempio n. 29
0
def test_wrap():
    def _is(box1, box2):
        return box1.__class__ == box2.__class__ and box1.value == box2.value

    p = lltype.malloc(lltype.GcStruct("S"))
    po = lltype.cast_opaque_ptr(llmemory.GCREF, p)
    assert _is(wrap(None, 42), BoxInt(42))
    assert _is(wrap(None, 42.5), boxfloat(42.5))
    assert _is(wrap(None, p), BoxPtr(po))
    assert _is(wrap(None, 42, in_const_box=True), ConstInt(42))
    assert _is(wrap(None, 42.5, in_const_box=True), constfloat(42.5))
    assert _is(wrap(None, p, in_const_box=True), ConstPtr(po))
    if longlong.supports_longlong:
        import sys
        from pypy.rlib.rarithmetic import r_longlong, r_ulonglong

        value = r_longlong(-sys.maxint * 17)
        assert _is(wrap(None, value), BoxFloat(value))
        assert _is(wrap(None, value, in_const_box=True), ConstFloat(value))
        value_unsigned = r_ulonglong(-sys.maxint * 17)
        assert _is(wrap(None, value_unsigned), BoxFloat(value))
    sfval = r_singlefloat(42.5)
    ival = longlong.singlefloat2int(sfval)
    assert _is(wrap(None, sfval), BoxInt(ival))
    assert _is(wrap(None, sfval, in_const_box=True), ConstInt(ival))
Esempio n. 30
0
def test_contains_unsupported_variable_type():
    def f(x):
        return x
    graph = support.getgraph(f, [5])
    for sf in [False, True]:
        for sll in [False, True]:
            for ssf in [False, True]:
                assert not contains_unsupported_variable_type(graph, sf,
                                                              sll, ssf)
    #
    graph = support.getgraph(f, [5.5])
    for sf in [False, True]:
        for sll in [False, True]:
            for ssf in [False, True]:
                res = contains_unsupported_variable_type(graph, sf, sll, ssf)
                assert res is not sf
    #
    graph = support.getgraph(f, [r_singlefloat(5.5)])
    for sf in [False, True]:
        for sll in [False, True]:
            for ssf in [False, True]:
                res = contains_unsupported_variable_type(graph, sf, sll, ssf)
                assert res == (not ssf)
    #
    graph = support.getgraph(f, [r_longlong(5)])
    for sf in [False, True]:
        for sll in [False, True]:
            for ssf in [False, True]:
                res = contains_unsupported_variable_type(graph, sf, sll, ssf)
                assert res == (sys.maxint == 2147483647 and not sll)
Esempio n. 31
0
def dump_int(buf, x):
    # only use TYPE_INT on 32-bit platforms
    if LONG_BIT > 32:
        dump_longlong(buf, r_longlong(x))
    else:
        buf.append(TYPE_INT)
        w_long(buf, x)
Esempio n. 32
0
 def f(n1, n2, m1, m2):
     # n == -30000000000000, m == -20000000000
     n = (r_longlong(n1) << 32) | r_longlong(n2)
     m = (r_longlong(m1) << 32) | r_longlong(m2)
     compare(n, -6985, 346562560)
     compare(m, -5, 1474836480)
     if not n: raise WrongResult
     if not r_longlong(m2): raise WrongResult
     if n-n: raise WrongResult
     compare(-n, 6984, -346562560)
     compare(~n, 6984, -346562561)
     compare(n + m, -6990, 1821399040)
     compare(n - m, -6981, -1128273920)
     compare(n * (-3), 20954, -1039687680)
     compare((-4) * m, 18, -1604378624)
     return 1
Esempio n. 33
0
 def f(n1, n2, m1, m2):
     # n == -30000000000000, m == -20000000000
     n = (r_longlong(n1) << 32) | r_longlong(n2)
     m = (r_longlong(m1) << 32) | r_longlong(m2)
     compare(n, -6985, 346562560)
     compare(m, -5, 1474836480)
     if not n: raise WrongResult
     if not r_longlong(m2): raise WrongResult
     if n - n: raise WrongResult
     compare(-n, 6984, -346562560)
     compare(~n, 6984, -346562561)
     compare(n + m, -6990, 1821399040)
     compare(n - m, -6981, -1128273920)
     compare(n * (-3), 20954, -1039687680)
     compare((-4) * m, 18, -1604378624)
     return 1
Esempio n. 34
0
def op_cast_float_to_longlong(f):
    assert type(f) is float
    r = float(0x100000000)
    small = f / r
    high = int(small)
    truncated = int((small - high) * r)
    return r_longlong(high) * 0x100000000 + truncated
Esempio n. 35
0
def op_cast_float_to_longlong(f):
    assert type(f) is float
    r = float(0x100000000)
    small = f / r
    high = int(small)
    truncated = int((small - high) * r)
    return r_longlong(high) * 0x100000000 + truncated
Esempio n. 36
0
    def test_neg_abs_ovf(self):
        for op in (operator.neg, abs):
            def f(x):
                try:
                    return ovfcheck(op(x))
                except OverflowError:
                    return 0
            res = self.interpret(f, [-1])
            assert res == 1
            res = self.interpret(f, [int(-1<<(r_int.BITS-1))])
            assert res == 0

            res = self.interpret(f, [r_longlong(-1)])
            assert res == 1
            res = self.interpret(f, [r_longlong(-1)<<(r_longlong.BITS-1)])
            assert res == 0
Esempio n. 37
0
    def test_float_constant_conversions(self):
        DIV = r_longlong(10 ** 10)
        def fn():
            return 420000000000.0 / DIV

        res = self.interpret(fn, [])
        assert self.float_eq(res, 42.0)
Esempio n. 38
0
def test_contains_unsupported_variable_type():
    def f(x):
        return x

    graph = support.getgraph(f, [5])
    for sf in [False, True]:
        for sll in [False, True]:
            for ssf in [False, True]:
                assert not contains_unsupported_variable_type(
                    graph, sf, sll, ssf)
    #
    graph = support.getgraph(f, [5.5])
    for sf in [False, True]:
        for sll in [False, True]:
            for ssf in [False, True]:
                res = contains_unsupported_variable_type(graph, sf, sll, ssf)
                assert res is not sf
    #
    graph = support.getgraph(f, [r_singlefloat(5.5)])
    for sf in [False, True]:
        for sll in [False, True]:
            for ssf in [False, True]:
                res = contains_unsupported_variable_type(graph, sf, sll, ssf)
                assert res == (not ssf)
    #
    graph = support.getgraph(f, [r_longlong(5)])
    for sf in [False, True]:
        for sll in [False, True]:
            for ssf in [False, True]:
                res = contains_unsupported_variable_type(graph, sf, sll, ssf)
                assert res == (sys.maxint == 2147483647 and not sll)
Esempio n. 39
0
def test_wraplonglongs():
    space = CPyObjSpace()
    w = space.wrap
    w_res = space.add(w(r_longlong(1)), w(r_ulonglong(1)))
    assert space.eq_w(w_res, w(2))
    res = space.int_w(w_res)
    assert res == 2
Esempio n. 40
0
def pow_ovr(space, w_int1, w_int2):
    try:
        return _impl_pow(space, r_longlong(w_int1.intval), w_int2)
    except FailedToImplementArgs:
        from pypy.objspace.std import longobject
        w_a = W_LongObject.fromint(space, w_int1.intval)
        w_b = W_LongObject.fromint(space, w_int2.intval)
        return longobject.pow__Long_Long_None(space, w_a, w_b, space.w_None)
Esempio n. 41
0
def pow_ovr(space, w_int1, w_int2):
    try:
        return _impl_pow(space, r_longlong(w_int1.intval), w_int2)
    except FailedToImplementArgs:
        from pypy.objspace.std import longobject
        w_a = W_LongObject.fromint(space, w_int1.intval)
        w_b = W_LongObject.fromint(space, w_int2.intval)
        return longobject.pow__Long_Long_None(space, w_a, w_b, space.w_None)
Esempio n. 42
0
 def test_array_longlong(self):
     from pypy.rlib.rarithmetic import r_longlong
     A = GcArray(('v', Signed))
     one = r_longlong(1)
     def llf():
         a = malloc(A, one)
         return a[0].v
     s = self.annotate(llf, [])
     assert s.knowntype == int
Esempio n. 43
0
 def test_array_longlong(self):
     from pypy.rlib.rarithmetic import r_longlong
     A = GcArray(('v', Signed))
     one = r_longlong(1)
     def llf():
         a = malloc(A, one)
         return a[0].v
     s = self.annotate(llf, [])
     assert s.knowntype == int
Esempio n. 44
0
def lshift_ovr(space, w_int1, w_int2):
    a = r_longlong(w_int1.intval)
    try:
        return lshift__SmallLong_Int(space, W_SmallLongObject(a), w_int2)
    except FailedToImplementArgs:
        from pypy.objspace.std import longobject
        w_a = W_LongObject.fromint(space, w_int1.intval)
        w_b = W_LongObject.fromint(space, w_int2.intval)
        return longobject.lshift__Long_Long(space, w_a, w_b)
Esempio n. 45
0
 def test_signed_longlong(self):
     space = self.space
     maxint32 = 2147483647 # we cannot really go above maxint on 64 bits
                           # (and we would not test anything, as there long
                           # is the same as long long)
     expected = maxint32+1
     if IS_32_BIT:
         expected = r_longlong(expected)
     self.check(app_types.slonglong, space.wrap(maxint32+1), expected)
Esempio n. 46
0
def lshift_ovr(space, w_int1, w_int2):
    a = r_longlong(w_int1.intval)
    try:
        return lshift__SmallLong_Int(space, W_SmallLongObject(a), w_int2)
    except FailedToImplementArgs:
        from pypy.objspace.std import longobject
        w_a = W_LongObject.fromint(space, w_int1.intval)
        w_b = W_LongObject.fromint(space, w_int2.intval)
        return longobject.lshift__Long_Long(space, w_a, w_b)
Esempio n. 47
0
 def test_signed_longlong(self):
     space = self.space
     maxint32 = 2147483647  # we cannot really go above maxint on 64 bits
     # (and we would not test anything, as there long
     # is the same as long long)
     expected = maxint32 + 1
     if IS_32_BIT:
         expected = r_longlong(expected)
     self.check(app_types.slonglong, space.wrap(maxint32 + 1), expected)
Esempio n. 48
0
def test_assemble_llong_consts():
    if sys.maxint > 2147483647:
        py.test.skip("only for 32-bit platforms")
    from pypy.rlib.rarithmetic import r_longlong, r_ulonglong
    ssarepr = SSARepr("test")
    ssarepr.insns = [
        ('float_return', Constant(r_longlong(-18000000000000000),
                                  lltype.SignedLongLong)),
        ('float_return', Constant(r_ulonglong(9900000000000000000),
                                  lltype.UnsignedLongLong)),
        ]
    assembler = Assembler()
    jitcode = assembler.assemble(ssarepr)
    assert jitcode.code == ("\x00\xFF"
                            "\x00\xFE")
    assert assembler.insns == {'float_return/f': 0}
    assert jitcode.constants_f == [r_longlong(-18000000000000000),
                                   r_longlong(-8546744073709551616)]
Esempio n. 49
0
 def test_struct_fields_longlong(self):
     POINT = lltype.Struct('POINT', ('x', rffi.LONGLONG),
                           ('y', rffi.ULONGLONG))
     y_ofs = 8
     p = lltype.malloc(POINT, flavor='raw')
     p.x = r_longlong(123)
     p.y = r_ulonglong(456)
     addr = rffi.cast(rffi.VOIDP, p)
     assert struct_getfield_longlong(types.slonglong, addr, 0) == 123
     assert struct_getfield_longlong(types.ulonglong, addr, y_ofs) == 456
     #
     v = rffi.cast(lltype.SignedLongLong, r_ulonglong(9223372036854775808))
     struct_setfield_longlong(types.slonglong, addr, 0, v)
     struct_setfield_longlong(types.ulonglong, addr, y_ofs, r_longlong(-1))
     assert p.x == -9223372036854775808
     assert rffi.cast(lltype.UnsignedLongLong, p.y) == 18446744073709551615
     #
     lltype.free(p, flavor='raw')
Esempio n. 50
0
 def test_interp2app_unwrap_spec_c_int(self):
     from pypy.rlib.rarithmetic import r_longlong
     space = self.space
     w = space.wrap
     def g(space, x):
         return space.wrap(x + 6)
     app_g = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace,
                                                'c_int'])
     app_ug = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace,
                                                'c_uint'])
     app_ng = gateway.interp2app(g, unwrap_spec=[gateway.ObjSpace,
                                                'c_nonnegint'])
     assert app_ug is not app_g
     w_app_g = space.wrap(app_g)
     w_app_ug = space.wrap(app_ug)
     w_app_ng = space.wrap(app_ng)
     #
     assert self.space.eq_w(space.call_function(w_app_g, space.wrap(7)),
                            space.wrap(13))
     space.raises_w(space.w_OverflowError,
                    space.call_function, w_app_g,
                    space.wrap(r_longlong(0x80000000)))
     space.raises_w(space.w_OverflowError,
                    space.call_function, w_app_g,
                    space.wrap(r_longlong(-0x80000001)))
     #
     assert self.space.eq_w(space.call_function(w_app_ug, space.wrap(7)),
                            space.wrap(13))
     assert self.space.eq_w(space.call_function(w_app_ug,
                                                space.wrap(0x7FFFFFFF)),
                            space.wrap(r_longlong(0x7FFFFFFF+6)))
     space.raises_w(space.w_ValueError,
                    space.call_function, w_app_ug, space.wrap(-1))
     space.raises_w(space.w_OverflowError,
                    space.call_function, w_app_ug,
                    space.wrap(r_longlong(0x100000000)))
     #
     assert self.space.eq_w(space.call_function(w_app_ng, space.wrap(7)),
                            space.wrap(13))
     space.raises_w(space.w_OverflowError,
                    space.call_function, w_app_ng,
                    space.wrap(r_longlong(0x80000000)))
     space.raises_w(space.w_ValueError,
                    space.call_function, w_app_ng, space.wrap(-1))
Esempio n. 51
0
def test_assemble_llong_consts():
    if sys.maxint > 2147483647:
        py.test.skip("only for 32-bit platforms")
    from pypy.rlib.rarithmetic import r_longlong, r_ulonglong
    ssarepr = SSARepr("test")
    ssarepr.insns = [
        ('float_return',
         Constant(r_longlong(-18000000000000000), lltype.SignedLongLong)),
        ('float_return',
         Constant(r_ulonglong(9900000000000000000), lltype.UnsignedLongLong)),
    ]
    assembler = Assembler()
    jitcode = assembler.assemble(ssarepr)
    assert jitcode.code == ("\x00\xFF" "\x00\xFE")
    assert assembler.insns == {'float_return/f': 0}
    assert jitcode.constants_f == [
        r_longlong(-18000000000000000),
        r_longlong(-8546744073709551616)
    ]
Esempio n. 52
0
 def __init__(self, space, stream, buffering):
     self.space = space
     self.stream = stream
     self.decompressor = W_BZ2Decompressor(space)
     self.readlength = r_longlong(0)
     self.buffer = ""
     self.finished = False
     if buffering < 1024:
         buffering = 1024  # minimum amount of compressed data read at once
     self.buffering = buffering
Esempio n. 53
0
 def __init__(self, space, stream, buffering):
     self.space = space
     self.stream = stream
     self.decompressor = W_BZ2Decompressor(space)
     self.readlength = r_longlong(0)
     self.buffer = ""
     self.finished = False
     if buffering < 1024:
         buffering = 1024   # minimum amount of compressed data read at once
     self.buffering = buffering
Esempio n. 54
0
 def __init__(self):
     self.top = frame.null_state
     self.restart_substate = -1
     self.retval_long = 0
     self.retval_longlong = rarithmetic.r_longlong(0)
     self.retval_float = 0.0
     self.retval_addr = llmemory.NULL
     self.retval_ref = frame.null_saved_ref
     self.exception = None
     self.masterarray = lltype.malloc(frame.FRAME_INFO_ARRAY, 0,
                                      immortal=True)
Esempio n. 55
0
 def entry_point(argv):
     assert str(r4800000000 + r_longlong(len(argv))) == '4800000003'
     fd = os.open(filename, os.O_RDWR | os.O_CREAT, 0644)
     os.lseek(fd, r4800000000, 0)
     newpos = os.lseek(fd, 0, 1)
     if newpos == r4800000000:
         print "OK"
     else:
         print "BAD POS"
     os.close(fd)
     return 0
Esempio n. 56
0
 def f(n):
     a = A()
     a.as_int = n
     a.as_char = chr(n)
     a.as_unichar = unichr(n)
     a.as_double = n + 0.5
     a.as_bool = bool(n)
     a.as_void = None
     a.as_longlong = r_longlong(n)
     a.as_reference = A()
     return a