[Nice-commit] Nice/src/bossa/syntax Monotype.java,1.40,1.41 customConstructor.nice,1.13,1.14 formalP
Brought to you by:
bonniot
|
From: Arjan B. <ar...@us...> - 2005-01-12 20:56:45
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28791/F:/nice/src/bossa/syntax Modified Files: Monotype.java customConstructor.nice formalParameters.nice importedconstructor.nice niceMethod.nice niceclass.nice nicefieldaccess.nice typeIdent.nice typedef.nice Log Message: More preparation for Monotype conversion. Index: typeIdent.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/typeIdent.nice,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** typeIdent.nice 18 Dec 2004 19:41:01 -0000 1.1 --- typeIdent.nice 12 Jan 2005 20:56:30 -0000 1.2 *************** *** 40,44 **** } ! resolveToTypeSymbol(scope) { let res = notNull(scope).lookup(name); --- 40,44 ---- } ! public mlsub.typing.TypeSymbol resolveToTypeSymbol(TypeMap scope) { let res = notNull(scope).lookup(name); *************** *** 51,55 **** rawResolve(scope) { ! let res = this.resolveToTypeSymbol(scope); if (res instanceof mlsub.typing.Monotype) --- 51,55 ---- rawResolve(scope) { ! let res = this.resolveToTypeSymbol(notNull(scope)); if (res instanceof mlsub.typing.Monotype) Index: typedef.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/typedef.nice,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** typedef.nice 10 Jan 2005 23:58:04 -0000 1.11 --- typedef.nice 12 Jan 2005 20:56:30 -0000 1.12 *************** *** 406,412 **** typeParameters[i] = mvar; ! bossa.syntax.Monotype v = bossa.syntax.Monotype.create(mvar); ! atoms.add(new MonotypeLeqCst(m1: bossa.syntax.Monotype.create(params[i]), m2: v)); ! atoms.add(new MonotypeLeqCst(m1: v, m2: bossa.syntax.Monotype.create(params[i]))); } --- 406,412 ---- typeParameters[i] = mvar; ! bossa.syntax.Monotype v = new Monotype.MonotypeWrapper(mvar); ! atoms.add(new MonotypeLeqCst(m1: new Monotype.MonotypeWrapper(params[i]), m2: v)); ! atoms.add(new MonotypeLeqCst(m1: v, m2: new Monotype.MonotypeWrapper(params[i]))); } Index: Monotype.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Monotype.java,v retrieving revision 1.40 retrieving revision 1.41 diff -C2 -d -r1.40 -r1.41 *** Monotype.java 12 Jan 2005 18:50:37 -0000 1.40 --- Monotype.java 12 Jan 2005 20:56:30 -0000 1.41 *************** *** 16,42 **** import bossa.util.*; - import mlsub.typing.MonotypeVar; - import mlsub.typing.TypeConstructor; - import nice.tools.typing.PrimitiveType; - /** Syntactic monomorphic type. - @version $Date$ - @author Daniel Bonniot (d.b...@ma...) */ ! public abstract class Monotype ! implements Located { - - /** @return true if "alike" appears inside this monotype. */ - abstract boolean containsAlike(); - - public boolean isVoid() { return false; } - - /************************************************************** - * Scoping - **************************************************************/ - /** Set by the parser. */ public byte nullness; --- 16,25 ---- import bossa.util.*; /** Syntactic monomorphic type. */ ! public abstract class Monotype implements Located { /** Set by the parser. */ public byte nullness; *************** *** 48,88 **** absent = 3; */ ! final String nullnessString() { ! switch(nullness) ! { ! case /*maybe*/1: return "?"; ! case /*sure*/2: return "!"; ! default: return ""; ! } } ! // public since it is called from bossa.dispatch ! public final mlsub.typing.Monotype resolve(TypeMap tm) { mlsub.typing.Monotype raw = rawResolve(tm); ! ! switch (nullness) { ! case /*none*/0: return raw; ! case /*maybe*/1: return sourceMaybe(raw); ! case /*sure*/2: return sourceSure(raw); ! case /*absent*/3: ! if (raw instanceof MonotypeVar) { ! nice.tools.typing.Types.makeMarkedType((MonotypeVar) raw); return raw; } else ! return sure(raw); ! default: ! throw Internal.error("Bad nullness tag"); } } ! abstract mlsub.typing.Monotype rawResolve(TypeMap tm); /** iterates resolve() on the collection of Monotype */ ! static final mlsub.typing.Monotype[] resolve(TypeMap s, Monotype[] c) { if(c == null || c.length == 0) --- 31,86 ---- absent = 3; */ ! ! /** @return true if "alike" appears inside this monotype. */ ! abstract boolean containsAlike(); ! ! abstract mlsub.typing.Monotype rawResolve(TypeMap tm); ! ! abstract Monotype substitute(Map/*<String,Monotype>*/ map); ! ! public boolean isVoid() { return false; } ! ! String nullnessString() { ! if (nullness == /*maybe*/1) ! return "?"; ! else if (nullness == /*sure*/2) ! return "!"; ! else ! return ""; } ! public mlsub.typing.Monotype resolve(TypeMap tm) { mlsub.typing.Monotype raw = rawResolve(tm); ! ! if (nullness == /*none*/0) ! return raw; ! else if (nullness == /*maybe*/1) ! return nice.tools.typing.Types.maybeMonotype(nice.tools.typing.Types.rawType(raw)); ! else if (nullness == /*sure*/2) ! return nice.tools.typing.Types.sureMonotype(nice.tools.typing.Types.rawType(raw)); ! else if (nullness == /*absent*/3) { ! if (raw instanceof mlsub.typing.MonotypeVar) { ! nice.tools.typing.Types.makeMarkedType((mlsub.typing.MonotypeVar) raw); return raw; } else ! return nice.tools.typing.Types.sureMonotype(raw); } + else + throw Internal.error("Bad nullness tag"); } ! /** called instead of toString if parenthesis are unnecessary */ ! public String toStringExtern() { return this.toString(); } ! ! /** don't print type parameters */ ! public String toStringBase() { return this.toString(); } /** iterates resolve() on the collection of Monotype */ ! static mlsub.typing.Monotype[] resolve(TypeMap s, Monotype[] c) { if(c == null || c.length == 0) *************** *** 103,143 **** return res; } ! ! abstract Monotype substitute(Map map); ! ! //temporarily method to call on TypeIdent's ! public mlsub.typing.TypeSymbol resolveToTypeSymbol(TypeMap scope) ! { ! return null; ! } ! ! /**************************************************************** ! * Printing ! ****************************************************************/ ! ! /** called instead of toString if parenthesis are unnecessary */ ! public String toStringExtern() ! { ! return toString(); ! } ! ! /** don't print type parameters */ ! public String toStringBase() { ! return toString(); ! } ! /**************************************************************** ! * Wrapping a mlsub Monotype in a syntactic monotype ! ****************************************************************/ ! ! public static Monotype create(mlsub.typing.Monotype m) ! { ! return new Wrapper(m); ! } ! ! private static class Wrapper extends Monotype ! { ! Wrapper(mlsub.typing.Monotype m) { this.type = m; --- 101,113 ---- return res; } ! ! /** ! Wrapping a mlsub Monotype in a syntactic monotype ! */ ! public static class MonotypeWrapper extends Monotype { ! final mlsub.typing.Monotype type; ! public MonotypeWrapper(mlsub.typing.Monotype m) { this.type = m; *************** *** 146,187 **** boolean containsAlike() { return false; } ! public mlsub.typing.Monotype rawResolve(TypeMap s) ! { ! return type; ! } ! Monotype substitute(Map m) ! { ! return this; ! } ! public Location location() ! { ! return Location.nowhere(); ! } ! public String toString() ! { ! return String.valueOf(type); ! } ! ! final mlsub.typing.Monotype type; } ! public static Monotype createVar(mlsub.typing.MonotypeVar m) ! { ! return new VarWrapper(m); ! } ! ! private static final class VarWrapper extends Wrapper { ! VarWrapper(mlsub.typing.MonotypeVar m) { super(m); } ! public mlsub.typing.Monotype rawResolve(TypeMap s) { ! mlsub.typing.TypeSymbol res = s.lookup(type.toString()); if (res != null) return (mlsub.typing.Monotype) res; --- 116,138 ---- boolean containsAlike() { return false; } ! public mlsub.typing.Monotype rawResolve(TypeMap tm) { return type; } ! Monotype substitute(Map map) { return this; } ! public Location location() { return Location.nowhere(); } ! public String toString() { return String.valueOf(type); } } ! public static final class MonotypeVarWrapper extends MonotypeWrapper { ! public MonotypeVarWrapper(mlsub.typing.MonotypeVar m) { super(m); } ! public mlsub.typing.Monotype rawResolve(TypeMap tm) { ! mlsub.typing.TypeSymbol res = tm.lookup(type.toString()); if (res != null) return (mlsub.typing.Monotype) res; *************** *** 191,271 **** } ! /**************************************************************** ! * Wrapper for delaying resolution of constructed monotypes. ! ****************************************************************/ ! ! static Monotype createSure(final TypeConstructor tc, final mlsub.typing.Monotype[] params) { ! return new Monotype() { ! boolean containsAlike() { return false; } ! ! public mlsub.typing.Monotype rawResolve(TypeMap typeMap) ! { ! try{ ! return sure(new mlsub.typing.MonotypeConstructor(tc, params)); ! } ! catch(mlsub.typing.BadSizeEx e){ ! // See if this is a class with default type parameters ! mlsub.typing.Monotype res = dispatch.getTypeWithTC(tc, params); ! if (res != null) ! return sure(res); ! ! throw User.error(this, "Class " + tc + ! Util.has(e.expected, "type parameter", e.actual)); ! } ! } ! ! Monotype substitute(Map m) ! { ! return this; ! } ! ! public Location location() ! { ! return Location.nowhere(); ! } ! public String toString() ! { ! return tc + ( params != null ? Util.map("<",",",">",params) : ""); ! } ! }; ! } ! /**************************************************************** ! * Nullness markers ! ****************************************************************/ ! /** ! Return a maybe type based on the raw type of the argument ! if the argument is a full type. ! */ ! static mlsub.typing.Monotype sourceMaybe(mlsub.typing.Monotype type) ! { ! mlsub.typing.Monotype raw = nice.tools.typing.Types.rawType(type); ! return maybe(raw); ! } ! public static mlsub.typing.Monotype maybe(mlsub.typing.Monotype type) ! { ! return new mlsub.typing.MonotypeConstructor ! (PrimitiveType.maybeTC, new mlsub.typing.Monotype[]{type}); ! } ! /** ! Return a sure type based on the raw type of the argument ! if the argument is a full type. ! */ ! static mlsub.typing.Monotype sourceSure(mlsub.typing.Monotype type) ! { ! mlsub.typing.Monotype raw = nice.tools.typing.Types.rawType(type); ! return sure(raw); ! } ! public static mlsub.typing.Monotype sure(mlsub.typing.Monotype type) ! { ! return new mlsub.typing.MonotypeConstructor ! (PrimitiveType.sureTC, new mlsub.typing.Monotype[]{type}); } } - --- 142,184 ---- } ! /** ! Wrapper for delaying resolution of constructed monotypes. ! */ ! public static final class SureMonotypeWrapper extends Monotype { ! mlsub.typing.TypeConstructor tc; ! mlsub.typing.Monotype[] params; ! public SureMonotypeWrapper(mlsub.typing.TypeConstructor tc, mlsub.typing.Monotype[] params) ! { ! this.tc = tc; ! this.params = params; ! } ! ! boolean containsAlike() { return false; } ! public mlsub.typing.Monotype rawResolve(TypeMap tm) ! { ! try{ ! return nice.tools.typing.Types.sureMonotype(new mlsub.typing.MonotypeConstructor(tc, params)); ! } ! catch(mlsub.typing.BadSizeEx e){ ! // See if this is a class with default type parameters ! mlsub.typing.Monotype res = dispatch.getTypeWithTC(tc, params); ! if (res != null) ! return nice.tools.typing.Types.sureMonotype(res); ! throw User.error(this, "Class " + tc + Util.has(e.expected, "type parameter", e.actual)); ! } ! } ! Monotype substitute(Map map) { return this; } ! public Location location() { return Location.nowhere(); } ! public String toString() ! { ! return tc + ( params != null ? Util.map("<",",",">",params) : ""); ! } } } Index: customConstructor.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/customConstructor.nice,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** customConstructor.nice 12 Jan 2005 18:50:37 -0000 1.13 --- customConstructor.nice 12 Jan 2005 20:56:30 -0000 1.14 *************** *** 87,91 **** for (int i = 0; i < source.length; i++) ! res.put(source[i].toString(), Monotype.create(destination[i])); return res; --- 87,91 ---- for (int i = 0; i < source.length; i++) ! res.put(source[i].toString(), new Monotype.MonotypeWrapper(destination[i])); return res; *************** *** 177,181 **** if (! (syms[i] instanceof mlsub.typing.MonotypeVar)) User.error(classe, syms[i] + " is not a type"); ! notNull(params)[i] = Monotype.create(cast(syms[i])); } --- 177,181 ---- if (! (syms[i] instanceof mlsub.typing.MonotypeVar)) User.error(classe, syms[i] + " is not a type"); ! notNull(params)[i] = new Monotype.MonotypeWrapper(cast(syms[i])); } Index: nicefieldaccess.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/nicefieldaccess.nice,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** nicefieldaccess.nice 12 Jan 2005 18:50:38 -0000 1.8 --- nicefieldaccess.nice 12 Jan 2005 20:56:30 -0000 1.9 *************** *** 46,50 **** let argType = sureMonotype(classDef.lowlevelMonotype()); ! let params = createFormalParameters([new Parameter(type: Monotype.create(argType))]); let constr = createConstraint(classDef.getBinders(), null); let res = new NiceFieldAccess(field.getName(), Node.down, --- 46,50 ---- let argType = sureMonotype(classDef.lowlevelMonotype()); ! let params = createFormalParameters([new Parameter(type: new Monotype.MonotypeWrapper(argType))]); let constr = createConstraint(classDef.getBinders(), null); let res = new NiceFieldAccess(field.getName(), Node.down, Index: importedconstructor.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/importedconstructor.nice,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** importedconstructor.nice 12 Jan 2005 18:50:37 -0000 1.10 --- importedconstructor.nice 12 Jan 2005 20:56:30 -0000 1.11 *************** *** 96,100 **** let classDef = def.getDefinition(); ! let returnType = Monotype.create(sureMonotype (new mlsub.typing.MonotypeConstructor(classDef.getTC(), classDef.getTypeParameters()))); --- 96,100 ---- let classDef = def.getDefinition(); ! let returnType = new Monotype.MonotypeWrapper(sureMonotype (new mlsub.typing.MonotypeConstructor(classDef.getTC(), classDef.getTypeParameters()))); Index: niceclass.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/niceclass.nice,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** niceclass.nice 12 Jan 2005 18:50:38 -0000 1.16 --- niceclass.nice 12 Jan 2005 20:56:30 -0000 1.17 *************** *** 408,412 **** List<Parameter> params = new ArrayList(); for (arg : m.getArgTypes()) ! params.add(new Parameter(type: Monotype.create(arg))); res.add((m, params)); --- 408,412 ---- List<Parameter> params = new ArrayList(); for (arg : m.getArgTypes()) ! params.add(new Parameter(type: new Monotype.MonotypeWrapper(arg))); res.add((m, params)); Index: niceMethod.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/niceMethod.nice,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** niceMethod.nice 12 Jan 2005 18:50:38 -0000 1.12 --- niceMethod.nice 12 Jan 2005 20:56:30 -0000 1.13 *************** *** 292,296 **** constraint.addAtom(new AtomicConstraintWrapper(atom: atom)); ! thisType = Monotype.create (sureMonotype (new mlsub.typing.MonotypeConstructor --- 292,296 ---- constraint.addAtom(new AtomicConstraintWrapper(atom: atom)); ! thisType = new Monotype.MonotypeWrapper (sureMonotype (new mlsub.typing.MonotypeConstructor *************** *** 308,312 **** } else ! thisType = Monotype.createSure(tc, c.getTypeParameters()); params.addThis(thisType); --- 308,312 ---- } else ! thisType = new Monotype.SureMonotypeWrapper(tc, c.getTypeParameters()); params.addThis(thisType); Index: formalParameters.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/formalParameters.nice,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** formalParameters.nice 12 Jan 2005 18:50:37 -0000 1.3 --- formalParameters.nice 12 Jan 2005 20:56:30 -0000 1.4 *************** *** 254,258 **** { Parameter p = parameters[i].cloneParam(); ! p.type = Monotype.create(p.type.resolve(scope)); res.add(p); } --- 254,258 ---- { Parameter p = parameters[i].cloneParam(); ! p.type = new Monotype.MonotypeWrapper(p.type.resolve(scope)); res.add(p); } |