Changeset 2162
- Timestamp:
- 07/01/08 11:49:25 (2 months ago)
- Files:
-
- trunk/ProjectFortress/src/com/sun/fortress/interpreter/env/WorseEnv.java (modified) (2 diffs)
- trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/BaseEnv.java (modified) (2 diffs)
- trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/BuildEnvironments.java (modified) (1 diff)
- trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/BuildNativeEnvironment.java (modified) (1 diff)
- trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/Environment.java (modified) (2 diffs)
- trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/Evaluator.java (modified) (3 diffs)
- trunk/ProjectFortress/src/com/sun/fortress/interpreter/rewrite/Desugarer.java (modified) (15 diffs)
- trunk/ProjectFortress/src/com/sun/fortress/interpreter/rewrite/Rewrite.java (modified) (1 diff)
- trunk/ProjectFortress/src/com/sun/fortress/nodes_util/ExprFactory.java (modified) (1 diff)
- trunk/ProjectFortress/src/com/sun/fortress/useful/StringComparer.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/ProjectFortress/src/com/sun/fortress/interpreter/env/WorseEnv.java
r2048 r2162 31 31 @Override 32 32 public Appendable dump(Appendable a) throws IOException { 33 // TODO Auto-generated method stub 34 return null; 33 throw new Error(); 34 35 35 } 36 36 37 37 public Environment extend() { 38 // TODO Auto-generated method stub 39 return null; 38 throw new Error(); 39 40 40 } 41 41 42 42 public Environment extend(Environment additions) { 43 // TODO Auto-generated method stub 44 return null; 43 throw new Error(); 44 45 45 } 46 46 47 47 public Environment extendAt(HasAt x) { 48 // TODO Auto-generated method stub 49 return null; 48 throw new Error(); 49 50 50 } 51 51 52 52 @Override 53 53 public Boolean getBoolNull(String str) { 54 // TODO Auto-generated method stub 55 return null; 54 throw new Error(); 55 56 56 } 57 57 58 58 public Number getIntNull(String s) { 59 // TODO Auto-generated method stub 60 return null; 59 throw new Error(); 60 61 61 } 62 62 63 63 @Override 64 64 public Number getNatNull(String str) { 65 // TODO Auto-generated method stub 66 return null; 65 throw new Error(); 66 67 67 } 68 68 69 69 @Override 70 70 public FType getTypeNull(String str) { 71 // TODO Auto-generated method stub 72 return null; 71 throw new Error(); 72 73 73 } 74 74 75 75 public FValue getValueRaw(String s) { 76 // TODO Auto-generated method stub 77 return null; 76 throw new Error(); 77 78 78 } 79 79 80 80 public void putBoolRaw(String str, Boolean f2) { 81 // TODO Auto-generated method stub 81 throw new Error(); 82 82 83 83 } 84 84 85 85 public void putIntRaw(String str, Number f2) { 86 // TODO Auto-generated method stub 86 throw new Error(); 87 87 88 88 } 89 89 90 90 public void putNatRaw(String str, Number f2) { 91 // TODO Auto-generated method stub 91 throw new Error(); 92 92 93 93 } 94 94 95 95 public void putTypeRaw(String str, FType f2) { 96 // TODO Auto-generated method stub 96 throw new Error(); 97 97 98 98 } 99 99 100 100 public void putValueRaw(String str, FValue f2) { 101 // TODO Auto-generated method stub 101 throw new Error(); 102 102 103 103 } 104 104 105 105 public void removeType(String s) { 106 // TODO Auto-generated method stub 106 throw new Error(); 107 107 108 108 } 109 109 110 110 public void removeVar(String name) { 111 // TODO Auto-generated method stub 111 throw new Error(); 112 112 113 113 } … … 116 116 Visitor2<String, Number> vi, Visitor2<String, FValue> vv, 117 117 Visitor2<String, Boolean> vb) { 118 // TODO Auto-generated method stub 118 throw new Error(); 119 119 120 120 } 121 121 122 122 public void visit(Visitor2<String, Object> nameCollector) { 123 // TODO Auto-generated method stub 123 throw new Error(); 124 124 125 125 } 126 126 127 127 public Iterable<String> youngestFrame() { 128 // TODO Auto-generated method stub 129 return null; 128 throw new Error(); 130 129 } 131 130 trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/BaseEnv.java
r2070 r2162 39 39 import com.sun.fortress.nodes.VarRef; 40 40 import com.sun.fortress.nodes_util.NodeUtil; 41 import com.sun.fortress.useful.BASet; 41 42 import com.sun.fortress.useful.HasAt; 42 43 import com.sun.fortress.useful.StringArrayIterator; … … 355 356 } 356 357 358 static private BASet<String> missedNames = new BASet<String>(com.sun.fortress.useful.StringComparer.V); 359 357 360 final public FValue getValueNull(VarRef vr) { 358 361 Id name = vr.getVar(); 359 362 String s = NodeUtil.nameString(name); 360 363 int l = vr.getLexicalDepth(); 361 if (l == -1)362 return error(errorMsg("Untagged VarRef ", vr));363 364 FValue v = getValueRaw(s, l); 365 if (l == -1) { 366 // Debugging code, currently fires for $self 367 if (false) 368 return error(errorMsg("Untagged VarRef ", vr)); 369 if (false) 370 missedNames.syncPut(s); 371 } 364 372 return getValueNullTail(s, v); 365 373 } trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/BuildEnvironments.java
r2072 r2162 687 687 // Create a little expression to run the constructor. 688 688 Expr init = ExprFactory.makeTightJuxt(x.getSpan(), 689 ExprFactory.makeVarRef(x.getSpan(), obfuscatedSingletonConstructorName(fname, x) ),689 ExprFactory.makeVarRef(x.getSpan(), obfuscatedSingletonConstructorName(fname, x), 0), 690 690 ExprFactory.makeVoidLiteralExpr(x.getSpan())); 691 691 FValue init_value = new LazilyEvaluatedCell(init, containing); trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/BuildNativeEnvironment.java
r1895 r2162 160 160 // Create a little expression to run the constructor. 161 161 Expr init = ExprFactory.makeTightJuxt(x.getSpan(), ExprFactory 162 .makeVarRef(x.getSpan(), obfuscatedSingletonConstructorName(fname, x) ),162 .makeVarRef(x.getSpan(), obfuscatedSingletonConstructorName(fname, x), 0), 163 163 ExprFactory.makeVoidLiteralExpr(x.getSpan())); 164 164 FValue init_value = new LazilyEvaluatedCell(init, containing); trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/Environment.java
r2062 r2162 24 24 import com.sun.fortress.interpreter.evaluator.values.FValue; 25 25 import com.sun.fortress.nodes.Id; 26 import com.sun.fortress.nodes.VarRef; 26 27 import com.sun.fortress.useful.HasAt; 27 28 import com.sun.fortress.useful.Visitor2; … … 106 107 */ 107 108 public abstract FValue getValueNull(String s); 109 110 /** 111 * Similar to the string version, but able to deal with 112 * depth information on the VarRef. 113 * 114 * @param vr 115 * @return 116 */ 117 public abstract FValue getValueNull(VarRef vr); 108 118 109 119 public abstract FValue getValueRaw(String s); trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/Evaluator.java
r2119 r2162 1611 1611 1612 1612 public FValue forVarRef(VarRef x) { 1613 Iterable<Id> names = NodeUtil.getIds(x.getVar()); 1614 1615 FValue res = e.getValueNull(IterUtil.last(names).getText()); 1616 if (res == null) 1613 FValue res = e.getValueNull(x); 1614 if (res == null) { 1615 Iterable<Id> names = NodeUtil.getIds(x.getVar()); 1617 1616 error(x, e, errorMsg("undefined variable ", names)); 1617 } 1618 1618 return res; 1619 1620 /*1621 if (!ProjectProperties.noStaticAnalysis) {1622 FValue res = e.getValueNull(IterUtil.last(names).getText());1623 if (res == null)1624 error(x, e, errorMsg("undefined variable ", names));1625 return res;1626 1627 } else {1628 1629 FValue res = e.getValueNull(IterUtil.first(names).getText());1630 if (res == null)1631 error(x, e, errorMsg("undefined variable ", IterUtil.first(1632 names).getText()));1633 1634 for (Id fld : IterUtil.skipFirst(names)) {1635 if (res instanceof Selectable) {1636 / *1637 * Selectable was introduced to make it not necessary to1638 * know whether a.b was field b of object a, or member b of1639 * api a (or api name prefix, extended).1640 * /1641 // TODO Need to distinguish between public/private1642 // methods/fields1643 try {1644 res = ((Selectable) res).select(fld.getText());1645 } catch (FortressException ex) {1646 throw ex.setContext(x, e);1647 }1648 } else {1649 res = error(x, e, errorMsg("Non-object cannot have field ",1650 fld.getText()));1651 }1652 }1653 return res;1654 }1655 */1656 1619 } 1657 1620 … … 1701 1664 * @see com.sun.fortress.interpreter.nodes.NodeVisitor#forFnRef(com.sun.fortress.interpreter.nodes.FnRef) 1702 1665 */ 1703 /** Assumes {@code x.getIds()} is a list of length 1. */1704 1666 @Override 1705 1667 public FValue forFnRef(FnRef x) { 1706 Id name = x.get Fns().get(0);1707 FValue g = for VarRef(new VarRef(name.getSpan(), name));1668 Id name = x.getOriginalName(); 1669 FValue g = forIdOfRef(name); 1708 1670 return applyToActualStaticArgs(g,x.getStaticArgs(),x); 1709 1671 } … … 1712 1674 public FValue for_RewriteObjectRef(_RewriteObjectRef that) { 1713 1675 Id name = that.getObj(); 1714 FValue g = for VarRef(new VarRef(name.getSpan(), name));1715 return applyToActualStaticArgs(g,that.getStaticArgs(),that);1676 FValue g = forIdOfRef(name); 1677 return applyToActualStaticArgs(g,that.getStaticArgs(),that); 1716 1678 } 1717 1679 1718 @Override 1680 private FValue forIdOfRef(Id x) { 1681 String s = x.getText(); 1682 FValue res = e.getValueNull(s); 1683 if (res == null) { 1684 error(x, e, errorMsg("undefined variable ", x)); 1685 } 1686 return res; 1687 } 1688 1689 @Override 1719 1690 public FValue for_RewriteFnRef(_RewriteFnRef x) { 1720 1691 Expr name = x.getFn(); trunk/ProjectFortress/src/com/sun/fortress/interpreter/rewrite/Desugarer.java
r2060 r2162 51 51 import com.sun.fortress.nodes_util.NodeUtil; 52 52 import com.sun.fortress.nodes_util.OprUtil; 53 import com.sun.fortress.nodes.Expr; 54 import com.sun.fortress.nodes.ExtentRange; 55 import com.sun.fortress.nodes.LValue; 56 import com.sun.fortress.nodes.LValueBind; 53 57 import com.sun.fortress.nodes.StaticParam; 54 58 import com.sun.fortress.nodes.TightJuxt; … … 56 60 import com.sun.fortress.nodes.BaseType; 57 61 import com.sun.fortress.nodes.Type; 62 import com.sun.fortress.nodes.UnpastingBind; 63 import com.sun.fortress.nodes.UnpastingSplit; 58 64 import com.sun.fortress.nodes.VarDecl; 59 65 import com.sun.fortress.nodes.VarRef; … … 315 321 */ 316 322 private BATree<String, Thing> rewrites; 323 324 public Thing rewrites_put(String k, Thing d) { 325 return rewrites.put(k, d); 326 } 317 327 318 328 /** … … 397 407 /** 398 408 * Adds, to the supplied environment, constructors for any object 399 * expressions encountered the tree(s) processed by this Disambiguator.409 * expressions encountered in the tree(s) processed by this Disambiguator. 400 410 * @param env 401 411 */ … … 497 507 /* Empty means do add */ 498 508 if (old == null) { 499 rewrites .put(putName, th);509 rewrites_put(putName, th); 500 510 return true; 501 511 } … … 699 709 if (atTopLevelInsideTraitOrObject) { 700 710 currentSelfName = fndef.getSelfName(); 701 rewrites .put(currentSelfName, new SelfRewrite(currentSelfName));711 rewrites_put(currentSelfName, new SelfRewrite(currentSelfName)); 702 712 } 703 713 atTopLevelInsideTraitOrObject = false; … … 772 782 } else if (node instanceof LocalVarDecl) { 773 783 atTopLevelInsideTraitOrObject = false; 774 // defined var is no longer eligible for rewrite. 775 //LocalVarDecl lb = (LocalVarDecl) node; 776 //List<LValue> lvals = lb.getLhs(); 784 lexicalNestingDepth++; 785 786 LocalVarDecl lvd = (LocalVarDecl) node; 787 788 List<LValue> lhs = lvd.getLhs(); 789 Option<Expr> rhs = lvd.getRhs(); 790 List<Expr> body = lvd.getBody(); 791 792 lvaluesToLocal(lhs); 793 // not quite right because initializing exprs are evaluated in the wrong context. 794 777 795 // TODO wip 778 796 … … 797 815 List<StaticParam> tparams = od.getStaticParams(); 798 816 List<BaseType> xtends = NodeUtil.getTypes(od.getExtendsClause()); 817 799 818 // TODO wip 800 819 lexicalNestingDepth++; 801 820 objectNestingDepth++; 802 821 atTopLevelInsideTraitOrObject = true; 822 803 823 defsToMembers(defs); 804 824 immediateDef = tparamsToLocals(tparams, immediateDef); … … 1285 1305 private void defsToLocals(List<? extends AbsDeclOrDecl> defs) { 1286 1306 for (AbsDeclOrDecl d : defs) { 1287 String s = d.stringName();1288 1307 if (d instanceof TraitAbsDeclOrDecl) { 1308 String s = d.stringName(); 1289 1309 TraitAbsDeclOrDecl dod = (TraitAbsDeclOrDecl) d; 1290 rewrites.put(s, new Trait(dod, rewrites)); 1310 rewrites_put(s, new Trait(dod, rewrites)); 1311 } else if (d instanceof ObjectDecl) { 1312 ObjectDecl od = (ObjectDecl) d; 1313 Option<List<Param>> params = od.getParams(); 1314 /* 1315 * Add the object itself (either constructor or singleton, 1316 * we don't care much) to the locals. 1317 * 1318 * If it is a constructor, it is also an arrow type. 1319 * 1320 */ 1321 String s = od.getName().getText(); 1322 rewrites_put(s, new Local()); 1323 1324 if (params.isNone()) 1325 arrows.remove(s); 1326 else 1327 arrows.add(s); 1291 1328 } else { 1292 rewrites.put(s, new Local()); 1329 for (String s : NodeUtil.stringNames(d)) { 1330 rewrites_put(s, new Local()); 1331 } 1293 1332 } 1294 1333 } … … 1303 1342 // "self" is not a local. 1304 1343 if (! s.equals(currentSelfName)) { 1305 rewrites .put(s, new Local());1344 rewrites_put(s, new Local()); 1306 1345 1307 1346 } 1308 1347 } 1348 } 1349 1350 1351 private NodeAbstractVisitor_void localVisitor = new NodeAbstractVisitor_void() { 1352 1353 @Override 1354 public void forExtentRange(ExtentRange that) { 1355 // TODO Auto-generated method stub 1356 super.forExtentRange(that); 1357 } 1358 1359 @Override 1360 public void forLValueBind(LValueBind that) { 1361 that.getName().accept(this); 1362 } 1363 1364 @Override 1365 public void forId(Id that) { 1366 String s = that.getText(); 1367 rewrites_put(s, new Local()); 1368 } 1369 1370 @Override 1371 public void forUnpastingBind(UnpastingBind that) { 1372 that.getName().accept(this); 1373 for (ExtentRange er : that.getDim()) 1374 er.accept(this); 1375 } 1376 1377 @Override 1378 public void forUnpastingSplit(UnpastingSplit that) { 1379 for (Unpasting up : that.getElems()) 1380 up.accept(this); 1381 } 1382 1383 }; 1384 1385 /** 1386 * @param params 1387 */ 1388 private void lvaluesToLocal(List<? extends LValue> params) { 1389 for (LValue param : params) 1390 param.accept(localVisitor); 1309 1391 } 1310 1392 … … 1316 1398 for (StaticParam d : params) { 1317 1399 String s = NodeUtil.getName(d); 1318 rewrites .put(s, new Local());1400 rewrites_put(s, new Local()); 1319 1401 visibleGenericParameters.put(s, d); 1320 1402 immediateDef = addToImmediateDef(immediateDef, s); … … 1341 1423 for (AbsDeclOrDecl d : defs) { 1342 1424 for (String s: NodeUtil.stringNames(d)) 1343 rewrites .put(s, new Member());1425 rewrites_put(s, new Member()); 1344 1426 } 1345 1427 … … 1353 1435 for (Param d : params.unwrap()) { 1354 1436 String s = d.getName().getText(); 1355 rewrites .put(s, new Member(NodeUtil.isTransient(d)));1437 rewrites_put(s, new Member(NodeUtil.isTransient(d))); 1356 1438 if (d.accept(isAnArrowName)) 1357 1439 arrows.add(s); … … 1368 1450 private void stringsToMembers(Collection<String> strings) { 1369 1451 for (String s : strings) { 1370 rewrites .put(s, new Member());1452 rewrites_put(s, new Member()); 1371 1453 arrows.remove(s); 1372 1454 } … … 1378 1460 private void stringsToLocals(Collection<String> strings) { 1379 1461 for (String s : strings) { 1380 rewrites .put(s, new Local());1462 rewrites_put(s, new Local()); 1381 1463 arrows.remove(s); 1382 1464 } trunk/ProjectFortress/src/com/sun/fortress/interpreter/rewrite/Rewrite.java
r1895 r2162 195 195 protected <T> Option<T> visitOption(Option<T> opt) { 196 196 if (opt.isSome()) { 197 T updated = visitObject(opt.unwrap()); 198 if (updated != null) { 197 T original = opt.unwrap(); 198 T updated = visitObject(original); 199 if (updated != null && updated != original) { 199 200 return Option.some(updated); 200 201 } trunk/ProjectFortress/src/com/sun/fortress/nodes_util/ExprFactory.java
r2112 r2162 453 453 } 454 454 455 public static VarRef makeVarRef(Span span, String s, int lexical_depth) { 456 return new VarRef(span, false, NodeFactory.makeId(span, s), lexical_depth); 457 } 458 455 459 public static VarRef makeVarRef(String s) { 456 460 return makeVarRef(NodeFactory.makeId(s)); trunk/ProjectFortress/src/com/sun/fortress/useful/StringComparer.java
r593 r2162 20 20 import java.util.Comparator; 21 21 22 /** 23 * Provides an ordinary, boring, comparator for strings that provides the 24 * default order. 25 * 26 * @author dr2chase 27 */ 22 28 public final class StringComparer implements Comparator<String> { 23 29
