from pypy.rpython.lltypesystem.rstr import string_repr vchunk = inputconst(string_repr, thing) i = inputconst(Signed, i) hop.genop('setarrayitem', [vtemp, i, vchunk]) hop.exception_cannot_occur() # to ignore the ZeroDivisionError of '%' return hop.gendirectcall(cls.ll_join_strs, size, vtemp) do_stringformat = classmethod(do_stringformat) TEMP = GcArray(Ptr(STR)) # ____________________________________________________________ STR.become(GcStruct('rpy_string', ('hash', Signed), ('chars', Array(Char, hints={'immutable': True})), adtmeths={'malloc' : staticAdtMethod(mallocstr), 'empty' : staticAdtMethod(emptystrfun), 'copy_contents' : staticAdtMethod(copy_string_contents), 'gethash': LLHelpers.ll_strhash})) UNICODE.become(GcStruct('rpy_unicode', ('hash', Signed), ('chars', Array(UniChar, hints={'immutable': True})), adtmeths={'malloc' : staticAdtMethod(mallocunicode), 'empty' : staticAdtMethod(emptyunicodefun), 'copy_contents' : staticAdtMethod(copy_unicode_contents), 'gethash': LLHelpers.ll_strhash} )) # 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
mallocstr = new_malloc(STR) mallocunicode = new_malloc(UNICODE) def emptystrfun(): return emptystr def emptyunicodefun(): return emptyunicode STR.become( GcStruct('rpy_string', ('hash', Signed), ('chars', Array(Char, hints={'immutable': True})), adtmeths={ 'malloc': staticAdtMethod(mallocstr), 'empty': staticAdtMethod(emptystrfun) })) UNICODE.become( GcStruct('rpy_unicode', ('hash', Signed), ('chars', Array(UniChar, hints={'immutable': True})), adtmeths={ 'malloc': staticAdtMethod(mallocunicode), 'empty': staticAdtMethod(emptyunicodefun) })) SIGNED_ARRAY = GcArray(Signed) CONST_STR_CACHE = WeakValueDictionary() CONST_UNICODE_CACHE = WeakValueDictionary()
return hop.gendirectcall(cls.ll_join_strs, size, vtemp) do_stringformat = classmethod(do_stringformat) TEMP = GcArray(Ptr(STR)) # ____________________________________________________________ STR.become( GcStruct( "rpy_string", ("hash", Signed), ("chars", Array(Char, hints={"immutable": True})), adtmeths={ "malloc": staticAdtMethod(mallocstr), "empty": staticAdtMethod(emptystrfun), "copy_contents": staticAdtMethod(copy_string_contents), "gethash": LLHelpers.ll_strhash, }, ) ) UNICODE.become( GcStruct( "rpy_unicode", ("hash", Signed), ("chars", Array(UniChar, hints={"immutable": True})), adtmeths={ "malloc": staticAdtMethod(mallocunicode), "empty": staticAdtMethod(emptyunicodefun), "copy_contents": staticAdtMethod(copy_unicode_contents),
hop.exception_cannot_occur() # to ignore the ZeroDivisionError of '%' return hop.gendirectcall(cls.ll_join_strs, size, vtemp) do_stringformat = classmethod(do_stringformat) TEMP = GcArray(Ptr(STR)) # ____________________________________________________________ STR.become( GcStruct('rpy_string', ('hash', Signed), ('chars', Array(Char, hints={'immutable': True})), adtmeths={ 'malloc': staticAdtMethod(mallocstr), 'empty': staticAdtMethod(emptystrfun), 'copy_contents': staticAdtMethod(copy_string_contents), 'gethash': LLHelpers.ll_strhash })) UNICODE.become( GcStruct('rpy_unicode', ('hash', Signed), ('chars', Array(UniChar, hints={'immutable': True})), adtmeths={ 'malloc': staticAdtMethod(mallocunicode), 'empty': staticAdtMethod(emptyunicodefun), 'copy_contents': staticAdtMethod(copy_unicode_contents), 'gethash': LLHelpers.ll_strhash })) # TODO: make the public interface of the rstr module cleaner
r.hash = 0 return r mallocstr._annspecialcase_ = 'specialize:semierased' return mallocstr mallocstr = new_malloc(STR) mallocunicode = new_malloc(UNICODE) def emptystrfun(): return emptystr def emptyunicodefun(): return emptyunicode STR.become(GcStruct('rpy_string', ('hash', Signed), ('chars', Array(Char, hints={'immutable': True})), adtmeths={'malloc' : staticAdtMethod(mallocstr), 'empty' : staticAdtMethod(emptystrfun)})) UNICODE.become(GcStruct('rpy_unicode', ('hash', Signed), ('chars', Array(UniChar, hints={'immutable': True})), adtmeths={'malloc' : staticAdtMethod(mallocunicode), 'empty' : staticAdtMethod(emptyunicodefun)} )) SIGNED_ARRAY = GcArray(Signed) CONST_STR_CACHE = WeakValueDictionary() CONST_UNICODE_CACHE = WeakValueDictionary() class BaseLLStringRepr(Repr): def convert_const(self, value): if value is None: return nullptr(self.lowleveltype.TO) #value = getattr(value, '__self__', value) # for bound string methods