File: irbuild-generics.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 (123 lines) | stat: -rw-r--r-- 2,212 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
[case testGenericFunction]
from typing import TypeVar, List
T = TypeVar('T')
def f(x: T) -> T:
    return x
def g(x: List[T]) -> List[T]:
    return [x[0]]
def h(x: int, y: List[int]) -> None:
    x = f(x)
    y = g(y)
[out]
def f(x):
    x :: object
L0:
    return x
def g(x):
    x :: list
    r0 :: object
    r1 :: list
    r2, r3 :: ptr
L0:
    r0 = CPyList_GetItemShort(x, 0)
    r1 = PyList_New(1)
    r2 = get_element_ptr r1 ob_item :: PyListObject
    r3 = load_mem r2, r1 :: ptr*
    set_mem r3, r0, r1 :: builtins.object*
    return r1
def h(x, y):
    x :: int
    y :: list
    r0, r1 :: object
    r2 :: int
    r3 :: list
L0:
    r0 = box(int, x)
    r1 = f(r0)
    r2 = unbox(int, r1)
    x = r2
    r3 = g(y)
    y = r3
    return 1

[case testGenericAttrAndTypeApplication]
from typing import TypeVar, Generic
T = TypeVar('T')
class C(Generic[T]):
    x: T
def f() -> None:
    c = C[int]()
    c.x = 1
    2 + c.x
[out]
def f():
    r0, c :: __main__.C
    r1 :: object
    r2 :: bool
    r3 :: object
    r4, r5 :: int
L0:
    r0 = C()
    c = r0
    r1 = box(short_int, 2)
    c.x = r1; r2 = is_error
    r3 = c.x
    r4 = unbox(int, r3)
    r5 = CPyTagged_Add(4, r4)
    return 1

[case testGenericMethod]
from typing import TypeVar, Generic
T = TypeVar('T')
class C(Generic[T]):
    x: T
    def __init__(self, x: T) -> None:
        self.x = x
    def get(self) -> T:
        return self.x
    def set(self, y: T) -> None:
        self.x = y
def f(x: C[int]) -> None:
    y = x.get()
    x.set(y + 1)
    x = C(2)
[out]
def C.__init__(self, x):
    self :: __main__.C
    x :: object
    r0 :: bool
L0:
    self.x = x; r0 = is_error
    return 1
def C.get(self):
    self :: __main__.C
    r0 :: object
L0:
    r0 = self.x
    return r0
def C.set(self, y):
    self :: __main__.C
    y :: object
    r0 :: bool
L0:
    self.x = y; r0 = is_error
    return 1
def f(x):
    x :: __main__.C
    r0 :: object
    r1, y, r2 :: int
    r3 :: object
    r4 :: None
    r5 :: object
    r6 :: __main__.C
L0:
    r0 = x.get()
    r1 = unbox(int, r0)
    y = r1
    r2 = CPyTagged_Add(y, 2)
    r3 = box(int, r2)
    r4 = x.set(r3)
    r5 = box(short_int, 4)
    r6 = C(r5)
    x = r6
    return 1