Пример #1
0
    def define_interior_ptrs(cls):
        from rpython.rtyper.lltypesystem.lltype import Struct, GcStruct, GcArray
        from rpython.rtyper.lltypesystem.lltype import Array, Signed, malloc

        S1 = Struct("S1", ('x', Signed))
        T1 = GcStruct("T1", ('s', S1))

        def f1():
            t = malloc(T1)
            t.s.x = 1
            return t.s.x

        S2 = Struct("S2", ('x', Signed))
        T2 = GcArray(S2)

        def f2():
            t = malloc(T2, 1)
            t[0].x = 1
            return t[0].x

        S3 = Struct("S3", ('x', Signed))
        T3 = GcStruct("T3", ('items', Array(S3)))

        def f3():
            t = malloc(T3, 1)
            t.items[0].x = 1
            return t.items[0].x

        S4 = Struct("S4", ('x', Signed))
        T4 = Struct("T4", ('s', S4))
        U4 = GcArray(T4)

        def f4():
            u = malloc(U4, 1)
            u[0].s.x = 1
            return u[0].s.x

        S5 = Struct("S5", ('x', Signed))
        T5 = GcStruct("T5", ('items', Array(S5)))

        def f5():
            t = malloc(T5, 1)
            return len(t.items)

        T6 = GcStruct("T6", ('s', Array(Signed)))

        def f6():
            t = malloc(T6, 1)
            t.s[0] = 1
            return t.s[0]

        def func():
            return (f1() * 100000 + f2() * 10000 + f3() * 1000 + f4() * 100 +
                    f5() * 10 + f6())

        assert func() == 111111
        return func
Пример #2
0
 def get_itemarray_lowleveltype(self):
     ITEM = self.item_repr.lowleveltype
     ITEMARRAY = GcArray(ITEM,
                         adtmeths = ADTIFixedList({
                              "ll_newlist": ll_fixed_newlist,
                              "ll_newemptylist": ll_fixed_newemptylist,
                              "ll_length": ll_fixed_length,
                              "ll_items": ll_fixed_items,
                              "ITEM": ITEM,
                              "ll_getitem_fast": ll_fixed_getitem_fast,
                              "ll_setitem_fast": ll_fixed_setitem_fast,
                         }))
     return ITEMARRAY
Пример #3
0
        dst = lst.ll_items()
        SRC = typeOf(src).TO  # STR or UNICODE
        DST = typeOf(dst).TO  # GcArray
        assert DST.OF is SRC.chars.OF
        # from here, no GC operations can happen
        asrc = llmemory.cast_ptr_to_adr(src) + (llmemory.offsetof(
            SRC, 'chars') + llmemory.itemoffsetof(SRC.chars, 0))
        adst = llmemory.cast_ptr_to_adr(dst) + llmemory.itemoffsetof(DST, 0)
        llmemory.raw_memcopy(asrc, adst, llmemory.sizeof(DST.OF) * length)
        # end of "no GC" section
        keepalive_until_here(src)
        keepalive_until_here(dst)
        return lst


TEMP = GcArray(Ptr(STR))
TEMP_UNICODE = GcArray(Ptr(UNICODE))

# ____________________________________________________________

STR.become(
    GcStruct(
        'rpy_string', ('hash', Signed),
        ('chars',
         Array(Char, hints={
             'immutable': True,
             'extra_item_after_alloc': 1
         })),
        adtmeths={
            'malloc': staticAdtMethod(mallocstr),
            'empty': staticAdtMethod(emptystrfun),
Пример #4
0
from rpython.rtyper.lltypesystem.lltype import GcArray, Array, Char, malloc
from rpython.rlib.rarithmetic import r_uint, r_longlong, r_ulonglong
from rpython.rlib import jit

CHAR_ARRAY = GcArray(Char)


def ll_unsigned(i):
    if isinstance(i, r_longlong) or isinstance(i, r_ulonglong):
        return r_ulonglong(i)
    else:
        return r_uint(i)


@jit.elidable
def ll_int2dec(val):
    from rpython.rtyper.lltypesystem.rstr import mallocstr

    sign = int(val < 0)
    if sign:
        val = ll_unsigned(-val)
    else:
        val = ll_unsigned(val)
    len = 0
    i = val
    while i:
        len += 1
        i //= 10

    total_len = sign + len + int(val == 0)
    result = mallocstr(total_len)