Changeset 2228
- Timestamp:
- 07/10/08 11:01:26 (17 months ago)
- Location:
- trunk
- Files:
-
- 10 modified
-
. (modified) (1 prop)
-
ProjectFortress/src/com/sun/fortress/interpreter/Driver.java (modified) (7 diffs)
-
ProjectFortress/src/com/sun/fortress/interpreter/env/ComponentWrapper.java (modified) (1 diff)
-
ProjectFortress/src/com/sun/fortress/interpreter/evaluator/BaseEnv.java (modified) (2 diffs)
-
ProjectFortress/src/com/sun/fortress/interpreter/evaluator/Environment.java (modified) (3 diffs)
-
ProjectFortress/src/com/sun/fortress/interpreter/evaluator/EvalType.java (modified) (3 diffs)
-
ProjectFortress/src/com/sun/fortress/interpreter/rewrite/Desugarer.java (modified) (20 diffs)
-
ProjectFortress/src/com/sun/fortress/nodes_util/NodeFactory.java (modified) (3 diffs)
-
ProjectFortress/src/com/sun/fortress/nodes_util/NodeUtil.java (modified) (1 diff)
-
ProjectFortress/src/com/sun/fortress/useful/BATreeNode.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:ignore
-
old new 7 7 testFile.txt 8 8 papers 9 tmp
-
- Property svn:ignore
-
trunk/ProjectFortress/src/com/sun/fortress/interpreter/Driver.java
r2227 r2228 49 49 import com.sun.fortress.interpreter.evaluator.types.FType; 50 50 import com.sun.fortress.interpreter.evaluator.values.Closure; 51 import com.sun.fortress.interpreter.evaluator.values.FGenericFunction; 51 52 import com.sun.fortress.interpreter.evaluator.values.FString; 52 53 import com.sun.fortress.interpreter.evaluator.values.FValue; 54 import com.sun.fortress.interpreter.evaluator.values.OverloadedFunction; 53 55 import com.sun.fortress.nodes.APIName; 54 56 import com.sun.fortress.nodes.AbsDecl; … … 302 304 } 303 305 304 importers = null;306 305 307 306 308 for (ComponentWrapper cw : components) { … … 313 315 cw.initFuncs(); 314 316 } 317 315 318 for (ComponentWrapper cw : components) { 316 319 finishAllFunctionalMethods(cw.getEnvironment()); 317 320 } 318 321 322 /* 323 * Special case -- finish (perhaps redundantly) any overloads that result 324 * only from imports (with no function definition in the importing 325 * component). Lack of a function definition means that BuildEnvironments 326 * does not do the finish step. See bug #147. 327 */ 328 for (Importer imp : importers) { 329 imp.finishOverloads(); 330 } 331 332 importers = null; 333 319 334 for (ComponentWrapper cw : components) { 335 cw.reset(); 336 } 337 338 for (ComponentWrapper cw : components) { 320 339 cw.initVars(); 321 340 } … … 576 595 static abstract class Importer { 577 596 abstract boolean runImports(); 597 abstract public void finishOverloads(); 578 598 abstract void reportErrors(); 579 599 } … … 611 631 612 632 collectImportedValueAndTypeNames(fromApi, vnames, tnames); 613 633 634 Set<String> actually_used = importer.desugarer.topLevelUses; 635 636 // HACK, types referenced from native code, I think. 637 actually_used.add("Any"); 638 actually_used.add("__immutableFactory1"); 639 640 // vnames.retainAll(actually_used); 641 // tnames.retainAll(actually_used); 642 643 614 644 final Importer imp = new Importer() { 615 645 public String toString() { … … 620 650 621 651 final Set<String> added = new HashSet<String>(); 652 final Set<String> overloaded = new HashSet<String>(); 653 final public void finishOverloads() { 654 for (String s: overloaded) { 655 OverloadedFunction fv = (OverloadedFunction) into_e.getValue(s); 656 fv.finishInitializing(); 657 } 658 } 622 659 @Override 623 660 synchronized void reportErrors() { … … 714 751 } 715 752 if (do_import) { 716 into_e.putValue(s, NI.cnnf(from_e.getValueRaw(s))); 753 FValue fv = NI.cnnf(from_e.getValueRaw(s)); 754 into_e.putValue(s, fv); 755 FValue fv2 = into_e.getValueRaw(s); 756 if ( 757 fv2 instanceof OverloadedFunction) { 758 // hack, leave this empty temporarily. 759 // overloaded.add(s); 760 } 717 761 added.add(s); 718 762 } else { -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/env/ComponentWrapper.java
r2181 r2228 54 54 private final static int UNVISITED=0, IMPORTED=1, POPULATED=2, TYPED=3, FUNCTIONED=4, FINISHED=5; 55 55 56 public void reset() { 57 ownNonFunctionNames = null; 58 ownNames = null; 59 ownTypeNames = null; 60 excludedImportNames = null; 61 importedNames = null; 62 HashMap<String, ComponentWrapper> exports = this.exports; 63 this.exports = null; 64 if (exports != null) 65 for (ComponentWrapper cw : exports.values()) { 66 cw.reset(); 67 } 68 } 69 56 70 Visitor2<String, Object> nameCollector = new Visitor2<String, Object>() { 57 71 -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/BaseEnv.java
r2190 r2228 39 39 import com.sun.fortress.nodes.APIName; 40 40 import com.sun.fortress.nodes.Id; 41 import com.sun.fortress.nodes.NamedType; 41 42 import com.sun.fortress.nodes.OpName; 42 43 import com.sun.fortress.nodes.OpRef; … … 313 314 } 314 315 316 final public FType getType(NamedType q) { 317 FType x = getTypeNull(q.getName()); 318 if (x == null) 319 { 320 // System.err.println(this.toString()); 321 return error(errorMsg("Missing type ", q)); 322 } 323 else 324 return x; 325 } 326 315 327 final public FType getType(Id q) { 316 328 FType x = getTypeNull(q); -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/Environment.java
r2190 r2228 26 26 import com.sun.fortress.nodes.APIName; 27 27 import com.sun.fortress.nodes.Id; 28 import com.sun.fortress.nodes.NamedType; 28 29 import com.sun.fortress.nodes.OpRef; 29 30 import com.sun.fortress.nodes.VarRef; … … 80 81 /* Type names take the form ID or Api.ID */ 81 82 public abstract FType getType(Id d); 83 84 public abstract FType getType(NamedType q); 82 85 83 86 public abstract FType getType(String str); … … 182 185 /** 183 186 * Put a value in the top-most scope. 184 * Return true if successful, false if already defined.185 187 * @param str 186 188 * @param f2 -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/EvalType.java
r2196 r2228 371 371 public FType forVarType(VarType i) { 372 372 try { 373 FType result = env.getType(i .getName());373 FType result = env.getType(i); 374 374 return result; 375 375 } catch (FortressException p) { … … 504 504 505 505 public FType forTraitType(TraitType x) { 506 FType ft1 = forId(x.getName()); 506 FType ft1; 507 try { 508 ft1 = env.getType(x); 509 } catch (FortressException p) { 510 throw p.setContext(x,env); 511 } 512 507 513 if (ft1 instanceof FTypeGeneric) { 508 514 FTypeGeneric ftg = (FTypeGeneric) ft1; … … 513 519 // TraitTypes (possibly with zero arguments). EricAllen 11/5/2007 514 520 return ft1; 515 // return error(x, env, errorMsg("Expected generic type, got ", ft1,516 // " instead"));517 521 } 518 522 } -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/rewrite/Desugarer.java
r2190 r2228 162 162 lexicalNestedness = lexicalNestingDepth; 163 163 } 164 164 165 /** May assume {@code original} has a non-zero length. */ 165 166 Expr replacement(VarRef original) { 166 167 return NodeFactory.makeVarRef(original, lexicalNestedness); 167 168 } 169 168 170 Expr replacement(FnRef original) { 169 171 return NodeFactory.makeFnRef(original, lexicalNestedness); … … 171 173 Expr replacement(OpRef original) { 172 174 return NodeFactory.makeOpRef(original, lexicalNestedness); 175 } 176 VarType replacement(VarType original) { 177 return NodeFactory.makeVarType(original, lexicalNestedness); 178 } 179 TraitType replacement(TraitType original) { 180 return NodeFactory.makeTraitType(original, lexicalNestedness); 173 181 } 174 182 public String toString() { return "Thing@"+objectNestedness+"/"+lexicalNestedness; } … … 204 212 if (_transient) isTransient = true; 205 213 } 214 @Override 206 215 Expr replacement(VarRef original) { 207 216 if (isTransient) { … … 238 247 239 248 240 private static class IsAnArrowName extends NodeAbstractVisitor<Boolean> { 249 private static class ArrowOrFunctional {}; 250 private final static ArrowOrFunctional NEITHER = new ArrowOrFunctional(); 251 private final static ArrowOrFunctional ARROW = new ArrowOrFunctional(); 252 private final static ArrowOrFunctional FUNCTIONAL = new ArrowOrFunctional(); 253 254 private static class IsAnArrowName extends NodeAbstractVisitor<ArrowOrFunctional> { 241 255 242 256 /* (non-Javadoc) … … 244 258 */ 245 259 @Override 246 public BooleanforLValueBind(LValueBind that) {260 public ArrowOrFunctional forLValueBind(LValueBind that) { 247 261 return optionTypeIsArrow(that.getType()); 248 262 } … … 270 284 */ 271 285 @Override 272 public BooleanforAbsFnDecl(AbsFnDecl that) {286 public ArrowOrFunctional forAbsFnDecl(AbsFnDecl that) { 273 287 // Return "is a self method" 274 return NodeUtil.selfParameterIndex(that) >= 0 ;288 return NodeUtil.selfParameterIndex(that) >= 0 ? FUNCTIONAL : NEITHER; 275 289 } 276 290 … … 279 293 */ 280 294 @Override 281 public BooleanforFnDef(FnDef that) {295 public ArrowOrFunctional forFnDef(FnDef that) { 282 296 // Return "is a self method" 283 return NodeUtil.selfParameterIndex(that) >= 0 ;297 return NodeUtil.selfParameterIndex(that) >= 0 ? FUNCTIONAL : NEITHER; 284 298 } 285 299 … … 288 302 */ 289 303 @Override 290 public BooleanforTestDecl(TestDecl that) {304 public ArrowOrFunctional forTestDecl(TestDecl that) { 291 305 // FALSE 292 return Boolean.FALSE;306 return NEITHER; 293 307 } 294 308 … … 299 313 */ 300 314 @Override 301 public BooleanforNormalParam(NormalParam that) {315 public ArrowOrFunctional forNormalParam(NormalParam that) { 302 316 return optionTypeIsArrow(that.getType()); 303 317 } … … 307 321 */ 308 322 @Override 309 public BooleanforVarargsParam(VarargsParam that) {310 return Boolean.FALSE;311 } 312 313 private BooleanoptionTypeIsArrow(Option<Type> ot) {314 return ot.unwrap(null) instanceof ArrowType ;323 public ArrowOrFunctional forVarargsParam(VarargsParam that) { 324 return NEITHER; 325 } 326 327 private ArrowOrFunctional optionTypeIsArrow(Option<Type> ot) { 328 return ot.unwrap(null) instanceof ArrowType ? ARROW : NEITHER; 315 329 } 316 330 … … 342 356 private BATree<String, StaticParam> visibleGenericParameters; 343 357 private BATree<String, StaticParam> usedGenericParameters; 344 358 public BASet<String> topLevelUses; 359 public BASet<String> functionals; 360 361 protected void noteUse(Thing t, String s) { 362 if (t.lexicalNestedness == 0 || functionals.contains(s)) 363 topLevelUses.add(s); 364 } 345 365 /** 346 366 * All the object exprs (this may generalize to nested functions as well) … … 353 373 Desugarer(BATree<String, Thing> initial, 354 374 BATree<String, StaticParam> initialGenericScope, 355 BASet<String> initialArrows) { 375 BASet<String> initialArrows, 376 BASet<String> initialTopLevelUses, 377 BASet<String> initialFunctionals) { 356 378 rewrites = initial; 357 379 arrows = initialArrows; 358 380 visibleGenericParameters = initialGenericScope; 359 381 usedGenericParameters = new BATree<String, StaticParam>(StringComparer.V); 382 topLevelUses = initialTopLevelUses; 383 functionals = initialFunctionals; 360 384 // packages = new BASet<String>(StringComparer.V); 361 385 } … … 364 388 this(new BATree<String, Thing>(StringComparer.V), 365 389 new BATree<String, StaticParam>(StringComparer.V), 366 new BASet<String>(StringComparer.V)); 390 new BASet<String>(StringComparer.V), 391 new BASet<String>(StringComparer.V), 392 new BASet<String>(StringComparer.V) 393 ); 367 394 this.isLibrary = isLibrary; 368 395 } … … 449 476 return vre; 450 477 } else { 478 noteUse(t,s); 451 479 return t.replacement(vre); 452 480 } … … 459 487 return vre; 460 488 } else { 489 noteUse(t,s); 461 490 return t.replacement(vre); 462 491 } 463 492 464 493 } 494 495 NamedType newType(VarType nt, String s) { 496 497 Thing t = rewrites.get(s); 498 if (t == null) { 499 return nt; 500 } else { 501 noteUse(t,s); 502 return t.replacement(nt); 503 } 504 } 505 506 NamedType newType(TraitType nt, String s) { 507 508 Thing t = rewrites.get(s); 509 if (t == null) { 510 return nt; 511 } else { 512 noteUse(t,s); 513 return t.replacement(nt); 514 } 515 } 465 516 466 517 // Iterable<Id> newName(Iterable<Id> ids, String s) { … … 647 698 } else if (node instanceof OpExpr) { 648 699 node = cleanupOpExpr((OpExpr)node); 700 649 701 } else if (node instanceof _RewriteFnRef) { 650 702 651 703 _RewriteFnRef fr = (_RewriteFnRef) node; 704 705 } else if (node instanceof VarType) { 706 VarType vre = (VarType) node; 707 String s = NodeUtil.nameString(vre.getName()); 708 StaticParam tp = visibleGenericParameters.get(s); 709 if (tp != null) { 710 usedGenericParameters.put(s, tp); 711 } 712 node = newType(vre, s); 713 714 } else if (node instanceof TraitType) { 715 TraitType vre = (TraitType) node; 716 String s = NodeUtil.nameString(vre.getName()); 717 node = newType(vre, s); 652 718 653 719 } else if (node instanceof TightJuxt&& looksLikeMethodInvocation((Juxt) node)) { … … 673 739 return NodeFactory.makeLValue(lvb, newId); 674 740 } 675 } else if (node instanceof VarType) {676 VarType vre = (VarType) node;677 String s = NodeUtil.nameString(vre.getName());678 StaticParam tp = visibleGenericParameters.get(s);679 if (tp != null) {680 usedGenericParameters.put(s, tp);681 }682 683 741 } else if (node instanceof FieldRef) { 684 742 atTopLevelInsideTraitOrObject = false; … … 902 960 } else if (node instanceof Accumulator) { 903 961 Accumulator ac = (Accumulator)node; 904 returnvisitAccumulator(ac.getSpan(), ac.getGens(),962 node = visitAccumulator(ac.getSpan(), ac.getGens(), 905 963 ac.getOpr(), ac.getBody(), 906 964 ac.getStaticArgs()); 965 return node; 907 966 } else if (node instanceof Spawn) { 908 967 return translateSpawn((Spawn)node); … … 1458 1517 String s = d.getName().getText(); 1459 1518 rewrites_put(s, new Member(NodeUtil.isTransient(d))); 1460 if (d.accept(isAnArrowName)) 1519 ArrowOrFunctional aof = d.accept(isAnArrowName); 1520 if (aof != NEITHER) { 1461 1521 arrows.add(s); 1462 else 1522 if (aof == FUNCTIONAL) 1523 functionals.add(s); 1524 } else 1463 1525 arrows.remove(s); 1464 1526 } … … 1542 1604 String sdd = dd.stringName(); 1543 1605 if (dd instanceof VarDecl) { 1544 visited.add(tdod);1606 //visited.add(tdod); 1545 1607 } else if (dd instanceof AbsVarDecl) { 1546 visited.add(tdod);1608 //visited.add(tdod); 1547 1609 } else { 1548 if (dd.accept(isAnArrowName)) { 1610 ArrowOrFunctional aof = dd.accept(isAnArrowName); 1611 1612 if (aof != NEITHER) { 1549 1613 arrow_names.add(sdd); 1614 if (aof == FUNCTIONAL) 1615 functionals.add(sdd); 1550 1616 } else { 1551 1617 not_arrow_names.add(sdd); -
trunk/ProjectFortress/src/com/sun/fortress/nodes_util/NodeFactory.java
r2214 r2228 1157 1157 } 1158 1158 1159 1159 1160 public static Expr makeFnRef(Span span, Id name, 1160 1161 List<StaticArg> staticArgs) { … … 1202 1203 } 1203 1204 1205 public static VarType makeVarType(VarType original, int lexicalNestedness) { 1206 return new VarType(original.getSpan(), original.isParenthesized(), original.getName(), lexicalNestedness); 1207 } 1208 1209 public static TraitType makeTraitType(TraitType original, int lexicalNestedness) { 1210 return new TraitType(original.getSpan(), original.isParenthesized(), original.getName(), lexicalNestedness, original.getArgs()); 1211 1212 } 1213 1204 1214 public static Import makeImportStar(String apiName) { 1205 1215 return NodeFactory.makeImportStar(NodeFactory.makeAPIName(apiName), new LinkedList<IdOrOpOrAnonymousName>()); … … 1216 1226 } 1217 1227 1228 1229 1230 1231 1218 1232 } -
trunk/ProjectFortress/src/com/sun/fortress/nodes_util/NodeUtil.java
r2183 r2228 143 143 144 144 public static String nameString(APIName n) { 145 Iterable<String> ns = IterUtil.map(n.getIds(), IdToStringFn); 146 return IterUtil.toString(ns, "", ".", ""); 145 return n.getText(); 146 // Iterable<String> ns = IterUtil.map(n.getIds(), IdToStringFn); 147 // return IterUtil.toString(ns, "", ".", ""); 147 148 } 148 149 -
trunk/ProjectFortress/src/com/sun/fortress/useful/BATreeNode.java
r1800 r2228 26 26 27 27 public String toString() { 28 return toStringBuffer(new StringBuffer()).toString();28 return recursiveToStringLines(); 29 29 } 30 30

