Changeset 2162

Show
Ignore:
Timestamp:
07/01/08 11:49:25 (2 months ago)
Author:
dr2chase
Message:

[Environments] fixed busted lexical depth annotation; cleaned up evaluation of various different references

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/env/WorseEnv.java

    r2048 r2162  
    3131        @Override 
    3232        public Appendable dump(Appendable a) throws IOException { 
    33                 // TODO Auto-generated method stub 
    34                 return null; 
     33            throw new Error(); 
     34 
    3535        } 
    3636 
    3737        public Environment extend() { 
    38                 // TODO Auto-generated method stub 
    39                 return null; 
     38            throw new Error(); 
     39 
    4040        } 
    4141 
    4242        public Environment extend(Environment additions) { 
    43                 // TODO Auto-generated method stub 
    44                 return null; 
     43            throw new Error(); 
     44 
    4545        } 
    4646 
    4747        public Environment extendAt(HasAt x) { 
    48                 // TODO Auto-generated method stub 
    49                 return null; 
     48            throw new Error(); 
     49 
    5050        } 
    5151 
    5252        @Override 
    5353        public Boolean getBoolNull(String str) { 
    54                 // TODO Auto-generated method stub 
    55                 return null; 
     54            throw new Error(); 
     55 
    5656        } 
    5757 
    5858        public Number getIntNull(String s) { 
    59                 // TODO Auto-generated method stub 
    60                 return null; 
     59            throw new Error(); 
     60 
    6161        } 
    6262 
    6363        @Override 
    6464        public Number getNatNull(String str) { 
    65                 // TODO Auto-generated method stub 
    66                 return null; 
     65            throw new Error(); 
     66 
    6767        } 
    6868 
    6969        @Override 
    7070        public FType getTypeNull(String str) { 
    71                 // TODO Auto-generated method stub 
    72                 return null; 
     71            throw new Error(); 
     72 
    7373        } 
    7474 
    7575        public FValue getValueRaw(String s) { 
    76                 // TODO Auto-generated method stub 
    77                 return null; 
     76            throw new Error(); 
     77 
    7878        } 
    7979 
    8080        public void putBoolRaw(String str, Boolean f2) { 
    81                 // TODO Auto-generated method stub 
     81            throw new Error(); 
    8282 
    8383        } 
    8484 
    8585        public void putIntRaw(String str, Number f2) { 
    86                 // TODO Auto-generated method stub 
     86            throw new Error(); 
    8787 
    8888        } 
    8989 
    9090        public void putNatRaw(String str, Number f2) { 
    91                 // TODO Auto-generated method stub 
     91            throw new Error(); 
    9292 
    9393        } 
    9494 
    9595        public void putTypeRaw(String str, FType f2) { 
    96                 // TODO Auto-generated method stub 
     96            throw new Error(); 
    9797 
    9898        } 
    9999 
    100100        public void putValueRaw(String str, FValue f2) { 
    101                 // TODO Auto-generated method stub 
     101            throw new Error(); 
    102102 
    103103        } 
    104104 
    105105        public void removeType(String s) { 
    106                 // TODO Auto-generated method stub 
     106            throw new Error(); 
    107107 
    108108        } 
    109109 
    110110        public void removeVar(String name) { 
    111                 // TODO Auto-generated method stub 
     111            throw new Error(); 
    112112 
    113113        } 
     
    116116                        Visitor2<String, Number> vi, Visitor2<String, FValue> vv, 
    117117                        Visitor2<String, Boolean> vb) { 
    118                 // TODO Auto-generated method stub 
     118            throw new Error(); 
    119119 
    120120        } 
    121121 
    122122        public void visit(Visitor2<String, Object> nameCollector) { 
    123                 // TODO Auto-generated method stub 
     123            throw new Error(); 
    124124 
    125125        } 
    126126 
    127127        public Iterable<String> youngestFrame() { 
    128                 // TODO Auto-generated method stub 
    129                 return null; 
     128                throw new Error(); 
    130129        } 
    131130 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/BaseEnv.java

    r2070 r2162  
    3939import com.sun.fortress.nodes.VarRef; 
    4040import com.sun.fortress.nodes_util.NodeUtil; 
     41import com.sun.fortress.useful.BASet; 
    4142import com.sun.fortress.useful.HasAt; 
    4243import com.sun.fortress.useful.StringArrayIterator; 
     
    355356    } 
    356357 
     358    static private BASet<String> missedNames = new BASet<String>(com.sun.fortress.useful.StringComparer.V); 
     359     
    357360    final public  FValue getValueNull(VarRef vr) { 
    358361        Id name = vr.getVar(); 
    359362        String s = NodeUtil.nameString(name); 
    360363        int l = vr.getLexicalDepth(); 
    361         if (l == -1) 
    362             return error(errorMsg("Untagged VarRef ", vr)); 
    363364        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        } 
    364372        return getValueNullTail(s, v); 
    365373    } 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/BuildEnvironments.java

    r2072 r2162  
    687687                // Create a little expression to run the constructor. 
    688688                Expr init = ExprFactory.makeTightJuxt(x.getSpan(), 
    689                       ExprFactory.makeVarRef(x.getSpan(), obfuscatedSingletonConstructorName(fname, x)), 
     689                      ExprFactory.makeVarRef(x.getSpan(), obfuscatedSingletonConstructorName(fname, x), 0), 
    690690                      ExprFactory.makeVoidLiteralExpr(x.getSpan())); 
    691691                FValue init_value = new LazilyEvaluatedCell(init, containing); 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/BuildNativeEnvironment.java

    r1895 r2162  
    160160                // Create a little expression to run the constructor. 
    161161                Expr init = ExprFactory.makeTightJuxt(x.getSpan(), ExprFactory 
    162                         .makeVarRef(x.getSpan(), obfuscatedSingletonConstructorName(fname, x)), 
     162                        .makeVarRef(x.getSpan(), obfuscatedSingletonConstructorName(fname, x), 0), 
    163163                        ExprFactory.makeVoidLiteralExpr(x.getSpan())); 
    164164                FValue init_value = new LazilyEvaluatedCell(init, containing); 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/Environment.java

    r2062 r2162  
    2424import com.sun.fortress.interpreter.evaluator.values.FValue; 
    2525import com.sun.fortress.nodes.Id; 
     26import com.sun.fortress.nodes.VarRef; 
    2627import com.sun.fortress.useful.HasAt; 
    2728import com.sun.fortress.useful.Visitor2; 
     
    106107     */ 
    107108    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); 
    108118 
    109119    public abstract FValue getValueRaw(String s); 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/Evaluator.java

    r2119 r2162  
    16111611 
    16121612    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()); 
    16171616            error(x, e, errorMsg("undefined variable ", names)); 
     1617        } 
    16181618        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 to 
    1638                      * know whether a.b was field b of object a, or member b of 
    1639                      * api a (or api name prefix, extended). 
    1640                      * / 
    1641                     // TODO Need to distinguish between public/private 
    1642                     // methods/fields 
    1643                     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     */ 
    16561619    } 
    16571620 
     
    17011664     * @see com.sun.fortress.interpreter.nodes.NodeVisitor#forFnRef(com.sun.fortress.interpreter.nodes.FnRef) 
    17021665     */ 
    1703     /** Assumes {@code x.getIds()} is a list of length 1. */ 
    17041666    @Override 
    17051667    public FValue forFnRef(FnRef x) { 
    1706         Id name = x.getFns().get(0); 
    1707         FValue g = forVarRef(new VarRef(name.getSpan(), name)); 
     1668        Id name = x.getOriginalName(); 
     1669        FValue g = forIdOfRef(name); 
    17081670        return applyToActualStaticArgs(g,x.getStaticArgs(),x); 
    17091671    } 
     
    17121674        public FValue for_RewriteObjectRef(_RewriteObjectRef that) { 
    17131675        Id name = that.getObj(); 
    1714         FValue g = forVarRef(new VarRef(name.getSpan(), name)); 
    1715                return applyToActualStaticArgs(g,that.getStaticArgs(),that); 
     1676        FValue g = forIdOfRef(name); 
     1677        return applyToActualStaticArgs(g,that.getStaticArgs(),that); 
    17161678        } 
    17171679 
    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 
    17191690    public FValue for_RewriteFnRef(_RewriteFnRef x) { 
    17201691        Expr name = x.getFn(); 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/rewrite/Desugarer.java

    r2060 r2162  
    5151import com.sun.fortress.nodes_util.NodeUtil; 
    5252import com.sun.fortress.nodes_util.OprUtil; 
     53import com.sun.fortress.nodes.Expr; 
     54import com.sun.fortress.nodes.ExtentRange; 
     55import com.sun.fortress.nodes.LValue; 
     56import com.sun.fortress.nodes.LValueBind; 
    5357import com.sun.fortress.nodes.StaticParam; 
    5458import com.sun.fortress.nodes.TightJuxt; 
     
    5660import com.sun.fortress.nodes.BaseType; 
    5761import com.sun.fortress.nodes.Type; 
     62import com.sun.fortress.nodes.UnpastingBind; 
     63import com.sun.fortress.nodes.UnpastingSplit; 
    5864import com.sun.fortress.nodes.VarDecl; 
    5965import com.sun.fortress.nodes.VarRef; 
     
    315321     */ 
    316322    private BATree<String, Thing> rewrites; 
     323     
     324    public Thing rewrites_put(String k, Thing d) { 
     325        return rewrites.put(k, d); 
     326    } 
    317327 
    318328    /** 
     
    397407    /** 
    398408     * 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. 
    400410     * @param env 
    401411     */ 
     
    497507        /* Empty means do  add */ 
    498508        if (old == null) { 
    499             rewrites.put(putName, th); 
     509            rewrites_put(putName, th); 
    500510            return true; 
    501511        } 
     
    699709                    if (atTopLevelInsideTraitOrObject) { 
    700710                        currentSelfName = fndef.getSelfName(); 
    701                         rewrites.put(currentSelfName, new SelfRewrite(currentSelfName)); 
     711                        rewrites_put(currentSelfName, new SelfRewrite(currentSelfName)); 
    702712                    } 
    703713                    atTopLevelInsideTraitOrObject = false; 
     
    772782                } else if (node instanceof LocalVarDecl) { 
    773783                    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                     
    777795                    // TODO wip 
    778796 
     
    797815                    List<StaticParam> tparams = od.getStaticParams(); 
    798816                    List<BaseType> xtends = NodeUtil.getTypes(od.getExtendsClause()); 
     817                     
    799818                    // TODO wip 
    800819                    lexicalNestingDepth++; 
    801820                    objectNestingDepth++; 
    802821                    atTopLevelInsideTraitOrObject = true; 
     822                     
    803823                    defsToMembers(defs); 
    804824                    immediateDef = tparamsToLocals(tparams, immediateDef); 
     
    12851305    private void defsToLocals(List<? extends AbsDeclOrDecl> defs) { 
    12861306        for (AbsDeclOrDecl d : defs) { 
    1287             String s = d.stringName(); 
    12881307            if (d instanceof TraitAbsDeclOrDecl) { 
     1308                String s = d.stringName(); 
    12891309                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); 
    12911328            } else { 
    1292                 rewrites.put(s, new Local()); 
     1329                for (String s : NodeUtil.stringNames(d)) { 
     1330                    rewrites_put(s, new Local()); 
     1331                } 
    12931332            } 
    12941333        } 
     
    13031342            // "self" is not a local. 
    13041343            if (! s.equals(currentSelfName)) { 
    1305                 rewrites.put(s, new Local()); 
     1344                rewrites_put(s, new Local()); 
    13061345 
    13071346            } 
    13081347        } 
     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); 
    13091391    } 
    13101392 
     
    13161398            for (StaticParam d : params) { 
    13171399                String s = NodeUtil.getName(d); 
    1318                 rewrites.put(s, new Local()); 
     1400                rewrites_put(s, new Local()); 
    13191401                visibleGenericParameters.put(s, d); 
    13201402                immediateDef = addToImmediateDef(immediateDef, s); 
     
    13411423        for (AbsDeclOrDecl d : defs) { 
    13421424            for (String s: NodeUtil.stringNames(d)) 
    1343             rewrites.put(s, new Member()); 
     1425            rewrites_put(s, new Member()); 
    13441426        } 
    13451427 
     
    13531435            for (Param d : params.unwrap()) { 
    13541436                String s = d.getName().getText(); 
    1355                 rewrites.put(s, new Member(NodeUtil.isTransient(d))); 
     1437                rewrites_put(s, new Member(NodeUtil.isTransient(d))); 
    13561438                if (d.accept(isAnArrowName)) 
    13571439                    arrows.add(s); 
     
    13681450    private void stringsToMembers(Collection<String> strings) { 
    13691451        for (String s : strings) { 
    1370             rewrites.put(s, new Member()); 
     1452            rewrites_put(s, new Member()); 
    13711453            arrows.remove(s); 
    13721454        } 
     
    13781460    private void stringsToLocals(Collection<String> strings) { 
    13791461        for (String s : strings) { 
    1380             rewrites.put(s, new Local()); 
     1462            rewrites_put(s, new Local()); 
    13811463            arrows.remove(s); 
    13821464        } 
  • trunk/ProjectFortress/src/com/sun/fortress/interpreter/rewrite/Rewrite.java

    r1895 r2162  
    195195    protected <T> Option<T> visitOption(Option<T> opt) { 
    196196        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) { 
    199200                return Option.some(updated); 
    200201            } 
  • trunk/ProjectFortress/src/com/sun/fortress/nodes_util/ExprFactory.java

    r2112 r2162  
    453453    } 
    454454 
     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 
    455459    public static VarRef makeVarRef(String s) { 
    456460        return makeVarRef(NodeFactory.makeId(s)); 
  • trunk/ProjectFortress/src/com/sun/fortress/useful/StringComparer.java

    r593 r2162  
    2020import java.util.Comparator; 
    2121 
     22/** 
     23 * Provides an ordinary, boring, comparator for strings that provides the 
     24 * default order. 
     25 *  
     26 * @author dr2chase 
     27 */ 
    2228public final class StringComparer implements Comparator<String> { 
    2329