|
Revision 2750, 1.9 kB
(checked in by jmaessen, 3 months ago)
|
Partial cleanup of getters and setters. FortressLibrary,
FortressBuiltin, and List ought to be fully converted (but I've
undoubtedly missed a few getter calls).
|
| Line | |
|---|
| 1 |
(******************************************************************************* |
|---|
| 2 |
Copyright 2008 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 |
|
|---|
| 18 |
component AlsoDo |
|---|
| 19 |
export Executable |
|---|
| 20 |
|
|---|
| 21 |
fib(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 |
|---|
| 35 |
end |
|---|
| 36 |
|
|---|
| 37 |
testAtomicAlso() = 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") |
|---|
| 54 |
end |
|---|
| 55 |
|
|---|
| 56 |
testManyClauses() = 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") |
|---|
| 78 |
end |
|---|
| 79 |
|
|---|
| 80 |
run(args:String...):()=do |
|---|
| 81 |
assert(fib(5), 8, "fib(5)=8") |
|---|
| 82 |
testAtomicAlso() |
|---|
| 83 |
testManyClauses() |
|---|
| 84 |
end |
|---|
| 85 |
end |
|---|