Changeset 1068
- Timestamp:
- 12/06/07 11:00:13 (1 year ago)
- Files:
-
- trunk/ProjectFortress/astgen/Fortress.ast (modified) (3 diffs)
- trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/Evaluator.java (modified) (2 diffs)
- trunk/ProjectFortress/src/com/sun/fortress/parser/Expression.rats (modified) (3 diffs)
- trunk/ProjectFortress/src/com/sun/fortress/parser/MethodParam.rats (modified) (1 diff)
- trunk/ProjectFortress/static_tests/lib/FortressLibrary.tfs (modified) (7 diffs)
- trunk/ProjectFortress/test_library/FortressAst.fsi (modified) (12 diffs)
- trunk/ProjectFortress/test_library/FortressAst.fss (modified) (12 diffs)
- trunk/ProjectFortress/tests/SubscriptedExpr.fss (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ProjectFortress/astgen/Fortress.ast
r1048 r1068 839 839 /** 840 840 * subscripting expression 841 * SubscriptExpr ::= Primary [ ExprList? ] 842 * | Primary LeftEncloser ExprList? RightEncloser 841 * SubscriptExpr ::= Primary LeftEncloser ExprList? RightEncloser 843 842 * e.g.) a[i] 844 843 */ … … 1185 1184 */ 1186 1185 UnitArg(UnitExpr unit); 1187 _RewriteImplicitType(); 1186 _RewriteImplicitType(); 1188 1187 /** 1189 1188 * static expression … … 1702 1701 Bracketing(); 1703 1702 /** 1704 * subscripting operator1703 * subscripting and subscripted assignment operator 1705 1704 * e.g.) a[i] 1706 1705 */ 1707 1706 SubscriptOp(); 1708 /**1709 * subscripted assignment operator1710 * e.g.) a[i] := 11711 */1712 SubscriptAssign();1713 1707 /** 1714 1708 * internal name for anonymous function expressions trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/Evaluator.java
r1065 r1068 141 141 import com.sun.fortress.nodes.StaticArg; 142 142 import com.sun.fortress.nodes.StringLiteral; 143 import com.sun.fortress.nodes.SubscriptAssign;144 143 import com.sun.fortress.nodes.SubscriptExpr; 145 144 import com.sun.fortress.nodes.SubscriptOp; … … 1129 1128 } 1130 1129 1131 public FValue forSubscriptAssign(SubscriptAssign x) {1132 // Didn't come here when it seemed like we should have.1133 // See LHSEvaluator.forSubscriptExpr1134 return NI("forSubscriptAssign");1135 }1136 1137 1130 /* 1138 1131 * (non-Javadoc) trunk/ProjectFortress/src/com/sun/fortress/parser/Expression.rats
r1038 r1068 90 90 | FieldSelection 91 91 | QualifiedName 92 SubscriptExpr ::= Primay [ (w ExprList)? w ]92 SubscriptExpr ::= Primay LeftEncloser (w ExprList)? w RightEncloser 93 93 FieldSelection ::= Primary . Id 94 94 */ 95 95 LHS AssignLeft = 96 seed:PrimaryFront list:AssignLeftTail+97 { Expr left = (Expr)apply(list, seed);98 if (left instanceof LHS) yyValue = (LHS)left;99 else yyValue = null;100 }101 / a1:QualifiedName102 { yyValue = new VarRef(createSpan(yyStart,yyCount), false, a1); };96 seed:PrimaryFront list:AssignLeftTail+ 97 { Expr left = (Expr)apply(list, seed); 98 if (left instanceof LHS) yyValue = (LHS)left; 99 else yyValue = null; 100 } 101 / a1:QualifiedName 102 { yyValue = new VarRef(createSpan(yyStart,yyCount), false, a1); }; 103 103 104 104 constant transient Action<Expr> AssignLeftTail = 105 SubscriptAssign106 / FieldSelectionAssign107 ;105 SubscriptAssign 106 / FieldSelectionAssign 107 ; 108 108 109 109 constant inline Action<Expr> SubscriptAssign = 110 a1:opensquare a2:(w ExprList)? w a3:closesquare 111 { yyValue = new Action<Expr>() { 112 public Expr run(Expr base) { 113 List<Expr> es; 114 if (a2 == null) es = FortressUtil.emptyExprs(); 115 else es = a2; 116 Span span = createSpan(yyStart,yyCount); 117 Op open = NodeFactory.makeOp(createSpan(yyStart, yyStart+1), a1); 118 Op close = NodeFactory.makeOp(createSpan(yyCount-1,1),a3); 119 SubscriptOp op = new SubscriptOp(span, open, close); 120 return ExprFactory.makeSubscriptExpr(span,base,es,Option.some(op)); 121 }}; 122 }; 110 a1:LeftEncloser a2:(w ExprList)? w a3:RightEncloser 111 { yyValue = new Action<Expr>() { 112 public Expr run(Expr base) { 113 Span span = createSpan(yyStart,yyCount); 114 List<Expr> es; 115 if (a2 == null) es = FortressUtil.emptyExprs(); 116 else es = a2; 117 SubscriptOp op = new SubscriptOp(FortressUtil.spanTwo(a1,a3),a1,a3); 118 return ExprFactory.makeSubscriptExpr(span,base,es,Option.some(op)); 119 }}; 120 }; 123 121 124 122 constant inline Action<Expr> FieldSelectionAssign = … … 290 288 | BaseExpr 291 289 | LeftEncloser (w ExprList)? w RightEncloser 292 | Primary [ (w ExprList)? w ]293 290 | Primary LeftEncloser (w ExprList)? w RightEncloser 294 291 | Primary . Id ([\ w StaticArgList w \])? TupleExpr … … 330 327 331 328 constant inline Action<PureList<Expr>> SubscriptExpr = 332 a1:opensquare a2:(w ExprList)? w a3:closesquare 333 { yyValue = new Action<PureList<Expr>>() { 334 public PureList<Expr> run(PureList<Expr> base) { 335 Span span = createSpan(yyStart,yyCount); 336 Expr arr = FortressUtil.buildPrimary((PureList<Expr>)base); 337 List<Expr> es; 338 if (a2 == null) es = FortressUtil.emptyExprs(); 339 else es = a2; 340 Op open = NodeFactory.makeOp(createSpan(yyStart, yyStart+1), a1); 341 Op close = NodeFactory.makeOp(createSpan(yyCount-1,1),a3); 342 SubscriptOp op = new SubscriptOp(span, open, close); 343 return PureList.make((Expr)ExprFactory.makeSubscriptExpr(span, arr, es, Option.some(op))); 344 }}; 345 } 346 / a1:LeftEncloser a2:(w ExprList)? w a3:RightEncloser 329 a1:LeftEncloser a2:(w ExprList)? w a3:RightEncloser 347 330 { yyValue = new Action<PureList<Expr>>() { 348 331 public PureList<Expr> run(PureList<Expr> base) { trunk/ProjectFortress/src/com/sun/fortress/parser/MethodParam.rats
r1038 r1068 66 66 name = new Bracketing(span, opa2, opa4); 67 67 } else { 68 if (opa5 == null) name = new SubscriptOp(span, opa2, opa4); 69 else name = new SubscriptAssign(span, opa2, opa4); 68 name = new SubscriptOp(span, opa2, opa4); 70 69 } 71 70 } else trunk/ProjectFortress/static_tests/lib/FortressLibrary.tfs
r1048 r1068 3071 3071 (AbsFnDecl @686:2~690:2 3072 3072 _contract=(Contract @"":0:0) 3073 _name=(Subscript Assign@"FortressLibrary.fss":686:2~163073 _name=(SubscriptOp @"FortressLibrary.fss":686:2~16 3074 3074 _close=(Op @686:9 _text="]") 3075 3075 _open=(Op @686:5~6 _text="[")) … … 3091 3091 (AbsFnDecl @690:2~691:2 3092 3092 _contract=(Contract @"":0:0) 3093 _name=(Subscript Assign@"FortressLibrary.fss":690:2~383093 _name=(SubscriptOp @"FortressLibrary.fss":690:2~38 3094 3094 _close=(Op @690:18 _text="]") 3095 3095 _open=(Op @690:5~6 _text="[")) … … 3127 3127 (AbsFnDecl @691:2~79 3128 3128 _contract=(Contract @"":0:0) 3129 _name=(Subscript Assign@"FortressLibrary.fss":691:2~443129 _name=(SubscriptOp @"FortressLibrary.fss":691:2~44 3130 3130 _close=(Op @691:24 _text="]") 3131 3131 _open=(Op @691:5~6 _text="[")) … … 4005 4005 (AbsFnDecl @767:4~768:6 4006 4006 _contract=(Contract @"":0:0) 4007 _name=(Subscript Assign@"FortressLibrary.fss":767:4~184007 _name=(SubscriptOp @"FortressLibrary.fss":767:4~18 4008 4008 _close=(Op @767:11 _text="]") 4009 4009 _open=(Op @767:7~8 _text="[")) … … 4043 4043 (AbsFnDecl @770:4~781:9 4044 4044 _contract=(Contract @"":0:0) 4045 _name=(Subscript Assign@"FortressLibrary.fss":770:4~404045 _name=(SubscriptOp @"FortressLibrary.fss":770:4~40 4046 4046 _close=(Op @770:20 _text="]") 4047 4047 _open=(Op @770:7~8 _text="[")) … … 6349 6349 (AbsFnDecl @1056:2~58 6350 6350 _contract=(Contract @"":0:0) 6351 _name=(Subscript Assign@"FortressLibrary.fss":1056:2~266351 _name=(SubscriptOp @"FortressLibrary.fss":1056:2~26 6352 6352 _close=(Op @1056:19 _text="]") 6353 6353 _open=(Op @1056:5~6 _text="[")) … … 9664 9664 (AbsFnDecl @1374:2~68 9665 9665 _contract=(Contract @"":0:0) 9666 _name=(Subscript Assign@"FortressLibrary.fss":1374:2~379666 _name=(SubscriptOp @"FortressLibrary.fss":1374:2~37 9667 9667 _close=(Op @1374:28 _text="]") 9668 9668 _open=(Op @1374:5~6 _text="[")) trunk/ProjectFortress/test_library/FortressAst.fsi
r1063 r1068 19 19 20 20 (* Fortress representation of Fortress AST nodes *) 21 trait Node 21 trait Node 22 22 toString():String 23 23 end … … 73 73 (* TODO: Implement traitObjectAbsDeclOrDecls *) 74 74 75 trait VarAbsDeclOrDecl extends AbsDeclOrDecl 75 trait VarAbsDeclOrDecl extends AbsDeclOrDecl 76 76 lhs:List[\LValueBind\] 77 77 end … … 154 154 155 155 trait TaggedUnitExpr extends Expr 156 val : Expr 156 val : Expr 157 157 unitExpr : UnitExpr 158 158 end … … 185 185 object FnExpr(parenthesized:Boolean, name:SimpleName, staticParams:List[\StaticParam\], params:List[\Param\], returnType:Maybe[\Type\], whereClause:List[\WhereClause\], throwsClause:Maybe[\List[\TraitType\]\], body:Expr) extends { Expr, Applicable } end 186 186 187 trait LetExpr extends Expr 187 trait LetExpr extends Expr 188 188 body:List[\Expr\] 189 189 end … … 192 192 193 193 object GeneratedExpr(expr:Expr, gens:List[\Generator\]) extends Expr end 194 194 195 195 trait OpExpr extends Expr end 196 196 object OprExpr(ops:List[\QualifiedOpName\], args:List[\Expr\]) extends OpExpr end … … 206 206 object FieldRef(field:IdName) extends AbstractFieldRef end 207 207 208 trait Juxt extends Primary 208 trait Juxt extends Primary 209 209 exprs:List[\Expr\] 210 210 end … … 221 221 object VarRef(avar:QualifiedIdName) extends { BaseExpr, Lhs } end 222 222 223 trait Literal extends BaseExpr 223 trait Literal extends BaseExpr 224 224 text:String 225 225 end … … 246 246 object ArrayComprehension(List[\ArrayComprehensionClause\] clauses) extends Comprehension end 247 247 *) 248 trait GeneratedComprehension extends Comprehension 248 trait GeneratedComprehension extends Comprehension 249 249 gens:List[\Generator\] 250 250 end … … 255 255 trait Type extends AbstractNode end 256 256 object ArrowType(domain:Type, range:Type, throwsClause:Maybe[\List[\TraitType\]\]) extends Type end 257 257 258 258 trait NonArrowType extends Type end 259 259 trait TraitType extends NonArrowType end … … 262 262 object MatrixType(element:Type, dimensions:List[\ExtentRange\]) extends TraitType end 263 263 object InstantiatedType(name:QualifiedIdName, args:List[\StaticArg\]) extends TraitType end 264 264 265 265 object TupleType(elements:List[\Type\], varargs:Maybe[\VarargsType\], keywords:List[\KeywordType\]) extends NonArrowType end 266 266 object VoidType() extends NonArrowType end … … 286 286 *) 287 287 trait BoolExpr extends StaticExpr end 288 288 289 289 (* TODO: rest *) 290 290 (** … … 408 408 object Bracketing(open:Op, close:Op) extends Enclosing end 409 409 (** 410 * subscripting o perator410 * subscripting or subscripted assignment operator 411 411 * e.g.) a[i] 412 412 *) 413 413 object SubscriptOp(open:Op, close:Op) extends Enclosing end 414 (**415 * subscripted assignment operator416 * e.g.) a[i] := 1417 *)418 object SubscriptAssign(open:Op, close:Op) extends Enclosing end419 414 420 415 (* TODO: Implement AnonymousFnName *) trunk/ProjectFortress/test_library/FortressAst.fss
r1064 r1068 25 25 (* Fortress representation of Fortress AST nodes *) 26 26 27 trait Node 27 trait Node 28 28 toString():String = "Node" 29 29 end … … 79 79 (* TODO: Implement traitObjectAbsDeclOrDecls *) 80 80 81 trait VarAbsDeclOrDecl extends AbsDeclOrDecl 81 trait VarAbsDeclOrDecl extends AbsDeclOrDecl 82 82 lhs:List[\LValueBind\] 83 83 end … … 160 160 161 161 trait TaggedUnitExpr extends Expr 162 val : Expr 162 val : Expr 163 163 unitExpr : UnitExpr 164 164 end … … 191 191 object FnExpr(parenthesized:Boolean, name:SimpleName, staticParams:List[\StaticParam\], params:List[\Param\], returnType:Maybe[\Type\], whereClause:List[\WhereClause\], throwsClause:Maybe[\List[\TraitType\]\], body:Expr) extends { Expr, Applicable } end 192 192 193 trait LetExpr extends Expr 193 trait LetExpr extends Expr 194 194 body:List[\Expr\] 195 195 end … … 198 198 199 199 object GeneratedExpr(expr:Expr, gens:List[\Generator\]) extends Expr end 200 200 201 201 trait OpExpr extends Expr end 202 202 object OprExpr(ops:List[\QualifiedOpName\], args:List[\Expr\]) extends OpExpr end … … 212 212 object FieldRef(field:IdName) extends AbstractFieldRef end 213 213 214 trait Juxt extends Primary 214 trait Juxt extends Primary 215 215 exprs:List[\Expr\] 216 216 end … … 227 227 object VarRef(avar:QualifiedIdName) extends { BaseExpr, Lhs } end 228 228 229 trait Literal extends BaseExpr 229 trait Literal extends BaseExpr 230 230 text:String 231 231 end … … 252 252 object ArrayComprehension(List[\ArrayComprehensionClause\] clauses) extends Comprehension end 253 253 *) 254 trait GeneratedComprehension extends Comprehension 254 trait GeneratedComprehension extends Comprehension 255 255 gens:List[\Generator\] 256 256 end … … 261 261 trait Type extends AbstractNode end 262 262 object ArrowType(domain:Type, range:Type, throwsClause:Maybe[\List[\TraitType\]\]) extends Type end 263 263 264 264 trait NonArrowType extends Type end 265 265 trait TraitType extends NonArrowType end … … 268 268 object MatrixType(element:Type, dimensions:List[\ExtentRange\]) extends TraitType end 269 269 object InstantiatedType(name:QualifiedIdName, args:List[\StaticArg\]) extends TraitType end 270 270 271 271 object TupleType(elements:List[\Type\], varargs:Maybe[\VarargsType\], keywords:List[\KeywordType\]) extends NonArrowType end 272 272 object VoidType() extends NonArrowType end … … 292 292 *) 293 293 trait BoolExpr extends StaticExpr end 294 294 295 295 (* TODO: rest *) 296 296 (** … … 414 414 object Bracketing(open:Op, close:Op) extends Enclosing end 415 415 (** 416 * subscripting o perator416 * subscripting or subscripted assignment operator 417 417 * e.g.) a[i] 418 418 *) 419 419 object SubscriptOp(open:Op, close:Op) extends Enclosing end 420 (**421 * subscripted assignment operator422 * e.g.) a[i] := 1423 *)424 object SubscriptAssign(open:Op, close:Op) extends Enclosing end425 420 426 421 (* TODO: Implement AnonymousFnName *) trunk/ProjectFortress/tests/SubscriptedExpr.fss
r904 r1068 21 21 22 22 object O 23 opr(/i:ZZ32/) : String = "SubscriptedExpr: (//)" 24 opr[i:ZZ32] : String = "SubscriptedExpr: []" 23 round: ZZ32[5] = array1[\ZZ32,5\]().fill(2) 24 flat : ZZ32[5] = array1[\ZZ32,5\]().fill(1) 25 opr(/i:ZZ32/): ZZ32 = round[i] 26 opr(/i:ZZ32/):=(v:ZZ32) = round[i] := v 27 opr[i:ZZ32] : ZZ32 = flat[i] 28 opr[i:ZZ32] :=(v:ZZ32) = flat[i] := v 25 29 end 26 30 27 run(args:String...) = if O[0] = O(/0/) then 28 println "FAIL!" 29 println O[0] 30 println O(/0/) 31 else 32 println O[0] 33 println O(/0/) 34 println "OK" 35 end 31 run(args:String...) = 32 if O[0] = O(/0/) then 33 println "FAIL!" 34 println O[0] 35 println O(/0/) 36 else 37 O(/2/) := 11 38 O[2] := 12 39 assert(O(/2/),11,"O(/2/) wrong") 40 assert(O[2],12,"O[2] wrong") 41 end 42 36 43 end
