Update of /cvsroot/nice/Nice/src/bossa/syntax
In directory
sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12858/F:/nice/src/bossa/syntax
Modified Files:
customConstructor.nice formalParameters.nice
importedconstructor.nice monotype.nice niceMethod.nice
niceclass.nice nicefieldaccess.nice polytype.nice symbol.nice
tools.nice tuple.nice typeIdent.nice typedef.nice
Removed Files:
Monotype.java
Log Message:
Converted Monotype.
Index: typeIdent.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/typeIdent.nice,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** typeIdent.nice 12 Jan 2005 20:56:30 -0000 1.2
--- typeIdent.nice 12 Jan 2005 22:06:54 -0000 1.3
***************
*** 49,55 ****
}
! rawResolve(scope)
{
! let res = this.resolveToTypeSymbol(notNull(scope));
if (res instanceof mlsub.typing.Monotype)
--- 49,55 ----
}
! rawResolve(tm)
{
! let res = this.resolveToTypeSymbol(tm);
if (res instanceof mlsub.typing.Monotype)
Index: customConstructor.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/customConstructor.nice,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** customConstructor.nice 12 Jan 2005 20:56:30 -0000 1.14
--- customConstructor.nice 12 Jan 2005 22:06:53 -0000 1.15
***************
*** 87,91 ****
for (int i = 0; i < source.length; i++)
! res.put(source[i].toString(), new
Monotype.MonotypeWrapper(destination[i]));
return res;
--- 87,91 ----
for (int i = 0; i < source.length; i++)
! res.put(source[i].toString(), new MonotypeWrapper(type:
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] = new Monotype.MonotypeWrapper(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 MonotypeWrapper(type: cast(syms[i]));
}
Index: monotype.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/monotype.nice,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** monotype.nice 12 Jan 2005 18:50:37 -0000 1.7
--- monotype.nice 12 Jan 2005 22:06:53 -0000 1.8
***************
*** 16,19 ****
--- 16,168 ----
/**
+ Syntactic monomorphic type.
+
+ */
+ public abstract class Monotype implements Located
+ {
+ /** Set by the parser. */
+ public byte nullness = 0;
+ /*
+ public static final byte
+ none = 0,
+ maybe = 1,
+ sure = 2,
+ absent = 3;
+ */
+
+ /** @return true if "alike" appears inside this monotype. */
+ boolean containsAlike();
+
+ mlsub.typing.Monotype rawResolve(TypeMap tm);
+
+ Monotype substitute(Map<String,Monotype> map);
+
+ public boolean isVoid() = 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 = this.rawResolve(tm);
+
+ if (nullness == /*none*/0)
+ return raw;
+ else if (nullness == /*maybe*/1)
+ return maybeMonotype(nice.tools.typing.Types.rawType(raw));
+ else if (nullness == /*sure*/2)
+ return sureMonotype(nice.tools.typing.Types.rawType(raw));
+ else if (nullness == /*absent*/3)
+ {
+ if (raw instanceof mlsub.typing.MonotypeVar)
+ {
+ nice.tools.typing.Types.makeMarkedType(raw);
+ return raw;
+ }
+ else
+ return sureMonotype(raw);
+ }
+ else
+ throw Internal.error("Bad nullness tag");
+ }
+
+ /** called instead of toString if parenthesis are unnecessary */
+ public String toStringExtern() = this.toString();
+
+ /** don't print type parameters */
+ public String toStringBase() = this.toString();
+ }
+
+ /** iterates resolve() on the collection of Monotype */
+ mlsub.typing.Monotype[?] resolveMonotypes(TypeMap s, Monotype[?] c)
+ {
+ if(c == null || c.length == 0)
+ return null;
+
+ mlsub.typing.Monotype[] res = cast(new mlsub.typing.Monotype[c.length]);
+
+ for (int n = c.length; --n >= 0;)
+ {
+ let old = c[n];
+ let nou = old.resolve(s);
+
+ if (nou == null)
+ User.error(old, old + " : Monotype not defined");
+
+ res[n] = nou;
+ }
+ return res;
+ }
+
+ /**
+ Wrapping a mlsub Monotype in a syntactic monotype
+ */
+ public class MonotypeWrapper extends Monotype
+ {
+ final mlsub.typing.Monotype type;
+
+ containsAlike() = false;
+
+ rawResolve(tm) = type;
+
+ substitute(map) = this;
+
+ location() = Location.nowhere();
+
+ toString() = String.valueOf(type);
+ }
+
+ public final class MonotypeVarWrapper extends MonotypeWrapper
+ {
+ rawResolve(tm)
+ {
+ let res = tm.lookup(type.toString());
+ if (res != null)
+ return cast(res);
+
+ return type;
+ }
+ }
+
+ /**
+ Wrapper for delaying resolution of constructed monotypes.
+ */
+ public final class SureMonotypeWrapper extends Monotype
+ {
+ mlsub.typing.TypeConstructor tc;
+ mlsub.typing.Monotype[?] params;
+
+ containsAlike() = false;
+
+ rawResolve(tm)
+ {
+ try{
+ return sureMonotype(new mlsub.typing.MonotypeConstructor(tc, params));
+ }
+ catch(mlsub.typing.BadSizeEx e){
+ // See if this is a class with default type parameters
+ let res = getTypeWithTC(tc, params);
+ if (res != null)
+ return sureMonotype(res);
+
+ throw User.error(this, "Class " + tc + Util.has(e.expected, "type
parameter", e.actual));
+ }
+ }
+
+ substitute(map) = this;
+
+ location() = Location.nowhere();
+
+ toString() = tc + ( params != null ? Util.map("<",",",">",params) : "");
+ }
+
+ /**
A monotype, build by application of
a type constructor to type parameters.
***************
*** 30,38 ****
Monotype cloneType() = new
MonotypeConstructor(tc:tc,parameters:parameters,loc:loc);
! rawResolve(typeMap)
{
if (lowlevelTC == null)
{
! let newTC = notNull(this.tc).resolveToTC(notNull(typeMap));
if (! (newTC instanceof TypeConstructor))
throw User.error(notNull(this.tc), notNull(this.tc)+" should be a
type constructor");
--- 179,187 ----
Monotype cloneType() = new
MonotypeConstructor(tc:tc,parameters:parameters,loc:loc);
! rawResolve(tm)
{
if (lowlevelTC == null)
{
! let newTC = notNull(this.tc).resolveToTC(tm);
if (! (newTC instanceof TypeConstructor))
throw User.error(notNull(this.tc), notNull(this.tc)+" should be a
type constructor");
***************
*** 40,44 ****
}
! mlsub.typing.Monotype[?] resolvedParams =
parameters.resolve(notNull(typeMap));
try{
--- 189,193 ----
}
! mlsub.typing.Monotype[?] resolvedParams = parameters.resolve(tm);
try{
***************
*** 107,111 ****
mlsub.typing.Monotype[?] resolve(TypeMap ts)
{
! return Monotype.resolve(ts, content);
}
--- 256,260 ----
mlsub.typing.Monotype[?] resolve(TypeMap ts)
{
! return resolveMonotypes(ts, content);
}
***************
*** 126,134 ****
private bossa.syntax.Monotype out;
! rawResolve(typeMap)
{
return new mlsub.typing.FunType
! (bossa.syntax.Monotype.resolve(notNull(typeMap), in),
! out.resolve(typeMap));
}
--- 275,283 ----
private bossa.syntax.Monotype out;
! rawResolve(tm)
{
return new mlsub.typing.FunType
! (resolveMonotypes(notNull(tm), in),
! out.resolve(tm));
}
***************
*** 175,179 ****
// Alike should be removed as soon as types are constructed.
! rawResolve(map)
{
throw User.error(this, "\"alike\" can only be used in class method
definitions");
--- 324,328 ----
// Alike should be removed as soon as types are constructed.
! rawResolve(tm)
{
throw User.error(this, "\"alike\" can only be used in class method
definitions");
Index: polytype.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/polytype.nice,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** polytype.nice 10 Jan 2005 23:58:04 -0000 1.2
--- polytype.nice 12 Jan 2005 22:06:53 -0000 1.3
***************
*** 31,35 ****
{
return new mlsub.typing.Polytype(constraint.resolveToLowlevel(),
! monotype.resolve(typeScope));
}
--- 31,35 ----
{
return new mlsub.typing.Polytype(constraint.resolveToLowlevel(),
! monotype.resolve(notNull(typeScope)));
}
Index: tuple.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/tuple.nice,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** tuple.nice 12 Jan 2005 18:50:38 -0000 1.3
--- tuple.nice 12 Jan 2005 22:06:54 -0000 1.4
***************
*** 23,28 ****
Location location;
! rawResolve(typeMap) = new mlsub.typing.TupleType
! (bossa.syntax.Monotype.resolve(notNull(typeMap), types.toArray()));
substitute(map)
--- 23,28 ----
Location location;
! rawResolve(tm) = new mlsub.typing.TupleType
! (resolveMonotypes(tm, types.toArray()));
substitute(map)
Index: niceclass.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/niceclass.nice,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** niceclass.nice 12 Jan 2005 20:56:30 -0000 1.17
--- niceclass.nice 12 Jan 2005 22:06:53 -0000 1.18
***************
*** 408,412 ****
List<Parameter> params = new ArrayList();
for (arg : m.getArgTypes())
! params.add(new Parameter(type: new Monotype.MonotypeWrapper(arg)));
res.add((m, params));
--- 408,412 ----
List<Parameter> params = new ArrayList();
for (arg : m.getArgTypes())
! params.add(new Parameter(type: new MonotypeWrapper(type: arg)));
res.add((m, params));
***************
*** 566,570 ****
let cname = new LocatedString("<init>",definition.location());
! let ctype = new mlsub.typing.Polytype(specificCst, new
mlsub.typing.FunType(Monotype.resolve(definition.getLocalScope(),
values.types()),sureMonotype(new
mlsub.typing.MonotypeConstructor(definition.getTC(),
definition.getTypeParameters()))));
notNull(constructorMethod)[i] = new DefaultConstructor
(cname, Node.global, parameters: values, arity: values.size,
--- 566,570 ----
let cname = new LocatedString("<init>",definition.location());
! let ctype = new mlsub.typing.Polytype(specificCst, new
mlsub.typing.FunType(resolveMonotypes(definition.getLocalScope(),
values.types()),sureMonotype(new
mlsub.typing.MonotypeConstructor(definition.getTC(),
definition.getTypeParameters()))));
notNull(constructorMethod)[i] = new DefaultConstructor
(cname, Node.global, parameters: values, arity: values.size,
Index: niceMethod.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/niceMethod.nice,v
retrieving revision 1.13
retrieving revision 1.14
diff -C2 -d -r1.13 -r1.14
*** niceMethod.nice 12 Jan 2005 20:56:30 -0000 1.13
--- niceMethod.nice 12 Jan 2005 22:06:53 -0000 1.14
***************
*** 292,297 ****
constraint.addAtom(new AtomicConstraintWrapper(atom: atom));
! thisType = new Monotype.MonotypeWrapper
! (sureMonotype
(new mlsub.typing.MonotypeConstructor
(alikeTC, c.getTypeParameters())));
--- 292,297 ----
constraint.addAtom(new AtomicConstraintWrapper(atom: atom));
! thisType = new MonotypeWrapper
! (type: sureMonotype
(new mlsub.typing.MonotypeConstructor
(alikeTC, c.getTypeParameters())));
***************
*** 308,312 ****
}
else
! thisType = new Monotype.SureMonotypeWrapper(tc, c.getTypeParameters());
params.addThis(thisType);
--- 308,312 ----
}
else
! thisType = new SureMonotypeWrapper(tc: tc, params:
c.getTypeParameters());
params.addThis(thisType);
Index: formalParameters.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/formalParameters.nice,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** formalParameters.nice 12 Jan 2005 20:56:30 -0000 1.4
--- formalParameters.nice 12 Jan 2005 22:06:53 -0000 1.5
***************
*** 254,258 ****
{
Parameter p = parameters[i].cloneParam();
! p.type = new Monotype.MonotypeWrapper(p.type.resolve(scope));
res.add(p);
}
--- 254,258 ----
{
Parameter p = parameters[i].cloneParam();
! p.type = new MonotypeWrapper(type: p.type.resolve(scope));
res.add(p);
}
Index: nicefieldaccess.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/nicefieldaccess.nice,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** nicefieldaccess.nice 12 Jan 2005 20:56:30 -0000 1.9
--- nicefieldaccess.nice 12 Jan 2005 22:06:53 -0000 1.10
***************
*** 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,
--- 46,50 ----
let argType = sureMonotype(classDef.lowlevelMonotype());
! let params = createFormalParameters([new Parameter(type: new
MonotypeWrapper(type: argType))]);
let constr = createConstraint(classDef.getBinders(), null);
let res = new NiceFieldAccess(field.getName(), Node.down,
Index: typedef.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/typedef.nice,v
retrieving revision 1.12
retrieving revision 1.13
diff -C2 -d -r1.12 -r1.13
*** typedef.nice 12 Jan 2005 20:56:30 -0000 1.12
--- typedef.nice 12 Jan 2005 22:06:54 -0000 1.13
***************
*** 333,337 ****
return null;
! return bossa.syntax.Monotype.resolve(typeScope,
cast(notNull(parent.parameters).content));
}
--- 333,337 ----
return null;
! return resolveMonotypes(typeScope,
cast(notNull(parent.parameters).content));
}
***************
*** 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])));
}
--- 406,412 ----
typeParameters[i] = mvar;
! bossa.syntax.Monotype v = new MonotypeWrapper(type: mvar);
! atoms.add(new MonotypeLeqCst(m1: new MonotypeWrapper(type: params[i]),
m2: v));
! atoms.add(new MonotypeLeqCst(m1: v, m2: new MonotypeWrapper(type:
params[i])));
}
--- Monotype.java DELETED ---
Index: symbol.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/symbol.nice,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** symbol.nice 11 Jan 2005 21:45:46 -0000 1.7
--- symbol.nice 12 Jan 2005 22:06:54 -0000 1.8
***************
*** 52,56 ****
resolve()
{
! type = notNull(syntacticType).resolve(typeScope);
syntacticType = null;
--- 52,56 ----
resolve()
{
! type = notNull(syntacticType).resolve(notNull(typeScope));
syntacticType = null;
Index: tools.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/tools.nice,v
retrieving revision 1.95
retrieving revision 1.96
diff -C2 -d -r1.95 -r1.96
*** tools.nice 12 Jan 2005 18:50:38 -0000 1.95
--- tools.nice 12 Jan 2005 22:06:54 -0000 1.96
***************
*** 235,239 ****
?gnu.expr.Declaration getDeclaration(VarSymbol) = native gnu.expr.Declaration
VarSymbol.getDeclaration();
void printInterface(ClassImplementation, java.io.PrintWriter) = native void
ClassImplementation.printInterface(java.io.PrintWriter);
- mlsub.typing.Monotype[?] resolve(TypeMap, Monotype[?]) = native
mlsub.typing.Monotype[] Monotype.resolve(TypeMap, Monotype[]);
?gnu.bytecode.Type TypeImport_lookup(LocatedString) = native
gnu.bytecode.Type nice.tools.code.TypeImport.lookup(LocatedString);
List<Node> children(Node) = native Node.children;
--- 235,238 ----
***************
*** 242,246 ****
gnu.expr.CopyArgument CopyArgument(Stack<gnu.bytecode.Variable>) = native new
gnu.expr.CopyArgument(Stack);
AST AST(List<Definition>, int) = native new AST(List, int);
- bossa.syntax.Monotype
substitute(bossa.syntax.Monotype,Map<String,bossa.syntax.Monotype>) = native
bossa.syntax.Monotype bossa.syntax.Monotype.substitute(Map);
?mlsub.typing.TypeSymbol lookup(TypeMap, LocatedString) = native
mlsub.typing.TypeSymbol TypeMap.lookup(LocatedString);
?mlsub.typing.TypeSymbol lookup(TypeMap, String) = native
mlsub.typing.TypeSymbol TypeMap.lookup(String);
--- 241,244 ----
Index: importedconstructor.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/importedconstructor.nice,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** importedconstructor.nice 12 Jan 2005 20:56:30 -0000 1.11
--- importedconstructor.nice 12 Jan 2005 22:06:53 -0000 1.12
***************
*** 96,100 ****
let classDef = def.getDefinition();
! let returnType = new Monotype.MonotypeWrapper(sureMonotype
(new mlsub.typing.MonotypeConstructor(classDef.getTC(),
classDef.getTypeParameters())));
--- 96,100 ----
let classDef = def.getDefinition();
! let returnType = new MonotypeWrapper(type: sureMonotype
(new mlsub.typing.MonotypeConstructor(classDef.getTC(),
classDef.getTypeParameters())));
-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
|