예제 #1
0
파일: rstr.py 프로젝트: sota/pypy
 def ll_join_strs(length_dummy, lst):
     if typeOf(lst).ITEM == ootype.String:
         buf = ootype.new(ootype.StringBuilder)
     else:
         buf = ootype.new(ootype.UnicodeBuilder)
     length = lst.ll_length()
     #buf.ll_allocate(length)
     i = 0
     while i < length:
         buf.ll_append(lst.ll_getitem_fast(i))
         i += 1
     return buf.ll_build()
예제 #2
0
 def ll_join_strs(length_dummy, lst):
     if typeOf(lst).ITEM == ootype.String:
         buf = ootype.new(ootype.StringBuilder)
     else:
         buf = ootype.new(ootype.UnicodeBuilder)
     length = lst.ll_length()
     #buf.ll_allocate(length)
     i = 0
     while i < length:
         buf.ll_append(lst.ll_getitem_fast(i))
         i += 1
     return buf.ll_build()
예제 #3
0
 def ll_char_mul(ch, times):
     if times < 0:
         times = 0
     if typeOf(ch) == Char:
         buf = ootype.new(ootype.StringBuilder)
     else:
         buf = ootype.new(ootype.UnicodeBuilder)
     buf.ll_allocate(times)
     i = 0
     while i < times:
         buf.ll_append_char(ch)
         i += 1
     return buf.ll_build()
예제 #4
0
파일: rstr.py 프로젝트: sota/pypy
 def ll_char_mul(ch, times):
     if times < 0:
         times = 0
     if typeOf(ch) == Char:
         buf = ootype.new(ootype.StringBuilder)
     else:
         buf = ootype.new(ootype.UnicodeBuilder)
     buf.ll_allocate(times)
     i = 0
     while i<times:
         buf.ll_append_char(ch)
         i+= 1
     return buf.ll_build()
예제 #5
0
 def ll_join_chars(length_dummy, lst, RES):
     if RES is ootype.String:
         target = Char
         buf = ootype.new(ootype.StringBuilder)
     else:
         target = UniChar
         buf = ootype.new(ootype.UnicodeBuilder)
     length = lst.ll_length()
     buf.ll_allocate(length)
     i = 0
     while i < length:
         buf.ll_append_char(cast_primitive(target, lst.ll_getitem_fast(i)))
         i += 1
     return buf.ll_build()
예제 #6
0
파일: rstr.py 프로젝트: sota/pypy
 def ll_join_chars(length_dummy, lst, RES):
     if RES is ootype.String:
         target = Char
         buf = ootype.new(ootype.StringBuilder)
     else:
         target = UniChar
         buf = ootype.new(ootype.UnicodeBuilder)
     length = lst.ll_length()
     buf.ll_allocate(length)
     i = 0
     while i < length:
         buf.ll_append_char(cast_primitive(target, lst.ll_getitem_fast(i)))
         i += 1
     return buf.ll_build()
예제 #7
0
파일: constant.py 프로젝트: sota/pypy-old
 def test_unwrap_object(self):
     A = ootype.Instance("A", ootype.ROOT, {})
     a1 = ootype.new(A)
     a2 = ootype.new(A)
     obj1 = ootype.cast_to_object(a1)
     obj2 = ootype.cast_to_object(a2)
     def fn(flag):
         if flag:
             obj = obj1
         else:
             obj = obj2
         a3 = ootype.cast_from_object(A, obj)
         return a3 is a1
     res = self.interpret(fn, [True], backendopt=False)
     assert res is True
예제 #8
0
def test_invalid_cache():
    DT = Dict(Signed, Signed)
    d = new(DT)
    py.test.raises(AssertionError, d.ll_get, 0)
    d.ll_set(42, 1)
    d.ll_contains(43)
    py.test.raises(AssertionError, d.ll_get, 42)
예제 #9
0
def ll_rangeiter(ITER, rng):
    iter = new(ITER)
    iter.next = rng.start
    iter.stop = rng.stop
    if ITER is RANGESTITER:
        iter.step = rng.step
    return iter
