Changeset 3138
- Timestamp:
- 12/02/08 17:29:50 (12 months ago)
- Location:
- trunk/ProjectFortress
- Files:
-
- 12 modified
-
astgen/Fortress.ast (modified) (3 diffs)
-
src/com/sun/fortress/compiler/desugarer/FreeNameCollector.java (modified) (2 diffs)
-
src/com/sun/fortress/compiler/desugarer/ObjectExpressionVisitor.java (modified) (1 diff)
-
src/com/sun/fortress/compiler/disambiguator/ExprDisambiguator.java (modified) (2 diffs)
-
src/com/sun/fortress/compiler/typechecker/TypeChecker.java (modified) (3 diffs)
-
src/com/sun/fortress/compiler/typechecker/TypeCheckerOutput.java (modified) (2 diffs)
-
src/com/sun/fortress/interpreter/rewrite/DesugarerVisitor.java (modified) (2 diffs)
-
src/com/sun/fortress/nodes_util/ExprFactory.java (modified) (1 diff)
-
src/com/sun/fortress/nodes_util/NodeUtil.java (modified) (1 diff)
-
src/com/sun/fortress/parser/LocalDecl.rats (modified) (1 diff)
-
src/com/sun/fortress/syntax_abstractions/phases/Transform.java (modified) (1 diff)
-
src/com/sun/fortress/tools/FortressAstToConcrete.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ProjectFortress/astgen/Fortress.ast
r3137 r3138 723 723 Option<Block> elseClause = Option.<Block>none()); 724 724 /** 725 * for expression726 * DelimitedExpr ::= for GeneratorClauseList DoFront end727 * e.g.) for i <- sequential(1:5) do728 * print (i " ")729 * end730 */731 For(List<GeneratorClause> gens, Block body);732 /**733 725 * if expression 734 726 * DelimitedExpr ::= if CondExpr then BlockElems Elifs? Else? end … … 834 826 */ 835 827 While(GeneratorClause testExpr, Do body); 828 /** 829 * for expression 830 * DelimitedExpr ::= for GeneratorClauseList DoFront end 831 * e.g.) for i <- sequential(1:5) do 832 * print (i " ") 833 * end 834 * 835 * generated expression 836 * BlockElem ::= Expr(, GeneratorClauseList)? 837 * e.g.) print (i " "), i <- sequential(1:5) 838 */ 839 For(List<GeneratorClause> gens, Block body); 836 840 /** 837 841 * comprehension or accumulator … … 940 944 LocalVarDecl(List<LValue> lhs, 941 945 Option<Expr> rhs = Option.<Expr>none()); 942 /**943 * generated expression944 * BlockElem ::= Expr(, GeneratorClauseList)?945 * e.g.) print (i " "), i <- sequential(1:5)946 */947 GeneratedExpr(Expr expr, List<GeneratorClause> gens);948 946 /** 949 947 * expression that is simple or using operators -
trunk/ProjectFortress/src/com/sun/fortress/compiler/desugarer/FreeNameCollector.java
r3132 r3138 45 45 // A stack keeping track of all nodes that can create new scope 46 46 // TraitDecl, ObjectDecl, FnDecl, FnExpr, IfClause, For, LetFn, LocalVarDecl, 47 // Label, Catch, Typecase, GeneratedExpr,While, and ObjectExpr47 // Label, Catch, Typecase, While, and ObjectExpr 48 48 private Stack<Node> scopeStack; 49 49 // A stack keeping track of (potentially nested) object exprs … … 212 212 213 213 @Override 214 public void forGeneratedExpr(GeneratedExpr that) {215 scopeStack.push(that);216 super.forGeneratedExpr(that);217 scopeStack.pop();218 }219 220 @Override221 214 public void forWhile(While that) { 222 215 scopeStack.push(that); -
trunk/ProjectFortress/src/com/sun/fortress/compiler/desugarer/ObjectExpressionVisitor.java
r3123 r3138 355 355 scopeStack.push(that); 356 356 Node returnValue = super.forTypecase(that); 357 scopeStack.pop();358 return returnValue;359 }360 361 @Override362 public Node forGeneratedExpr(GeneratedExpr that) {363 scopeStack.push(that);364 Node returnValue = super.forGeneratedExpr(that);365 357 scopeStack.pop(); 366 358 return returnValue; -
trunk/ProjectFortress/src/com/sun/fortress/compiler/disambiguator/ExprDisambiguator.java
r3137 r3138 48 48 import com.sun.fortress.nodes.FnRef; 49 49 import com.sun.fortress.nodes.For; 50 import com.sun.fortress.nodes.GeneratedExpr;51 50 import com.sun.fortress.nodes.GeneratorClause; 52 51 import com.sun.fortress.nodes.GrammarDef; … … 831 830 832 831 @Override 833 public Node forGeneratedExpr(GeneratedExpr that) {834 Pair<List<GeneratorClause>,Set<Id>> pair = bindInListGenClauses(this, that.getGens());835 ExprDisambiguator extended_d = this.extendWithVars(pair.second());836 Option<Type> type_result = recurOnOptionOfType(that.getExprType());837 return forGeneratedExprOnly(that, type_result,838 (Expr)that.getExpr().accept(extended_d),839 pair.first());840 }841 842 843 @Override844 832 public Node forAccumulator(Accumulator that) { 845 833 // Accumulator can bind variables -
trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeChecker.java
r3137 r3138 2285 2285 returnType = wrap(bodyType); 2286 2286 } 2287 2287 2288 2288 // System.err.println("Location: " + that.getSpan()); 2289 2289 // System.err.println("body type: " + bodyType.getClass() + ":" + bodyType); 2290 // if (bodyType instanceof TraitType) { 2290 // if (bodyType instanceof TraitType) { 2291 2291 // System.err.println("name: " + ((TraitType)bodyType).getName()); 2292 2292 // System.err.println("args:" + ((TraitType)bodyType).getArgs()); 2293 2293 // } 2294 2294 // System.err.println("return type: " + returnType.unwrap().getClass() + ":" + returnType.unwrap()); 2295 // if (returnType.unwrap() instanceof TraitType) { 2295 // if (returnType.unwrap() instanceof TraitType) { 2296 2296 // System.err.println("name: " + ((TraitType)returnType.unwrap()).getName()); 2297 2297 // System.err.println("args:" + ((TraitType)returnType.unwrap()).getArgs()); … … 2574 2574 } 2575 2575 2576 @Override2577 public TypeCheckerResult forGeneratedExpr(GeneratedExpr that) {2578 Pair<List<TypeCheckerResult>,List<LValue>> pair = recurOnListsOfGeneratorClauseBindings(that.getGens());2579 TypeChecker extend = this.extend(pair.second());2580 TypeCheckerResult body_result = that.getExpr().accept(extend);2581 List<TypeCheckerResult> res = pair.first();2582 2583 // make sure body type-checked2584 if( !body_result.isSuccessful() )2585 return TypeCheckerResult.compose(that, subtypeChecker, body_result);2586 2587 //make sure body has type void?2588 String err = "Body of generated expression must have type VOID but had type " + body_result.type().unwrap();2589 TypeCheckerResult void_body = checkSubtype(body_result.type().unwrap(), Types.VOID, that.getExpr(), err);2590 2591 GeneratedExpr new_node = new GeneratedExpr(that.getSpan(),2592 that.isParenthesized(),2593 Option.<Type>some(Types.VOID),2594 (Expr)body_result.ast(),2595 (List<GeneratorClause>)TypeCheckerResult.astFromResults(res));2596 2597 TypeCheckerResult result = TypeCheckerResult.compose(new_node, subtypeChecker, body_result, void_body,2598 TypeCheckerResult.compose(new_node, subtypeChecker, res)).addNodeTypeEnvEntry(new_node, typeEnv);2599 return TypeCheckerResult.compose(new_node, Types.VOID, subtypeChecker, result);2600 }2601 2602 2576 private Pair<TypeCheckerResult, List<LValue>> forGeneratorClauseGetBindings(GeneratorClause that, 2603 2577 boolean mustBeCondition) { … … 2633 2607 (Expr)init_result.ast()); 2634 2608 2635 2609 2636 2610 // If bindings are empty, then init_result must be of type boolean, a filter, 13.14 2637 2611 TypeCheckerResult bool_result; 2638 2612 2639 if (init_result.type().isNone()) { 2613 if (init_result.type().isNone()) { 2640 2614 String err = "Filter expressions in generator clauses must have type boolean, but " + 2641 2615 that.getInit() + " was not well typed."; 2642 2616 bool_result = new TypeCheckerResult(that.getInit(), TypeError.make(err, that.getInit())); 2643 } else { 2617 } else { 2644 2618 bool_result = 2645 2619 this.checkSubtype(init_result.type().unwrap(), Types.BOOLEAN, that.getInit(), -
trunk/ProjectFortress/src/com/sun/fortress/compiler/typechecker/TypeCheckerOutput.java
r3102 r3138 34 34 import com.sun.fortress.nodes.FnExpr; 35 35 import com.sun.fortress.nodes.For; 36 import com.sun.fortress.nodes.GeneratedExpr;37 36 import com.sun.fortress.nodes.IfClause; 38 37 import com.sun.fortress.nodes.Label; … … 130 129 131 130 @Override 132 public void forGeneratedExpr(GeneratedExpr that) {133 // TODO Auto-generated method stub134 removed.remove(Pair.make(that,that.getSpan()));135 super.forGeneratedExpr(that);136 }137 138 @Override139 131 public void forIfClause(IfClause that) { 140 132 // TODO Auto-generated method stub -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/rewrite/DesugarerVisitor.java
r3137 r3138 68 68 import com.sun.fortress.nodes.FnExpr; 69 69 import com.sun.fortress.nodes.For; 70 import com.sun.fortress.nodes.GeneratedExpr;71 70 import com.sun.fortress.nodes.GeneratorClause; 72 71 import com.sun.fortress.nodes.GrammarDef; … … 1097 1096 1098 1097 @Override 1099 public Node forGeneratedExpr(GeneratedExpr ge) {1100 return visitLoop(ge.getSpan(), ge.getGens(), ge.getExpr());1101 }1102 1103 @Override1104 1098 public Node forSpawn(Spawn s) { 1105 1099 Expr body = s.getBody(); -
trunk/ProjectFortress/src/com/sun/fortress/nodes_util/ExprFactory.java
r3137 r3138 798 798 e.getReturnType(), e.getWhereClause(), 799 799 e.getThrowsClause(), e.getBody()); 800 }801 public Expr forGeneratedExpr(GeneratedExpr e) {802 return new GeneratedExpr(e.getSpan(), true,803 e.getExpr(), e.getGens());804 800 } 805 801 public Expr forLetFn(LetFn e) { -
trunk/ProjectFortress/src/com/sun/fortress/nodes_util/NodeUtil.java
r3133 r3138 458 458 public IterableOnce<String> forFnDecl(FnDecl d) { 459 459 return new UnitIterable<String>(nameString(d.getName())); 460 }461 public IterableOnce<String> forGeneratedExpr(GeneratedExpr d) {462 return new UnitIterable<String>("GeneratedExpr");463 460 } 464 461 public IterableOnce<String> forLetFn(LetFn d) { -
trunk/ProjectFortress/src/com/sun/fortress/parser/LocalDecl.rats
r3082 r3138 65 65 / a1:NoNewlineExpr a2:(s comma w NoNewlineGeneratorClauseList)? 66 66 { if (a2 == null) yyValue = a1; 67 else yyValue = new GeneratedExpr(createSpan(yyStart,yyCount), false,68 a1, a2);67 else yyValue = new For(createSpan(yyStart,yyCount), false, 68 a2, ExprFactory.makeBlock(a1)); 69 69 }; 70 70 -
trunk/ProjectFortress/src/com/sun/fortress/syntax_abstractions/phases/Transform.java
r3137 r3138 137 137 * While - done 138 138 * Accumulator - 139 * GeneratedExpr140 139 * ArrayComprehensionClause 141 140 * IfClause - done -
trunk/ProjectFortress/src/com/sun/fortress/tools/FortressAstToConcrete.java
r3137 r3138 1577 1577 } 1578 1578 1579 @Override public String forGeneratedExprOnly(GeneratedExpr that, Option<String> exprType_result,1580 String expr_result,1581 List<String> gens_result) {1582 StringBuilder s = new StringBuilder();1583 1584 s.append( expr_result );1585 if ( ! gens_result.isEmpty() ) {1586 s.append( ", " );1587 s.append( join(gens_result, ", ") );1588 }1589 1590 return handleParen( s.toString(),1591 that.isParenthesized() );1592 }1593 1594 1579 @Override public String forSubscriptExprOnly(SubscriptExpr that, Option<String> exprType_result, 1595 1580 String obj_result,

