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 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
|
[case testDictGet]
from typing import Dict
def f(d: Dict[int, bool]) -> bool:
return d[0]
[out]
def f(d):
d :: dict
r0, r1 :: object
r2 :: bool
L0:
r0 = box(short_int, 0)
r1 = CPyDict_GetItem(d, r0)
r2 = unbox(bool, r1)
return r2
[case testDictSet]
from typing import Dict
def f(d: Dict[int, bool]) -> None:
d[0] = False
[out]
def f(d):
d :: dict
r0, r1 :: object
r2 :: int32
r3 :: bit
L0:
r0 = box(short_int, 0)
r1 = box(bool, 0)
r2 = CPyDict_SetItem(d, r0, r1)
r3 = r2 >= 0 :: signed
return 1
[case testNewEmptyDict]
from typing import Dict
def f() -> None:
d = {} # type: Dict[bool, int]
[out]
def f():
r0, d :: dict
L0:
r0 = PyDict_New()
d = r0
return 1
[case testNewDictWithValues]
def f(x: object) -> None:
d = {1: 2, '': x}
[out]
def f(x):
x :: object
r0 :: str
r1, r2 :: object
r3, d :: dict
L0:
r0 = load_global CPyStatic_unicode_1 :: static
r1 = box(short_int, 2)
r2 = box(short_int, 4)
r3 = CPyDict_Build(2, r1, r2, r0, x)
d = r3
return 1
[case testInDict]
from typing import Dict
def f(d: Dict[int, int]) -> bool:
if 4 in d:
return True
else:
return False
[out]
def f(d):
d :: dict
r0 :: object
r1 :: int32
r2 :: bit
r3 :: bool
L0:
r0 = box(short_int, 8)
r1 = PyDict_Contains(d, r0)
r2 = r1 >= 0 :: signed
r3 = truncate r1: int32 to builtins.bool
if r3 goto L1 else goto L2 :: bool
L1:
return 1
L2:
return 0
L3:
unreachable
[case testNotInDict]
from typing import Dict
def f(d: Dict[int, int]) -> bool:
if 4 not in d:
return True
else:
return False
[out]
def f(d):
d :: dict
r0 :: object
r1 :: int32
r2 :: bit
r3, r4 :: bool
L0:
r0 = box(short_int, 8)
r1 = PyDict_Contains(d, r0)
r2 = r1 >= 0 :: signed
r3 = truncate r1: int32 to builtins.bool
r4 = r3 ^ 1
if r4 goto L1 else goto L2 :: bool
L1:
return 1
L2:
return 0
L3:
unreachable
[case testDictUpdate]
from typing import Dict
def f(a: Dict[int, int], b: Dict[int, int]) -> None:
a.update(b)
[out]
def f(a, b):
a, b :: dict
r0 :: int32
r1 :: bit
L0:
r0 = CPyDict_Update(a, b)
r1 = r0 >= 0 :: signed
return 1
[case testDictKeyLvalue]
from typing import Dict
def increment(d: Dict[str, int]) -> Dict[str, int]:
for k in d:
d[k] += 1
return d
[out]
def increment(d):
d :: dict
r0 :: short_int
r1 :: native_int
r2 :: short_int
r3 :: object
r4 :: tuple[bool, int, object]
r5 :: int
r6 :: bool
r7 :: object
r8, k :: str
r9, r10, r11 :: object
r12 :: int32
r13, r14, r15 :: bit
L0:
r0 = 0
r1 = PyDict_Size(d)
r2 = r1 << 1
r3 = CPyDict_GetKeysIter(d)
L1:
r4 = CPyDict_NextKey(r3, r0)
r5 = r4[1]
r0 = r5
r6 = r4[0]
if r6 goto L2 else goto L4 :: bool
L2:
r7 = r4[2]
r8 = cast(str, r7)
k = r8
r9 = CPyDict_GetItem(d, k)
r10 = box(short_int, 2)
r11 = PyNumber_InPlaceAdd(r9, r10)
r12 = CPyDict_SetItem(d, k, r11)
r13 = r12 >= 0 :: signed
L3:
r14 = CPyDict_CheckSize(d, r2)
goto L1
L4:
r15 = CPy_NoErrOccured()
L5:
return d
[case testDictDisplay]
from typing import Dict
def f(x: str, y: Dict[str, int]) -> Dict[str, int]:
return {x: 2, **y, 'z': 3}
[out]
def f(x, y):
x :: str
y :: dict
r0 :: str
r1 :: object
r2 :: dict
r3 :: int32
r4 :: bit
r5 :: object
r6 :: int32
r7 :: bit
L0:
r0 = load_global CPyStatic_unicode_3 :: static ('z')
r1 = box(short_int, 4)
r2 = CPyDict_Build(1, x, r1)
r3 = CPyDict_UpdateInDisplay(r2, y)
r4 = r3 >= 0 :: signed
r5 = box(short_int, 6)
r6 = CPyDict_SetItem(r2, r0, r5)
r7 = r6 >= 0 :: signed
return r2
[case testDictIterationMethods]
from typing import Dict
def print_dict_methods(d1: Dict[int, int], d2: Dict[int, int]) -> None:
for v in d1.values():
if v in d2:
return
for k, v in d2.items():
d2[k] += v
[out]
def print_dict_methods(d1, d2):
d1, d2 :: dict
r0 :: short_int
r1 :: native_int
r2 :: short_int
r3 :: object
r4 :: tuple[bool, int, object]
r5 :: int
r6 :: bool
r7 :: object
r8, v :: int
r9 :: object
r10 :: int32
r11 :: bit
r12 :: bool
r13, r14 :: bit
r15 :: short_int
r16 :: native_int
r17 :: short_int
r18 :: object
r19 :: tuple[bool, int, object, object]
r20 :: int
r21 :: bool
r22, r23 :: object
r24, r25, k :: int
r26, r27, r28, r29, r30 :: object
r31 :: int32
r32, r33, r34 :: bit
L0:
r0 = 0
r1 = PyDict_Size(d1)
r2 = r1 << 1
r3 = CPyDict_GetValuesIter(d1)
L1:
r4 = CPyDict_NextValue(r3, r0)
r5 = r4[1]
r0 = r5
r6 = r4[0]
if r6 goto L2 else goto L6 :: bool
L2:
r7 = r4[2]
r8 = unbox(int, r7)
v = r8
r9 = box(int, v)
r10 = PyDict_Contains(d2, r9)
r11 = r10 >= 0 :: signed
r12 = truncate r10: int32 to builtins.bool
if r12 goto L3 else goto L4 :: bool
L3:
return 1
L4:
L5:
r13 = CPyDict_CheckSize(d1, r2)
goto L1
L6:
r14 = CPy_NoErrOccured()
L7:
r15 = 0
r16 = PyDict_Size(d2)
r17 = r16 << 1
r18 = CPyDict_GetItemsIter(d2)
L8:
r19 = CPyDict_NextItem(r18, r15)
r20 = r19[1]
r15 = r20
r21 = r19[0]
if r21 goto L9 else goto L11 :: bool
L9:
r22 = r19[2]
r23 = r19[3]
r24 = unbox(int, r22)
r25 = unbox(int, r23)
k = r24
v = r25
r26 = box(int, k)
r27 = CPyDict_GetItem(d2, r26)
r28 = box(int, v)
r29 = PyNumber_InPlaceAdd(r27, r28)
r30 = box(int, k)
r31 = CPyDict_SetItem(d2, r30, r29)
r32 = r31 >= 0 :: signed
L10:
r33 = CPyDict_CheckSize(d2, r17)
goto L8
L11:
r34 = CPy_NoErrOccured()
L12:
return 1
[case testDictLoadAddress]
def f() -> None:
x = dict
[out]
def f():
r0, x :: object
L0:
r0 = load_address PyDict_Type
x = r0
return 1
[case testDictClear]
from typing import Dict
def f(d: Dict[int, int]) -> None:
return d.clear()
[out]
def f(d):
d :: dict
r0 :: bit
L0:
r0 = CPyDict_Clear(d)
return 1
|