예제 #10
0
파일: rrange.py 프로젝트: sota/pypy
def ll_rangeiter(ITER, rng):
    iter = new(ITER)
    iter.next = rng.start
    iter.stop = rng.stop
    if ITER is RANGESTITER:
        iter.step = rng.step
    return iter
예제 #11
0
def ll_known_maxlength2list(RESLIST, l):
    res = ootype.new(RESLIST)
    length = l.length
    res._ll_resize_ge(length)
    for i in range(length):
        item = l.items.ll_getitem_fast(i)
        res.ll_setitem_fast(i, item)
    return res
예제 #12
0
파일: rrange.py 프로젝트: sota/pypy
def ll_newrangest(start, stop, step):
    if step == 0:
        raise ValueError
    l = new(RANGEST)
    l.start = start
    l.stop = stop
    l.step = step
    return l
예제 #13
0
 def ll_decode_latin1(self, value):
     sb = ootype.new(ootype.UnicodeBuilder)
     length = value.ll_strlen()
     sb.ll_allocate(length)
     for i in range(length):
         c = value.ll_stritem_nonneg(i)
         sb.ll_append_char(cast_primitive(UniChar, c))
     return sb.ll_build()
예제 #14
0
파일: rstr.py 프로젝트: sota/pypy
 def ll_decode_latin1(self, value):
     sb = ootype.new(ootype.UnicodeBuilder)
     length = value.ll_strlen()
     sb.ll_allocate(length)
     for i in range(length):
         c = value.ll_stritem_nonneg(i)
         sb.ll_append_char(cast_primitive(UniChar, c))
     return sb.ll_build()
예제 #15
0
def ll_newrangest(start, stop, step):
    if step == 0:
        raise ValueError
    l = new(RANGEST)
    l.start = start
    l.stop = stop
    l.step = step
    return l
예제 #16
0
파일: rdict.py 프로젝트: sota/pypy
def ll_popitem(ELEM, d):
    it = d.ll_get_items_iterator()
    if it.ll_go_next():
        res = ootype.new(ELEM)
        key = res.item0 = it.ll_current_key()
        res.item1 = it.ll_current_value()
        d.ll_remove(key)
        return res
    raise KeyError
예제 #17
0
파일: rdict.py 프로젝트: sota/pypy-old
def ll_popitem(ELEM, d):
    it = d.ll_get_items_iterator()
    if it.ll_go_next():
        res = ootype.new(ELEM)
        key = res.item0 = it.ll_current_key()
        res.item1 = it.ll_current_value()
        d.ll_remove(key)
        return res
    raise KeyError
예제 #18
0
파일: rstr.py 프로젝트: sota/pypy
 def ll_encode_latin1(self, value):
     sb = ootype.new(ootype.StringBuilder)
     length = value.ll_strlen()
     sb.ll_allocate(length)
     for i in range(length):
         c = value.ll_stritem_nonneg(i)
         if ord(c) > 255:
             raise UnicodeEncodeError("%d > 255, not latin-1" % ord(c))
         sb.ll_append_char(cast_primitive(Char, c))
     return sb.ll_build()
예제 #19
0
 def fn():
     a = ootype.new(A)
     ahash = ootype.identityhash(a)
     obj = ootype.cast_to_object(a)
     native = cast_to_native_object(obj)
     name = native.GetType().get_Name()
     obj2 = cast_from_native_object(native)
     a2 = ootype.cast_from_object(A, obj2)
     a2hash = ootype.identityhash(a2)
     return name, ahash == a2hash
예제 #20
0
 def ll_encode_latin1(self, value):
     sb = ootype.new(ootype.StringBuilder)
     length = value.ll_strlen()
     sb.ll_allocate(length)
     for i in range(length):
         c = value.ll_stritem_nonneg(i)
         if ord(c) > 255:
             raise UnicodeEncodeError("%d > 255, not latin-1" % ord(c))
         sb.ll_append_char(cast_primitive(Char, c))
     return sb.ll_build()
