[Nice-commit] Nice/src/bossa/syntax OverloadedSymbolExp.java,1.48,1.49 CallExp.java,1.72,1.73
Brought to you by:
bonniot
From: <bo...@us...> - 2003-03-01 00:58:31
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1:/tmp/cvs-serv18080/src/bossa/syntax Modified Files: OverloadedSymbolExp.java CallExp.java Log Message: Computed expected bytecode type for actual arguments of polymorphic methods. Index: OverloadedSymbolExp.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/OverloadedSymbolExp.java,v retrieving revision 1.48 retrieving revision 1.49 diff -C2 -d -r1.48 -r1.49 *** OverloadedSymbolExp.java 25 Sep 2002 16:40:26 -0000 1.48 --- OverloadedSymbolExp.java 1 Mar 2003 00:58:28 -0000 1.49 *************** *** 174,177 **** --- 174,179 ---- { VarSymbol res = (VarSymbol) symbols.get(0); + // store the formal argument types for later use together with the type + callExp.argTypes = nice.tools.code.Types.domain(res.getClonedType()); res.releaseClonedType(); Index: CallExp.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/CallExp.java,v retrieving revision 1.72 retrieving revision 1.73 diff -C2 -d -r1.72 -r1.73 *** CallExp.java 24 Jan 2003 19:09:25 -0000 1.72 --- CallExp.java 1 Mar 2003 00:58:28 -0000 1.73 *************** *** 257,271 **** } ! /* ! If type is not monomorphic, simplification can result in ! a more precise result for the java type used in compilation. ! However, it is probably not perfect. setByteCodetype should be usefull. ! FIXME and test me with regtest case. ! */ if (! type.trySimplify()) User.warning(this, "This call might have a type error, or this might be a bug in the compiler. \nPlease contact bo...@us..."); - //Types.setBytecodeType(type); } boolean isAssignable() { --- 257,289 ---- } ! if (! type.isMonomorphic() && argTypes != null) ! { ! /* ! We construct the instantiated version of the function type: ! the type of the function, constrained by the actual arguments. ! Then we simplify it. ! It is useful to constrain the arguments to have the expected ! bytecode types. ! */ ! instanciatedType = new Polytype ! (type.getConstraint(), new FunType(argTypes, type.getMonotype())); ! instanciatedType = instanciatedType.cloneType(); ! // By default, a polytype is suppose to be simplified. ! instanciatedType.setNotSimplified(); ! instanciatedType.simplify(); ! } ! if (! type.trySimplify()) User.warning(this, "This call might have a type error, or this might be a bug in the compiler. \nPlease contact bo...@us..."); } + /** The types of the formal arguments of the function, in the same + polymorphic instance as the computed type. + */ + Monotype[] argTypes; + + /** The type of the function, constrained by the actual arguments. */ + private Polytype instanciatedType; + boolean isAssignable() { *************** *** 286,299 **** res = new gnu.expr.ApplyExp(function.generateCode(), compileParams()); ! gnu.bytecode.Type expectedType; ! if ("notNull".equals(function.toString())) ! { ! expectedType = Types.javaType(getType()); ! //System.out.println(this + ", " + res.getType() + "; " + expectedType + "^" + getType()); ! expectedType = Types.javaType(getType()); ! //System.out.println(this + ", " + res.getType() + "; " + expectedType + "^" + getType()); ! } ! expectedType = Types.javaType(getType()); ! return EnsureTypeProc.ensure(res, expectedType); } --- 304,308 ---- res = new gnu.expr.ApplyExp(function.generateCode(), compileParams()); ! return EnsureTypeProc.ensure(res, Types.javaType(type)); } *************** *** 313,316 **** --- 322,335 ---- } } + + // Make sure the arguments have the expected bytecode type, + // matching the instantiated type of the (polymorphic) function. + Monotype[] domain = null; + if (instanciatedType != null) + domain = Types.domain(instanciatedType); + if (domain != null) + for (int i = 0; i < params.length; i++) + params[i] = EnsureTypeProc.ensure + (params[i], Types.javaType(domain[i])); return params; |