-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Expand file tree
/
Copy pathirbuild-bytes.test
More file actions
301 lines (283 loc) · 5.98 KB
/
irbuild-bytes.test
File metadata and controls
301 lines (283 loc) · 5.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
[case testBytesBasics]
def f(num: int, l: list, d: dict, s: str) -> None:
b1 = bytes()
b2 = bytes(num)
b3 = bytes(l)
b4 = bytes(d)
b5 = bytes(s)
[out]
def f(num, l, d, s):
num :: int
l :: list
d :: dict
s :: str
r0, r1 :: object
r2, b1 :: bytes
r3, r4 :: object
r5 :: object[1]
r6 :: object_ptr
r7 :: object
r8, b2, r9, b3, r10, b4, r11, b5 :: bytes
L0:
r0 = load_address PyBytes_Type
r1 = PyObject_Vectorcall(r0, 0, 0, 0)
r2 = cast(bytes, r1)
b1 = r2
r3 = load_address PyBytes_Type
r4 = box(int, num)
r5 = [r4]
r6 = load_address r5
r7 = PyObject_Vectorcall(r3, r6, 1, 0)
keep_alive r4
r8 = cast(bytes, r7)
b2 = r8
r9 = PyBytes_FromObject(l)
b3 = r9
r10 = PyBytes_FromObject(d)
b4 = r10
r11 = PyBytes_FromObject(s)
b5 = r11
return 1
[case testBytearrayBasics]
def f(s: str, num: int) -> None:
a = bytearray()
b = bytearray(s)
c = bytearray(num)
[out]
def f(s, num):
s :: str
num :: int
r0, a, r1, b :: bytearray
r2 :: object
r3, c :: bytearray
L0:
r0 = CPyByteArray_New()
a = r0
r1 = PyByteArray_FromObject(s)
b = r1
r2 = box(int, num)
r3 = PyByteArray_FromObject(r2)
c = r3
return 1
[case testBytesEquality]
def eq(x: bytes, y: bytes) -> bool:
return x == y
def neq(x: bytes, y: bytes) -> bool:
return x != y
[out]
def eq(x, y):
x, y :: bytes
r0 :: i32
r1, r2 :: bit
L0:
r0 = CPyBytes_Compare(x, y)
r1 = r0 >= 0 :: signed
r2 = r0 == 1
return r2
def neq(x, y):
x, y :: bytes
r0 :: i32
r1, r2 :: bit
L0:
r0 = CPyBytes_Compare(x, y)
r1 = r0 >= 0 :: signed
r2 = r0 != 1
return r2
[case testBytesSlicing]
def f(a: bytes, start: int, end: int) -> bytes:
return a[start:end]
[out]
def f(a, start, end):
a :: bytes
start, end :: int
r0 :: bytes
L0:
r0 = CPyBytes_GetSlice(a, start, end)
return r0
[case testBytesIndex]
from mypy_extensions import i64
def f(a: bytes, i: i64) -> int:
return a[i]
[out]
def f(a, i):
a :: bytes
i, r0 :: i64
r1, r2 :: bool
r3 :: int
L0:
r0 = CPyBytes_AdjustIndex(a, i)
r1 = CPyBytes_RangeCheck(a, r0)
if r1 goto L2 else goto L1 :: bool
L1:
r2 = raise IndexError('index out of range')
unreachable
L2:
r3 = CPyBytes_GetItemUnsafe(a, r0)
return r3
[case testBytesConcat]
def f(a: bytes, b: bytes) -> bytes:
return a + b
[out]
def f(a, b):
a, b, r0 :: bytes
L0:
r0 = CPyBytes_Concat(a, b)
return r0
[case testBytesJoin]
from typing import List
def f(b: List[bytes]) -> bytes:
return b" ".join(b)
[out]
def f(b):
b :: list
r0, r1 :: bytes
L0:
r0 = b' '
r1 = CPyBytes_Join(r0, b)
return r1
[case testBytesLen]
def f(b: bytes) -> int:
return len(b)
[out]
def f(b):
b :: bytes
r0 :: native_int
r1 :: short_int
L0:
r0 = var_object_size b
r1 = r0 << 1
return r1
[case testBytesFormatting]
def f(var: bytes, num: int) -> None:
b1 = b'aaaa%bbbbb%s' % (var, var)
b2 = b'aaaa%bbbbb%s%d' % (var, var, num)
b3 = b'%b' % var
b4 = b'%ssss' % var
b5 = b'%d' % num
b6 = b'%d' % 42
b7 = b'%d' % (67 + 2)
[typing fixtures/typing-full.pyi]
[out]
def f(var, num):
var :: bytes
num :: int
r0, r1, r2, b1, r3, r4, r5, r6, b2, r7, b3, r8, r9, b4, r10, r11, b5, r12, r13, b6, r14, r15, b7 :: bytes
L0:
r0 = b'aaaa'
r1 = b'bbbb'
r2 = CPyBytes_Build(4, r0, var, r1, var)
b1 = r2
r3 = CPyTagged_AsciiBytes(num)
r4 = b'aaaa'
r5 = b'bbbb'
r6 = CPyBytes_Build(5, r4, var, r5, var, r3)
b2 = r6
r7 = CPyBytes_Build(1, var)
b3 = r7
r8 = b'sss'
r9 = CPyBytes_Build(2, var, r8)
b4 = r9
r10 = CPyTagged_AsciiBytes(num)
r11 = CPyBytes_Build(1, r10)
b5 = r11
r12 = b'42'
r13 = CPyBytes_Build(1, r12)
b6 = r13
r14 = b'69'
r15 = CPyBytes_Build(1, r14)
b7 = r15
return 1
[case testOptionalBytesEquality]
from typing import Optional
def non_opt_opt(x: bytes, y: Optional[bytes]) -> bool:
return x != y
[out]
def non_opt_opt(x, y):
x :: bytes
y :: union[bytes, None]
r0 :: object
r1 :: bit
r2 :: bool
r3 :: bytes
r4 :: i32
r5, r6 :: bit
L0:
r0 = load_address _Py_NoneStruct
r1 = y == r0
if r1 goto L1 else goto L2 :: bool
L1:
r2 = 1
goto L3
L2:
r3 = unchecked borrow cast(bytes, y)
r4 = CPyBytes_Compare(r3, x)
r5 = r4 >= 0 :: signed
r6 = r4 != 1
r2 = r6
L3:
keep_alive y
return r2
[case testBytesMultiply]
def b_times_i(s: bytes, n: int) -> bytes:
return s * n
def i_times_b(s: bytes, n: int) -> bytes:
return n * s
[out]
def b_times_i(s, n):
s :: bytes
n :: int
r0 :: bytes
L0:
r0 = CPyBytes_Multiply(s, n)
return r0
def i_times_b(s, n):
s :: bytes
n :: int
r0 :: bytes
L0:
r0 = CPyBytes_Multiply(s, n)
return r0
[case testBytesTranslate]
def f(b: bytes, table: bytes) -> bytes:
return b.translate(table)
[out]
def f(b, table):
b, table, r0 :: bytes
L0:
r0 = CPyBytes_Translate(b, table)
return r0
[case testBytesStartsWith]
def f(a: bytes, b: bytes) -> bool:
return a.startswith(b)
[out]
def f(a, b):
a, b :: bytes
r0 :: i32
r1 :: bool
L0:
r0 = CPyBytes_Startswith(a, b)
r1 = truncate r0: i32 to builtins.bool
return r1
[case testBytesEndsWith]
def f(a: bytes, b: bytes) -> bool:
return a.endswith(b)
[out]
def f(a, b):
a, b :: bytes
r0 :: i32
r1 :: bool
L0:
r0 = CPyBytes_Endswith(a, b)
r1 = truncate r0: i32 to builtins.bool
return r1
[case testBytesVsBytearray]
def bytes_func(b: bytes) -> None: pass
def bytearray_func(ba: bytearray) -> None: pass
def foo(b: bytes, ba: bytearray) -> None:
bytes_func(b)
bytearray_func(ba)
bytes_func(ba)
bytearray_func(b)
[out]
main:7: error: Argument 1 to "bytes_func" has incompatible type "bytearray"; expected "bytes"
main:8: error: Argument 1 to "bytearray_func" has incompatible type "bytes"; expected "bytearray"