File: irbuild-lists.test

package info (click to toggle)
mypy 0.812-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 18,596 kB
  • sloc: python: 74,869; cpp: 11,212; ansic: 3,935; makefile: 238; sh: 13
file content (252 lines) | stat: -rw-r--r-- 4,867 bytes parent folder | download
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
[case testListGet]
from typing import List
def f(x: List[int]) -> int:
    return x[0]
[out]
def f(x):
    x :: list
    r0 :: object
    r1 :: int
L0:
    r0 = CPyList_GetItemShort(x, 0)
    r1 = unbox(int, r0)
    return r1

[case testListOfListGet]
from typing import List
def f(x: List[List[int]]) -> List[int]:
    return x[0]
[out]
def f(x):
    x :: list
    r0 :: object
    r1 :: list
L0:
    r0 = CPyList_GetItemShort(x, 0)
    r1 = cast(list, r0)
    return r1

[case testListOfListGet2]
from typing import List
def f(x: List[List[int]]) -> int:
    return x[0][1]
[out]
def f(x):
    x :: list
    r0 :: object
    r1 :: list
    r2 :: object
    r3 :: int
L0:
    r0 = CPyList_GetItemShort(x, 0)
    r1 = cast(list, r0)
    r2 = CPyList_GetItemShort(r1, 2)
    r3 = unbox(int, r2)
    return r3

[case testListSet]
from typing import List
def f(x: List[int]) -> None:
    x[0] = 1
[out]
def f(x):
    x :: list
    r0 :: object
    r1 :: bit
L0:
    r0 = box(short_int, 2)
    r1 = CPyList_SetItem(x, 0, r0)
    return 1

[case testNewListEmpty]
from typing import List
def f() -> None:
    x = []  # type: List[int]
[out]
def f():
    r0, x :: list
L0:
    r0 = PyList_New(0)
    x = r0
    return 1

[case testNewListTwoItems]
from typing import List
def f() -> None:
    x: List[int] = [1, 2]
[out]
def f():
    r0 :: list
    r1, r2 :: object
    r3, r4, r5 :: ptr
    x :: list
L0:
    r0 = PyList_New(2)
    r1 = box(short_int, 2)
    r2 = box(short_int, 4)
    r3 = get_element_ptr r0 ob_item :: PyListObject
    r4 = load_mem r3, r0 :: ptr*
    set_mem r4, r1, r0 :: builtins.object*
    r5 = r4 + WORD_SIZE*1
    set_mem r5, r2, r0 :: builtins.object*
    x = r0
    return 1

[case testListMultiply]
from typing import List
def f(a: List[int]) -> None:
    b = a * 2
    b = 3 * [4]
[out]
def f(a):
    a, r0, b, r1 :: list
    r2 :: object
    r3, r4 :: ptr
    r5 :: list
L0:
    r0 = CPySequence_Multiply(a, 4)
    b = r0
    r1 = PyList_New(1)
    r2 = box(short_int, 8)
    r3 = get_element_ptr r1 ob_item :: PyListObject
    r4 = load_mem r3, r1 :: ptr*
    set_mem r4, r2, r1 :: builtins.object*
    r5 = CPySequence_RMultiply(6, r1)
    b = r5
    return 1

[case testListLen]
from typing import List
def f(a: List[int]) -> int:
    return len(a)
[out]
def f(a):
    a :: list
    r0 :: ptr
    r1 :: native_int
    r2 :: short_int
L0:
    r0 = get_element_ptr a ob_size :: PyVarObject
    r1 = load_mem r0, a :: native_int*
    r2 = r1 << 1
    return r2

[case testListAppend]
from typing import List
def f(a: List[int], x: int) -> None:
    a.append(x)
[out]
def f(a, x):
    a :: list
    x :: int
    r0 :: object
    r1 :: int32
    r2 :: bit
L0:
    r0 = box(int, x)
    r1 = PyList_Append(a, r0)
    r2 = r1 >= 0 :: signed
    return 1

[case testIndexLvalue]
from typing import List
def increment(l: List[int]) -> List[int]:
    for i in range(len(l)):
        l[i] += 1
    return l
[out]
def increment(l):
    l :: list
    r0 :: ptr
    r1 :: native_int
    r2, r3 :: short_int
    i :: int
    r4 :: bit
    r5, r6, r7 :: object
    r8 :: bit
    r9 :: short_int
L0:
    r0 = get_element_ptr l ob_size :: PyVarObject
    r1 = load_mem r0, l :: native_int*
    r2 = r1 << 1
    r3 = 0
    i = r3
L1:
    r4 = r3 < r2 :: signed
    if r4 goto L2 else goto L4 :: bool
L2:
    r5 = CPyList_GetItem(l, i)
    r6 = box(short_int, 2)
    r7 = PyNumber_InPlaceAdd(r5, r6)
    r8 = CPyList_SetItem(l, i, r7)
L3:
    r9 = r3 + 2
    r3 = r9
    i = r9
    goto L1
L4:
    return l

[case testListDisplay]
from typing import List
def f(x: List[int], y: List[int]) -> List[int]:
    return [1, 2, *x, *y, 3]
[out]
def f(x, y):
    x, y, r0 :: list
    r1, r2 :: object
    r3, r4, r5 :: ptr
    r6, r7, r8 :: object
    r9 :: int32
    r10 :: bit
L0:
    r0 = PyList_New(2)
    r1 = box(short_int, 2)
    r2 = box(short_int, 4)
    r3 = get_element_ptr r0 ob_item :: PyListObject
    r4 = load_mem r3, r0 :: ptr*
    set_mem r4, r1, r0 :: builtins.object*
    r5 = r4 + WORD_SIZE*1
    set_mem r5, r2, r0 :: builtins.object*
    r6 = CPyList_Extend(r0, x)
    r7 = CPyList_Extend(r0, y)
    r8 = box(short_int, 6)
    r9 = PyList_Append(r0, r8)
    r10 = r9 >= 0 :: signed
    return r0

[case testListIn]
from typing import List
def f(x: List[int], y: int) -> bool:
    return y in x
[out]
def f(x, y):
    x :: list
    y :: int
    r0 :: object
    r1 :: int32
    r2 :: bit
    r3 :: bool
L0:
    r0 = box(int, y)
    r1 = PySequence_Contains(x, r0)
    r2 = r1 >= 0 :: signed
    r3 = truncate r1: int32 to builtins.bool
    return r3

[case testListInsert]
from typing import List
def f(x: List[int], y: int) -> None:
    x.insert(0, y)
[out]
def f(x, y):
    x :: list
    y :: int
    r0 :: object
    r1 :: int32
    r2 :: bit
L0:
    r0 = box(int, y)
    r1 = CPyList_Insert(x, 0, r0)
    r2 = r1 >= 0 :: signed
    return 1