[Nice-commit] Nice/src/bossa/syntax typecheck.nice,1.88,1.89 analyse.nice,1.86,1.87 MonoSymbol.java,
Brought to you by:
bonniot
From: <bo...@us...> - 2003-11-24 19:22:05
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1:/tmp/cvs-serv27954/src/bossa/syntax Modified Files: typecheck.nice analyse.nice MonoSymbol.java Log Message: Consider captured from all anonymous functions, even those that appear after the current point. Do not mark as captured local variables of an anonymous function when only accessed from that function. Index: typecheck.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/typecheck.nice,v retrieving revision 1.88 retrieving revision 1.89 diff -C2 -d -r1.88 -r1.89 *** typecheck.nice 21 Nov 2003 15:09:42 -0000 1.88 --- typecheck.nice 24 Nov 2003 19:22:02 -0000 1.89 *************** *** 42,47 **** let variable = localVariable(to); - if (variable != null && Node.getCurrentFunction() instanceof FunExp) - setCaptured(variable); try{ --- 42,45 ---- *************** *** 488,512 **** (levels, conditionalTypes) = closureEnvironments.pop(); - } - - void setCaptured(MonoSymbol variable) - { - if (!variable.captured) - { - variable.captured = true; - //set all conditional types back to the original type - let origType = getOriginalType(variable) || variable.type; - variable.type = origType; - for (int i = 0; i < closureEnvironments.size(); i++) - { - (Stack<int> lvls, Stack<(MonoSymbol, mlsub.typing.Monotype)> condTypes) = closureEnvironments.get(i); - for (int k = 0; k < condTypes.size(); k++) - { - (MonoSymbol v, mlsub.typing.Monotype t) = condTypes.get(k); - if (v == variable) - condTypes.set(k, (v, origType)); - } - } - } } --- 486,489 ---- Index: analyse.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/analyse.nice,v retrieving revision 1.86 retrieving revision 1.87 diff -C2 -d -r1.86 -r1.87 *** analyse.nice 24 Nov 2003 16:50:24 -0000 1.86 --- analyse.nice 24 Nov 2003 19:22:02 -0000 1.87 *************** *** 83,86 **** --- 83,96 ---- int varIndex = 0; + /* + The number of nested blocks. + */ + int depth = 0; + + /* + The depth of the current anonymous function. + */ + int anonFunDepth = 0; + boolean getUnreachable() = (this.flags & 1) != 0; void setUnreachable() { this.flags |= 1; } *************** *** 142,145 **** --- 152,156 ---- this.vars.begin(); this.typeVars.begin(); + this.depth++; } *************** *** 148,151 **** --- 159,163 ---- this.vars.end(); this.typeVars.end(); + this.depth--; } *************** *** 188,191 **** --- 200,204 ---- this.checkNotDefined(symbol); this.vars[symbol.name.toString()] = symbol; + symbol.depth = this.depth; } *************** *** 377,399 **** analyse(e@FunExp, info) { ! info.beginInner(); ! info.begin(); ! if (e.constraint != Constraint.True && e.constraint != null) ! { ! e.cst = notNull(e.constraint).resolveToLowlevel(); ! addTypeVars(info, notNull(e.cst).binders()); ! } ! e.constraint = null; ! if (e.formals != null) ! addVars(info, elementsNotNull(notNull(e.formals))); ! analyse(e.body, info); ! e.setAlwaysReturns(info.getUnreachable()); ! info.end(); ! info.endInner(); ! return e; } --- 390,420 ---- analyse(e@FunExp, info) { ! let savedDepth = info.anonFunDepth; ! try { ! info.beginInner(); ! info.begin(); ! info.anonFunDepth = info.depth; ! if (e.constraint != Constraint.True && e.constraint != null) ! { ! e.cst = notNull(e.constraint).resolveToLowlevel(); ! addTypeVars(info, notNull(e.cst).binders()); ! } ! e.constraint = null; ! if (e.formals != null) ! addVars(info, elementsNotNull(notNull(e.formals))); ! analyse(e.body, info); ! e.setAlwaysReturns(info.getUnreachable()); ! ! return e; ! } ! finally { ! info.end(); ! info.endInner(); ! info.anonFunDepth = savedDepth; ! } } *************** *** 414,424 **** else { ! if (sym instanceof Block.LocalVariable.Symbol) ! { ! if (assigned) ! setInitialized(sym, info, e.location()); ! else ! checkInitialized(sym, info, e.location()); ! } return new SymbolExp(sym, e.location()); } --- 435,452 ---- else { ! if (sym instanceof MonoSymbol) ! { ! if (sym.depth < info.anonFunDepth) ! sym.captured = true; ! ! if (sym instanceof Block.LocalVariable.Symbol) ! { ! if (assigned) ! setInitialized(sym, info, e.location()); ! else ! checkInitialized(sym, info, e.location()); ! } ! } ! return new SymbolExp(sym, e.location()); } Index: MonoSymbol.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/MonoSymbol.java,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** MonoSymbol.java 20 Nov 2003 01:16:49 -0000 1.26 --- MonoSymbol.java 24 Nov 2003 19:22:02 -0000 1.27 *************** *** 161,164 **** --- 161,167 ---- boolean captured = false; + /** The depth of nested block at which this variable is defined. */ + int depth; + Monotype syntacticType; mlsub.typing.Monotype type; |