| [case testTrivialFunction] | |
| def f() -> int: | |
| return 1 | |
| [out] | |
| def f(): | |
| L0: | |
| return 2 | |
| [case testFunctionArgument] | |
| def f(x: int) -> int: | |
| return x | |
| [out] | |
| def f(x): | |
| x :: int | |
| L0: | |
| return x | |
| [case testExplicitNoneReturn] | |
| def f() -> None: | |
| return | |
| [out] | |
| def f(): | |
| L0: | |
| return 1 | |
| [case testExplicitNoneReturn2] | |
| def f() -> None: | |
| return None | |
| [out] | |
| def f(): | |
| L0: | |
| return 1 | |
| [case testAssignment] | |
| def f() -> int: | |
| x = 1 | |
| y = x | |
| return y | |
| [out] | |
| def f(): | |
| x, y :: int | |
| L0: | |
| x = 2 | |
| y = x | |
| return y | |
| [case testAssignmentTwice] | |
| def f(x: int) -> None: | |
| y = 1 | |
| y = x | |
| return | |
| [out] | |
| def f(x): | |
| x, y :: int | |
| L0: | |
| y = 2 | |
| y = x | |
| return 1 | |
| [case testIntArithmetic] | |
| def f(x: int, y: int) -> int: | |
| return x * (y + 1) | |
| [out] | |
| def f(x, y): | |
| x, y, r0, r1 :: int | |
| L0: | |
| r0 = CPyTagged_Add(y, 2) | |
| r1 = CPyTagged_Multiply(x, r0) | |
| return r1 | |
| [case testIf] | |
| def f(x: int, y: int) -> int: | |
| if x < y: | |
| x = 1 | |
| return x | |
| [out] | |
| def f(x, y): | |
| x, y :: int | |
| r0 :: bit | |
| L0: | |
| r0 = int_lt x, y | |
| if r0 goto L1 else goto L2 :: bool | |
| L1: | |
| x = 2 | |
| L2: | |
| return x | |
| [case testIfElse] | |
| def f(x: int, y: int) -> int: | |
| if x < y: | |
| x = 1 | |
| else: | |
| x = 2 | |
| return x | |
| [out] | |
| def f(x, y): | |
| x, y :: int | |
| r0 :: bit | |
| L0: | |
| r0 = int_lt x, y | |
| if r0 goto L1 else goto L2 :: bool | |
| L1: | |
| x = 2 | |
| goto L3 | |
| L2: | |
| x = 4 | |
| L3: | |
| return x | |
| [case testAnd1] | |
| def f(x: int, y: int) -> int: | |
| if x < y and x > y: | |
| x = 1 | |
| else: | |
| x = 2 | |
| return x | |
| [out] | |
| def f(x, y): | |
| x, y :: int | |
| r0, r1 :: bit | |
| L0: | |
| r0 = int_lt x, y | |
| if r0 goto L1 else goto L3 :: bool | |
| L1: | |
| r1 = int_gt x, y | |
| if r1 goto L2 else goto L3 :: bool | |
| L2: | |
| x = 2 | |
| goto L4 | |
| L3: | |
| x = 4 | |
| L4: | |
| return x | |
| [case testAnd2] | |
| def f(x: object, y: object) -> str: | |
| return str(x) or str(y) | |
| [out] | |
| def f(x, y): | |
| x, y :: object | |
| r0 :: str | |
| r1 :: bit | |
| r2, r3 :: str | |
| L0: | |
| r0 = PyObject_Str(x) | |
| r1 = CPyStr_IsTrue(r0) | |
| if r1 goto L1 else goto L2 :: bool | |
| L1: | |
| r2 = r0 | |
| goto L3 | |
| L2: | |
| r3 = PyObject_Str(y) | |
| r2 = r3 | |
| L3: | |
| return r2 | |
| [case testOr] | |
| def f(x: int, y: int) -> int: | |
| if x < y or x > y: | |
| x = 1 | |
| else: | |
| x = 2 | |
| return x | |
| [out] | |
| def f(x, y): | |
| x, y :: int | |
| r0, r1 :: bit | |
| L0: | |
| r0 = int_lt x, y | |
| if r0 goto L2 else goto L1 :: bool | |
| L1: | |
| r1 = int_gt x, y | |
| if r1 goto L2 else goto L3 :: bool | |
| L2: | |
| x = 2 | |
| goto L4 | |
| L3: | |
| x = 4 | |
| L4: | |
| return x | |
| [case testOr2] | |
| def f(x: object, y: object) -> str: | |
| return str(x) and str(y) | |
| [out] | |
| def f(x, y): | |
| x, y :: object | |
| r0 :: str | |
| r1 :: bit | |
| r2, r3 :: str | |
| L0: | |
| r0 = PyObject_Str(x) | |
| r1 = CPyStr_IsTrue(r0) | |
| if r1 goto L2 else goto L1 :: bool | |
| L1: | |
| r2 = r0 | |
| goto L3 | |
| L2: | |
| r3 = PyObject_Str(y) | |
| r2 = r3 | |
| L3: | |
| return r2 | |
| [case testSimpleNot] | |
| def f(x: int, y: int) -> int: | |
| if not (x < y): | |
| x = 1 | |
| return x | |
| [out] | |
| def f(x, y): | |
| x, y :: int | |
| r0 :: bit | |
| L0: | |
| r0 = int_lt x, y | |
| if r0 goto L2 else goto L1 :: bool | |
| L1: | |
| x = 2 | |
| L2: | |
| return x | |
| [case testNotAnd] | |
| def f(x: int, y: int) -> int: | |
| if not (x < y and x > y): | |
| x = 1 | |
| return x | |
| [out] | |
| def f(x, y): | |
| x, y :: int | |
| r0, r1 :: bit | |
| L0: | |
| r0 = int_lt x, y | |
| if r0 goto L1 else goto L2 :: bool | |
| L1: | |
| r1 = int_gt x, y | |
| if r1 goto L3 else goto L2 :: bool | |
| L2: | |
| x = 2 | |
| L3: | |
| return x | |
| [case testWhile] | |
| def f(x: int, y: int) -> int: | |
| while x > y: | |
| x = x - y | |
| return x | |
| [out] | |
| def f(x, y): | |
| x, y :: int | |
| r0 :: bit | |
| r1 :: int | |
| L0: | |
| L1: | |
| r0 = int_gt x, y | |
| if r0 goto L2 else goto L3 :: bool | |
| L2: | |
| r1 = CPyTagged_Subtract(x, y) | |
| x = r1 | |
| goto L1 | |
| L3: | |
| return x | |
| [case testWhile2] | |
| def f(x: int, y: int) -> int: | |
| x = 1 | |
| while x > y: | |
| x = x - y | |
| return x | |
| [out] | |
| def f(x, y): | |
| x, y :: int | |
| r0 :: bit | |
| r1 :: int | |
| L0: | |
| x = 2 | |
| L1: | |
| r0 = int_gt x, y | |
| if r0 goto L2 else goto L3 :: bool | |
| L2: | |
| r1 = CPyTagged_Subtract(x, y) | |
| x = r1 | |
| goto L1 | |
| L3: | |
| return x | |
| [case testImplicitNoneReturn] | |
| def f() -> None: | |
| pass | |
| [out] | |
| def f(): | |
| L0: | |
| return 1 | |
| [case testImplicitNoneReturn2] | |
| def f() -> None: | |
| x = 1 | |
| [out] | |
| def f(): | |
| x :: int | |
| L0: | |
| x = 2 | |
| return 1 | |
| [case testImplicitNoneReturnAndIf] | |
| def f(x: int, y: int) -> None: | |
| if x < y: | |
| x = 1 | |
| else: | |
| y = 2 | |
| [out] | |
| def f(x, y): | |
| x, y :: int | |
| r0 :: bit | |
| L0: | |
| r0 = int_lt x, y | |
| if r0 goto L1 else goto L2 :: bool | |
| L1: | |
| x = 2 | |
| goto L3 | |
| L2: | |
| y = 4 | |
| L3: | |
| return 1 | |
| [case testRecursion] | |
| def f(n: int) -> int: | |
| if n <= 1: | |
| return 1 | |
| else: | |
| return f(n - 1) + f(n - 2) | |
| [out] | |
| def f(n): | |
| n :: int | |
| r0 :: bit | |
| r1, r2, r3, r4, r5 :: int | |
| L0: | |
| r0 = int_le n, 2 | |
| if r0 goto L1 else goto L2 :: bool | |
| L1: | |
| return 2 | |
| L2: | |
| r1 = CPyTagged_Subtract(n, 2) | |
| r2 = f(r1) | |
| r3 = CPyTagged_Subtract(n, 4) | |
| r4 = f(r3) | |
| r5 = CPyTagged_Add(r2, r4) | |
| return r5 | |
| L3: | |
| unreachable | |
| [case testReportTypeCheckError] | |
| def f() -> None: | |
| return 1 # E: No return value expected | |
| [case testReportSemanticaAnalysisError1] | |
| def f(x: List[int]) -> None: pass # E: Name "List" is not defined \ | |
| # N: Did you forget to import it from "typing"? (Suggestion: "from typing import List") | |
| [case testReportSemanticaAnalysisError2] | |
| def f() -> None: | |
| x # E: Name "x" is not defined | |
| [case testElif] | |
| def f(n: int) -> int: | |
| if n < 0: | |
| x = 1 | |
| elif n == 0: | |
| x = 1 | |
| else: | |
| x = 2 | |
| return x | |
| [out] | |
| def f(n): | |
| n :: int | |
| r0 :: bit | |
| x :: int | |
| r1 :: bit | |
| L0: | |
| r0 = int_lt n, 0 | |
| if r0 goto L1 else goto L2 :: bool | |
| L1: | |
| x = 2 | |
| goto L6 | |
| L2: | |
| r1 = int_eq n, 0 | |
| if r1 goto L3 else goto L4 :: bool | |
| L3: | |
| x = 2 | |
| goto L5 | |
| L4: | |
| x = 4 | |
| L5: | |
| L6: | |
| return x | |
| [case testUnaryMinus] | |
| def f(n: int) -> int: | |
| return -n | |
| [out] | |
| def f(n): | |
| n, r0 :: int | |
| L0: | |
| r0 = CPyTagged_Negate(n) | |
| return r0 | |
| [case testConditionalExpr] | |
| def f(n: int) -> int: | |
| return 0 if n == 0 else 1 | |
| [out] | |
| def f(n): | |
| n :: int | |
| r0 :: bit | |
| r1 :: int | |
| L0: | |
| r0 = int_eq n, 0 | |
| if r0 goto L1 else goto L2 :: bool | |
| L1: | |
| r1 = 0 | |
| goto L3 | |
| L2: | |
| r1 = 2 | |
| L3: | |
| return r1 | |
| [case testOperatorAssignment] | |
| def f() -> int: | |
| x = 0 | |
| x += 1 | |
| return x | |
| [out] | |
| def f(): | |
| x, r0 :: int | |
| L0: | |
| x = 0 | |
| r0 = CPyTagged_Add(x, 2) | |
| x = r0 | |
| return x | |
| [case testTrue] | |
| def f() -> bool: | |
| return True | |
| [out] | |
| def f(): | |
| L0: | |
| return 1 | |
| [case testFalse] | |
| def f() -> bool: | |
| return False | |
| [out] | |
| def f(): | |
| L0: | |
| return 0 | |
| [case testBoolCond] | |
| def f(x: bool) -> bool: | |
| if x: | |
| return False | |
| else: | |
| return True | |
| [out] | |
| def f(x): | |
| x :: bool | |
| L0: | |
| if x goto L1 else goto L2 :: bool | |
| L1: | |
| return 0 | |
| L2: | |
| return 1 | |
| L3: | |
| unreachable | |
| [case testPycall] | |
| import testmodule | |
| def f(x: int) -> int: | |
| return testmodule.factorial(x) | |
| [file testmodule.py] | |
| def factorial(x: int) -> int: | |
| if x == 0: | |
| return 1 | |
| else: | |
| return x * factorial(x-1) | |
| [out] | |
| def f(x): | |
| x :: int | |
| r0 :: object | |
| r1 :: str | |
| r2, r3 :: object | |
| r4 :: object[1] | |
| r5 :: object_ptr | |
| r6 :: object | |
| r7 :: int | |
| L0: | |
| r0 = testmodule :: module | |
| r1 = 'factorial' | |
| r2 = CPyObject_GetAttr(r0, r1) | |
| r3 = box(int, x) | |
| r4 = [r3] | |
| r5 = load_address r4 | |
| r6 = PyObject_Vectorcall(r2, r5, 1, 0) | |
| keep_alive r3 | |
| r7 = unbox(int, r6) | |
| return r7 | |
| [case testImport_toplevel] | |
| import sys | |
| import enum as enum2 | |
| import collections.abc | |
| import collections.abc as abc2 | |
| _ = "filler" | |
| import single | |
| single.hello() | |
| [file single.py] | |
| def hello() -> None: | |
| print("hello, world") | |
| [out] | |
| def __top_level__(): | |
| r0 :: c_ptr | |
| r1 :: str | |
| r2, r3 :: object | |
| r4 :: bit | |
| r5 :: object | |
| r6, r7, r8, r9 :: c_ptr | |
| r10 :: c_ptr[4] | |
| r11 :: c_ptr | |
| r12 :: native_int[4] | |
| r13 :: c_ptr | |
| r14 :: object | |
| r15 :: dict | |
| r16, r17 :: str | |
| r18 :: bit | |
| r19 :: str | |
| r20 :: dict | |
| r21 :: str | |
| r22 :: i32 | |
| r23 :: bit | |
| r24 :: c_ptr | |
| r25 :: c_ptr[1] | |
| r26 :: c_ptr | |
| r27 :: native_int[1] | |
| r28 :: c_ptr | |
| r29 :: object | |
| r30 :: dict | |
| r31, r32 :: str | |
| r33 :: bit | |
| r34 :: object | |
| r35 :: str | |
| r36, r37 :: object | |
| L0: | |
| r0 = load_address builtins :: module | |
| r1 = 'builtins' | |
| r2 = CPyImport_GetModuleCacheForImport(r0, r1) | |
| r3 = load_address _Py_NoneStruct | |
| r4 = r2 != r3 | |
| if r4 goto L2 else goto L1 :: bool | |
| L1: | |
| r5 = PyImport_Import(r1) | |
| CPyImport_ReplaceModuleCacheForImport(r0, r5) | |
| L2: | |
| r6 = load_address sys :: module | |
| r7 = load_address enum :: module | |
| r8 = load_address collections.abc :: module | |
| r9 = load_address collections.abc :: module | |
| r10 = [r6, r7, r8, r9] | |
| r11 = load_address r10 | |
| r12 = [1, 2, 3, 4] | |
| r13 = load_address r12 | |
| r14 = (('sys', 'sys', 'sys'), ('enum', 'enum', 'enum2'), ('collections.abc', 'collections', 'collections'), ('collections.abc', 'collections.abc', 'abc2')) | |
| r15 = __main__.globals :: static | |
| r16 = 'main' | |
| r17 = '<module>' | |
| r18 = CPyImport_ImportMany(r14, r11, r15, r16, r17, r13) | |
| r19 = 'filler' | |
| keep_alive r0 | |
| r20 = __main__.globals :: static | |
| r21 = '_' | |
| r22 = CPyDict_SetItem(r20, r21, r19) | |
| r23 = r22 >= 0 :: signed | |
| r24 = load_address single :: module | |
| r25 = [r24] | |
| r26 = load_address r25 | |
| r27 = [6] | |
| r28 = load_address r27 | |
| r29 = (('single', 'single', 'single'),) | |
| r30 = __main__.globals :: static | |
| r31 = 'main' | |
| r32 = '<module>' | |
| r33 = CPyImport_ImportMany(r29, r26, r30, r31, r32, r28) | |
| r34 = single :: module | |
| r35 = 'hello' | |
| r36 = CPyObject_GetAttr(r34, r35) | |
| r37 = PyObject_Vectorcall(r36, 0, 0, 0) | |
| return 1 | |
| [case testFromImport_toplevel] | |
| from testmodule import g, h | |
| from testmodule import h as two | |
| def f(x: int) -> int: | |
| return g(x) + h() + two() | |
| [file testmodule.py] | |
| def g(x: int) -> int: | |
| return x + 1 | |
| def h() -> int: | |
| return 2 | |
| [out] | |
| def f(x): | |
| x :: int | |
| r0 :: dict | |
| r1 :: str | |
| r2, r3 :: object | |
| r4 :: object[1] | |
| r5 :: object_ptr | |
| r6 :: object | |
| r7 :: int | |
| r8 :: dict | |
| r9 :: str | |
| r10, r11 :: object | |
| r12, r13 :: int | |
| r14 :: dict | |
| r15 :: str | |
| r16, r17 :: object | |
| r18, r19 :: int | |
| L0: | |
| r0 = __main__.globals :: static | |
| r1 = 'g' | |
| r2 = CPyDict_GetItem(r0, r1) | |
| r3 = box(int, x) | |
| r4 = [r3] | |
| r5 = load_address r4 | |
| r6 = PyObject_Vectorcall(r2, r5, 1, 0) | |
| keep_alive r3 | |
| r7 = unbox(int, r6) | |
| r8 = __main__.globals :: static | |
| r9 = 'h' | |
| r10 = CPyDict_GetItem(r8, r9) | |
| r11 = PyObject_Vectorcall(r10, 0, 0, 0) | |
| r12 = unbox(int, r11) | |
| r13 = CPyTagged_Add(r7, r12) | |
| r14 = __main__.globals :: static | |
| r15 = 'two' | |
| r16 = CPyDict_GetItem(r14, r15) | |
| r17 = PyObject_Vectorcall(r16, 0, 0, 0) | |
| r18 = unbox(int, r17) | |
| r19 = CPyTagged_Add(r13, r18) | |
| return r19 | |
| def __top_level__(): | |
| r0 :: c_ptr | |
| r1 :: str | |
| r2, r3 :: object | |
| r4 :: bit | |
| r5, r6 :: object | |
| r7 :: str | |
| r8 :: dict | |
| r9 :: object | |
| r10 :: c_ptr | |
| r11, r12 :: object | |
| r13 :: str | |
| r14 :: dict | |
| r15 :: object | |
| r16 :: c_ptr | |
| L0: | |
| r0 = load_address builtins :: module | |
| r1 = 'builtins' | |
| r2 = CPyImport_GetModuleCacheForImport(r0, r1) | |
| r3 = load_address _Py_NoneStruct | |
| r4 = r2 != r3 | |
| if r4 goto L2 else goto L1 :: bool | |
| L1: | |
| r5 = PyImport_Import(r1) | |
| CPyImport_ReplaceModuleCacheForImport(r0, r5) | |
| L2: | |
| r6 = ('g', 'h') | |
| r7 = 'testmodule' | |
| r8 = __main__.globals :: static | |
| r9 = CPyImport_ImportFromMany(r7, r6, r6, r8) | |
| r10 = load_address testmodule :: module | |
| CPyImport_ReplaceModuleCacheForImport(r10, r9) | |
| r11 = ('h',) | |
| r12 = ('two',) | |
| r13 = 'testmodule' | |
| r14 = __main__.globals :: static | |
| r15 = CPyImport_ImportFromMany(r13, r11, r12, r14) | |
| r16 = load_address testmodule :: module | |
| CPyImport_ReplaceModuleCacheForImport(r16, r15) | |
| return 1 | |
| [case testPrintFullname] | |
| import builtins | |
| def f(x: int) -> None: | |
| builtins.print(5) | |
| [out] | |
| def f(x): | |
| x :: int | |
| r0 :: object | |
| r1 :: str | |
| r2, r3 :: object | |
| r4 :: object[1] | |
| r5 :: object_ptr | |
| r6 :: object | |
| L0: | |
| r0 = builtins :: module | |
| r1 = 'print' | |
| r2 = CPyObject_GetAttr(r0, r1) | |
| r3 = object 5 | |
| r4 = [r3] | |
| r5 = load_address r4 | |
| r6 = PyObject_Vectorcall(r2, r5, 1, 0) | |
| keep_alive r3 | |
| return 1 | |
| [case testPrint] | |
| import builtins | |
| def f(x: int) -> None: | |
| print(5) | |
| [out] | |
| def f(x): | |
| x :: int | |
| r0 :: object | |
| r1 :: str | |
| r2, r3 :: object | |
| r4 :: object[1] | |
| r5 :: object_ptr | |
| r6 :: object | |
| L0: | |
| r0 = builtins :: module | |
| r1 = 'print' | |
| r2 = CPyObject_GetAttr(r0, r1) | |
| r3 = object 5 | |
| r4 = [r3] | |
| r5 = load_address r4 | |
| r6 = PyObject_Vectorcall(r2, r5, 1, 0) | |
| keep_alive r3 | |
| return 1 | |
| [case testUnicodeLiteral] | |
| def f() -> str: | |
| x = "some string" | |
| return "some other string" | |
| [out] | |
| def f(): | |
| r0, x, r1 :: str | |
| L0: | |
| r0 = 'some string' | |
| x = r0 | |
| r1 = 'some other string' | |
| return r1 | |
| [case testBytesLiteral] | |
| def f() -> bytes: | |
| x = b'\xf0' | |
| return b'1234' | |
| [out] | |
| def f(): | |
| r0, x, r1 :: bytes | |
| L0: | |
| r0 = b'\xf0' | |
| x = r0 | |
| r1 = b'1234' | |
| return r1 | |
| [case testPyMethodCall1_64bit] | |
| from typing import Any | |
| def f(x: Any) -> int: | |
| y: int = x.pop() | |
| return x.pop() | |
| [out] | |
| def f(x): | |
| x :: object | |
| r0 :: str | |
| r1 :: object[1] | |
| r2 :: object_ptr | |
| r3 :: object | |
| r4, y :: int | |
| r5 :: str | |
| r6 :: object[1] | |
| r7 :: object_ptr | |
| r8 :: object | |
| r9 :: int | |
| L0: | |
| r0 = 'pop' | |
| r1 = [x] | |
| r2 = load_address r1 | |
| r3 = PyObject_VectorcallMethod(r0, r2, 9223372036854775809, 0) | |
| keep_alive x | |
| r4 = unbox(int, r3) | |
| y = r4 | |
| r5 = 'pop' | |
| r6 = [x] | |
| r7 = load_address r6 | |
| r8 = PyObject_VectorcallMethod(r5, r7, 9223372036854775809, 0) | |
| keep_alive x | |
| r9 = unbox(int, r8) | |
| return r9 | |
| [case testObjectType] | |
| def g(y: object) -> None: | |
| g(y) | |
| g([1]) | |
| g(None) | |
| [out] | |
| def g(y): | |
| y :: object | |
| r0 :: None | |
| r1 :: list | |
| r2 :: object | |
| r3 :: ptr | |
| r4 :: None | |
| r5 :: object | |
| r6 :: None | |
| L0: | |
| r0 = g(y) | |
| r1 = PyList_New(1) | |
| r2 = object 1 | |
| r3 = list_items r1 | |
| buf_init_item r3, 0, r2 | |
| keep_alive r1 | |
| r4 = g(r1) | |
| r5 = box(None, 1) | |
| r6 = g(r5) | |
| return 1 | |
| [case testCoerceToObject1] | |
| def g(y: object) -> object: | |
| g(1) | |
| a = [y] | |
| a[0] = (1, 2) | |
| y = True | |
| return 3 | |
| [out] | |
| def g(y): | |
| y, r0, r1 :: object | |
| r2 :: list | |
| r3 :: ptr | |
| a :: list | |
| r4 :: tuple[int, int] | |
| r5 :: object | |
| r6 :: bit | |
| r7, r8 :: object | |
| L0: | |
| r0 = object 1 | |
| r1 = g(r0) | |
| r2 = PyList_New(1) | |
| r3 = list_items r2 | |
| buf_init_item r3, 0, y | |
| keep_alive r2 | |
| a = r2 | |
| r4 = (2, 4) | |
| r5 = box(tuple[int, int], r4) | |
| r6 = CPyList_SetItem(a, 0, r5) | |
| r7 = box(bool, 1) | |
| y = r7 | |
| r8 = object 3 | |
| return r8 | |
| [case testCoerceToObject2] | |
| class A: | |
| x: object | |
| n: int | |
| def f(a: A, o: object) -> None: | |
| a.x = 1 | |
| o = a.n | |
| [out] | |
| def f(a, o): | |
| a :: __main__.A | |
| o, r0 :: object | |
| r1 :: bool | |
| r2 :: int | |
| r3 :: object | |
| L0: | |
| r0 = object 1 | |
| a.x = r0; r1 = is_error | |
| r2 = a.n | |
| r3 = box(int, r2) | |
| o = r3 | |
| return 1 | |
| [case testAssertType] | |
| from typing import assert_type | |
| def f(x: int) -> None: | |
| y = assert_type(x, int) | |
| [out] | |
| def f(x): | |
| x, y :: int | |
| L0: | |
| y = x | |
| return 1 | |
| [case testDownCast] | |
| from typing import cast, List, Tuple | |
| class A: pass | |
| def f(x: object) -> None: | |
| n = cast(int, x) | |
| b = cast(bool, x) | |
| a = cast(A, x) | |
| l = cast(List[int], x) | |
| t = cast(Tuple[int, A], x) | |
| [out] | |
| def f(x): | |
| x :: object | |
| r0, n :: int | |
| r1, b :: bool | |
| r2, a :: __main__.A | |
| r3, l :: list | |
| r4, t :: tuple[int, __main__.A] | |
| L0: | |
| r0 = unbox(int, x) | |
| n = r0 | |
| r1 = unbox(bool, x) | |
| b = r1 | |
| r2 = cast(__main__.A, x) | |
| a = r2 | |
| r3 = cast(list, x) | |
| l = r3 | |
| r4 = unbox(tuple[int, __main__.A], x) | |
| t = r4 | |
| return 1 | |
| [case testDownCastSpecialCases] | |
| from typing import cast, Optional, Tuple | |
| class A: pass | |
| def f(o: Optional[A], n: int, t: Tuple[int, ...], tt: Tuple[int, int]) -> None: | |
| a = cast(A, o) | |
| m = cast(bool, n) | |
| t = tt | |
| [out] | |
| def f(o, n, t, tt): | |
| o :: union[__main__.A, None] | |
| n :: int | |
| t :: tuple | |
| tt :: tuple[int, int] | |
| r0, a :: __main__.A | |
| r1 :: object | |
| r2, m :: bool | |
| r3 :: object | |
| L0: | |
| r0 = cast(__main__.A, o) | |
| a = r0 | |
| r1 = box(int, n) | |
| r2 = unbox(bool, r1) | |
| m = r2 | |
| r3 = box(tuple[int, int], tt) | |
| t = r3 | |
| return 1 | |
| [case testSuccessfulCast] | |
| from typing import cast, Optional, Tuple, List, Dict | |
| class A: pass | |
| def f(o: object, | |
| p: Optional[A], | |
| n: int, | |
| b: bool, | |
| t: Tuple[int, ...], | |
| s: Tuple[int, int], | |
| a: A, | |
| l: List[A], | |
| d: Dict[int, str]) -> None: | |
| o = cast(object, o) | |
| p = cast(Optional[A], p) | |
| n = cast(int, n) | |
| b = cast(bool, b) | |
| t = cast(Tuple[int, ...], t) | |
| s = cast(Tuple[int, int], s) | |
| o = cast(object, n) | |
| a = cast(A, a) | |
| l2 = cast(List[object], l) | |
| d2 = cast(Dict[object, str], d) | |
| [out] | |
| def f(o, p, n, b, t, s, a, l, d): | |
| o :: object | |
| p :: union[__main__.A, None] | |
| n :: int | |
| b :: bool | |
| t :: tuple | |
| s :: tuple[int, int] | |
| a :: __main__.A | |
| l :: list | |
| d :: dict | |
| r0 :: object | |
| l2 :: list | |
| d2 :: dict | |
| L0: | |
| o = o | |
| p = p | |
| n = n | |
| b = b | |
| t = t | |
| s = s | |
| r0 = box(int, n) | |
| o = r0 | |
| a = a | |
| l2 = l | |
| d2 = d | |
| return 1 | |
| [case testGenericSetItem] | |
| from typing import Any | |
| def f(x: Any, y: Any, z: Any) -> None: | |
| x[y] = z | |
| [out] | |
| def f(x, y, z): | |
| x, y, z :: object | |
| r0 :: i32 | |
| r1 :: bit | |
| L0: | |
| r0 = PyObject_SetItem(x, y, z) | |
| r1 = r0 >= 0 :: signed | |
| return 1 | |
| [case testLoadFloatSum] | |
| def assign_and_return_float_sum() -> float: | |
| f1 = 1.0 | |
| f2 = 2.0 | |
| f3 = 3.0 | |
| return f1 * f2 + f3 | |
| [out] | |
| def assign_and_return_float_sum(): | |
| f1, f2, f3, r0, r1 :: float | |
| L0: | |
| f1 = 1.0 | |
| f2 = 2.0 | |
| f3 = 3.0 | |
| r0 = f1 * f2 | |
| r1 = r0 + f3 | |
| return r1 | |
| [case testLoadComplex] | |
| def load() -> complex: | |
| real = 1 | |
| return 5j+real | |
| [out] | |
| def load(): | |
| real :: int | |
| r0, r1, r2 :: object | |
| L0: | |
| real = 2 | |
| r0 = 5j | |
| r1 = box(int, real) | |
| r2 = PyNumber_Add(r0, r1) | |
| return r2 | |
| [case testBigIntLiteral_64bit] | |
| def big_int() -> None: | |
| a_62_bit = 4611686018427387902 | |
| max_62_bit = 4611686018427387903 | |
| b_63_bit = 4611686018427387904 | |
| c_63_bit = 9223372036854775806 | |
| max_63_bit = 9223372036854775807 | |
| d_64_bit = 9223372036854775808 | |
| max_32_bit = 2147483647 | |
| max_31_bit = 1073741823 | |
| [out] | |
| def big_int(): | |
| 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 | |
| L0: | |
| a_62_bit = 9223372036854775804 | |
| max_62_bit = 9223372036854775806 | |
| r0 = object 4611686018427387904 | |
| b_63_bit = r0 | |
| r1 = object 9223372036854775806 | |
| c_63_bit = r1 | |
| r2 = object 9223372036854775807 | |
| max_63_bit = r2 | |
| r3 = object 9223372036854775808 | |
| d_64_bit = r3 | |
| max_32_bit = 4294967294 | |
| max_31_bit = 2147483646 | |
| return 1 | |
| [case testBigIntLiteral_32bit] | |
| def big_int() -> None: | |
| a_62_bit = 4611686018427387902 | |
| max_62_bit = 4611686018427387903 | |
| b_63_bit = 4611686018427387904 | |
| c_63_bit = 9223372036854775806 | |
| max_63_bit = 9223372036854775807 | |
| d_64_bit = 9223372036854775808 | |
| max_32_bit = 2147483647 | |
| max_31_bit = 1073741823 | |
| [out] | |
| def big_int(): | |
| 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 | |
| L0: | |
| r0 = object 4611686018427387902 | |
| a_62_bit = r0 | |
| r1 = object 4611686018427387903 | |
| max_62_bit = r1 | |
| r2 = object 4611686018427387904 | |
| b_63_bit = r2 | |
| r3 = object 9223372036854775806 | |
| c_63_bit = r3 | |
| r4 = object 9223372036854775807 | |
| max_63_bit = r4 | |
| r5 = object 9223372036854775808 | |
| d_64_bit = r5 | |
| r6 = object 2147483647 | |
| max_32_bit = r6 | |
| max_31_bit = 2147483646 | |
| return 1 | |
| [case testCallableTypes] | |
| from typing import Callable, Any | |
| from m import f | |
| def absolute_value(x: int) -> int: | |
| return x if x > 0 else -x | |
| def call_native_function(x: int) -> int: | |
| return absolute_value(x) | |
| def call_python_function(x: int) -> int: | |
| return f(x) | |
| def return_float() -> float: | |
| return 5.0 | |
| def return_callable_type() -> Callable[[], float]: | |
| return return_float | |
| def call_callable_type() -> float: | |
| f = return_callable_type() | |
| return f() | |
| [file m.py] | |
| def f(x: int) -> int: | |
| return x | |
| [out] | |
| def absolute_value(x): | |
| x :: int | |
| r0 :: bit | |
| r1, r2 :: int | |
| L0: | |
| r0 = int_gt x, 0 | |
| if r0 goto L1 else goto L2 :: bool | |
| L1: | |
| r1 = x | |
| goto L3 | |
| L2: | |
| r2 = CPyTagged_Negate(x) | |
| r1 = r2 | |
| L3: | |
| return r1 | |
| def call_native_function(x): | |
| x, r0 :: int | |
| L0: | |
| r0 = absolute_value(x) | |
| return r0 | |
| def call_python_function(x): | |
| x :: int | |
| r0 :: dict | |
| r1 :: str | |
| r2, r3 :: object | |
| r4 :: object[1] | |
| r5 :: object_ptr | |
| r6 :: object | |
| r7 :: int | |
| L0: | |
| r0 = __main__.globals :: static | |
| r1 = 'f' | |
| r2 = CPyDict_GetItem(r0, r1) | |
| r3 = box(int, x) | |
| r4 = [r3] | |
| r5 = load_address r4 | |
| r6 = PyObject_Vectorcall(r2, r5, 1, 0) | |
| keep_alive r3 | |
| r7 = unbox(int, r6) | |
| return r7 | |
| def return_float(): | |
| L0: | |
| return 5.0 | |
| def return_callable_type(): | |
| r0 :: dict | |
| r1 :: str | |
| r2 :: object | |
| L0: | |
| r0 = __main__.globals :: static | |
| r1 = 'return_float' | |
| r2 = CPyDict_GetItem(r0, r1) | |
| return r2 | |
| def call_callable_type(): | |
| r0, f, r1 :: object | |
| r2 :: float | |
| L0: | |
| r0 = return_callable_type() | |
| f = r0 | |
| r1 = PyObject_Vectorcall(f, 0, 0, 0) | |
| r2 = unbox(float, r1) | |
| return r2 | |
| [case testCallableTypesWithKeywordArgs_64bit] | |
| from typing import List | |
| def call_python_function_with_keyword_arg(x: str) -> int: | |
| return int(x, base=2) | |
| def call_python_method_with_keyword_args(xs: List[int], first: int, second: int) -> List[int]: | |
| xs.insert(0, x=first) | |
| xs.insert(x=second, i=1) | |
| return xs | |
| [out] | |
| def call_python_function_with_keyword_arg(x): | |
| x :: str | |
| r0, r1 :: object | |
| r2 :: object[2] | |
| r3 :: object_ptr | |
| r4, r5 :: object | |
| r6 :: int | |
| L0: | |
| r0 = load_address PyLong_Type | |
| r1 = object 2 | |
| r2 = [x, r1] | |
| r3 = load_address r2 | |
| r4 = ('base',) | |
| r5 = PyObject_Vectorcall(r0, r3, 1, r4) | |
| keep_alive x, r1 | |
| r6 = unbox(int, r5) | |
| return r6 | |
| def call_python_method_with_keyword_args(xs, first, second): | |
| xs :: list | |
| first, second :: int | |
| r0 :: str | |
| r1, r2 :: object | |
| r3 :: object[3] | |
| r4 :: object_ptr | |
| r5, r6 :: object | |
| r7 :: str | |
| r8, r9 :: object | |
| r10 :: object[3] | |
| r11 :: object_ptr | |
| r12, r13 :: object | |
| L0: | |
| r0 = 'insert' | |
| r1 = object 0 | |
| r2 = box(int, first) | |
| r3 = [xs, r1, r2] | |
| r4 = load_address r3 | |
| r5 = ('x',) | |
| r6 = PyObject_VectorcallMethod(r0, r4, 9223372036854775810, r5) | |
| keep_alive xs, r1, r2 | |
| r7 = 'insert' | |
| r8 = box(int, second) | |
| r9 = object 1 | |
| r10 = [xs, r8, r9] | |
| r11 = load_address r10 | |
| r12 = ('x', 'i') | |
| r13 = PyObject_VectorcallMethod(r7, r11, 9223372036854775809, r12) | |
| keep_alive xs, r8, r9 | |
| return xs | |
| [case testObjectAsBoolean] | |
| from typing import List | |
| def obj(x: object) -> int: | |
| if x: | |
| return 1 | |
| else: | |
| return 0 | |
| def num(x: int) -> int: | |
| if x: | |
| return 1 | |
| else: | |
| return 0 | |
| def lst(x: List[int]) -> int: | |
| if x: | |
| return 1 | |
| else: | |
| return 0 | |
| [out] | |
| def obj(x): | |
| x :: object | |
| r0 :: i32 | |
| r1 :: bit | |
| r2 :: bool | |
| L0: | |
| r0 = PyObject_IsTrue(x) | |
| r1 = r0 >= 0 :: signed | |
| r2 = truncate r0: i32 to builtins.bool | |
| if r2 goto L1 else goto L2 :: bool | |
| L1: | |
| return 2 | |
| L2: | |
| return 0 | |
| L3: | |
| unreachable | |
| def num(x): | |
| x :: int | |
| r0 :: bit | |
| L0: | |
| r0 = x != 0 | |
| if r0 goto L1 else goto L2 :: bool | |
| L1: | |
| return 2 | |
| L2: | |
| return 0 | |
| L3: | |
| unreachable | |
| def lst(x): | |
| x :: list | |
| r0 :: native_int | |
| r1 :: short_int | |
| r2 :: bit | |
| L0: | |
| r0 = var_object_size x | |
| r1 = r0 << 1 | |
| r2 = int_ne r1, 0 | |
| if r2 goto L1 else goto L2 :: bool | |
| L1: | |
| return 2 | |
| L2: | |
| return 0 | |
| L3: | |
| unreachable | |
| [case testOptionalAsBoolean] | |
| from typing import Optional | |
| class A: pass | |
| def opt_int(x: Optional[int]) -> int: | |
| if x: | |
| return 1 | |
| else: | |
| return 0 | |
| def opt_a(x: Optional[A]) -> int: | |
| if x: | |
| return 1 | |
| else: | |
| return 0 | |
| def opt_o(x: Optional[object]) -> int: | |
| if x: | |
| return 1 | |
| else: | |
| return 0 | |
| [out] | |
| def opt_int(x): | |
| x :: union[int, None] | |
| r0 :: object | |
| r1 :: bit | |
| r2 :: int | |
| r3 :: bit | |
| L0: | |
| r0 = load_address _Py_NoneStruct | |
| r1 = x != r0 | |
| if r1 goto L1 else goto L3 :: bool | |
| L1: | |
| r2 = unbox(int, x) | |
| r3 = r2 != 0 | |
| if r3 goto L2 else goto L3 :: bool | |
| L2: | |
| return 2 | |
| L3: | |
| return 0 | |
| L4: | |
| unreachable | |
| def opt_a(x): | |
| x :: union[__main__.A, None] | |
| r0 :: object | |
| r1 :: bit | |
| L0: | |
| r0 = load_address _Py_NoneStruct | |
| r1 = x != r0 | |
| if r1 goto L1 else goto L2 :: bool | |
| L1: | |
| return 2 | |
| L2: | |
| return 0 | |
| L3: | |
| unreachable | |
| def opt_o(x): | |
| x :: union[object, None] | |
| r0 :: object | |
| r1 :: bit | |
| r2 :: object | |
| r3 :: i32 | |
| r4 :: bit | |
| r5 :: bool | |
| L0: | |
| r0 = load_address _Py_NoneStruct | |
| r1 = x != r0 | |
| if r1 goto L1 else goto L3 :: bool | |
| L1: | |
| r2 = cast(object, x) | |
| r3 = PyObject_IsTrue(r2) | |
| r4 = r3 >= 0 :: signed | |
| r5 = truncate r3: i32 to builtins.bool | |
| if r5 goto L2 else goto L3 :: bool | |
| L2: | |
| return 2 | |
| L3: | |
| return 0 | |
| L4: | |
| unreachable | |
| [case testRaise] | |
| def foo() -> None: | |
| raise Exception() | |
| def bar() -> None: | |
| raise Exception | |
| [out] | |
| def foo(): | |
| r0 :: object | |
| r1 :: str | |
| r2, r3 :: object | |
| L0: | |
| r0 = builtins :: module | |
| r1 = 'Exception' | |
| r2 = CPyObject_GetAttr(r0, r1) | |
| r3 = PyObject_Vectorcall(r2, 0, 0, 0) | |
| CPy_Raise(r3) | |
| unreachable | |
| def bar(): | |
| r0 :: object | |
| r1 :: str | |
| r2 :: object | |
| L0: | |
| r0 = builtins :: module | |
| r1 = 'Exception' | |
| r2 = CPyObject_GetAttr(r0, r1) | |
| CPy_Raise(r2) | |
| unreachable | |
| [case testModuleTopLevel_toplevel] | |
| x = 1 | |
| print(x) | |
| def f() -> None: | |
| print(x) | |
| [out] | |
| def f(): | |
| r0 :: dict | |
| r1 :: str | |
| r2 :: object | |
| r3 :: int | |
| r4 :: object | |
| r5 :: str | |
| r6, r7 :: object | |
| r8 :: object[1] | |
| r9 :: object_ptr | |
| r10 :: object | |
| L0: | |
| r0 = __main__.globals :: static | |
| r1 = 'x' | |
| r2 = CPyDict_GetItem(r0, r1) | |
| r3 = unbox(int, r2) | |
| r4 = builtins :: module | |
| r5 = 'print' | |
| r6 = CPyObject_GetAttr(r4, r5) | |
| r7 = box(int, r3) | |
| r8 = [r7] | |
| r9 = load_address r8 | |
| r10 = PyObject_Vectorcall(r6, r9, 1, 0) | |
| keep_alive r7 | |
| return 1 | |
| def __top_level__(): | |
| r0 :: c_ptr | |
| r1 :: str | |
| r2, r3 :: object | |
| r4 :: bit | |
| r5 :: object | |
| r6 :: dict | |
| r7 :: str | |
| r8 :: object | |
| r9 :: i32 | |
| r10 :: bit | |
| r11 :: dict | |
| r12 :: str | |
| r13 :: object | |
| r14 :: int | |
| r15 :: object | |
| r16 :: str | |
| r17, r18 :: object | |
| r19 :: object[1] | |
| r20 :: object_ptr | |
| r21 :: object | |
| L0: | |
| r0 = load_address builtins :: module | |
| r1 = 'builtins' | |
| r2 = CPyImport_GetModuleCacheForImport(r0, r1) | |
| r3 = load_address _Py_NoneStruct | |
| r4 = r2 != r3 | |
| if r4 goto L2 else goto L1 :: bool | |
| L1: | |
| r5 = PyImport_Import(r1) | |
| CPyImport_ReplaceModuleCacheForImport(r0, r5) | |
| L2: | |
| keep_alive r0 | |
| r6 = __main__.globals :: static | |
| r7 = 'x' | |
| r8 = object 1 | |
| r9 = CPyDict_SetItem(r6, r7, r8) | |
| r10 = r9 >= 0 :: signed | |
| r11 = __main__.globals :: static | |
| r12 = 'x' | |
| r13 = CPyDict_GetItem(r11, r12) | |
| r14 = unbox(int, r13) | |
| r15 = builtins :: module | |
| r16 = 'print' | |
| r17 = CPyObject_GetAttr(r15, r16) | |
| r18 = box(int, r14) | |
| r19 = [r18] | |
| r20 = load_address r19 | |
| r21 = PyObject_Vectorcall(r17, r20, 1, 0) | |
| keep_alive r18 | |
| return 1 | |
| [case testCallOverloaded] | |
| import m | |
| def f() -> str: | |
| return m.f(1) | |
| [file m.pyi] | |
| from typing import overload | |
| @overload | |
| def f(x: int) -> str: ... | |
| @overload | |
| def f(x: str) -> int: ... | |
| [out] | |
| def f(): | |
| r0 :: object | |
| r1 :: str | |
| r2, r3 :: object | |
| r4 :: object[1] | |
| r5 :: object_ptr | |
| r6 :: object | |
| r7 :: str | |
| L0: | |
| r0 = m :: module | |
| r1 = 'f' | |
| r2 = CPyObject_GetAttr(r0, r1) | |
| r3 = object 1 | |
| r4 = [r3] | |
| r5 = load_address r4 | |
| r6 = PyObject_Vectorcall(r2, r5, 1, 0) | |
| keep_alive r3 | |
| r7 = cast(str, r6) | |
| return r7 | |
| [case testCallOverloadedNative] | |
| from typing import overload, Union | |
| @overload | |
| def foo(x: int) -> int: ... | |
| @overload | |
| def foo(x: str) -> str: ... | |
| def foo(x: Union[int, str]) -> Union[int, str]: | |
| return x | |
| def main() -> None: | |
| x = foo(0) | |
| [out] | |
| def foo(x): | |
| x :: union[int, str] | |
| L0: | |
| return x | |
| def main(): | |
| r0 :: object | |
| r1 :: union[int, str] | |
| r2, x :: int | |
| L0: | |
| r0 = object 0 | |
| r1 = foo(r0) | |
| r2 = unbox(int, r1) | |
| x = r2 | |
| return 1 | |
| [case testCallOverloadedNativeSubclass] | |
| from typing import overload, Union | |
| class A: | |
| x: int | |
| class B(A): | |
| y: int | |
| @overload | |
| def foo(x: int) -> B: ... | |
| @overload | |
| def foo(x: Union[int, str]) -> A: ... | |
| def foo(x: Union[int, str]) -> A: | |
| if isinstance(x, int): | |
| return B() | |
| return A() | |
| def main() -> None: | |
| x = foo(0) | |
| [out] | |
| def foo(x): | |
| x :: union[int, str] | |
| r0 :: bit | |
| r1 :: __main__.B | |
| r2 :: __main__.A | |
| L0: | |
| r0 = PyLong_Check(x) | |
| if r0 goto L1 else goto L2 :: bool | |
| L1: | |
| r1 = B() | |
| return r1 | |
| L2: | |
| r2 = A() | |
| return r2 | |
| def main(): | |
| r0 :: object | |
| r1 :: __main__.A | |
| r2, x :: __main__.B | |
| L0: | |
| r0 = object 0 | |
| r1 = foo(r0) | |
| r2 = cast(__main__.B, r1) | |
| x = r2 | |
| return 1 | |
| [case testFunctionCallWithKeywordArgs] | |
| def f(x: int, y: str) -> None: pass | |
| def g() -> None: | |
| f(y='a', x=0) | |
| f(1, y='b') | |
| [out] | |
| def f(x, y): | |
| x :: int | |
| y :: str | |
| L0: | |
| return 1 | |
| def g(): | |
| r0 :: str | |
| r1 :: None | |
| r2 :: str | |
| r3 :: None | |
| L0: | |
| r0 = 'a' | |
| r1 = f(0, r0) | |
| r2 = 'b' | |
| r3 = f(2, r2) | |
| return 1 | |
| [case testMethodCallWithKeywordArgs] | |
| class A: | |
| def f(self, x: int, y: str) -> None: pass | |
| def g(a: A) -> None: | |
| a.f(y='a', x=0) | |
| a.f(1, y='b') | |
| [out] | |
| def A.f(self, x, y): | |
| self :: __main__.A | |
| x :: int | |
| y :: str | |
| L0: | |
| return 1 | |
| def g(a): | |
| a :: __main__.A | |
| r0 :: str | |
| r1 :: None | |
| r2 :: str | |
| r3 :: None | |
| L0: | |
| r0 = 'a' | |
| r1 = a.f(0, r0) | |
| r2 = 'b' | |
| r3 = a.f(2, r2) | |
| return 1 | |
| [case testStarArgs] | |
| from typing import Tuple | |
| def f(a: int, b: int, c: int) -> Tuple[int, int, int]: | |
| return a, b, c | |
| def g() -> Tuple[int, int, int]: | |
| return f(*(1, 2, 3)) | |
| def h() -> Tuple[int, int, int]: | |
| return f(1, *(2, 3)) | |
| [out] | |
| def f(a, b, c): | |
| a, b, c, r0, r1, r2 :: int | |
| r3 :: tuple[int, int, int] | |
| L0: | |
| r0 = a | |
| r1 = b | |
| r2 = c | |
| r3 = (r0, r1, r2) | |
| return r3 | |
| def g(): | |
| r0 :: tuple[int, int, int] | |
| r1 :: dict | |
| r2 :: str | |
| r3, r4, r5 :: object | |
| r6 :: tuple[int, int, int] | |
| L0: | |
| r0 = (2, 4, 6) | |
| r1 = __main__.globals :: static | |
| r2 = 'f' | |
| r3 = CPyDict_GetItem(r1, r2) | |
| r4 = box(tuple[int, int, int], r0) | |
| r5 = PyObject_CallObject(r3, r4) | |
| r6 = unbox(tuple[int, int, int], r5) | |
| return r6 | |
| def h(): | |
| r0 :: tuple[int, int] | |
| r1 :: dict | |
| r2 :: str | |
| r3 :: object | |
| r4 :: list | |
| r5 :: object | |
| r6 :: ptr | |
| r7, r8 :: object | |
| r9 :: tuple | |
| r10 :: object | |
| r11 :: tuple[int, int, int] | |
| L0: | |
| r0 = (4, 6) | |
| r1 = __main__.globals :: static | |
| r2 = 'f' | |
| r3 = CPyDict_GetItem(r1, r2) | |
| r4 = PyList_New(1) | |
| r5 = object 1 | |
| r6 = list_items r4 | |
| buf_init_item r6, 0, r5 | |
| keep_alive r4 | |
| r7 = box(tuple[int, int], r0) | |
| r8 = CPyList_Extend(r4, r7) | |
| r9 = PyList_AsTuple(r4) | |
| r10 = PyObject_CallObject(r3, r9) | |
| r11 = unbox(tuple[int, int, int], r10) | |
| return r11 | |
| [case testStar2Args] | |
| from typing import Tuple | |
| def f(a: int, b: int, c: int) -> Tuple[int, int, int]: | |
| return a, b, c | |
| def g() -> Tuple[int, int, int]: | |
| return f(**{'a': 1, 'b': 2, 'c': 3}) | |
| def h() -> Tuple[int, int, int]: | |
| return f(1, **{'b': 2, 'c': 3}) | |
| [out] | |
| def f(a, b, c): | |
| a, b, c, r0, r1, r2 :: int | |
| r3 :: tuple[int, int, int] | |
| L0: | |
| r0 = a | |
| r1 = b | |
| r2 = c | |
| r3 = (r0, r1, r2) | |
| return r3 | |
| def g(): | |
| r0, r1, r2 :: str | |
| r3, r4, r5 :: object | |
| r6, r7 :: dict | |
| r8 :: str | |
| r9 :: object | |
| r10 :: tuple | |
| r11 :: dict | |
| r12 :: object | |
| r13 :: tuple[int, int, int] | |
| L0: | |
| r0 = 'a' | |
| r1 = 'b' | |
| r2 = 'c' | |
| r3 = object 1 | |
| r4 = object 2 | |
| r5 = object 3 | |
| r6 = CPyDict_Build(3, r0, r3, r1, r4, r2, r5) | |
| r7 = __main__.globals :: static | |
| r8 = 'f' | |
| r9 = CPyDict_GetItem(r7, r8) | |
| r10 = CPyTuple_LoadEmptyTupleConstant() | |
| r11 = PyDict_Copy(r6) | |
| r12 = PyObject_Call(r9, r10, r11) | |
| r13 = unbox(tuple[int, int, int], r12) | |
| return r13 | |
| def h(): | |
| r0, r1 :: str | |
| r2, r3 :: object | |
| r4, r5 :: dict | |
| r6 :: str | |
| r7 :: object | |
| r8 :: dict | |
| r9 :: i32 | |
| r10 :: bit | |
| r11 :: object | |
| r12 :: tuple | |
| r13 :: object | |
| r14 :: tuple[int, int, int] | |
| L0: | |
| r0 = 'b' | |
| r1 = 'c' | |
| r2 = object 2 | |
| r3 = object 3 | |
| r4 = CPyDict_Build(2, r0, r2, r1, r3) | |
| r5 = __main__.globals :: static | |
| r6 = 'f' | |
| r7 = CPyDict_GetItem(r5, r6) | |
| r8 = PyDict_New() | |
| r9 = CPyDict_UpdateInDisplay(r8, r4) | |
| r10 = r9 >= 0 :: signed | |
| r11 = object 1 | |
| r12 = PyTuple_Pack(1, r11) | |
| r13 = PyObject_Call(r7, r12, r8) | |
| r14 = unbox(tuple[int, int, int], r13) | |
| return r14 | |
| [case testFunctionCallWithDefaultArgs] | |
| def f(x: int, y: int = 3, z: str = "test") -> None: | |
| return None | |
| def g() -> None: | |
| f(2) | |
| f(y = 3, x = 6) | |
| [out] | |
| def f(x, y, z): | |
| x, y :: int | |
| z, r0 :: str | |
| L0: | |
| if is_error(y) goto L1 else goto L2 | |
| L1: | |
| y = 6 | |
| L2: | |
| if is_error(z) goto L3 else goto L4 | |
| L3: | |
| r0 = 'test' | |
| z = r0 | |
| L4: | |
| return 1 | |
| def g(): | |
| r0 :: int | |
| r1 :: str | |
| r2 :: None | |
| r3 :: str | |
| r4 :: None | |
| L0: | |
| r0 = <error> :: int | |
| r1 = <error> :: str | |
| r2 = f(4, r0, r1) | |
| r3 = <error> :: str | |
| r4 = f(12, 6, r3) | |
| return 1 | |
| [case testMethodCallWithDefaultArgs] | |
| class A: | |
| def f(self, x: int, y: int = 3, z: str = "test") -> None: | |
| return None | |
| def g() -> None: | |
| a = A() | |
| a.f(2) | |
| a.f(y = 3, x = 6) | |
| [out] | |
| def A.f(self, x, y, z): | |
| self :: __main__.A | |
| x, y :: int | |
| z, r0 :: str | |
| L0: | |
| if is_error(y) goto L1 else goto L2 | |
| L1: | |
| y = 6 | |
| L2: | |
| if is_error(z) goto L3 else goto L4 | |
| L3: | |
| r0 = 'test' | |
| z = r0 | |
| L4: | |
| return 1 | |
| def g(): | |
| r0, a :: __main__.A | |
| r1 :: int | |
| r2 :: str | |
| r3 :: None | |
| r4 :: str | |
| r5 :: None | |
| L0: | |
| r0 = A() | |
| a = r0 | |
| r1 = <error> :: int | |
| r2 = <error> :: str | |
| r3 = a.f(4, r1, r2) | |
| r4 = <error> :: str | |
| r5 = a.f(12, 6, r4) | |
| return 1 | |
| [case testListComprehension_withgil] | |
| from typing import List | |
| def f() -> List[int]: | |
| return [x*x for x in [1,2,3] if x != 2 if x != 3] | |
| [out] | |
| def f(): | |
| r0, r1 :: list | |
| r2, r3, r4 :: object | |
| r5 :: ptr | |
| r6, r7 :: native_int | |
| r8 :: bit | |
| r9 :: object | |
| r10, x :: int | |
| r11, r12 :: bit | |
| r13 :: int | |
| r14 :: object | |
| r15 :: i32 | |
| r16 :: bit | |
| r17 :: native_int | |
| L0: | |
| r0 = PyList_New(0) | |
| r1 = PyList_New(3) | |
| r2 = object 1 | |
| r3 = object 2 | |
| r4 = object 3 | |
| r5 = list_items r1 | |
| buf_init_item r5, 0, r2 | |
| buf_init_item r5, 1, r3 | |
| buf_init_item r5, 2, r4 | |
| keep_alive r1 | |
| r6 = 0 | |
| L1: | |
| r7 = var_object_size r1 | |
| r8 = r6 < r7 :: signed | |
| if r8 goto L2 else goto L8 :: bool | |
| L2: | |
| r9 = list_get_item_unsafe r1, r6 | |
| r10 = unbox(int, r9) | |
| x = r10 | |
| r11 = int_ne x, 4 | |
| if r11 goto L4 else goto L3 :: bool | |
| L3: | |
| goto L7 | |
| L4: | |
| r12 = int_ne x, 6 | |
| if r12 goto L6 else goto L5 :: bool | |
| L5: | |
| goto L7 | |
| L6: | |
| r13 = CPyTagged_Multiply(x, x) | |
| r14 = box(int, r13) | |
| r15 = PyList_Append(r0, r14) | |
| r16 = r15 >= 0 :: signed | |
| L7: | |
| r17 = r6 + 1 | |
| r6 = r17 | |
| goto L1 | |
| L8: | |
| return r0 | |
| [case testDictComprehension_withgil] | |
| from typing import Dict | |
| def f() -> Dict[int, int]: | |
| return {x: x*x for x in [1,2,3] if x != 2 if x != 3} | |
| [out] | |
| def f(): | |
| r0 :: dict | |
| r1 :: list | |
| r2, r3, r4 :: object | |
| r5 :: ptr | |
| r6, r7 :: native_int | |
| r8 :: bit | |
| r9 :: object | |
| r10, x :: int | |
| r11, r12 :: bit | |
| r13 :: int | |
| r14, r15 :: object | |
| r16 :: i32 | |
| r17 :: bit | |
| r18 :: native_int | |
| L0: | |
| r0 = PyDict_New() | |
| r1 = PyList_New(3) | |
| r2 = object 1 | |
| r3 = object 2 | |
| r4 = object 3 | |
| r5 = list_items r1 | |
| buf_init_item r5, 0, r2 | |
| buf_init_item r5, 1, r3 | |
| buf_init_item r5, 2, r4 | |
| keep_alive r1 | |
| r6 = 0 | |
| L1: | |
| r7 = var_object_size r1 | |
| r8 = r6 < r7 :: signed | |
| if r8 goto L2 else goto L8 :: bool | |
| L2: | |
| r9 = list_get_item_unsafe r1, r6 | |
| r10 = unbox(int, r9) | |
| x = r10 | |
| r11 = int_ne x, 4 | |
| if r11 goto L4 else goto L3 :: bool | |
| L3: | |
| goto L7 | |
| L4: | |
| r12 = int_ne x, 6 | |
| if r12 goto L6 else goto L5 :: bool | |
| L5: | |
| goto L7 | |
| L6: | |
| r13 = CPyTagged_Multiply(x, x) | |
| r14 = box(int, x) | |
| r15 = box(int, r13) | |
| r16 = PyDict_SetItem(r0, r14, r15) | |
| r17 = r16 >= 0 :: signed | |
| L7: | |
| r18 = r6 + 1 | |
| r6 = r18 | |
| goto L1 | |
| L8: | |
| return r0 | |
| [case testLoopsMultipleAssign_withgil] | |
| from typing import List, Tuple | |
| def f(l: List[Tuple[int, int, int]]) -> List[int]: | |
| for x, y, z in l: | |
| pass | |
| return [x+y+z for x, y, z in l] | |
| [out] | |
| def f(l): | |
| l :: list | |
| r0, r1 :: native_int | |
| r2 :: bit | |
| r3 :: object | |
| r4 :: tuple[int, int, int] | |
| r5, x, r6, y, r7, z :: int | |
| r8, r9 :: native_int | |
| r10 :: list | |
| r11, r12 :: native_int | |
| r13 :: bit | |
| r14 :: object | |
| r15 :: tuple[int, int, int] | |
| r16, x_2, r17, y_2, r18, z_2, r19, r20 :: int | |
| r21 :: object | |
| r22 :: native_int | |
| L0: | |
| r0 = 0 | |
| L1: | |
| r1 = var_object_size l | |
| r2 = r0 < r1 :: signed | |
| if r2 goto L2 else goto L4 :: bool | |
| L2: | |
| r3 = list_get_item_unsafe l, r0 | |
| r4 = unbox(tuple[int, int, int], r3) | |
| r5 = r4[0] | |
| x = r5 | |
| r6 = r4[1] | |
| y = r6 | |
| r7 = r4[2] | |
| z = r7 | |
| L3: | |
| r8 = r0 + 1 | |
| r0 = r8 | |
| goto L1 | |
| L4: | |
| r9 = var_object_size l | |
| r10 = PyList_New(r9) | |
| r11 = 0 | |
| L5: | |
| r12 = var_object_size l | |
| r13 = r11 < r12 :: signed | |
| if r13 goto L6 else goto L8 :: bool | |
| L6: | |
| r14 = list_get_item_unsafe l, r11 | |
| r15 = unbox(tuple[int, int, int], r14) | |
| r16 = r15[0] | |
| x_2 = r16 | |
| r17 = r15[1] | |
| y_2 = r17 | |
| r18 = r15[2] | |
| z_2 = r18 | |
| r19 = CPyTagged_Add(x_2, y_2) | |
| r20 = CPyTagged_Add(r19, z_2) | |
| r21 = box(int, r20) | |
| CPyList_SetItemUnsafe(r10, r11, r21) | |
| L7: | |
| r22 = r11 + 1 | |
| r11 = r22 | |
| goto L5 | |
| L8: | |
| return r10 | |
| [case testProperty_withgil] | |
| class PropertyHolder: | |
| @property | |
| def value(self) -> int: | |
| return self.left + self.right if self.is_add else self.left - self.right | |
| def __init__(self, left: int, right: int, is_add: bool) -> None: | |
| self.left = left | |
| self.right = right | |
| self.is_add = is_add | |
| def twice_value(self) -> int: | |
| return 2 * self.value | |
| [out] | |
| def PropertyHolder.value(self): | |
| self :: __main__.PropertyHolder | |
| r0 :: bool | |
| r1, r2, r3, r4, r5, r6, r7 :: int | |
| L0: | |
| r0 = self.is_add | |
| if r0 goto L1 else goto L2 :: bool | |
| L1: | |
| r1 = borrow self.left | |
| r2 = borrow self.right | |
| r3 = CPyTagged_Add(r1, r2) | |
| keep_alive self, self | |
| r4 = r3 | |
| goto L3 | |
| L2: | |
| r5 = borrow self.left | |
| r6 = borrow self.right | |
| r7 = CPyTagged_Subtract(r5, r6) | |
| keep_alive self, self | |
| r4 = r7 | |
| L3: | |
| return r4 | |
| def PropertyHolder.__init__(self, left, right, is_add): | |
| self :: __main__.PropertyHolder | |
| left, right :: int | |
| is_add :: bool | |
| L0: | |
| self.left = left | |
| self.right = right | |
| self.is_add = is_add | |
| return 1 | |
| def PropertyHolder.twice_value(self): | |
| self :: __main__.PropertyHolder | |
| r0, r1 :: int | |
| L0: | |
| r0 = self.value | |
| r1 = CPyTagged_Multiply(4, r0) | |
| return r1 | |
| [case testNativeIndex_withgil] | |
| from typing import List | |
| class A: | |
| def __getitem__(self, index: int) -> int: pass | |
| def g(a: A, b: List[int], c: int) -> int: | |
| return a[c] + b[c] | |
| [out] | |
| def A.__getitem__(self, index): | |
| self :: __main__.A | |
| index :: int | |
| L0: | |
| unreachable | |
| def g(a, b, c): | |
| a :: __main__.A | |
| b :: list | |
| c, r0 :: int | |
| r1 :: object | |
| r2, r3 :: int | |
| L0: | |
| r0 = a.__getitem__(c) | |
| r1 = CPyList_GetItemBorrow(b, c) | |
| r2 = unbox(int, r1) | |
| r3 = CPyTagged_Add(r0, r2) | |
| keep_alive b, c | |
| return r3 | |
| [case testTypeAlias_toplevel] | |
| from typing import List, NewType, NamedTuple | |
| Lol = NamedTuple('Lol', (('a', int), ('b', str))) | |
| x = Lol(1, '') | |
| Foo = List[int] | |
| Bar = NewType('Bar', Foo) | |
| y = Bar([1,2,3]) | |
| [out] | |
| def __top_level__(): | |
| r0 :: c_ptr | |
| r1 :: str | |
| r2, r3 :: object | |
| r4 :: bit | |
| r5, r6 :: object | |
| r7 :: str | |
| r8 :: dict | |
| r9 :: object | |
| r10 :: c_ptr | |
| r11, r12 :: str | |
| r13 :: object | |
| r14 :: tuple[str, object] | |
| r15 :: object | |
| r16 :: str | |
| r17 :: object | |
| r18 :: tuple[str, object] | |
| r19 :: object | |
| r20 :: tuple[object, object] | |
| r21 :: object | |
| r22 :: dict | |
| r23 :: str | |
| r24 :: object | |
| r25 :: object[2] | |
| r26 :: object_ptr | |
| r27 :: object | |
| r28 :: dict | |
| r29 :: str | |
| r30 :: i32 | |
| r31 :: bit | |
| r32 :: str | |
| r33 :: dict | |
| r34 :: str | |
| r35, r36 :: object | |
| r37 :: object[2] | |
| r38 :: object_ptr | |
| r39 :: object | |
| r40 :: tuple | |
| r41 :: dict | |
| r42 :: str | |
| r43 :: i32 | |
| r44 :: bit | |
| r45 :: dict | |
| r46 :: str | |
| r47, r48, r49 :: object | |
| r50 :: dict | |
| r51 :: str | |
| r52 :: i32 | |
| r53 :: bit | |
| r54 :: str | |
| r55 :: dict | |
| r56 :: str | |
| r57 :: object | |
| r58 :: dict | |
| r59 :: str | |
| r60 :: object | |
| r61 :: object[2] | |
| r62 :: object_ptr | |
| r63 :: object | |
| r64 :: dict | |
| r65 :: str | |
| r66 :: i32 | |
| r67 :: bit | |
| r68 :: list | |
| r69, r70, r71 :: object | |
| r72 :: ptr | |
| r73 :: dict | |
| r74 :: str | |
| r75 :: i32 | |
| r76 :: bit | |
| L0: | |
| r0 = load_address builtins :: module | |
| r1 = 'builtins' | |
| r2 = CPyImport_GetModuleCacheForImport(r0, r1) | |
| r3 = load_address _Py_NoneStruct | |
| r4 = r2 != r3 | |
| if r4 goto L2 else goto L1 :: bool | |
| L1: | |
| r5 = PyImport_Import(r1) | |
| CPyImport_ReplaceModuleCacheForImport(r0, r5) | |
| L2: | |
| r6 = ('List', 'NewType', 'NamedTuple') | |
| r7 = 'typing' | |
| r8 = __main__.globals :: static | |
| r9 = CPyImport_ImportFromMany(r7, r6, r6, r8) | |
| r10 = load_address typing :: module | |
| CPyImport_ReplaceModuleCacheForImport(r10, r9) | |
| r11 = 'Lol' | |
| keep_alive r0 | |
| r12 = 'a' | |
| r13 = load_address PyLong_Type | |
| r14 = (r12, r13) | |
| r15 = box(tuple[str, object], r14) | |
| r16 = 'b' | |
| r17 = load_address PyUnicode_Type | |
| r18 = (r16, r17) | |
| r19 = box(tuple[str, object], r18) | |
| r20 = (r15, r19) | |
| r21 = box(tuple[object, object], r20) | |
| r22 = __main__.globals :: static | |
| r23 = 'NamedTuple' | |
| r24 = CPyDict_GetItem(r22, r23) | |
| r25 = [r11, r21] | |
| r26 = load_address r25 | |
| r27 = PyObject_Vectorcall(r24, r26, 2, 0) | |
| keep_alive r11, r21 | |
| r28 = __main__.globals :: static | |
| r29 = 'Lol' | |
| r30 = CPyDict_SetItem(r28, r29, r27) | |
| r31 = r30 >= 0 :: signed | |
| r32 = '' | |
| r33 = __main__.globals :: static | |
| r34 = 'Lol' | |
| r35 = CPyDict_GetItem(r33, r34) | |
| r36 = object 1 | |
| r37 = [r36, r32] | |
| r38 = load_address r37 | |
| r39 = PyObject_Vectorcall(r35, r38, 2, 0) | |
| keep_alive r36, r32 | |
| r40 = cast(tuple, r39) | |
| r41 = __main__.globals :: static | |
| r42 = 'x' | |
| r43 = CPyDict_SetItem(r41, r42, r40) | |
| r44 = r43 >= 0 :: signed | |
| r45 = __main__.globals :: static | |
| r46 = 'List' | |
| r47 = CPyDict_GetItem(r45, r46) | |
| r48 = load_address PyLong_Type | |
| r49 = PyObject_GetItem(r47, r48) | |
| r50 = __main__.globals :: static | |
| r51 = 'Foo' | |
| r52 = CPyDict_SetItem(r50, r51, r49) | |
| r53 = r52 >= 0 :: signed | |
| r54 = 'Bar' | |
| r55 = __main__.globals :: static | |
| r56 = 'Foo' | |
| r57 = CPyDict_GetItem(r55, r56) | |
| r58 = __main__.globals :: static | |
| r59 = 'NewType' | |
| r60 = CPyDict_GetItem(r58, r59) | |
| r61 = [r54, r57] | |
| r62 = load_address r61 | |
| r63 = PyObject_Vectorcall(r60, r62, 2, 0) | |
| keep_alive r54, r57 | |
| r64 = __main__.globals :: static | |
| r65 = 'Bar' | |
| r66 = CPyDict_SetItem(r64, r65, r63) | |
| r67 = r66 >= 0 :: signed | |
| r68 = PyList_New(3) | |
| r69 = object 1 | |
| r70 = object 2 | |
| r71 = object 3 | |
| r72 = list_items r68 | |
| buf_init_item r72, 0, r69 | |
| buf_init_item r72, 1, r70 | |
| buf_init_item r72, 2, r71 | |
| keep_alive r68 | |
| r73 = __main__.globals :: static | |
| r74 = 'y' | |
| r75 = CPyDict_SetItem(r73, r74, r68) | |
| r76 = r75 >= 0 :: signed | |
| return 1 | |
| [case testChainedConditional] | |
| def g(x: int) -> int: | |
| return x | |
| def f(x: int, y: int, z: int) -> bool: | |
| return g(x) < g(y) > g(z) | |
| [out] | |
| def g(x): | |
| x :: int | |
| L0: | |
| return x | |
| def f(x, y, z): | |
| x, y, z, r0, r1 :: int | |
| r2 :: bit | |
| r3 :: bool | |
| r4 :: int | |
| r5 :: bit | |
| L0: | |
| r0 = g(x) | |
| r1 = g(y) | |
| r2 = int_lt r0, r1 | |
| if r2 goto L2 else goto L1 :: bool | |
| L1: | |
| r3 = r2 | |
| goto L3 | |
| L2: | |
| r4 = g(z) | |
| r5 = int_gt r1, r4 | |
| r3 = r5 | |
| L3: | |
| return r3 | |
| [case testEq] | |
| class A: | |
| def __eq__(self, x: object) -> bool: | |
| return NotImplemented | |
| [out] | |
| def A.__eq__(self, x): | |
| self :: __main__.A | |
| x, r0 :: object | |
| L0: | |
| r0 = load_address _Py_NotImplementedStruct | |
| return r0 | |
| def A.__ne__(__mypyc_self__, rhs): | |
| __mypyc_self__ :: __main__.A | |
| rhs, r0, r1 :: object | |
| r2 :: bit | |
| r3 :: object | |
| r4, r5 :: bit | |
| r6 :: object | |
| r7 :: bit | |
| r8 :: i32 | |
| r9 :: bit | |
| r10 :: bool | |
| r11 :: object | |
| L0: | |
| r0 = __mypyc_self__.__eq__(rhs) | |
| r1 = load_address _Py_NotImplementedStruct | |
| r2 = r0 == r1 | |
| if r2 goto L7 else goto L1 :: bool | |
| L1: | |
| r3 = load_global Py_True :: static | |
| r4 = r0 == r3 | |
| if r4 goto L2 else goto L3 :: bool | |
| L2: | |
| r5 = 0 | |
| goto L6 | |
| L3: | |
| r6 = load_global Py_False :: static | |
| r7 = r0 == r6 | |
| if r7 goto L4 else goto L5 :: bool | |
| L4: | |
| r5 = 1 | |
| goto L6 | |
| L5: | |
| r8 = PyObject_Not(r0) | |
| r9 = r8 >= 0 :: signed | |
| r10 = truncate r8: i32 to builtins.bool | |
| r5 = r10 | |
| L6: | |
| r11 = box(bit, r5) | |
| return r11 | |
| L7: | |
| return r1 | |
| [case testDecorators_toplevel] | |
| from typing import Callable | |
| def a(f: Callable[[], None]) -> Callable[[], None]: | |
| def g() -> None: | |
| print('Entering') | |
| f() | |
| print('Exited') | |
| return g | |
| def b(f: Callable[[], None]) -> Callable[[], None]: | |
| def g() -> None: | |
| print('---') | |
| f() | |
| print('---') | |
| return g | |
| @a | |
| @b | |
| def c() -> None: | |
| @a | |
| @b | |
| def d() -> None: | |
| print('d') | |
| print('c') | |
| d() | |
| [out] | |
| def g_a_obj.__get__(__mypyc_self__, instance, owner): | |
| __mypyc_self__, instance, owner, r0 :: object | |
| r1 :: bit | |
| r2 :: object | |
| L0: | |
| r0 = load_address _Py_NoneStruct | |
| r1 = instance == r0 | |
| if r1 goto L1 else goto L2 :: bool | |
| L1: | |
| return __mypyc_self__ | |
| L2: | |
| r2 = PyMethod_New(__mypyc_self__, instance) | |
| return r2 | |
| def g_a_obj.__call__(__mypyc_self__): | |
| __mypyc_self__ :: __main__.g_a_obj | |
| r0 :: __main__.a_env | |
| r1 :: str | |
| r2 :: object | |
| r3 :: str | |
| r4 :: object | |
| r5 :: object[1] | |
| r6 :: object_ptr | |
| r7, r8, r9 :: object | |
| r10 :: str | |
| r11 :: object | |
| r12 :: str | |
| r13 :: object | |
| r14 :: object[1] | |
| r15 :: object_ptr | |
| r16 :: object | |
| L0: | |
| r0 = borrow __mypyc_self__.__mypyc_env__ | |
| r1 = 'Entering' | |
| r2 = builtins :: module | |
| r3 = 'print' | |
| r4 = CPyObject_GetAttr(r2, r3) | |
| r5 = [r1] | |
| r6 = load_address r5 | |
| r7 = PyObject_Vectorcall(r4, r6, 1, 0) | |
| keep_alive r1 | |
| r8 = r0.f | |
| r9 = PyObject_Vectorcall(r8, 0, 0, 0) | |
| r10 = 'Exited' | |
| r11 = builtins :: module | |
| r12 = 'print' | |
| r13 = CPyObject_GetAttr(r11, r12) | |
| r14 = [r10] | |
| r15 = load_address r14 | |
| r16 = PyObject_Vectorcall(r13, r15, 1, 0) | |
| keep_alive r10 | |
| return 1 | |
| def a(f): | |
| f :: object | |
| r0 :: __main__.a_env | |
| r1 :: bool | |
| r2 :: __main__.g_a_obj | |
| g :: object | |
| L0: | |
| r0 = a_env() | |
| r0.f = f; r1 = is_error | |
| r2 = g_a_obj() | |
| r2.__mypyc_env__ = r0 | |
| g = r2 | |
| return g | |
| def g_b_obj.__get__(__mypyc_self__, instance, owner): | |
| __mypyc_self__, instance, owner, r0 :: object | |
| r1 :: bit | |
| r2 :: object | |
| L0: | |
| r0 = load_address _Py_NoneStruct | |
| r1 = instance == r0 | |
| if r1 goto L1 else goto L2 :: bool | |
| L1: | |
| return __mypyc_self__ | |
| L2: | |
| r2 = PyMethod_New(__mypyc_self__, instance) | |
| return r2 | |
| def g_b_obj.__call__(__mypyc_self__): | |
| __mypyc_self__ :: __main__.g_b_obj | |
| r0 :: __main__.b_env | |
| r1 :: str | |
| r2 :: object | |
| r3 :: str | |
| r4 :: object | |
| r5 :: object[1] | |
| r6 :: object_ptr | |
| r7, r8, r9 :: object | |
| r10 :: str | |
| r11 :: object | |
| r12 :: str | |
| r13 :: object | |
| r14 :: object[1] | |
| r15 :: object_ptr | |
| r16 :: object | |
| L0: | |
| r0 = borrow __mypyc_self__.__mypyc_env__ | |
| r1 = '---' | |
| r2 = builtins :: module | |
| r3 = 'print' | |
| r4 = CPyObject_GetAttr(r2, r3) | |
| r5 = [r1] | |
| r6 = load_address r5 | |
| r7 = PyObject_Vectorcall(r4, r6, 1, 0) | |
| keep_alive r1 | |
| r8 = r0.f | |
| r9 = PyObject_Vectorcall(r8, 0, 0, 0) | |
| r10 = '---' | |
| r11 = builtins :: module | |
| r12 = 'print' | |
| r13 = CPyObject_GetAttr(r11, r12) | |
| r14 = [r10] | |
| r15 = load_address r14 | |
| r16 = PyObject_Vectorcall(r13, r15, 1, 0) | |
| keep_alive r10 | |
| return 1 | |
| def b(f): | |
| f :: object | |
| r0 :: __main__.b_env | |
| r1 :: bool | |
| r2 :: __main__.g_b_obj | |
| g :: object | |
| L0: | |
| r0 = b_env() | |
| r0.f = f; r1 = is_error | |
| r2 = g_b_obj() | |
| r2.__mypyc_env__ = r0 | |
| g = r2 | |
| return g | |
| def d_c_obj.__get__(__mypyc_self__, instance, owner): | |
| __mypyc_self__, instance, owner, r0 :: object | |
| r1 :: bit | |
| r2 :: object | |
| L0: | |
| r0 = load_address _Py_NoneStruct | |
| r1 = instance == r0 | |
| if r1 goto L1 else goto L2 :: bool | |
| L1: | |
| return __mypyc_self__ | |
| L2: | |
| r2 = PyMethod_New(__mypyc_self__, instance) | |
| return r2 | |
| def d_c_obj.__call__(__mypyc_self__): | |
| __mypyc_self__ :: __main__.d_c_obj | |
| r0 :: __main__.c_env | |
| r1 :: str | |
| r2 :: object | |
| r3 :: str | |
| r4 :: object | |
| r5 :: object[1] | |
| r6 :: object_ptr | |
| r7 :: object | |
| L0: | |
| r0 = borrow __mypyc_self__.__mypyc_env__ | |
| r1 = 'd' | |
| r2 = builtins :: module | |
| r3 = 'print' | |
| r4 = CPyObject_GetAttr(r2, r3) | |
| r5 = [r1] | |
| r6 = load_address r5 | |
| r7 = PyObject_Vectorcall(r4, r6, 1, 0) | |
| keep_alive r1 | |
| return 1 | |
| def c(): | |
| r0 :: __main__.c_env | |
| r1 :: __main__.d_c_obj | |
| r2 :: dict | |
| r3 :: str | |
| r4 :: object | |
| r5 :: object[1] | |
| r6 :: object_ptr | |
| r7 :: object | |
| r8 :: dict | |
| r9 :: str | |
| r10 :: object | |
| r11 :: object[1] | |
| r12 :: object_ptr | |
| r13, d :: object | |
| r14 :: dict | |
| r15 :: str | |
| r16 :: i32 | |
| r17 :: bit | |
| r18 :: str | |
| r19 :: object | |
| r20 :: str | |
| r21 :: object | |
| r22 :: object[1] | |
| r23 :: object_ptr | |
| r24, r25 :: object | |
| L0: | |
| r0 = c_env() | |
| r1 = d_c_obj() | |
| r1.__mypyc_env__ = r0 | |
| r2 = __main__.globals :: static | |
| r3 = 'b' | |
| r4 = CPyDict_GetItem(r2, r3) | |
| r5 = [r1] | |
| r6 = load_address r5 | |
| r7 = PyObject_Vectorcall(r4, r6, 1, 0) | |
| keep_alive r1 | |
| r8 = __main__.globals :: static | |
| r9 = 'a' | |
| r10 = CPyDict_GetItem(r8, r9) | |
| r11 = [r7] | |
| r12 = load_address r11 | |
| r13 = PyObject_Vectorcall(r10, r12, 1, 0) | |
| keep_alive r7 | |
| d = r13 | |
| r14 = __main__.globals :: static | |
| r15 = 'd' | |
| r16 = PyDict_SetItem(r14, r15, r13) | |
| r17 = r16 >= 0 :: signed | |
| r18 = 'c' | |
| r19 = builtins :: module | |
| r20 = 'print' | |
| r21 = CPyObject_GetAttr(r19, r20) | |
| r22 = [r18] | |
| r23 = load_address r22 | |
| r24 = PyObject_Vectorcall(r21, r23, 1, 0) | |
| keep_alive r18 | |
| r25 = PyObject_Vectorcall(d, 0, 0, 0) | |
| return 1 | |
| def __top_level__(): | |
| r0 :: c_ptr | |
| r1 :: str | |
| r2, r3 :: object | |
| r4 :: bit | |
| r5, r6 :: object | |
| r7 :: str | |
| r8 :: dict | |
| r9 :: object | |
| r10 :: c_ptr | |
| r11 :: dict | |
| r12 :: str | |
| r13 :: object | |
| r14 :: dict | |
| r15 :: str | |
| r16 :: object | |
| r17 :: object[1] | |
| r18 :: object_ptr | |
| r19 :: object | |
| r20 :: dict | |
| r21 :: str | |
| r22 :: object | |
| r23 :: object[1] | |
| r24 :: object_ptr | |
| r25 :: object | |
| r26 :: dict | |
| r27 :: str | |
| r28 :: i32 | |
| r29 :: bit | |
| L0: | |
| r0 = load_address builtins :: module | |
| r1 = 'builtins' | |
| r2 = CPyImport_GetModuleCacheForImport(r0, r1) | |
| r3 = load_address _Py_NoneStruct | |
| r4 = r2 != r3 | |
| if r4 goto L2 else goto L1 :: bool | |
| L1: | |
| r5 = PyImport_Import(r1) | |
| CPyImport_ReplaceModuleCacheForImport(r0, r5) | |
| L2: | |
| r6 = ('Callable',) | |
| r7 = 'typing' | |
| r8 = __main__.globals :: static | |
| r9 = CPyImport_ImportFromMany(r7, r6, r6, r8) | |
| r10 = load_address typing :: module | |
| CPyImport_ReplaceModuleCacheForImport(r10, r9) | |
| r11 = __main__.globals :: static | |
| r12 = 'c' | |
| r13 = CPyDict_GetItem(r11, r12) | |
| r14 = __main__.globals :: static | |
| r15 = 'b' | |
| r16 = CPyDict_GetItem(r14, r15) | |
| r17 = [r13] | |
| r18 = load_address r17 | |
| r19 = PyObject_Vectorcall(r16, r18, 1, 0) | |
| keep_alive r13 | |
| r20 = __main__.globals :: static | |
| r21 = 'a' | |
| r22 = CPyDict_GetItem(r20, r21) | |
| r23 = [r19] | |
| r24 = load_address r23 | |
| r25 = PyObject_Vectorcall(r22, r24, 1, 0) | |
| keep_alive r19 | |
| r26 = __main__.globals :: static | |
| r27 = 'c' | |
| r28 = PyDict_SetItem(r26, r27, r25) | |
| r29 = r28 >= 0 :: signed | |
| return 1 | |
| [case testDecoratorsSimple_toplevel] | |
| from typing import Callable | |
| def a(f: Callable[[], None]) -> Callable[[], None]: | |
| def g() -> None: | |
| print('Entering') | |
| f() | |
| print('Exited') | |
| return g | |
| [out] | |
| def g_a_obj.__get__(__mypyc_self__, instance, owner): | |
| __mypyc_self__, instance, owner, r0 :: object | |
| r1 :: bit | |
| r2 :: object | |
| L0: | |
| r0 = load_address _Py_NoneStruct | |
| r1 = instance == r0 | |
| if r1 goto L1 else goto L2 :: bool | |
| L1: | |
| return __mypyc_self__ | |
| L2: | |
| r2 = PyMethod_New(__mypyc_self__, instance) | |
| return r2 | |
| def g_a_obj.__call__(__mypyc_self__): | |
| __mypyc_self__ :: __main__.g_a_obj | |
| r0 :: __main__.a_env | |
| r1 :: str | |
| r2 :: object | |
| r3 :: str | |
| r4 :: object | |
| r5 :: object[1] | |
| r6 :: object_ptr | |
| r7, r8, r9 :: object | |
| r10 :: str | |
| r11 :: object | |
| r12 :: str | |
| r13 :: object | |
| r14 :: object[1] | |
| r15 :: object_ptr | |
| r16 :: object | |
| L0: | |
| r0 = borrow __mypyc_self__.__mypyc_env__ | |
| r1 = 'Entering' | |
| r2 = builtins :: module | |
| r3 = 'print' | |
| r4 = CPyObject_GetAttr(r2, r3) | |
| r5 = [r1] | |
| r6 = load_address r5 | |
| r7 = PyObject_Vectorcall(r4, r6, 1, 0) | |
| keep_alive r1 | |
| r8 = r0.f | |
| r9 = PyObject_Vectorcall(r8, 0, 0, 0) | |
| r10 = 'Exited' | |
| r11 = builtins :: module | |
| r12 = 'print' | |
| r13 = CPyObject_GetAttr(r11, r12) | |
| r14 = [r10] | |
| r15 = load_address r14 | |
| r16 = PyObject_Vectorcall(r13, r15, 1, 0) | |
| keep_alive r10 | |
| return 1 | |
| def a(f): | |
| f :: object | |
| r0 :: __main__.a_env | |
| r1 :: bool | |
| r2 :: __main__.g_a_obj | |
| g :: object | |
| L0: | |
| r0 = a_env() | |
| r0.f = f; r1 = is_error | |
| r2 = g_a_obj() | |
| r2.__mypyc_env__ = r0 | |
| g = r2 | |
| return g | |
| def __top_level__(): | |
| r0 :: c_ptr | |
| r1 :: str | |
| r2, r3 :: object | |
| r4 :: bit | |
| r5, r6 :: object | |
| r7 :: str | |
| r8 :: dict | |
| r9 :: object | |
| r10 :: c_ptr | |
| L0: | |
| r0 = load_address builtins :: module | |
| r1 = 'builtins' | |
| r2 = CPyImport_GetModuleCacheForImport(r0, r1) | |
| r3 = load_address _Py_NoneStruct | |
| r4 = r2 != r3 | |
| if r4 goto L2 else goto L1 :: bool | |
| L1: | |
| r5 = PyImport_Import(r1) | |
| CPyImport_ReplaceModuleCacheForImport(r0, r5) | |
| L2: | |
| r6 = ('Callable',) | |
| r7 = 'typing' | |
| r8 = __main__.globals :: static | |
| r9 = CPyImport_ImportFromMany(r7, r6, r6, r8) | |
| r10 = load_address typing :: module | |
| CPyImport_ReplaceModuleCacheForImport(r10, r9) | |
| return 1 | |
| [case testAnyAllG] | |
| from typing import Iterable | |
| def call_any(l: Iterable[int]) -> bool: | |
| return any(i == 0 for i in l) | |
| def call_all(l: Iterable[int]) -> bool: | |
| return all(i == 0 for i in l) | |
| [out] | |
| def call_any(l): | |
| l :: object | |
| r0 :: bool | |
| r1, r2 :: object | |
| r3, i :: int | |
| r4, r5 :: bit | |
| L0: | |
| r0 = 0 | |
| r1 = PyObject_GetIter(l) | |
| L1: | |
| r2 = PyIter_Next(r1) | |
| if is_error(r2) goto L6 else goto L2 | |
| L2: | |
| r3 = unbox(int, r2) | |
| i = r3 | |
| r4 = int_eq i, 0 | |
| if r4 goto L3 else goto L4 :: bool | |
| L3: | |
| r0 = 1 | |
| goto L8 | |
| L4: | |
| L5: | |
| goto L1 | |
| L6: | |
| r5 = CPy_NoErrOccurred() | |
| L7: | |
| L8: | |
| return r0 | |
| def call_all(l): | |
| l :: object | |
| r0 :: bool | |
| r1, r2 :: object | |
| r3, i :: int | |
| r4, r5, r6 :: bit | |
| L0: | |
| r0 = 1 | |
| r1 = PyObject_GetIter(l) | |
| L1: | |
| r2 = PyIter_Next(r1) | |
| if is_error(r2) goto L6 else goto L2 | |
| L2: | |
| r3 = unbox(int, r2) | |
| i = r3 | |
| r4 = int_eq i, 0 | |
| r5 = r4 ^ 1 | |
| if r5 goto L3 else goto L4 :: bool | |
| L3: | |
| r0 = 0 | |
| goto L8 | |
| L4: | |
| L5: | |
| goto L1 | |
| L6: | |
| r6 = CPy_NoErrOccurred() | |
| L7: | |
| L8: | |
| return r0 | |
| [case testSum] | |
| from typing import Callable, Iterable | |
| def call_sum(l: Iterable[int], comparison: Callable[[int], bool]) -> int: | |
| return sum(comparison(x) for x in l) | |
| [out] | |
| def call_sum(l, comparison): | |
| l, comparison :: object | |
| r0 :: int | |
| r1, r2 :: object | |
| r3, x :: int | |
| r4 :: object | |
| r5 :: object[1] | |
| r6 :: object_ptr | |
| r7 :: object | |
| r8, r9 :: bool | |
| r10, r11 :: int | |
| r12 :: bit | |
| L0: | |
| r0 = 0 | |
| r1 = PyObject_GetIter(l) | |
| L1: | |
| r2 = PyIter_Next(r1) | |
| if is_error(r2) goto L4 else goto L2 | |
| L2: | |
| r3 = unbox(int, r2) | |
| x = r3 | |
| r4 = box(int, x) | |
| r5 = [r4] | |
| r6 = load_address r5 | |
| r7 = PyObject_Vectorcall(comparison, r6, 1, 0) | |
| keep_alive r4 | |
| r8 = unbox(bool, r7) | |
| r9 = r8 << 1 | |
| r10 = extend r9: builtins.bool to builtins.int | |
| r11 = CPyTagged_Add(r0, r10) | |
| r0 = r11 | |
| L3: | |
| goto L1 | |
| L4: | |
| r12 = CPy_NoErrOccurred() | |
| L5: | |
| return r0 | |
| [case testSetAttr1] | |
| from typing import Any, Dict, List | |
| def lol(x: Any): | |
| setattr(x, 'x', '5') | |
| [out] | |
| def lol(x): | |
| x :: object | |
| r0, r1 :: str | |
| r2 :: i32 | |
| r3 :: bit | |
| r4 :: object | |
| L0: | |
| r0 = 'x' | |
| r1 = '5' | |
| r2 = PyObject_SetAttr(x, r0, r1) | |
| r3 = r2 >= 0 :: signed | |
| r4 = box(None, 1) | |
| return r4 | |
| [case testFinalModuleInt] | |
| from typing import Final | |
| x: Final = 1 | |
| y: Final = 2 | |
| def f(a: bool) -> int: | |
| if a: | |
| return x | |
| else: | |
| return y | |
| [out] | |
| def f(a): | |
| a :: bool | |
| L0: | |
| if a goto L1 else goto L2 :: bool | |
| L1: | |
| return 2 | |
| L2: | |
| return 4 | |
| L3: | |
| unreachable | |
| [case testFinalModuleStr] | |
| from typing import Final | |
| x: Final = 'x' | |
| y: Final = 'y' | |
| def f(a: bool) -> str: | |
| if a: | |
| return x | |
| else: | |
| return y | |
| [out] | |
| def f(a): | |
| a :: bool | |
| r0, r1 :: str | |
| L0: | |
| if a goto L1 else goto L2 :: bool | |
| L1: | |
| r0 = 'x' | |
| return r0 | |
| L2: | |
| r1 = 'y' | |
| return r1 | |
| L3: | |
| unreachable | |
| [case testFinalModuleBool] | |
| from typing import Final | |
| x: Final = True | |
| y: Final = False | |
| def f(a: bool) -> bool: | |
| if a: | |
| return x | |
| else: | |
| return y | |
| [out] | |
| def f(a): | |
| a :: bool | |
| L0: | |
| if a goto L1 else goto L2 :: bool | |
| L1: | |
| return 1 | |
| L2: | |
| return 0 | |
| L3: | |
| unreachable | |
| [case testFinalClass] | |
| from typing import Final | |
| class C: | |
| x: Final = 1 | |
| y: Final = 2 | |
| def f(a: bool) -> int: | |
| if a: | |
| return C.x | |
| else: | |
| return C.y | |
| [out] | |
| def f(a): | |
| a :: bool | |
| L0: | |
| if a goto L1 else goto L2 :: bool | |
| L1: | |
| return 2 | |
| L2: | |
| return 4 | |
| L3: | |
| unreachable | |
| [case testFinalStaticList] | |
| from typing import Final | |
| x: Final = [1] | |
| def f() -> int: | |
| return x[0] | |
| [out] | |
| def f(): | |
| r0 :: list | |
| r1 :: bool | |
| r2 :: object | |
| r3 :: int | |
| L0: | |
| r0 = __main__.x :: static | |
| if is_error(r0) goto L1 else goto L2 | |
| L1: | |
| r1 = raise NameError('value for final name "x" was not set') | |
| unreachable | |
| L2: | |
| r2 = CPyList_GetItemShort(r0, 0) | |
| r3 = unbox(int, r2) | |
| return r3 | |
| [case testFinalStaticTuple] | |
| from typing import Final | |
| x: Final = (1, 2) | |
| def f() -> int: | |
| return x[0] | |
| [out] | |
| def f(): | |
| r0 :: tuple[int, int] | |
| r1 :: bool | |
| r2 :: int | |
| L0: | |
| r0 = __main__.x :: static | |
| if is_error(r0) goto L1 else goto L2 | |
| L1: | |
| r1 = raise NameError('value for final name "x" was not set') | |
| unreachable | |
| L2: | |
| r2 = r0[0] | |
| return r2 | |
| [case testFinalStaticInt] | |
| from typing import Final | |
| x: Final = 1 + int() | |
| def f() -> int: | |
| return x - 1 | |
| [out] | |
| def f(): | |
| r0 :: int | |
| r1 :: bool | |
| r2 :: int | |
| L0: | |
| r0 = __main__.x :: static | |
| if is_error(r0) goto L1 else goto L2 | |
| L1: | |
| r1 = raise NameError('value for final name "x" was not set') | |
| unreachable | |
| L2: | |
| r2 = CPyTagged_Subtract(r0, 2) | |
| return r2 | |
| [case testFinalRestrictedTypeVar] | |
| from typing import TypeVar | |
| if False: | |
| from typing import Final | |
| FOO = 10 # type: Final | |
| Targ = TypeVar('Targ', int, str) | |
| def foo(z: Targ) -> None: | |
| FOO | |
| [out] | |
| def foo(z): | |
| z :: object | |
| L0: | |
| return 1 | |
| [case testFinalLocals] | |
| from typing import Final | |
| def inlined() -> str: | |
| # XXX: the final type must be declared explicitly for Var.final_value to be set. | |
| const: Final[str] = "Oppenheimer" | |
| return const | |
| def local() -> str: | |
| const: Final[str] = inlined() | |
| return const | |
| [out] | |
| def inlined(): | |
| r0, const, r1 :: str | |
| L0: | |
| r0 = 'Oppenheimer' | |
| const = r0 | |
| r1 = 'Oppenheimer' | |
| return r1 | |
| def local(): | |
| r0, const :: str | |
| L0: | |
| r0 = inlined() | |
| const = r0 | |
| return const | |
| [case testDirectlyCall__bool__] | |
| class A: | |
| def __bool__(self) -> bool: | |
| return True | |
| class B(A): | |
| def __bool__(self) -> bool: | |
| return False | |
| def lol(x: A) -> int: | |
| if x: | |
| return 1 | |
| else: | |
| return 0 | |
| [out] | |
| def A.__bool__(self): | |
| self :: __main__.A | |
| L0: | |
| return 1 | |
| def B.__bool__(self): | |
| self :: __main__.B | |
| L0: | |
| return 0 | |
| def lol(x): | |
| x :: __main__.A | |
| r0 :: bool | |
| L0: | |
| r0 = x.__bool__() | |
| if r0 goto L1 else goto L2 :: bool | |
| L1: | |
| return 2 | |
| L2: | |
| return 0 | |
| L3: | |
| unreachable | |
| [case testRevealType] | |
| def f(x: int) -> None: | |
| reveal_type(x) # type: ignore | |
| [out] | |
| def f(x): | |
| x :: int | |
| r0 :: object | |
| r1 :: str | |
| r2, r3 :: object | |
| r4 :: object[1] | |
| r5 :: object_ptr | |
| r6 :: object | |
| L0: | |
| r0 = builtins :: module | |
| r1 = 'reveal_type' | |
| r2 = CPyObject_GetAttr(r0, r1) | |
| r3 = box(int, x) | |
| r4 = [r3] | |
| r5 = load_address r4 | |
| r6 = PyObject_Vectorcall(r2, r5, 1, 0) | |
| keep_alive r3 | |
| return 1 | |
| [case testCallCWithStrJoinMethod] | |
| from typing import List | |
| def f(x: str, y: List[str]) -> str: | |
| return x.join(y) | |
| [out] | |
| def f(x, y): | |
| x :: str | |
| y :: list | |
| r0 :: str | |
| L0: | |
| r0 = PyUnicode_Join(x, y) | |
| return r0 | |
| [case testCallCWithToListFunction] | |
| from typing import List, Iterable, Tuple, Dict | |
| # generic object | |
| def f(x: Iterable[int]) -> List[int]: | |
| return list(x) | |
| # need coercing | |
| def g(x: Tuple[int, int, int]) -> List[int]: | |
| return list(x) | |
| # non-list object | |
| def h(x: Dict[int, str]) -> List[int]: | |
| return list(x) | |
| [out] | |
| def f(x): | |
| x :: object | |
| r0 :: list | |
| L0: | |
| r0 = PySequence_List(x) | |
| return r0 | |
| def g(x): | |
| x :: tuple[int, int, int] | |
| r0 :: object | |
| r1 :: list | |
| L0: | |
| r0 = box(tuple[int, int, int], x) | |
| r1 = PySequence_List(r0) | |
| return r1 | |
| def h(x): | |
| x :: dict | |
| r0 :: list | |
| L0: | |
| r0 = PySequence_List(x) | |
| return r0 | |
| [case testBoolFunction] | |
| def f(x: object) -> bool: | |
| return bool(x) | |
| [out] | |
| def f(x): | |
| x :: object | |
| r0 :: i32 | |
| r1 :: bit | |
| r2 :: bool | |
| L0: | |
| r0 = PyObject_IsTrue(x) | |
| r1 = r0 >= 0 :: signed | |
| r2 = truncate r0: i32 to builtins.bool | |
| return r2 | |
| [case testLocalImports] | |
| def root() -> None: | |
| import dataclasses | |
| import enum | |
| def submodule() -> int: | |
| import p.m | |
| return p.x | |
| [file p/__init__.py] | |
| x = 1 | |
| [file p/m.py] | |
| [out] | |
| def root(): | |
| r0 :: dict | |
| r1 :: c_ptr | |
| r2 :: str | |
| r3, r4 :: object | |
| r5 :: bit | |
| r6 :: object | |
| r7 :: str | |
| r8 :: dict | |
| r9 :: str | |
| r10 :: object | |
| r11 :: i32 | |
| r12 :: bit | |
| r13 :: dict | |
| r14 :: c_ptr | |
| r15 :: str | |
| r16, r17 :: object | |
| r18 :: bit | |
| r19 :: object | |
| r20 :: str | |
| r21 :: dict | |
| r22 :: str | |
| r23 :: object | |
| r24 :: i32 | |
| r25 :: bit | |
| L0: | |
| r0 = __main__.globals :: static | |
| r1 = load_address dataclasses :: module | |
| r2 = 'dataclasses' | |
| r3 = CPyImport_GetModuleCacheForImport(r1, r2) | |
| r4 = load_address _Py_NoneStruct | |
| r5 = r3 != r4 | |
| if r5 goto L2 else goto L1 :: bool | |
| L1: | |
| r6 = PyImport_Import(r2) | |
| CPyImport_ReplaceModuleCacheForImport(r1, r6) | |
| L2: | |
| r7 = 'dataclasses' | |
| r8 = PyImport_GetModuleDict() | |
| r9 = 'dataclasses' | |
| r10 = CPyDict_GetItem(r8, r9) | |
| r11 = CPyDict_SetItem(r0, r7, r10) | |
| r12 = r11 >= 0 :: signed | |
| r13 = __main__.globals :: static | |
| r14 = load_address enum :: module | |
| r15 = 'enum' | |
| r16 = CPyImport_GetModuleCacheForImport(r14, r15) | |
| r17 = load_address _Py_NoneStruct | |
| r18 = r16 != r17 | |
| if r18 goto L4 else goto L3 :: bool | |
| L3: | |
| r19 = PyImport_Import(r15) | |
| CPyImport_ReplaceModuleCacheForImport(r14, r19) | |
| L4: | |
| r20 = 'enum' | |
| r21 = PyImport_GetModuleDict() | |
| r22 = 'enum' | |
| r23 = CPyDict_GetItem(r21, r22) | |
| r24 = CPyDict_SetItem(r13, r20, r23) | |
| r25 = r24 >= 0 :: signed | |
| return 1 | |
| def submodule(): | |
| r0 :: dict | |
| r1 :: c_ptr | |
| r2 :: str | |
| r3, r4 :: object | |
| r5 :: bit | |
| r6 :: object | |
| r7 :: str | |
| r8 :: dict | |
| r9 :: str | |
| r10 :: object | |
| r11 :: i32 | |
| r12 :: bit | |
| r13 :: dict | |
| r14 :: str | |
| r15 :: object | |
| r16 :: str | |
| r17 :: object | |
| r18 :: int | |
| L0: | |
| r0 = __main__.globals :: static | |
| r1 = load_address p.m :: module | |
| r2 = 'p.m' | |
| r3 = CPyImport_GetModuleCacheForImport(r1, r2) | |
| r4 = load_address _Py_NoneStruct | |
| r5 = r3 != r4 | |
| if r5 goto L2 else goto L1 :: bool | |
| L1: | |
| r6 = PyImport_Import(r2) | |
| CPyImport_ReplaceModuleCacheForImport(r1, r6) | |
| L2: | |
| r7 = 'p' | |
| r8 = PyImport_GetModuleDict() | |
| r9 = 'p' | |
| r10 = CPyDict_GetItem(r8, r9) | |
| r11 = CPyDict_SetItem(r0, r7, r10) | |
| r12 = r11 >= 0 :: signed | |
| r13 = PyImport_GetModuleDict() | |
| r14 = 'p' | |
| r15 = CPyDict_GetItem(r13, r14) | |
| keep_alive r1 | |
| r16 = 'x' | |
| r17 = CPyObject_GetAttr(r15, r16) | |
| r18 = unbox(int, r17) | |
| return r18 | |
| [case testIsinstanceBool] | |
| def f(x: object) -> bool: | |
| return isinstance(x, bool) | |
| [out] | |
| def f(x): | |
| x :: object | |
| r0 :: bit | |
| L0: | |
| r0 = PyBool_Check(x) | |
| return r0 | |
| [case testRangeObject] | |
| def range_object() -> None: | |
| r = range(4, 12, 2) | |
| sum = 0 | |
| for i in r: | |
| sum += i | |
| def range_in_loop() -> None: | |
| sum = 0 | |
| for i in range(4, 12, 2): | |
| sum += i | |
| [out] | |
| def range_object(): | |
| r0, r1, r2, r3 :: object | |
| r4 :: object[3] | |
| r5 :: object_ptr | |
| r6 :: object | |
| r7, r :: range | |
| sum :: int | |
| r8, r9 :: object | |
| r10, i, r11 :: int | |
| r12 :: bit | |
| L0: | |
| r0 = load_address PyRange_Type | |
| r1 = object 4 | |
| r2 = object 12 | |
| r3 = object 2 | |
| r4 = [r1, r2, r3] | |
| r5 = load_address r4 | |
| r6 = PyObject_Vectorcall(r0, r5, 3, 0) | |
| keep_alive r1, r2, r3 | |
| r7 = cast(range, r6) | |
| r = r7 | |
| sum = 0 | |
| r8 = PyObject_GetIter(r) | |
| L1: | |
| r9 = PyIter_Next(r8) | |
| if is_error(r9) goto L4 else goto L2 | |
| L2: | |
| r10 = unbox(int, r9) | |
| i = r10 | |
| r11 = CPyTagged_Add(sum, i) | |
| sum = r11 | |
| L3: | |
| goto L1 | |
| L4: | |
| r12 = CPy_NoErrOccurred() | |
| L5: | |
| return 1 | |
| def range_in_loop(): | |
| sum :: int | |
| r0 :: short_int | |
| i :: int | |
| r1 :: bit | |
| r2 :: int | |
| r3 :: short_int | |
| L0: | |
| sum = 0 | |
| r0 = 8 | |
| i = r0 | |
| L1: | |
| r1 = int_lt r0, 24 | |
| if r1 goto L2 else goto L4 :: bool | |
| L2: | |
| i = r0 | |
| r2 = CPyTagged_Add(sum, i) | |
| sum = r2 | |
| L3: | |
| r3 = r0 + 4 | |
| r0 = r3 | |
| goto L1 | |
| L4: | |
| return 1 | |
| [case testLocalRedefinition] | |
| # mypy: allow-redefinition-old | |
| def f() -> None: | |
| i = 0 | |
| i += 1 | |
| i = "foo" | |
| i += i | |
| i = 0.0 | |
| [out] | |
| def f(): | |
| i, r0 :: int | |
| r1, i__redef__, r2 :: str | |
| i__redef____redef__ :: float | |
| L0: | |
| i = 0 | |
| r0 = CPyTagged_Add(i, 2) | |
| i = r0 | |
| r1 = 'foo' | |
| i__redef__ = r1 | |
| r2 = CPyStr_Append(i__redef__, i__redef__) | |
| i__redef__ = r2 | |
| i__redef____redef__ = 0.0 | |
| return 1 | |
| [case testNewType] | |
| from typing import NewType | |
| class A: pass | |
| N = NewType("N", A) | |
| def f(arg: A) -> N: | |
| return N(arg) | |
| [out] | |
| def f(arg): | |
| arg :: __main__.A | |
| L0: | |
| return arg | |
| [case testTypeCheckingFlag] | |
| from typing import TYPE_CHECKING, List | |
| def f(arg: List[int]) -> int: | |
| if TYPE_CHECKING: | |
| from collections.abc import Sized | |
| s: Sized = arg | |
| return len(s) | |
| [out] | |
| def f(arg): | |
| arg :: list | |
| r0 :: bool | |
| r1 :: int | |
| r2 :: bit | |
| s :: object | |
| r3 :: int | |
| L0: | |
| r0 = 0 << 1 | |
| r1 = extend r0: builtins.bool to builtins.int | |
| r2 = r1 != 0 | |
| if r2 goto L1 else goto L2 :: bool | |
| L1: | |
| goto L3 | |
| L2: | |
| L3: | |
| s = arg | |
| r3 = CPyObject_Size(s) | |
| return r3 | |
| [case testUndefinedFunction] | |
| def f(): | |
| non_existent_function() | |
| [out] | |
| def f(): | |
| r0 :: bool | |
| r1, r2, r3 :: object | |
| L0: | |
| r0 = raise NameError('name "non_existent_function" is not defined') | |
| r1 = box(None, 1) | |
| r2 = PyObject_Vectorcall(r1, 0, 0, 0) | |
| r3 = box(None, 1) | |
| return r3 | |
| [case testStarArgFastPathTuple] | |
| from typing import Any, Callable | |
| def deco(fn: Callable[..., Any]) -> Callable[..., Any]: | |
| def wrapper(*args: Any) -> Any: | |
| return fn(*args) | |
| return wrapper | |
| [out] | |
| def wrapper_deco_obj.__get__(__mypyc_self__, instance, owner): | |
| __mypyc_self__, instance, owner, r0 :: object | |
| r1 :: bit | |
| r2 :: object | |
| L0: | |
| r0 = load_address _Py_NoneStruct | |
| r1 = instance == r0 | |
| if r1 goto L1 else goto L2 :: bool | |
| L1: | |
| return __mypyc_self__ | |
| L2: | |
| r2 = PyMethod_New(__mypyc_self__, instance) | |
| return r2 | |
| def wrapper_deco_obj.__call__(__mypyc_self__, args): | |
| __mypyc_self__ :: __main__.wrapper_deco_obj | |
| args :: tuple | |
| r0 :: __main__.deco_env | |
| r1, r2 :: object | |
| L0: | |
| r0 = borrow __mypyc_self__.__mypyc_env__ | |
| r1 = r0.fn | |
| r2 = PyObject_CallObject(r1, args) | |
| return r2 | |
| def deco(fn): | |
| fn :: object | |
| r0 :: __main__.deco_env | |
| r1 :: bool | |
| r2 :: __main__.wrapper_deco_obj | |
| wrapper :: object | |
| L0: | |
| r0 = deco_env() | |
| r0.fn = fn; r1 = is_error | |
| r2 = wrapper_deco_obj() | |
| r2.__mypyc_env__ = r0 | |
| wrapper = r2 | |
| return wrapper | |
| [case testStarArgFastPathList] | |
| from typing import Any, Callable | |
| def deco(fn: Callable[..., Any]) -> Callable[[list[Any]], Any]: | |
| def wrapper(args: list[Any]) -> Any: | |
| return fn(*args) | |
| return wrapper | |
| [out] | |
| def wrapper_deco_obj.__get__(__mypyc_self__, instance, owner): | |
| __mypyc_self__, instance, owner, r0 :: object | |
| r1 :: bit | |
| r2 :: object | |
| L0: | |
| r0 = load_address _Py_NoneStruct | |
| r1 = instance == r0 | |
| if r1 goto L1 else goto L2 :: bool | |
| L1: | |
| return __mypyc_self__ | |
| L2: | |
| r2 = PyMethod_New(__mypyc_self__, instance) | |
| return r2 | |
| def wrapper_deco_obj.__call__(__mypyc_self__, args): | |
| __mypyc_self__ :: __main__.wrapper_deco_obj | |
| args :: list | |
| r0 :: __main__.deco_env | |
| r1 :: object | |
| r2 :: tuple | |
| r3 :: object | |
| L0: | |
| r0 = borrow __mypyc_self__.__mypyc_env__ | |
| r1 = r0.fn | |
| r2 = PyList_AsTuple(args) | |
| r3 = PyObject_CallObject(r1, r2) | |
| return r3 | |
| def deco(fn): | |
| fn :: object | |
| r0 :: __main__.deco_env | |
| r1 :: bool | |
| r2 :: __main__.wrapper_deco_obj | |
| wrapper :: object | |
| L0: | |
| r0 = deco_env() | |
| r0.fn = fn; r1 = is_error | |
| r2 = wrapper_deco_obj() | |
| r2.__mypyc_env__ = r0 | |
| wrapper = r2 | |
| return wrapper | |
| [case testStarArgFastPathListWithKwargs] | |
| from typing import Any, Callable | |
| def deco(fn: Callable[..., Any]) -> Callable[..., Any]: | |
| def wrapper(lst: list[Any], kwargs: dict[str, Any]) -> Any: | |
| return fn(*lst, **kwargs) | |
| return wrapper | |
| [out] | |
| def wrapper_deco_obj.__get__(__mypyc_self__, instance, owner): | |
| __mypyc_self__, instance, owner, r0 :: object | |
| r1 :: bit | |
| r2 :: object | |
| L0: | |
| r0 = load_address _Py_NoneStruct | |
| r1 = instance == r0 | |
| if r1 goto L1 else goto L2 :: bool | |
| L1: | |
| return __mypyc_self__ | |
| L2: | |
| r2 = PyMethod_New(__mypyc_self__, instance) | |
| return r2 | |
| def wrapper_deco_obj.__call__(__mypyc_self__, lst, kwargs): | |
| __mypyc_self__ :: __main__.wrapper_deco_obj | |
| lst :: list | |
| kwargs :: dict | |
| r0 :: __main__.deco_env | |
| r1 :: object | |
| r2 :: tuple | |
| r3 :: dict | |
| r4 :: object | |
| L0: | |
| r0 = borrow __mypyc_self__.__mypyc_env__ | |
| r1 = r0.fn | |
| r2 = PyList_AsTuple(lst) | |
| r3 = PyDict_Copy(kwargs) | |
| r4 = PyObject_Call(r1, r2, r3) | |
| return r4 | |
| def deco(fn): | |
| fn :: object | |
| r0 :: __main__.deco_env | |
| r1 :: bool | |
| r2 :: __main__.wrapper_deco_obj | |
| wrapper :: object | |
| L0: | |
| r0 = deco_env() | |
| r0.fn = fn; r1 = is_error | |
| r2 = wrapper_deco_obj() | |
| r2.__mypyc_env__ = r0 | |
| wrapper = r2 | |
| return wrapper | |
| [case testStarArgFastPathSequence] | |
| from typing import Any, Callable | |
| def deco(fn: Callable[[Any], Any]) -> Callable[[Any], Any]: | |
| def wrapper(args: Any) -> Any: | |
| return fn(*args) | |
| return wrapper | |
| [out] | |
| def wrapper_deco_obj.__get__(__mypyc_self__, instance, owner): | |
| __mypyc_self__, instance, owner, r0 :: object | |
| r1 :: bit | |
| r2 :: object | |
| L0: | |
| r0 = load_address _Py_NoneStruct | |
| r1 = instance == r0 | |
| if r1 goto L1 else goto L2 :: bool | |
| L1: | |
| return __mypyc_self__ | |
| L2: | |
| r2 = PyMethod_New(__mypyc_self__, instance) | |
| return r2 | |
| def wrapper_deco_obj.__call__(__mypyc_self__, args): | |
| __mypyc_self__ :: __main__.wrapper_deco_obj | |
| args :: object | |
| r0 :: __main__.deco_env | |
| r1 :: object | |
| r2 :: tuple | |
| r3 :: object | |
| L0: | |
| r0 = borrow __mypyc_self__.__mypyc_env__ | |
| r1 = r0.fn | |
| r2 = PySequence_Tuple(args) | |
| r3 = PyObject_CallObject(r1, r2) | |
| return r3 | |
| def deco(fn): | |
| fn :: object | |
| r0 :: __main__.deco_env | |
| r1 :: bool | |
| r2 :: __main__.wrapper_deco_obj | |
| wrapper :: object | |
| L0: | |
| r0 = deco_env() | |
| r0.fn = fn; r1 = is_error | |
| r2 = wrapper_deco_obj() | |
| r2.__mypyc_env__ = r0 | |
| wrapper = r2 | |
| return wrapper | |
| [case testStarArgFastPathSequenceWithKwargs] | |
| from typing import Any, Callable | |
| def deco(fn: Callable[[Any], Any]) -> Callable[[Any], Any]: | |
| def wrapper(args: Any, **kwargs: Any) -> Any: | |
| return fn(*args, **kwargs) | |
| return wrapper | |
| [out] | |
| def wrapper_deco_obj.__get__(__mypyc_self__, instance, owner): | |
| __mypyc_self__, instance, owner, r0 :: object | |
| r1 :: bit | |
| r2 :: object | |
| L0: | |
| r0 = load_address _Py_NoneStruct | |
| r1 = instance == r0 | |
| if r1 goto L1 else goto L2 :: bool | |
| L1: | |
| return __mypyc_self__ | |
| L2: | |
| r2 = PyMethod_New(__mypyc_self__, instance) | |
| return r2 | |
| def wrapper_deco_obj.__call__(__mypyc_self__, args, kwargs): | |
| __mypyc_self__ :: __main__.wrapper_deco_obj | |
| args :: object | |
| kwargs :: dict | |
| r0 :: __main__.deco_env | |
| r1 :: object | |
| r2 :: tuple | |
| r3 :: dict | |
| r4 :: object | |
| L0: | |
| r0 = borrow __mypyc_self__.__mypyc_env__ | |
| r1 = r0.fn | |
| r2 = PySequence_Tuple(args) | |
| r3 = PyDict_Copy(kwargs) | |
| r4 = PyObject_Call(r1, r2, r3) | |
| return r4 | |
| def deco(fn): | |
| fn :: object | |
| r0 :: __main__.deco_env | |
| r1 :: bool | |
| r2 :: __main__.wrapper_deco_obj | |
| wrapper :: object | |
| L0: | |
| r0 = deco_env() | |
| r0.fn = fn; r1 = is_error | |
| r2 = wrapper_deco_obj() | |
| r2.__mypyc_env__ = r0 | |
| wrapper = r2 | |
| return wrapper | |
| [case testStaticLength] | |
| def get_length() -> int: | |
| return len("https://w3id.org/cwl/salad#") | |
| [out] | |
| def get_length(): | |
| r0 :: str | |
| L0: | |
| r0 = 'https://w3id.org/cwl/salad#' | |
| return 54 |