| 1 |
[case testTrivialFunction] |
| 2 |
def f() -> int: |
| 3 |
return 1 |
| 4 |
[out] |
| 5 |
def f(): |
| 6 |
L0: |
| 7 |
return 2 |
| 8 |
[case testFunctionArgument] |
| 9 |
def f(x: int) -> int: |
| 10 |
return x |
| 11 |
[out] |
| 12 |
def f(x): |
| 13 |
x :: int |
| 14 |
L0: |
| 15 |
return x |
| 16 |
|
| 17 |
|
| 18 |
[case testExplicitNoneReturn] |
| 19 |
def f() -> None: |
| 20 |
return |
| 21 |
[out] |
| 22 |
def f(): |
| 23 |
L0: |
| 24 |
return 1 |
| 25 |
|
| 26 |
[case testExplicitNoneReturn2] |
| 27 |
def f() -> None: |
| 28 |
return None |
| 29 |
[out] |
| 30 |
def f(): |
| 31 |
L0: |
| 32 |
return 1 |
| 33 |
|
| 34 |
[case testAssignment] |
| 35 |
def f() -> int: |
| 36 |
x = 1 |
| 37 |
y = x |
| 38 |
return y |
| 39 |
[out] |
| 40 |
def f(): |
| 41 |
x, y :: int |
| 42 |
L0: |
| 43 |
x = 2 |
| 44 |
y = x |
| 45 |
return y |
| 46 |
|
| 47 |
[case testAssignmentTwice] |
| 48 |
def f(x: int) -> None: |
| 49 |
y = 1 |
| 50 |
y = x |
| 51 |
return |
| 52 |
[out] |
| 53 |
def f(x): |
| 54 |
x, y :: int |
| 55 |
L0: |
| 56 |
y = 2 |
| 57 |
y = x |
| 58 |
return 1 |
| 59 |
|
| 60 |
[case testIntArithmetic] |
| 61 |
def f(x: int, y: int) -> int: |
| 62 |
return x * (y + 1) |
| 63 |
[out] |
| 64 |
def f(x, y): |
| 65 |
x, y, r0, r1 :: int |
| 66 |
L0: |
| 67 |
r0 = CPyTagged_Add(y, 2) |
| 68 |
r1 = CPyTagged_Multiply(x, r0) |
| 69 |
return r1 |
| 70 |
|
| 71 |
[case testIf] |
| 72 |
def f(x: int, y: int) -> int: |
| 73 |
if x < y: |
| 74 |
x = 1 |
| 75 |
return x |
| 76 |
[out] |
| 77 |
def f(x, y): |
| 78 |
x, y :: int |
| 79 |
r0 :: bit |
| 80 |
L0: |
| 81 |
r0 = int_lt x, y |
| 82 |
if r0 goto L1 else goto L2 :: bool |
| 83 |
L1: |
| 84 |
x = 2 |
| 85 |
L2: |
| 86 |
return x |
| 87 |
|
| 88 |
[case testIfElse] |
| 89 |
def f(x: int, y: int) -> int: |
| 90 |
if x < y: |
| 91 |
x = 1 |
| 92 |
else: |
| 93 |
x = 2 |
| 94 |
return x |
| 95 |
[out] |
| 96 |
def f(x, y): |
| 97 |
x, y :: int |
| 98 |
r0 :: bit |
| 99 |
L0: |
| 100 |
r0 = int_lt x, y |
| 101 |
if r0 goto L1 else goto L2 :: bool |
| 102 |
L1: |
| 103 |
x = 2 |
| 104 |
goto L3 |
| 105 |
L2: |
| 106 |
x = 4 |
| 107 |
L3: |
| 108 |
return x |
| 109 |
|
| 110 |
[case testAnd1] |
| 111 |
def f(x: int, y: int) -> int: |
| 112 |
if x < y and x > y: |
| 113 |
x = 1 |
| 114 |
else: |
| 115 |
x = 2 |
| 116 |
return x |
| 117 |
[out] |
| 118 |
def f(x, y): |
| 119 |
x, y :: int |
| 120 |
r0, r1 :: bit |
| 121 |
L0: |
| 122 |
r0 = int_lt x, y |
| 123 |
if r0 goto L1 else goto L3 :: bool |
| 124 |
L1: |
| 125 |
r1 = int_gt x, y |
| 126 |
if r1 goto L2 else goto L3 :: bool |
| 127 |
L2: |
| 128 |
x = 2 |
| 129 |
goto L4 |
| 130 |
L3: |
| 131 |
x = 4 |
| 132 |
L4: |
| 133 |
return x |
| 134 |
|
| 135 |
[case testAnd2] |
| 136 |
def f(x: object, y: object) -> str: |
| 137 |
return str(x) or str(y) |
| 138 |
[out] |
| 139 |
def f(x, y): |
| 140 |
x, y :: object |
| 141 |
r0 :: str |
| 142 |
r1 :: bit |
| 143 |
r2, r3 :: str |
| 144 |
L0: |
| 145 |
r0 = PyObject_Str(x) |
| 146 |
r1 = CPyStr_IsTrue(r0) |
| 147 |
if r1 goto L1 else goto L2 :: bool |
| 148 |
L1: |
| 149 |
r2 = r0 |
| 150 |
goto L3 |
| 151 |
L2: |
| 152 |
r3 = PyObject_Str(y) |
| 153 |
r2 = r3 |
| 154 |
L3: |
| 155 |
return r2 |
| 156 |
|
| 157 |
[case testOr] |
| 158 |
def f(x: int, y: int) -> int: |
| 159 |
if x < y or x > y: |
| 160 |
x = 1 |
| 161 |
else: |
| 162 |
x = 2 |
| 163 |
return x |
| 164 |
[out] |
| 165 |
def f(x, y): |
| 166 |
x, y :: int |
| 167 |
r0, r1 :: bit |
| 168 |
L0: |
| 169 |
r0 = int_lt x, y |
| 170 |
if r0 goto L2 else goto L1 :: bool |
| 171 |
L1: |
| 172 |
r1 = int_gt x, y |
| 173 |
if r1 goto L2 else goto L3 :: bool |
| 174 |
L2: |
| 175 |
x = 2 |
| 176 |
goto L4 |
| 177 |
L3: |
| 178 |
x = 4 |
| 179 |
L4: |
| 180 |
return x |
| 181 |
|
| 182 |
[case testOr2] |
| 183 |
def f(x: object, y: object) -> str: |
| 184 |
return str(x) and str(y) |
| 185 |
[out] |
| 186 |
def f(x, y): |
| 187 |
x, y :: object |
| 188 |
r0 :: str |
| 189 |
r1 :: bit |
| 190 |
r2, r3 :: str |
| 191 |
L0: |
| 192 |
r0 = PyObject_Str(x) |
| 193 |
r1 = CPyStr_IsTrue(r0) |
| 194 |
if r1 goto L2 else goto L1 :: bool |
| 195 |
L1: |
| 196 |
r2 = r0 |
| 197 |
goto L3 |
| 198 |
L2: |
| 199 |
r3 = PyObject_Str(y) |
| 200 |
r2 = r3 |
| 201 |
L3: |
| 202 |
return r2 |
| 203 |
|
| 204 |
[case testSimpleNot] |
| 205 |
def f(x: int, y: int) -> int: |
| 206 |
if not (x < y): |
| 207 |
x = 1 |
| 208 |
return x |
| 209 |
[out] |
| 210 |
def f(x, y): |
| 211 |
x, y :: int |
| 212 |
r0 :: bit |
| 213 |
L0: |
| 214 |
r0 = int_lt x, y |
| 215 |
if r0 goto L2 else goto L1 :: bool |
| 216 |
L1: |
| 217 |
x = 2 |
| 218 |
L2: |
| 219 |
return x |
| 220 |
|
| 221 |
[case testNotAnd] |
| 222 |
def f(x: int, y: int) -> int: |
| 223 |
if not (x < y and x > y): |
| 224 |
x = 1 |
| 225 |
return x |
| 226 |
[out] |
| 227 |
def f(x, y): |
| 228 |
x, y :: int |
| 229 |
r0, r1 :: bit |
| 230 |
L0: |
| 231 |
r0 = int_lt x, y |
| 232 |
if r0 goto L1 else goto L2 :: bool |
| 233 |
L1: |
| 234 |
r1 = int_gt x, y |
| 235 |
if r1 goto L3 else goto L2 :: bool |
| 236 |
L2: |
| 237 |
x = 2 |
| 238 |
L3: |
| 239 |
return x |
| 240 |
|
| 241 |
[case testWhile] |
| 242 |
def f(x: int, y: int) -> int: |
| 243 |
while x > y: |
| 244 |
x = x - y |
| 245 |
return x |
| 246 |
[out] |
| 247 |
def f(x, y): |
| 248 |
x, y :: int |
| 249 |
r0 :: bit |
| 250 |
r1 :: int |
| 251 |
L0: |
| 252 |
L1: |
| 253 |
r0 = int_gt x, y |
| 254 |
if r0 goto L2 else goto L3 :: bool |
| 255 |
L2: |
| 256 |
r1 = CPyTagged_Subtract(x, y) |
| 257 |
x = r1 |
| 258 |
goto L1 |
| 259 |
L3: |
| 260 |
return x |
| 261 |
|
| 262 |
[case testWhile2] |
| 263 |
def f(x: int, y: int) -> int: |
| 264 |
x = 1 |
| 265 |
while x > y: |
| 266 |
x = x - y |
| 267 |
return x |
| 268 |
[out] |
| 269 |
def f(x, y): |
| 270 |
x, y :: int |
| 271 |
r0 :: bit |
| 272 |
r1 :: int |
| 273 |
L0: |
| 274 |
x = 2 |
| 275 |
L1: |
| 276 |
r0 = int_gt x, y |
| 277 |
if r0 goto L2 else goto L3 :: bool |
| 278 |
L2: |
| 279 |
r1 = CPyTagged_Subtract(x, y) |
| 280 |
x = r1 |
| 281 |
goto L1 |
| 282 |
L3: |
| 283 |
return x |
| 284 |
|
| 285 |
[case testImplicitNoneReturn] |
| 286 |
def f() -> None: |
| 287 |
pass |
| 288 |
[out] |
| 289 |
def f(): |
| 290 |
L0: |
| 291 |
return 1 |
| 292 |
|
| 293 |
[case testImplicitNoneReturn2] |
| 294 |
def f() -> None: |
| 295 |
x = 1 |
| 296 |
[out] |
| 297 |
def f(): |
| 298 |
x :: int |
| 299 |
L0: |
| 300 |
x = 2 |
| 301 |
return 1 |
| 302 |
|
| 303 |
[case testImplicitNoneReturnAndIf] |
| 304 |
def f(x: int, y: int) -> None: |
| 305 |
if x < y: |
| 306 |
x = 1 |
| 307 |
else: |
| 308 |
y = 2 |
| 309 |
[out] |
| 310 |
def f(x, y): |
| 311 |
x, y :: int |
| 312 |
r0 :: bit |
| 313 |
L0: |
| 314 |
r0 = int_lt x, y |
| 315 |
if r0 goto L1 else goto L2 :: bool |
| 316 |
L1: |
| 317 |
x = 2 |
| 318 |
goto L3 |
| 319 |
L2: |
| 320 |
y = 4 |
| 321 |
L3: |
| 322 |
return 1 |
| 323 |
|
| 324 |
[case testRecursion] |
| 325 |
def f(n: int) -> int: |
| 326 |
if n <= 1: |
| 327 |
return 1 |
| 328 |
else: |
| 329 |
return f(n - 1) + f(n - 2) |
| 330 |
[out] |
| 331 |
def f(n): |
| 332 |
n :: int |
| 333 |
r0 :: bit |
| 334 |
r1, r2, r3, r4, r5 :: int |
| 335 |
L0: |
| 336 |
r0 = int_le n, 2 |
| 337 |
if r0 goto L1 else goto L2 :: bool |
| 338 |
L1: |
| 339 |
return 2 |
| 340 |
L2: |
| 341 |
r1 = CPyTagged_Subtract(n, 2) |
| 342 |
r2 = f(r1) |
| 343 |
r3 = CPyTagged_Subtract(n, 4) |
| 344 |
r4 = f(r3) |
| 345 |
r5 = CPyTagged_Add(r2, r4) |
| 346 |
return r5 |
| 347 |
L3: |
| 348 |
unreachable |
| 349 |
|
| 350 |
[case testReportTypeCheckError] |
| 351 |
def f() -> None: |
| 352 |
return 1 # E: No return value expected |
| 353 |
|
| 354 |
[case testReportSemanticaAnalysisError1] |
| 355 |
def f(x: List[int]) -> None: pass # E: Name "List" is not defined \ |
| 356 |
# N: Did you forget to import it from "typing"? (Suggestion: "from typing import List") |
| 357 |
|
| 358 |
[case testReportSemanticaAnalysisError2] |
| 359 |
def f() -> None: |
| 360 |
x # E: Name "x" is not defined |
| 361 |
|
| 362 |
[case testElif] |
| 363 |
def f(n: int) -> int: |
| 364 |
if n < 0: |
| 365 |
x = 1 |
| 366 |
elif n == 0: |
| 367 |
x = 1 |
| 368 |
else: |
| 369 |
x = 2 |
| 370 |
return x |
| 371 |
[out] |
| 372 |
def f(n): |
| 373 |
n :: int |
| 374 |
r0 :: bit |
| 375 |
x :: int |
| 376 |
r1 :: bit |
| 377 |
L0: |
| 378 |
r0 = int_lt n, 0 |
| 379 |
if r0 goto L1 else goto L2 :: bool |
| 380 |
L1: |
| 381 |
x = 2 |
| 382 |
goto L6 |
| 383 |
L2: |
| 384 |
r1 = int_eq n, 0 |
| 385 |
if r1 goto L3 else goto L4 :: bool |
| 386 |
L3: |
| 387 |
x = 2 |
| 388 |
goto L5 |
| 389 |
L4: |
| 390 |
x = 4 |
| 391 |
L5: |
| 392 |
L6: |
| 393 |
return x |
| 394 |
|
| 395 |
[case testUnaryMinus] |
| 396 |
def f(n: int) -> int: |
| 397 |
return -n |
| 398 |
[out] |
| 399 |
def f(n): |
| 400 |
n, r0 :: int |
| 401 |
L0: |
| 402 |
r0 = CPyTagged_Negate(n) |
| 403 |
return r0 |
| 404 |
|
| 405 |
[case testConditionalExpr] |
| 406 |
def f(n: int) -> int: |
| 407 |
return 0 if n == 0 else 1 |
| 408 |
[out] |
| 409 |
def f(n): |
| 410 |
n :: int |
| 411 |
r0 :: bit |
| 412 |
r1 :: int |
| 413 |
L0: |
| 414 |
r0 = int_eq n, 0 |
| 415 |
if r0 goto L1 else goto L2 :: bool |
| 416 |
L1: |
| 417 |
r1 = 0 |
| 418 |
goto L3 |
| 419 |
L2: |
| 420 |
r1 = 2 |
| 421 |
L3: |
| 422 |
return r1 |
| 423 |
|
| 424 |
[case testOperatorAssignment] |
| 425 |
def f() -> int: |
| 426 |
x = 0 |
| 427 |
x += 1 |
| 428 |
return x |
| 429 |
[out] |
| 430 |
def f(): |
| 431 |
x, r0 :: int |
| 432 |
L0: |
| 433 |
x = 0 |
| 434 |
r0 = CPyTagged_Add(x, 2) |
| 435 |
x = r0 |
| 436 |
return x |
| 437 |
|
| 438 |
[case testTrue] |
| 439 |
def f() -> bool: |
| 440 |
return True |
| 441 |
[out] |
| 442 |
def f(): |
| 443 |
L0: |
| 444 |
return 1 |
| 445 |
|
| 446 |
[case testFalse] |
| 447 |
def f() -> bool: |
| 448 |
return False |
| 449 |
[out] |
| 450 |
def f(): |
| 451 |
L0: |
| 452 |
return 0 |
| 453 |
[case testBoolCond] |
| 454 |
def f(x: bool) -> bool: |
| 455 |
if x: |
| 456 |
return False |
| 457 |
else: |
| 458 |
return True |
| 459 |
[out] |
| 460 |
def f(x): |
| 461 |
x :: bool |
| 462 |
L0: |
| 463 |
if x goto L1 else goto L2 :: bool |
| 464 |
L1: |
| 465 |
return 0 |
| 466 |
L2: |
| 467 |
return 1 |
| 468 |
L3: |
| 469 |
unreachable |
| 470 |
|
| 471 |
[case testPycall] |
| 472 |
import testmodule |
| 473 |
|
| 474 |
def f(x: int) -> int: |
| 475 |
return testmodule.factorial(x) |
| 476 |
[file testmodule.py] |
| 477 |
def factorial(x: int) -> int: |
| 478 |
if x == 0: |
| 479 |
return 1 |
| 480 |
else: |
| 481 |
return x * factorial(x-1) |
| 482 |
[out] |
| 483 |
def f(x): |
| 484 |
x :: int |
| 485 |
r0 :: object |
| 486 |
r1 :: str |
| 487 |
r2, r3 :: object |
| 488 |
r4 :: object[1] |
| 489 |
r5 :: object_ptr |
| 490 |
r6 :: object |
| 491 |
r7 :: int |
| 492 |
L0: |
| 493 |
r0 = testmodule :: module |
| 494 |
r1 = 'factorial' |
| 495 |
r2 = CPyObject_GetAttr(r0, r1) |
| 496 |
r3 = box(int, x) |
| 497 |
r4 = [r3] |
| 498 |
r5 = load_address r4 |
| 499 |
r6 = PyObject_Vectorcall(r2, r5, 1, 0) |
| 500 |
keep_alive r3 |
| 501 |
r7 = unbox(int, r6) |
| 502 |
return r7 |
| 503 |
|
| 504 |
[case testImport_toplevel] |
| 505 |
import sys |
| 506 |
import enum as enum2 |
| 507 |
import collections.abc |
| 508 |
import collections.abc as abc2 |
| 509 |
_ = "filler" |
| 510 |
import single |
| 511 |
single.hello() |
| 512 |
|
| 513 |
[file single.py] |
| 514 |
def hello() -> None: |
| 515 |
print("hello, world") |
| 516 |
|
| 517 |
[out] |
| 518 |
def __top_level__(): |
| 519 |
r0, r1 :: object |
| 520 |
r2 :: bit |
| 521 |
r3 :: str |
| 522 |
r4 :: object |
| 523 |
r5, r6, r7, r8 :: object_ptr |
| 524 |
r9 :: object_ptr[4] |
| 525 |
r10 :: c_ptr |
| 526 |
r11 :: native_int[4] |
| 527 |
r12 :: c_ptr |
| 528 |
r13 :: object |
| 529 |
r14 :: dict |
| 530 |
r15, r16 :: str |
| 531 |
r17 :: bit |
| 532 |
r18 :: str |
| 533 |
r19 :: dict |
| 534 |
r20 :: str |
| 535 |
r21 :: i32 |
| 536 |
r22 :: bit |
| 537 |
r23 :: object_ptr |
| 538 |
r24 :: object_ptr[1] |
| 539 |
r25 :: c_ptr |
| 540 |
r26 :: native_int[1] |
| 541 |
r27 :: c_ptr |
| 542 |
r28 :: object |
| 543 |
r29 :: dict |
| 544 |
r30, r31 :: str |
| 545 |
r32 :: bit |
| 546 |
r33 :: object |
| 547 |
r34 :: str |
| 548 |
r35, r36 :: object |
| 549 |
L0: |
| 550 |
r0 = builtins :: module |
| 551 |
r1 = load_address _Py_NoneStruct |
| 552 |
r2 = r0 != r1 |
| 553 |
if r2 goto L2 else goto L1 :: bool |
| 554 |
L1: |
| 555 |
r3 = 'builtins' |
| 556 |
r4 = PyImport_Import(r3) |
| 557 |
builtins = r4 :: module |
| 558 |
L2: |
| 559 |
r5 = load_address sys :: module |
| 560 |
r6 = load_address enum :: module |
| 561 |
r7 = load_address collections.abc :: module |
| 562 |
r8 = load_address collections.abc :: module |
| 563 |
r9 = [r5, r6, r7, r8] |
| 564 |
r10 = load_address r9 |
| 565 |
r11 = [1, 2, 3, 4] |
| 566 |
r12 = load_address r11 |
| 567 |
r13 = (('sys', 'sys', 'sys'), ('enum', 'enum', 'enum2'), ('collections.abc', 'collections', 'collections'), ('collections.abc', 'collections.abc', 'abc2')) |
| 568 |
r14 = __main__.globals :: static |
| 569 |
r15 = 'main' |
| 570 |
r16 = '<module>' |
| 571 |
r17 = CPyImport_ImportMany(r13, r10, r14, r15, r16, r12) |
| 572 |
r18 = 'filler' |
| 573 |
r19 = __main__.globals :: static |
| 574 |
r20 = '_' |
| 575 |
r21 = CPyDict_SetItem(r19, r20, r18) |
| 576 |
r22 = r21 >= 0 :: signed |
| 577 |
r23 = load_address single :: module |
| 578 |
r24 = [r23] |
| 579 |
r25 = load_address r24 |
| 580 |
r26 = [6] |
| 581 |
r27 = load_address r26 |
| 582 |
r28 = (('single', 'single', 'single'),) |
| 583 |
r29 = __main__.globals :: static |
| 584 |
r30 = 'main' |
| 585 |
r31 = '<module>' |
| 586 |
r32 = CPyImport_ImportMany(r28, r25, r29, r30, r31, r27) |
| 587 |
r33 = single :: module |
| 588 |
r34 = 'hello' |
| 589 |
r35 = CPyObject_GetAttr(r33, r34) |
| 590 |
r36 = PyObject_Vectorcall(r35, 0, 0, 0) |
| 591 |
return 1 |
| 592 |
|
| 593 |
[case testFromImport_toplevel] |
| 594 |
from testmodule import g, h |
| 595 |
from testmodule import h as two |
| 596 |
|
| 597 |
def f(x: int) -> int: |
| 598 |
return g(x) + h() + two() |
| 599 |
[file testmodule.py] |
| 600 |
def g(x: int) -> int: |
| 601 |
return x + 1 |
| 602 |
def h() -> int: |
| 603 |
return 2 |
| 604 |
[out] |
| 605 |
def f(x): |
| 606 |
x :: int |
| 607 |
r0 :: dict |
| 608 |
r1 :: str |
| 609 |
r2, r3 :: object |
| 610 |
r4 :: object[1] |
| 611 |
r5 :: object_ptr |
| 612 |
r6 :: object |
| 613 |
r7 :: int |
| 614 |
r8 :: dict |
| 615 |
r9 :: str |
| 616 |
r10, r11 :: object |
| 617 |
r12, r13 :: int |
| 618 |
r14 :: dict |
| 619 |
r15 :: str |
| 620 |
r16, r17 :: object |
| 621 |
r18, r19 :: int |
| 622 |
L0: |
| 623 |
r0 = __main__.globals :: static |
| 624 |
r1 = 'g' |
| 625 |
r2 = CPyDict_GetItem(r0, r1) |
| 626 |
r3 = box(int, x) |
| 627 |
r4 = [r3] |
| 628 |
r5 = load_address r4 |
| 629 |
r6 = PyObject_Vectorcall(r2, r5, 1, 0) |
| 630 |
keep_alive r3 |
| 631 |
r7 = unbox(int, r6) |
| 632 |
r8 = __main__.globals :: static |
| 633 |
r9 = 'h' |
| 634 |
r10 = CPyDict_GetItem(r8, r9) |
| 635 |
r11 = PyObject_Vectorcall(r10, 0, 0, 0) |
| 636 |
r12 = unbox(int, r11) |
| 637 |
r13 = CPyTagged_Add(r7, r12) |
| 638 |
r14 = __main__.globals :: static |
| 639 |
r15 = 'two' |
| 640 |
r16 = CPyDict_GetItem(r14, r15) |
| 641 |
r17 = PyObject_Vectorcall(r16, 0, 0, 0) |
| 642 |
r18 = unbox(int, r17) |
| 643 |
r19 = CPyTagged_Add(r13, r18) |
| 644 |
return r19 |
| 645 |
def __top_level__(): |
| 646 |
r0, r1 :: object |
| 647 |
r2 :: bit |
| 648 |
r3 :: str |
| 649 |
r4, r5 :: object |
| 650 |
r6 :: str |
| 651 |
r7 :: dict |
| 652 |
r8, r9, r10 :: object |
| 653 |
r11 :: str |
| 654 |
r12 :: dict |
| 655 |
r13 :: object |
| 656 |
L0: |
| 657 |
r0 = builtins :: module |
| 658 |
r1 = load_address _Py_NoneStruct |
| 659 |
r2 = r0 != r1 |
| 660 |
if r2 goto L2 else goto L1 :: bool |
| 661 |
L1: |
| 662 |
r3 = 'builtins' |
| 663 |
r4 = PyImport_Import(r3) |
| 664 |
builtins = r4 :: module |
| 665 |
L2: |
| 666 |
r5 = ('g', 'h') |
| 667 |
r6 = 'testmodule' |
| 668 |
r7 = __main__.globals :: static |
| 669 |
r8 = CPyImport_ImportFromMany(r6, r5, r5, r7) |
| 670 |
testmodule = r8 :: module |
| 671 |
r9 = ('h',) |
| 672 |
r10 = ('two',) |
| 673 |
r11 = 'testmodule' |
| 674 |
r12 = __main__.globals :: static |
| 675 |
r13 = CPyImport_ImportFromMany(r11, r9, r10, r12) |
| 676 |
testmodule = r13 :: module |
| 677 |
return 1 |
| 678 |
|
| 679 |
[case testPrintFullname] |
| 680 |
import builtins |
| 681 |
def f(x: int) -> None: |
| 682 |
builtins.print(5) |
| 683 |
[out] |
| 684 |
def f(x): |
| 685 |
x :: int |
| 686 |
r0 :: object |
| 687 |
r1 :: str |
| 688 |
r2, r3 :: object |
| 689 |
r4 :: object[1] |
| 690 |
r5 :: object_ptr |
| 691 |
r6 :: object |
| 692 |
L0: |
| 693 |
r0 = builtins :: module |
| 694 |
r1 = 'print' |
| 695 |
r2 = CPyObject_GetAttr(r0, r1) |
| 696 |
r3 = object 5 |
| 697 |
r4 = [r3] |
| 698 |
r5 = load_address r4 |
| 699 |
r6 = PyObject_Vectorcall(r2, r5, 1, 0) |
| 700 |
keep_alive r3 |
| 701 |
return 1 |
| 702 |
|
| 703 |
[case testPrint] |
| 704 |
import builtins |
| 705 |
def f(x: int) -> None: |
| 706 |
print(5) |
| 707 |
[out] |
| 708 |
def f(x): |
| 709 |
x :: int |
| 710 |
r0 :: object |
| 711 |
r1 :: str |
| 712 |
r2, r3 :: object |
| 713 |
r4 :: object[1] |
| 714 |
r5 :: object_ptr |
| 715 |
r6 :: object |
| 716 |
L0: |
| 717 |
r0 = builtins :: module |
| 718 |
r1 = 'print' |
| 719 |
r2 = CPyObject_GetAttr(r0, r1) |
| 720 |
r3 = object 5 |
| 721 |
r4 = [r3] |
| 722 |
r5 = load_address r4 |
| 723 |
r6 = PyObject_Vectorcall(r2, r5, 1, 0) |
| 724 |
keep_alive r3 |
| 725 |
return 1 |
| 726 |
|
| 727 |
[case testUnicodeLiteral] |
| 728 |
def f() -> str: |
| 729 |
x = "some string" |
| 730 |
return "some other string" |
| 731 |
[out] |
| 732 |
def f(): |
| 733 |
r0, x, r1 :: str |
| 734 |
L0: |
| 735 |
r0 = 'some string' |
| 736 |
x = r0 |
| 737 |
r1 = 'some other string' |
| 738 |
return r1 |
| 739 |
|
| 740 |
[case testBytesLiteral] |
| 741 |
def f() -> bytes: |
| 742 |
x = b'\xf0' |
| 743 |
return b'1234' |
| 744 |
[out] |
| 745 |
def f(): |
| 746 |
r0, x, r1 :: bytes |
| 747 |
L0: |
| 748 |
r0 = b'\xf0' |
| 749 |
x = r0 |
| 750 |
r1 = b'1234' |
| 751 |
return r1 |
| 752 |
|
| 753 |
[case testPyMethodCall1_64bit] |
| 754 |
from typing import Any |
| 755 |
def f(x: Any) -> int: |
| 756 |
y: int = x.pop() |
| 757 |
return x.pop() |
| 758 |
[out] |
| 759 |
def f(x): |
| 760 |
x :: object |
| 761 |
r0 :: str |
| 762 |
r1 :: object[1] |
| 763 |
r2 :: object_ptr |
| 764 |
r3 :: object |
| 765 |
r4, y :: int |
| 766 |
r5 :: str |
| 767 |
r6 :: object[1] |
| 768 |
r7 :: object_ptr |
| 769 |
r8 :: object |
| 770 |
r9 :: int |
| 771 |
L0: |
| 772 |
r0 = 'pop' |
| 773 |
r1 = [x] |
| 774 |
r2 = load_address r1 |
| 775 |
r3 = PyObject_VectorcallMethod(r0, r2, 9223372036854775809, 0) |
| 776 |
keep_alive x |
| 777 |
r4 = unbox(int, r3) |
| 778 |
y = r4 |
| 779 |
r5 = 'pop' |
| 780 |
r6 = [x] |
| 781 |
r7 = load_address r6 |
| 782 |
r8 = PyObject_VectorcallMethod(r5, r7, 9223372036854775809, 0) |
| 783 |
keep_alive x |
| 784 |
r9 = unbox(int, r8) |
| 785 |
return r9 |
| 786 |
|
| 787 |
[case testObjectType] |
| 788 |
def g(y: object) -> None: |
| 789 |
g(y) |
| 790 |
g([1]) |
| 791 |
g(None) |
| 792 |
[out] |
| 793 |
def g(y): |
| 794 |
y :: object |
| 795 |
r0 :: None |
| 796 |
r1 :: list |
| 797 |
r2 :: object |
| 798 |
r3 :: ptr |
| 799 |
r4 :: None |
| 800 |
r5 :: object |
| 801 |
r6 :: None |
| 802 |
L0: |
| 803 |
r0 = g(y) |
| 804 |
r1 = PyList_New(1) |
| 805 |
r2 = object 1 |
| 806 |
r3 = list_items r1 |
| 807 |
buf_init_item r3, 0, r2 |
| 808 |
keep_alive r1 |
| 809 |
r4 = g(r1) |
| 810 |
r5 = box(None, 1) |
| 811 |
r6 = g(r5) |
| 812 |
return 1 |
| 813 |
|
| 814 |
[case testCoerceToObject1] |
| 815 |
def g(y: object) -> object: |
| 816 |
g(1) |
| 817 |
a = [y] |
| 818 |
a[0] = (1, 2) |
| 819 |
y = True |
| 820 |
return 3 |
| 821 |
[out] |
| 822 |
def g(y): |
| 823 |
y, r0, r1 :: object |
| 824 |
r2 :: list |
| 825 |
r3 :: ptr |
| 826 |
a :: list |
| 827 |
r4 :: tuple[int, int] |
| 828 |
r5 :: object |
| 829 |
r6 :: bit |
| 830 |
r7, r8 :: object |
| 831 |
L0: |
| 832 |
r0 = object 1 |
| 833 |
r1 = g(r0) |
| 834 |
r2 = PyList_New(1) |
| 835 |
r3 = list_items r2 |
| 836 |
buf_init_item r3, 0, y |
| 837 |
keep_alive r2 |
| 838 |
a = r2 |
| 839 |
r4 = (2, 4) |
| 840 |
r5 = box(tuple[int, int], r4) |
| 841 |
r6 = CPyList_SetItem(a, 0, r5) |
| 842 |
r7 = box(bool, 1) |
| 843 |
y = r7 |
| 844 |
r8 = object 3 |
| 845 |
return r8 |
| 846 |
|
| 847 |
[case testCoerceToObject2] |
| 848 |
class A: |
| 849 |
x: object |
| 850 |
n: int |
| 851 |
def f(a: A, o: object) -> None: |
| 852 |
a.x = 1 |
| 853 |
o = a.n |
| 854 |
[out] |
| 855 |
def f(a, o): |
| 856 |
a :: __main__.A |
| 857 |
o, r0 :: object |
| 858 |
r1 :: bool |
| 859 |
r2 :: int |
| 860 |
r3 :: object |
| 861 |
L0: |
| 862 |
r0 = object 1 |
| 863 |
a.x = r0; r1 = is_error |
| 864 |
r2 = a.n |
| 865 |
r3 = box(int, r2) |
| 866 |
o = r3 |
| 867 |
return 1 |
| 868 |
|
| 869 |
[case testAssertType] |
| 870 |
from typing import assert_type |
| 871 |
def f(x: int) -> None: |
| 872 |
y = assert_type(x, int) |
| 873 |
[out] |
| 874 |
def f(x): |
| 875 |
x, y :: int |
| 876 |
L0: |
| 877 |
y = x |
| 878 |
return 1 |
| 879 |
|
| 880 |
[case testDownCast] |
| 881 |
from typing import cast, List, Tuple |
| 882 |
class A: pass |
| 883 |
def f(x: object) -> None: |
| 884 |
n = cast(int, x) |
| 885 |
b = cast(bool, x) |
| 886 |
a = cast(A, x) |
| 887 |
l = cast(List[int], x) |
| 888 |
t = cast(Tuple[int, A], x) |
| 889 |
[out] |
| 890 |
def f(x): |
| 891 |
x :: object |
| 892 |
r0, n :: int |
| 893 |
r1, b :: bool |
| 894 |
r2, a :: __main__.A |
| 895 |
r3, l :: list |
| 896 |
r4, t :: tuple[int, __main__.A] |
| 897 |
L0: |
| 898 |
r0 = unbox(int, x) |
| 899 |
n = r0 |
| 900 |
r1 = unbox(bool, x) |
| 901 |
b = r1 |
| 902 |
r2 = cast(__main__.A, x) |
| 903 |
a = r2 |
| 904 |
r3 = cast(list, x) |
| 905 |
l = r3 |
| 906 |
r4 = unbox(tuple[int, __main__.A], x) |
| 907 |
t = r4 |
| 908 |
return 1 |
| 909 |
|
| 910 |
[case testDownCastSpecialCases] |
| 911 |
from typing import cast, Optional, Tuple |
| 912 |
class A: pass |
| 913 |
def f(o: Optional[A], n: int, t: Tuple[int, ...], tt: Tuple[int, int]) -> None: |
| 914 |
a = cast(A, o) |
| 915 |
m = cast(bool, n) |
| 916 |
t = tt |
| 917 |
[out] |
| 918 |
def f(o, n, t, tt): |
| 919 |
o :: union[__main__.A, None] |
| 920 |
n :: int |
| 921 |
t :: tuple |
| 922 |
tt :: tuple[int, int] |
| 923 |
r0, a :: __main__.A |
| 924 |
r1 :: object |
| 925 |
r2, m :: bool |
| 926 |
r3 :: object |
| 927 |
L0: |
| 928 |
r0 = cast(__main__.A, o) |
| 929 |
a = r0 |
| 930 |
r1 = box(int, n) |
| 931 |
r2 = unbox(bool, r1) |
| 932 |
m = r2 |
| 933 |
r3 = box(tuple[int, int], tt) |
| 934 |
t = r3 |
| 935 |
return 1 |
| 936 |
|
| 937 |
[case testSuccessfulCast] |
| 938 |
from typing import cast, Optional, Tuple, List, Dict |
| 939 |
class A: pass |
| 940 |
def f(o: object, |
| 941 |
p: Optional[A], |
| 942 |
n: int, |
| 943 |
b: bool, |
| 944 |
t: Tuple[int, ...], |
| 945 |
s: Tuple[int, int], |
| 946 |
a: A, |
| 947 |
l: List[A], |
| 948 |
d: Dict[int, str]) -> None: |
| 949 |
o = cast(object, o) |
| 950 |
p = cast(Optional[A], p) |
| 951 |
n = cast(int, n) |
| 952 |
b = cast(bool, b) |
| 953 |
t = cast(Tuple[int, ...], t) |
| 954 |
s = cast(Tuple[int, int], s) |
| 955 |
o = cast(object, n) |
| 956 |
a = cast(A, a) |
| 957 |
l2 = cast(List[object], l) |
| 958 |
d2 = cast(Dict[object, str], d) |
| 959 |
[out] |
| 960 |
def f(o, p, n, b, t, s, a, l, d): |
| 961 |
o :: object |
| 962 |
p :: union[__main__.A, None] |
| 963 |
n :: int |
| 964 |
b :: bool |
| 965 |
t :: tuple |
| 966 |
s :: tuple[int, int] |
| 967 |
a :: __main__.A |
| 968 |
l :: list |
| 969 |
d :: dict |
| 970 |
r0 :: object |
| 971 |
l2 :: list |
| 972 |
d2 :: dict |
| 973 |
L0: |
| 974 |
o = o |
| 975 |
p = p |
| 976 |
n = n |
| 977 |
b = b |
| 978 |
t = t |
| 979 |
s = s |
| 980 |
r0 = box(int, n) |
| 981 |
o = r0 |
| 982 |
a = a |
| 983 |
l2 = l |
| 984 |
d2 = d |
| 985 |
return 1 |
| 986 |
|
| 987 |
[case testGenericSetItem] |
| 988 |
from typing import Any |
| 989 |
def f(x: Any, y: Any, z: Any) -> None: |
| 990 |
x[y] = z |
| 991 |
[out] |
| 992 |
def f(x, y, z): |
| 993 |
x, y, z :: object |
| 994 |
r0 :: i32 |
| 995 |
r1 :: bit |
| 996 |
L0: |
| 997 |
r0 = PyObject_SetItem(x, y, z) |
| 998 |
r1 = r0 >= 0 :: signed |
| 999 |
return 1 |
| 1000 |
|
| 1001 |
[case testLoadFloatSum] |
| 1002 |
def assign_and_return_float_sum() -> float: |
| 1003 |
f1 = 1.0 |
| 1004 |
f2 = 2.0 |
| 1005 |
f3 = 3.0 |
| 1006 |
return f1 * f2 + f3 |
| 1007 |
[out] |
| 1008 |
def assign_and_return_float_sum(): |
| 1009 |
f1, f2, f3, r0, r1 :: float |
| 1010 |
L0: |
| 1011 |
f1 = 1.0 |
| 1012 |
f2 = 2.0 |
| 1013 |
f3 = 3.0 |
| 1014 |
r0 = f1 * f2 |
| 1015 |
r1 = r0 + f3 |
| 1016 |
return r1 |
| 1017 |
|
| 1018 |
[case testLoadComplex] |
| 1019 |
def load() -> complex: |
| 1020 |
real = 1 |
| 1021 |
return 5j+real |
| 1022 |
[out] |
| 1023 |
def load(): |
| 1024 |
real :: int |
| 1025 |
r0, r1, r2 :: object |
| 1026 |
L0: |
| 1027 |
real = 2 |
| 1028 |
r0 = 5j |
| 1029 |
r1 = box(int, real) |
| 1030 |
r2 = PyNumber_Add(r0, r1) |
| 1031 |
return r2 |
| 1032 |
|
| 1033 |
[case testBigIntLiteral_64bit] |
| 1034 |
def big_int() -> None: |
| 1035 |
a_62_bit = 4611686018427387902 |
| 1036 |
max_62_bit = 4611686018427387903 |
| 1037 |
b_63_bit = 4611686018427387904 |
| 1038 |
c_63_bit = 9223372036854775806 |
| 1039 |
max_63_bit = 9223372036854775807 |
| 1040 |
d_64_bit = 9223372036854775808 |
| 1041 |
max_32_bit = 2147483647 |
| 1042 |
max_31_bit = 1073741823 |
| 1043 |
[out] |
| 1044 |
def big_int(): |
| 1045 |
a_62_bit, max_62_bit, r0, b_63_bit, r1, c_63_bit, r2, max_63_bit, r3, d_64_bit, max_32_bit, max_31_bit :: int |
| 1046 |
L0: |
| 1047 |
a_62_bit = 9223372036854775804 |
| 1048 |
max_62_bit = 9223372036854775806 |
| 1049 |
r0 = object 4611686018427387904 |
| 1050 |
b_63_bit = r0 |
| 1051 |
r1 = object 9223372036854775806 |
| 1052 |
c_63_bit = r1 |
| 1053 |
r2 = object 9223372036854775807 |
| 1054 |
max_63_bit = r2 |
| 1055 |
r3 = object 9223372036854775808 |
| 1056 |
d_64_bit = r3 |
| 1057 |
max_32_bit = 4294967294 |
| 1058 |
max_31_bit = 2147483646 |
| 1059 |
return 1 |
| 1060 |
|
| 1061 |
[case testBigIntLiteral_32bit] |
| 1062 |
def big_int() -> None: |
| 1063 |
a_62_bit = 4611686018427387902 |
| 1064 |
max_62_bit = 4611686018427387903 |
| 1065 |
b_63_bit = 4611686018427387904 |
| 1066 |
c_63_bit = 9223372036854775806 |
| 1067 |
max_63_bit = 9223372036854775807 |
| 1068 |
d_64_bit = 9223372036854775808 |
| 1069 |
max_32_bit = 2147483647 |
| 1070 |
max_31_bit = 1073741823 |
| 1071 |
[out] |
| 1072 |
def big_int(): |
| 1073 |
r0, a_62_bit, r1, max_62_bit, r2, b_63_bit, r3, c_63_bit, r4, max_63_bit, r5, d_64_bit, r6, max_32_bit, max_31_bit :: int |
| 1074 |
L0: |
| 1075 |
r0 = object 4611686018427387902 |
| 1076 |
a_62_bit = r0 |
| 1077 |
r1 = object 4611686018427387903 |
| 1078 |
max_62_bit = r1 |
| 1079 |
r2 = object 4611686018427387904 |
| 1080 |
b_63_bit = r2 |
| 1081 |
r3 = object 9223372036854775806 |
| 1082 |
c_63_bit = r3 |
| 1083 |
r4 = object 9223372036854775807 |
| 1084 |
max_63_bit = r4 |
| 1085 |
r5 = object 9223372036854775808 |
| 1086 |
d_64_bit = r5 |
| 1087 |
r6 = object 2147483647 |
| 1088 |
max_32_bit = r6 |
| 1089 |
max_31_bit = 2147483646 |
| 1090 |
return 1 |
| 1091 |
|
| 1092 |
[case testCallableTypes] |
| 1093 |
from typing import Callable, Any |
| 1094 |
from m import f |
| 1095 |
|
| 1096 |
def absolute_value(x: int) -> int: |
| 1097 |
return x if x > 0 else -x |
| 1098 |
|
| 1099 |
def call_native_function(x: int) -> int: |
| 1100 |
return absolute_value(x) |
| 1101 |
|
| 1102 |
def call_python_function(x: int) -> int: |
| 1103 |
return f(x) |
| 1104 |
|
| 1105 |
def return_float() -> float: |
| 1106 |
return 5.0 |
| 1107 |
|
| 1108 |
def return_callable_type() -> Callable[[], float]: |
| 1109 |
return return_float |
| 1110 |
|
| 1111 |
def call_callable_type() -> float: |
| 1112 |
f = return_callable_type() |
| 1113 |
return f() |
| 1114 |
[file m.py] |
| 1115 |
def f(x: int) -> int: |
| 1116 |
return x |
| 1117 |
[out] |
| 1118 |
def absolute_value(x): |
| 1119 |
x :: int |
| 1120 |
r0 :: bit |
| 1121 |
r1, r2 :: int |
| 1122 |
L0: |
| 1123 |
r0 = int_gt x, 0 |
| 1124 |
if r0 goto L1 else goto L2 :: bool |
| 1125 |
L1: |
| 1126 |
r1 = x |
| 1127 |
goto L3 |
| 1128 |
L2: |
| 1129 |
r2 = CPyTagged_Negate(x) |
| 1130 |
r1 = r2 |
| 1131 |
L3: |
| 1132 |
return r1 |
| 1133 |
def call_native_function(x): |
| 1134 |
x, r0 :: int |
| 1135 |
L0: |
| 1136 |
r0 = absolute_value(x) |
| 1137 |
return r0 |
| 1138 |
def call_python_function(x): |
| 1139 |
x :: int |
| 1140 |
r0 :: dict |
| 1141 |
r1 :: str |
| 1142 |
r2, r3 :: object |
| 1143 |
r4 :: object[1] |
| 1144 |
r5 :: object_ptr |
| 1145 |
r6 :: object |
| 1146 |
r7 :: int |
| 1147 |
L0: |
| 1148 |
r0 = __main__.globals :: static |
| 1149 |
r1 = 'f' |
| 1150 |
r2 = CPyDict_GetItem(r0, r1) |
| 1151 |
r3 = box(int, x) |
| 1152 |
r4 = [r3] |
| 1153 |
r5 = load_address r4 |
| 1154 |
r6 = PyObject_Vectorcall(r2, r5, 1, 0) |
| 1155 |
keep_alive r3 |
| 1156 |
r7 = unbox(int, r6) |
| 1157 |
return r7 |
| 1158 |
def return_float(): |
| 1159 |
L0: |
| 1160 |
return 5.0 |
| 1161 |
def return_callable_type(): |
| 1162 |
r0 :: dict |
| 1163 |
r1 :: str |
| 1164 |
r2 :: object |
| 1165 |
L0: |
| 1166 |
r0 = __main__.globals :: static |
| 1167 |
r1 = 'return_float' |
| 1168 |
r2 = CPyDict_GetItem(r0, r1) |
| 1169 |
return r2 |
| 1170 |
def call_callable_type(): |
| 1171 |
r0, f, r1 :: object |
| 1172 |
r2 :: float |
| 1173 |
L0: |
| 1174 |
r0 = return_callable_type() |
| 1175 |
f = r0 |
| 1176 |
r1 = PyObject_Vectorcall(f, 0, 0, 0) |
| 1177 |
r2 = unbox(float, r1) |
| 1178 |
return r2 |
| 1179 |
|
| 1180 |
[case testCallableTypesWithKeywordArgs_64bit] |
| 1181 |
from typing import List |
| 1182 |
|
| 1183 |
def call_python_function_with_keyword_arg(x: str) -> int: |
| 1184 |
return int(x, base=2) |
| 1185 |
|
| 1186 |
def call_python_method_with_keyword_args(xs: List[int], first: int, second: int) -> List[int]: |
| 1187 |
xs.insert(0, x=first) |
| 1188 |
xs.insert(x=second, i=1) |
| 1189 |
return xs |
| 1190 |
|
| 1191 |
[out] |
| 1192 |
def call_python_function_with_keyword_arg(x): |
| 1193 |
x :: str |
| 1194 |
r0, r1 :: object |
| 1195 |
r2 :: object[2] |
| 1196 |
r3 :: object_ptr |
| 1197 |
r4, r5 :: object |
| 1198 |
r6 :: int |
| 1199 |
L0: |
| 1200 |
r0 = load_address PyLong_Type |
| 1201 |
r1 = object 2 |
| 1202 |
r2 = [x, r1] |
| 1203 |
r3 = load_address r2 |
| 1204 |
r4 = ('base',) |
| 1205 |
r5 = PyObject_Vectorcall(r0, r3, 1, r4) |
| 1206 |
keep_alive x, r1 |
| 1207 |
r6 = unbox(int, r5) |
| 1208 |
return r6 |
| 1209 |
def call_python_method_with_keyword_args(xs, first, second): |
| 1210 |
xs :: list |
| 1211 |
first, second :: int |
| 1212 |
r0 :: str |
| 1213 |
r1, r2 :: object |
| 1214 |
r3 :: object[3] |
| 1215 |
r4 :: object_ptr |
| 1216 |
r5, r6 :: object |
| 1217 |
r7 :: str |
| 1218 |
r8, r9 :: object |
| 1219 |
r10 :: object[3] |
| 1220 |
r11 :: object_ptr |
| 1221 |
r12, r13 :: object |
| 1222 |
L0: |
| 1223 |
r0 = 'insert' |
| 1224 |
r1 = object 0 |
| 1225 |
r2 = box(int, first) |
| 1226 |
r3 = [xs, r1, r2] |
| 1227 |
r4 = load_address r3 |
| 1228 |
r5 = ('x',) |
| 1229 |
r6 = PyObject_VectorcallMethod(r0, r4, 9223372036854775810, r5) |
| 1230 |
keep_alive xs, r1, r2 |
| 1231 |
r7 = 'insert' |
| 1232 |
r8 = box(int, second) |
| 1233 |
r9 = object 1 |
| 1234 |
r10 = [xs, r8, r9] |
| 1235 |
r11 = load_address r10 |
| 1236 |
r12 = ('x', 'i') |
| 1237 |
r13 = PyObject_VectorcallMethod(r7, r11, 9223372036854775809, r12) |
| 1238 |
keep_alive xs, r8, r9 |
| 1239 |
return xs |
| 1240 |
|
| 1241 |
[case testObjectAsBoolean] |
| 1242 |
from typing import List |
| 1243 |
|
| 1244 |
def obj(x: object) -> int: |
| 1245 |
if x: |
| 1246 |
return 1 |
| 1247 |
else: |
| 1248 |
return 0 |
| 1249 |
|
| 1250 |
def num(x: int) -> int: |
| 1251 |
if x: |
| 1252 |
return 1 |
| 1253 |
else: |
| 1254 |
return 0 |
| 1255 |
|
| 1256 |
def lst(x: List[int]) -> int: |
| 1257 |
if x: |
| 1258 |
return 1 |
| 1259 |
else: |
| 1260 |
return 0 |
| 1261 |
[out] |
| 1262 |
def obj(x): |
| 1263 |
x :: object |
| 1264 |
r0 :: i32 |
| 1265 |
r1 :: bit |
| 1266 |
r2 :: bool |
| 1267 |
L0: |
| 1268 |
r0 = PyObject_IsTrue(x) |
| 1269 |
r1 = r0 >= 0 :: signed |
| 1270 |
r2 = truncate r0: i32 to builtins.bool |
| 1271 |
if r2 goto L1 else goto L2 :: bool |
| 1272 |
L1: |
| 1273 |
return 2 |
| 1274 |
L2: |
| 1275 |
return 0 |
| 1276 |
L3: |
| 1277 |
unreachable |
| 1278 |
def num(x): |
| 1279 |
x :: int |
| 1280 |
r0 :: bit |
| 1281 |
L0: |
| 1282 |
r0 = x != 0 |
| 1283 |
if r0 goto L1 else goto L2 :: bool |
| 1284 |
L1: |
| 1285 |
return 2 |
| 1286 |
L2: |
| 1287 |
return 0 |
| 1288 |
L3: |
| 1289 |
unreachable |
| 1290 |
def lst(x): |
| 1291 |
x :: list |
| 1292 |
r0 :: native_int |
| 1293 |
r1 :: short_int |
| 1294 |
r2 :: bit |
| 1295 |
L0: |
| 1296 |
r0 = var_object_size x |
| 1297 |
r1 = r0 << 1 |
| 1298 |
r2 = int_ne r1, 0 |
| 1299 |
if r2 goto L1 else goto L2 :: bool |
| 1300 |
L1: |
| 1301 |
return 2 |
| 1302 |
L2: |
| 1303 |
return 0 |
| 1304 |
L3: |
| 1305 |
unreachable |
| 1306 |
|
| 1307 |
[case testOptionalAsBoolean] |
| 1308 |
from typing import Optional |
| 1309 |
|
| 1310 |
class A: pass |
| 1311 |
|
| 1312 |
def opt_int(x: Optional[int]) -> int: |
| 1313 |
if x: |
| 1314 |
return 1 |
| 1315 |
else: |
| 1316 |
return 0 |
| 1317 |
|
| 1318 |
def opt_a(x: Optional[A]) -> int: |
| 1319 |
if x: |
| 1320 |
return 1 |
| 1321 |
else: |
| 1322 |
return 0 |
| 1323 |
|
| 1324 |
def opt_o(x: Optional[object]) -> int: |
| 1325 |
if x: |
| 1326 |
return 1 |
| 1327 |
else: |
| 1328 |
return 0 |
| 1329 |
[out] |
| 1330 |
def opt_int(x): |
| 1331 |
x :: union[int, None] |
| 1332 |
r0 :: object |
| 1333 |
r1 :: bit |
| 1334 |
r2 :: int |
| 1335 |
r3 :: bit |
| 1336 |
L0: |
| 1337 |
r0 = load_address _Py_NoneStruct |
| 1338 |
r1 = x != r0 |
| 1339 |
if r1 goto L1 else goto L3 :: bool |
| 1340 |
L1: |
| 1341 |
r2 = unbox(int, x) |
| 1342 |
r3 = r2 != 0 |
| 1343 |
if r3 goto L2 else goto L3 :: bool |
| 1344 |
L2: |
| 1345 |
return 2 |
| 1346 |
L3: |
| 1347 |
return 0 |
| 1348 |
L4: |
| 1349 |
unreachable |
| 1350 |
def opt_a(x): |
| 1351 |
x :: union[__main__.A, None] |
| 1352 |
r0 :: object |
| 1353 |
r1 :: bit |
| 1354 |
L0: |
| 1355 |
r0 = load_address _Py_NoneStruct |
| 1356 |
r1 = x != r0 |
| 1357 |
if r1 goto L1 else goto L2 :: bool |
| 1358 |
L1: |
| 1359 |
return 2 |
| 1360 |
L2: |
| 1361 |
return 0 |
| 1362 |
L3: |
| 1363 |
unreachable |
| 1364 |
def opt_o(x): |
| 1365 |
x :: union[object, None] |
| 1366 |
r0 :: object |
| 1367 |
r1 :: bit |
| 1368 |
r2 :: object |
| 1369 |
r3 :: i32 |
| 1370 |
r4 :: bit |
| 1371 |
r5 :: bool |
| 1372 |
L0: |
| 1373 |
r0 = load_address _Py_NoneStruct |
| 1374 |
r1 = x != r0 |
| 1375 |
if r1 goto L1 else goto L3 :: bool |
| 1376 |
L1: |
| 1377 |
r2 = cast(object, x) |
| 1378 |
r3 = PyObject_IsTrue(r2) |
| 1379 |
r4 = r3 >= 0 :: signed |
| 1380 |
r5 = truncate r3: i32 to builtins.bool |
| 1381 |
if r5 goto L2 else goto L3 :: bool |
| 1382 |
L2: |
| 1383 |
return 2 |
| 1384 |
L3: |
| 1385 |
return 0 |
| 1386 |
L4: |
| 1387 |
unreachable |
| 1388 |
|
| 1389 |
[case testRaise] |
| 1390 |
def foo() -> None: |
| 1391 |
raise Exception() |
| 1392 |
|
| 1393 |
def bar() -> None: |
| 1394 |
raise Exception |
| 1395 |
[out] |
| 1396 |
def foo(): |
| 1397 |
r0 :: object |
| 1398 |
r1 :: str |
| 1399 |
r2, r3 :: object |
| 1400 |
L0: |
| 1401 |
r0 = builtins :: module |
| 1402 |
r1 = 'Exception' |
| 1403 |
r2 = CPyObject_GetAttr(r0, r1) |
| 1404 |
r3 = PyObject_Vectorcall(r2, 0, 0, 0) |
| 1405 |
CPy_Raise(r3) |
| 1406 |
unreachable |
| 1407 |
def bar(): |
| 1408 |
r0 :: object |
| 1409 |
r1 :: str |
| 1410 |
r2 :: object |
| 1411 |
L0: |
| 1412 |
r0 = builtins :: module |
| 1413 |
r1 = 'Exception' |
| 1414 |
r2 = CPyObject_GetAttr(r0, r1) |
| 1415 |
CPy_Raise(r2) |
| 1416 |
unreachable |
| 1417 |
|
| 1418 |
[case testModuleTopLevel_toplevel] |
| 1419 |
x = 1 |
| 1420 |
print(x) |
| 1421 |
|
| 1422 |
def f() -> None: |
| 1423 |
print(x) |
| 1424 |
[out] |
| 1425 |
def f(): |
| 1426 |
r0 :: dict |
| 1427 |
r1 :: str |
| 1428 |
r2 :: object |
| 1429 |
r3 :: int |
| 1430 |
r4 :: object |
| 1431 |
r5 :: str |
| 1432 |
r6, r7 :: object |
| 1433 |
r8 :: object[1] |
| 1434 |
r9 :: object_ptr |
| 1435 |
r10 :: object |
| 1436 |
L0: |
| 1437 |
r0 = __main__.globals :: static |
| 1438 |
r1 = 'x' |
| 1439 |
r2 = CPyDict_GetItem(r0, r1) |
| 1440 |
r3 = unbox(int, r2) |
| 1441 |
r4 = builtins :: module |
| 1442 |
r5 = 'print' |
| 1443 |
r6 = CPyObject_GetAttr(r4, r5) |
| 1444 |
r7 = box(int, r3) |
| 1445 |
r8 = [r7] |
| 1446 |
r9 = load_address r8 |
| 1447 |
r10 = PyObject_Vectorcall(r6, r9, 1, 0) |
| 1448 |
keep_alive r7 |
| 1449 |
return 1 |
| 1450 |
def __top_level__(): |
| 1451 |
r0, r1 :: object |
| 1452 |
r2 :: bit |
| 1453 |
r3 :: str |
| 1454 |
r4 :: object |
| 1455 |
r5 :: dict |
| 1456 |
r6 :: str |
| 1457 |
r7 :: object |
| 1458 |
r8 :: i32 |
| 1459 |
r9 :: bit |
| 1460 |
r10 :: dict |
| 1461 |
r11 :: str |
| 1462 |
r12 :: object |
| 1463 |
r13 :: int |
| 1464 |
r14 :: object |
| 1465 |
r15 :: str |
| 1466 |
r16, r17 :: object |
| 1467 |
r18 :: object[1] |
| 1468 |
r19 :: object_ptr |
| 1469 |
r20 :: object |
| 1470 |
L0: |
| 1471 |
r0 = builtins :: module |
| 1472 |
r1 = load_address _Py_NoneStruct |
| 1473 |
r2 = r0 != r1 |
| 1474 |
if r2 goto L2 else goto L1 :: bool |
| 1475 |
L1: |
| 1476 |
r3 = 'builtins' |
| 1477 |
r4 = PyImport_Import(r3) |
| 1478 |
builtins = r4 :: module |
| 1479 |
L2: |
| 1480 |
r5 = __main__.globals :: static |
| 1481 |
r6 = 'x' |
| 1482 |
r7 = object 1 |
| 1483 |
r8 = CPyDict_SetItem(r5, r6, r7) |
| 1484 |
r9 = r8 >= 0 :: signed |
| 1485 |
r10 = __main__.globals :: static |
| 1486 |
r11 = 'x' |
| 1487 |
r12 = CPyDict_GetItem(r10, r11) |
| 1488 |
r13 = unbox(int, r12) |
| 1489 |
r14 = builtins :: module |
| 1490 |
r15 = 'print' |
| 1491 |
r16 = CPyObject_GetAttr(r14, r15) |
| 1492 |
r17 = box(int, r13) |
| 1493 |
r18 = [r17] |
| 1494 |
r19 = load_address r18 |
| 1495 |
r20 = PyObject_Vectorcall(r16, r19, 1, 0) |
| 1496 |
keep_alive r17 |
| 1497 |
return 1 |
| 1498 |
|
| 1499 |
[case testCallOverloaded] |
| 1500 |
import m |
| 1501 |
def f() -> str: |
| 1502 |
return m.f(1) |
| 1503 |
[file m.pyi] |
| 1504 |
from typing import overload |
| 1505 |
@overload |
| 1506 |
def f(x: int) -> str: ... |
| 1507 |
@overload |
| 1508 |
def f(x: str) -> int: ... |
| 1509 |
[out] |
| 1510 |
def f(): |
| 1511 |
r0 :: object |
| 1512 |
r1 :: str |
| 1513 |
r2, r3 :: object |
| 1514 |
r4 :: object[1] |
| 1515 |
r5 :: object_ptr |
| 1516 |
r6 :: object |
| 1517 |
r7 :: str |
| 1518 |
L0: |
| 1519 |
r0 = m :: module |
| 1520 |
r1 = 'f' |
| 1521 |
r2 = CPyObject_GetAttr(r0, r1) |
| 1522 |
r3 = object 1 |
| 1523 |
r4 = [r3] |
| 1524 |
r5 = load_address r4 |
| 1525 |
r6 = PyObject_Vectorcall(r2, r5, 1, 0) |
| 1526 |
keep_alive r3 |
| 1527 |
r7 = cast(str, r6) |
| 1528 |
return r7 |
| 1529 |
|
| 1530 |
[case testCallOverloadedNative] |
| 1531 |
from typing import overload, Union |
| 1532 |
|
| 1533 |
@overload |
| 1534 |
def foo(x: int) -> int: ... |
| 1535 |
|
| 1536 |
@overload |
| 1537 |
def foo(x: str) -> str: ... |
| 1538 |
|
| 1539 |
def foo(x: Union[int, str]) -> Union[int, str]: |
| 1540 |
return x |
| 1541 |
|
| 1542 |
def main() -> None: |
| 1543 |
x = foo(0) |
| 1544 |
[out] |
| 1545 |
def foo(x): |
| 1546 |
x :: union[int, str] |
| 1547 |
L0: |
| 1548 |
return x |
| 1549 |
def main(): |
| 1550 |
r0 :: object |
| 1551 |
r1 :: union[int, str] |
| 1552 |
r2, x :: int |
| 1553 |
L0: |
| 1554 |
r0 = object 0 |
| 1555 |
r1 = foo(r0) |
| 1556 |
r2 = unbox(int, r1) |
| 1557 |
x = r2 |
| 1558 |
return 1 |
| 1559 |
|
| 1560 |
[case testCallOverloadedNativeSubclass] |
| 1561 |
from typing import overload, Union |
| 1562 |
|
| 1563 |
class A: |
| 1564 |
x: int |
| 1565 |
class B(A): |
| 1566 |
y: int |
| 1567 |
|
| 1568 |
@overload |
| 1569 |
def foo(x: int) -> B: ... |
| 1570 |
|
| 1571 |
@overload |
| 1572 |
def foo(x: Union[int, str]) -> A: ... |
| 1573 |
|
| 1574 |
def foo(x: Union[int, str]) -> A: |
| 1575 |
if isinstance(x, int): |
| 1576 |
return B() |
| 1577 |
return A() |
| 1578 |
|
| 1579 |
def main() -> None: |
| 1580 |
x = foo(0) |
| 1581 |
[out] |
| 1582 |
def foo(x): |
| 1583 |
x :: union[int, str] |
| 1584 |
r0 :: bit |
| 1585 |
r1 :: __main__.B |
| 1586 |
r2 :: __main__.A |
| 1587 |
L0: |
| 1588 |
r0 = PyLong_Check(x) |
| 1589 |
if r0 goto L1 else goto L2 :: bool |
| 1590 |
L1: |
| 1591 |
r1 = B() |
| 1592 |
return r1 |
| 1593 |
L2: |
| 1594 |
r2 = A() |
| 1595 |
return r2 |
| 1596 |
def main(): |
| 1597 |
r0 :: object |
| 1598 |
r1 :: __main__.A |
| 1599 |
r2, x :: __main__.B |
| 1600 |
L0: |
| 1601 |
r0 = object 0 |
| 1602 |
r1 = foo(r0) |
| 1603 |
r2 = cast(__main__.B, r1) |
| 1604 |
x = r2 |
| 1605 |
return 1 |
| 1606 |
|
| 1607 |
[case testFunctionCallWithKeywordArgs] |
| 1608 |
def f(x: int, y: str) -> None: pass |
| 1609 |
|
| 1610 |
def g() -> None: |
| 1611 |
f(y='a', x=0) |
| 1612 |
f(1, y='b') |
| 1613 |
[out] |
| 1614 |
def f(x, y): |
| 1615 |
x :: int |
| 1616 |
y :: str |
| 1617 |
L0: |
| 1618 |
return 1 |
| 1619 |
def g(): |
| 1620 |
r0 :: str |
| 1621 |
r1 :: None |
| 1622 |
r2 :: str |
| 1623 |
r3 :: None |
| 1624 |
L0: |
| 1625 |
r0 = 'a' |
| 1626 |
r1 = f(0, r0) |
| 1627 |
r2 = 'b' |
| 1628 |
r3 = f(2, r2) |
| 1629 |
return 1 |
| 1630 |
|
| 1631 |
[case testMethodCallWithKeywordArgs] |
| 1632 |
class A: |
| 1633 |
def f(self, x: int, y: str) -> None: pass |
| 1634 |
|
| 1635 |
def g(a: A) -> None: |
| 1636 |
a.f(y='a', x=0) |
| 1637 |
a.f(1, y='b') |
| 1638 |
[out] |
| 1639 |
def A.f(self, x, y): |
| 1640 |
self :: __main__.A |
| 1641 |
x :: int |
| 1642 |
y :: str |
| 1643 |
L0: |
| 1644 |
return 1 |
| 1645 |
def g(a): |
| 1646 |
a :: __main__.A |
| 1647 |
r0 :: str |
| 1648 |
r1 :: None |
| 1649 |
r2 :: str |
| 1650 |
r3 :: None |
| 1651 |
L0: |
| 1652 |
r0 = 'a' |
| 1653 |
r1 = a.f(0, r0) |
| 1654 |
r2 = 'b' |
| 1655 |
r3 = a.f(2, r2) |
| 1656 |
return 1 |
| 1657 |
|
| 1658 |
[case testStarArgs] |
| 1659 |
from typing import Tuple |
| 1660 |
def f(a: int, b: int, c: int) -> Tuple[int, int, int]: |
| 1661 |
return a, b, c |
| 1662 |
def g() -> Tuple[int, int, int]: |
| 1663 |
return f(*(1, 2, 3)) |
| 1664 |
def h() -> Tuple[int, int, int]: |
| 1665 |
return f(1, *(2, 3)) |
| 1666 |
[out] |
| 1667 |
def f(a, b, c): |
| 1668 |
a, b, c, r0, r1, r2 :: int |
| 1669 |
r3 :: tuple[int, int, int] |
| 1670 |
L0: |
| 1671 |
r0 = a |
| 1672 |
r1 = b |
| 1673 |
r2 = c |
| 1674 |
r3 = (r0, r1, r2) |
| 1675 |
return r3 |
| 1676 |
def g(): |
| 1677 |
r0 :: tuple[int, int, int] |
| 1678 |
r1 :: dict |
| 1679 |
r2 :: str |
| 1680 |
r3, r4, r5 :: object |
| 1681 |
r6 :: tuple[int, int, int] |
| 1682 |
L0: |
| 1683 |
r0 = (2, 4, 6) |
| 1684 |
r1 = __main__.globals :: static |
| 1685 |
r2 = 'f' |
| 1686 |
r3 = CPyDict_GetItem(r1, r2) |
| 1687 |
r4 = box(tuple[int, int, int], r0) |
| 1688 |
r5 = PyObject_CallObject(r3, r4) |
| 1689 |
r6 = unbox(tuple[int, int, int], r5) |
| 1690 |
return r6 |
| 1691 |
def h(): |
| 1692 |
r0 :: tuple[int, int] |
| 1693 |
r1 :: dict |
| 1694 |
r2 :: str |
| 1695 |
r3 :: object |
| 1696 |
r4 :: list |
| 1697 |
r5 :: object |
| 1698 |
r6 :: ptr |
| 1699 |
r7, r8 :: object |
| 1700 |
r9 :: tuple |
| 1701 |
r10 :: object |
| 1702 |
r11 :: tuple[int, int, int] |
| 1703 |
L0: |
| 1704 |
r0 = (4, 6) |
| 1705 |
r1 = __main__.globals :: static |
| 1706 |
r2 = 'f' |
| 1707 |
r3 = CPyDict_GetItem(r1, r2) |
| 1708 |
r4 = PyList_New(1) |
| 1709 |
r5 = object 1 |
| 1710 |
r6 = list_items r4 |
| 1711 |
buf_init_item r6, 0, r5 |
| 1712 |
keep_alive r4 |
| 1713 |
r7 = box(tuple[int, int], r0) |
| 1714 |
r8 = CPyList_Extend(r4, r7) |
| 1715 |
r9 = PyList_AsTuple(r4) |
| 1716 |
r10 = PyObject_CallObject(r3, r9) |
| 1717 |
r11 = unbox(tuple[int, int, int], r10) |
| 1718 |
return r11 |
| 1719 |
|
| 1720 |
[case testStar2Args] |
| 1721 |
from typing import Tuple |
| 1722 |
def f(a: int, b: int, c: int) -> Tuple[int, int, int]: |
| 1723 |
return a, b, c |
| 1724 |
def g() -> Tuple[int, int, int]: |
| 1725 |
return f(**{'a': 1, 'b': 2, 'c': 3}) |
| 1726 |
def h() -> Tuple[int, int, int]: |
| 1727 |
return f(1, **{'b': 2, 'c': 3}) |
| 1728 |
[out] |
| 1729 |
def f(a, b, c): |
| 1730 |
a, b, c, r0, r1, r2 :: int |
| 1731 |
r3 :: tuple[int, int, int] |
| 1732 |
L0: |
| 1733 |
r0 = a |
| 1734 |
r1 = b |
| 1735 |
r2 = c |
| 1736 |
r3 = (r0, r1, r2) |
| 1737 |
return r3 |
| 1738 |
def g(): |
| 1739 |
r0, r1, r2 :: str |
| 1740 |
r3, r4, r5 :: object |
| 1741 |
r6, r7 :: dict |
| 1742 |
r8 :: str |
| 1743 |
r9 :: object |
| 1744 |
r10 :: tuple |
| 1745 |
r11 :: dict |
| 1746 |
r12 :: object |
| 1747 |
r13 :: tuple[int, int, int] |
| 1748 |
L0: |
| 1749 |
r0 = 'a' |
| 1750 |
r1 = 'b' |
| 1751 |
r2 = 'c' |
| 1752 |
r3 = object 1 |
| 1753 |
r4 = object 2 |
| 1754 |
r5 = object 3 |
| 1755 |
r6 = CPyDict_Build(3, r0, r3, r1, r4, r2, r5) |
| 1756 |
r7 = __main__.globals :: static |
| 1757 |
r8 = 'f' |
| 1758 |
r9 = CPyDict_GetItem(r7, r8) |
| 1759 |
r10 = CPyTuple_LoadEmptyTupleConstant() |
| 1760 |
r11 = PyDict_Copy(r6) |
| 1761 |
r12 = PyObject_Call(r9, r10, r11) |
| 1762 |
r13 = unbox(tuple[int, int, int], r12) |
| 1763 |
return r13 |
| 1764 |
def h(): |
| 1765 |
r0, r1 :: str |
| 1766 |
r2, r3 :: object |
| 1767 |
r4, r5 :: dict |
| 1768 |
r6 :: str |
| 1769 |
r7 :: object |
| 1770 |
r8 :: dict |
| 1771 |
r9 :: i32 |
| 1772 |
r10 :: bit |
| 1773 |
r11 :: object |
| 1774 |
r12 :: tuple |
| 1775 |
r13 :: object |
| 1776 |
r14 :: tuple[int, int, int] |
| 1777 |
L0: |
| 1778 |
r0 = 'b' |
| 1779 |
r1 = 'c' |
| 1780 |
r2 = object 2 |
| 1781 |
r3 = object 3 |
| 1782 |
r4 = CPyDict_Build(2, r0, r2, r1, r3) |
| 1783 |
r5 = __main__.globals :: static |
| 1784 |
r6 = 'f' |
| 1785 |
r7 = CPyDict_GetItem(r5, r6) |
| 1786 |
r8 = PyDict_New() |
| 1787 |
r9 = CPyDict_UpdateInDisplay(r8, r4) |
| 1788 |
r10 = r9 >= 0 :: signed |
| 1789 |
r11 = object 1 |
| 1790 |
r12 = PyTuple_Pack(1, r11) |
| 1791 |
r13 = PyObject_Call(r7, r12, r8) |
| 1792 |
r14 = unbox(tuple[int, int, int], r13) |
| 1793 |
return r14 |
| 1794 |
|
| 1795 |
[case testFunctionCallWithDefaultArgs] |
| 1796 |
def f(x: int, y: int = 3, z: str = "test") -> None: |
| 1797 |
return None |
| 1798 |
|
| 1799 |
def g() -> None: |
| 1800 |
f(2) |
| 1801 |
f(y = 3, x = 6) |
| 1802 |
[out] |
| 1803 |
def f(x, y, z): |
| 1804 |
x, y :: int |
| 1805 |
z, r0 :: str |
| 1806 |
L0: |
| 1807 |
if is_error(y) goto L1 else goto L2 |
| 1808 |
L1: |
| 1809 |
y = 6 |
| 1810 |
L2: |
| 1811 |
if is_error(z) goto L3 else goto L4 |
| 1812 |
L3: |
| 1813 |
r0 = 'test' |
| 1814 |
z = r0 |
| 1815 |
L4: |
| 1816 |
return 1 |
| 1817 |
def g(): |
| 1818 |
r0 :: int |
| 1819 |
r1 :: str |
| 1820 |
r2 :: None |
| 1821 |
r3 :: str |
| 1822 |
r4 :: None |
| 1823 |
L0: |
| 1824 |
r0 = <error> :: int |
| 1825 |
r1 = <error> :: str |
| 1826 |
r2 = f(4, r0, r1) |
| 1827 |
r3 = <error> :: str |
| 1828 |
r4 = f(12, 6, r3) |
| 1829 |
return 1 |
| 1830 |
|
| 1831 |
[case testMethodCallWithDefaultArgs] |
| 1832 |
class A: |
| 1833 |
def f(self, x: int, y: int = 3, z: str = "test") -> None: |
| 1834 |
return None |
| 1835 |
|
| 1836 |
def g() -> None: |
| 1837 |
a = A() |
| 1838 |
a.f(2) |
| 1839 |
a.f(y = 3, x = 6) |
| 1840 |
[out] |
| 1841 |
def A.f(self, x, y, z): |
| 1842 |
self :: __main__.A |
| 1843 |
x, y :: int |
| 1844 |
z, r0 :: str |
| 1845 |
L0: |
| 1846 |
if is_error(y) goto L1 else goto L2 |
| 1847 |
L1: |
| 1848 |
y = 6 |
| 1849 |
L2: |
| 1850 |
if is_error(z) goto L3 else goto L4 |
| 1851 |
L3: |
| 1852 |
r0 = 'test' |
| 1853 |
z = r0 |
| 1854 |
L4: |
| 1855 |
return 1 |
| 1856 |
def g(): |
| 1857 |
r0, a :: __main__.A |
| 1858 |
r1 :: int |
| 1859 |
r2 :: str |
| 1860 |
r3 :: None |
| 1861 |
r4 :: str |
| 1862 |
r5 :: None |
| 1863 |
L0: |
| 1864 |
r0 = A() |
| 1865 |
a = r0 |
| 1866 |
r1 = <error> :: int |
| 1867 |
r2 = <error> :: str |
| 1868 |
r3 = a.f(4, r1, r2) |
| 1869 |
r4 = <error> :: str |
| 1870 |
r5 = a.f(12, 6, r4) |
| 1871 |
return 1 |
| 1872 |
|
| 1873 |
[case testListComprehension_withgil] |
| 1874 |
from typing import List |
| 1875 |
|
| 1876 |
def f() -> List[int]: |
| 1877 |
return [x*x for x in [1,2,3] if x != 2 if x != 3] |
| 1878 |
[out] |
| 1879 |
def f(): |
| 1880 |
r0, r1 :: list |
| 1881 |
r2, r3, r4 :: object |
| 1882 |
r5 :: ptr |
| 1883 |
r6, r7 :: native_int |
| 1884 |
r8 :: bit |
| 1885 |
r9 :: object |
| 1886 |
r10, x :: int |
| 1887 |
r11, r12 :: bit |
| 1888 |
r13 :: int |
| 1889 |
r14 :: object |
| 1890 |
r15 :: i32 |
| 1891 |
r16 :: bit |
| 1892 |
r17 :: native_int |
| 1893 |
L0: |
| 1894 |
r0 = PyList_New(0) |
| 1895 |
r1 = PyList_New(3) |
| 1896 |
r2 = object 1 |
| 1897 |
r3 = object 2 |
| 1898 |
r4 = object 3 |
| 1899 |
r5 = list_items r1 |
| 1900 |
buf_init_item r5, 0, r2 |
| 1901 |
buf_init_item r5, 1, r3 |
| 1902 |
buf_init_item r5, 2, r4 |
| 1903 |
keep_alive r1 |
| 1904 |
r6 = 0 |
| 1905 |
L1: |
| 1906 |
r7 = var_object_size r1 |
| 1907 |
r8 = r6 < r7 :: signed |
| 1908 |
if r8 goto L2 else goto L8 :: bool |
| 1909 |
L2: |
| 1910 |
r9 = list_get_item_unsafe r1, r6 |
| 1911 |
r10 = unbox(int, r9) |
| 1912 |
x = r10 |
| 1913 |
r11 = int_ne x, 4 |
| 1914 |
if r11 goto L4 else goto L3 :: bool |
| 1915 |
L3: |
| 1916 |
goto L7 |
| 1917 |
L4: |
| 1918 |
r12 = int_ne x, 6 |
| 1919 |
if r12 goto L6 else goto L5 :: bool |
| 1920 |
L5: |
| 1921 |
goto L7 |
| 1922 |
L6: |
| 1923 |
r13 = CPyTagged_Multiply(x, x) |
| 1924 |
r14 = box(int, r13) |
| 1925 |
r15 = PyList_Append(r0, r14) |
| 1926 |
r16 = r15 >= 0 :: signed |
| 1927 |
L7: |
| 1928 |
r17 = r6 + 1 |
| 1929 |
r6 = r17 |
| 1930 |
goto L1 |
| 1931 |
L8: |
| 1932 |
return r0 |
| 1933 |
|
| 1934 |
[case testDictComprehension_withgil] |
| 1935 |
from typing import Dict |
| 1936 |
def f() -> Dict[int, int]: |
| 1937 |
return {x: x*x for x in [1,2,3] if x != 2 if x != 3} |
| 1938 |
[out] |
| 1939 |
def f(): |
| 1940 |
r0 :: dict |
| 1941 |
r1 :: list |
| 1942 |
r2, r3, r4 :: object |
| 1943 |
r5 :: ptr |
| 1944 |
r6, r7 :: native_int |
| 1945 |
r8 :: bit |
| 1946 |
r9 :: object |
| 1947 |
r10, x :: int |
| 1948 |
r11, r12 :: bit |
| 1949 |
r13 :: int |
| 1950 |
r14, r15 :: object |
| 1951 |
r16 :: i32 |
| 1952 |
r17 :: bit |
| 1953 |
r18 :: native_int |
| 1954 |
L0: |
| 1955 |
r0 = PyDict_New() |
| 1956 |
r1 = PyList_New(3) |
| 1957 |
r2 = object 1 |
| 1958 |
r3 = object 2 |
| 1959 |
r4 = object 3 |
| 1960 |
r5 = list_items r1 |
| 1961 |
buf_init_item r5, 0, r2 |
| 1962 |
buf_init_item r5, 1, r3 |
| 1963 |
buf_init_item r5, 2, r4 |
| 1964 |
keep_alive r1 |
| 1965 |
r6 = 0 |
| 1966 |
L1: |
| 1967 |
r7 = var_object_size r1 |
| 1968 |
r8 = r6 < r7 :: signed |
| 1969 |
if r8 goto L2 else goto L8 :: bool |
| 1970 |
L2: |
| 1971 |
r9 = list_get_item_unsafe r1, r6 |
| 1972 |
r10 = unbox(int, r9) |
| 1973 |
x = r10 |
| 1974 |
r11 = int_ne x, 4 |
| 1975 |
if r11 goto L4 else goto L3 :: bool |
| 1976 |
L3: |
| 1977 |
goto L7 |
| 1978 |
L4: |
| 1979 |
r12 = int_ne x, 6 |
| 1980 |
if r12 goto L6 else goto L5 :: bool |
| 1981 |
L5: |
| 1982 |
goto L7 |
| 1983 |
L6: |
| 1984 |
r13 = CPyTagged_Multiply(x, x) |
| 1985 |
r14 = box(int, x) |
| 1986 |
r15 = box(int, r13) |
| 1987 |
r16 = PyDict_SetItem(r0, r14, r15) |
| 1988 |
r17 = r16 >= 0 :: signed |
| 1989 |
L7: |
| 1990 |
r18 = r6 + 1 |
| 1991 |
r6 = r18 |
| 1992 |
goto L1 |
| 1993 |
L8: |
| 1994 |
return r0 |
| 1995 |
|
| 1996 |
[case testLoopsMultipleAssign_withgil] |
| 1997 |
from typing import List, Tuple |
| 1998 |
def f(l: List[Tuple[int, int, int]]) -> List[int]: |
| 1999 |
for x, y, z in l: |
| 2000 |
pass |
| 2001 |
return [x+y+z for x, y, z in l] |
| 2002 |
[out] |
| 2003 |
def f(l): |
| 2004 |
l :: list |
| 2005 |
r0, r1 :: native_int |
| 2006 |
r2 :: bit |
| 2007 |
r3 :: object |
| 2008 |
r4 :: tuple[int, int, int] |
| 2009 |
r5, x, r6, y, r7, z :: int |
| 2010 |
r8, r9 :: native_int |
| 2011 |
r10 :: list |
| 2012 |
r11, r12 :: native_int |
| 2013 |
r13 :: bit |
| 2014 |
r14 :: object |
| 2015 |
r15 :: tuple[int, int, int] |
| 2016 |
r16, x_2, r17, y_2, r18, z_2, r19, r20 :: int |
| 2017 |
r21 :: object |
| 2018 |
r22 :: native_int |
| 2019 |
L0: |
| 2020 |
r0 = 0 |
| 2021 |
L1: |
| 2022 |
r1 = var_object_size l |
| 2023 |
r2 = r0 < r1 :: signed |
| 2024 |
if r2 goto L2 else goto L4 :: bool |
| 2025 |
L2: |
| 2026 |
r3 = list_get_item_unsafe l, r0 |
| 2027 |
r4 = unbox(tuple[int, int, int], r3) |
| 2028 |
r5 = r4[0] |
| 2029 |
x = r5 |
| 2030 |
r6 = r4[1] |
| 2031 |
y = r6 |
| 2032 |
r7 = r4[2] |
| 2033 |
z = r7 |
| 2034 |
L3: |
| 2035 |
r8 = r0 + 1 |
| 2036 |
r0 = r8 |
| 2037 |
goto L1 |
| 2038 |
L4: |
| 2039 |
r9 = var_object_size l |
| 2040 |
r10 = PyList_New(r9) |
| 2041 |
r11 = 0 |
| 2042 |
L5: |
| 2043 |
r12 = var_object_size l |
| 2044 |
r13 = r11 < r12 :: signed |
| 2045 |
if r13 goto L6 else goto L8 :: bool |
| 2046 |
L6: |
| 2047 |
r14 = list_get_item_unsafe l, r11 |
| 2048 |
r15 = unbox(tuple[int, int, int], r14) |
| 2049 |
r16 = r15[0] |
| 2050 |
x_2 = r16 |
| 2051 |
r17 = r15[1] |
| 2052 |
y_2 = r17 |
| 2053 |
r18 = r15[2] |
| 2054 |
z_2 = r18 |
| 2055 |
r19 = CPyTagged_Add(x_2, y_2) |
| 2056 |
r20 = CPyTagged_Add(r19, z_2) |
| 2057 |
r21 = box(int, r20) |
| 2058 |
CPyList_SetItemUnsafe(r10, r11, r21) |
| 2059 |
L7: |
| 2060 |
r22 = r11 + 1 |
| 2061 |
r11 = r22 |
| 2062 |
goto L5 |
| 2063 |
L8: |
| 2064 |
return r10 |
| 2065 |
|
| 2066 |
[case testProperty_withgil] |
| 2067 |
class PropertyHolder: |
| 2068 |
@property |
| 2069 |
def value(self) -> int: |
| 2070 |
return self.left + self.right if self.is_add else self.left - self.right |
| 2071 |
def __init__(self, left: int, right: int, is_add: bool) -> None: |
| 2072 |
self.left = left |
| 2073 |
self.right = right |
| 2074 |
self.is_add = is_add |
| 2075 |
def twice_value(self) -> int: |
| 2076 |
return 2 * self.value |
| 2077 |
[out] |
| 2078 |
def PropertyHolder.value(self): |
| 2079 |
self :: __main__.PropertyHolder |
| 2080 |
r0 :: bool |
| 2081 |
r1, r2, r3, r4, r5, r6, r7 :: int |
| 2082 |
L0: |
| 2083 |
r0 = self.is_add |
| 2084 |
if r0 goto L1 else goto L2 :: bool |
| 2085 |
L1: |
| 2086 |
r1 = borrow self.left |
| 2087 |
r2 = borrow self.right |
| 2088 |
r3 = CPyTagged_Add(r1, r2) |
| 2089 |
keep_alive self, self |
| 2090 |
r4 = r3 |
| 2091 |
goto L3 |
| 2092 |
L2: |
| 2093 |
r5 = borrow self.left |
| 2094 |
r6 = borrow self.right |
| 2095 |
r7 = CPyTagged_Subtract(r5, r6) |
| 2096 |
keep_alive self, self |
| 2097 |
r4 = r7 |
| 2098 |
L3: |
| 2099 |
return r4 |
| 2100 |
def PropertyHolder.__init__(self, left, right, is_add): |
| 2101 |
self :: __main__.PropertyHolder |
| 2102 |
left, right :: int |
| 2103 |
is_add :: bool |
| 2104 |
L0: |
| 2105 |
self.left = left |
| 2106 |
self.right = right |
| 2107 |
self.is_add = is_add |
| 2108 |
return 1 |
| 2109 |
def PropertyHolder.twice_value(self): |
| 2110 |
self :: __main__.PropertyHolder |
| 2111 |
r0, r1 :: int |
| 2112 |
L0: |
| 2113 |
r0 = self.value |
| 2114 |
r1 = CPyTagged_Multiply(4, r0) |
| 2115 |
return r1 |
| 2116 |
|
| 2117 |
[case testNativeIndex_withgil] |
| 2118 |
from typing import List |
| 2119 |
class A: |
| 2120 |
def __getitem__(self, index: int) -> int: pass |
| 2121 |
|
| 2122 |
def g(a: A, b: List[int], c: int) -> int: |
| 2123 |
return a[c] + b[c] |
| 2124 |
[out] |
| 2125 |
def A.__getitem__(self, index): |
| 2126 |
self :: __main__.A |
| 2127 |
index :: int |
| 2128 |
L0: |
| 2129 |
unreachable |
| 2130 |
def g(a, b, c): |
| 2131 |
a :: __main__.A |
| 2132 |
b :: list |
| 2133 |
c, r0 :: int |
| 2134 |
r1 :: object |
| 2135 |
r2, r3 :: int |
| 2136 |
L0: |
| 2137 |
r0 = a.__getitem__(c) |
| 2138 |
r1 = CPyList_GetItemBorrow(b, c) |
| 2139 |
r2 = unbox(int, r1) |
| 2140 |
r3 = CPyTagged_Add(r0, r2) |
| 2141 |
keep_alive b, c |
| 2142 |
return r3 |
| 2143 |
|
| 2144 |
[case testTypeAlias_toplevel] |
| 2145 |
from typing import List, NewType, NamedTuple |
| 2146 |
Lol = NamedTuple('Lol', (('a', int), ('b', str))) |
| 2147 |
x = Lol(1, '') |
| 2148 |
Foo = List[int] |
| 2149 |
Bar = NewType('Bar', Foo) |
| 2150 |
y = Bar([1,2,3]) |
| 2151 |
[out] |
| 2152 |
def __top_level__(): |
| 2153 |
r0, r1 :: object |
| 2154 |
r2 :: bit |
| 2155 |
r3 :: str |
| 2156 |
r4, r5 :: object |
| 2157 |
r6 :: str |
| 2158 |
r7 :: dict |
| 2159 |
r8 :: object |
| 2160 |
r9, r10 :: str |
| 2161 |
r11 :: object |
| 2162 |
r12 :: tuple[str, object] |
| 2163 |
r13 :: object |
| 2164 |
r14 :: str |
| 2165 |
r15 :: object |
| 2166 |
r16 :: tuple[str, object] |
| 2167 |
r17 :: object |
| 2168 |
r18 :: tuple[object, object] |
| 2169 |
r19 :: object |
| 2170 |
r20 :: dict |
| 2171 |
r21 :: str |
| 2172 |
r22 :: object |
| 2173 |
r23 :: object[2] |
| 2174 |
r24 :: object_ptr |
| 2175 |
r25 :: object |
| 2176 |
r26 :: dict |
| 2177 |
r27 :: str |
| 2178 |
r28 :: i32 |
| 2179 |
r29 :: bit |
| 2180 |
r30 :: str |
| 2181 |
r31 :: dict |
| 2182 |
r32 :: str |
| 2183 |
r33, r34 :: object |
| 2184 |
r35 :: object[2] |
| 2185 |
r36 :: object_ptr |
| 2186 |
r37 :: object |
| 2187 |
r38 :: tuple |
| 2188 |
r39 :: dict |
| 2189 |
r40 :: str |
| 2190 |
r41 :: i32 |
| 2191 |
r42 :: bit |
| 2192 |
r43 :: dict |
| 2193 |
r44 :: str |
| 2194 |
r45, r46, r47 :: object |
| 2195 |
r48 :: dict |
| 2196 |
r49 :: str |
| 2197 |
r50 :: i32 |
| 2198 |
r51 :: bit |
| 2199 |
r52 :: str |
| 2200 |
r53 :: dict |
| 2201 |
r54 :: str |
| 2202 |
r55 :: object |
| 2203 |
r56 :: dict |
| 2204 |
r57 :: str |
| 2205 |
r58 :: object |
| 2206 |
r59 :: object[2] |
| 2207 |
r60 :: object_ptr |
| 2208 |
r61 :: object |
| 2209 |
r62 :: dict |
| 2210 |
r63 :: str |
| 2211 |
r64 :: i32 |
| 2212 |
r65 :: bit |
| 2213 |
r66 :: list |
| 2214 |
r67, r68, r69 :: object |
| 2215 |
r70 :: ptr |
| 2216 |
r71 :: dict |
| 2217 |
r72 :: str |
| 2218 |
r73 :: i32 |
| 2219 |
r74 :: bit |
| 2220 |
L0: |
| 2221 |
r0 = builtins :: module |
| 2222 |
r1 = load_address _Py_NoneStruct |
| 2223 |
r2 = r0 != r1 |
| 2224 |
if r2 goto L2 else goto L1 :: bool |
| 2225 |
L1: |
| 2226 |
r3 = 'builtins' |
| 2227 |
r4 = PyImport_Import(r3) |
| 2228 |
builtins = r4 :: module |
| 2229 |
L2: |
| 2230 |
r5 = ('List', 'NewType', 'NamedTuple') |
| 2231 |
r6 = 'typing' |
| 2232 |
r7 = __main__.globals :: static |
| 2233 |
r8 = CPyImport_ImportFromMany(r6, r5, r5, r7) |
| 2234 |
typing = r8 :: module |
| 2235 |
r9 = 'Lol' |
| 2236 |
r10 = 'a' |
| 2237 |
r11 = load_address PyLong_Type |
| 2238 |
r12 = (r10, r11) |
| 2239 |
r13 = box(tuple[str, object], r12) |
| 2240 |
r14 = 'b' |
| 2241 |
r15 = load_address PyUnicode_Type |
| 2242 |
r16 = (r14, r15) |
| 2243 |
r17 = box(tuple[str, object], r16) |
| 2244 |
r18 = (r13, r17) |
| 2245 |
r19 = box(tuple[object, object], r18) |
| 2246 |
r20 = __main__.globals :: static |
| 2247 |
r21 = 'NamedTuple' |
| 2248 |
r22 = CPyDict_GetItem(r20, r21) |
| 2249 |
r23 = [r9, r19] |
| 2250 |
r24 = load_address r23 |
| 2251 |
r25 = PyObject_Vectorcall(r22, r24, 2, 0) |
| 2252 |
keep_alive r9, r19 |
| 2253 |
r26 = __main__.globals :: static |
| 2254 |
r27 = 'Lol' |
| 2255 |
r28 = CPyDict_SetItem(r26, r27, r25) |
| 2256 |
r29 = r28 >= 0 :: signed |
| 2257 |
r30 = '' |
| 2258 |
r31 = __main__.globals :: static |
| 2259 |
r32 = 'Lol' |
| 2260 |
r33 = CPyDict_GetItem(r31, r32) |
| 2261 |
r34 = object 1 |
| 2262 |
r35 = [r34, r30] |
| 2263 |
r36 = load_address r35 |
| 2264 |
r37 = PyObject_Vectorcall(r33, r36, 2, 0) |
| 2265 |
keep_alive r34, r30 |
| 2266 |
r38 = cast(tuple, r37) |
| 2267 |
r39 = __main__.globals :: static |
| 2268 |
r40 = 'x' |
| 2269 |
r41 = CPyDict_SetItem(r39, r40, r38) |
| 2270 |
r42 = r41 >= 0 :: signed |
| 2271 |
r43 = __main__.globals :: static |
| 2272 |
r44 = 'List' |
| 2273 |
r45 = CPyDict_GetItem(r43, r44) |
| 2274 |
r46 = load_address PyLong_Type |
| 2275 |
r47 = PyObject_GetItem(r45, r46) |
| 2276 |
r48 = __main__.globals :: static |
| 2277 |
r49 = 'Foo' |
| 2278 |
r50 = CPyDict_SetItem(r48, r49, r47) |
| 2279 |
r51 = r50 >= 0 :: signed |
| 2280 |
r52 = 'Bar' |
| 2281 |
r53 = __main__.globals :: static |
| 2282 |
r54 = 'Foo' |
| 2283 |
r55 = CPyDict_GetItem(r53, r54) |
| 2284 |
r56 = __main__.globals :: static |
| 2285 |
r57 = 'NewType' |
| 2286 |
r58 = CPyDict_GetItem(r56, r57) |
| 2287 |
r59 = [r52, r55] |
| 2288 |
r60 = load_address r59 |
| 2289 |
r61 = PyObject_Vectorcall(r58, r60, 2, 0) |
| 2290 |
keep_alive r52, r55 |
| 2291 |
r62 = __main__.globals :: static |
| 2292 |
r63 = 'Bar' |
| 2293 |
r64 = CPyDict_SetItem(r62, r63, r61) |
| 2294 |
r65 = r64 >= 0 :: signed |
| 2295 |
r66 = PyList_New(3) |
| 2296 |
r67 = object 1 |
| 2297 |
r68 = object 2 |
| 2298 |
r69 = object 3 |
| 2299 |
r70 = list_items r66 |
| 2300 |
buf_init_item r70, 0, r67 |
| 2301 |
buf_init_item r70, 1, r68 |
| 2302 |
buf_init_item r70, 2, r69 |
| 2303 |
keep_alive r66 |
| 2304 |
r71 = __main__.globals :: static |
| 2305 |
r72 = 'y' |
| 2306 |
r73 = CPyDict_SetItem(r71, r72, r66) |
| 2307 |
r74 = r73 >= 0 :: signed |
| 2308 |
return 1 |
| 2309 |
|
| 2310 |
[case testChainedConditional] |
| 2311 |
def g(x: int) -> int: |
| 2312 |
return x |
| 2313 |
def f(x: int, y: int, z: int) -> bool: |
| 2314 |
return g(x) < g(y) > g(z) |
| 2315 |
[out] |
| 2316 |
def g(x): |
| 2317 |
x :: int |
| 2318 |
L0: |
| 2319 |
return x |
| 2320 |
def f(x, y, z): |
| 2321 |
x, y, z, r0, r1 :: int |
| 2322 |
r2 :: bit |
| 2323 |
r3 :: bool |
| 2324 |
r4 :: int |
| 2325 |
r5 :: bit |
| 2326 |
L0: |
| 2327 |
r0 = g(x) |
| 2328 |
r1 = g(y) |
| 2329 |
r2 = int_lt r0, r1 |
| 2330 |
if r2 goto L2 else goto L1 :: bool |
| 2331 |
L1: |
| 2332 |
r3 = r2 |
| 2333 |
goto L3 |
| 2334 |
L2: |
| 2335 |
r4 = g(z) |
| 2336 |
r5 = int_gt r1, r4 |
| 2337 |
r3 = r5 |
| 2338 |
L3: |
| 2339 |
return r3 |
| 2340 |
|
| 2341 |
[case testEq] |
| 2342 |
class A: |
| 2343 |
def __eq__(self, x: object) -> bool: |
| 2344 |
return NotImplemented |
| 2345 |
[out] |
| 2346 |
def A.__eq__(self, x): |
| 2347 |
self :: __main__.A |
| 2348 |
x, r0 :: object |
| 2349 |
L0: |
| 2350 |
r0 = load_address _Py_NotImplementedStruct |
| 2351 |
return r0 |
| 2352 |
def A.__ne__(__mypyc_self__, rhs): |
| 2353 |
__mypyc_self__ :: __main__.A |
| 2354 |
rhs, r0, r1 :: object |
| 2355 |
r2 :: bit |
| 2356 |
r3 :: object |
| 2357 |
r4, r5 :: bit |
| 2358 |
r6 :: object |
| 2359 |
r7 :: bit |
| 2360 |
r8 :: i32 |
| 2361 |
r9 :: bit |
| 2362 |
r10 :: bool |
| 2363 |
r11 :: object |
| 2364 |
L0: |
| 2365 |
r0 = __mypyc_self__.__eq__(rhs) |
| 2366 |
r1 = load_address _Py_NotImplementedStruct |
| 2367 |
r2 = r0 == r1 |
| 2368 |
if r2 goto L7 else goto L1 :: bool |
| 2369 |
L1: |
| 2370 |
r3 = load_global Py_True :: static |
| 2371 |
r4 = r0 == r3 |
| 2372 |
if r4 goto L2 else goto L3 :: bool |
| 2373 |
L2: |
| 2374 |
r5 = 0 |
| 2375 |
goto L6 |
| 2376 |
L3: |
| 2377 |
r6 = load_global Py_False :: static |
| 2378 |
r7 = r0 == r6 |
| 2379 |
if r7 goto L4 else goto L5 :: bool |
| 2380 |
L4: |
| 2381 |
r5 = 1 |
| 2382 |
goto L6 |
| 2383 |
L5: |
| 2384 |
r8 = PyObject_Not(r0) |
| 2385 |
r9 = r8 >= 0 :: signed |
| 2386 |
r10 = truncate r8: i32 to builtins.bool |
| 2387 |
r5 = r10 |
| 2388 |
L6: |
| 2389 |
r11 = box(bit, r5) |
| 2390 |
return r11 |
| 2391 |
L7: |
| 2392 |
return r1 |
| 2393 |
|
| 2394 |
[case testDecorators_toplevel] |
| 2395 |
from typing import Callable |
| 2396 |
|
| 2397 |
def a(f: Callable[[], None]) -> Callable[[], None]: |
| 2398 |
def g() -> None: |
| 2399 |
print('Entering') |
| 2400 |
f() |
| 2401 |
print('Exited') |
| 2402 |
return g |
| 2403 |
|
| 2404 |
def b(f: Callable[[], None]) -> Callable[[], None]: |
| 2405 |
def g() -> None: |
| 2406 |
print('---') |
| 2407 |
f() |
| 2408 |
print('---') |
| 2409 |
return g |
| 2410 |
|
| 2411 |
@a |
| 2412 |
@b |
| 2413 |
def c() -> None: |
| 2414 |
@a |
| 2415 |
@b |
| 2416 |
def d() -> None: |
| 2417 |
print('d') |
| 2418 |
print('c') |
| 2419 |
d() |
| 2420 |
|
| 2421 |
[out] |
| 2422 |
def g_a_obj.__get__(__mypyc_self__, instance, owner): |
| 2423 |
__mypyc_self__, instance, owner, r0 :: object |
| 2424 |
r1 :: bit |
| 2425 |
r2 :: object |
| 2426 |
L0: |
| 2427 |
r0 = load_address _Py_NoneStruct |
| 2428 |
r1 = instance == r0 |
| 2429 |
if r1 goto L1 else goto L2 :: bool |
| 2430 |
L1: |
| 2431 |
return __mypyc_self__ |
| 2432 |
L2: |
| 2433 |
r2 = PyMethod_New(__mypyc_self__, instance) |
| 2434 |
return r2 |
| 2435 |
def g_a_obj.__call__(__mypyc_self__): |
| 2436 |
__mypyc_self__ :: __main__.g_a_obj |
| 2437 |
r0 :: __main__.a_env |
| 2438 |
r1 :: str |
| 2439 |
r2 :: object |
| 2440 |
r3 :: str |
| 2441 |
r4 :: object |
| 2442 |
r5 :: object[1] |
| 2443 |
r6 :: object_ptr |
| 2444 |
r7, r8, r9 :: object |
| 2445 |
r10 :: str |
| 2446 |
r11 :: object |
| 2447 |
r12 :: str |
| 2448 |
r13 :: object |
| 2449 |
r14 :: object[1] |
| 2450 |
r15 :: object_ptr |
| 2451 |
r16 :: object |
| 2452 |
L0: |
| 2453 |
r0 = __mypyc_self__.__mypyc_env__ |
| 2454 |
r1 = 'Entering' |
| 2455 |
r2 = builtins :: module |
| 2456 |
r3 = 'print' |
| 2457 |
r4 = CPyObject_GetAttr(r2, r3) |
| 2458 |
r5 = [r1] |
| 2459 |
r6 = load_address r5 |
| 2460 |
r7 = PyObject_Vectorcall(r4, r6, 1, 0) |
| 2461 |
keep_alive r1 |
| 2462 |
r8 = r0.f |
| 2463 |
r9 = PyObject_Vectorcall(r8, 0, 0, 0) |
| 2464 |
r10 = 'Exited' |
| 2465 |
r11 = builtins :: module |
| 2466 |
r12 = 'print' |
| 2467 |
r13 = CPyObject_GetAttr(r11, r12) |
| 2468 |
r14 = [r10] |
| 2469 |
r15 = load_address r14 |
| 2470 |
r16 = PyObject_Vectorcall(r13, r15, 1, 0) |
| 2471 |
keep_alive r10 |
| 2472 |
return 1 |
| 2473 |
def a(f): |
| 2474 |
f :: object |
| 2475 |
r0 :: __main__.a_env |
| 2476 |
r1 :: bool |
| 2477 |
r2 :: __main__.g_a_obj |
| 2478 |
r3 :: bool |
| 2479 |
g :: object |
| 2480 |
L0: |
| 2481 |
r0 = a_env() |
| 2482 |
r0.f = f; r1 = is_error |
| 2483 |
r2 = g_a_obj() |
| 2484 |
r2.__mypyc_env__ = r0; r3 = is_error |
| 2485 |
g = r2 |
| 2486 |
return g |
| 2487 |
def g_b_obj.__get__(__mypyc_self__, instance, owner): |
| 2488 |
__mypyc_self__, instance, owner, r0 :: object |
| 2489 |
r1 :: bit |
| 2490 |
r2 :: object |
| 2491 |
L0: |
| 2492 |
r0 = load_address _Py_NoneStruct |
| 2493 |
r1 = instance == r0 |
| 2494 |
if r1 goto L1 else goto L2 :: bool |
| 2495 |
L1: |
| 2496 |
return __mypyc_self__ |
| 2497 |
L2: |
| 2498 |
r2 = PyMethod_New(__mypyc_self__, instance) |
| 2499 |
return r2 |
| 2500 |
def g_b_obj.__call__(__mypyc_self__): |
| 2501 |
__mypyc_self__ :: __main__.g_b_obj |
| 2502 |
r0 :: __main__.b_env |
| 2503 |
r1 :: str |
| 2504 |
r2 :: object |
| 2505 |
r3 :: str |
| 2506 |
r4 :: object |
| 2507 |
r5 :: object[1] |
| 2508 |
r6 :: object_ptr |
| 2509 |
r7, r8, r9 :: object |
| 2510 |
r10 :: str |
| 2511 |
r11 :: object |
| 2512 |
r12 :: str |
| 2513 |
r13 :: object |
| 2514 |
r14 :: object[1] |
| 2515 |
r15 :: object_ptr |
| 2516 |
r16 :: object |
| 2517 |
L0: |
| 2518 |
r0 = __mypyc_self__.__mypyc_env__ |
| 2519 |
r1 = '---' |
| 2520 |
r2 = builtins :: module |
| 2521 |
r3 = 'print' |
| 2522 |
r4 = CPyObject_GetAttr(r2, r3) |
| 2523 |
r5 = [r1] |
| 2524 |
r6 = load_address r5 |
| 2525 |
r7 = PyObject_Vectorcall(r4, r6, 1, 0) |
| 2526 |
keep_alive r1 |
| 2527 |
r8 = r0.f |
| 2528 |
r9 = PyObject_Vectorcall(r8, 0, 0, 0) |
| 2529 |
r10 = '---' |
| 2530 |
r11 = builtins :: module |
| 2531 |
r12 = 'print' |
| 2532 |
r13 = CPyObject_GetAttr(r11, r12) |
| 2533 |
r14 = [r10] |
| 2534 |
r15 = load_address r14 |
| 2535 |
r16 = PyObject_Vectorcall(r13, r15, 1, 0) |
| 2536 |
keep_alive r10 |
| 2537 |
return 1 |
| 2538 |
def b(f): |
| 2539 |
f :: object |
| 2540 |
r0 :: __main__.b_env |
| 2541 |
r1 :: bool |
| 2542 |
r2 :: __main__.g_b_obj |
| 2543 |
r3 :: bool |
| 2544 |
g :: object |
| 2545 |
L0: |
| 2546 |
r0 = b_env() |
| 2547 |
r0.f = f; r1 = is_error |
| 2548 |
r2 = g_b_obj() |
| 2549 |
r2.__mypyc_env__ = r0; r3 = is_error |
| 2550 |
g = r2 |
| 2551 |
return g |
| 2552 |
def d_c_obj.__get__(__mypyc_self__, instance, owner): |
| 2553 |
__mypyc_self__, instance, owner, r0 :: object |
| 2554 |
r1 :: bit |
| 2555 |
r2 :: object |
| 2556 |
L0: |
| 2557 |
r0 = load_address _Py_NoneStruct |
| 2558 |
r1 = instance == r0 |
| 2559 |
if r1 goto L1 else goto L2 :: bool |
| 2560 |
L1: |
| 2561 |
return __mypyc_self__ |
| 2562 |
L2: |
| 2563 |
r2 = PyMethod_New(__mypyc_self__, instance) |
| 2564 |
return r2 |
| 2565 |
def d_c_obj.__call__(__mypyc_self__): |
| 2566 |
__mypyc_self__ :: __main__.d_c_obj |
| 2567 |
r0 :: __main__.c_env |
| 2568 |
r1 :: str |
| 2569 |
r2 :: object |
| 2570 |
r3 :: str |
| 2571 |
r4 :: object |
| 2572 |
r5 :: object[1] |
| 2573 |
r6 :: object_ptr |
| 2574 |
r7 :: object |
| 2575 |
L0: |
| 2576 |
r0 = __mypyc_self__.__mypyc_env__ |
| 2577 |
r1 = 'd' |
| 2578 |
r2 = builtins :: module |
| 2579 |
r3 = 'print' |
| 2580 |
r4 = CPyObject_GetAttr(r2, r3) |
| 2581 |
r5 = [r1] |
| 2582 |
r6 = load_address r5 |
| 2583 |
r7 = PyObject_Vectorcall(r4, r6, 1, 0) |
| 2584 |
keep_alive r1 |
| 2585 |
return 1 |
| 2586 |
def c(): |
| 2587 |
r0 :: __main__.c_env |
| 2588 |
r1 :: __main__.d_c_obj |
| 2589 |
r2 :: bool |
| 2590 |
r3 :: dict |
| 2591 |
r4 :: str |
| 2592 |
r5 :: object |
| 2593 |
r6 :: object[1] |
| 2594 |
r7 :: object_ptr |
| 2595 |
r8 :: object |
| 2596 |
r9 :: dict |
| 2597 |
r10 :: str |
| 2598 |
r11 :: object |
| 2599 |
r12 :: object[1] |
| 2600 |
r13 :: object_ptr |
| 2601 |
r14, d :: object |
| 2602 |
r15 :: dict |
| 2603 |
r16 :: str |
| 2604 |
r17 :: i32 |
| 2605 |
r18 :: bit |
| 2606 |
r19 :: str |
| 2607 |
r20 :: object |
| 2608 |
r21 :: str |
| 2609 |
r22 :: object |
| 2610 |
r23 :: object[1] |
| 2611 |
r24 :: object_ptr |
| 2612 |
r25, r26 :: object |
| 2613 |
L0: |
| 2614 |
r0 = c_env() |
| 2615 |
r1 = d_c_obj() |
| 2616 |
r1.__mypyc_env__ = r0; r2 = is_error |
| 2617 |
r3 = __main__.globals :: static |
| 2618 |
r4 = 'b' |
| 2619 |
r5 = CPyDict_GetItem(r3, r4) |
| 2620 |
r6 = [r1] |
| 2621 |
r7 = load_address r6 |
| 2622 |
r8 = PyObject_Vectorcall(r5, r7, 1, 0) |
| 2623 |
keep_alive r1 |
| 2624 |
r9 = __main__.globals :: static |
| 2625 |
r10 = 'a' |
| 2626 |
r11 = CPyDict_GetItem(r9, r10) |
| 2627 |
r12 = [r8] |
| 2628 |
r13 = load_address r12 |
| 2629 |
r14 = PyObject_Vectorcall(r11, r13, 1, 0) |
| 2630 |
keep_alive r8 |
| 2631 |
d = r14 |
| 2632 |
r15 = __main__.globals :: static |
| 2633 |
r16 = 'd' |
| 2634 |
r17 = PyDict_SetItem(r15, r16, r14) |
| 2635 |
r18 = r17 >= 0 :: signed |
| 2636 |
r19 = 'c' |
| 2637 |
r20 = builtins :: module |
| 2638 |
r21 = 'print' |
| 2639 |
r22 = CPyObject_GetAttr(r20, r21) |
| 2640 |
r23 = [r19] |
| 2641 |
r24 = load_address r23 |
| 2642 |
r25 = PyObject_Vectorcall(r22, r24, 1, 0) |
| 2643 |
keep_alive r19 |
| 2644 |
r26 = PyObject_Vectorcall(d, 0, 0, 0) |
| 2645 |
return 1 |
| 2646 |
def __top_level__(): |
| 2647 |
r0, r1 :: object |
| 2648 |
r2 :: bit |
| 2649 |
r3 :: str |
| 2650 |
r4, r5 :: object |
| 2651 |
r6 :: str |
| 2652 |
r7 :: dict |
| 2653 |
r8 :: object |
| 2654 |
r9 :: dict |
| 2655 |
r10 :: str |
| 2656 |
r11 :: object |
| 2657 |
r12 :: dict |
| 2658 |
r13 :: str |
| 2659 |
r14 :: object |
| 2660 |
r15 :: object[1] |
| 2661 |
r16 :: object_ptr |
| 2662 |
r17 :: object |
| 2663 |
r18 :: dict |
| 2664 |
r19 :: str |
| 2665 |
r20 :: object |
| 2666 |
r21 :: object[1] |
| 2667 |
r22 :: object_ptr |
| 2668 |
r23 :: object |
| 2669 |
r24 :: dict |
| 2670 |
r25 :: str |
| 2671 |
r26 :: i32 |
| 2672 |
r27 :: bit |
| 2673 |
L0: |
| 2674 |
r0 = builtins :: module |
| 2675 |
r1 = load_address _Py_NoneStruct |
| 2676 |
r2 = r0 != r1 |
| 2677 |
if r2 goto L2 else goto L1 :: bool |
| 2678 |
L1: |
| 2679 |
r3 = 'builtins' |
| 2680 |
r4 = PyImport_Import(r3) |
| 2681 |
builtins = r4 :: module |
| 2682 |
L2: |
| 2683 |
r5 = ('Callable',) |
| 2684 |
r6 = 'typing' |
| 2685 |
r7 = __main__.globals :: static |
| 2686 |
r8 = CPyImport_ImportFromMany(r6, r5, r5, r7) |
| 2687 |
typing = r8 :: module |
| 2688 |
r9 = __main__.globals :: static |
| 2689 |
r10 = 'c' |
| 2690 |
r11 = CPyDict_GetItem(r9, r10) |
| 2691 |
r12 = __main__.globals :: static |
| 2692 |
r13 = 'b' |
| 2693 |
r14 = CPyDict_GetItem(r12, r13) |
| 2694 |
r15 = [r11] |
| 2695 |
r16 = load_address r15 |
| 2696 |
r17 = PyObject_Vectorcall(r14, r16, 1, 0) |
| 2697 |
keep_alive r11 |
| 2698 |
r18 = __main__.globals :: static |
| 2699 |
r19 = 'a' |
| 2700 |
r20 = CPyDict_GetItem(r18, r19) |
| 2701 |
r21 = [r17] |
| 2702 |
r22 = load_address r21 |
| 2703 |
r23 = PyObject_Vectorcall(r20, r22, 1, 0) |
| 2704 |
keep_alive r17 |
| 2705 |
r24 = __main__.globals :: static |
| 2706 |
r25 = 'c' |
| 2707 |
r26 = PyDict_SetItem(r24, r25, r23) |
| 2708 |
r27 = r26 >= 0 :: signed |
| 2709 |
return 1 |
| 2710 |
|
| 2711 |
[case testDecoratorsSimple_toplevel] |
| 2712 |
from typing import Callable |
| 2713 |
|
| 2714 |
def a(f: Callable[[], None]) -> Callable[[], None]: |
| 2715 |
def g() -> None: |
| 2716 |
print('Entering') |
| 2717 |
f() |
| 2718 |
print('Exited') |
| 2719 |
return g |
| 2720 |
|
| 2721 |
[out] |
| 2722 |
def g_a_obj.__get__(__mypyc_self__, instance, owner): |
| 2723 |
__mypyc_self__, instance, owner, r0 :: object |
| 2724 |
r1 :: bit |
| 2725 |
r2 :: object |
| 2726 |
L0: |
| 2727 |
r0 = load_address _Py_NoneStruct |
| 2728 |
r1 = instance == r0 |
| 2729 |
if r1 goto L1 else goto L2 :: bool |
| 2730 |
L1: |
| 2731 |
return __mypyc_self__ |
| 2732 |
L2: |
| 2733 |
r2 = PyMethod_New(__mypyc_self__, instance) |
| 2734 |
return r2 |
| 2735 |
def g_a_obj.__call__(__mypyc_self__): |
| 2736 |
__mypyc_self__ :: __main__.g_a_obj |
| 2737 |
r0 :: __main__.a_env |
| 2738 |
r1 :: str |
| 2739 |
r2 :: object |
| 2740 |
r3 :: str |
| 2741 |
r4 :: object |
| 2742 |
r5 :: object[1] |
| 2743 |
r6 :: object_ptr |
| 2744 |
r7, r8, r9 :: object |
| 2745 |
r10 :: str |
| 2746 |
r11 :: object |
| 2747 |
r12 :: str |
| 2748 |
r13 :: object |
| 2749 |
r14 :: object[1] |
| 2750 |
r15 :: object_ptr |
| 2751 |
r16 :: object |
| 2752 |
L0: |
| 2753 |
r0 = __mypyc_self__.__mypyc_env__ |
| 2754 |
r1 = 'Entering' |
| 2755 |
r2 = builtins :: module |
| 2756 |
r3 = 'print' |
| 2757 |
r4 = CPyObject_GetAttr(r2, r3) |
| 2758 |
r5 = [r1] |
| 2759 |
r6 = load_address r5 |
| 2760 |
r7 = PyObject_Vectorcall(r4, r6, 1, 0) |
| 2761 |
keep_alive r1 |
| 2762 |
r8 = r0.f |
| 2763 |
r9 = PyObject_Vectorcall(r8, 0, 0, 0) |
| 2764 |
r10 = 'Exited' |
| 2765 |
r11 = builtins :: module |
| 2766 |
r12 = 'print' |
| 2767 |
r13 = CPyObject_GetAttr(r11, r12) |
| 2768 |
r14 = [r10] |
| 2769 |
r15 = load_address r14 |
| 2770 |
r16 = PyObject_Vectorcall(r13, r15, 1, 0) |
| 2771 |
keep_alive r10 |
| 2772 |
return 1 |
| 2773 |
def a(f): |
| 2774 |
f :: object |
| 2775 |
r0 :: __main__.a_env |
| 2776 |
r1 :: bool |
| 2777 |
r2 :: __main__.g_a_obj |
| 2778 |
r3 :: bool |
| 2779 |
g :: object |
| 2780 |
L0: |
| 2781 |
r0 = a_env() |
| 2782 |
r0.f = f; r1 = is_error |
| 2783 |
r2 = g_a_obj() |
| 2784 |
r2.__mypyc_env__ = r0; r3 = is_error |
| 2785 |
g = r2 |
| 2786 |
return g |
| 2787 |
def __top_level__(): |
| 2788 |
r0, r1 :: object |
| 2789 |
r2 :: bit |
| 2790 |
r3 :: str |
| 2791 |
r4, r5 :: object |
| 2792 |
r6 :: str |
| 2793 |
r7 :: dict |
| 2794 |
r8 :: object |
| 2795 |
L0: |
| 2796 |
r0 = builtins :: module |
| 2797 |
r1 = load_address _Py_NoneStruct |
| 2798 |
r2 = r0 != r1 |
| 2799 |
if r2 goto L2 else goto L1 :: bool |
| 2800 |
L1: |
| 2801 |
r3 = 'builtins' |
| 2802 |
r4 = PyImport_Import(r3) |
| 2803 |
builtins = r4 :: module |
| 2804 |
L2: |
| 2805 |
r5 = ('Callable',) |
| 2806 |
r6 = 'typing' |
| 2807 |
r7 = __main__.globals :: static |
| 2808 |
r8 = CPyImport_ImportFromMany(r6, r5, r5, r7) |
| 2809 |
typing = r8 :: module |
| 2810 |
return 1 |
| 2811 |
|
| 2812 |
[case testAnyAllG] |
| 2813 |
from typing import Iterable |
| 2814 |
|
| 2815 |
def call_any(l: Iterable[int]) -> bool: |
| 2816 |
return any(i == 0 for i in l) |
| 2817 |
|
| 2818 |
def call_all(l: Iterable[int]) -> bool: |
| 2819 |
return all(i == 0 for i in l) |
| 2820 |
|
| 2821 |
[out] |
| 2822 |
def call_any(l): |
| 2823 |
l :: object |
| 2824 |
r0 :: bool |
| 2825 |
r1, r2 :: object |
| 2826 |
r3, i :: int |
| 2827 |
r4, r5 :: bit |
| 2828 |
L0: |
| 2829 |
r0 = 0 |
| 2830 |
r1 = PyObject_GetIter(l) |
| 2831 |
L1: |
| 2832 |
r2 = PyIter_Next(r1) |
| 2833 |
if is_error(r2) goto L6 else goto L2 |
| 2834 |
L2: |
| 2835 |
r3 = unbox(int, r2) |
| 2836 |
i = r3 |
| 2837 |
r4 = int_eq i, 0 |
| 2838 |
if r4 goto L3 else goto L4 :: bool |
| 2839 |
L3: |
| 2840 |
r0 = 1 |
| 2841 |
goto L8 |
| 2842 |
L4: |
| 2843 |
L5: |
| 2844 |
goto L1 |
| 2845 |
L6: |
| 2846 |
r5 = CPy_NoErrOccurred() |
| 2847 |
L7: |
| 2848 |
L8: |
| 2849 |
return r0 |
| 2850 |
def call_all(l): |
| 2851 |
l :: object |
| 2852 |
r0 :: bool |
| 2853 |
r1, r2 :: object |
| 2854 |
r3, i :: int |
| 2855 |
r4, r5, r6 :: bit |
| 2856 |
L0: |
| 2857 |
r0 = 1 |
| 2858 |
r1 = PyObject_GetIter(l) |
| 2859 |
L1: |
| 2860 |
r2 = PyIter_Next(r1) |
| 2861 |
if is_error(r2) goto L6 else goto L2 |
| 2862 |
L2: |
| 2863 |
r3 = unbox(int, r2) |
| 2864 |
i = r3 |
| 2865 |
r4 = int_eq i, 0 |
| 2866 |
r5 = r4 ^ 1 |
| 2867 |
if r5 goto L3 else goto L4 :: bool |
| 2868 |
L3: |
| 2869 |
r0 = 0 |
| 2870 |
goto L8 |
| 2871 |
L4: |
| 2872 |
L5: |
| 2873 |
goto L1 |
| 2874 |
L6: |
| 2875 |
r6 = CPy_NoErrOccurred() |
| 2876 |
L7: |
| 2877 |
L8: |
| 2878 |
return r0 |
| 2879 |
|
| 2880 |
[case testSum] |
| 2881 |
from typing import Callable, Iterable |
| 2882 |
|
| 2883 |
def call_sum(l: Iterable[int], comparison: Callable[[int], bool]) -> int: |
| 2884 |
return sum(comparison(x) for x in l) |
| 2885 |
|
| 2886 |
[out] |
| 2887 |
def call_sum(l, comparison): |
| 2888 |
l, comparison :: object |
| 2889 |
r0 :: int |
| 2890 |
r1, r2 :: object |
| 2891 |
r3, x :: int |
| 2892 |
r4 :: object |
| 2893 |
r5 :: object[1] |
| 2894 |
r6 :: object_ptr |
| 2895 |
r7 :: object |
| 2896 |
r8, r9 :: bool |
| 2897 |
r10, r11 :: int |
| 2898 |
r12 :: bit |
| 2899 |
L0: |
| 2900 |
r0 = 0 |
| 2901 |
r1 = PyObject_GetIter(l) |
| 2902 |
L1: |
| 2903 |
r2 = PyIter_Next(r1) |
| 2904 |
if is_error(r2) goto L4 else goto L2 |
| 2905 |
L2: |
| 2906 |
r3 = unbox(int, r2) |
| 2907 |
x = r3 |
| 2908 |
r4 = box(int, x) |
| 2909 |
r5 = [r4] |
| 2910 |
r6 = load_address r5 |
| 2911 |
r7 = PyObject_Vectorcall(comparison, r6, 1, 0) |
| 2912 |
keep_alive r4 |
| 2913 |
r8 = unbox(bool, r7) |
| 2914 |
r9 = r8 << 1 |
| 2915 |
r10 = extend r9: builtins.bool to builtins.int |
| 2916 |
r11 = CPyTagged_Add(r0, r10) |
| 2917 |
r0 = r11 |
| 2918 |
L3: |
| 2919 |
goto L1 |
| 2920 |
L4: |
| 2921 |
r12 = CPy_NoErrOccurred() |
| 2922 |
L5: |
| 2923 |
return r0 |
| 2924 |
|
| 2925 |
[case testSetAttr1] |
| 2926 |
from typing import Any, Dict, List |
| 2927 |
def lol(x: Any): |
| 2928 |
setattr(x, 'x', '5') |
| 2929 |
|
| 2930 |
[out] |
| 2931 |
def lol(x): |
| 2932 |
x :: object |
| 2933 |
r0, r1 :: str |
| 2934 |
r2 :: i32 |
| 2935 |
r3 :: bit |
| 2936 |
r4 :: object |
| 2937 |
L0: |
| 2938 |
r0 = 'x' |
| 2939 |
r1 = '5' |
| 2940 |
r2 = PyObject_SetAttr(x, r0, r1) |
| 2941 |
r3 = r2 >= 0 :: signed |
| 2942 |
r4 = box(None, 1) |
| 2943 |
return r4 |
| 2944 |
|
| 2945 |
[case testFinalModuleInt] |
| 2946 |
from typing import Final |
| 2947 |
|
| 2948 |
x: Final = 1 |
| 2949 |
y: Final = 2 |
| 2950 |
|
| 2951 |
def f(a: bool) -> int: |
| 2952 |
if a: |
| 2953 |
return x |
| 2954 |
else: |
| 2955 |
return y |
| 2956 |
[out] |
| 2957 |
def f(a): |
| 2958 |
a :: bool |
| 2959 |
L0: |
| 2960 |
if a goto L1 else goto L2 :: bool |
| 2961 |
L1: |
| 2962 |
return 2 |
| 2963 |
L2: |
| 2964 |
return 4 |
| 2965 |
L3: |
| 2966 |
unreachable |
| 2967 |
|
| 2968 |
[case testFinalModuleStr] |
| 2969 |
from typing import Final |
| 2970 |
|
| 2971 |
x: Final = 'x' |
| 2972 |
y: Final = 'y' |
| 2973 |
|
| 2974 |
def f(a: bool) -> str: |
| 2975 |
if a: |
| 2976 |
return x |
| 2977 |
else: |
| 2978 |
return y |
| 2979 |
[out] |
| 2980 |
def f(a): |
| 2981 |
a :: bool |
| 2982 |
r0, r1 :: str |
| 2983 |
L0: |
| 2984 |
if a goto L1 else goto L2 :: bool |
| 2985 |
L1: |
| 2986 |
r0 = 'x' |
| 2987 |
return r0 |
| 2988 |
L2: |
| 2989 |
r1 = 'y' |
| 2990 |
return r1 |
| 2991 |
L3: |
| 2992 |
unreachable |
| 2993 |
|
| 2994 |
[case testFinalModuleBool] |
| 2995 |
from typing import Final |
| 2996 |
|
| 2997 |
x: Final = True |
| 2998 |
y: Final = False |
| 2999 |
|
| 3000 |
def f(a: bool) -> bool: |
| 3001 |
if a: |
| 3002 |
return x |
| 3003 |
else: |
| 3004 |
return y |
| 3005 |
[out] |
| 3006 |
def f(a): |
| 3007 |
a :: bool |
| 3008 |
L0: |
| 3009 |
if a goto L1 else goto L2 :: bool |
| 3010 |
L1: |
| 3011 |
return 1 |
| 3012 |
L2: |
| 3013 |
return 0 |
| 3014 |
L3: |
| 3015 |
unreachable |
| 3016 |
|
| 3017 |
[case testFinalClass] |
| 3018 |
from typing import Final |
| 3019 |
|
| 3020 |
class C: |
| 3021 |
x: Final = 1 |
| 3022 |
y: Final = 2 |
| 3023 |
|
| 3024 |
def f(a: bool) -> int: |
| 3025 |
if a: |
| 3026 |
return C.x |
| 3027 |
else: |
| 3028 |
return C.y |
| 3029 |
[out] |
| 3030 |
def C.__mypyc_defaults_setup(__mypyc_self__): |
| 3031 |
__mypyc_self__ :: __main__.C |
| 3032 |
L0: |
| 3033 |
__mypyc_self__.x = 2 |
| 3034 |
__mypyc_self__.y = 4 |
| 3035 |
return 1 |
| 3036 |
def f(a): |
| 3037 |
a :: bool |
| 3038 |
L0: |
| 3039 |
if a goto L1 else goto L2 :: bool |
| 3040 |
L1: |
| 3041 |
return 2 |
| 3042 |
L2: |
| 3043 |
return 4 |
| 3044 |
L3: |
| 3045 |
unreachable |
| 3046 |
|
| 3047 |
[case testFinalStaticList] |
| 3048 |
from typing import Final |
| 3049 |
|
| 3050 |
x: Final = [1] |
| 3051 |
|
| 3052 |
def f() -> int: |
| 3053 |
return x[0] |
| 3054 |
[out] |
| 3055 |
def f(): |
| 3056 |
r0 :: list |
| 3057 |
r1 :: bool |
| 3058 |
r2 :: object |
| 3059 |
r3 :: int |
| 3060 |
L0: |
| 3061 |
r0 = __main__.x :: static |
| 3062 |
if is_error(r0) goto L1 else goto L2 |
| 3063 |
L1: |
| 3064 |
r1 = raise NameError('value for final name "x" was not set') |
| 3065 |
unreachable |
| 3066 |
L2: |
| 3067 |
r2 = CPyList_GetItemShort(r0, 0) |
| 3068 |
r3 = unbox(int, r2) |
| 3069 |
return r3 |
| 3070 |
|
| 3071 |
[case testFinalStaticTuple] |
| 3072 |
from typing import Final |
| 3073 |
|
| 3074 |
x: Final = (1, 2) |
| 3075 |
|
| 3076 |
def f() -> int: |
| 3077 |
return x[0] |
| 3078 |
[out] |
| 3079 |
def f(): |
| 3080 |
r0 :: tuple[int, int] |
| 3081 |
r1 :: bool |
| 3082 |
r2 :: int |
| 3083 |
L0: |
| 3084 |
r0 = __main__.x :: static |
| 3085 |
if is_error(r0) goto L1 else goto L2 |
| 3086 |
L1: |
| 3087 |
r1 = raise NameError('value for final name "x" was not set') |
| 3088 |
unreachable |
| 3089 |
L2: |
| 3090 |
r2 = r0[0] |
| 3091 |
return r2 |
| 3092 |
|
| 3093 |
[case testFinalStaticInt] |
| 3094 |
from typing import Final |
| 3095 |
|
| 3096 |
x: Final = 1 + int() |
| 3097 |
|
| 3098 |
def f() -> int: |
| 3099 |
return x - 1 |
| 3100 |
[out] |
| 3101 |
def f(): |
| 3102 |
r0 :: int |
| 3103 |
r1 :: bool |
| 3104 |
r2 :: int |
| 3105 |
L0: |
| 3106 |
r0 = __main__.x :: static |
| 3107 |
if is_error(r0) goto L1 else goto L2 |
| 3108 |
L1: |
| 3109 |
r1 = raise NameError('value for final name "x" was not set') |
| 3110 |
unreachable |
| 3111 |
L2: |
| 3112 |
r2 = CPyTagged_Subtract(r0, 2) |
| 3113 |
return r2 |
| 3114 |
|
| 3115 |
[case testFinalRestrictedTypeVar] |
| 3116 |
from typing import TypeVar |
| 3117 |
if False: |
| 3118 |
from typing import Final |
| 3119 |
|
| 3120 |
FOO = 10 # type: Final |
| 3121 |
|
| 3122 |
Targ = TypeVar('Targ', int, str) |
| 3123 |
def foo(z: Targ) -> None: |
| 3124 |
FOO |
| 3125 |
[out] |
| 3126 |
def foo(z): |
| 3127 |
z :: object |
| 3128 |
L0: |
| 3129 |
return 1 |
| 3130 |
|
| 3131 |
[case testFinalLocals] |
| 3132 |
from typing import Final |
| 3133 |
|
| 3134 |
def inlined() -> str: |
| 3135 |
# XXX: the final type must be declared explicitly for Var.final_value to be set. |
| 3136 |
const: Final[str] = "Oppenheimer" |
| 3137 |
return const |
| 3138 |
|
| 3139 |
def local() -> str: |
| 3140 |
const: Final[str] = inlined() |
| 3141 |
return const |
| 3142 |
[out] |
| 3143 |
def inlined(): |
| 3144 |
r0, const, r1 :: str |
| 3145 |
L0: |
| 3146 |
r0 = 'Oppenheimer' |
| 3147 |
const = r0 |
| 3148 |
r1 = 'Oppenheimer' |
| 3149 |
return r1 |
| 3150 |
def local(): |
| 3151 |
r0, const :: str |
| 3152 |
L0: |
| 3153 |
r0 = inlined() |
| 3154 |
const = r0 |
| 3155 |
return const |
| 3156 |
|
| 3157 |
[case testDirectlyCall__bool__] |
| 3158 |
class A: |
| 3159 |
def __bool__(self) -> bool: |
| 3160 |
return True |
| 3161 |
class B(A): |
| 3162 |
def __bool__(self) -> bool: |
| 3163 |
return False |
| 3164 |
|
| 3165 |
def lol(x: A) -> int: |
| 3166 |
if x: |
| 3167 |
return 1 |
| 3168 |
else: |
| 3169 |
return 0 |
| 3170 |
|
| 3171 |
[out] |
| 3172 |
def A.__bool__(self): |
| 3173 |
self :: __main__.A |
| 3174 |
L0: |
| 3175 |
return 1 |
| 3176 |
def B.__bool__(self): |
| 3177 |
self :: __main__.B |
| 3178 |
L0: |
| 3179 |
return 0 |
| 3180 |
def lol(x): |
| 3181 |
x :: __main__.A |
| 3182 |
r0 :: bool |
| 3183 |
L0: |
| 3184 |
r0 = x.__bool__() |
| 3185 |
if r0 goto L1 else goto L2 :: bool |
| 3186 |
L1: |
| 3187 |
return 2 |
| 3188 |
L2: |
| 3189 |
return 0 |
| 3190 |
L3: |
| 3191 |
unreachable |
| 3192 |
|
| 3193 |
[case testRevealType] |
| 3194 |
def f(x: int) -> None: |
| 3195 |
reveal_type(x) # type: ignore |
| 3196 |
[out] |
| 3197 |
def f(x): |
| 3198 |
x :: int |
| 3199 |
r0 :: object |
| 3200 |
r1 :: str |
| 3201 |
r2, r3 :: object |
| 3202 |
r4 :: object[1] |
| 3203 |
r5 :: object_ptr |
| 3204 |
r6 :: object |
| 3205 |
L0: |
| 3206 |
r0 = builtins :: module |
| 3207 |
r1 = 'reveal_type' |
| 3208 |
r2 = CPyObject_GetAttr(r0, r1) |
| 3209 |
r3 = box(int, x) |
| 3210 |
r4 = [r3] |
| 3211 |
r5 = load_address r4 |
| 3212 |
r6 = PyObject_Vectorcall(r2, r5, 1, 0) |
| 3213 |
keep_alive r3 |
| 3214 |
return 1 |
| 3215 |
|
| 3216 |
[case testCallCWithStrJoinMethod] |
| 3217 |
from typing import List |
| 3218 |
def f(x: str, y: List[str]) -> str: |
| 3219 |
return x.join(y) |
| 3220 |
[out] |
| 3221 |
def f(x, y): |
| 3222 |
x :: str |
| 3223 |
y :: list |
| 3224 |
r0 :: str |
| 3225 |
L0: |
| 3226 |
r0 = PyUnicode_Join(x, y) |
| 3227 |
return r0 |
| 3228 |
|
| 3229 |
[case testCallCWithToListFunction] |
| 3230 |
from typing import List, Iterable, Tuple, Dict |
| 3231 |
# generic object |
| 3232 |
def f(x: Iterable[int]) -> List[int]: |
| 3233 |
return list(x) |
| 3234 |
|
| 3235 |
# need coercing |
| 3236 |
def g(x: Tuple[int, int, int]) -> List[int]: |
| 3237 |
return list(x) |
| 3238 |
|
| 3239 |
# non-list object |
| 3240 |
def h(x: Dict[int, str]) -> List[int]: |
| 3241 |
return list(x) |
| 3242 |
|
| 3243 |
[out] |
| 3244 |
def f(x): |
| 3245 |
x :: object |
| 3246 |
r0 :: list |
| 3247 |
L0: |
| 3248 |
r0 = PySequence_List(x) |
| 3249 |
return r0 |
| 3250 |
def g(x): |
| 3251 |
x :: tuple[int, int, int] |
| 3252 |
r0 :: object |
| 3253 |
r1 :: list |
| 3254 |
L0: |
| 3255 |
r0 = box(tuple[int, int, int], x) |
| 3256 |
r1 = PySequence_List(r0) |
| 3257 |
return r1 |
| 3258 |
def h(x): |
| 3259 |
x :: dict |
| 3260 |
r0 :: list |
| 3261 |
L0: |
| 3262 |
r0 = PySequence_List(x) |
| 3263 |
return r0 |
| 3264 |
|
| 3265 |
[case testBoolFunction] |
| 3266 |
def f(x: object) -> bool: |
| 3267 |
return bool(x) |
| 3268 |
[out] |
| 3269 |
def f(x): |
| 3270 |
x :: object |
| 3271 |
r0 :: i32 |
| 3272 |
r1 :: bit |
| 3273 |
r2 :: bool |
| 3274 |
L0: |
| 3275 |
r0 = PyObject_IsTrue(x) |
| 3276 |
r1 = r0 >= 0 :: signed |
| 3277 |
r2 = truncate r0: i32 to builtins.bool |
| 3278 |
return r2 |
| 3279 |
|
| 3280 |
[case testLocalImports] |
| 3281 |
def root() -> None: |
| 3282 |
import dataclasses |
| 3283 |
import enum |
| 3284 |
|
| 3285 |
def submodule() -> int: |
| 3286 |
import p.m |
| 3287 |
return p.x |
| 3288 |
[file p/__init__.py] |
| 3289 |
x = 1 |
| 3290 |
[file p/m.py] |
| 3291 |
[out] |
| 3292 |
def root(): |
| 3293 |
r0 :: dict |
| 3294 |
r1, r2 :: object |
| 3295 |
r3 :: bit |
| 3296 |
r4 :: str |
| 3297 |
r5 :: object |
| 3298 |
r6 :: str |
| 3299 |
r7 :: dict |
| 3300 |
r8 :: str |
| 3301 |
r9 :: object |
| 3302 |
r10 :: i32 |
| 3303 |
r11 :: bit |
| 3304 |
r12 :: dict |
| 3305 |
r13, r14 :: object |
| 3306 |
r15 :: bit |
| 3307 |
r16 :: str |
| 3308 |
r17 :: object |
| 3309 |
r18 :: str |
| 3310 |
r19 :: dict |
| 3311 |
r20 :: str |
| 3312 |
r21 :: object |
| 3313 |
r22 :: i32 |
| 3314 |
r23 :: bit |
| 3315 |
L0: |
| 3316 |
r0 = __main__.globals :: static |
| 3317 |
r1 = dataclasses :: module |
| 3318 |
r2 = load_address _Py_NoneStruct |
| 3319 |
r3 = r1 != r2 |
| 3320 |
if r3 goto L2 else goto L1 :: bool |
| 3321 |
L1: |
| 3322 |
r4 = 'dataclasses' |
| 3323 |
r5 = PyImport_Import(r4) |
| 3324 |
dataclasses = r5 :: module |
| 3325 |
L2: |
| 3326 |
r6 = 'dataclasses' |
| 3327 |
r7 = PyImport_GetModuleDict() |
| 3328 |
r8 = 'dataclasses' |
| 3329 |
r9 = CPyDict_GetItem(r7, r8) |
| 3330 |
r10 = CPyDict_SetItem(r0, r6, r9) |
| 3331 |
r11 = r10 >= 0 :: signed |
| 3332 |
r12 = __main__.globals :: static |
| 3333 |
r13 = enum :: module |
| 3334 |
r14 = load_address _Py_NoneStruct |
| 3335 |
r15 = r13 != r14 |
| 3336 |
if r15 goto L4 else goto L3 :: bool |
| 3337 |
L3: |
| 3338 |
r16 = 'enum' |
| 3339 |
r17 = PyImport_Import(r16) |
| 3340 |
enum = r17 :: module |
| 3341 |
L4: |
| 3342 |
r18 = 'enum' |
| 3343 |
r19 = PyImport_GetModuleDict() |
| 3344 |
r20 = 'enum' |
| 3345 |
r21 = CPyDict_GetItem(r19, r20) |
| 3346 |
r22 = CPyDict_SetItem(r12, r18, r21) |
| 3347 |
r23 = r22 >= 0 :: signed |
| 3348 |
return 1 |
| 3349 |
def submodule(): |
| 3350 |
r0 :: dict |
| 3351 |
r1, r2 :: object |
| 3352 |
r3 :: bit |
| 3353 |
r4 :: str |
| 3354 |
r5 :: object |
| 3355 |
r6 :: str |
| 3356 |
r7 :: dict |
| 3357 |
r8 :: str |
| 3358 |
r9 :: object |
| 3359 |
r10 :: i32 |
| 3360 |
r11 :: bit |
| 3361 |
r12 :: dict |
| 3362 |
r13 :: str |
| 3363 |
r14 :: object |
| 3364 |
r15 :: str |
| 3365 |
r16 :: object |
| 3366 |
r17 :: int |
| 3367 |
L0: |
| 3368 |
r0 = __main__.globals :: static |
| 3369 |
r1 = p.m :: module |
| 3370 |
r2 = load_address _Py_NoneStruct |
| 3371 |
r3 = r1 != r2 |
| 3372 |
if r3 goto L2 else goto L1 :: bool |
| 3373 |
L1: |
| 3374 |
r4 = 'p.m' |
| 3375 |
r5 = PyImport_Import(r4) |
| 3376 |
p.m = r5 :: module |
| 3377 |
L2: |
| 3378 |
r6 = 'p' |
| 3379 |
r7 = PyImport_GetModuleDict() |
| 3380 |
r8 = 'p' |
| 3381 |
r9 = CPyDict_GetItem(r7, r8) |
| 3382 |
r10 = CPyDict_SetItem(r0, r6, r9) |
| 3383 |
r11 = r10 >= 0 :: signed |
| 3384 |
r12 = PyImport_GetModuleDict() |
| 3385 |
r13 = 'p' |
| 3386 |
r14 = CPyDict_GetItem(r12, r13) |
| 3387 |
r15 = 'x' |
| 3388 |
r16 = CPyObject_GetAttr(r14, r15) |
| 3389 |
r17 = unbox(int, r16) |
| 3390 |
return r17 |
| 3391 |
|
| 3392 |
[case testIsinstanceBool] |
| 3393 |
def f(x: object) -> bool: |
| 3394 |
return isinstance(x, bool) |
| 3395 |
[out] |
| 3396 |
def f(x): |
| 3397 |
x :: object |
| 3398 |
r0 :: bit |
| 3399 |
L0: |
| 3400 |
r0 = PyBool_Check(x) |
| 3401 |
return r0 |
| 3402 |
|
| 3403 |
[case testRangeObject] |
| 3404 |
def range_object() -> None: |
| 3405 |
r = range(4, 12, 2) |
| 3406 |
sum = 0 |
| 3407 |
for i in r: |
| 3408 |
sum += i |
| 3409 |
|
| 3410 |
def range_in_loop() -> None: |
| 3411 |
sum = 0 |
| 3412 |
for i in range(4, 12, 2): |
| 3413 |
sum += i |
| 3414 |
[out] |
| 3415 |
def range_object(): |
| 3416 |
r0, r1, r2, r3 :: object |
| 3417 |
r4 :: object[3] |
| 3418 |
r5 :: object_ptr |
| 3419 |
r6 :: object |
| 3420 |
r7, r :: range |
| 3421 |
sum :: int |
| 3422 |
r8, r9 :: object |
| 3423 |
r10, i, r11 :: int |
| 3424 |
r12 :: bit |
| 3425 |
L0: |
| 3426 |
r0 = load_address PyRange_Type |
| 3427 |
r1 = object 4 |
| 3428 |
r2 = object 12 |
| 3429 |
r3 = object 2 |
| 3430 |
r4 = [r1, r2, r3] |
| 3431 |
r5 = load_address r4 |
| 3432 |
r6 = PyObject_Vectorcall(r0, r5, 3, 0) |
| 3433 |
keep_alive r1, r2, r3 |
| 3434 |
r7 = cast(range, r6) |
| 3435 |
r = r7 |
| 3436 |
sum = 0 |
| 3437 |
r8 = PyObject_GetIter(r) |
| 3438 |
L1: |
| 3439 |
r9 = PyIter_Next(r8) |
| 3440 |
if is_error(r9) goto L4 else goto L2 |
| 3441 |
L2: |
| 3442 |
r10 = unbox(int, r9) |
| 3443 |
i = r10 |
| 3444 |
r11 = CPyTagged_Add(sum, i) |
| 3445 |
sum = r11 |
| 3446 |
L3: |
| 3447 |
goto L1 |
| 3448 |
L4: |
| 3449 |
r12 = CPy_NoErrOccurred() |
| 3450 |
L5: |
| 3451 |
return 1 |
| 3452 |
def range_in_loop(): |
| 3453 |
sum :: int |
| 3454 |
r0 :: short_int |
| 3455 |
i :: int |
| 3456 |
r1 :: bit |
| 3457 |
r2 :: int |
| 3458 |
r3 :: short_int |
| 3459 |
L0: |
| 3460 |
sum = 0 |
| 3461 |
r0 = 8 |
| 3462 |
i = r0 |
| 3463 |
L1: |
| 3464 |
r1 = int_lt r0, 24 |
| 3465 |
if r1 goto L2 else goto L4 :: bool |
| 3466 |
L2: |
| 3467 |
i = r0 |
| 3468 |
r2 = CPyTagged_Add(sum, i) |
| 3469 |
sum = r2 |
| 3470 |
L3: |
| 3471 |
r3 = r0 + 4 |
| 3472 |
r0 = r3 |
| 3473 |
goto L1 |
| 3474 |
L4: |
| 3475 |
return 1 |
| 3476 |
|
| 3477 |
[case testLocalRedefinition] |
| 3478 |
# mypy: allow-redefinition-old |
| 3479 |
def f() -> None: |
| 3480 |
i = 0 |
| 3481 |
i += 1 |
| 3482 |
i = "foo" |
| 3483 |
i += i |
| 3484 |
i = 0.0 |
| 3485 |
[out] |
| 3486 |
def f(): |
| 3487 |
i, r0 :: int |
| 3488 |
r1, i__redef__, r2 :: str |
| 3489 |
i__redef____redef__ :: float |
| 3490 |
L0: |
| 3491 |
i = 0 |
| 3492 |
r0 = CPyTagged_Add(i, 2) |
| 3493 |
i = r0 |
| 3494 |
r1 = 'foo' |
| 3495 |
i__redef__ = r1 |
| 3496 |
r2 = CPyStr_Append(i__redef__, i__redef__) |
| 3497 |
i__redef__ = r2 |
| 3498 |
i__redef____redef__ = 0.0 |
| 3499 |
return 1 |
| 3500 |
|
| 3501 |
[case testNewType] |
| 3502 |
from typing import NewType |
| 3503 |
|
| 3504 |
class A: pass |
| 3505 |
|
| 3506 |
N = NewType("N", A) |
| 3507 |
|
| 3508 |
def f(arg: A) -> N: |
| 3509 |
return N(arg) |
| 3510 |
[out] |
| 3511 |
def f(arg): |
| 3512 |
arg :: __main__.A |
| 3513 |
L0: |
| 3514 |
return arg |
| 3515 |
|
| 3516 |
[case testTypeCheckingFlag] |
| 3517 |
from typing import TYPE_CHECKING, List |
| 3518 |
|
| 3519 |
def f(arg: List[int]) -> int: |
| 3520 |
if TYPE_CHECKING: |
| 3521 |
from collections.abc import Sized |
| 3522 |
s: Sized = arg |
| 3523 |
return len(s) |
| 3524 |
|
| 3525 |
[out] |
| 3526 |
def f(arg): |
| 3527 |
arg :: list |
| 3528 |
r0 :: bool |
| 3529 |
r1 :: int |
| 3530 |
r2 :: bit |
| 3531 |
s :: object |
| 3532 |
r3 :: int |
| 3533 |
L0: |
| 3534 |
r0 = 0 << 1 |
| 3535 |
r1 = extend r0: builtins.bool to builtins.int |
| 3536 |
r2 = r1 != 0 |
| 3537 |
if r2 goto L1 else goto L2 :: bool |
| 3538 |
L1: |
| 3539 |
goto L3 |
| 3540 |
L2: |
| 3541 |
L3: |
| 3542 |
s = arg |
| 3543 |
r3 = CPyObject_Size(s) |
| 3544 |
return r3 |
| 3545 |
|
| 3546 |
[case testUndefinedFunction] |
| 3547 |
def f(): |
| 3548 |
non_existent_function() |
| 3549 |
|
| 3550 |
[out] |
| 3551 |
def f(): |
| 3552 |
r0 :: bool |
| 3553 |
r1, r2, r3 :: object |
| 3554 |
L0: |
| 3555 |
r0 = raise NameError('name "non_existent_function" is not defined') |
| 3556 |
r1 = box(None, 1) |
| 3557 |
r2 = PyObject_Vectorcall(r1, 0, 0, 0) |
| 3558 |
r3 = box(None, 1) |
| 3559 |
return r3 |
| 3560 |
|
| 3561 |
[case testStarArgFastPathTuple] |
| 3562 |
from typing import Any, Callable |
| 3563 |
def deco(fn: Callable[..., Any]) -> Callable[..., Any]: |
| 3564 |
def wrapper(*args: Any) -> Any: |
| 3565 |
return fn(*args) |
| 3566 |
return wrapper |
| 3567 |
|
| 3568 |
[out] |
| 3569 |
def wrapper_deco_obj.__get__(__mypyc_self__, instance, owner): |
| 3570 |
__mypyc_self__, instance, owner, r0 :: object |
| 3571 |
r1 :: bit |
| 3572 |
r2 :: object |
| 3573 |
L0: |
| 3574 |
r0 = load_address _Py_NoneStruct |
| 3575 |
r1 = instance == r0 |
| 3576 |
if r1 goto L1 else goto L2 :: bool |
| 3577 |
L1: |
| 3578 |
return __mypyc_self__ |
| 3579 |
L2: |
| 3580 |
r2 = PyMethod_New(__mypyc_self__, instance) |
| 3581 |
return r2 |
| 3582 |
def wrapper_deco_obj.__call__(__mypyc_self__, args): |
| 3583 |
__mypyc_self__ :: __main__.wrapper_deco_obj |
| 3584 |
args :: tuple |
| 3585 |
r0 :: __main__.deco_env |
| 3586 |
r1, r2 :: object |
| 3587 |
L0: |
| 3588 |
r0 = __mypyc_self__.__mypyc_env__ |
| 3589 |
r1 = r0.fn |
| 3590 |
r2 = PyObject_CallObject(r1, args) |
| 3591 |
return r2 |
| 3592 |
def deco(fn): |
| 3593 |
fn :: object |
| 3594 |
r0 :: __main__.deco_env |
| 3595 |
r1 :: bool |
| 3596 |
r2 :: __main__.wrapper_deco_obj |
| 3597 |
r3 :: bool |
| 3598 |
wrapper :: object |
| 3599 |
L0: |
| 3600 |
r0 = deco_env() |
| 3601 |
r0.fn = fn; r1 = is_error |
| 3602 |
r2 = wrapper_deco_obj() |
| 3603 |
r2.__mypyc_env__ = r0; r3 = is_error |
| 3604 |
wrapper = r2 |
| 3605 |
return wrapper |
| 3606 |
|
| 3607 |
[case testStarArgFastPathList] |
| 3608 |
from typing import Any, Callable |
| 3609 |
def deco(fn: Callable[..., Any]) -> Callable[[list[Any]], Any]: |
| 3610 |
def wrapper(args: list[Any]) -> Any: |
| 3611 |
return fn(*args) |
| 3612 |
return wrapper |
| 3613 |
|
| 3614 |
[out] |
| 3615 |
def wrapper_deco_obj.__get__(__mypyc_self__, instance, owner): |
| 3616 |
__mypyc_self__, instance, owner, r0 :: object |
| 3617 |
r1 :: bit |
| 3618 |
r2 :: object |
| 3619 |
L0: |
| 3620 |
r0 = load_address _Py_NoneStruct |
| 3621 |
r1 = instance == r0 |
| 3622 |
if r1 goto L1 else goto L2 :: bool |
| 3623 |
L1: |
| 3624 |
return __mypyc_self__ |
| 3625 |
L2: |
| 3626 |
r2 = PyMethod_New(__mypyc_self__, instance) |
| 3627 |
return r2 |
| 3628 |
def wrapper_deco_obj.__call__(__mypyc_self__, args): |
| 3629 |
__mypyc_self__ :: __main__.wrapper_deco_obj |
| 3630 |
args :: list |
| 3631 |
r0 :: __main__.deco_env |
| 3632 |
r1 :: object |
| 3633 |
r2 :: tuple |
| 3634 |
r3 :: object |
| 3635 |
L0: |
| 3636 |
r0 = __mypyc_self__.__mypyc_env__ |
| 3637 |
r1 = r0.fn |
| 3638 |
r2 = PyList_AsTuple(args) |
| 3639 |
r3 = PyObject_CallObject(r1, r2) |
| 3640 |
return r3 |
| 3641 |
def deco(fn): |
| 3642 |
fn :: object |
| 3643 |
r0 :: __main__.deco_env |
| 3644 |
r1 :: bool |
| 3645 |
r2 :: __main__.wrapper_deco_obj |
| 3646 |
r3 :: bool |
| 3647 |
wrapper :: object |
| 3648 |
L0: |
| 3649 |
r0 = deco_env() |
| 3650 |
r0.fn = fn; r1 = is_error |
| 3651 |
r2 = wrapper_deco_obj() |
| 3652 |
r2.__mypyc_env__ = r0; r3 = is_error |
| 3653 |
wrapper = r2 |
| 3654 |
return wrapper |
| 3655 |
|
| 3656 |
[case testStarArgFastPathListWithKwargs] |
| 3657 |
from typing import Any, Callable |
| 3658 |
def deco(fn: Callable[..., Any]) -> Callable[..., Any]: |
| 3659 |
def wrapper(lst: list[Any], kwargs: dict[str, Any]) -> Any: |
| 3660 |
return fn(*lst, **kwargs) |
| 3661 |
return wrapper |
| 3662 |
|
| 3663 |
[out] |
| 3664 |
def wrapper_deco_obj.__get__(__mypyc_self__, instance, owner): |
| 3665 |
__mypyc_self__, instance, owner, r0 :: object |
| 3666 |
r1 :: bit |
| 3667 |
r2 :: object |
| 3668 |
L0: |
| 3669 |
r0 = load_address _Py_NoneStruct |
| 3670 |
r1 = instance == r0 |
| 3671 |
if r1 goto L1 else goto L2 :: bool |
| 3672 |
L1: |
| 3673 |
return __mypyc_self__ |
| 3674 |
L2: |
| 3675 |
r2 = PyMethod_New(__mypyc_self__, instance) |
| 3676 |
return r2 |
| 3677 |
def wrapper_deco_obj.__call__(__mypyc_self__, lst, kwargs): |
| 3678 |
__mypyc_self__ :: __main__.wrapper_deco_obj |
| 3679 |
lst :: list |
| 3680 |
kwargs :: dict |
| 3681 |
r0 :: __main__.deco_env |
| 3682 |
r1 :: object |
| 3683 |
r2 :: tuple |
| 3684 |
r3 :: dict |
| 3685 |
r4 :: object |
| 3686 |
L0: |
| 3687 |
r0 = __mypyc_self__.__mypyc_env__ |
| 3688 |
r1 = r0.fn |
| 3689 |
r2 = PyList_AsTuple(lst) |
| 3690 |
r3 = PyDict_Copy(kwargs) |
| 3691 |
r4 = PyObject_Call(r1, r2, r3) |
| 3692 |
return r4 |
| 3693 |
def deco(fn): |
| 3694 |
fn :: object |
| 3695 |
r0 :: __main__.deco_env |
| 3696 |
r1 :: bool |
| 3697 |
r2 :: __main__.wrapper_deco_obj |
| 3698 |
r3 :: bool |
| 3699 |
wrapper :: object |
| 3700 |
L0: |
| 3701 |
r0 = deco_env() |
| 3702 |
r0.fn = fn; r1 = is_error |
| 3703 |
r2 = wrapper_deco_obj() |
| 3704 |
r2.__mypyc_env__ = r0; r3 = is_error |
| 3705 |
wrapper = r2 |
| 3706 |
return wrapper |
| 3707 |
|
| 3708 |
[case testStarArgFastPathSequence] |
| 3709 |
from typing import Any, Callable |
| 3710 |
def deco(fn: Callable[[Any], Any]) -> Callable[[Any], Any]: |
| 3711 |
def wrapper(args: Any) -> Any: |
| 3712 |
return fn(*args) |
| 3713 |
return wrapper |
| 3714 |
|
| 3715 |
[out] |
| 3716 |
def wrapper_deco_obj.__get__(__mypyc_self__, instance, owner): |
| 3717 |
__mypyc_self__, instance, owner, r0 :: object |
| 3718 |
r1 :: bit |
| 3719 |
r2 :: object |
| 3720 |
L0: |
| 3721 |
r0 = load_address _Py_NoneStruct |
| 3722 |
r1 = instance == r0 |
| 3723 |
if r1 goto L1 else goto L2 :: bool |
| 3724 |
L1: |
| 3725 |
return __mypyc_self__ |
| 3726 |
L2: |
| 3727 |
r2 = PyMethod_New(__mypyc_self__, instance) |
| 3728 |
return r2 |
| 3729 |
def wrapper_deco_obj.__call__(__mypyc_self__, args): |
| 3730 |
__mypyc_self__ :: __main__.wrapper_deco_obj |
| 3731 |
args :: object |
| 3732 |
r0 :: __main__.deco_env |
| 3733 |
r1 :: object |
| 3734 |
r2 :: tuple |
| 3735 |
r3 :: object |
| 3736 |
L0: |
| 3737 |
r0 = __mypyc_self__.__mypyc_env__ |
| 3738 |
r1 = r0.fn |
| 3739 |
r2 = PySequence_Tuple(args) |
| 3740 |
r3 = PyObject_CallObject(r1, r2) |
| 3741 |
return r3 |
| 3742 |
def deco(fn): |
| 3743 |
fn :: object |
| 3744 |
r0 :: __main__.deco_env |
| 3745 |
r1 :: bool |
| 3746 |
r2 :: __main__.wrapper_deco_obj |
| 3747 |
r3 :: bool |
| 3748 |
wrapper :: object |
| 3749 |
L0: |
| 3750 |
r0 = deco_env() |
| 3751 |
r0.fn = fn; r1 = is_error |
| 3752 |
r2 = wrapper_deco_obj() |
| 3753 |
r2.__mypyc_env__ = r0; r3 = is_error |
| 3754 |
wrapper = r2 |
| 3755 |
return wrapper |
| 3756 |
|
| 3757 |
[case testStarArgFastPathSequenceWithKwargs] |
| 3758 |
from typing import Any, Callable |
| 3759 |
def deco(fn: Callable[[Any], Any]) -> Callable[[Any], Any]: |
| 3760 |
def wrapper(args: Any, **kwargs: Any) -> Any: |
| 3761 |
return fn(*args, **kwargs) |
| 3762 |
return wrapper |
| 3763 |
|
| 3764 |
[out] |
| 3765 |
def wrapper_deco_obj.__get__(__mypyc_self__, instance, owner): |
| 3766 |
__mypyc_self__, instance, owner, r0 :: object |
| 3767 |
r1 :: bit |
| 3768 |
r2 :: object |
| 3769 |
L0: |
| 3770 |
r0 = load_address _Py_NoneStruct |
| 3771 |
r1 = instance == r0 |
| 3772 |
if r1 goto L1 else goto L2 :: bool |
| 3773 |
L1: |
| 3774 |
return __mypyc_self__ |
| 3775 |
L2: |
| 3776 |
r2 = PyMethod_New(__mypyc_self__, instance) |
| 3777 |
return r2 |
| 3778 |
def wrapper_deco_obj.__call__(__mypyc_self__, args, kwargs): |
| 3779 |
__mypyc_self__ :: __main__.wrapper_deco_obj |
| 3780 |
args :: object |
| 3781 |
kwargs :: dict |
| 3782 |
r0 :: __main__.deco_env |
| 3783 |
r1 :: object |
| 3784 |
r2 :: tuple |
| 3785 |
r3 :: dict |
| 3786 |
r4 :: object |
| 3787 |
L0: |
| 3788 |
r0 = __mypyc_self__.__mypyc_env__ |
| 3789 |
r1 = r0.fn |
| 3790 |
r2 = PySequence_Tuple(args) |
| 3791 |
r3 = PyDict_Copy(kwargs) |
| 3792 |
r4 = PyObject_Call(r1, r2, r3) |
| 3793 |
return r4 |
| 3794 |
def deco(fn): |
| 3795 |
fn :: object |
| 3796 |
r0 :: __main__.deco_env |
| 3797 |
r1 :: bool |
| 3798 |
r2 :: __main__.wrapper_deco_obj |
| 3799 |
r3 :: bool |
| 3800 |
wrapper :: object |
| 3801 |
L0: |
| 3802 |
r0 = deco_env() |
| 3803 |
r0.fn = fn; r1 = is_error |
| 3804 |
r2 = wrapper_deco_obj() |
| 3805 |
r2.__mypyc_env__ = r0; r3 = is_error |
| 3806 |
wrapper = r2 |
| 3807 |
return wrapper |
| 3808 |
|
| 3809 |
[case testStaticLength] |
| 3810 |
def get_length() -> int: |
| 3811 |
return len("https://w3id.org/cwl/salad#") |
| 3812 |
[out] |
| 3813 |
def get_length(): |
| 3814 |
r0 :: str |
| 3815 |
L0: |
| 3816 |
r0 = 'https://w3id.org/cwl/salad#' |
| 3817 |
return 54 |