-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontrol_flow.py
70 lines (54 loc) · 1.03 KB
/
control_flow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
from wasmfunc import i32, wasmfunc
@wasmfunc()
def while_loop() -> i32:
i: i32 = 1
j: i32 = 0
i += 1
j = i
i *= 3
while i < 20:
i = i + 1
if i == 10:
continue
if i == 24:
break
j -= i
else:
i = i - 1
j *= i
return i + j
testinputs_while_loop = [()]
@wasmfunc()
def double_while() -> i32:
i: i32 = 0
j: i32 = 0
while i < 20:
i = i + 1
while j < 50:
j = j + 1
return i + j
testinputs_double_while = [()]
@wasmfunc()
def if_else(x: i32) -> i32:
a: i32 = 0
if x > 0:
a = 1
else:
a = 6
return a
@wasmfunc()
def if_exp(x: i32) -> i32:
# y: i32 = 1 if x > 0 else 0
y: i32 = 1 if x > 42 else x - 5
return y
@wasmfunc()
def while_true() -> i32:
x = 0
while x > 10:
x += 1
if x == 10:
# return x
break
return x
testinputs_if_else = [(1,), (-5,), (8,)]
testinputs_if_exp = [(1,), (-5,), (8,), (55,), (545,)]