예제 #21
0
파일: test_dotnet.py 프로젝트: sota/pypy
 def fn():
     a = ootype.new(A)
     ahash = ootype.identityhash(a)
     obj = ootype.cast_to_object(a)
     native = cast_to_native_object(obj)
     name = native.GetType().get_Name()
     obj2 = cast_from_native_object(native)
     a2 = ootype.cast_from_object(A, obj2)
     a2hash = ootype.identityhash(a2)
     return name, ahash == a2hash
예제 #22
0
def test_iteritems():
    DT = Dict(Signed, Float)
    d = new(DT)
    d.ll_set(42, 43.0)
    d.ll_set(52, 53.0)
    it = d.ll_get_items_iterator()
    items = []
    while it.ll_go_next():
        items.append((it.ll_current_key(), it.ll_current_value()))
    items.sort()
    assert items == [(42, 43.0), (52, 53.0)]
예제 #23
0
    def get_meta_instance(self, cast_to_root_meta=True):
        if self.lowleveltype == ootype.Class:
            raise TyperError("no meta-instance for class %r" %
                             (self.classdef, ))
        if self.meta_instance is None:
            self.meta_instance = ootype.new(self.lowleveltype)
            self.setup_meta_instance(self.meta_instance, self)

        meta_instance = self.meta_instance
        if cast_to_root_meta:
            meta_instance = ootype.ooupcast(META, meta_instance)
        return meta_instance
예제 #24
0
파일: rclass.py 프로젝트: sota/pypy
 def get_meta_instance(self, cast_to_root_meta=True):
     if self.lowleveltype == ootype.Class:
         raise TyperError("no meta-instance for class %r" % 
                          (self.classdef,))
     if self.meta_instance is None:
         self.meta_instance = ootype.new(self.lowleveltype) 
         self.setup_meta_instance(self.meta_instance, self)
     
     meta_instance = self.meta_instance
     if cast_to_root_meta:
         meta_instance = ootype.ooupcast(META, meta_instance)
     return meta_instance
예제 #25
0
파일: rstr.py 프로젝트: sota/pypy
 def ll_str_mul(s, times):
     if times < 0:
         times = 0
     try:
         size = ovfcheck(s.ll_strlen() * times)
     except OverflowError:
         raise MemoryError
     buf = ootype.new(typeOf(s).builder)
     buf.ll_allocate(size)
     for i in xrange(times):
         buf.ll_append(s)
     return buf.ll_build()
예제 #26
0
 def ll_str_mul(s, times):
     if times < 0:
         times = 0
     try:
         size = ovfcheck(s.ll_strlen() * times)
     except OverflowError:
         raise MemoryError
     buf = ootype.new(typeOf(s).builder)
     buf.ll_allocate(size)
     for i in xrange(times):
         buf.ll_append(s)
     return buf.ll_build()
예제 #27
0
 def ll_str(self, value):
     if not value:
         return self.ll.ll_constant('None')
     sb = ootype.new(ootype.StringBuilder)
     lgt = value.ll_strlen()
     sb.ll_allocate(lgt)
     for i in range(lgt):
         c = value.ll_stritem_nonneg(i)
         if ord(c) > 127:
             raise UnicodeEncodeError("%d > 127, not ascii" % ord(c))
         sb.ll_append_char(cast_primitive(Char, c))
     return sb.ll_build()
예제 #28
0
파일: rstr.py 프로젝트: sota/pypy
 def ll_str(self, value):
     if not value:
         return self.ll.ll_constant('None')
     sb = ootype.new(ootype.StringBuilder)
     lgt = value.ll_strlen()
     sb.ll_allocate(lgt)
     for i in range(lgt):
         c = value.ll_stritem_nonneg(i)
         if ord(c) > 127:
             raise UnicodeEncodeError("%d > 127, not ascii" % ord(c))
         sb.ll_append_char(cast_primitive(Char, c))
     return sb.ll_build()
