root/trunk/ProjectFortress/tests/AlsoDo.fss

Revision 3550, 1.9 KB (checked in by sukyoungryu, 9 months ago)

[copyright] Fixed the copyright notices.

Line 
1(*******************************************************************************
2    Copyright 2009 Sun Microsystems, Inc.,
3    4150 Network Circle, Santa Clara, California 95054, U.S.A.
4    All rights reserved.
5
6    U.S. Government Rights - Commercial software.
7    Government users are subject to the Sun Microsystems, Inc. standard
8    license agreement and applicable provisions of the FAR and its supplements.
9
10    Use is subject to license terms.
11
12    This distribution may include materials developed by third parties.
13
14    Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered
15    trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
16 ******************************************************************************)
17
18component AlsoDo
19export Executable
20
21fib(x)=do
22    var res:ZZ32 := 1
23    n1:ZZ32
24    n2:ZZ32
25
26    if x > 1 then
27        do
28            n1 = fib(x-1)
29        also do
30            n2 = fib(x-2)
31        end
32        res := n1 + n2
33    end
34    res
35end
36
37testAtomicAlso() = do
38    x:ZZ32 := 0
39    y:ZZ32 := 0
40    z:ZZ32 := 0
41    atomic do
42        x += 1
43        x += 1
44    also do
45        z := x
46    end
47    deny(z, 1, "testAtomicAlso got impossible read result")
48    atomic do
49        z := y + y
50    also do
51        y := 1
52    end
53    deny(z, 1, "testAtomicAlso got impossible write result")
54end
55
56testManyClauses() = do
57    res:ZZ32 := 0
58    atomic do
59        res += 9
60    also atomic do
61        res += 80
62    also atomic do
63        res += 700
64    also atomic do
65        res += 6000
66    also atomic do
67        res += 50000
68    also atomic do
69        res += 400000
70    also atomic do
71        res += 3000000
72    also atomic do
73        res += 20000000
74    also atomic do
75        res += 100000000
76    end
77    assert(res, 123456789, "Many atomic clauses failed")
78end
79
80run():()=do
81    assert(fib(5), 8, "fib(5)=8")
82    testAtomicAlso()
83    testManyClauses()
84end
85end
Note: See TracBrowser for help on using the browser.