Changeset 3137
- Timestamp:
- 12/02/08 15:10:53 (12 months ago)
- Location:
- trunk/ProjectFortress
- Files:
-
- 11 modified
-
astgen/Fortress.ast (modified) (4 diffs)
-
src/com/sun/fortress/compiler/disambiguator/ExprDisambiguator.java (modified) (2 diffs)
-
src/com/sun/fortress/compiler/typechecker/TypeChecker.java (modified) (4 diffs)
-
src/com/sun/fortress/interpreter/evaluator/Evaluator.java (modified) (5 diffs)
-
src/com/sun/fortress/interpreter/rewrite/DesugarerVisitor.java (modified) (2 diffs)
-
src/com/sun/fortress/nodes_util/ExprFactory.java (modified) (2 diffs)
-
src/com/sun/fortress/parser/DelimitedExpr.rats (modified) (1 diff)
-
src/com/sun/fortress/syntax_abstractions/phases/Transform.java (modified) (1 diff)
-
src/com/sun/fortress/tools/FortressAstToConcrete.java (modified) (2 diffs)
-
static_tests/static_arg_inference/opr_arg_1/Expected.fsg (modified) (1 diff)
-
static_tests/static_arg_inference/simple_arg_1/Expected.fsg (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ProjectFortress/astgen/Fortress.ast
r3133 r3137 683 683 * sequence of block elements implicitly enclosed by do/end 684 684 * BlockElems ::= BlockElem+ 685 * DoFront ::= (at Expr)? atomic? do BlockElems? 685 686 * e.g.) y = x 686 687 * z = 2x 687 688 * y + z 688 */ 689 Block(List<Expr> exprs); 689 * e.g.) at a.region(j) do w := a_j 690 */ 691 Block(Option<Expr> loc = Option.<Expr>none(), 692 boolean atomicBlock = false, 693 boolean withinDo = false, 694 List<Expr> exprs); 695 /** 696 * do expression 697 * Do ::= (DoFront also)* DoFront end 698 * e.g.) do 699 * accum += treeSum(t.left) 700 * also do 701 * accum += treeSum(t.right) 702 * also do 703 * accum += t.datum 704 * end 705 */ 706 Do(List<Block> fronts); 690 707 /** 691 708 * case expression or extremum expression … … 706 723 Option<Block> elseClause = Option.<Block>none()); 707 724 /** 708 * do expression709 * Do ::= (DoFront also)* DoFront end710 * e.g.) do711 * accum += treeSum(t.left)712 * also do713 * accum += treeSum(t.right)714 * also do715 * accum += t.datum716 * end717 */718 Do(List<DoFront> fronts);719 /**720 725 * for expression 721 726 * DelimitedExpr ::= for GeneratorClauseList DoFront end … … 724 729 * end 725 730 */ 726 For(List<GeneratorClause> gens, DoFrontbody);731 For(List<GeneratorClause> gens, Block body); 727 732 /** 728 733 * if expression … … 1958 1963 CatchClause(BaseType matchType, Block body); 1959 1964 /** 1960 * block expression used in do expressions1961 * DoFront ::= (at Expr)? atomic? do BlockElems?1962 * e.g.) at a.region(j) do w := a_j1963 */1964 DoFront(Option<Expr> loc = Option.<Expr>none(),1965 boolean atomicBlock = false,1966 Block expr);1967 /**1968 1965 * if clause used in if expressions 1969 1966 * DelimitedExpr ::= if Expr then BlockElems Elifs? Else? end -
trunk/ProjectFortress/src/com/sun/fortress/compiler/disambiguator/ExprDisambiguator.java
r3132 r3137 42 42 import com.sun.fortress.nodes.DimDecl; 43 43 import com.sun.fortress.nodes.Do; 44 import com.sun.fortress.nodes.DoFront;45 44 import com.sun.fortress.nodes.Exit; 46 45 import com.sun.fortress.nodes.Expr; … … 938 937 return forForOnly(that, type_result, 939 938 pair.first(), 940 ( DoFront)that.getBody().accept(new_disambiguator));939 (Block)that.getBody().accept(new_disambiguator)); 941 940 } 942 941 -
trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeChecker.java
r3136 r3137 1609 1609 1610 1610 @Override 1611 public TypeCheckerResult forBlockOnly(Block that, Option<TypeCheckerResult> exprType_result, List<TypeCheckerResult> exprs_result) {1612 // Type is type of last expression or void if none.1613 if ( exprs_result.isEmpty() ) {1614 Block new_node = new Block(that.getSpan(), that.isParenthesized(), Option.<Type>some(Types.VOID), Collections.<Expr>emptyList());1615 return TypeCheckerResult.compose(new_node, Types.VOID, subtypeChecker, exprs_result);1616 } else {1617 List<TypeCheckerResult> body_void = allVoidButLast(exprs_result,that.getExprs());1618 Option<Type> result_type = IterUtil.last(exprs_result).type();1619 Block new_node = new Block(that.getSpan(),1620 that.isParenthesized(),1621 result_type,1622 (List<Expr>)TypeCheckerResult.astFromResults(exprs_result));1623 return TypeCheckerResult.compose(new_node, result_type, subtypeChecker,1624 TypeCheckerResult.compose(new_node, subtypeChecker, body_void),1625 TypeCheckerResult.compose(new_node, subtypeChecker, exprs_result));1626 }1627 }1628 1629 @Override1630 1611 public TypeCheckerResult forCaseExpr(CaseExpr that) { 1631 1612 Option<TypeCheckerResult> param_result = this.recurOnOptionOfExpr(that.getParam()); … … 2065 2046 } 2066 2047 2067 public TypeCheckerResult forDoFront(DoFront that) { 2068 TypeCheckerResult bodyResult = 2069 that.isAtomicBlock() ? forAtomic( 2070 that.getExpr(), 2071 errorMsg("A 'spawn' expression must not occur inside", 2072 "an 'atomic' do block.")) 2073 : that.getExpr().accept(this); 2074 2075 Option<TypeCheckerResult> loc_result_ = this.recurOnOptionOfExpr(that.getLoc()); 2076 TypeCheckerResult loc_result = loc_result_.isNone() ? new TypeCheckerResult(that) : 2077 loc_result_.unwrap(); 2078 2079 TypeCheckerResult region_result = new TypeCheckerResult(that); 2080 if (loc_result_.isSome() && loc_result_.unwrap().type().isSome()) { 2081 Type locType = loc_result_.unwrap().type().unwrap(); 2082 region_result = checkSubtype(locType, 2083 Types.REGION, 2084 that.getLoc().unwrap(), 2085 errorMsg("Location of 'do' block must ", 2086 "have type Region: ", locType)); 2087 2088 } 2089 2090 DoFront new_node = new DoFront(that.getSpan(), 2091 (Option<Expr>)TypeCheckerResult.astFromResult(loc_result_), 2092 that.isAtomicBlock(), 2093 (Block)bodyResult.ast()); 2094 return TypeCheckerResult.compose(new_node, 2095 bodyResult.type(), 2096 subtypeChecker, 2097 bodyResult, 2098 loc_result, 2099 region_result); 2048 public TypeCheckerResult forBlock(Block that) { 2049 if ( that.isAtomicBlock() ) 2050 return forAtomic(new Block(that.getSpan(), that.isParenthesized(), 2051 that.getExprType(), that.getLoc(), 2052 false, that.isWithinDo(), that.getExprs()), 2053 errorMsg("A 'spawn' expression must not occur inside", 2054 "an 'atomic' do block.")); 2055 2056 Option<TypeCheckerResult> loc_result_ = this.recurOnOptionOfExpr(that.getLoc()); 2057 TypeCheckerResult loc_result = loc_result_.isNone() ? new TypeCheckerResult(that) : 2058 loc_result_.unwrap(); 2059 2060 TypeCheckerResult region_result = new TypeCheckerResult(that); 2061 if (loc_result_.isSome() && loc_result_.unwrap().type().isSome()) { 2062 Type locType = loc_result_.unwrap().type().unwrap(); 2063 region_result = checkSubtype(locType, 2064 Types.REGION, 2065 that.getLoc().unwrap(), 2066 errorMsg("Location of 'do' block must ", 2067 "have type Region: ", locType)); 2068 } 2069 List<TypeCheckerResult> exprs_result = this.recurOnListOfExpr(that.getExprs()); 2070 // Type is type of last expression or void if none. 2071 Option<Type> result_type; 2072 List<Expr> es; 2073 List<TypeCheckerResult> body_void; 2074 if ( exprs_result.isEmpty() ) { 2075 result_type = Option.<Type>some(Types.VOID); 2076 es = Collections.<Expr>emptyList(); 2077 body_void = Collections.<TypeCheckerResult>emptyList(); 2078 } else { 2079 result_type = IterUtil.last(exprs_result).type(); 2080 es = (List<Expr>)TypeCheckerResult.astFromResults(exprs_result); 2081 body_void = allVoidButLast(exprs_result,that.getExprs()); 2082 } 2083 Block new_node = new Block(that.getSpan(), 2084 that.isParenthesized(), 2085 result_type, 2086 (Option<Expr>)TypeCheckerResult.astFromResult(loc_result_), 2087 that.isAtomicBlock(), that.isWithinDo(), 2088 (List<Expr>)TypeCheckerResult.astFromResults(exprs_result)); 2089 return TypeCheckerResult.compose(new_node, 2090 result_type, 2091 subtypeChecker, 2092 TypeCheckerResult.compose(new_node, subtypeChecker, body_void), 2093 loc_result, 2094 region_result, 2095 TypeCheckerResult.compose(new_node, subtypeChecker, exprs_result)); 2100 2096 } 2101 2097 … … 2114 2110 that.isParenthesized(), 2115 2111 some(result_type), 2116 (List< DoFront>)TypeCheckerResult.astFromResults(fronts_result));2112 (List<Block>)TypeCheckerResult.astFromResults(fronts_result)); 2117 2113 2118 2114 return TypeCheckerResult.compose(new_node, result_type, subtypeChecker, fronts_result); … … 2570 2566 Option.<Type>some(Types.VOID), 2571 2567 (List<GeneratorClause>)TypeCheckerResult.astFromResults(gens_result), 2572 ( DoFront)body_result.ast());2568 (Block)body_result.ast()); 2573 2569 2574 2570 TypeCheckerResult result = TypeCheckerResult.compose(for_, subtypeChecker, body_void, body_result, -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/Evaluator.java
r3135 r3137 88 88 import com.sun.fortress.nodes.CharLiteralExpr; 89 89 import com.sun.fortress.nodes.Do; 90 import com.sun.fortress.nodes.DoFront;91 90 import com.sun.fortress.nodes.Exit; 92 91 import com.sun.fortress.nodes.ExponentiationMI; … … 363 362 if (s == 0) return FVoid.V; 364 363 if (s == 1) { 365 DoFrontf = x.getFronts().get(0);364 Block f = x.getFronts().get(0); 366 365 if (f.getLoc().isSome()) { 367 366 Expr regionExp = f.getLoc().unwrap(); … … 370 369 if (f.isAtomicBlock()) 371 370 return forAtomicExpr(new AtomicExpr(x.getSpan(), false, 372 f .getExpr()));373 return f. getExpr().accept(new Evaluator(this));371 f)); 372 return f.accept(new Evaluator(this)); 374 373 } 375 374 … … 377 376 List<Expr> locs = new ArrayList<Expr>(0); 378 377 for (int i = 0; i < s; i++) { 379 DoFrontf = x.getFronts().get(i);378 Block f = x.getFronts().get(i); 380 379 if (f.getLoc().isSome()) { 381 380 locs.add(f.getLoc().unwrap()); … … 383 382 if (f.isAtomicBlock()) 384 383 tasks[i] = new TupleTask(new AtomicExpr(x.getSpan(), false, 385 f .getExpr()), this);384 f), this); 386 385 else 387 tasks[i] = new TupleTask(f .getExpr(), new Evaluator(this));386 tasks[i] = new TupleTask(f, new Evaluator(this)); 388 387 } 389 388 if (locs.size()>0) { -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/rewrite/DesugarerVisitor.java
r3123 r3137 60 60 import com.sun.fortress.nodes.Decl; 61 61 import com.sun.fortress.nodes.Do; 62 import com.sun.fortress.nodes.DoFront;63 62 import com.sun.fortress.nodes.EnsuresClause; 64 63 import com.sun.fortress.nodes.Expr; … … 1092 1091 @Override 1093 1092 public Node forFor(For f) { 1094 DoFrontdf = f.getBody();1093 Block df = f.getBody(); 1095 1094 Do doBlock = new Do(df.getSpan(),Useful.list(df)); 1096 1095 return visitLoop(f.getSpan(), f.getGens(), doBlock); -
trunk/ProjectFortress/src/com/sun/fortress/nodes_util/ExprFactory.java
r3132 r3137 577 577 // Might not work; empty Do may be naughty. 578 578 return new While(sp, makeGeneratorClause(cond.getSpan(), cond), 579 new Do(sp, Collections.< DoFront>emptyList()));579 new Do(sp, Collections.<Block>emptyList())); 580 580 } 581 581 … … 592 592 public static Do makeDo(Span sp, Option<Type> t, Expr e) { 593 593 List<Expr> b = Collections.singletonList(e); 594 List< DoFront> body = new ArrayList<DoFront>(1);595 body.add(new DoFront(sp, new Block(sp, t, b)));594 List<Block> body = new ArrayList<Block>(1); 595 body.add(new Block(sp, t, false, true, b)); 596 596 return new Do(sp, t, body); 597 597 } 598 598 599 599 public static Do makeDo(Span sp, Option<Type> t, List<Expr> exprs) { 600 List< DoFront> body = new ArrayList<DoFront>(1);601 body.add(new DoFront(sp, new Block(sp, t, exprs)));600 List<Block> body = new ArrayList<Block>(1); 601 body.add(new Block(sp, t, false, true, exprs)); 602 602 return new Do(sp, t, body); 603 603 } -
trunk/ProjectFortress/src/com/sun/fortress/parser/DelimitedExpr.rats
r3132 r3137 168 168 169 169 /* DoFront ::= (at w Expr w)? (atomic w)? do (w BlockElems)? */ 170 private DoFrontDoFront =170 private Block DoFront = 171 171 a1:(at w Expr w)? a2:(atomic w)? do a3:(w BlockElems)? 172 172 { Span span = createSpan(yyStart,yyCount); 173 173 Option<Expr> at = Option.wrap(a1); 174 174 boolean atomic = (a2 == null) ? false : true; 175 if (a3 == null) a3 = FortressUtil.doBlock(span); 176 yyValue = new DoFront(span, at, atomic, a3); 175 List<Expr> es; 176 if (a3 == null) es = Collections.<Expr>emptyList(); 177 else es = a3.getExprs(); 178 yyValue = new Block(span, false, Option.<Type>none(), at, atomic, true, es); 177 179 }; 178 180 -
trunk/ProjectFortress/src/com/sun/fortress/syntax_abstractions/phases/Transform.java
r3123 r3137 176 176 } 177 177 }); 178 DoFront body_result = (DoFront) recur(that.getBody());178 Block body_result = (Block) recur(that.getBody()); 179 179 setSyntaxEnvironment(save); 180 180 return forForOnly(that, exprType_result, gens_result, body_result); -
trunk/ProjectFortress/src/com/sun/fortress/tools/FortressAstToConcrete.java
r3133 r3137 1125 1125 1126 1126 @Override public String forBlockOnly(Block that, Option<String> exprType_result, 1127 Option<String> loc_result, 1127 1128 List<String> exprs_result) { 1128 1129 StringBuilder s = new StringBuilder(); 1130 1131 increaseIndent(); 1132 if ( loc_result.isSome() ) { 1133 s.append( "at " ).append( loc_result.unwrap() ).append( " " ); 1134 } 1135 if ( that.isAtomicBlock() ) { 1136 s.append( "atomic " ); 1137 } 1138 if ( that.isWithinDo() ) { 1139 s.append( "do\n" ); 1140 } 1129 1141 s.append( join( exprs_result, "\n" ) ); 1142 decreaseIndent(); 1143 1130 1144 return handleParen( s.toString(), 1131 1145 that.isParenthesized() ); … … 2814 2828 } 2815 2829 2816 @Override public String forDoFrontOnly(DoFront that,2817 Option<String> loc_result,2818 String expr_result) {2819 StringBuilder s = new StringBuilder();2820 increaseIndent();2821 2822 if ( loc_result.isSome() ) {2823 s.append( "at " ).append( loc_result.unwrap() ).append( " " );2824 }2825 if ( that.isAtomicBlock() ) {2826 s.append( "atomic " );2827 }2828 s.append( "do\n" ).append( indent(expr_result) );2829 2830 decreaseIndent();2831 2832 return s.toString();2833 }2834 2835 2830 @Override public String forIfClauseOnly(IfClause that, 2836 2831 String test_result, -
trunk/ProjectFortress/static_tests/static_arg_inference/opr_arg_1/Expected.fsg
r2906 r3137 11 11 callSiteFn(): FortressLibrary.String = 12 12 do 13 a: Blank[\FortressLibrary.String\] = Blank[\FortressLibrary.String\]("Some string")14 a + a13 a: Blank[\FortressLibrary.String\] = Blank[\FortressLibrary.String\]("Some string") 14 a + a 15 15 end 16 16 -
trunk/ProjectFortress/static_tests/static_arg_inference/simple_arg_1/Expected.fsg
r2906 r3137 11 11 callSiteFn(): FortressLibrary.String = 12 12 do 13 a: Blank[\FortressLibrary.String\] = Blank[\FortressLibrary.String\]("Some string")14 topLevelFn[\FortressLibrary.String\](a)13 a: Blank[\FortressLibrary.String\] = Blank[\FortressLibrary.String\]("Some string") 14 topLevelFn[\FortressLibrary.String\](a) 15 15 end 16 16

