Debian Codegraph @

mypyc/test-data/irbuild-i64.test

raw
1 [case testI64Basics]
2 from mypy_extensions import i64
3
4 def f() -> i64:
5 x: i64 = 5
6 y = x
7 return y
8 [out]
9 def f():
10 x, y :: i64
11 L0:
12 x = 5
13 y = x
14 return y
15
16 [case testI64Compare]
17 from mypy_extensions import i64
18
19 def min(x: i64, y: i64) -> i64:
20 if x < y:
21 return x
22 else:
23 return y
24
25 def all_comparisons(x: i64) -> int:
26 if x == 2:
27 y = 10
28 elif 3 != x:
29 y = 11
30 elif x > 4:
31 y = 12
32 elif 6 >= x:
33 y = 13
34 elif x < 5:
35 y = 14
36 elif 6 <= x:
37 y = 15
38 else:
39 y = 16
40 return y
41 [out]
42 def min(x, y):
43 x, y :: i64
44 r0 :: bit
45 L0:
46 r0 = x < y :: signed
47 if r0 goto L1 else goto L2 :: bool
48 L1:
49 return x
50 L2:
51 return y
52 L3:
53 unreachable
54 def all_comparisons(x):
55 x :: i64
56 r0 :: bit
57 y :: int
58 r1, r2, r3, r4, r5 :: bit
59 L0:
60 r0 = x == 2
61 if r0 goto L1 else goto L2 :: bool
62 L1:
63 y = 20
64 goto L18
65 L2:
66 r1 = 3 != x
67 if r1 goto L3 else goto L4 :: bool
68 L3:
69 y = 22
70 goto L17
71 L4:
72 r2 = x > 4 :: signed
73 if r2 goto L5 else goto L6 :: bool
74 L5:
75 y = 24
76 goto L16
77 L6:
78 r3 = 6 >= x :: signed
79 if r3 goto L7 else goto L8 :: bool
80 L7:
81 y = 26
82 goto L15
83 L8:
84 r4 = x < 5 :: signed
85 if r4 goto L9 else goto L10 :: bool
86 L9:
87 y = 28
88 goto L14
89 L10:
90 r5 = 6 <= x :: signed
91 if r5 goto L11 else goto L12 :: bool
92 L11:
93 y = 30
94 goto L13
95 L12:
96 y = 32
97 L13:
98 L14:
99 L15:
100 L16:
101 L17:
102 L18:
103 return y
104
105 [case testI64Arithmetic]
106 from mypy_extensions import i64
107
108 def f(x: i64, y: i64) -> i64:
109 z = x + y
110 return y - z
111 [out]
112 def f(x, y):
113 x, y, r0, z, r1 :: i64
114 L0:
115 r0 = x + y
116 z = r0
117 r1 = y - z
118 return r1
119
120 [case testI64Negation]
121 from mypy_extensions import i64
122
123 def f() -> i64:
124 i: i64 = -3
125 return -i
126 [out]
127 def f():
128 i, r0 :: i64
129 L0:
130 i = -3
131 r0 = 0 - i
132 return r0
133
134 [case testI64MoreUnaryOps]
135 from mypy_extensions import i64
136
137 def unary(x: i64) -> i64:
138 y = ~x
139 x = +y
140 return x
141 [out]
142 def unary(x):
143 x, r0, y :: i64
144 L0:
145 r0 = x ^ -1
146 y = r0
147 x = y
148 return x
149
150 [case testI64BoxingAndUnboxing]
151 from typing import Any
152 from mypy_extensions import i64
153
154 def f(a: Any) -> None:
155 b: i64 = a
156 a = b
157 [out]
158 def f(a):
159 a :: object
160 r0, b :: i64
161 r1 :: object
162 L0:
163 r0 = unbox(i64, a)
164 b = r0
165 r1 = box(i64, b)
166 a = r1
167 return 1
168
169 [case testI64ListGetSetItem]
170 from typing import List
171 from mypy_extensions import i64
172
173 def get(a: List[i64], i: i64) -> i64:
174 return a[i]
175 def set(a: List[i64], i: i64, x: i64) -> None:
176 a[i] = x
177 [out]
178 def get(a, i):
179 a :: list
180 i :: i64
181 r0 :: object
182 r1 :: i64
183 L0:
184 r0 = CPyList_GetItemInt64(a, i)
185 r1 = unbox(i64, r0)
186 return r1
187 def set(a, i, x):
188 a :: list
189 i, x :: i64
190 r0 :: object
191 r1 :: bit
192 L0:
193 r0 = box(i64, x)
194 r1 = CPyList_SetItemInt64(a, i, r0)
195 return 1
196
197 [case testI64MixedArithmetic]
198 from mypy_extensions import i64
199
200 def f() -> i64:
201 a: i64 = 1
202 b = a + 2
203 return 3 - b
204 [out]
205 def f():
206 a, r0, b, r1 :: i64
207 L0:
208 a = 1
209 r0 = a + 2
210 b = r0
211 r1 = 3 - b
212 return r1
213
214 [case testI64MixedComparison]
215 from mypy_extensions import i64
216
217 def f(a: i64) -> i64:
218 if a < 3:
219 return 1
220 elif 3 < a:
221 return 2
222 return 3
223 [out]
224 def f(a):
225 a :: i64
226 r0, r1 :: bit
227 L0:
228 r0 = a < 3 :: signed
229 if r0 goto L1 else goto L2 :: bool
230 L1:
231 return 1
232 L2:
233 r1 = 3 < a :: signed
234 if r1 goto L3 else goto L4 :: bool
235 L3:
236 return 2
237 L4:
238 L5:
239 return 3
240
241 [case testI64InplaceOperations]
242 from mypy_extensions import i64
243
244 def add(a: i64) -> i64:
245 b = a
246 b += 1
247 a += b
248 return a
249 def others(a: i64, b: i64) -> i64:
250 a -= b
251 a *= b
252 a &= b
253 a |= b
254 a ^= b
255 a <<= b
256 a >>= b
257 return a
258 [out]
259 def add(a):
260 a, b, r0, r1 :: i64
261 L0:
262 b = a
263 r0 = b + 1
264 b = r0
265 r1 = a + b
266 a = r1
267 return a
268 def others(a, b):
269 a, b, r0, r1, r2, r3, r4, r5, r6 :: i64
270 L0:
271 r0 = a - b
272 a = r0
273 r1 = a * b
274 a = r1
275 r2 = a & b
276 a = r2
277 r3 = a | b
278 a = r3
279 r4 = a ^ b
280 a = r4
281 r5 = a << b
282 a = r5
283 r6 = a >> b
284 a = r6
285 return a
286
287 [case testI64BitwiseOps]
288 from mypy_extensions import i64
289
290 def forward(a: i64, b: i64) -> i64:
291 b = a & 1
292 a = b | 2
293 b = a ^ 3
294 a = b << 4
295 b = a >> 5
296 return b
297
298 def reverse(a: i64, b: i64) -> i64:
299 b = 1 & a
300 a = 2 | b
301 b = 3 ^ a
302 a = 4 << b
303 b = 5 >> a
304 return b
305
306 def unary(a: i64) -> i64:
307 return ~a
308 [out]
309 def forward(a, b):
310 a, b, r0, r1, r2, r3, r4 :: i64
311 L0:
312 r0 = a & 1
313 b = r0
314 r1 = b | 2
315 a = r1
316 r2 = a ^ 3
317 b = r2
318 r3 = b << 4
319 a = r3
320 r4 = a >> 5
321 b = r4
322 return b
323 def reverse(a, b):
324 a, b, r0, r1, r2, r3, r4 :: i64
325 L0:
326 r0 = 1 & a
327 b = r0
328 r1 = 2 | b
329 a = r1
330 r2 = 3 ^ a
331 b = r2
332 r3 = 4 << b
333 a = r3
334 r4 = 5 >> a
335 b = r4
336 return b
337 def unary(a):
338 a, r0 :: i64
339 L0:
340 r0 = a ^ -1
341 return r0
342
343 [case testI64Division]
344 from mypy_extensions import i64
345
346 def constant_divisor(x: i64) -> i64:
347 return x // 7
348 def variable_divisor(x: i64, y: i64) -> i64:
349 return x // y
350 def constant_lhs(x: i64) -> i64:
351 return 27 // x
352 def divide_by_neg_one(x: i64) -> i64:
353 return x // -1
354 def divide_by_zero(x: i64) -> i64:
355 return x // 0
356 [out]
357 def constant_divisor(x):
358 x, r0, r1 :: i64
359 r2, r3, r4 :: bit
360 r5 :: i64
361 r6 :: bit
362 r7 :: i64
363 L0:
364 r0 = x / 7
365 r1 = r0
366 r2 = x < 0 :: signed
367 r3 = 7 < 0 :: signed
368 r4 = r2 == r3
369 if r4 goto L3 else goto L1 :: bool
370 L1:
371 r5 = r1 * 7
372 r6 = r5 == x
373 if r6 goto L3 else goto L2 :: bool
374 L2:
375 r7 = r1 - 1
376 r1 = r7
377 L3:
378 return r1
379 def variable_divisor(x, y):
380 x, y, r0 :: i64
381 L0:
382 r0 = CPyInt64_Divide(x, y)
383 return r0
384 def constant_lhs(x):
385 x, r0 :: i64
386 L0:
387 r0 = CPyInt64_Divide(27, x)
388 return r0
389 def divide_by_neg_one(x):
390 x, r0 :: i64
391 L0:
392 r0 = CPyInt64_Divide(x, -1)
393 return r0
394 def divide_by_zero(x):
395 x, r0 :: i64
396 L0:
397 r0 = CPyInt64_Divide(x, 0)
398 return r0
399
400 [case testI64Mod]
401 from mypy_extensions import i64
402
403 def constant_divisor(x: i64) -> i64:
404 return x % 7
405 def variable_divisor(x: i64, y: i64) -> i64:
406 return x % y
407 def constant_lhs(x: i64) -> i64:
408 return 27 % x
409 def mod_by_zero(x: i64) -> i64:
410 return x % 0
411 [out]
412 def constant_divisor(x):
413 x, r0, r1 :: i64
414 r2, r3, r4, r5 :: bit
415 r6 :: i64
416 L0:
417 r0 = x % 7
418 r1 = r0
419 r2 = x < 0 :: signed
420 r3 = 7 < 0 :: signed
421 r4 = r2 == r3
422 if r4 goto L3 else goto L1 :: bool
423 L1:
424 r5 = r1 == 0
425 if r5 goto L3 else goto L2 :: bool
426 L2:
427 r6 = r1 + 7
428 r1 = r6
429 L3:
430 return r1
431 def variable_divisor(x, y):
432 x, y, r0 :: i64
433 L0:
434 r0 = CPyInt64_Remainder(x, y)
435 return r0
436 def constant_lhs(x):
437 x, r0 :: i64
438 L0:
439 r0 = CPyInt64_Remainder(27, x)
440 return r0
441 def mod_by_zero(x):
442 x, r0 :: i64
443 L0:
444 r0 = CPyInt64_Remainder(x, 0)
445 return r0
446
447 [case testI64InPlaceDiv]
448 from mypy_extensions import i64
449
450 def by_constant(x: i64) -> i64:
451 x //= 7
452 return x
453 def by_variable(x: i64, y: i64) -> i64:
454 x //= y
455 return x
456 [out]
457 def by_constant(x):
458 x, r0, r1 :: i64
459 r2, r3, r4 :: bit
460 r5 :: i64
461 r6 :: bit
462 r7 :: i64
463 L0:
464 r0 = x / 7
465 r1 = r0
466 r2 = x < 0 :: signed
467 r3 = 7 < 0 :: signed
468 r4 = r2 == r3
469 if r4 goto L3 else goto L1 :: bool
470 L1:
471 r5 = r1 * 7
472 r6 = r5 == x
473 if r6 goto L3 else goto L2 :: bool
474 L2:
475 r7 = r1 - 1
476 r1 = r7
477 L3:
478 x = r1
479 return x
480 def by_variable(x, y):
481 x, y, r0 :: i64
482 L0:
483 r0 = CPyInt64_Divide(x, y)
484 x = r0
485 return x
486
487 [case testI64InPlaceMod]
488 from mypy_extensions import i64
489
490 def by_constant(x: i64) -> i64:
491 x %= 7
492 return x
493 def by_variable(x: i64, y: i64) -> i64:
494 x %= y
495 return x
496 [out]
497 def by_constant(x):
498 x, r0, r1 :: i64
499 r2, r3, r4, r5 :: bit
500 r6 :: i64
501 L0:
502 r0 = x % 7
503 r1 = r0
504 r2 = x < 0 :: signed
505 r3 = 7 < 0 :: signed
506 r4 = r2 == r3
507 if r4 goto L3 else goto L1 :: bool
508 L1:
509 r5 = r1 == 0
510 if r5 goto L3 else goto L2 :: bool
511 L2:
512 r6 = r1 + 7
513 r1 = r6
514 L3:
515 x = r1
516 return x
517 def by_variable(x, y):
518 x, y, r0 :: i64
519 L0:
520 r0 = CPyInt64_Remainder(x, y)
521 x = r0
522 return x
523
524 [case testI64ForRange]
525 from mypy_extensions import i64
526
527 def g(a: i64) -> None: pass
528
529 def f(x: i64) -> None:
530 n: i64 # TODO: Infer the type
531 for n in range(x):
532 g(n)
533 [out]
534 def g(a):
535 a :: i64
536 L0:
537 return 1
538 def f(x):
539 x, r0, n :: i64
540 r1 :: bit
541 r2 :: None
542 r3 :: i64
543 L0:
544 r0 = 0
545 n = r0
546 L1:
547 r1 = r0 < x :: signed
548 if r1 goto L2 else goto L4 :: bool
549 L2:
550 n = r0
551 r2 = g(n)
552 L3:
553 r3 = r0 + 1
554 r0 = r3
555 goto L1
556 L4:
557 return 1
558
559 [case testI64ConvertFromInt_64bit]
560 from mypy_extensions import i64
561
562 def int_to_i64(a: int) -> i64:
563 return a
564 [out]
565 def int_to_i64(a):
566 a :: int
567 r0 :: native_int
568 r1 :: bit
569 r2, r3 :: i64
570 r4 :: ptr
571 r5 :: c_ptr
572 r6 :: i64
573 L0:
574 r0 = a & 1
575 r1 = r0 == 0
576 if r1 goto L1 else goto L2 :: bool
577 L1:
578 r2 = a >> 1
579 r3 = r2
580 goto L3
581 L2:
582 r4 = a ^ 1
583 r5 = r4
584 r6 = CPyLong_AsInt64(r5)
585 r3 = r6
586 keep_alive a
587 L3:
588 return r3
589
590 [case testI64ConvertToInt_64bit]
591 from mypy_extensions import i64
592
593 def i64_to_int(a: i64) -> int:
594 return a
595 [out]
596 def i64_to_int(a):
597 a :: i64
598 r0, r1 :: bit
599 r2, r3, r4 :: int
600 L0:
601 r0 = a <= 4611686018427387903 :: signed
602 if r0 goto L1 else goto L2 :: bool
603 L1:
604 r1 = a >= -4611686018427387904 :: signed
605 if r1 goto L3 else goto L2 :: bool
606 L2:
607 r2 = CPyTagged_FromInt64(a)
608 r3 = r2
609 goto L4
610 L3:
611 r4 = a << 1
612 r3 = r4
613 L4:
614 return r3
615
616 [case testI64ConvertToInt_32bit]
617 from mypy_extensions import i64
618
619 def i64_to_int(a: i64) -> int:
620 return a
621 [out]
622 def i64_to_int(a):
623 a :: i64
624 r0, r1 :: bit
625 r2, r3 :: int
626 r4 :: native_int
627 r5 :: int
628 L0:
629 r0 = a <= 1073741823 :: signed
630 if r0 goto L1 else goto L2 :: bool
631 L1:
632 r1 = a >= -1073741824 :: signed
633 if r1 goto L3 else goto L2 :: bool
634 L2:
635 r2 = CPyTagged_FromInt64(a)
636 r3 = r2
637 goto L4
638 L3:
639 r4 = truncate a: i64 to native_int
640 r5 = r4 << 1
641 r3 = r5
642 L4:
643 return r3
644
645 [case testI64Tuple]
646 from typing import Tuple
647 from mypy_extensions import i64
648
649 def f(x: i64, y: i64) -> Tuple[i64, i64]:
650 return x, y
651
652 def g() -> Tuple[i64, i64]:
653 return 1, 2
654
655 def h() -> i64:
656 x, y = g()
657 t = g()
658 return x + y + t[0]
659 [out]
660 def f(x, y):
661 x, y, r0, r1 :: i64
662 r2 :: tuple[i64, i64]
663 L0:
664 r0 = x
665 r1 = y
666 r2 = (r0, r1)
667 return r2
668 def g():
669 r0 :: tuple[int, int]
670 r1 :: tuple[i64, i64]
671 L0:
672 r0 = (2, 4)
673 r1 = (1, 2)
674 return r1
675 def h():
676 r0 :: tuple[i64, i64]
677 r1, x, r2, y :: i64
678 r3, t :: tuple[i64, i64]
679 r4, r5, r6 :: i64
680 L0:
681 r0 = g()
682 r1 = r0[0]
683 x = r1
684 r2 = r0[1]
685 y = r2
686 r3 = g()
687 t = r3
688 r4 = x + y
689 r5 = t[0]
690 r6 = r4 + r5
691 return r6
692
693 [case testI64MixWithTagged1_64bit]
694 from mypy_extensions import i64
695 def f(x: i64, y: int) -> i64:
696 return x + y
697 [out]
698 def f(x, y):
699 x :: i64
700 y :: int
701 r0 :: native_int
702 r1 :: bit
703 r2, r3 :: i64
704 r4 :: ptr
705 r5 :: c_ptr
706 r6, r7 :: i64
707 L0:
708 r0 = y & 1
709 r1 = r0 == 0
710 if r1 goto L1 else goto L2 :: bool
711 L1:
712 r2 = y >> 1
713 r3 = r2
714 goto L3
715 L2:
716 r4 = y ^ 1
717 r5 = r4
718 r6 = CPyLong_AsInt64(r5)
719 r3 = r6
720 keep_alive y
721 L3:
722 r7 = x + r3
723 return r7
724
725 [case testI64MixWithTagged2_64bit]
726 from mypy_extensions import i64
727 def f(x: int, y: i64) -> i64:
728 return x + y
729 [out]
730 def f(x, y):
731 x :: int
732 y :: i64
733 r0 :: native_int
734 r1 :: bit
735 r2, r3 :: i64
736 r4 :: ptr
737 r5 :: c_ptr
738 r6, r7 :: i64
739 L0:
740 r0 = x & 1
741 r1 = r0 == 0
742 if r1 goto L1 else goto L2 :: bool
743 L1:
744 r2 = x >> 1
745 r3 = r2
746 goto L3
747 L2:
748 r4 = x ^ 1
749 r5 = r4
750 r6 = CPyLong_AsInt64(r5)
751 r3 = r6
752 keep_alive x
753 L3:
754 r7 = r3 + y
755 return r7
756
757 [case testI64MixWithTaggedInPlace1_64bit]
758 from mypy_extensions import i64
759 def f(y: i64) -> int:
760 x = 0
761 x += y
762 return x
763 [out]
764 def f(y):
765 y :: i64
766 x :: int
767 r0 :: native_int
768 r1 :: bit
769 r2, r3 :: i64
770 r4 :: ptr
771 r5 :: c_ptr
772 r6, r7 :: i64
773 r8, r9 :: bit
774 r10, r11, r12 :: int
775 L0:
776 x = 0
777 r0 = x & 1
778 r1 = r0 == 0
779 if r1 goto L1 else goto L2 :: bool
780 L1:
781 r2 = x >> 1
782 r3 = r2
783 goto L3
784 L2:
785 r4 = x ^ 1
786 r5 = r4
787 r6 = CPyLong_AsInt64(r5)
788 r3 = r6
789 keep_alive x
790 L3:
791 r7 = r3 + y
792 r8 = r7 <= 4611686018427387903 :: signed
793 if r8 goto L4 else goto L5 :: bool
794 L4:
795 r9 = r7 >= -4611686018427387904 :: signed
796 if r9 goto L6 else goto L5 :: bool
797 L5:
798 r10 = CPyTagged_FromInt64(r7)
799 r11 = r10
800 goto L7
801 L6:
802 r12 = r7 << 1
803 r11 = r12
804 L7:
805 x = r11
806 return x
807
808 [case testI64MixWithTaggedInPlace2_64bit]
809 from mypy_extensions import i64
810 def f(y: int) -> i64:
811 x: i64 = 0
812 x += y
813 return x
814 [out]
815 def f(y):
816 y :: int
817 x :: i64
818 r0 :: native_int
819 r1 :: bit
820 r2, r3 :: i64
821 r4 :: ptr
822 r5 :: c_ptr
823 r6, r7 :: i64
824 L0:
825 x = 0
826 r0 = y & 1
827 r1 = r0 == 0
828 if r1 goto L1 else goto L2 :: bool
829 L1:
830 r2 = y >> 1
831 r3 = r2
832 goto L3
833 L2:
834 r4 = y ^ 1
835 r5 = r4
836 r6 = CPyLong_AsInt64(r5)
837 r3 = r6
838 keep_alive y
839 L3:
840 r7 = x + r3
841 x = r7
842 return x
843
844 [case testI64MixedCompare1_64bit]
845 from mypy_extensions import i64
846 def f(x: int, y: i64) -> bool:
847 return x == y
848 [out]
849 def f(x, y):
850 x :: int
851 y :: i64
852 r0 :: native_int
853 r1 :: bit
854 r2, r3 :: i64
855 r4 :: ptr
856 r5 :: c_ptr
857 r6 :: i64
858 r7 :: bit
859 L0:
860 r0 = x & 1
861 r1 = r0 == 0
862 if r1 goto L1 else goto L2 :: bool
863 L1:
864 r2 = x >> 1
865 r3 = r2
866 goto L3
867 L2:
868 r4 = x ^ 1
869 r5 = r4
870 r6 = CPyLong_AsInt64(r5)
871 r3 = r6
872 keep_alive x
873 L3:
874 r7 = r3 == y
875 return r7
876
877 [case testI64MixedCompare2_64bit]
878 from mypy_extensions import i64
879 def f(x: i64, y: int) -> bool:
880 return x == y
881 [out]
882 def f(x, y):
883 x :: i64
884 y :: int
885 r0 :: native_int
886 r1 :: bit
887 r2, r3 :: i64
888 r4 :: ptr
889 r5 :: c_ptr
890 r6 :: i64
891 r7 :: bit
892 L0:
893 r0 = y & 1
894 r1 = r0 == 0
895 if r1 goto L1 else goto L2 :: bool
896 L1:
897 r2 = y >> 1
898 r3 = r2
899 goto L3
900 L2:
901 r4 = y ^ 1
902 r5 = r4
903 r6 = CPyLong_AsInt64(r5)
904 r3 = r6
905 keep_alive y
906 L3:
907 r7 = x == r3
908 return r7
909
910 [case testI64MixedCompare_32bit]
911 from mypy_extensions import i64
912 def f(x: int, y: i64) -> bool:
913 return x == y
914 [out]
915 def f(x, y):
916 x :: int
917 y :: i64
918 r0 :: native_int
919 r1 :: bit
920 r2, r3, r4 :: i64
921 r5 :: ptr
922 r6 :: c_ptr
923 r7 :: i64
924 r8 :: bit
925 L0:
926 r0 = x & 1
927 r1 = r0 == 0
928 if r1 goto L1 else goto L2 :: bool
929 L1:
930 r2 = extend signed x: builtins.int to i64
931 r3 = r2 >> 1
932 r4 = r3
933 goto L3
934 L2:
935 r5 = x ^ 1
936 r6 = r5
937 r7 = CPyLong_AsInt64(r6)
938 r4 = r7
939 keep_alive x
940 L3:
941 r8 = r4 == y
942 return r8
943
944 [case testI64AsBool]
945 from mypy_extensions import i64
946 def f(x: i64) -> i64:
947 if x:
948 return 5
949 elif not x:
950 return 6
951 return 3
952 def unary_not(x: i64) -> bool:
953 return not x
954 [out]
955 def f(x):
956 x :: i64
957 r0, r1 :: bit
958 L0:
959 r0 = x != 0
960 if r0 goto L1 else goto L2 :: bool
961 L1:
962 return 5
963 L2:
964 r1 = x != 0
965 if r1 goto L4 else goto L3 :: bool
966 L3:
967 return 6
968 L4:
969 L5:
970 return 3
971 def unary_not(x):
972 x :: i64
973 r0 :: bit
974 L0:
975 r0 = x == 0
976 return r0
977
978 [case testI64AssignMixed_64bit]
979 from mypy_extensions import i64
980 def f(x: i64, y: int) -> i64:
981 x = y
982 return x
983 def g(x: i64, y: int) -> int:
984 y = x
985 return y
986 [out]
987 def f(x, y):
988 x :: i64
989 y :: int
990 r0 :: native_int
991 r1 :: bit
992 r2, r3 :: i64
993 r4 :: ptr
994 r5 :: c_ptr
995 r6 :: i64
996 L0:
997 r0 = y & 1
998 r1 = r0 == 0
999 if r1 goto L1 else goto L2 :: bool
1000 L1:
1001 r2 = y >> 1
1002 r3 = r2
1003 goto L3
1004 L2:
1005 r4 = y ^ 1
1006 r5 = r4
1007 r6 = CPyLong_AsInt64(r5)
1008 r3 = r6
1009 keep_alive y
1010 L3:
1011 x = r3
1012 return x
1013 def g(x, y):
1014 x :: i64
1015 y :: int
1016 r0, r1 :: bit
1017 r2, r3, r4 :: int
1018 L0:
1019 r0 = x <= 4611686018427387903 :: signed
1020 if r0 goto L1 else goto L2 :: bool
1021 L1:
1022 r1 = x >= -4611686018427387904 :: signed
1023 if r1 goto L3 else goto L2 :: bool
1024 L2:
1025 r2 = CPyTagged_FromInt64(x)
1026 r3 = r2
1027 goto L4
1028 L3:
1029 r4 = x << 1
1030 r3 = r4
1031 L4:
1032 y = r3
1033 return y
1034
1035 [case testBorrowOverI64Arithmetic]
1036 from mypy_extensions import i64
1037
1038 def add_simple(c: C) -> i64:
1039 return c.x + c.y
1040
1041 def inplace_add_simple(c: C) -> None:
1042 c.x += c.y
1043
1044 def add_borrow(d: D) -> i64:
1045 return d.c.x + d.c.y
1046
1047 class D:
1048 c: C
1049
1050 class C:
1051 x: i64
1052 y: i64
1053 [out]
1054 def add_simple(c):
1055 c :: __main__.C
1056 r0, r1, r2 :: i64
1057 L0:
1058 r0 = c.x
1059 r1 = c.y
1060 r2 = r0 + r1
1061 return r2
1062 def inplace_add_simple(c):
1063 c :: __main__.C
1064 r0, r1, r2 :: i64
1065 r3 :: bool
1066 L0:
1067 r0 = c.x
1068 r1 = c.y
1069 r2 = r0 + r1
1070 c.x = r2; r3 = is_error
1071 return 1
1072 def add_borrow(d):
1073 d :: __main__.D
1074 r0 :: __main__.C
1075 r1 :: i64
1076 r2 :: __main__.C
1077 r3, r4 :: i64
1078 L0:
1079 r0 = borrow d.c
1080 r1 = r0.x
1081 r2 = borrow d.c
1082 r3 = r2.y
1083 r4 = r1 + r3
1084 keep_alive d, d
1085 return r4
1086
1087 [case testBorrowOverI64Bitwise]
1088 from mypy_extensions import i64
1089
1090 def bitwise_simple(c: C) -> i64:
1091 return c.x | c.y
1092
1093 def inplace_bitwide_simple(c: C) -> None:
1094 c.x &= c.y
1095
1096 def bitwise_borrow(d: D) -> i64:
1097 return d.c.x ^ d.c.y
1098
1099 class D:
1100 c: C
1101
1102 class C:
1103 x: i64
1104 y: i64
1105 [out]
1106 def bitwise_simple(c):
1107 c :: __main__.C
1108 r0, r1, r2 :: i64
1109 L0:
1110 r0 = c.x
1111 r1 = c.y
1112 r2 = r0 | r1
1113 return r2
1114 def inplace_bitwide_simple(c):
1115 c :: __main__.C
1116 r0, r1, r2 :: i64
1117 r3 :: bool
1118 L0:
1119 r0 = c.x
1120 r1 = c.y
1121 r2 = r0 & r1
1122 c.x = r2; r3 = is_error
1123 return 1
1124 def bitwise_borrow(d):
1125 d :: __main__.D
1126 r0 :: __main__.C
1127 r1 :: i64
1128 r2 :: __main__.C
1129 r3, r4 :: i64
1130 L0:
1131 r0 = borrow d.c
1132 r1 = r0.x
1133 r2 = borrow d.c
1134 r3 = r2.y
1135 r4 = r1 ^ r3
1136 keep_alive d, d
1137 return r4
1138
1139 [case testBorrowOverI64ListGetItem1]
1140 from mypy_extensions import i64
1141
1142 def f(n: i64) -> str:
1143 a = [C()]
1144 return a[n].s
1145
1146 class C:
1147 s: str
1148 [out]
1149 def f(n):
1150 n :: i64
1151 r0 :: __main__.C
1152 r1 :: list
1153 r2 :: ptr
1154 a :: list
1155 r3 :: object
1156 r4 :: __main__.C
1157 r5 :: str
1158 L0:
1159 r0 = C()
1160 r1 = PyList_New(1)
1161 r2 = list_items r1
1162 buf_init_item r2, 0, r0
1163 keep_alive r1
1164 a = r1
1165 r3 = CPyList_GetItemInt64Borrow(a, n)
1166 r4 = borrow cast(__main__.C, r3)
1167 r5 = r4.s
1168 keep_alive a, n, r3
1169 return r5
1170
1171 [case testBorrowOverI64ListGetItem2]
1172 from typing import List
1173 from mypy_extensions import i64
1174
1175 def f(a: List[i64], n: i64) -> bool:
1176 if a[n] == 0:
1177 return True
1178 return False
1179 [out]
1180 def f(a, n):
1181 a :: list
1182 n :: i64
1183 r0 :: object
1184 r1 :: i64
1185 r2 :: bit
1186 L0:
1187 r0 = CPyList_GetItemInt64Borrow(a, n)
1188 r1 = unbox(i64, r0)
1189 r2 = r1 == 0
1190 keep_alive a, n
1191 if r2 goto L1 else goto L2 :: bool
1192 L1:
1193 return 1
1194 L2:
1195 return 0
1196
1197 [case testCoerceShortIntToI64]
1198 from mypy_extensions import i64
1199 from typing import List
1200
1201 def f(a: List[i64], y: i64) -> bool:
1202 if len(a) < y:
1203 return True
1204 return False
1205
1206 def g(a: List[i64], y: i64) -> bool:
1207 if y < len(a):
1208 return True
1209 return False
1210 [out]
1211 def f(a, y):
1212 a :: list
1213 y :: i64
1214 r0 :: native_int
1215 r1 :: short_int
1216 r2 :: i64
1217 r3 :: bit
1218 L0:
1219 r0 = var_object_size a
1220 r1 = r0 << 1
1221 r2 = r1 >> 1
1222 r3 = r2 < y :: signed
1223 if r3 goto L1 else goto L2 :: bool
1224 L1:
1225 return 1
1226 L2:
1227 return 0
1228 def g(a, y):
1229 a :: list
1230 y :: i64
1231 r0 :: native_int
1232 r1 :: short_int
1233 r2 :: i64
1234 r3 :: bit
1235 L0:
1236 r0 = var_object_size a
1237 r1 = r0 << 1
1238 r2 = r1 >> 1
1239 r3 = y < r2 :: signed
1240 if r3 goto L1 else goto L2 :: bool
1241 L1:
1242 return 1
1243 L2:
1244 return 0
1245
1246 [case testMultiplyListByI64_64bit]
1247 from mypy_extensions import i64
1248 from typing import List
1249
1250 def f(n: i64) -> List[i64]:
1251 return [n] * n
1252 [out]
1253 def f(n):
1254 n :: i64
1255 r0 :: list
1256 r1 :: object
1257 r2 :: ptr
1258 r3, r4 :: bit
1259 r5, r6, r7 :: int
1260 r8 :: list
1261 L0:
1262 r0 = PyList_New(1)
1263 r1 = box(i64, n)
1264 r2 = list_items r0
1265 buf_init_item r2, 0, r1
1266 keep_alive r0
1267 r3 = n <= 4611686018427387903 :: signed
1268 if r3 goto L1 else goto L2 :: bool
1269 L1:
1270 r4 = n >= -4611686018427387904 :: signed
1271 if r4 goto L3 else goto L2 :: bool
1272 L2:
1273 r5 = CPyTagged_FromInt64(n)
1274 r6 = r5
1275 goto L4
1276 L3:
1277 r7 = n << 1
1278 r6 = r7
1279 L4:
1280 r8 = CPySequence_Multiply(r0, r6)
1281 return r8
1282
1283 [case testShortIntAndI64Op]
1284 from mypy_extensions import i64
1285 from typing import List
1286
1287 def add_i64(a: List[i64], n: i64) -> i64:
1288 return len(a) + n
1289 def add_i64_2(a: List[i64], n: i64) -> i64:
1290 return n + len(a)
1291 def eq_i64(a: List[i64], n: i64) -> bool:
1292 if len(a) == n:
1293 return True
1294 return False
1295 def lt_i64(a: List[i64], n: i64) -> bool:
1296 if n < len(a):
1297 return True
1298 return False
1299 [out]
1300 def add_i64(a, n):
1301 a :: list
1302 n :: i64
1303 r0 :: native_int
1304 r1 :: short_int
1305 r2, r3 :: i64
1306 L0:
1307 r0 = var_object_size a
1308 r1 = r0 << 1
1309 r2 = r1 >> 1
1310 r3 = r2 + n
1311 return r3
1312 def add_i64_2(a, n):
1313 a :: list
1314 n :: i64
1315 r0 :: native_int
1316 r1 :: short_int
1317 r2, r3 :: i64
1318 L0:
1319 r0 = var_object_size a
1320 r1 = r0 << 1
1321 r2 = r1 >> 1
1322 r3 = n + r2
1323 return r3
1324 def eq_i64(a, n):
1325 a :: list
1326 n :: i64
1327 r0 :: native_int
1328 r1 :: short_int
1329 r2 :: i64
1330 r3 :: bit
1331 L0:
1332 r0 = var_object_size a
1333 r1 = r0 << 1
1334 r2 = r1 >> 1
1335 r3 = r2 == n
1336 if r3 goto L1 else goto L2 :: bool
1337 L1:
1338 return 1
1339 L2:
1340 return 0
1341 def lt_i64(a, n):
1342 a :: list
1343 n :: i64
1344 r0 :: native_int
1345 r1 :: short_int
1346 r2 :: i64
1347 r3 :: bit
1348 L0:
1349 r0 = var_object_size a
1350 r1 = r0 << 1
1351 r2 = r1 >> 1
1352 r3 = n < r2 :: signed
1353 if r3 goto L1 else goto L2 :: bool
1354 L1:
1355 return 1
1356 L2:
1357 return 0
1358
1359 [case testOptionalI64_64bit]
1360 from typing import Optional
1361 from mypy_extensions import i64
1362
1363 def f(x: Optional[i64]) -> i64:
1364 if x is None:
1365 return 1
1366 return x
1367 [out]
1368 def f(x):
1369 x :: union[i64, None]
1370 r0 :: object
1371 r1 :: bit
1372 r2 :: i64
1373 L0:
1374 r0 = load_address _Py_NoneStruct
1375 r1 = x == r0
1376 if r1 goto L1 else goto L2 :: bool
1377 L1:
1378 return 1
1379 L2:
1380 r2 = unbox(i64, x)
1381 return r2
1382
1383 [case testI64DefaultValueSingle]
1384 from mypy_extensions import i64
1385
1386 def f(x: i64, y: i64 = 0) -> i64:
1387 return x + y
1388
1389 def g() -> i64:
1390 return f(7) + f(8, 9)
1391 [out]
1392 def f(x, y, __bitmap):
1393 x, y :: i64
1394 __bitmap, r0 :: u32
1395 r1 :: bit
1396 r2 :: i64
1397 L0:
1398 r0 = __bitmap & 1
1399 r1 = r0 == 0
1400 if r1 goto L1 else goto L2 :: bool
1401 L1:
1402 y = 0
1403 L2:
1404 r2 = x + y
1405 return r2
1406 def g():
1407 r0, r1, r2 :: i64
1408 L0:
1409 r0 = f(7, 0, 0)
1410 r1 = f(8, 9, 1)
1411 r2 = r0 + r1
1412 return r2
1413
1414 [case testI64DefaultValueWithMultipleArgs]
1415 from mypy_extensions import i64
1416
1417 def f(a: i64, b: i64 = 1, c: int = 2, d: i64 = 3) -> i64:
1418 return 0
1419
1420 def g() -> i64:
1421 return f(7) + f(8, 9) + f(1, 2, 3) + f(4, 5, 6, 7)
1422 [out]
1423 def f(a, b, c, d, __bitmap):
1424 a, b :: i64
1425 c :: int
1426 d :: i64
1427 __bitmap, r0 :: u32
1428 r1 :: bit
1429 r2 :: u32
1430 r3 :: bit
1431 L0:
1432 r0 = __bitmap & 1
1433 r1 = r0 == 0
1434 if r1 goto L1 else goto L2 :: bool
1435 L1:
1436 b = 1
1437 L2:
1438 if is_error(c) goto L3 else goto L4
1439 L3:
1440 c = 4
1441 L4:
1442 r2 = __bitmap & 2
1443 r3 = r2 == 0
1444 if r3 goto L5 else goto L6 :: bool
1445 L5:
1446 d = 3
1447 L6:
1448 return 0
1449 def g():
1450 r0 :: int
1451 r1 :: i64
1452 r2 :: int
1453 r3, r4, r5, r6, r7, r8 :: i64
1454 L0:
1455 r0 = <error> :: int
1456 r1 = f(7, 0, r0, 0, 0)
1457 r2 = <error> :: int
1458 r3 = f(8, 9, r2, 0, 1)
1459 r4 = r1 + r3
1460 r5 = f(1, 2, 6, 0, 1)
1461 r6 = r4 + r5
1462 r7 = f(4, 5, 12, 7, 3)
1463 r8 = r6 + r7
1464 return r8
1465
1466 [case testI64MethodDefaultValue]
1467 from mypy_extensions import i64
1468
1469 class C:
1470 def m(self, x: i64 = 5) -> None:
1471 pass
1472
1473 def f(c: C) -> None:
1474 c.m()
1475 c.m(6)
1476 [out]
1477 def C.m(self, x, __bitmap):
1478 self :: __main__.C
1479 x :: i64
1480 __bitmap, r0 :: u32
1481 r1 :: bit
1482 L0:
1483 r0 = __bitmap & 1
1484 r1 = r0 == 0
1485 if r1 goto L1 else goto L2 :: bool
1486 L1:
1487 x = 5
1488 L2:
1489 return 1
1490 def f(c):
1491 c :: __main__.C
1492 r0, r1 :: None
1493 L0:
1494 r0 = c.m(0, 0)
1495 r1 = c.m(6, 1)
1496 return 1
1497
1498 [case testI64ExplicitConversionFromNativeInt]
1499 from mypy_extensions import i64, i32, i16
1500
1501 def from_i16(x: i16) -> i64:
1502 return i64(x)
1503
1504 def from_i32(x: i32) -> i64:
1505 return i64(x)
1506
1507 def from_i64(x: i64) -> i64:
1508 return i64(x)
1509 [out]
1510 def from_i16(x):
1511 x :: i16
1512 r0 :: i64
1513 L0:
1514 r0 = extend signed x: i16 to i64
1515 return r0
1516 def from_i32(x):
1517 x :: i32
1518 r0 :: i64
1519 L0:
1520 r0 = extend signed x: i32 to i64
1521 return r0
1522 def from_i64(x):
1523 x :: i64
1524 L0:
1525 return x
1526
1527 [case testI64ExplicitConversionFromInt_64bit]
1528 from mypy_extensions import i64
1529
1530 def f(x: int) -> i64:
1531 return i64(x)
1532 [out]
1533 def f(x):
1534 x :: int
1535 r0 :: native_int
1536 r1 :: bit
1537 r2, r3 :: i64
1538 r4 :: ptr
1539 r5 :: c_ptr
1540 r6 :: i64
1541 L0:
1542 r0 = x & 1
1543 r1 = r0 == 0
1544 if r1 goto L1 else goto L2 :: bool
1545 L1:
1546 r2 = x >> 1
1547 r3 = r2
1548 goto L3
1549 L2:
1550 r4 = x ^ 1
1551 r5 = r4
1552 r6 = CPyLong_AsInt64(r5)
1553 r3 = r6
1554 keep_alive x
1555 L3:
1556 return r3
1557
1558 [case testI64ExplicitConversionToInt_64bit]
1559 from mypy_extensions import i64
1560
1561 def f(x: i64) -> int:
1562 return int(x)
1563 [out]
1564 def f(x):
1565 x :: i64
1566 r0, r1 :: bit
1567 r2, r3, r4 :: int
1568 L0:
1569 r0 = x <= 4611686018427387903 :: signed
1570 if r0 goto L1 else goto L2 :: bool
1571 L1:
1572 r1 = x >= -4611686018427387904 :: signed
1573 if r1 goto L3 else goto L2 :: bool
1574 L2:
1575 r2 = CPyTagged_FromInt64(x)
1576 r3 = r2
1577 goto L4
1578 L3:
1579 r4 = x << 1
1580 r3 = r4
1581 L4:
1582 return r3
1583
1584 [case testI64ExplicitConversionFromLiteral]
1585 from mypy_extensions import i64
1586
1587 def f() -> None:
1588 x = i64(0)
1589 y = i64(11)
1590 z = i64(-3)
1591 [out]
1592 def f():
1593 x, y, z :: i64
1594 L0:
1595 x = 0
1596 y = 11
1597 z = -3
1598 return 1
1599
1600 [case testI64ForLoopOverRange]
1601 from mypy_extensions import i64
1602
1603 def f() -> None:
1604 for x in range(i64(4)):
1605 y = x
1606 [out]
1607 def f():
1608 r0, x :: i64
1609 r1 :: bit
1610 y, r2 :: i64
1611 L0:
1612 r0 = 0
1613 x = r0
1614 L1:
1615 r1 = r0 < 4 :: signed
1616 if r1 goto L2 else goto L4 :: bool
1617 L2:
1618 x = r0
1619 y = x
1620 L3:
1621 r2 = r0 + 1
1622 r0 = r2
1623 goto L1
1624 L4:
1625 return 1
1626
1627 [case testI64ForLoopOverRange2]
1628 from mypy_extensions import i64
1629
1630 def f() -> None:
1631 for x in range(0, i64(4)):
1632 y = x
1633 [out]
1634 def f():
1635 r0, x :: i64
1636 r1 :: bit
1637 y, r2 :: i64
1638 L0:
1639 r0 = 0
1640 x = r0
1641 L1:
1642 r1 = r0 < 4 :: signed
1643 if r1 goto L2 else goto L4 :: bool
1644 L2:
1645 x = r0
1646 y = x
1647 L3:
1648 r2 = r0 + 1
1649 r0 = r2
1650 goto L1
1651 L4:
1652 return 1
1653
1654 [case testI64MethodDefaultValueOverride]
1655 from mypy_extensions import i64
1656
1657 class C:
1658 def f(self, x: i64 = 11) -> None: pass
1659 class D(C):
1660 def f(self, x: i64 = 12) -> None: pass
1661 [out]
1662 def C.f(self, x, __bitmap):
1663 self :: __main__.C
1664 x :: i64
1665 __bitmap, r0 :: u32
1666 r1 :: bit
1667 L0:
1668 r0 = __bitmap & 1
1669 r1 = r0 == 0
1670 if r1 goto L1 else goto L2 :: bool
1671 L1:
1672 x = 11
1673 L2:
1674 return 1
1675 def D.f(self, x, __bitmap):
1676 self :: __main__.D
1677 x :: i64
1678 __bitmap, r0 :: u32
1679 r1 :: bit
1680 L0:
1681 r0 = __bitmap & 1
1682 r1 = r0 == 0
1683 if r1 goto L1 else goto L2 :: bool
1684 L1:
1685 x = 12
1686 L2:
1687 return 1
1688
1689 [case testI64FinalConstants]
1690 from typing import Final
1691 from mypy_extensions import i64
1692
1693 A: Final = -1
1694 B: Final = -(1 + 3*2)
1695 C: Final = 0
1696 D: Final = A - B
1697 E: Final[i64] = 1 + 3
1698
1699 def f1() -> i64:
1700 return A
1701
1702 def f2() -> i64:
1703 return A + B
1704
1705 def f3() -> i64:
1706 return C
1707
1708 def f4() -> i64:
1709 return D
1710
1711 def f5() -> i64:
1712 return E
1713 [out]
1714 def f1():
1715 L0:
1716 return -1
1717 def f2():
1718 L0:
1719 return -8
1720 def f3():
1721 L0:
1722 return 0
1723 def f4():
1724 L0:
1725 return 6
1726 def f5():
1727 L0:
1728 return 4
1729
1730 [case testI64OperationsWithBools]
1731 from mypy_extensions import i64
1732
1733 # TODO: Other mixed operations
1734
1735 def add_bool_to_int(n: i64, b: bool) -> i64:
1736 return n + b
1737
1738 def compare_bool_to_i64(n: i64, b: bool) -> bool:
1739 if n == b:
1740 return b != n
1741 return True
1742 [out]
1743 def add_bool_to_int(n, b):
1744 n :: i64
1745 b :: bool
1746 r0, r1 :: i64
1747 L0:
1748 r0 = extend b: builtins.bool to i64
1749 r1 = n + r0
1750 return r1
1751 def compare_bool_to_i64(n, b):
1752 n :: i64
1753 b :: bool
1754 r0 :: i64
1755 r1 :: bit
1756 r2 :: i64
1757 r3 :: bit
1758 L0:
1759 r0 = extend b: builtins.bool to i64
1760 r1 = n == r0
1761 if r1 goto L1 else goto L2 :: bool
1762 L1:
1763 r2 = extend b: builtins.bool to i64
1764 r3 = r2 != n
1765 return r3
1766 L2:
1767 return 1
1768
1769 [case testI64Cast_64bit]
1770 from typing import cast
1771 from mypy_extensions import i64
1772
1773 def cast_object(o: object) -> i64:
1774 return cast(i64, o)
1775
1776 def cast_int(x: int) -> i64:
1777 return cast(i64, x)
1778 [out]
1779 def cast_object(o):
1780 o :: object
1781 r0 :: i64
1782 L0:
1783 r0 = unbox(i64, o)
1784 return r0
1785 def cast_int(x):
1786 x :: int
1787 r0 :: native_int
1788 r1 :: bit
1789 r2, r3 :: i64
1790 r4 :: ptr
1791 r5 :: c_ptr
1792 r6 :: i64
1793 L0:
1794 r0 = x & 1
1795 r1 = r0 == 0
1796 if r1 goto L1 else goto L2 :: bool
1797 L1:
1798 r2 = x >> 1
1799 r3 = r2
1800 goto L3
1801 L2:
1802 r4 = x ^ 1
1803 r5 = r4
1804 r6 = CPyLong_AsInt64(r5)
1805 r3 = r6
1806 keep_alive x
1807 L3:
1808 return r3
1809
1810 [case testI64Cast_32bit]
1811 from typing import cast
1812 from mypy_extensions import i64
1813
1814 def cast_int(x: int) -> i64:
1815 return cast(i64, x)
1816 [out]
1817 def cast_int(x):
1818 x :: int
1819 r0 :: native_int
1820 r1 :: bit
1821 r2, r3, r4 :: i64
1822 r5 :: ptr
1823 r6 :: c_ptr
1824 r7 :: i64
1825 L0:
1826 r0 = x & 1
1827 r1 = r0 == 0
1828 if r1 goto L1 else goto L2 :: bool
1829 L1:
1830 r2 = extend signed x: builtins.int to i64
1831 r3 = r2 >> 1
1832 r4 = r3
1833 goto L3
1834 L2:
1835 r5 = x ^ 1
1836 r6 = r5
1837 r7 = CPyLong_AsInt64(r6)
1838 r4 = r7
1839 keep_alive x
1840 L3:
1841 return r4
1842
1843 [case testI64ExplicitConversionFromVariousTypes_64bit]
1844 from mypy_extensions import i64
1845
1846 def bool_to_i64(b: bool) -> i64:
1847 return i64(b)
1848
1849 def str_to_i64(s: str) -> i64:
1850 return i64(s)
1851
1852 def str_to_i64_with_base(s: str) -> i64:
1853 return i64(s, 2)
1854
1855 class C:
1856 def __int__(self) -> i64:
1857 return 5
1858
1859 def instance_to_i64(c: C) -> i64:
1860 return i64(c)
1861
1862 def float_to_i64(x: float) -> i64:
1863 return i64(x)
1864 [out]
1865 def bool_to_i64(b):
1866 b :: bool
1867 r0 :: i64
1868 L0:
1869 r0 = extend b: builtins.bool to i64
1870 return r0
1871 def str_to_i64(s):
1872 s :: str
1873 r0 :: object
1874 r1 :: i64
1875 L0:
1876 r0 = CPyLong_FromStr(s)
1877 r1 = unbox(i64, r0)
1878 return r1
1879 def str_to_i64_with_base(s):
1880 s :: str
1881 r0 :: object
1882 r1 :: i64
1883 L0:
1884 r0 = CPyLong_FromStrWithBase(s, 4)
1885 r1 = unbox(i64, r0)
1886 return r1
1887 def C.__int__(self):
1888 self :: __main__.C
1889 L0:
1890 return 5
1891 def instance_to_i64(c):
1892 c :: __main__.C
1893 r0 :: i64
1894 L0:
1895 r0 = c.__int__()
1896 return r0
1897 def float_to_i64(x):
1898 x :: float
1899 r0 :: int
1900 r1 :: native_int
1901 r2 :: bit
1902 r3, r4 :: i64
1903 r5 :: ptr
1904 r6 :: c_ptr
1905 r7 :: i64
1906 L0:
1907 r0 = CPyTagged_FromFloat(x)
1908 r1 = r0 & 1
1909 r2 = r1 == 0
1910 if r2 goto L1 else goto L2 :: bool
1911 L1:
1912 r3 = r0 >> 1
1913 r4 = r3
1914 goto L3
1915 L2:
1916 r5 = r0 ^ 1
1917 r6 = r5
1918 r7 = CPyLong_AsInt64(r6)
1919 r4 = r7
1920 keep_alive r0
1921 L3:
1922 return r4
1923
1924 [case testI64ExplicitConversionFromFloat_32bit]
1925 from mypy_extensions import i64
1926
1927 def float_to_i64(x: float) -> i64:
1928 return i64(x)
1929 [out]
1930 def float_to_i64(x):
1931 x :: float
1932 r0 :: int
1933 r1 :: native_int
1934 r2 :: bit
1935 r3, r4, r5 :: i64
1936 r6 :: ptr
1937 r7 :: c_ptr
1938 r8 :: i64
1939 L0:
1940 r0 = CPyTagged_FromFloat(x)
1941 r1 = r0 & 1
1942 r2 = r1 == 0
1943 if r2 goto L1 else goto L2 :: bool
1944 L1:
1945 r3 = extend signed r0: builtins.int to i64
1946 r4 = r3 >> 1
1947 r5 = r4
1948 goto L3
1949 L2:
1950 r6 = r0 ^ 1
1951 r7 = r6
1952 r8 = CPyLong_AsInt64(r7)
1953 r5 = r8
1954 keep_alive r0
1955 L3:
1956 return r5
1957
1958 [case testI64ConvertToFloat_64bit]
1959 from mypy_extensions import i64
1960
1961 def i64_to_float(x: i64) -> float:
1962 return float(x)
1963 [out]
1964 def i64_to_float(x):
1965 x :: i64
1966 r0, r1 :: bit
1967 r2, r3, r4 :: int
1968 r5 :: float
1969 L0:
1970 r0 = x <= 4611686018427387903 :: signed
1971 if r0 goto L1 else goto L2 :: bool
1972 L1:
1973 r1 = x >= -4611686018427387904 :: signed
1974 if r1 goto L3 else goto L2 :: bool
1975 L2:
1976 r2 = CPyTagged_FromInt64(x)
1977 r3 = r2
1978 goto L4
1979 L3:
1980 r4 = x << 1
1981 r3 = r4
1982 L4:
1983 r5 = CPyFloat_FromTagged(r3)
1984 return r5
1985
1986 [case testI64ConvertToFloat_32bit]
1987 from mypy_extensions import i64
1988
1989 def i64_to_float(x: i64) -> float:
1990 return float(x)
1991 [out]
1992 def i64_to_float(x):
1993 x :: i64
1994 r0, r1 :: bit
1995 r2, r3 :: int
1996 r4 :: native_int
1997 r5 :: int
1998 r6 :: float
1999 L0:
2000 r0 = x <= 1073741823 :: signed
2001 if r0 goto L1 else goto L2 :: bool
2002 L1:
2003 r1 = x >= -1073741824 :: signed
2004 if r1 goto L3 else goto L2 :: bool
2005 L2:
2006 r2 = CPyTagged_FromInt64(x)
2007 r3 = r2
2008 goto L4
2009 L3:
2010 r4 = truncate x: i64 to native_int
2011 r5 = r4 << 1
2012 r3 = r5
2013 L4:
2014 r6 = CPyFloat_FromTagged(r3)
2015 return r6
2016
2017 [case testI64IsinstanceNarrowing]
2018 from typing import Union
2019 from mypy_extensions import i64
2020
2021 class C:
2022 a: i64
2023
2024 def narrow1(x: Union[C, i64]) -> i64:
2025 if isinstance(x, i64):
2026 return x
2027 return x.a
2028
2029 def narrow2(x: Union[C, i64]) -> i64:
2030 if isinstance(x, int):
2031 return x
2032 return x.a
2033 [out]
2034 def narrow1(x):
2035 x :: union[__main__.C, i64]
2036 r0 :: object
2037 r1 :: i32
2038 r2 :: bit
2039 r3 :: bool
2040 r4 :: i64
2041 r5 :: __main__.C
2042 r6 :: i64
2043 L0:
2044 r0 = load_address PyLong_Type
2045 r1 = PyObject_IsInstance(x, r0)
2046 r2 = r1 >= 0 :: signed
2047 r3 = truncate r1: i32 to builtins.bool
2048 if r3 goto L1 else goto L2 :: bool
2049 L1:
2050 r4 = unbox(i64, x)
2051 return r4
2052 L2:
2053 r5 = borrow cast(__main__.C, x)
2054 r6 = r5.a
2055 keep_alive x
2056 return r6
2057 def narrow2(x):
2058 x :: union[__main__.C, i64]
2059 r0 :: bit
2060 r1 :: i64
2061 r2 :: __main__.C
2062 r3 :: i64
2063 L0:
2064 r0 = PyLong_Check(x)
2065 if r0 goto L1 else goto L2 :: bool
2066 L1:
2067 r1 = unbox(i64, x)
2068 return r1
2069 L2:
2070 r2 = borrow cast(__main__.C, x)
2071 r3 = r2.a
2072 keep_alive x
2073 return r3
2074
2075 [case testI64ConvertBetweenTuples_64bit]
2076 from __future__ import annotations
2077 from mypy_extensions import i64
2078
2079 def f(t: tuple[int, i64, int]) -> None:
2080 tt: tuple[int, i64, i64] = t
2081
2082 def g(n: int) -> None:
2083 t: tuple[i64, i64] = (1, n)
2084 [out]
2085 def f(t):
2086 t :: tuple[int, i64, int]
2087 r0 :: int
2088 r1 :: i64
2089 r2 :: int
2090 r3 :: native_int
2091 r4 :: bit
2092 r5, r6 :: i64
2093 r7 :: ptr
2094 r8 :: c_ptr
2095 r9 :: i64
2096 r10, tt :: tuple[int, i64, i64]
2097 L0:
2098 r0 = t[0]
2099 r1 = t[1]
2100 r2 = t[2]
2101 r3 = r2 & 1
2102 r4 = r3 == 0
2103 if r4 goto L1 else goto L2 :: bool
2104 L1:
2105 r5 = r2 >> 1
2106 r6 = r5
2107 goto L3
2108 L2:
2109 r7 = r2 ^ 1
2110 r8 = r7
2111 r9 = CPyLong_AsInt64(r8)
2112 r6 = r9
2113 keep_alive r2
2114 L3:
2115 r10 = (r0, r1, r6)
2116 tt = r10
2117 return 1
2118 def g(n):
2119 n, r0 :: int
2120 r1 :: tuple[int, int]
2121 r2 :: int
2122 r3 :: native_int
2123 r4 :: bit
2124 r5, r6 :: i64
2125 r7 :: ptr
2126 r8 :: c_ptr
2127 r9 :: i64
2128 r10, t :: tuple[i64, i64]
2129 L0:
2130 r0 = n
2131 r1 = (2, r0)
2132 r2 = r1[1]
2133 r3 = r2 & 1
2134 r4 = r3 == 0
2135 if r4 goto L1 else goto L2 :: bool
2136 L1:
2137 r5 = r2 >> 1
2138 r6 = r5
2139 goto L3
2140 L2:
2141 r7 = r2 ^ 1
2142 r8 = r7
2143 r9 = CPyLong_AsInt64(r8)
2144 r6 = r9
2145 keep_alive r2
2146 L3:
2147 r10 = (1, r6)
2148 t = r10
2149 return 1