Example #1
0
    def stress_combination(self, key_can_be_none, value_can_be_none):
        from pypy.rpython.lltypesystem.rstr import string_repr
        from pypy.annotation.dictdef import DictKey, DictValue
        from pypy.annotation import model as annmodel

        print
        print "Testing combination with can_be_None: keys %s, values %s" % (
            key_can_be_none, value_can_be_none)

        class PseudoRTyper:
            cache_dummy_values = {}
        dictrepr = rdict.DictRepr(PseudoRTyper(), string_repr, string_repr,
                       DictKey(None, annmodel.SomeString(key_can_be_none)),
                       DictValue(None, annmodel.SomeString(value_can_be_none)))
        dictrepr.setup()
        print dictrepr.lowleveltype
        for key, value in dictrepr.DICTENTRY._adtmeths.items():
            print '    %s = %s' % (key, value)
        l_dict = rdict.ll_newdict(dictrepr.DICT)
        referencetable = [None] * 400
        referencelength = 0
        values = not_really_random()
        keytable = [string_repr.convert_const("foo%d" % n)
                    for n in range(len(referencetable))]

        def complete_check():
            for n, refvalue in zip(range(len(referencetable)), referencetable):
                try:
                    gotvalue = rdict.ll_dict_getitem(l_dict, keytable[n])
                except KeyError:
                    assert refvalue is None
                else:
                    assert gotvalue == refvalue

        for x in not_really_random():
            n = int(x*100.0)    # 0 <= x < 400
            op = repr(x)[-1]
            if op <= '2' and referencetable[n] is not None:
                rdict.ll_dict_delitem(l_dict, keytable[n])
                referencetable[n] = None
                referencelength -= 1
            elif op <= '6':
                ll_value = string_repr.convert_const(str(values.next()))
                rdict.ll_dict_setitem(l_dict, keytable[n], ll_value)
                if referencetable[n] is None:
                    referencelength += 1
                referencetable[n] = ll_value
            else:
                try:
                    gotvalue = rdict.ll_dict_getitem(l_dict, keytable[n])
                except KeyError:
                    assert referencetable[n] is None
                else:
                    assert gotvalue == referencetable[n]
            if 1.38 <= x <= 1.39:
                complete_check()
                print 'current dict length:', referencelength
            assert l_dict.num_items == referencelength
        complete_check()
Example #2
0
    def stress_combination(self, key_can_be_none, value_can_be_none):
        from pypy.rpython.lltypesystem.rstr import string_repr
        from pypy.annotation.dictdef import DictKey, DictValue
        from pypy.annotation import model as annmodel

        print
        print "Testing combination with can_be_None: keys %s, values %s" % (
            key_can_be_none, value_can_be_none)

        class PseudoRTyper:
            cache_dummy_values = {}
        dictrepr = rdict.DictRepr(PseudoRTyper(), string_repr, string_repr,
                       DictKey(None, annmodel.SomeString(key_can_be_none)),
                       DictValue(None, annmodel.SomeString(value_can_be_none)))
        dictrepr.setup()
        print dictrepr.lowleveltype
        for key, value in dictrepr.DICTENTRY._adtmeths.items():
            print '    %s = %s' % (key, value)
        l_dict = rdict.ll_newdict(dictrepr.DICT)
        referencetable = [None] * 400
        referencelength = 0
        values = not_really_random()
        keytable = [string_repr.convert_const("foo%d" % n)
                    for n in range(len(referencetable))]

        def complete_check():
            for n, refvalue in zip(range(len(referencetable)), referencetable):
                try:
                    gotvalue = rdict.ll_dict_getitem(l_dict, keytable[n])
                except KeyError:
                    assert refvalue is None
                else:
                    assert gotvalue == refvalue

        for x in not_really_random():
            n = int(x*100.0)    # 0 <= x < 400
            op = repr(x)[-1]
            if op <= '2' and referencetable[n] is not None:
                rdict.ll_dict_delitem(l_dict, keytable[n])
                referencetable[n] = None
                referencelength -= 1
            elif op <= '6':
                ll_value = string_repr.convert_const(str(values.next()))
                rdict.ll_dict_setitem(l_dict, keytable[n], ll_value)
                if referencetable[n] is None:
                    referencelength += 1
                referencetable[n] = ll_value
            else:
                try:
                    gotvalue = rdict.ll_dict_getitem(l_dict, keytable[n])
                except KeyError:
                    assert referencetable[n] is None
                else:
                    assert gotvalue == referencetable[n]
            if 1.38 <= x <= 1.39:
                complete_check()
                print 'current dict length:', referencelength
            assert l_dict.num_items == referencelength
        complete_check()
