forked from M-Labs/nac3
1
0
Fork 0

standalone: improve src/assignment.py

This commit is contained in:
lyken 2024-08-29 10:32:14 +08:00
parent 15ac00708a
commit 4318f8de84
No known key found for this signature in database
GPG Key ID: 3BD5FC6AC8325DD8
1 changed files with 11 additions and 1 deletions

View File

@ -9,6 +9,7 @@ def output_bool(x: bool):
def example1(): def example1():
x, *ys, z = (1, 2, 3, 4, 5) x, *ys, z = (1, 2, 3, 4, 5)
output_int32(x) output_int32(x)
output_int32(len(ys))
output_int32(ys[0]) output_int32(ys[0])
output_int32(ys[1]) output_int32(ys[1])
output_int32(ys[2]) output_int32(ys[2])
@ -18,12 +19,14 @@ def example2():
x, y, *zs = (1, 2, 3, 4, 5) x, y, *zs = (1, 2, 3, 4, 5)
output_int32(x) output_int32(x)
output_int32(y) output_int32(y)
output_int32(len(zs))
output_int32(zs[0]) output_int32(zs[0])
output_int32(zs[1]) output_int32(zs[1])
output_int32(zs[2]) output_int32(zs[2])
def example3(): def example3():
*xs, y, z = (1, 2, 3, 4, 5) *xs, y, z = (1, 2, 3, 4, 5)
output_int32(len(xs))
output_int32(xs[0]) output_int32(xs[0])
output_int32(xs[1]) output_int32(xs[1])
output_int32(xs[2]) output_int32(xs[2])
@ -31,6 +34,12 @@ def example3():
output_int32(z) output_int32(z)
def example4(): def example4():
*xs, y, z = (4, 5)
output_int32(len(xs))
output_int32(y)
output_int32(z)
def example5():
# Example from: https://docs.python.org/3/reference/simple_stmts.html#assignment-statements # Example from: https://docs.python.org/3/reference/simple_stmts.html#assignment-statements
x = [0, 1] x = [0, 1]
i = 0 i = 0
@ -44,7 +53,7 @@ class A:
def __init__(self): def __init__(self):
self.value = 1000 self.value = 1000
def example5(): def example6():
ws = [88, 7, 8] ws = [88, 7, 8]
a = A() a = A()
x, [y, *ys, a.value], ws[0], (ws[0],) = 1, (2, False, 4, 5), 99, (6,) x, [y, *ys, a.value], ws[0], (ws[0],) = 1, (2, False, 4, 5), 99, (6,)
@ -63,4 +72,5 @@ def run() -> int32:
example3() example3()
example4() example4()
example5() example5()
example6()
return 0 return 0