Debian Codegraph @

rpython/rtyper/rbytearray.py

raw symbols SCIP
1 from rpython.annotator import model as annmodel
2 from rpython.rtyper.lltypesystem import lltype
3 from rpython.rtyper.rint import IntegerRepr
4 from rpython.rtyper.rstr import AbstractStringRepr
5 from rpython.tool.pairtype import pairtype
6
7
8 class AbstractByteArrayRepr(AbstractStringRepr):
9 pass
10
11 class __extend__(pairtype(AbstractByteArrayRepr, AbstractByteArrayRepr)):
12 def rtype_add((r_b1, r_b2), hop):
13 if hop.s_result.is_constant():
14 return hop.inputconst(r_b1, hop.s_result.const)
15 v_b1, v_b2 = hop.inputargs(r_b1, r_b2)
16 return hop.gendirectcall(r_b1.ll.ll_strconcat, v_b1, v_b2)
17
18 class __extend__(pairtype(AbstractByteArrayRepr, AbstractStringRepr)):
19 def rtype_add((r_b1, r_s2), hop):
20 str_repr = r_s2.repr
21 if hop.s_result.is_constant():
22 return hop.inputconst(r_b1, hop.s_result.const)
23 v_b1, v_str2 = hop.inputargs(r_b1, str_repr)
24 return hop.gendirectcall(r_b1.ll.ll_strconcat, v_b1, v_str2)
25
26 class __extend__(pairtype(AbstractStringRepr, AbstractByteArrayRepr)):
27 def rtype_add((r_s1, r_b2), hop):
28 str_repr = r_s1.repr
29 if hop.s_result.is_constant():
30 return hop.inputconst(r_b2, hop.s_result.const)
31 v_str1, v_b2 = hop.inputargs(str_repr, r_b2)
32 return hop.gendirectcall(r_b2.ll.ll_strconcat, v_str1, v_b2)
33
34 class __extend__(pairtype(AbstractByteArrayRepr, IntegerRepr)):
35 def rtype_setitem((r_b, r_int), hop, checkidx=False):
36 bytearray_repr = r_b.repr
37 v_str, v_index, v_item = hop.inputargs(bytearray_repr, lltype.Signed,
38 lltype.Signed)
39 if checkidx:
40 if hop.args_s[1].nonneg:
41 llfn = r_b.ll.ll_strsetitem_nonneg_checked
42 else:
43 llfn = r_b.ll.ll_strsetitem_checked
44 else:
45 if hop.args_s[1].nonneg:
46 llfn = r_b.ll.ll_strsetitem_nonneg
47 else:
48 llfn = r_b.ll.ll_strsetitem
49 if checkidx:
50 hop.exception_is_here()
51 else:
52 hop.exception_cannot_occur()
53 return hop.gendirectcall(llfn, v_str, v_index, v_item)
54
55 class __extend__(annmodel.SomeByteArray):
56 def rtyper_makekey(self):
57 return self.__class__,
58
59 def rtyper_makerepr(self, rtyper):
60 from rpython.rtyper.lltypesystem.rbytearray import bytearray_repr
61 return bytearray_repr