Example #3
0
 def handle_unreachable(self, op):
     from pypy.rpython.lltypesystem.rstr import string_repr
     msg = 'unreachable: %s' % (op,)
     ll_msg = string_repr.convert_const(msg)
     c_msg = Constant(ll_msg, lltype.typeOf(ll_msg))
     newresult = self.make_rt_result(op.result)
     return [SpaceOperation('debug_fatalerror', [c_msg], newresult)]
Example #4
0
 def handle_unreachable(self, op):
     from pypy.rpython.lltypesystem.rstr import string_repr
     msg = 'unreachable: %s' % (op,)
     ll_msg = string_repr.convert_const(msg)
     c_msg = Constant(ll_msg, lltype.typeOf(ll_msg))
     newresult = self.make_rt_result(op.result)
     return [SpaceOperation('debug_fatalerror', [c_msg], newresult)]
Example #5
0
File: rstr.py Project: alkorzt/pypy
                        ))


# TODO: make the public interface of the rstr module cleaner
ll_strconcat = LLHelpers.ll_strconcat
ll_join = LLHelpers.ll_join
ll_str2unicode = LLHelpers.ll_str2unicode
do_stringformat = LLHelpers.do_stringformat

string_repr = StringRepr()
char_repr = CharRepr()
unichar_repr = UniCharRepr()
char_repr.ll = LLHelpers
unichar_repr.ll = LLHelpers
unicode_repr = UnicodeRepr()
emptystr = string_repr.convert_const("")
emptyunicode = unicode_repr.convert_const(u'')

StringRepr.repr = string_repr
UnicodeRepr.repr = unicode_repr
UniCharRepr.repr = unicode_repr
UniCharRepr.char_repr = unichar_repr
UnicodeRepr.char_repr = unichar_repr
CharRepr.char_repr = char_repr
StringRepr.char_repr = char_repr

class BaseStringIteratorRepr(AbstractStringIteratorRepr):

    def __init__(self):
        self.ll_striter = ll_striter
        self.ll_strnext = ll_strnext
Example #6
0

TEMP = GcArray(Ptr(STR))

# TODO: make the public interface of the rstr module cleaner
ll_strconcat = LLHelpers.ll_strconcat
ll_join = LLHelpers.ll_join
do_stringformat = LLHelpers.do_stringformat

string_repr = StringRepr()
char_repr = CharRepr()
unichar_repr = UniCharRepr()
char_repr.ll = LLHelpers
unichar_repr.ll = LLHelpers
unicode_repr = UnicodeRepr()
emptystr = string_repr.convert_const("")
emptyunicode = unicode_repr.convert_const(u'')

StringRepr.repr = string_repr
UnicodeRepr.repr = unicode_repr
UniCharRepr.repr = unicode_repr
UniCharRepr.char_repr = unichar_repr
UnicodeRepr.char_repr = unichar_repr
CharRepr.char_repr = char_repr
StringRepr.char_repr = char_repr


class BaseStringIteratorRepr(AbstractStringIteratorRepr):
    def __init__(self):
        self.ll_striter = ll_striter
        self.ll_strnext = ll_strnext
Example #7
0
 def handle_unreachable(self, v_result):
     from pypy.rpython.lltypesystem.rstr import string_repr
     msg = "unreachable operation (from malloc.py)"
     ll_msg = string_repr.convert_const(msg)
     c_msg = Constant(ll_msg, lltype.typeOf(ll_msg))
     return SpaceOperation("debug_fatalerror", [c_msg], v_result)
Example #8
0
 def str2subarray(string):
     llstring = string_repr.convert_const(string)
     keepalive.append(llstring)
     return lltype.direct_arrayitems(llstring.chars)
Example #9
0
 def handle_unreachable(self, v_result):
     from pypy.rpython.lltypesystem.rstr import string_repr
     msg = "unreachable operation (from malloc.py)"
     ll_msg = string_repr.convert_const(msg)
     c_msg = Constant(ll_msg, lltype.typeOf(ll_msg))
     return SpaceOperation("debug_fatalerror", [c_msg], v_result)