blob: d9732218f68488d8d13dbfcee95a85341d6c22cb [file] [log] [blame]
[case testForInRange]
def f() -> None:
x = 0
for i in range(5):
x = x + i
[out]
def f():
r0 :: short_int
x :: int
r1, r2, r3 :: short_int
i :: int
r4 :: bool
r5 :: int
r6, r7 :: short_int
r8 :: None
L0:
r0 = 0
x = r0
r1 = 0
r2 = 5
r3 = r1
i = r3
L1:
r4 = CPyTagged_IsLt(r3, r2)
if r4 goto L2 else goto L4 :: bool
L2:
r5 = CPyTagged_Add(x, i)
x = r5
L3:
r6 = 1
r7 = r3 + r6 :: short_int
r3 = r7
i = r7
goto L1
L4:
r8 = None
return r8
[case testForInNegativeRange]
def f() -> None:
for i in range(10, 0, -1):
pass
[out]
def f():
r0, r1, r2 :: short_int
i :: int
r3 :: bool
r4, r5 :: short_int
r6 :: None
L0:
r0 = 10
r1 = 0
r2 = r0
i = r2
L1:
r3 = CPyTagged_IsGt(r2, r1)
if r3 goto L2 else goto L4 :: bool
L2:
L3:
r4 = -1
r5 = r2 + r4 :: short_int
r2 = r5
i = r5
goto L1
L4:
r6 = None
return r6
[case testBreak]
def f() -> None:
n = 0
while n < 5:
break
[out]
def f():
r0 :: short_int
n :: int
r1 :: short_int
r2 :: bool
r3 :: None
L0:
r0 = 0
n = r0
L1:
r1 = 5
r2 = CPyTagged_IsLt(n, r1)
if r2 goto L2 else goto L3 :: bool
L2:
L3:
r3 = None
return r3
[case testBreakFor]
def f() -> None:
for n in range(5):
break
[out]
def f():
r0, r1, r2 :: short_int
n :: int
r3 :: bool
r4, r5 :: short_int
r6 :: None
L0:
r0 = 0
r1 = 5
r2 = r0
n = r2
L1:
r3 = CPyTagged_IsLt(r2, r1)
if r3 goto L2 else goto L4 :: bool
L2:
goto L4
L3:
r4 = 1
r5 = r2 + r4 :: short_int
r2 = r5
n = r5
goto L1
L4:
r6 = None
return r6
[case testBreakNested]
def f() -> None:
n = 0
while n < 5:
while n < 4:
break
break
[out]
def f():
r0 :: short_int
n :: int
r1 :: short_int
r2 :: bool
r3 :: short_int
r4 :: bool
r5 :: None
L0:
r0 = 0
n = r0
L1:
r1 = 5
r2 = CPyTagged_IsLt(n, r1)
if r2 goto L2 else goto L6 :: bool
L2:
L3:
r3 = 4
r4 = CPyTagged_IsLt(n, r3)
if r4 goto L4 else goto L5 :: bool
L4:
L5:
L6:
r5 = None
return r5
[case testContinue]
def f() -> None:
n = 0
while n < 5:
continue
[out]
def f():
r0 :: short_int
n :: int
r1 :: short_int
r2 :: bool
r3 :: None
L0:
r0 = 0
n = r0
L1:
r1 = 5
r2 = CPyTagged_IsLt(n, r1)
if r2 goto L2 else goto L3 :: bool
L2:
goto L1
L3:
r3 = None
return r3
[case testContinueFor]
def f() -> None:
for n in range(5):
continue
[out]
def f():
r0, r1, r2 :: short_int
n :: int
r3 :: bool
r4, r5 :: short_int
r6 :: None
L0:
r0 = 0
r1 = 5
r2 = r0
n = r2
L1:
r3 = CPyTagged_IsLt(r2, r1)
if r3 goto L2 else goto L4 :: bool
L2:
L3:
r4 = 1
r5 = r2 + r4 :: short_int
r2 = r5
n = r5
goto L1
L4:
r6 = None
return r6
[case testContinueNested]
def f() -> None:
n = 0
while n < 5:
while n < 4:
continue
continue
[out]
def f():
r0 :: short_int
n :: int
r1 :: short_int
r2 :: bool
r3 :: short_int
r4 :: bool
r5 :: None
L0:
r0 = 0
n = r0
L1:
r1 = 5
r2 = CPyTagged_IsLt(n, r1)
if r2 goto L2 else goto L6 :: bool
L2:
L3:
r3 = 4
r4 = CPyTagged_IsLt(n, r3)
if r4 goto L4 else goto L5 :: bool
L4:
goto L3
L5:
goto L1
L6:
r5 = None
return r5
[case testForList]
from typing import List
def f(ls: List[int]) -> int:
y = 0
for x in ls:
y = y + x
return y
[out]
def f(ls):
ls :: list
r0 :: short_int
y :: int
r1, r2, r3 :: short_int
r4 :: bool
r5 :: object
x, r6, r7 :: int
r8, r9 :: short_int
L0:
r0 = 0
y = r0
r1 = 0
r2 = r1
L1:
r3 = len ls :: list
r4 = CPyTagged_IsLt(r2, r3)
if r4 goto L2 else goto L4 :: bool
L2:
r5 = ls[r2] :: unsafe list
r6 = unbox(int, r5)
x = r6
r7 = CPyTagged_Add(y, x)
y = r7
L3:
r8 = 1
r9 = r2 + r8 :: short_int
r2 = r9
goto L1
L4:
return y
[case testForDictBasic]
from typing import Dict
def f(d: Dict[int, int]) -> None:
for key in d:
d[key]
[out]
def f(d):
d :: dict
r0, r1 :: short_int
r2 :: int
r3 :: object
r4 :: tuple[bool, int, object]
r5 :: int
r6 :: bool
r7 :: object
key, r8 :: int
r9, r10 :: object
r11 :: int
r12, r13 :: bool
r14 :: None
L0:
r0 = 0
r1 = r0
r2 = len d :: dict
r3 = key_iter d :: dict
L1:
r4 = next_key r3, offset=r1
r5 = r4[1]
r1 = r5
r6 = r4[0]
if r6 goto L2 else goto L4 :: bool
L2:
r7 = r4[2]
r8 = unbox(int, r7)
key = r8
r9 = box(int, key)
r10 = d[r9] :: dict
r11 = unbox(int, r10)
L3:
r12 = assert size(d) == r2
goto L1
L4:
r13 = no_err_occurred
L5:
r14 = None
return r14
[case testForDictContinue]
from typing import Dict
def sum_over_even_values(d: Dict[int, int]) -> int:
s = 0
for key in d:
if d[key] % 2:
continue
s = s + d[key]
return s
[out]
def sum_over_even_values(d):
d :: dict
r0 :: short_int
s :: int
r1, r2 :: short_int
r3 :: int
r4 :: object
r5 :: tuple[bool, int, object]
r6 :: int
r7 :: bool
r8 :: object
key, r9 :: int
r10, r11 :: object
r12 :: int
r13 :: short_int
r14 :: int
r15 :: short_int
r16 :: bool
r17, r18 :: object
r19, r20 :: int
r21, r22 :: bool
L0:
r0 = 0
s = r0
r1 = 0
r2 = r1
r3 = len d :: dict
r4 = key_iter d :: dict
L1:
r5 = next_key r4, offset=r2
r6 = r5[1]
r2 = r6
r7 = r5[0]
if r7 goto L2 else goto L6 :: bool
L2:
r8 = r5[2]
r9 = unbox(int, r8)
key = r9
r10 = box(int, key)
r11 = d[r10] :: dict
r12 = unbox(int, r11)
r13 = 2
r14 = CPyTagged_Remainder(r12, r13)
r15 = 0
r16 = CPyTagged_IsNe(r14, r15)
if r16 goto L3 else goto L4 :: bool
L3:
goto L5
L4:
r17 = box(int, key)
r18 = d[r17] :: dict
r19 = unbox(int, r18)
r20 = CPyTagged_Add(s, r19)
s = r20
L5:
r21 = assert size(d) == r3
goto L1
L6:
r22 = no_err_occurred
L7:
return s
[case testMultipleAssignment]
from typing import Tuple, Any
def from_tuple(t: Tuple[int, str]) -> None:
x, y = t
def from_any(a: Any) -> None:
x, y = a
[out]
def from_tuple(t):
t :: tuple[int, str]
x :: int
y :: str
r0 :: int
r1 :: str
r2 :: None
L0:
r0 = t[0]
x = r0
r1 = t[1]
y = r1
r2 = None
return r2
def from_any(a):
a, x, y, r0, r1 :: object
r2 :: bool
r3 :: object
r4 :: bool
r5 :: object
r6 :: bool
r7 :: None
L0:
r0 = iter a :: object
r1 = next r0 :: object
if is_error(r1) goto L1 else goto L2
L1:
raise ValueError('not enough values to unpack')
unreachable
L2:
x = r1
r3 = next r0 :: object
if is_error(r3) goto L3 else goto L4
L3:
raise ValueError('not enough values to unpack')
unreachable
L4:
y = r3
r5 = next r0 :: object
if is_error(r5) goto L6 else goto L5
L5:
raise ValueError('too many values to unpack')
unreachable
L6:
r7 = None
return r7
[case testMultiAssignmentCoercions]
from typing import Tuple, Any
def from_tuple(t: Tuple[int, Any]) -> None:
x: object
y: int
x, y = t
def from_any(a: Any) -> None:
x: int
x, y = a
[out]
def from_tuple(t):
t :: tuple[int, object]
x :: object
y, r0 :: int
r1, r2 :: object
r3 :: int
r4 :: None
L0:
r0 = t[0]
r1 = box(int, r0)
x = r1
r2 = t[1]
r3 = unbox(int, r2)
y = r3
r4 = None
return r4
def from_any(a):
a :: object
x :: int
y, r0, r1 :: object
r2 :: bool
r3 :: int
r4 :: object
r5 :: bool
r6 :: object
r7 :: bool
r8 :: None
L0:
r0 = iter a :: object
r1 = next r0 :: object
if is_error(r1) goto L1 else goto L2
L1:
raise ValueError('not enough values to unpack')
unreachable
L2:
r3 = unbox(int, r1)
x = r3
r4 = next r0 :: object
if is_error(r4) goto L3 else goto L4
L3:
raise ValueError('not enough values to unpack')
unreachable
L4:
y = r4
r6 = next r0 :: object
if is_error(r6) goto L6 else goto L5
L5:
raise ValueError('too many values to unpack')
unreachable
L6:
r8 = None
return r8
[case testMultiAssignmentNested]
from typing import Tuple, Any, List
class A:
x: int
def multi_assign(t: Tuple[int, Tuple[str, Any]], a: A, l: List[str]) -> None:
z: int
a.x, (l[0], z) = t
[out]
def multi_assign(t, a, l):
t :: tuple[int, tuple[str, object]]
a :: __main__.A
l :: list
z :: int
r0 :: short_int
r1 :: int
r2 :: bool
r3 :: tuple[str, object]
r4 :: str
r5 :: bool
r6 :: object
r7 :: int
r8 :: None
L0:
r0 = 0
r1 = t[0]
a.x = r1; r2 = is_error
r3 = t[1]
r4 = r3[0]
r5 = CPyList_SetItem(l, r0, r4)
r6 = r3[1]
r7 = unbox(int, r6)
z = r7
r8 = None
return r8
[case testAssert]
from typing import Optional
def no_msg(x: bool) -> int:
assert x
return 1
def literal_msg(x: object) -> int:
assert x, 'message'
return 2
def complex_msg(x: Optional[str], s: str) -> None:
assert x, s
[out]
def no_msg(x):
x, r0 :: bool
r1 :: short_int
L0:
if x goto L2 else goto L1 :: bool
L1:
raise AssertionError
unreachable
L2:
r1 = 1
return r1
def literal_msg(x):
x :: object
r0, r1 :: bool
r2 :: short_int
L0:
r0 = bool x :: object
if r0 goto L2 else goto L1 :: bool
L1:
raise AssertionError('message')
unreachable
L2:
r2 = 2
return r2
def complex_msg(x, s):
x :: union[str, None]
s :: str
r0 :: object
r1 :: bool
r2 :: str
r3 :: bool
r4 :: object
r5 :: str
r6, r7 :: object
r8 :: None
L0:
r0 = builtins.None :: object
r1 = x is not r0
if r1 goto L1 else goto L2 :: bool
L1:
r2 = cast(str, x)
r3 = bool r2 :: object
if r3 goto L3 else goto L2 :: bool
L2:
r4 = builtins :: module
r5 = unicode_3 :: static ('AssertionError')
r6 = getattr r4, r5
r7 = py_call(r6, s)
CPy_Raise(r7)
unreachable
L3:
r8 = None
return r8
[case testDelList]
def delList() -> None:
l = [1, 2]
del l[1]
def delListMultiple() -> None:
l = [1, 2, 3, 4, 5, 6, 7]
del l[1], l[2], l[3]
[out]
def delList():
r0, r1 :: short_int
r2, r3 :: object
r4, l :: list
r5 :: short_int
r6 :: object
r7 :: bool
r8 :: None
L0:
r0 = 1
r1 = 2
r2 = box(short_int, r0)
r3 = box(short_int, r1)
r4 = [r2, r3]
l = r4
r5 = 1
r6 = box(short_int, r5)
r7 = l.__delitem__(r6) :: object
r8 = None
return r8
def delListMultiple():
r0, r1, r2, r3, r4, r5, r6 :: short_int
r7, r8, r9, r10, r11, r12, r13 :: object
r14, l :: list
r15, r16, r17 :: short_int
r18 :: object
r19 :: bool
r20 :: object
r21 :: bool
r22 :: object
r23 :: bool
r24 :: None
L0:
r0 = 1
r1 = 2
r2 = 3
r3 = 4
r4 = 5
r5 = 6
r6 = 7
r7 = box(short_int, r0)
r8 = box(short_int, r1)
r9 = box(short_int, r2)
r10 = box(short_int, r3)
r11 = box(short_int, r4)
r12 = box(short_int, r5)
r13 = box(short_int, r6)
r14 = [r7, r8, r9, r10, r11, r12, r13]
l = r14
r15 = 1
r16 = 2
r17 = 3
r18 = box(short_int, r15)
r19 = l.__delitem__(r18) :: object
r20 = box(short_int, r16)
r21 = l.__delitem__(r20) :: object
r22 = box(short_int, r17)
r23 = l.__delitem__(r22) :: object
r24 = None
return r24
[case testDelDict]
def delDict() -> None:
d = {"one":1, "two":2}
del d["one"]
def delDictMultiple() -> None:
d = {"one":1, "two":2, "three":3, "four":4}
del d["one"], d["four"]
[out]
def delDict():
r0 :: str
r1 :: short_int
r2 :: str
r3 :: short_int
r4 :: native_int
r5, r6 :: object
r7, d :: dict
r8 :: str
r9 :: bool
r10 :: None
L0:
r0 = unicode_1 :: static ('one')
r1 = 1
r2 = unicode_2 :: static ('two')
r3 = 2
r4 = 2
r5 = box(short_int, r1)
r6 = box(short_int, r3)
r7 = CPyDict_Build(r4, r0, r5, r2, r6)
d = r7
r8 = unicode_1 :: static ('one')
r9 = d.__delitem__(r8) :: object
r10 = None
return r10
def delDictMultiple():
r0 :: str
r1 :: short_int
r2 :: str
r3 :: short_int
r4 :: str
r5 :: short_int
r6 :: str
r7 :: short_int
r8 :: native_int
r9, r10, r11, r12 :: object
r13, d :: dict
r14, r15 :: str
r16, r17 :: bool
r18 :: None
L0:
r0 = unicode_1 :: static ('one')
r1 = 1
r2 = unicode_2 :: static ('two')
r3 = 2
r4 = unicode_3 :: static ('three')
r5 = 3
r6 = unicode_4 :: static ('four')
r7 = 4
r8 = 4
r9 = box(short_int, r1)
r10 = box(short_int, r3)
r11 = box(short_int, r5)
r12 = box(short_int, r7)
r13 = CPyDict_Build(r8, r0, r9, r2, r10, r4, r11, r6, r12)
d = r13
r14 = unicode_1 :: static ('one')
r15 = unicode_4 :: static ('four')
r16 = d.__delitem__(r14) :: object
r17 = d.__delitem__(r15) :: object
r18 = None
return r18
[case testDelAttribute]
class Dummy():
def __init__(self, x: int, y: int) -> None:
self.x = x
self.y = y
def delAttribute() -> None:
dummy = Dummy(1, 2)
del dummy.x
def delAttributeMultiple() -> None:
dummy = Dummy(1, 2)
del dummy.x, dummy.y
[out]
def Dummy.__init__(self, x, y):
self :: __main__.Dummy
x, y :: int
r0, r1 :: bool
r2 :: None
L0:
self.x = x; r0 = is_error
self.y = y; r1 = is_error
r2 = None
return r2
def delAttribute():
r0, r1 :: short_int
r2, dummy :: __main__.Dummy
r3 :: str
r4 :: bool
r5 :: None
L0:
r0 = 1
r1 = 2
r2 = Dummy(r0, r1)
dummy = r2
r3 = unicode_3 :: static ('x')
r4 = delattr dummy, r3
r5 = None
return r5
def delAttributeMultiple():
r0, r1 :: short_int
r2, dummy :: __main__.Dummy
r3 :: str
r4 :: bool
r5 :: str
r6 :: bool
r7 :: None
L0:
r0 = 1
r1 = 2
r2 = Dummy(r0, r1)
dummy = r2
r3 = unicode_3 :: static ('x')
r4 = delattr dummy, r3
r5 = unicode_4 :: static ('y')
r6 = delattr dummy, r5
r7 = None
return r7
[case testForEnumerate]
from typing import List, Iterable
def f(a: List[int]) -> None:
for i, x in enumerate(a):
i + x
def g(x: Iterable[int]) -> None:
for i, n in enumerate(x):
pass
[out]
def f(a):
a :: list
r0, r1 :: short_int
i :: int
r2, r3, r4 :: short_int
r5 :: bool
r6 :: object
x, r7, r8 :: int
r9, r10, r11, r12 :: short_int
r13 :: None
L0:
r0 = 0
r1 = r0
i = r0
r2 = 0
r3 = r2
L1:
r4 = len a :: list
r5 = CPyTagged_IsLt(r3, r4)
if r5 goto L2 else goto L4 :: bool
L2:
r6 = a[r3] :: unsafe list
r7 = unbox(int, r6)
x = r7
r8 = CPyTagged_Add(i, x)
L3:
r9 = 1
r10 = r1 + r9 :: short_int
r1 = r10
i = r10
r11 = 1
r12 = r3 + r11 :: short_int
r3 = r12
goto L1
L4:
L5:
r13 = None
return r13
def g(x):
x :: object
r0, r1 :: short_int
i :: int
r2, r3 :: object
r4, n :: int
r5, r6 :: short_int
r7 :: bool
r8 :: None
L0:
r0 = 0
r1 = r0
i = r0
r2 = iter x :: object
L1:
r3 = next r2 :: object
if is_error(r3) goto L4 else goto L2
L2:
r4 = unbox(int, r3)
n = r4
L3:
r5 = 1
r6 = r1 + r5 :: short_int
r1 = r6
i = r6
goto L1
L4:
r7 = no_err_occurred
L5:
r8 = None
return r8
[case testForZip]
from typing import List, Iterable
def f(a: List[int], b: Iterable[bool]) -> None:
for x, y in zip(a, b):
if b:
x = 1
def g(a: Iterable[bool], b: List[int]) -> None:
for x, y, z in zip(a, b, range(5)):
x = False
[out]
def f(a, b):
a :: list
b :: object
r0, r1 :: short_int
r2 :: object
r3 :: short_int
r4 :: bool
r5, r6 :: object
x, r7 :: int
r8, y, r9 :: bool
r10, r11, r12 :: short_int
r13 :: bool
r14 :: None
L0:
r0 = 0
r1 = r0
r2 = iter b :: object
L1:
r3 = len a :: list
r4 = CPyTagged_IsLt(r1, r3)
if r4 goto L2 else goto L7 :: bool
L2:
r5 = next r2 :: object
if is_error(r5) goto L7 else goto L3
L3:
r6 = a[r1] :: unsafe list
r7 = unbox(int, r6)
x = r7
r8 = unbox(bool, r5)
y = r8
r9 = bool b :: object
if r9 goto L4 else goto L5 :: bool
L4:
r10 = 1
x = r10
L5:
L6:
r11 = 1
r12 = r1 + r11 :: short_int
r1 = r12
goto L1
L7:
r13 = no_err_occurred
L8:
r14 = None
return r14
def g(a, b):
a :: object
b :: list
r0 :: object
r1, r2, r3, r4, r5 :: short_int
z :: int
r6 :: object
r7 :: short_int
r8, r9, r10, x :: bool
r11 :: object
y, r12 :: int
r13 :: bool
r14, r15, r16, r17 :: short_int
r18 :: bool
r19 :: None
L0:
r0 = iter a :: object
r1 = 0
r2 = r1
r3 = 0
r4 = 5
r5 = r3
z = r5
L1:
r6 = next r0 :: object
if is_error(r6) goto L6 else goto L2
L2:
r7 = len b :: list
r8 = CPyTagged_IsLt(r2, r7)
if r8 goto L3 else goto L6 :: bool
L3:
r9 = CPyTagged_IsLt(r5, r4)
if r9 goto L4 else goto L6 :: bool
L4:
r10 = unbox(bool, r6)
x = r10
r11 = b[r2] :: unsafe list
r12 = unbox(int, r11)
y = r12
r13 = False
x = r13
L5:
r14 = 1
r15 = r2 + r14 :: short_int
r2 = r15
r16 = 1
r17 = r5 + r16 :: short_int
r5 = r17
z = r17
goto L1
L6:
r18 = no_err_occurred
L7:
r19 = None
return r19