예제 #29
0
파일: ll_str.py 프로젝트: sota/pypy-old
def ll_int2oct(i, addPrefix):
    if not addPrefix or i==0:
        return oostring(i, 8)

    buf = new(StringBuilder)
    if i<0:
        if i == SPECIAL_VALUE:
            return SPECIAL_VALUE_OCT
        i = -i
        buf.ll_append_char('-')

    buf.ll_append_char('0')
    buf.ll_append(oostring(i, 8))
    return buf.ll_build()
예제 #30
0
파일: rdict.py 프로젝트: sota/pypy
    def ll_dictnext(RETURNTYPE, iter):
        # note that RETURNTYPE is None for keys and values
        it = iter.iterator
        if not it.ll_go_next():
            raise StopIteration

        if kind == 'keys':
            return it.ll_current_key()
        elif kind == 'values':
            return it.ll_current_value()
        elif kind == 'items':
            res = ootype.new(RETURNTYPE)
            res.item0 = it.ll_current_key()
            res.item1 = it.ll_current_value()
            return res
예제 #31
0
파일: ll_str.py 프로젝트: sota/pypy-old
def ll_int2hex(i, addPrefix):
    if not addPrefix:
        return oostring(i, 16)

    buf = new(StringBuilder)
    if i<0:
        if i == SPECIAL_VALUE:
            return SPECIAL_VALUE_HEX
        i = -i
        buf.ll_append_char('-')

    buf.ll_append_char('0')
    buf.ll_append_char('x')
    buf.ll_append(oostring(i, 16))
    return buf.ll_build()
예제 #32
0
파일: rdict.py 프로젝트: sota/pypy-old
    def ll_dictnext(RETURNTYPE, iter):
        # note that RETURNTYPE is None for keys and values
        it = iter.iterator
        if not it.ll_go_next():
            raise StopIteration

        if kind == 'keys':
            return it.ll_current_key()
        elif kind == 'values':
            return it.ll_current_value()
        elif kind == 'items':
            res = ootype.new(RETURNTYPE)
            res.item0 = it.ll_current_key()
            res.item1 = it.ll_current_value()
            return res
예제 #33
0
파일: rdict.py 프로젝트: sota/pypy-old
 def ll_dict_kvi(LIST, d):
     length = d.ll_length()
     result = LIST.ll_newlist(length)
     it = d.ll_get_items_iterator()
     i = 0
     while it.ll_go_next():
         if kind == 'keys':
             result.ll_setitem_fast(i, it.ll_current_key())
         elif kind == 'values':
             result.ll_setitem_fast(i, it.ll_current_value())
         elif kind == 'items':
             r = ootype.new(LIST.ITEM)
             r.item0 = it.ll_current_key()  # TODO: do we need casting?
             r.item1 = it.ll_current_value()
             result.ll_setitem_fast(i, r)
         i += 1
     assert i == length
     return result
예제 #34
0
파일: rdict.py 프로젝트: sota/pypy
 def ll_dict_kvi(LIST, d):
     length = d.ll_length()
     result = LIST.ll_newlist(length)
     it = d.ll_get_items_iterator()
     i = 0
     while it.ll_go_next():
         if kind == 'keys':
             result.ll_setitem_fast(i, it.ll_current_key())
         elif kind == 'values':
             result.ll_setitem_fast(i, it.ll_current_value())
         elif kind == 'items':
             r = ootype.new(LIST.ITEM)
             r.item0 = it.ll_current_key()   # TODO: do we need casting?
             r.item1 = it.ll_current_value()
             result.ll_setitem_fast(i, r)
         i += 1
     assert i == length
     return result
예제 #35
0
    def ll_join(s, length_dummy, lst):
        length = lst.ll_length()
        buf = ootype.new(typeOf(s).builder)

        # TODO: check if it's worth of preallocating the buffer with
        # the exact length
        ##        itemslen = 0
        ##        i = 0
        ##        while i < length:
        ##            itemslen += lst.ll_getitem_fast(i).ll_strlen()
        ##            i += 1
        ##        resultlen = itemslen + s.ll_strlen()*(length-1)
        ##        buf.ll_allocate(resultlen)

        i = 0
        while i < length - 1:
            item = lst.ll_getitem_fast(i)
            buf.ll_append(item)
            buf.ll_append(s)
            i += 1
        if length > 0:
            lastitem = lst.ll_getitem_fast(i)
            buf.ll_append(lastitem)
        return buf.ll_build()
