Esempio n. 1
0
def test_Numbering_create():
    l = [rffi.r_short(1), rffi.r_short(2)]
    numb = Numbering(None, l)
    assert not numb.prev
    assert list(numb.nums) == l

    l1 = [rffi.r_short(3)]
    numb1 = Numbering(numb, l1)
    assert numb1.prev == numb
    assert list(numb1.nums) == l1
Esempio n. 2
0
def test_tag():
    assert tag(3, 1) == rffi.r_short(3 << 2 | 1)
    assert tag(-3, 2) == rffi.r_short(-3 << 2 | 2)
    assert tag((1 << 13) - 1, 3) == rffi.r_short(((1 << 15) - 1) | 3)
    assert tag(-1 << 13, 3) == rffi.r_short((-1 << 15) | 3)
    py.test.raises(ValueError, tag, 3, 5)
    py.test.raises(ValueError, tag, 1 << 13, 0)
    py.test.raises(ValueError, tag, (1 << 13) + 1, 0)
    py.test.raises(ValueError, tag, (-1 << 13) - 1, 0)
    py.test.raises(ValueError, tag, (-1 << 13) - 5, 0)
Esempio n. 3
0
def test_tag():
    assert tag(3, 1) == rffi.r_short(3<<2|1)
    assert tag(-3, 2) == rffi.r_short(-3<<2|2)
    assert tag((1<<13)-1, 3) == rffi.r_short(((1<<15)-1)|3)
    assert tag(-1<<13, 3) == rffi.r_short((-1<<15)|3)
    py.test.raises(ValueError, tag, 3, 5)
    py.test.raises(ValueError, tag, 1<<13, 0)
    py.test.raises(ValueError, tag, (1<<13)+1, 0)
    py.test.raises(ValueError, tag, (-1<<13)-1, 0)
    py.test.raises(ValueError, tag, (-1<<13)-5, 0)
Esempio n. 4
0
def tag(value, tagbits):
    if tagbits >> 2:
        raise ValueError
    sx = value >> 13
    if sx != 0 and sx != -1:
        raise ValueError
    return rffi.r_short(value<<2|tagbits)
Esempio n. 5
0
 def test_cast_primitive(self):
     from pypy.rpython.annlowlevel import LowLevelAnnotatorPolicy
     def llf(u):
         return lltype.cast_primitive(lltype.Signed, u)
     res = self.interpret(llf, [r_uint(-1)], policy=LowLevelAnnotatorPolicy())
     assert res == -1
     res = self.interpret(llf, ['x'], policy=LowLevelAnnotatorPolicy())
     assert res == ord('x')
     def llf(v):
         return lltype.cast_primitive(lltype.Unsigned, v)
     res = self.interpret(llf, [-1], policy=LowLevelAnnotatorPolicy())
     assert res == r_uint(-1)
     res = self.interpret(llf, [u'x'], policy=LowLevelAnnotatorPolicy())
     assert res == ord(u'x')
     res = self.interpret(llf, [1.0], policy=LowLevelAnnotatorPolicy())
     assert res == r_uint(1)
     def llf(v):
         return lltype.cast_primitive(lltype.Char, v)
     res = self.interpret(llf, [ord('x')], policy=LowLevelAnnotatorPolicy())
     assert res == 'x'
     def llf(v):
         return lltype.cast_primitive(lltype.UniChar, v)
     res = self.interpret(llf, [ord('x')], policy=LowLevelAnnotatorPolicy())
     assert res == u'x'
     def llf(v):
         return lltype.cast_primitive(rffi.SHORT, v)
     res = self.interpret(llf, [123], policy=LowLevelAnnotatorPolicy())
     assert res == 123
     def llf(v):
         return lltype.cast_primitive(lltype.Signed, v)
     res = self.interpret(llf, [rffi.r_short(123)], policy=LowLevelAnnotatorPolicy())
     assert res == 123
Esempio n. 6
0
def tag(value, tagbits):
    if tagbits >> 2:
        raise ValueError
    sx = value >> 13
    if sx != 0 and sx != -1:
        raise ValueError
    return rffi.r_short(value<<2|tagbits)
Esempio n. 7
0
    def test_cast_primitive(self):
        from pypy.rpython.annlowlevel import LowLevelAnnotatorPolicy

        def llf(u):
            return lltype.cast_primitive(lltype.Signed, u)

        res = self.interpret(llf, [r_uint(-1)],
                             policy=LowLevelAnnotatorPolicy())
        assert res == -1
        res = self.interpret(llf, ['x'], policy=LowLevelAnnotatorPolicy())
        assert res == ord('x')

        def llf(v):
            return lltype.cast_primitive(lltype.Unsigned, v)

        res = self.interpret(llf, [-1], policy=LowLevelAnnotatorPolicy())
        assert res == r_uint(-1)
        res = self.interpret(llf, [u'x'], policy=LowLevelAnnotatorPolicy())
        assert res == ord(u'x')
        res = self.interpret(llf, [1.0], policy=LowLevelAnnotatorPolicy())
        assert res == r_uint(1)

        def llf(v):
            return lltype.cast_primitive(lltype.Char, v)

        res = self.interpret(llf, [ord('x')], policy=LowLevelAnnotatorPolicy())
        assert res == 'x'

        def llf(v):
            return lltype.cast_primitive(lltype.UniChar, v)

        res = self.interpret(llf, [ord('x')], policy=LowLevelAnnotatorPolicy())
        assert res == u'x'

        def llf(v):
            return lltype.cast_primitive(rffi.SHORT, v)

        res = self.interpret(llf, [123], policy=LowLevelAnnotatorPolicy())
        assert res == 123

        def llf(v):
            return lltype.cast_primitive(lltype.Signed, v)

        res = self.interpret(llf, [rffi.r_short(123)],
                             policy=LowLevelAnnotatorPolicy())
        assert res == 123
Esempio n. 8
0
 def f(i):
     l = [r_short(0)] * 10
     l[i + 1] = r_short(3)
     return rarithmetic.widen(l[i])
Esempio n. 9
0
 def f(i):
     l = [r_short(0)] * 10
     l[i + 1] = r_short(3)
     return rarithmetic.widen(l[i])