File: irbuild-tuple.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 (257 lines) | stat: -rw-r--r-- 4,615 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
253
254
255
256
257
[case testTupleGet]
from typing import Tuple

def f(x: Tuple[Tuple[int, bool], bool]) -> int:
    return x[0][0]
[out]
def f(x):
    x :: tuple[tuple[int, bool], bool]
    r0 :: tuple[int, bool]
    r1 :: int
L0:
    r0 = x[0]
    r1 = r0[0]
    return r1

[case testTupleNew]
from typing import Tuple

def f() -> int:
    t = (True, 1)
    return t[1]
[out]
def f():
    r0, t :: tuple[bool, int]
    r1 :: int
L0:
    r0 = (1, 2)
    t = r0
    r1 = t[1]
    return r1

[case testTupleLen]
from typing import Tuple
def f(x: Tuple[bool, bool, int]) -> int:
    return len(x)
[out]
def f(x):
    x :: tuple[bool, bool, int]
L0:
    return 6

[case testSequenceTuple]
from typing import List
def f(x: List[bool]) -> bool:
    return tuple(x)[1]
[out]
def f(x):
    x :: list
    r0 :: tuple
    r1 :: object
    r2 :: bool
L0:
    r0 = PyList_AsTuple(x)
    r1 = CPySequenceTuple_GetItem(r0, 2)
    r2 = unbox(bool, r1)
    return r2

[case testSequenceTupleLen]
from typing import Tuple
def f(x: Tuple[int, ...]) -> int:
  return len(x)
[out]
def f(x):
    x :: tuple
    r0 :: ptr
    r1 :: native_int
    r2 :: short_int
L0:
    r0 = get_element_ptr x ob_size :: PyVarObject
    r1 = load_mem r0, x :: native_int*
    r2 = r1 << 1
    return r2

[case testSequenceTupleForced]
from typing import Tuple
def f() -> int:
    t = (1, 2) # type: Tuple[int, ...]
    return t[1]
[out]
def f():
    r0 :: tuple[int, int]
    r1 :: object
    t :: tuple
    r2 :: object
    r3 :: int
L0:
    r0 = (2, 4)
    r1 = box(tuple[int, int], r0)
    t = r1
    r2 = CPySequenceTuple_GetItem(t, 2)
    r3 = unbox(int, r2)
    return r3

[case testTupleDisplay]
from typing import Sequence, Tuple
def f(x: Sequence[int], y: Sequence[int]) -> Tuple[int, ...]:
    return (1, 2, *x, *y, 3)
[out]
def f(x, y):
    x, y :: object
    r0 :: list
    r1, r2 :: object
    r3, r4, r5 :: ptr
    r6, r7, r8 :: object
    r9 :: int32
    r10 :: bit
    r11 :: tuple
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
    r11 = PyList_AsTuple(r0)
    return r11

[case testTupleFor]
from typing import Tuple, List
def f(xs: Tuple[str, ...]) -> None:
    for x in xs:
        pass
[out]
def f(xs):
    xs :: tuple
    r0 :: short_int
    r1 :: ptr
    r2 :: native_int
    r3 :: short_int
    r4 :: bit
    r5 :: object
    r6, x :: str
    r7 :: short_int
L0:
    r0 = 0
L1:
    r1 = get_element_ptr xs ob_size :: PyVarObject
    r2 = load_mem r1, xs :: native_int*
    r3 = r2 << 1
    r4 = r0 < r3 :: signed
    if r4 goto L2 else goto L4 :: bool
L2:
    r5 = CPySequenceTuple_GetItem(xs, r0)
    r6 = cast(str, r5)
    x = r6
L3:
    r7 = r0 + 2
    r0 = r7
    goto L1
L4:
    return 1

[case testNamedTupleAttribute]
from typing import NamedTuple

NT = NamedTuple('NT', [('x', int), ('y', int)])

def f(nt: NT, b: bool) -> int:
    if b:
        return nt.x
    return nt.y
[out]
def f(nt, b):
    nt :: tuple
    b :: bool
    r0 :: object
    r1 :: int
    r2 :: object
    r3 :: int
L0:
    if b goto L1 else goto L2 :: bool
L1:
    r0 = CPySequenceTuple_GetItem(nt, 0)
    r1 = unbox(int, r0)
    return r1
L2:
    r2 = CPySequenceTuple_GetItem(nt, 2)
    r3 = unbox(int, r2)
    return r3


[case testTupleOperatorIn]
def f(i: int) -> bool:
    return i in [1, 2, 3]
[out]
def f(i):
    i :: int
    r0 :: native_int
    r1, r2 :: bit
    r3 :: bool
    r4 :: bit
    r5 :: bool
    r6 :: native_int
    r7, r8 :: bit
    r9 :: bool
    r10 :: bit
    r11 :: bool
    r12 :: native_int
    r13, r14 :: bit
    r15 :: bool
    r16 :: bit
L0:
    r0 = i & 1
    r1 = r0 == 0
    if r1 goto L1 else goto L2 :: bool
L1:
    r2 = i == 2
    r3 = r2
    goto L3
L2:
    r4 = CPyTagged_IsEq_(i, 2)
    r3 = r4
L3:
    if r3 goto L4 else goto L5 :: bool
L4:
    r5 = r3
    goto L9
L5:
    r6 = i & 1
    r7 = r6 == 0
    if r7 goto L6 else goto L7 :: bool
L6:
    r8 = i == 4
    r9 = r8
    goto L8
L7:
    r10 = CPyTagged_IsEq_(i, 4)
    r9 = r10
L8:
    r5 = r9
L9:
    if r5 goto L10 else goto L11 :: bool
L10:
    r11 = r5
    goto L15
L11:
    r12 = i & 1
    r13 = r12 == 0
    if r13 goto L12 else goto L13 :: bool
L12:
    r14 = i == 6
    r15 = r14
    goto L14
L13:
    r16 = CPyTagged_IsEq_(i, 6)
    r15 = r16
L14:
    r11 = r15
L15:
    return r11