Salome HOME
projects
/
modules
/
yacs.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
history
|
raw
|
HEAD
Updated copyright comment
[modules/yacs.git]
/
src
/
py2yacs
/
Test
/
example_while.py
1
import yacsdecorator
2
3
@yacsdecorator.leaf
4
def while_func(context):
5
context -= 1
6
print("while ", context)
7
cond = context > 0
8
return cond, context
9
10
@yacsdecorator.leaf
11
def extra_init():
12
a = 5
13
return a
14
15
@yacsdecorator.leaf
16
def post(x):
17
v = x
18
return v
19
20
@yacsdecorator.leaf
21
def f1(x):
22
y = x + 2
23
return y
24
25
@yacsdecorator.leaf
26
def f2(x):
27
y = x * 2
28
return y
29
30
@yacsdecorator.leaf
31
def g(a, b):
32
r = a + b
33
print("g(", r, ")")
34
cond = r < 100
35
return cond, r
36
37
@yacsdecorator.block
38
def while_block(context):
39
a = f1(context)
40
b = f2(context)
41
cond, r = g(a,b)
42
return cond, r
43
44
@yacsdecorator.block
45
def main():
46
v = extra_init()
47
x = yacsdecorator.whileloop(while_func, v)
48
post(x)
49
yacsdecorator.whileloop(while_func, 3)
50
r = yacsdecorator.whileloop(while_block, 1)
51
print("r final:", r)
52
53
if __name__ == "__main__" :
54
main()