| 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 | api For |
|---|
| 18 | |
|---|
| 19 | import FortressAst.{...} |
|---|
| 20 | import FortressSyntax.{...} |
|---|
| 21 | |
|---|
| 22 | object Unreachable extends UncheckedException end |
|---|
| 23 | |
|---|
| 24 | grammar ForLoop extends {Expression, Identifier} |
|---|
| 25 | Expr |:= for b:forStart => <[ b ]> |
|---|
| 26 | |
|---|
| 27 | forStart :Expr:= |
|---|
| 28 | i:Id <- e:Expr d:doFront => <[ ((e).loop(fn i => d)) ]> |
|---|
| 29 | | e:Expr d:doFront => <[ if e then d end ]> |
|---|
| 30 | | i:Id <- e:Expr , b:forStart => <[ ((e).loop(fn i => b)) ]> |
|---|
| 31 | | e:Expr , b:forStart => <[ if e then b end ]> |
|---|
| 32 | |
|---|
| 33 | doFront :Expr:= |
|---|
| 34 | a:atomicFront => <[ a ]> |
|---|
| 35 | | at e:Expr a:atomicFront => <[ a ]> |
|---|
| 36 | |
|---|
| 37 | atomicFront :Expr:= |
|---|
| 38 | do d:doBody => <[ d ]> |
|---|
| 39 | | atomic do d:doBody => |
|---|
| 40 | <[ label atomicBlock |
|---|
| 41 | while true do |
|---|
| 42 | try |
|---|
| 43 | result = tryatomic d |
|---|
| 44 | exit atomicBlock with result |
|---|
| 45 | catch e |
|---|
| 46 | TryAtomicFailure => () |
|---|
| 47 | end |
|---|
| 48 | end |
|---|
| 49 | throw Unreachable |
|---|
| 50 | end atomicBlock |
|---|
| 51 | ]> |
|---|
| 52 | |
|---|
| 53 | doBody :Expr:= |
|---|
| 54 | end => <[ () ]> |
|---|
| 55 | | block:Expr end => <[ block ]> |
|---|
| 56 | end |
|---|
| 57 | |
|---|
| 58 | end |
|---|