[Nice-commit] Nice/src/bossa/syntax typecheck.nice,1.97,1.98 tools.nice,1.32,1.33 NiceMethod.java,1.
Brought to you by:
bonniot
From: Daniel B. <bo...@us...> - 2004-03-17 17:05:08
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19931/src/bossa/syntax Modified Files: typecheck.nice tools.nice NiceMethod.java MethodDeclaration.java Log Message: Do type inference on local bindings with polymorphic values. Index: tools.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/tools.nice,v retrieving revision 1.32 retrieving revision 1.33 diff -C2 -d -r1.32 -r1.33 *** tools.nice 25 Feb 2004 11:23:28 -0000 1.32 --- tools.nice 17 Mar 2004 16:55:34 -0000 1.33 *************** *** 66,82 **** notNull(bossa.syntax.Monotype.maybe(nice.tools.typing.Types.rawType(m))); ! mlsub.typing.Monotype checkMonomorphic(mlsub.typing.Polytype type, ! Block.LocalValue decl) { ! if (! type.isMonomorphic()) ! { ! type.simplify(); ! if (! type.isMonomorphic()) ! throw new bossa.util.UserError ! (decl, ! "The value has a polymorphic type: " + type + ! "\nOmitting the type here is not supported by Nice yet." + ! "\nPlease declare the monomorphic type of " + decl.getName()); } --- 66,79 ---- notNull(bossa.syntax.Monotype.maybe(nice.tools.typing.Types.rawType(m))); ! mlsub.typing.Monotype ensureMonomorphic(mlsub.typing.Polytype type, ! Block.LocalValue decl) { ! type.simplify(); ! if (type.getConstraint != null) ! { ! // If the type is polymorphic, we treat the type variables as soft: ! // we enter them in the context, so they are not generalized. ! type.getConstraint.enter(true); } *************** *** 84,88 **** } ! /* Make sure that the error is attached to a location. If not, located it a the given located object (which should be a close --- 81,85 ---- } ! /* Make sure that the error is attached to a location. If not, located it a the given located object (which should be a close Index: typecheck.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/typecheck.nice,v retrieving revision 1.97 retrieving revision 1.98 diff -C2 -d -r1.97 -r1.98 *** typecheck.nice 25 Feb 2004 11:23:28 -0000 1.97 --- typecheck.nice 17 Mar 2004 16:55:34 -0000 1.98 *************** *** 669,673 **** value.typecheck(); e.initValue = decl.value = value = value.noOverloading(); ! target.type = checkMonomorphic(value.getType(), decl); if (nice.tools.typing.Types.isVoid(target.type)) --- 669,673 ---- value.typecheck(); e.initValue = decl.value = value = value.noOverloading(); ! target.type = ensureMonomorphic(value.getType(), decl); if (nice.tools.typing.Types.isVoid(target.type)) *************** *** 734,738 **** value.typecheck(); decl.value = value = value.noOverloading(); ! target.type = checkMonomorphic(value.getType(), decl); if (target.type == PrimitiveType.byteType || target.type == PrimitiveType.shortType) --- 734,738 ---- value.typecheck(); decl.value = value = value.noOverloading(); ! target.type = ensureMonomorphic(value.getType(), decl); if (target.type == PrimitiveType.byteType || target.type == PrimitiveType.shortType) *************** *** 770,774 **** mlsub.typing.Polytype type = notNull(decl.value).getType(); ! notNull(decl.left).type = checkMonomorphic(type, decl); if (nice.tools.typing.Types.isVoid(notNull(decl.left).type)) throw error(decl, "A variable cannot have a void type"); --- 770,775 ---- mlsub.typing.Polytype type = notNull(decl.value).getType(); ! notNull(decl.left).type = ensureMonomorphic(type, decl); ! if (nice.tools.typing.Types.isVoid(notNull(decl.left).type)) throw error(decl, "A variable cannot have a void type"); *************** *** 1003,1006 **** // Local Variables: ! // nice-xprogram: "nicec -d \"$HOME/Nice/classes\" --sourcepath=\"$HOME/Nice/src\" --classpath=\"$HOME/Nice/classes\"" // End: --- 1004,1007 ---- // Local Variables: ! // nice-xprogram: "$HOME/Nice/bin/nicec -d ../classes" // End: Index: NiceMethod.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/NiceMethod.java,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** NiceMethod.java 17 Mar 2004 00:36:46 -0000 1.36 --- NiceMethod.java 17 Mar 2004 16:55:34 -0000 1.37 *************** *** 349,353 **** { super.innerTypecheck(); ! implementation.innerTypecheck(); } --- 349,357 ---- { super.innerTypecheck(); ! try { ! implementation.innerTypecheck(); ! } finally { ! mlsub.typing.lowlevel.Engine.existentialLevel = 0; ! } } Index: MethodDeclaration.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/MethodDeclaration.java,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -d -r1.56 -r1.57 *** MethodDeclaration.java 5 Mar 2004 16:24:26 -0000 1.56 --- MethodDeclaration.java 17 Mar 2004 16:55:34 -0000 1.57 *************** *** 211,214 **** --- 211,215 ---- } + UserError error = null; try{ Typing.enter(); *************** *** 216,220 **** try{ type.getConstraint().enter(); ! innerTypecheck(); } finally{ --- 217,226 ---- try{ type.getConstraint().enter(); ! ! try { ! innerTypecheck(); ! } catch(UserError e){ ! error = e; ! } } finally{ *************** *** 223,230 **** } catch(TypingEx e){ ! User.error(this, ! "The type of method " + symbol.name + ! " is not well formed: " + type + "\n" + e); } } --- 229,240 ---- } catch(TypingEx e){ ! // If we got an earlier error, it's preferable to report that one. ! if (error == null) ! User.error(this, ! "The type of method " + symbol.name + ! " is not well formed: " + type + "\n" + e); } + if (error != null) + throw error; } |