예제 #36
0
파일: rstr.py 프로젝트: sota/pypy
    def ll_join(s, length_dummy, lst):
        length = lst.ll_length()
        buf = ootype.new(typeOf(s).builder)

        # TODO: check if it's worth of preallocating the buffer with
        # the exact length
##        itemslen = 0
##        i = 0
##        while i < length:
##            itemslen += lst.ll_getitem_fast(i).ll_strlen()
##            i += 1
##        resultlen = itemslen + s.ll_strlen()*(length-1)
##        buf.ll_allocate(resultlen)

        i = 0
        while i < length-1:
            item = lst.ll_getitem_fast(i)
            buf.ll_append(item)
            buf.ll_append(s)
            i += 1
        if length > 0:
            lastitem = lst.ll_getitem_fast(i)
            buf.ll_append(lastitem)
        return buf.ll_build()
예제 #37
0
파일: rlist.py 프로젝트: sota/pypy
def ll_listiter(ITER, lst):
    iter = ootype.new(ITER)
    iter.iterable = lst
    iter.index = 0
    return iter
예제 #38
0
파일: test_oortype.py 프로젝트: sota/pypy
 def fn(x, y):
     a = ootype.new(A)
     meth = a.m
     args = (x, y)
     return meth(*args)
예제 #39
0
파일: rtuple.py 프로젝트: sota/pypy
def ll_tupleiter(ITERINST, tuple):
    iter = ootype.new(ITERINST)
    iter.iterable = tuple
    return iter
예제 #40
0
파일: rstr.py 프로젝트: sota/pypy
 def ll_build_start(parts_count):
     return ootype.new(ootype.StringBuilder)
예제 #41
0
파일: rstr.py 프로젝트: sota/pypy
def ll_unicodeiter(string):
    iter = ootype.new(unicode_repr.string_iterator_repr.lowleveltype)
    iter.string = string
    iter.index = 0
    return iter
예제 #42
0
파일: rlist.py 프로젝트: sota/pypy
def ll_newlist_maxlength(LIST, ARRAY, length):
    lst = ootype.new(LIST)
    lst.items = ootype.oonewarray(ARRAY, length)
    lst.length = 0
    return lst
예제 #43
0
파일: rlist.py 프로젝트: sota/pypy
def ll_newlist(LIST, length):
    lst = ootype.new(LIST)
    lst._ll_resize(length)
    return lst
예제 #44
0
 def create_instance(self):
     return ootype.new(self.object_type)
예제 #45
0
 def fn3(x):
     return new(C).bar(x)
예제 #46
0
 def f():
     buf = ootype.new(ootype.StringBuilder)
     buf.ll_append(myconst)
     return buf.ll_build()
예제 #47
0
def test_string_builder():
    b = ootype.new(ootype.StringBuilder)
    b.ll_append_char('a')
    b.ll_append(ootype.make_string('bcd'))
    res = b.ll_build()
    assert res._str == 'abcd'
예제 #48
0
파일: rclass.py 프로젝트: sota/pypy
 def create_instance(self):
     return ootype.new(self.object_type)
예제 #49
0
 def fn(x, y):
     a = ootype.new(A)
     meth = a.m
     args = (x, y)
     return meth(*args)
예제 #50
0
 def fn1():
     return new(C).foo('a')
예제 #51
0
파일: rrange.py 프로젝트: sota/pypy
def ll_newrange(_RANGE, start, stop):
    l = new(RANGE)
    l.start = start
    l.stop = stop
    return l
예제 #52
0
 def fn2():
     return new(C).foo('aa')
예제 #53
0
 def create():
     if isinstance(TYPE, ootype.OOType):
         return boxresult(TYPE, ootype.new(TYPE))
     return None
예제 #54
0
 def fn(flag):
     a = ootype.new(A)
     a.xx = 42
     b_obj = box(a)
     a2 = unbox(b_obj, A)
     return a2.xx