nice-commit Mailing List for The Nice Programming Language (Page 27)
Brought to you by:
bonniot
You can subscribe to this list here.
2003 |
Jan
|
Feb
(60) |
Mar
(125) |
Apr
(183) |
May
(140) |
Jun
(227) |
Jul
(141) |
Aug
(181) |
Sep
(75) |
Oct
(89) |
Nov
(187) |
Dec
(162) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2004 |
Jan
(69) |
Feb
(197) |
Mar
(98) |
Apr
(26) |
May
(10) |
Jun
(85) |
Jul
(88) |
Aug
(79) |
Sep
(80) |
Oct
(81) |
Nov
(53) |
Dec
(109) |
2005 |
Jan
(68) |
Feb
(77) |
Mar
(232) |
Apr
(79) |
May
(37) |
Jun
(37) |
Jul
(3) |
Aug
(18) |
Sep
|
Oct
|
Nov
|
Dec
|
2006 |
Jan
(10) |
Feb
|
Mar
(4) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
(1) |
Dec
(9) |
2007 |
Jan
(2) |
Feb
(8) |
Mar
(2) |
Apr
(5) |
May
|
Jun
|
Jul
|
Aug
(4) |
Sep
|
Oct
|
Nov
(17) |
Dec
(6) |
2008 |
Jan
|
Feb
(3) |
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2011 |
Jan
|
Feb
|
Mar
|
Apr
(1) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6256/F:/nice/src/bossa/syntax Modified Files: GlobalTypeScope.java MethodDeclaration.java Node.java analyse.nice dispatch.java.bootstrap importedconstructor.nice javaclass.nice new.nice scope.nice super.nice tools.nice typedef.nice Added Files: javaFieldAccess.nice javaMethod.nice retypedMethod.nice Removed Files: JavaClasses.java JavaConstructor.java JavaFieldAccess.java JavaMethod.java RetypedJavaMethod.java Log Message: Converted the Java* classes. (by Luc Perrin) Index: analyse.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/analyse.nice,v retrieving revision 1.118 retrieving revision 1.119 diff -C2 -d -r1.118 -r1.119 *** analyse.nice 16 Dec 2004 23:40:00 -0000 1.118 --- analyse.nice 19 Dec 2004 22:37:31 -0000 1.119 *************** *** 396,401 **** // since the method is not called but just referenced. { ! List<VarSymbol> possibilities = JavaClasses.findJavaMethods ! (e.declaringClass, funName.toString()); if (possibilities.size() == 0) --- 396,401 ---- // since the method is not called but just referenced. { ! List<VarSymbol> possibilities = findJavaMethods ! (notNull(e.declaringClass), funName.toString()); if (possibilities.size() == 0) *************** *** 418,423 **** } ! List<VarSymbol> possibilities = JavaClasses.findJavaMethods ! (e.declaringClass, funName.toString(), arity); if (possibilities.size() == 0) --- 418,423 ---- } ! List<VarSymbol> possibilities = findJavaMethods ! (notNull(e.declaringClass), funName.toString(), arity); if (possibilities.size() == 0) --- JavaMethod.java DELETED --- Index: tools.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/tools.nice,v retrieving revision 1.80 retrieving revision 1.81 diff -C2 -d -r1.80 -r1.81 *** tools.nice 19 Dec 2004 16:49:14 -0000 1.80 --- tools.nice 19 Dec 2004 22:37:32 -0000 1.81 *************** *** 209,214 **** ?gnu.bytecode.ClassType staticClass(Arguments) = native gnu.bytecode.ClassType Arguments.staticClass(); ?gnu.bytecode.ClassType staticClass(Expression) = native gnu.bytecode.ClassType Expression.staticClass(); - List<VarSymbol> findJavaMethods(?gnu.bytecode.ClassType, String, int) = native List JavaClasses.findJavaMethods(gnu.bytecode.ClassType,java.lang.String,int); - List<VarSymbol> findJavaMethods(?gnu.bytecode.ClassType, String) = native List JavaClasses.findJavaMethods(gnu.bytecode.ClassType,java.lang.String); TypeParameters TypeParameters(List<Monotype>) = native new bossa.syntax.TypeParameters(List); TypeParameters TypeParameters(Monotype[]) = native new bossa.syntax.TypeParameters(Monotype[]); --- 209,212 ---- *************** *** 288,291 **** --- 286,290 ---- Monotype[] Monotype_toArray(?List<Monotype>) = native Monotype[] Monotype.toArray(List); List<VarSymbol> lookup(VarScope, LocatedString) = native List VarScope.lookup(LocatedString); + Map<gnu.bytecode.Type,mlsub.typing.TypeConstructor> javaTypeConstructors(bossa.modules.Compilation ) = native bossa.modules.Compilation.javaTypeConstructors; // Retypings needed since java types are not strict. --- JavaConstructor.java DELETED --- Index: scope.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/scope.nice,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** scope.nice 19 Dec 2004 16:49:14 -0000 1.1 --- scope.nice 19 Dec 2004 22:37:32 -0000 1.2 *************** *** 22,26 **** { // If there is any method by that name waiting, load it. ! JavaClasses.nameRequired(i.toString()); return super; --- 22,26 ---- { // If there is any method by that name waiting, load it. ! loadJavaMethods(i.toString()); return super; Index: Node.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Node.java,v retrieving revision 1.62 retrieving revision 1.63 diff -C2 -d -r1.62 -r1.63 *** Node.java 19 Dec 2004 16:49:14 -0000 1.62 --- Node.java 19 Dec 2004 22:37:31 -0000 1.63 *************** *** 139,150 **** return globalTypeScope; } ! public static void setModule(Module module) { // For multiple compilations in the same JVM: // If we are starting a new compilation, reset the global scopes. ! if (JavaClasses.compilation != module.compilation()) { ! JavaClasses.compilation = module.compilation(); globalScope = dispatch.createGlobalVarScope(); globalTypeScope = new GlobalTypeScope(); --- 139,152 ---- return globalTypeScope; } ! ! public static bossa.modules.Compilation compilation = null; ! public static void setModule(Module module) { // For multiple compilations in the same JVM: // If we are starting a new compilation, reset the global scopes. ! if (compilation != module.compilation()) { ! compilation = module.compilation(); globalScope = dispatch.createGlobalVarScope(); globalTypeScope = new GlobalTypeScope(); Index: javaclass.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/javaclass.nice,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** javaclass.nice 25 Nov 2004 19:28:18 -0000 1.2 --- javaclass.nice 19 Dec 2004 22:37:31 -0000 1.3 *************** *** 58,62 **** User.error(definition, javaName + " has " + nativeArity + " type parameters"); ! let old = JavaClasses.setTypeConstructorForJavaClass (definition.compilation(), definition.getTC(), classType); --- 58,62 ---- User.error(definition, javaName + " has " + nativeArity + " type parameters"); ! let old = setTypeConstructorForJavaClass (definition.compilation(), definition.getTC(), classType); *************** *** 72,76 **** return; ! JavaClasses.fetchMethods(definition.getTC(), cast(definition.getJavaType())); } --- 72,76 ---- return; ! fetchMethods(definition.getTC(), cast(definition.getJavaType())); } *************** *** 80,81 **** --- 80,269 ---- } } + + + /** + * Returns a java type constructor with the given name + * and the given java type. + * <p> + * Usefull for primitive types. + */ + TypeConstructor makeJavaClass(bossa.modules.Compilation compilation, String name, + gnu.bytecode.Type javaType) + { + ?TypeConstructor tc = compilation.javaTypeConstructors.get(javaType); + if(tc!=null) + return tc; + + // we put the new JTC in the hashtable in the constructor + // and not after it returned, to avoid infinite loop + // if the code of the constructor does a lookup. + return createJavaType(compilation, name, javaType); + } + + /** + * @return null, except if javaName already had an + * associated TypeConstructor in which case it is returned. + */ + ?TypeConstructor setTypeConstructorForJavaClass + (bossa.modules.Compilation compilation, TypeConstructor tc, gnu.bytecode.Type type) = + compilation.javaTypeConstructors.put(type, tc); + + let gnu.bytecode.Type[] blackListClass = [ + gnu.bytecode.ClassType.make("java.lang.Object")]; + + let gnu.bytecode.Type[] blackListInterface = [ + gnu.bytecode.ClassType.make("java.io.Serializable"), + gnu.bytecode.ClassType.make("java.lang.Cloneable"), + gnu.bytecode.ClassType.make("java.lang.Comparable")]; + + boolean excludedClass(gnu.bytecode.Type[] blackList, gnu.bytecode.Type classType) + { + for (int i=0; i<blackList.length; i++) + if (classType==blackList[i]) + return true; + return false; + } + + boolean excludedInterface(TypeConstructor itf) + { + ?gnu.bytecode.Type t = nice.tools.code.Types.get(itf); + if (t == null) + return false; + + return excludedClass(blackListInterface, t); + } + + TypeConstructor createJavaType(bossa.modules.Compilation compilation, String className, + gnu.bytecode.Type javaType) + { + if (bossa.util.Debug.javaTypes) + bossa.util.Debug.println("Registering java class "+className); + + // as the tc is not introduced, it should not be set instantiable + // (thus used at link test with an error) + // these late TCs should be avoided + boolean instantiable = !Typing.isInRigidContext() && instantiable(javaType); + + TypeConstructor res = new TypeConstructor(className, null, instantiable, true); + + let old = compilation.javaTypeConstructors.put(javaType, res); + if (old != null) + User.error(old + " was already associated with the Nice class " + old); + + nice.tools.code.Types.set(res, javaType); + + if(Typing.isInRigidContext()) + // We should not add new classes at this point. + // It doesn't matter, as this type is not used explicitely. + { + Internal.warning(className + " added late"); + + setArity(res, 0); + return res; + } + + Typing.introduce(res); + + // Recursive search for java super-classes + if (javaType instanceof gnu.bytecode.ClassType) + { + let classType = javaType; + + int arity = classType.getArity(); + if (arity != -1) + setArity(res, classType.getArity()); + + ?gnu.bytecode.ClassType superClass = classType.getSuperclass(); + + if (superClass!=null && !(excludedClass(blackListClass, superClass))) + { + try { + TypeConstructor superTC = nice.tools.code.Types.typeConstructor(superClass); + Typing.initialLeq(res, superTC); + } + catch(TypingEx e) { + Internal.warning("Invalid java super-class "+superClass+" for "+className); + } + catch(nice.tools.code.Types.NotIntroducedClassException e) { + Internal.warning(res + " extends " + superClass + ", which is not usable"); + } + } + + gnu.bytecode.ClassType[?] itfs = null; + try { + itfs = classType.getInterfaces(); + } + catch(NoClassDefFoundError ex) { + User.warning("Interface " + ex.getMessage() + + " implemented by " + classType.getName() + + " was not found in classpath"); + } + + if (itfs!=null) + for (gnu.bytecode.ClassType itf : itfs) + { + if (excludedClass(blackListInterface, itf)) + continue; + + try { + TypeConstructor superTC = nice.tools.code.Types.typeConstructor(itf); + Typing.initialLeq(res, superTC); + } + catch(TypingEx e) { + Internal.warning(res+" cannot implement " + itf /* + ": " + e.toString()*/); + } + catch(nice.tools.code.Types.NotIntroducedClassException e) { + Internal.warning(res + " implements " + itf + ", which is not usable"); + } + } + + // The default arity is 0. + if (res.getKind() == null) + setArity(res, 0); + + if (classType.isFinal()) + res.setMinimal(); + } + + if (javaType instanceof gnu.bytecode.ClassType) + fetchMethods(res, javaType); + + return res; + } + + void setArity(TypeConstructor tc, int arity) + { + try { + Variance variance = arity == 0 ? + Variance.empty() : Variance.make(new int[arity]); + mlsub.typing.lowlevel.Engine.setKind(tc, variance.getConstraint()); + } + catch(mlsub.typing.lowlevel.Unsatisfiable ex) { + User.error("Java class " + tc + " cannot have arity " + arity); + } + } + + boolean instantiable(gnu.bytecode.Type javaType) + { + if (!(javaType instanceof gnu.bytecode.ClassType)) + return false; + + return (javaType.getModifiers() + & (gnu.bytecode.Access.ABSTRACT| + gnu.bytecode.Access.INTERFACE)) == 0; + } + + ?TypeConstructor lookupJavaClass(String className, Location loc) + { + ?gnu.bytecode.Type classType = nice.tools.code.TypeImport.lookup(className, loc); + + if (classType == null) + return null; + + bossa.modules.Compilation compilation = notNull(Node.compilation); + + if (compilation.javaTypeConstructors.containsKey(classType)) + return compilation.javaTypeConstructors.get(classType); + + return createJavaType(compilation, classType.getName(), classType); + } --- JavaFieldAccess.java DELETED --- --- NEW FILE: javaMethod.nice --- /**************************************************************************/ /* N I C E */ /* A high-level object-oriented research language */ /* (c) Daniel Bonniot 2004 */ /* */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License, or */ /* (at your option) any later version. */ /* */ /**************************************************************************/ package bossa.syntax; import bossa.util.*; /** A Native Java Method. */ public class JavaMethod extends MethodDeclaration { ?gnu.bytecode.Method reflectMethod = null; boolean registered = false; { if (this.reflectMethod != null) this.registerForDispatch(); } isJavaMethod() = true; getReflectMethod() = notNull(reflectMethod); /** @return a string that uniquely represents this method */ getFullName() { return "JAVA:" + name + ':' + this.getType(); } gnu.expr.LambdaExp getLambda() = nice.tools.code.Gen.dereference(this.getCode()); javaReturnType() { let reflectMethod = this.reflectMethod; assert reflectMethod != null; return reflectMethod.getReturnType(); } javaArgTypes() { let reflectMethod = this.reflectMethod; assert reflectMethod != null; return reflectMethod.getParameterTypes(); } computeCode() = new gnu.expr.QuoteExp(new gnu.expr.PrimProcedure(notNull(this.reflectMethod))); getCode() = nice.tools.code.Gen.wrapInLambda(new gnu.expr.PrimProcedure(notNull(this.reflectMethod))); printInterface(w) { Internal.error("Automatic java methods should not be exported"); } registerForDispatch() { if (this.registered) return; bossa.link.DispatchTest.register(this); this.registered = true; } } new JavaMethod( LocatedString name, mlsub.typing.Polytype type, gnu.bytecode.Method reflectMethod ) { this( name, null, type, reflectMethod : reflectMethod ); } /** A Java constructor method. */ class JavaConstructor extends JavaMethod { computeCode() = new gnu.expr.QuoteExp(new gnu.expr.InstantiateProc(notNull(this.reflectMethod))); getConstructorInvocation(omitDefaults) = new gnu.expr.QuoteExp(new gnu.expr.InitializeProc(this.reflectMethod)); } ?JavaMethod makeJavaMethod(gnu.bytecode.Method m, boolean constructor) { ?mlsub.typing.Polytype type = nice.tools.code.Import.type(m); // We could not turn the bytecode type into a Nice type. if (type == null) return null; if (constructor) return new JavaConstructor( new LocatedString("new " + m.getDeclaringClass().getName(), Location.nowhere()), type, m); else return new JavaMethod(new LocatedString(m.getName(), Location.nowhere()), type, m); } /** * Remember known methods, by name. */ let Map<String,List<gnu.bytecode.Method>> knownMethods = new HashMap(); void registerMethod(gnu.bytecode.Method m) { ?List<gnu.bytecode.Method> methods = knownMethods.get(m.getName()); if (methods == null) knownMethods.put( m.getName(), methods = new ArrayList() ); assert methods != null; methods.add(m); } /** Utility function for analyse.nice */ /** * Returns a list of static java methods that match a given name. */ List<VarSymbol> findJavaMethods(gnu.bytecode.ClassType declaringClass, String funName) = findJavaMethods(declaringClass, funName, -1); /** * Returns a list of java methods that match the name and arity. * If arity == -1, the arity does not matter, and the method or field must be static. */ List<VarSymbol> findJavaMethods(gnu.bytecode.ClassType declaringClass, String funName, int arity) { List<VarSymbol> possibilities = new LinkedList(); declaringClass.addMethods(); // search methods for (?gnu.bytecode.Method method = declaringClass.getMethods(); method != null; method = method.next) { if (!method.getName().equals(funName)) continue; if (arity == -1 && !method.getStaticFlag()) continue; if (arity >= 0 && notNull(method.arg_types).length + ( method.getStaticFlag() ? 0 : 1 ) != arity ) continue; ?MethodDeclaration md = retyped.get(method); if (md != null || ( md = makeJavaMethod(method, false ) ) != null ) possibilities.add(notNull(md).getSymbol()); else if( bossa.util.Debug.javaTypes ) bossa.util.Debug.println("Method " + method + " ignored"); } // search a field if (arity <= 0) findStaticJavaFields(declaringClass, funName, possibilities); return possibilities; } /** * Search recursively in superclasses and interfaces for static java fields. */ void findStaticJavaFields (gnu.bytecode.ClassType declaringClass, String fieldName, List<VarSymbol> possibilities) { declaringClass.addMethods(); ?gnu.bytecode.Field field = declaringClass.getField(fieldName); if (field != null && field.getStaticFlag()) { ?MethodDeclaration md = retyped.get(field); if (md != null || (md = makeJavaFieldAccess(field)) != null) { assert md != null; if (!possibilities.contains(md.getSymbol())) { possibilities.add(md.getSymbol()); return; } } else if(bossa.util.Debug.javaTypes) bossa.util.Debug.println("Field " + field + " ignored"); } ?gnu.bytecode.ClassType superClass = declaringClass.getSuperclass(); if (superClass != null) findStaticJavaFields(superClass, fieldName, possibilities); gnu.bytecode.ClassType[?] interfaces = declaringClass.getInterfaces(); if (interfaces != null) for (gnu.bytecode.ClassType itf : interfaces) findStaticJavaFields(itf, fieldName, possibilities); } /** * Loads the methods defined in the java class * to make them available to the nice code. */ void fetchMethods(TypeConstructor tc, gnu.bytecode.ClassType classType) { try { classType.addMethods(); for (?gnu.bytecode.Field f = classType.getFields(); f != null; f = f.next) if (retyped.get(f) == null) addJavaSymbol(f, makeJavaFieldAccess(f)); for (?gnu.bytecode.Method m = classType.getMethods(); m != null; m = m.next) { // Ignore the method if it is explicitely retyped if (retyped.get(m) != null) continue; fetchMethod(m, tc, classType); } } catch(NoClassDefFoundError e) { User.warning("Class " + e.getMessage().replace('/','.') + " was not found.\n" + "It is refered to in class " + classType.getName() + "\nYou probably need to install the corresponding package."); } catch (ClassFormatError e) { User.warning("Class " + classType.getName() + " has an invalid bytecode format"); } } void fetchMethod(gnu.bytecode.Method m, TypeConstructor tc, gnu.bytecode.ClassType classType) { if (m.isConstructor()) { let res = makeJavaMethod(m, true); assert res != null; TypeConstructors.addConstructor(tc, res); retyped.put(m, res); } else { /* We don't need to put static methods in the global scope. They can and must be accessed by specifying the class explicitely, like in Java. */ if (m.getStaticFlag()) return; ?gnu.bytecode.Method base = findBaseMethod(classType, m); if (base != null) return; registerMethod(m); } } ?gnu.bytecode.Method alreadyHasMethod(gnu.bytecode.ClassType c, gnu.bytecode.Method m) = c.getMethod(m.getName(), m.getParameterTypes()); private ?gnu.bytecode.Method findBaseMethod(gnu.bytecode.ClassType classType, gnu.bytecode.Method m) { ?gnu.bytecode.Method res = null; /* Skips m if it was just overriden in classType but declared in a superclass or superinterface. */ ?gnu.bytecode.ClassType superClass = classType.getSuperclass(); /* If the super class is null, the current class is an interface. We consider that interfaces do not declare new methods if they also belong to Object. For instance, java.lang.CharSequence in JDK 1.4 declares toString. */ if (superClass == null) superClass = gnu.bytecode.Type.pointer_type; assert superClass != null; // Typechecker limitation res = alreadyHasMethod(superClass,m); if (res != null) return res; for (gnu.bytecode.ClassType itf : classType.getInterfaces()) { res = alreadyHasMethod(itf,m); if (res != null) return res; } return null; } /** Called when the given name is going to be needed. */ void loadJavaMethods(String name) { ?List<gnu.bytecode.Method> methods = knownMethods.get(name); if (methods == null) return; knownMethods.remove(name); for (gnu.bytecode.Method m : methods) { if (bossa.util.Debug.javaTypes) bossa.util.Debug.println("Loaded native method " + m); if (retyped.get(m) != null) continue; addJavaSymbol(m, makeJavaMethod(m, false)); } } void addJavaSymbol(gnu.bytecode.AttrContainer m, ?MethodDeclaration def) { if (def == null || Node.getGlobalScope() == null) return; Node.getGlobalScope().addSymbol(def.getSymbol()); retyped.put(m, def); } var ?JavaMethod javaObjectConstructor = null; void resetJavaClasses() { retyped.clear(); knownMethods.clear(); javaObjectConstructor = null; } JavaMethod getJavaObjectConstructor() { if (javaObjectConstructor == null) javaObjectConstructor = makeJavaMethod(getDeclaredMethod(notNull(gnu.bytecode.Type.pointer_type),"<init>", 0), true); return notNull(javaObjectConstructor); } Index: GlobalTypeScope.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/GlobalTypeScope.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** GlobalTypeScope.java 13 Dec 2003 14:51:48 -0000 1.8 --- GlobalTypeScope.java 19 Dec 2004 22:37:17 -0000 1.9 *************** *** 102,106 **** return res; ! return JavaClasses.lookup(name, loc); } --- 102,106 ---- return res; ! return dispatch.lookupJavaClass(name, loc); } --- NEW FILE: retypedMethod.nice --- /**************************************************************************/ /* N I C E */ /* A high-level object-oriented research language */ /* (c) Daniel Bonniot 2004 */ /* */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License, or */ /* (at your option) any later version. */ /* */ /**************************************************************************/ package bossa.syntax; /** A Java method which is explicitely given a more precise type in the Nice source program. */ public class RetypedJavaMethod extends JavaMethod { LocatedString className; String methodName; List<LocatedString> javaTypes; boolean ignoredRetyping = false; private ?gnu.bytecode.Type javaRetType = null; private gnu.bytecode.Type[?] javaArgType = null; buildScope(outer, typeOuter) { // We put this here, since we need 'module' to be computed // since it is used to open the imported packages. this.findReflectMethod(); super; } isIgnored() = ignoredRetyping; private ?gnu.bytecode.Type type(LocatedString s) { ?gnu.bytecode.Type res = nice.tools.code.Types.type(s); if(res == null && !ignoredRetyping) this.setIgnoredRetyping(s, "Ignoring retyping because java class " + s + " is not known"); return res; } javaReturnType() = notNull(javaRetType); javaArgTypes() = notNull(javaArgType); private void findReflectMethod() { if (this.reflectMethod != null) return; ?gnu.bytecode.Type holderType = nice.tools.code.TypeImport.lookup(className); if (holderType == null) { this.setIgnoredRetyping(this, "Ignoring retyping because class " + className + " was not found"); javaArgType = cast(new Type[javaTypes.size()-1]); return; } if (!(holderType instanceof gnu.bytecode.ClassType)) { User.error(className, className + " is a primitive type"); return; } gnu.bytecode.ClassType holder = holderType; this.className = new LocatedString(holder.getName(), className.location()); gnu.bytecode.Type[?] javaArgType = this.javaArgType = cast( new gnu.bytecode.Type[javaTypes.size()-1].fill( int i => { LocatedString t = javaTypes.get(i+1); let res = this.type(t); if (res != null) // set the fully qualified name back javaTypes.set(i+1, new LocatedString(res.getName(), t.location())); return res; } ) ); let retTypeString = javaTypes.get(0); this.javaRetType = this.type(retTypeString); if (ignoredRetyping) return; // set the fully qualified name of the return type back javaTypes.set(0, new LocatedString(notNull(this.javaRetType).getName(), retTypeString.location())); assert javaArgType != null; this.reflectMethod = holder.getDeclaredMethod(methodName, javaArgType); if (this.reflectMethod == null) { try { this.reflectMethod = holder.getDeclaredMethod(methodName, javaArgType.length); } catch (Error e) { this.setIgnoredRetyping(this, "Ignored retyping because no declaration exist with " + javaArgType.length + " arguments"); } if (this.reflectMethod == null) { if (methodName.equals("<init>")) this.setIgnoredRetyping(className, "Ignored retyping because class " + holder.getName() + " has no constructor with " + javaArgType.length + " arguments"); else this.setIgnoredRetyping(className, "Ignored retyping because no method named " + methodName + " with " + javaArgType.length + " arguments was found in class " + holder.getName()); return; } this.setIgnoredRetyping(className, "Ignored retyping because the types of the arguments don't match the declaration:\n" + reflectMethod); } // use the following, or the Type.flushTypeChanges() in SpecialTypes //reflectMethod.arg_types = javaArgType; //if(!methodName.equals("<init>")) //reflectMethod.return_type = javaRetType; let reflectMethod = this.reflectMethod; assert reflectMethod != null; if (reflectMethod.isConstructor()) { try { ?mlsub.typing.TypeConstructor tc = nice.tools.code.Types.typeConstructor(holder); if (tc != null) { TypeConstructors.addConstructor(tc, this); registerNativeConstructor(this, reflectMethod, tc); } } catch(nice.tools.code.Types.NotIntroducedClassException ex) {} } else registerNativeMethod(this, reflectMethod); int javaArity; if (reflectMethod.getStaticFlag() || reflectMethod.isConstructor()) javaArity = javaTypes.size()-1; else javaArity = javaTypes.size(); if (javaTypes != null && javaArity != arity) User.error(this, "Native method " + this.getSymbol().name + " has not the same number of parameters " + "in Java (" + javaArity + ") and in Nice (" + arity + ")"); } typedResolve() { if (this.ignoredRetyping) return; super; } void setIgnoredRetyping(Located loc, String message) { if (!this.inInterfaceFile()) User.warning(loc, message); this.ignoredRetyping = true; bossa.link.DispatchTest.unregister(this); } getConstructorInvocation(omitDefaults) { return new gnu.expr.QuoteExp(new gnu.expr.InitializeProc(reflectMethod)); } printInterface(s) { if (this.ignoredRetyping) return; s.print(this.toString() + " = native " + (this.methodName.equals("<init>") ? "new " + this.className : this.javaTypes.get(0) + " " + this.className + "." + this.methodName) + this.mapJavaArgTypes() + ";\n"); } private String mapJavaArgTypes() { let javaArgType = this.javaArgType; if (javaArgType == null) return "((NULL))"; String res = "("; for (int n = 0; n<javaArgType.length; n++) { if (n != 0) res += ", "; if (javaArgType[n] == null) res += this.javaTypes.get(n+1); else res += javaArgType[n].getName(); } return res + ")"; } } RetypedJavaMethod createRetypedJavaMethod( LocatedString className, String methodName, List<LocatedString> javaTypes, // Nice information LocatedString name, Constraint constraint, Monotype returnType, FormalParameters parameters) { return new RetypedJavaMethod(name, constraint, returnType, parameters, className: className, methodName: methodName, javaTypes: javaTypes); } /** * Remembers native methods and fields explicitly bound with a new type. * Also store implicit method and fields (automatically fetched from the * bytecode), so that they can be discarded if an explicit retyping * is found later. */ let Map<gnu.bytecode.AttrContainer,MethodDeclaration> retyped = new HashMap(); void registerNativeMethod(RetypedJavaMethod m, gnu.bytecode.Method reflectMethod) { ?MethodDeclaration auto = retyped.put(reflectMethod, m); /* If auto is a RetypedJavaMethod, we are explicitely declaring two methods for the same native method. This is useful to give it several incomparable types. Otherwise, auto is an implicit java method, and we discard it in favor of the new explicit one. */ if (auto != null && ! (auto instanceof RetypedJavaMethod)) removeFromScope(auto); } void registerNativeConstructor(RetypedJavaMethod m, gnu.bytecode.Method reflectMethod, TypeConstructor classe) { ?MethodDeclaration auto = retyped.put(reflectMethod, m); /* If auto is a RetypedJavaMethod, we are explicitely declaring two constructors for the same native constructor. This is useful to give it several incomparable types. Otherwise, auto is an implicit java constructor, and we discard it in favor of the new explicit one. */ if (auto != null && ! (auto instanceof RetypedJavaMethod)) TypeConstructors.removeConstructor(classe, auto); } void registerNativeField(JavaFieldAccess f, gnu.bytecode.Field reflectField) { ?MethodDeclaration auto = retyped.put(reflectField, f); if (auto != null) removeFromScope(auto); } private void removeFromScope(MethodDeclaration m) { Node.getGlobalScope().removeSymbol(m.getSymbol()); bossa.link.DispatchTest.unregister(m); } Index: typedef.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/typedef.nice,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** typedef.nice 18 Dec 2004 19:41:01 -0000 1.6 --- typedef.nice 19 Dec 2004 22:37:32 -0000 1.7 *************** *** 275,279 **** if (ji != null) for (int i = 0; i < ji.length; i++) ! if (tc.arity() == 0 || ! JavaClasses.excludedInterface(ji[i])) try { Typing.initialLeq(tc, ji[i]); --- 275,279 ---- if (ji != null) for (int i = 0; i < ji.length; i++) ! if (tc.arity() == 0 || ! excludedInterface(ji[i])) try { Typing.initialLeq(tc, ji[i]); Index: new.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/new.nice,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** new.nice 4 Dec 2004 19:38:18 -0000 1.8 --- new.nice 19 Dec 2004 22:37:31 -0000 1.9 *************** *** 78,82 **** private void setObject() { ! JavaMethod method = JavaClasses.getObjectConstructor(); function = createSymbolExp(method.getSymbol(), ti.location()); --- 78,82 ---- private void setObject() { ! JavaMethod method = getJavaObjectConstructor(); function = createSymbolExp(method.getSymbol(), ti.location()); Index: MethodDeclaration.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/MethodDeclaration.java,v retrieving revision 1.64 retrieving revision 1.65 diff -C2 -d -r1.64 -r1.65 *** MethodDeclaration.java 19 Dec 2004 19:58:28 -0000 1.64 --- MethodDeclaration.java 19 Dec 2004 22:37:17 -0000 1.65 *************** *** 129,132 **** --- 129,147 ---- } + public boolean isJavaMethod() + { + return false; + } + + // Overriden in JavaMethod + public gnu.bytecode.Method getReflectMethod() + { + return null; + } + + // Overriden in JavaMethod + public void registerForDispatch() + { } + /**************************************************************** * Typechecking --- NEW FILE: javaFieldAccess.nice --- /**************************************************************************/ /* N I C E */ /* A high-level object-oriented research language */ /* (c) Daniel Bonniot 2000 */ /* */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License, or */ /* (at your option) any later version. */ /* */ /**************************************************************************/ package bossa.syntax; /** A native java field access. */ public class JavaFieldAccess extends FieldAccess { private ?gnu.bytecode.Field field = null; /** The java class this method is defined in */ LocatedString className; String fieldName; isFinal() = notNull(this.field).isFinal(); isStatic() = notNull(this.field).isStatic(); { let field = this.field; if (field != null) this.fieldDecl = new gnu.expr.Declaration(field.getName(), field); } buildScope(outer, typeOuter) { super; // We put this here, since we need 'module' to be computed // since it is used to open the imported packages. // The registration must be done before resolution. if (this.field == null) { let field = this.field = this.getField(className,fieldName); if (field == null) User.error(this, "Field "+fieldName+" not found in class "+className); else { if (field.getStaticFlag()) { if (arity != 0) User.error(name, name + " should have no parameters"); } else { if (arity != 1) User.error(name, name + " should have exactly one parameter"); } registerNativeField(this, field); } } this.fieldDecl = new gnu.expr.Declaration(fieldName, field); } ?gnu.bytecode.Field getField(LocatedString javaClass, String name) { ?gnu.bytecode.ClassType c = null; try { let type = nice.tools.code.Types.type(javaClass); if (type instanceof gnu.bytecode.ClassType) { c = type; assert c != null; // Typechecker limitation // remembers the fully qualified name className.content = c.getName(); for (?gnu.bytecode.Field f = c.getFields(); f != null; f = f.next ) if (name.equals(f.getName())) return f; } else User.error(javaClass,"Class " + javaClass + " not found"); } catch(ClassCastException e) { User.error(javaClass, javaClass + " is a primitive type, it has no field"); } return null; } printInterface(s) { s.print(this.toString() + "\n"); } toString() = super + " = native " + this.className + "." + (this.field==null ? this.fieldName : notNull(this.field).getName()) + ";"; } new JavaFieldAccess(LocatedString className,String fieldName, LocatedString name,Constraint cst, Monotype returnType, FormalParameters parameters) { this(name, cst, parameters, returnType, className : className, fieldName : fieldName ); } new JavaFieldAccess(gnu.bytecode.Field field, mlsub.typing.Monotype[?] parameters) { this( new LocatedString(field.getName(), Location.nowhere()), null, parameters, nice.tools.code.Types.monotype(field.getType(), field.isFinal()), field : field, className : new LocatedString(field.getDeclaringClass().getName(), Location.nowhere()), fieldName : field.getName() ); } ?MethodDeclaration makeJavaFieldAccess(gnu.bytecode.Field f) { try { mlsub.typing.Monotype[?] params; if (!f.getStaticFlag()) { params = [nice.tools.code.Types.monotype(f.getDeclaringClass(), true)]; } else params = null; JavaFieldAccess res = new JavaFieldAccess(f, params); if (bossa.util.Debug.javaTypes) bossa.util.Debug.println("Loaded field " + res); return res; } catch(nice.tools.code.Types.ParametricClassException e) { return null; } catch(nice.tools.code.Types.NotIntroducedClassException e){ return null; } } Index: super.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/super.nice,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** super.nice 25 Nov 2004 19:28:19 -0000 1.4 --- super.nice 19 Dec 2004 22:37:32 -0000 1.5 *************** *** 181,187 **** } ! public ?gnu.bytecode.Method getImplementationAbove(JavaMethod decl, gnu.bytecode.ClassType firstArg) { ! let thisMethod = decl.reflectMethod; let superClass = firstArg.getSuperclass(); if (superClass == null) --- 181,187 ---- } ! public ?gnu.bytecode.Method getImplementationAbove(MethodDeclaration /* JavaMethod */ decl, gnu.bytecode.ClassType firstArg) { ! let thisMethod = decl.getReflectMethod(); let superClass = firstArg.getSuperclass(); if (superClass == null) Index: importedconstructor.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/importedconstructor.nice,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** importedconstructor.nice 14 Dec 2004 22:49:12 -0000 1.3 --- importedconstructor.nice 19 Dec 2004 22:37:31 -0000 1.4 *************** *** 106,110 **** constraint, returnType, FormalParameters.readBytecodeAttribute(attr, ! notNull(JavaClasses.compilation).parser), classe: def, isDefault: gnu.bytecode.Attribute.get(method, "default") != null, method: method); --- 106,110 ---- constraint, returnType, FormalParameters.readBytecodeAttribute(attr, ! notNull(Node.compilation).parser), classe: def, isDefault: gnu.bytecode.Attribute.get(method, "default") != null, method: method); Index: dispatch.java.bootstrap =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/dispatch.java.bootstrap,v retrieving revision 1.39 retrieving revision 1.40 diff -C2 -d -r1.39 -r1.40 *** dispatch.java.bootstrap 19 Dec 2004 16:49:14 -0000 1.39 --- dispatch.java.bootstrap 19 Dec 2004 22:37:31 -0000 1.40 *************** *** 13,16 **** --- 13,23 ---- public class dispatch { + public static void loadJavaMethods(String name) {} + + public static mlsub.typing.TypeConstructor lookupJavaClass(String className, bossa.util.Location loc) + { return null; } + + public static void resetJavaClasses() {} + static VarScope createGlobalVarScope() { return null; } *************** *** 49,53 **** { return null; } ! public static gnu.bytecode.Method getImplementationAbove(JavaMethod decl, gnu.bytecode.ClassType firstArg) { return null; } --- 56,60 ---- { return null; } ! public static gnu.bytecode.Method getImplementationAbove(MethodDeclaration decl, gnu.bytecode.ClassType firstArg) { return null; } --- JavaClasses.java DELETED --- --- RetypedJavaMethod.java DELETED --- |
From: Arjan B. <ar...@us...> - 2004-12-19 19:58:41
|
Update of /cvsroot/nice/Nice/src/bossa/modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4526/F:/nice/src/bossa/modules Modified Files: Package.java Log Message: Converted NiceMethod. Index: Package.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/modules/Package.java,v retrieving revision 1.126 retrieving revision 1.127 diff -C2 -d -r1.126 -r1.127 *** Package.java 19 Dec 2004 00:28:29 -0000 1.126 --- Package.java 19 Dec 2004 19:58:26 -0000 1.127 *************** *** 775,779 **** } ! public gnu.expr.Expression getDispatchMethod(NiceMethod def) { String name = def.getName().toString(); --- 775,779 ---- } ! public gnu.expr.Expression getDispatchMethod(UserOperator/*NiceMethod*/ def) { String name = def.getName().toString(); |
From: Arjan B. <ar...@us...> - 2004-12-19 19:58:40
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4526/F:/nice/src/bossa/syntax Modified Files: MethodDeclaration.java Module.java UserOperator.java defaultMethod.nice Added Files: niceMethod.nice Removed Files: NiceMethod.java Log Message: Converted NiceMethod. --- NEW FILE: niceMethod.nice --- /**************************************************************************/ /* N I C E */ /* A simple imperative object-oriented research language */ /* (c) Daniel Bonniot 2004 */ /* */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License, or */ /* (at your option) any later version. */ /* */ /**************************************************************************/ package bossa.syntax; import bossa.util.*; /** A method defined in Nice. */ public class NiceMethod extends UserOperator { private boolean isOverride; private bossa.util.Location returnTypeLocation = Location.nowhere(); private ?List<VarSymbol> homonyms = null; private ?List<MethodDeclaration> specializedMethods = null; { bossa.link.DispatchTest.register(this); } isMain() { return name.toString().equals("main") && arity==1 && this.getType().domain()[0].toString().equals("java.lang.String[]"); } resolve() { super; // In interface files, we can assume that if the method overrides // any other known method, there is an explicit override keyword. // So we can avoid looking for specializations when there isn't one. if (isOverride || ! module.interfaceFile()) { homonyms = Node.getGlobalScope().lookup(this.getName()); if (notNull(homonyms).size() == 1) homonyms = null; else notNull(homonyms).remove(this.getSymbol()); } } typedResolve() { this.findSpecializedMethods(); if (isOverride && specializedMethods == null) User.error(this, "This method does not override any other method"); if (! this.inInterfaceFile() && ! isOverride && specializedMethods != null) { let parent = notNull(specializedMethods)[0]; boolean sameResult = this.getReturnType().toString().equals(parent.getReturnType().toString()); if (sameResult) User.warning(this, "This method overrides " + parent + "\nYou should make this explicit, either by omitting the return type" + "\nor by using the 'override' keyword"); else User.warning(this, "This method overrides " + parent + "\nYou should make this explicit by using the 'override' keyword"); } super; } listSpecializedMethods() { return specializedMethods == null ? null : notNull(specializedMethods).iterator(); } specializesMethods() = specializedMethods != null; private void findSpecializedMethods() { if (homonyms == null) return; mlsub.typing.Domain ourDomain = nice.tools.typing.Types.domain(this.getType()); for (s : notNull(homonyms)) { let d = s.getMethodDeclaration(); // Ignore non-methods. if (d == null || d.isIgnored()) continue; // Check that we have the same number of arguments if (d.getArity() != this.getArity()) continue; mlsub.typing.Domain itsDomain = nice.tools.typing.Types.domain(s.getType()); // Do we have a smaller domain? if (! (mlsub.typing.Typing.smaller(ourDomain, itsDomain, true)) || nice.tools.typing.Types.typeParameterDispatch(this.getType(), s.getType())) { // If the method is imported, // check if the reverse relation holds with that method if (d.module != null && d.module.interfaceFile() && mlsub.typing.Typing.smaller(itsDomain, ourDomain, true) && ! nice.tools.typing.Types.typeParameterDispatch(s.getType(), this.getType())) { if (! nice.tools.typing.Types.covariantSpecialization(s.getType(), this.getType())) User.error (returnTypeLocation!=null ? returnTypeLocation : this.location(), "The return type should be less precise than the return type of method\n" + d + "\ndefined in:\n" + d.location()); // d is a specialized version of this. if (d instanceof NiceMethod) d.addSpecializedMethod(this); // Therefore, all its implementations also belong to this. bossa.link.Alternative.addAll(d, this); } continue; } // In a compiled package, we don't need checking. if (module.interfaceFile()) { this.addSpecializedMethod(d); continue; } if (! nice.tools.typing.Types.covariantSpecialization(this.getType(), s.getType())) { User.error (returnTypeLocation != null ? returnTypeLocation : this.location(), "The return type is less precise than the original return type of method\n" + d + "\ndefined in:\n" + d.location()); } // Check if we are a proper specialization, or if we actually have // the same domain. if (mlsub.typing.Typing.smaller(itsDomain, ourDomain)) { if (module == d.module) User.error(this, "This method has a domain identical to " + d + ", which is defined at " + d.location()); else // Methods with identical domains in different packages are // accepted, but they do not specialize each other. // They can be refered to unambiguously by using their // fully qualified name. continue; } this.addSpecializedMethod(d); } homonyms = null; } private void addSpecializedMethod(MethodDeclaration method) { if (specializedMethods == null) specializedMethods = new ArrayList(5); notNull(specializedMethods).add(method); } /** @return a string that uniquely represents this method */ getFullName() = module.getName() + '.' + name + ':' + this.getType(); computeCode() = module.getDispatchMethod(this); getLambda() = nice.tools.code.Gen.dereference(this.getCode()); compile() {} printInterface(s) { if (specializedMethods != null) s.print("override "); s.print(this.toString() + ";\n"); } } public NiceMethod createNiceMethod(LocatedString name, Constraint constraint, Monotype returnType, FormalParameters parameters, Contract contract, boolean isOverride) { let res = new NiceMethod(name, constraint, returnType, parameters, contract, isOverride: isOverride, returnTypeLocation: returnType.location()); return res; } /** The method is a class or interface member. @param c the class this method belongs to. @param name the name of the method @param typeParams the type parameters @param constraint the constraint @param returnType the return type @param params the MonoTypes of the parameters @param body the body of the function, or null if this is a real method */ public Definition createMemberMethod (MethodContainer c, LocatedString name, Constraint constraint, Monotype returnType, FormalParameters params, Statement body, Contract contract, boolean isOverride) { // it is a class method, there is an implicit "this" argument boolean hasAlike = returnType.containsAlike() || params.containsAlike(); let thisConstraint = c.classConstraint; mlsub.typing.TypeSymbol[?] thisBinders = c.getBinders(); int thisBindersLen = (thisBinders == null ? 0 : thisBinders.length); mlsub.typing.TypeSymbol container = c.getTypeSymbol(); // contains the interface if container is one ?mlsub.typing.Interface itf = null; // contains the associated tc if possible ?mlsub.typing.TypeConstructor tc = null; if (container instanceof mlsub.typing.TypeConstructor) tc = container; else { itf = cast(container); tc = notNull(itf).associatedTC(); } // if the constraint is True // we must create a new one, otherwise we would // modify other methods! if (constraint == Constraint.True) constraint = new Constraint (new ArrayList(thisBindersLen + (hasAlike ? 1 : 0)), new ArrayList((hasAlike ? 1 : 0) + (thisConstraint == null ? 0 : thisConstraint.getAtoms().size()))); constraint.addBinders(thisBinders); if (thisConstraint != null) constraint.addAtoms(thisConstraint.getAtoms()); Monotype thisType; // "alike" is not created for a non-abstract interface // if alike is not present in the type, since it saves // a type parameter (more intuituve for rebinding) // and it does not change typing to do so. if (hasAlike || tc == null) { TypeConstructor alikeTC = new TypeConstructor("Alike", c.variance, false, false); // Add in front. Important for rebinding in method alternatives constraint.addFirstBinder(alikeTC); mlsub.typing.AtomicConstraint atom; if (itf != null) atom = new mlsub.typing.ImplementsCst(alikeTC, itf); else atom = new mlsub.typing.TypeConstructorLeqCst(alikeTC, tc); constraint.addAtom(AtomicConstraint.create(atom)); thisType = Monotype.create (Monotype.sure (new mlsub.typing.MonotypeConstructor (alikeTC, c.getTypeParameters()))); if (hasAlike) { Map<String, bossa.syntax.Monotype> map = new HashMap(); map.put(getAlikeID(), createMonotypeConstructor(alikeTC, new TypeParameters(new ArrayList()), notNull(name.location()))); returnType = returnType.substitute(map); params.substitute(map); } } else thisType = Monotype.createSure(tc, c.getTypeParameters()); params.addThis(thisType); if (body == null) return createNiceMethod(name, constraint, returnType, params, contract, isOverride); else return createMethodWithDefault (name, constraint, returnType, params, body, contract, isOverride); } Index: MethodDeclaration.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/MethodDeclaration.java,v retrieving revision 1.63 retrieving revision 1.64 diff -C2 -d -r1.63 -r1.64 *** MethodDeclaration.java 21 Nov 2004 23:24:36 -0000 1.63 --- MethodDeclaration.java 19 Dec 2004 19:58:28 -0000 1.64 *************** *** 395,399 **** return code; } ! public gnu.bytecode.Type javaReturnType() { --- 395,399 ---- return code; } ! public gnu.bytecode.Type javaReturnType() { Index: defaultMethod.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/defaultMethod.nice,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** defaultMethod.nice 19 Dec 2004 03:40:59 -0000 1.2 --- defaultMethod.nice 19 Dec 2004 19:58:28 -0000 1.3 *************** *** 53,57 **** { if (body == null) ! return new NiceMethod(name, constraint, returnType, parameters, contract, isOverride); --- 53,57 ---- { if (body == null) ! return createNiceMethod(name, constraint, returnType, parameters, contract, isOverride); *************** *** 131,135 **** createPattern(param.getName() || new LocatedString("_", name.location())))); res.declaration = new MethodWithDefault(name, constraint, returnType, ! parameters, contract, isOverride, implementation: res); res.addChild(res.declaration); return res; --- 131,135 ---- createPattern(param.getName() || new LocatedString("_", name.location())))); res.declaration = new MethodWithDefault(name, constraint, returnType, ! parameters, contract, isOverride: isOverride, implementation: res); res.addChild(res.declaration); return res; Index: UserOperator.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/UserOperator.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** UserOperator.java 25 Nov 2004 12:35:48 -0000 1.11 --- UserOperator.java 19 Dec 2004 19:58:28 -0000 1.12 *************** *** 25,29 **** */ ! abstract class UserOperator extends MethodDeclaration { UserOperator(LocatedString name, --- 25,29 ---- */ ! public abstract class UserOperator extends MethodDeclaration { UserOperator(LocatedString name, *************** *** 40,43 **** --- 40,48 ---- public Contract getContract() { return contract; } + public boolean isMain() + { + return false; + } + /**************************************************************** * Resolution *************** *** 145,147 **** --- 150,158 ---- typecheck(); } + + public gnu.expr.LambdaExp getLambda() + { + return null; + } + } --- NiceMethod.java DELETED --- Index: Module.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Module.java,v retrieving revision 1.20 retrieving revision 1.21 diff -C2 -d -r1.20 -r1.21 *** Module.java 5 Mar 2004 14:07:14 -0000 1.20 --- Module.java 19 Dec 2004 19:58:28 -0000 1.21 *************** *** 32,36 **** gnu.bytecode.ClassType createClass(String name); void addGlobalVar(gnu.expr.Declaration declaration, boolean constant); ! gnu.expr.Expression getDispatchMethod(NiceMethod def); gnu.expr.ReferenceExp addMethod(gnu.expr.LambdaExp method, boolean packageMethod); --- 32,36 ---- gnu.bytecode.ClassType createClass(String name); void addGlobalVar(gnu.expr.Declaration declaration, boolean constant); ! gnu.expr.Expression getDispatchMethod(UserOperator/*NiceMethod*/ def); gnu.expr.ReferenceExp addMethod(gnu.expr.LambdaExp method, boolean packageMethod); |
From: Arjan B. <ar...@us...> - 2004-12-19 19:58:38
|
Update of /cvsroot/nice/Nice/src/bossa/link In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4526/F:/nice/src/bossa/link Modified Files: Compilation.java DispatchTest.java Log Message: Converted NiceMethod. Index: DispatchTest.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/link/DispatchTest.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DispatchTest.java 19 Dec 2004 00:28:29 -0000 1.1 --- DispatchTest.java 19 Dec 2004 19:58:27 -0000 1.2 *************** *** 44,48 **** private DispatchTest() { } ! public static void register(NiceMethod m) { methods.add(m); --- 44,48 ---- private DispatchTest() { } ! public static void register(UserOperator/*NiceMethod*/ m) { methods.add(m); *************** *** 73,77 **** try { for(Iterator i = methods.iterator(); i.hasNext();) ! test((NiceMethod) i.next(), module); for (Iterator i = javaMethods.iterator(); i.hasNext();) --- 73,77 ---- try { for(Iterator i = methods.iterator(); i.hasNext();) ! test((UserOperator/*NiceMethod*/) i.next(), module); for (Iterator i = javaMethods.iterator(); i.hasNext();) *************** *** 83,87 **** } ! private static void test(NiceMethod m, bossa.modules.Package module) { Stack sortedAlternatives = Alternative.sortedAlternatives(m); --- 83,87 ---- } ! private static void test(UserOperator/*NiceMethod*/ m, bossa.modules.Package module) { Stack sortedAlternatives = Alternative.sortedAlternatives(m); *************** *** 143,147 **** } ! private static boolean shortTestOk(NiceMethod method, Stack alternatives) { if (alternatives.size() < 2) --- 143,147 ---- } ! private static boolean shortTestOk(UserOperator/*NiceMethod*/ method, Stack alternatives) { if (alternatives.size() < 2) Index: Compilation.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/link/Compilation.java,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** Compilation.java 25 Nov 2004 19:28:19 -0000 1.18 --- Compilation.java 19 Dec 2004 19:58:27 -0000 1.19 *************** *** 35,39 **** public final class Compilation { ! static void compile(NiceMethod m, Stack sortedAlternatives, bossa.modules.Package module) --- 35,39 ---- public final class Compilation { ! static void compile(UserOperator/*NiceMethod*/ m, Stack sortedAlternatives, bossa.modules.Package module) |
From: Arjan B. <ar...@us...> - 2004-12-19 19:58:36
|
Update of /cvsroot/nice/Nice/src/bossa/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4526/F:/nice/src/bossa/parser Modified Files: Parser.jj Log Message: Converted NiceMethod. Index: Parser.jj =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/parser/Parser.jj,v retrieving revision 1.287 retrieving revision 1.288 diff -C2 -d -r1.287 -r1.288 *** Parser.jj 18 Dec 2004 22:04:55 -0000 1.287 --- Parser.jj 19 Dec 2004 19:58:25 -0000 1.288 *************** *** 923,927 **** ( ";" | body = code() {statements.add(body);} ) ! { return NiceMethod.create(c, name, cst, returnType, parameters, body != null ? bossa.syntax.dispatch.createBlock(statements) : null, contract, isOverride); } --- 923,927 ---- ( ";" | body = code() {statements.add(body);} ) ! { return bossa.syntax.dispatch.createMemberMethod(c, name, cst, returnType, parameters, body != null ? bossa.syntax.dispatch.createBlock(statements) : null, contract, isOverride); } |
From: Arjan B. <ar...@us...> - 2004-12-19 16:49:37
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28179/F:/nice/src/bossa/syntax Modified Files: Node.java dispatch.java.bootstrap tools.nice Added Files: scope.nice Removed Files: GlobalVarScope.java Log Message: Converted GlobalVarScope. Index: tools.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/tools.nice,v retrieving revision 1.79 retrieving revision 1.80 diff -C2 -d -r1.79 -r1.80 *** tools.nice 19 Dec 2004 13:35:48 -0000 1.79 --- tools.nice 19 Dec 2004 16:49:14 -0000 1.80 *************** *** 287,291 **** ?Iterator<MethodDeclaration> listSpecializedMethods(MethodDeclaration) = native Iterator MethodDeclaration.listSpecializedMethods(); Monotype[] Monotype_toArray(?List<Monotype>) = native Monotype[] Monotype.toArray(List); ! // Retypings needed since java types are not strict. --- 287,291 ---- ?Iterator<MethodDeclaration> listSpecializedMethods(MethodDeclaration) = native Iterator MethodDeclaration.listSpecializedMethods(); Monotype[] Monotype_toArray(?List<Monotype>) = native Monotype[] Monotype.toArray(List); ! List<VarSymbol> lookup(VarScope, LocatedString) = native List VarScope.lookup(LocatedString); // Retypings needed since java types are not strict. Index: Node.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Node.java,v retrieving revision 1.61 retrieving revision 1.62 diff -C2 -d -r1.61 -r1.62 *** Node.java 21 Nov 2004 23:24:37 -0000 1.61 --- Node.java 19 Dec 2004 16:49:14 -0000 1.62 *************** *** 128,133 **** */ ! private static GlobalVarScope globalScope; ! public static final GlobalVarScope getGlobalScope() { return globalScope; --- 128,133 ---- */ ! private static VarScope globalScope; ! public static final VarScope getGlobalScope() { return globalScope; *************** *** 147,151 **** { JavaClasses.compilation = module.compilation(); ! globalScope = new GlobalVarScope(); globalTypeScope = new GlobalTypeScope(); } --- 147,151 ---- { JavaClasses.compilation = module.compilation(); ! globalScope = dispatch.createGlobalVarScope(); globalTypeScope = new GlobalTypeScope(); } Index: dispatch.java.bootstrap =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/dispatch.java.bootstrap,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** dispatch.java.bootstrap 19 Dec 2004 03:40:59 -0000 1.38 --- dispatch.java.bootstrap 19 Dec 2004 16:49:14 -0000 1.39 *************** *** 13,16 **** --- 13,19 ---- public class dispatch { + static VarScope createGlobalVarScope() + { return null; } + static String getAlikeID() { return null; } --- GlobalVarScope.java DELETED --- --- NEW FILE: scope.nice --- /**************************************************************************/ /* N I C E */ /* A high-level object-oriented research language */ /* (c) Daniel Bonniot 2004 */ /* */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License, or */ /* (at your option) any later version. */ /* */ /**************************************************************************/ package bossa.syntax; /** The global scope of symbols. */ public class GlobalVarScope extends VarScope { lookup(i) { // If there is any method by that name waiting, load it. JavaClasses.nameRequired(i.toString()); return super; } } VarScope createGlobalVarScope() { return new GlobalVarScope(null); } |
From: Daniel B. <bo...@us...> - 2004-12-19 14:44:57
|
Update of /cvsroot/nice/Nice In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4496 Modified Files: NEWS Log Message: Grammar. Index: NEWS =================================================================== RCS file: /cvsroot/nice/Nice/NEWS,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -d -r1.56 -r1.57 *** NEWS 19 Dec 2004 13:40:23 -0000 1.56 --- NEWS 19 Dec 2004 14:44:46 -0000 1.57 *************** *** 10,14 **** override x = 5; } ! It's possible for final fields too. * Imported methods can be generalized. That is, it is possible to define a new method which is more general than an existing one, --- 10,14 ---- override x = 5; } ! This also works for final fields. * Imported methods can be generalized. That is, it is possible to define a new method which is more general than an existing one, *************** *** 22,30 **** the new add method, which makes Collection a valid Addable class. * Java methods and fields with parametric types are given a type with ! UnknownTypes as typeparameters instead of being ignored. * Bug fixes (disallowed redefinition of parameters, execution order of initializers in super classes, visibility checking of java classes, cyclic custom constructors, methods and fields in classes with less type ! params, this in custom constructors, ... ) -- --- 22,30 ---- the new add method, which makes Collection a valid Addable class. * Java methods and fields with parametric types are given a type with ! UnknownTypes as type parameters instead of being ignored. * Bug fixes (disallowed redefinition of parameters, execution order of initializers in super classes, visibility checking of java classes, cyclic custom constructors, methods and fields in classes with less type ! parameters, 'this' in custom constructors, ... ) -- |
From: Arjan B. <ar...@us...> - 2004-12-19 13:40:33
|
Update of /cvsroot/nice/Nice In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24190/Nice Modified Files: NEWS Log Message: Updated changelog. Index: NEWS =================================================================== RCS file: /cvsroot/nice/Nice/NEWS,v retrieving revision 1.55 retrieving revision 1.56 diff -C2 -d -r1.55 -r1.56 *** NEWS 19 Dec 2004 13:07:09 -0000 1.55 --- NEWS 19 Dec 2004 13:40:23 -0000 1.56 *************** *** 21,26 **** Method java.util.Collection.add() is recognized as implementing the new add method, which makes Collection a valid Addable class. * Bug fixes (disallowed redefinition of parameters, execution order of ! initializers in super classes, ... ) -- --- 21,30 ---- Method java.util.Collection.add() is recognized as implementing the new add method, which makes Collection a valid Addable class. + * Java methods and fields with parametric types are given a type with + UnknownTypes as typeparameters instead of being ignored. * Bug fixes (disallowed redefinition of parameters, execution order of ! initializers in super classes, visibility checking of java classes, ! cyclic custom constructors, methods and fields in classes with less type ! params, this in custom constructors, ... ) -- |
From: Arjan B. <ar...@us...> - 2004-12-19 13:36:02
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23208/F:/nice/src/bossa/syntax Modified Files: methodImplementation.nice tools.nice Log Message: Retypings for bootstrapping with older versions. Index: tools.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/tools.nice,v retrieving revision 1.78 retrieving revision 1.79 diff -C2 -d -r1.78 -r1.79 *** tools.nice 19 Dec 2004 03:40:59 -0000 1.78 --- tools.nice 19 Dec 2004 13:35:48 -0000 1.79 *************** *** 285,288 **** --- 285,291 ---- ?mlsub.typing.TypeSymbol lookup(TypeMap, String) = native mlsub.typing.TypeSymbol TypeMap.lookup(String); void substitute(bossa.syntax.FormalParameters, Map<java.lang.String, bossa.syntax.Monotype>) = native void FormalParameters.substitute(Map); + ?Iterator<MethodDeclaration> listSpecializedMethods(MethodDeclaration) = native Iterator MethodDeclaration.listSpecializedMethods(); + Monotype[] Monotype_toArray(?List<Monotype>) = native Monotype[] Monotype.toArray(List); + // Retypings needed since java types are not strict. Index: methodImplementation.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/methodImplementation.nice,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** methodImplementation.nice 19 Dec 2004 03:40:59 -0000 1.1 --- methodImplementation.nice 19 Dec 2004 13:35:48 -0000 1.2 *************** *** 63,67 **** } ! MonoSymbol[] res = cast(new MonoSymbol[formals.length]); for (int tn = 0; tn < formals.length; tn++) { --- 63,67 ---- } ! VarSymbol[] res = cast(new MonoSymbol[formals.length]); for (int tn = 0; tn < formals.length; tn++) { *************** *** 98,102 **** } notNull(scope).addSymbols(res); ! parameters = res; } --- 98,102 ---- } notNull(scope).addSymbols(res); ! parameters = cast(res); } |
From: Daniel B. <bo...@us...> - 2004-12-19 13:07:30
|
Update of /cvsroot/nice/Nice In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv17590 Modified Files: NEWS Log Message: Mention method generalization. Index: NEWS =================================================================== RCS file: /cvsroot/nice/Nice/NEWS,v retrieving revision 1.54 retrieving revision 1.55 diff -C2 -d -r1.54 -r1.55 *** NEWS 14 Oct 2004 17:23:04 -0000 1.54 --- NEWS 19 Dec 2004 13:07:09 -0000 1.55 *************** *** 11,14 **** --- 11,24 ---- } It's possible for final fields too. + * Imported methods can be generalized. That is, it is possible to + define a new method which is more general than an existing one, + and the existing method will be recognized as a special case of the + general one. For instance, consider: + + abstract interface Addable<T> { void add(T item); } + interface java.util.Collection implements Addable; + + Method java.util.Collection.add() is recognized as implementing + the new add method, which makes Collection a valid Addable class. * Bug fixes (disallowed redefinition of parameters, execution order of initializers in super classes, ... ) |
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9607/F:/nice/src/bossa/syntax Modified Files: defaultMethod.nice dispatch.java.bootstrap methodbody.nice tools.nice Added Files: methodImplementation.nice Removed Files: MethodImplementation.java Log Message: Converted MethodImplementation. Index: methodbody.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/methodbody.nice,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** methodbody.nice 18 Dec 2004 19:41:01 -0000 1.4 --- methodbody.nice 19 Dec 2004 03:40:59 -0000 1.5 *************** *** 485,490 **** Statement body) { ! let res = new MethodBodyDefinition(name, body, ! makeFormals(formals, container, notNull(name.location())), binders: binders); --- 485,490 ---- Statement body) { ! let res = new MethodBodyDefinition(name, Node.down, body: body, ! formals: makeFormals(formals, container, notNull(name.location())), binders: binders); --- NEW FILE: methodImplementation.nice --- /**************************************************************************/ /* N I C E */ /* A high-level object-oriented research language */ /* (c) Daniel Bonniot 2004 */ /* */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License, or */ /* (at your option) any later version. */ /* */ /**************************************************************************/ package bossa.syntax; import bossa.util.*; /* import nice.tools.typing.Types; import nice.tools.code.Gen; import mlsub.typing.Typing; import mlsub.typing.TypeConstructor; import mlsub.typing.Monotype; import mlsub.typing.MonotypeVar; import gnu.bytecode.*; import bossa.util.Debug; import bossa.util.User; */ /** An implementation of a method */ public abstract class MethodImplementation extends Definition implements Function { Pattern[] formals; Statement body; ?MethodDeclaration declaration = null; MonoSymbol[?] parameters = null; private ?bossa.link.Alternative alternative = null; ?gnu.expr.ReferenceExp ref = null; ?gnu.expr.LambdaExp compiledMethod = null; public MethodDeclaration getDeclaration() = notNull(declaration); public Pattern[] getPatterns() = formals; boolean hasThis() = notNull(declaration).formalParameters().hasThis(); void buildSymbols() { mlsub.typing.Monotype[] types = notNull(declaration).getArgTypes(); if (formals.length != types.length) { if (types.length == 0) User.error(this, "Method "+name+" has no parameters"); else if (types.length == 1) User.error(this, "Method "+name+" has 1 parameter"); else User.error(this, "Method "+name+" has "+types.length+" parameters"); } MonoSymbol[] res = cast(new MonoSymbol[formals.length]); for (int tn = 0; tn < formals.length; tn++) { Pattern p = formals[tn]; mlsub.typing.Monotype type; if (p.atAny()) { // When a parameter is not dispatched on, it has the declared type // of that parameter in the method declaration. type = types[tn]; } else if (p.getRuntimeTC() != null) { let v = notNull(p.tc).variance; notNull(p.getRuntimeTC()).setVariance(v); type = new mlsub.typing.MonotypeConstructor(notNull(p.getRuntimeTC()), cast(mlsub.typing.MonotypeVar.news(notNull(v).arity()))); type.setKind(notNull(v)); type = bossa.syntax.Monotype.sure(type); } else { if (p.name == null) // anonymous pattern type = new mlsub.typing.MonotypeVar(types[tn].toString()+ "(argument_" + tn+")"); else type = new mlsub.typing.MonotypeVar(types[tn].toString()+ "(" + p.name + ")"); } LocatedString argName = p.getName() != null ? notNull(p.getName()) : new LocatedString("argument_"+tn, bossa.util.Location.nowhere()); res[tn] = new MonoSymbol(argName, type); } notNull(scope).addSymbols(res); parameters = res; } /** Where no patterns are present, add those corresponding to the method declaration. */ void addPatterns() { mlsub.typing.Monotype[] parameters = notNull(nice.tools.typing.Types.parameters(notNull(declaration).getType())); for (int i = 0; i < formals.length; i++) if (formals[i].tc == null) formals[i] = createPattern(formals[i].name, nice.tools.typing.Types.concreteConstructor(parameters[i]), nice.tools.typing.Types.isSure(parameters[i])); } resolveBody() { if (this.hasThis()) Node.thisExp = createSymbolExp(notNull(parameters)[0], this.location()); try { body = analyseMethodBody(body, notNull(scope), notNull(typeScope), notNull(parameters), !nice.tools.typing.Types.isVoid(notNull(declaration).getReturnType())); } finally { Node.thisExp = null; } // Register this alternative for the link test alternative = createSourceAlternative(this); } bossa.link.Alternative getAlternative() = notNull(alternative); getExpectedType() = notNull(declaration).getReturnType(); checkReturnedType(returned) { try { mlsub.typing.Typing.leq(returned, notNull(declaration).getReturnType()); } catch (mlsub.typing.TypingEx e) { throw new Function.WrongReturnType(e, notNull(declaration).getReturnType()); } } gnu.bytecode.Type[] javaArgTypes(); public gnu.expr.ReferenceExp getRefExp() { if (ref == null) { ref = this.createRef(); nice.tools.code.Gen.setMethodBody(compiledMethod, body.generateCode()); } return notNull(ref); } compile() { if (bossa.util.Debug.codeGeneration) bossa.util.Debug.println("Compiling method body " + this); this.getRefExp(); this.createSerializationMethod(); } private gnu.expr.ReferenceExp createRef() { this.createMethod(name.toString()); gnu.expr.ReferenceExp ref = module.addMethod(compiledMethod, true); return ref; } private void createMethod(String bytecodeName) { compiledMethod = nice.tools.code.Gen.createMethod(bytecodeName, this.javaArgTypes(), notNull(declaration).javaReturnType(), parameters, true, false); notNull(compiledMethod).addBytecodeAttribute (new gnu.bytecode.MiscAttr("definition", notNull(declaration).getAllFullNames().getBytes())); notNull(compiledMethod).addBytecodeAttribute (new gnu.bytecode.MiscAttr("patterns", Pattern.bytecodeRepresentation(formals).getBytes())); } TypeConstructor firstArgument(); /** If the method implemented corresponds to readObject or writeObject, create private member methods in the class of the first argument, so that the Java serialization process picks them up. */ private void createSerializationMethod() { let arity = formals.length; let name = this.name.toString(); if (arity != 2 || !(name.equals("writeObject")||name.equals("readObject"))) return; let def = getTypeDefinition(this.firstArgument()); if (def == null || ! (def.getImplementation() instanceof NiceClass)) return; NiceClass c = cast(def.getImplementation()); gnu.expr.Expression[] params = cast(new gnu.expr.Expression[arity]); gnu.expr.LambdaExp method = nice.tools.code.Gen.createMemberMethod (name.toString(), c.getClassExp().getType(), arity==2 ? [notNull(declaration).javaArgTypes()[1]] : null, notNull(declaration).javaReturnType(), params); nice.tools.code.Gen.setMethodBody(method, new gnu.expr.ApplyExp(this.getRefExp(), params)); c.getClassExp().addMethod(method, true); } } --- MethodImplementation.java DELETED --- Index: tools.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/tools.nice,v retrieving revision 1.77 retrieving revision 1.78 diff -C2 -d -r1.77 -r1.78 *** tools.nice 18 Dec 2004 18:18:13 -0000 1.77 --- tools.nice 19 Dec 2004 03:40:59 -0000 1.78 *************** *** 263,267 **** ?FormalParameters getFormalParameters(VarSymbol) = native FormalParameters VarSymbol.getFormalParameters(); List<Node> children(Node) = native Node.children; - Pattern[] formals(MethodImplementation) = native MethodImplementation.formals; LocatedString name(Definition) = native Definition.name; void addMappingsLS(TypeScope, Collection<LocatedString>, TypeSymbol[]) = native void TypeScope.addMappingsLS(Collection, TypeSymbol[]); --- 263,266 ---- Index: dispatch.java.bootstrap =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/dispatch.java.bootstrap,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** dispatch.java.bootstrap 18 Dec 2004 23:43:14 -0000 1.37 --- dispatch.java.bootstrap 19 Dec 2004 03:40:59 -0000 1.38 *************** *** 13,19 **** public class dispatch { - public static bossa.link.Alternative createSourceAlternative(MethodImplementation implementation) - { return null; } - static String getAlikeID() { return null; } --- 13,16 ---- Index: defaultMethod.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/defaultMethod.nice,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** defaultMethod.nice 16 Dec 2004 20:18:47 -0000 1.1 --- defaultMethod.nice 19 Dec 2004 03:40:59 -0000 1.2 *************** *** 127,132 **** Statement body) { ! let res = new DefaultMethodImplementation(name, body, ! parameters.asList().mapToArray(FormalParameters.Parameter param => createPattern(param.getName() || new LocatedString("_", name.location())))); res.declaration = new MethodWithDefault(name, constraint, returnType, --- 127,132 ---- Statement body) { ! let res = new DefaultMethodImplementation(name, Node.down, body: body, ! formals: parameters.asList().mapToArray(FormalParameters.Parameter param => createPattern(param.getName() || new LocatedString("_", name.location())))); res.declaration = new MethodWithDefault(name, constraint, returnType, |
From: Arjan B. <ar...@us...> - 2004-12-19 00:28:41
|
Update of /cvsroot/nice/Nice/src/bossa/modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6347/F:/nice/src/bossa/modules Modified Files: Package.java Log Message: Renamed bossa.link.Dispatch to DispatchTest. Index: Package.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/modules/Package.java,v retrieving revision 1.125 retrieving revision 1.126 diff -C2 -d -r1.125 -r1.126 *** Package.java 1 Dec 2004 02:00:13 -0000 1.125 --- Package.java 19 Dec 2004 00:28:29 -0000 1.126 *************** *** 289,293 **** nice.tools.code.SpecialTypes.init(); bossa.link.Alternative.reset(); ! bossa.link.Dispatch.reset(); bossa.syntax.dispatch.resetTypeDefinitionMappings(); TypeConstructors.reset(); --- 289,293 ---- nice.tools.code.SpecialTypes.init(); bossa.link.Alternative.reset(); ! bossa.link.DispatchTest.reset(); bossa.syntax.dispatch.resetTypeDefinitionMappings(); TypeConstructors.reset(); *************** *** 340,344 **** { compilation.progress(this, "linking"); ! bossa.link.Dispatch.test(this); finishCompilation(); --- 340,344 ---- { compilation.progress(this, "linking"); ! bossa.link.DispatchTest.test(this); finishCompilation(); |
From: Arjan B. <ar...@us...> - 2004-12-19 00:28:40
|
Update of /cvsroot/nice/Nice/src/bossa/link In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6347/F:/nice/src/bossa/link Added Files: DispatchTest.java Removed Files: Dispatch.java Log Message: Renamed bossa.link.Dispatch to DispatchTest. --- Dispatch.java DELETED --- --- NEW FILE: DispatchTest.java --- /**************************************************************************/ /* N I C E */ /* A high-level object-oriented research language */ /* (c) Daniel Bonniot 2002 */ /* */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License, or */ /* (at your option) any later version. */ /* */ /**************************************************************************/ package bossa.link; import bossa.syntax.*; import bossa.util.*; import mlsub.typing.*; import mlsub.typing.Polytype; import mlsub.typing.TupleType; import mlsub.typing.Monotype; import mlsub.typing.MonotypeConstructor; import mlsub.typing.Constraint; import mlsub.typing.MonotypeLeqCst; import mlsub.typing.lowlevel.Element; import nice.tools.typing.PrimitiveType; import gnu.bytecode.ClassType; import java.util.*; import bossa.util.Debug; import nice.tools.util.Chronometer; /** Static class performing the coverage and non-ambiguity test. @version $Date: 2004/12/19 00:28:29 $ @author Daniel Bonniot */ public final class DispatchTest { // Non instantiable private DispatchTest() { } public static void register(NiceMethod m) { methods.add(m); } public static void register(JavaMethod m) { javaMethods.add(m); } public static void unregister(MethodDeclaration m) { javaMethods.remove(m); } private static Collection methods, javaMethods; public static void reset() { methods = new ArrayList(); javaMethods = new ArrayList(); } private static Chronometer chrono = Chronometer.make("Dispatch tests"); public static void test(bossa.modules.Package module) { chrono.start(); try { for(Iterator i = methods.iterator(); i.hasNext();) test((NiceMethod) i.next(), module); for (Iterator i = javaMethods.iterator(); i.hasNext();) test((JavaMethod) i.next(), module); } finally { chrono.stop(); } } private static void test(NiceMethod m, bossa.modules.Package module) { Stack sortedAlternatives = Alternative.sortedAlternatives(m); if (! trivialTestOK(sortedAlternatives)) if (! shortTestOk(m, sortedAlternatives)) test(m, sortedAlternatives, false); if(Debug.codeGeneration) Debug.println("Generating dispatch function for "+m); Compilation.compile(m, sortedAlternatives, module); } private static void test(JavaMethod m, bossa.modules.Package module) { Stack sortedAlternatives = Alternative.sortedAlternatives(m); if (! trivialTestJava(m, sortedAlternatives)) test(m, sortedAlternatives, true); if(Debug.codeGeneration) Debug.println("Generating dispatch function for " + m); Compilation.compile(m, sortedAlternatives, module); } private static boolean trivialTestOK(Stack alternatives) { // return true iff // there is only one alternative and it does not constrain its arguments if(alternatives.size()!=1) return false; Alternative a = (Alternative) alternatives.peek(); return a.allAtAny(); } private static boolean trivialTestJava(JavaMethod m, Stack alternatives) { gnu.bytecode.Method reflectMethod = m.reflectMethod; // Static methods and constructors cannot be overriden, so there is // no problem. if (reflectMethod.getStaticFlag() || reflectMethod.isConstructor()) return true; if (! reflectMethod.isAbstract()) // The only risk with a non abstract method is that it might be // ambiguous. // We know this won't happen in two cases: // 1) if there is only one argument (single // inheritance, since the root must be a class), // 2) if there are less than two implementations. return m.getArity() == 1 || alternatives.size() < 2; // This method will need testing. return false; } private static boolean shortTestOk(NiceMethod method, Stack alternatives) { if (alternatives.size() < 2) return false; //check for default implementation if (! ((Alternative) alternatives.peek()).allAtAny()) return false; for (int i = 0; i < alternatives.size(); i++) for (int k = i+1; k < alternatives.size(); k++) { Alternative altA = (Alternative)alternatives.get(i); Alternative altB = (Alternative)alternatives.get(k); if (Alternative.leq(altB, altA)) User.error(method, "ambiguity because of equivalent patterns in:\n" + altA.printLocated() + "\nand\n" + altB.printLocated()); if (! (Alternative.leq(altA, altB) || Alternative.disjoint(altA, altB))) { Alternative glb = Alternative.greatestLowerBound(altA, altB); if (glb == null) return false; boolean glbMatch = false; for (int j = i-1; j >= 0; j--) if (Alternative.leq(glb, (Alternative)alternatives.get(j))) { glbMatch = true; break; } if (! glbMatch) return false; } } return true; } private static boolean[] findUsedPositions(int len, Stack alternatives) { // We want all solutions for both the nullness marker and the tag, // if that position is used. boolean[] res = new boolean[len * 2]; for (Iterator it = alternatives.iterator(); it.hasNext();) { Alternative a = (Alternative) it.next(); if (len != a.patterns.length) Internal.error("Expected number of patterns is " + len + ".\nThe incorrect alternative: " + a); for (int i = 0; i < len; i++) if (! a.patterns[i].atAny()) res[2*i] = res[2*i + 1] = true; } return res; } private static void test(MethodDeclaration method, final Stack sortedAlternatives, boolean isJavaMethod) { if(Debug.linkTests) { Debug.println("\nLink test for "+method); for(Iterator i = sortedAlternatives.iterator(); i.hasNext();) Debug.println("Alternative: "+i.next().toString()); } boolean[] used = findUsedPositions(method.getArity(), sortedAlternatives); mlsub.typing.Polytype type = method.getType(); if (type == null) throw Internal.error(method + " is not in a proper state."); List multitags = enumerate(type, used); boolean[] isValue = new boolean[method.getArity()]; List values = generateValues(sortedAlternatives, isValue); boolean hasValues = values.size() > 0; List errors = new ArrayList(3); int nb_errors = 0; for(Iterator i = multitags.iterator(); i.hasNext();) { TypeConstructor[] tags = (TypeConstructor[]) i.next(); // For java methods, we are only concerned with cases // where the first argument is a Nice class. ClassType firstArg = null; if (isJavaMethod) { firstArg = classTypeOfNiceClass(tags[0]); if (firstArg == null) continue; } if (test(method, tags, sortedAlternatives, firstArg, errors)) { if (++nb_errors > 3) break; } else if (hasValues && testValues(method, tags, values, isValue, sortedAlternatives, errors) ) if (++nb_errors > 0) break; } if (nb_errors > 0) User.error(method, "The implementation test failed for method " + method.toString() + ":\n" + Util.map("", "\n", "", errors)); } private static ClassType classTypeOfNiceClass(TypeConstructor tc) { TypeDefinition def = bossa.syntax.dispatch.getTypeDefinition(tc); if (def == null || ! (def.getImplementation() instanceof NiceClass)) return null; return ((NiceClass) def.getImplementation()).getClassExp().getClassType(); } /** Tests that the 'tags' tuple has a best-match in alternatives @param method the method being tested @param tags a tuple of TypeConstructors @param alternatives a list of Alternatives @return true if the test failed */ private static boolean test(MethodDeclaration method, TypeConstructor[] tags, final Stack sortedAlternatives, ClassType firstArg, List errors) { boolean failed = false; if(Debug.linkTests) Debug.println(Util.map("Multitag: ",", ","",tags)); // Tests that a match exists, and that the first match is a "best-match" Alternative first = null; for(Iterator i = sortedAlternatives.iterator(); i.hasNext() && !failed;) { Alternative a = (Alternative) i.next(); if (a.matches(tags)) if (first == null) first = a; else if (!Alternative.less(first, a) && !a.containsTypeMatchingValue()) { failed = true; errors.add("ambiguity for parameters of type " + toString(tags)+ "\nboth\n" + first.printLocated() + "\nand\n" + a.printLocated() + "\nmatch."); } } if (first == null) { if (firstArg != null) { gnu.bytecode.Method superImplementation = bossa.syntax.dispatch.getImplementationAbove ((JavaMethod) method, firstArg); if (superImplementation != null && superImplementation.isAbstract() == false) // It's OK, this case is covered by a Java implementation. return false; } failed = true; if(sortedAlternatives.size()==0) User.error (method, "Method " + method + " is declared but never implemented:\n" + "no alternative matches " + toString(tags)); else errors.add("no alternative matches " + toString(tags)); } return failed; } /** Special version of above that tests tags with all combinations of integer values. */ private static boolean testValues (MethodDeclaration method, TypeConstructor[] tags, List valueCombis, boolean[] isValue, final Stack sortedAlternatives, List errors) { boolean failed = false; List sortedTypeMatches = new ArrayList(); for (Iterator i = sortedAlternatives.iterator(); i.hasNext(); ) { Alternative a = (Alternative) i.next(); if (a.matchesTypePart(tags, isValue)) sortedTypeMatches.add(a); } for (Iterator valit = valueCombis.iterator(); valit.hasNext(); ) { Alternative first = null; ConstantExp[] values = (ConstantExp[]) valit.next(); outer: for (Iterator i = sortedTypeMatches.iterator(); i.hasNext();) { Alternative a = (Alternative) i.next(); if (a.matchesValuePart(values, isValue)) if (first == null) first = a; else if (!Alternative.less(first, a)) { failed = true; errors.add("ambiguity for parameters of type/value " + toString(tags, values, isValue)+ "\nboth\n" + first.printLocated() + "\nand\n" + a.printLocated() + "\nmatch."); break outer; } } if(first==null) { failed = true; errors.add("no alternative matches "+ toString(tags, values, isValue)); Debug.println(sortedAlternatives.toString() + "\n" + toString(tags, values, isValue)); break; } } return failed; } private static String toString(TypeConstructor[] tags) { StringBuffer res = new StringBuffer(); res.append('('); for (int i = 0, n = 0; i < tags.length; i++) { res.append(tags[n++]); if (i + 1 < tags.length) res.append(", "); } return res.append(')').toString(); } private static String toString(TypeConstructor[] tags, ConstantExp[] values, boolean[] isValue) { StringBuffer res = new StringBuffer(); res.append('('); for (int i = 0, n = 0; i < tags.length; i++) { if(isValue[n]) res.append(values[n++]); else res.append(tags[n++]); if (i + 1 < tags.length) res.append(", "); } return res.append(')').toString(); } /** Enumerate all the tuples of tags in the domain of a polytype. @return a List of TypeConstructor[] an element of an array is set to: null if it cannot be matched (e.g. a function type) PrimtiveType.nullTC if it can be matched by @null **/ private static List enumerate(Polytype type, boolean[] used) { Monotype[] domains = type.domain(); Constraint cst = type.getConstraint(); int len = used.length; Element[] types = new Element[len]; for (int i = domains.length; --i >= 0;) { Monotype arg = domains[i]; TypeConstructor marker; Monotype raw; // We deconstruct 'arg' as 'marker<raw>' // This is easy and more efficent if arg is already a constructed type if (arg instanceof MonotypeConstructor) { MonotypeConstructor mc = (MonotypeConstructor) arg; marker = mc.getTC(); raw = nice.tools.typing.Types.rawType(mc); } else { marker = new TypeConstructor(PrimitiveType.maybeTC.variance); MonotypeVar var = new MonotypeVar("dispatchType"); raw = var; Monotype t = MonotypeConstructor.apply(marker, raw); cst = Constraint.and(cst, marker, var, new MonotypeLeqCst(t, arg), new MonotypeLeqCst(arg, t)); } types[--len] = raw; types[--len] = marker; } if (! (len == 0)) throw new Error(); List res = mlsub.typing.Enumeration.enumerate(cst, types, used); return mergeNullCases(res, domains.length); } /** Merges all null<*> into null. @param tuples a list of tuples. Each tuple has 2 * length elements, alternatively a nullness marker TC and a normal TC */ private static List mergeNullCases(List tuples, int length) { LinkedList res = new LinkedList(); Set tupleSet = new TreeSet(tagComp); for (Iterator i = tuples.iterator(); i.hasNext();) { TypeConstructor[] tags = flatten((TypeConstructor[]) i.next(), length); //add only non duplicate tags if (tupleSet.add(tags)) res.add(tags); } return res; } private static Comparator tagComp = new TagComparator(); private static class TagComparator implements Comparator { public TagComparator(){} public int compare(Object o1, Object o2) { TypeConstructor[] tc1 = (TypeConstructor[])o1; TypeConstructor[] tc2 = (TypeConstructor[])o2; for(int i = 0; i<tc1.length; i++) { if (tc1[i] == null) { if (tc2[i] == null) return 0; return -1; } if (tc2[i] == null) return 1; int a = tc1[i].getId(); int b = tc2[i].getId(); if (a<b) return -1; if (a>b) return 1; } return 0; } public boolean equals(Object obj) { return false; } } /** Translates (nullTC, *) into nullTC and (sureTC, tc) into tc @param tags a list of tuples. Each tuple has 2 * length elements, alternatively a nullness marker TC and a normal TC */ private static TypeConstructor[] flatten(TypeConstructor[] tags, int length) { TypeConstructor[] res = new TypeConstructor[length]; for (int i = length; --i >= 0 ;) if (tags[2 * i] == PrimitiveType.nullTC) res[i] = PrimitiveType.nullTC; else res[i] = tags[2 * i + 1]; return res; } /** Generate all combinations of values from the alternatives * @return List<ConstantExp> */ private static List generateValues(List alternatives, boolean[] isValue) { List values = new ArrayList(); if (alternatives.size() < 1) return values; int len = isValue.length; for (int pos = 0; pos < len; pos++) { List valuesAtPos = new ArrayList(); for (Iterator i = alternatives.iterator(); i.hasNext(); ) { Pattern pat = ((Alternative)i.next()).getPatterns()[pos]; if (pat.atValue()) { isValue[pos] = true; pat.addValues(valuesAtPos); } } //remove duplicates /* for (int i = 0; i < valuesAtPos.size(); i++) for (int j = i+1; j < valuesAtPos.size(); j++) if (valuesAtPos.get(i).equals(valuesAtPos.get(j))) valuesAtPos.remove(j--); */ int valueCount = valuesAtPos.size(); if (valueCount > 0) { List res = new ArrayList(); if (values.size() == 0) for (int i = 0; i < valueCount; i++) { ConstantExp[] arr2 = new ConstantExp[len]; arr2[pos] = (ConstantExp)valuesAtPos.get(i); res.add(arr2); } else for (Iterator it = values.iterator(); it.hasNext(); ) { ConstantExp[] arr = (ConstantExp[])it.next(); for (int i = 0; i < valueCount; i++) { ConstantExp[] arr2 = new ConstantExp[len]; System.arraycopy(arr,0,arr2,0,len); arr2[pos] = (ConstantExp)valuesAtPos.get(i); res.add(arr2); } } values = res; } } return values; } } |
From: Arjan B. <ar...@us...> - 2004-12-19 00:28:38
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6347/F:/nice/src/bossa/syntax Modified Files: JavaClasses.java JavaMethod.java NiceMethod.java RetypedJavaMethod.java Log Message: Renamed bossa.link.Dispatch to DispatchTest. Index: JavaMethod.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/JavaMethod.java,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** JavaMethod.java 12 Oct 2004 23:35:48 -0000 1.31 --- JavaMethod.java 19 Dec 2004 00:28:28 -0000 1.32 *************** *** 123,127 **** return; ! bossa.link.Dispatch.register(this); registered = true; } --- 123,127 ---- return; ! bossa.link.DispatchTest.register(this); registered = true; } Index: JavaClasses.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/JavaClasses.java,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** JavaClasses.java 26 Jan 2004 13:14:16 -0000 1.45 --- JavaClasses.java 19 Dec 2004 00:28:28 -0000 1.46 *************** *** 264,268 **** { Node.getGlobalScope().removeSymbol(m.getSymbol()); ! bossa.link.Dispatch.unregister(m); } --- 264,268 ---- { Node.getGlobalScope().removeSymbol(m.getSymbol()); ! bossa.link.DispatchTest.unregister(m); } Index: NiceMethod.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/NiceMethod.java,v retrieving revision 1.46 retrieving revision 1.47 diff -C2 -d -r1.46 -r1.47 *** NiceMethod.java 18 Dec 2004 22:04:59 -0000 1.46 --- NiceMethod.java 19 Dec 2004 00:28:28 -0000 1.47 *************** *** 147,151 **** this.isOverride = isOverride; this.returnTypeLocation = returnType.location(); ! bossa.link.Dispatch.register(this); } --- 147,151 ---- this.isOverride = isOverride; this.returnTypeLocation = returnType.location(); ! bossa.link.DispatchTest.register(this); } Index: RetypedJavaMethod.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/RetypedJavaMethod.java,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** RetypedJavaMethod.java 15 Mar 2004 12:06:02 -0000 1.16 --- RetypedJavaMethod.java 19 Dec 2004 00:28:28 -0000 1.17 *************** *** 231,235 **** ignoredRetyping = true; ! bossa.link.Dispatch.unregister(this); } --- 231,235 ---- ignoredRetyping = true; ! bossa.link.DispatchTest.unregister(this); } |
From: Arjan B. <ar...@us...> - 2004-12-19 00:10:00
|
Update of /cvsroot/nice/Nice/testsuite/compiler/methods In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2349/F:/nice/testsuite/compiler/methods Modified Files: implementations.testsuite Log Message: removed ambigious fail here marker. Index: implementations.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/methods/implementations.testsuite,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** implementations.testsuite 13 Oct 2004 18:28:49 -0000 1.17 --- implementations.testsuite 19 Dec 2004 00:09:50 -0000 1.18 *************** *** 42,46 **** // Try to implement a method for a case equivalent to the default. // This should create an ambiguity. ! /*/// FAIL HERE */ fA(A a) {} /// PASS --- 42,46 ---- // Try to implement a method for a case equivalent to the default. // This should create an ambiguity. ! fA(A a) {} /// PASS |
From: Arjan B. <ar...@us...> - 2004-12-18 23:43:38
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29189/F:/nice/src/bossa/syntax Modified Files: MethodImplementation.java dispatch.java.bootstrap Added Files: alternative.nice Log Message: Converted SourceAlternative. --- NEW FILE: alternative.nice --- /**************************************************************************/ /* N I C E */ /* A high-level object-oriented research language */ /* (c) Daniel Bonniot 2004 */ /* */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License, or */ /* (at your option) any later version. */ /* */ /**************************************************************************/ // TODO: this class belongs in bossa.link package bossa.syntax; import bossa.util.*; /** An alternative present in the source code. */ public class SourceAlternative extends Alternative implements Located { private MethodImplementation implementation; location() = implementation.location(); printLocated() = implementation.location() + ": " + this.toString(); methodExp() = implementation.getRefExp(); } public Alternative createSourceAlternative(MethodImplementation implementation) { let res = new SourceAlternative(implementation.getDeclaration().getName().toString(), implementation.getPatterns(), implementation: implementation); res.add(implementation.getDeclaration().getFullName()); ?java.util.Iterator<MethodDeclaration> specializedMethods = cast(implementation.getDeclaration().listSpecializedMethods()); if (specializedMethods != null) while(specializedMethods.hasNext()) res.add(specializedMethods.next().getFullName()); return res; } Index: dispatch.java.bootstrap =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/dispatch.java.bootstrap,v retrieving revision 1.36 retrieving revision 1.37 diff -C2 -d -r1.36 -r1.37 *** dispatch.java.bootstrap 18 Dec 2004 22:04:59 -0000 1.36 --- dispatch.java.bootstrap 18 Dec 2004 23:43:14 -0000 1.37 *************** *** 13,16 **** --- 13,19 ---- public class dispatch { + public static bossa.link.Alternative createSourceAlternative(MethodImplementation implementation) + { return null; } + static String getAlikeID() { return null; } Index: MethodImplementation.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/MethodImplementation.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** MethodImplementation.java 4 Dec 2004 19:38:18 -0000 1.11 --- MethodImplementation.java 18 Dec 2004 23:43:14 -0000 1.12 *************** *** 125,129 **** // Register this alternative for the link test ! alternative = new bossa.link.SourceAlternative(this); } --- 125,129 ---- // Register this alternative for the link test ! alternative = dispatch.createSourceAlternative(this); } |
From: Arjan B. <ar...@us...> - 2004-12-18 23:43:26
|
Update of /cvsroot/nice/Nice/src/bossa/link In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29189/F:/nice/src/bossa/link Modified Files: Alternative.java Removed Files: SourceAlternative.java Log Message: Converted SourceAlternative. --- SourceAlternative.java DELETED --- Index: Alternative.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/link/Alternative.java,v retrieving revision 1.56 retrieving revision 1.57 diff -C2 -d -r1.56 -r1.57 *** Alternative.java 3 Nov 2004 12:07:54 -0000 1.56 --- Alternative.java 18 Dec 2004 23:43:14 -0000 1.57 *************** *** 218,222 **** } ! protected void add(String fullName) { List l = (List) alternatives.get(fullName); --- 218,222 ---- } ! public void add(String fullName) { List l = (List) alternatives.get(fullName); |
From: Arjan B. <ar...@us...> - 2004-12-18 22:05:12
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9584/F:/nice/src/bossa/syntax Modified Files: NiceMethod.java dispatch.java.bootstrap monotype.nice Removed Files: Alike.java Log Message: Converted Alike. Index: dispatch.java.bootstrap =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/dispatch.java.bootstrap,v retrieving revision 1.35 retrieving revision 1.36 diff -C2 -d -r1.35 -r1.36 *** dispatch.java.bootstrap 18 Dec 2004 19:41:01 -0000 1.35 --- dispatch.java.bootstrap 18 Dec 2004 22:04:59 -0000 1.36 *************** *** 13,16 **** --- 13,19 ---- public class dispatch { + static String getAlikeID() + { return null; } + public static Monotype createTypeIdent(LocatedString name) { return null;} Index: monotype.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/monotype.nice,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** monotype.nice 18 Dec 2004 19:41:01 -0000 1.4 --- monotype.nice 18 Dec 2004 22:04:59 -0000 1.5 *************** *** 143,144 **** --- 143,195 ---- return new FunType(in: (in != null ? in : []), out: out); } + + /** + The "alike" syntactic keyword in Monotypes + + */ + public class Alike extends bossa.syntax.Monotype + { + private Monotype[] parameters; + private Location loc; + + // 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"); + } + + void typecheck() + { + Internal.error("Alike not resolved"); + } + + substitute(map) + { + let tc = map.get(alike_id); + + if (tc == null) + return this; + + assert tc instanceof MonotypeConstructor; + let res = createMonotypeConstructor(notNull(tc.lowlevelTC), + new TypeParameters(Monotype.substitute(map, parameters)), + loc); + res.nullness = this.nullness; + return res; + } + + containsAlike() = true; + + toString() = "alike" + Util.map("<", ", ", ">", parameters); + + location() = loc; + } + + // common ID object + let String alike_id = "<ALIKE>"; + String getAlikeID() = alike_id; + + public Monotype createAlike(List<Monotype> parameters, Location location) + { + return new Alike(parameters: Monotype.toArray(parameters), loc: location); + } --- Alike.java DELETED --- Index: NiceMethod.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/NiceMethod.java,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** NiceMethod.java 17 Dec 2004 20:45:10 -0000 1.45 --- NiceMethod.java 18 Dec 2004 22:04:59 -0000 1.46 *************** *** 118,122 **** { Map map = new HashMap(); ! map.put(Alike.id, alikeTC); returnType = returnType.substitute(map); params.substitute(map); --- 118,124 ---- { Map map = new HashMap(); ! map.put(dispatch.getAlikeID(), ! dispatch.createMonotypeConstructor(alikeTC, ! new TypeParameters(new ArrayList()), name.location())); returnType = returnType.substitute(map); params.substitute(map); |
From: Arjan B. <ar...@us...> - 2004-12-18 22:05:11
|
Update of /cvsroot/nice/Nice/src/bossa/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv9584/F:/nice/src/bossa/parser Modified Files: Parser.jj Log Message: Converted Alike. Index: Parser.jj =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/parser/Parser.jj,v retrieving revision 1.286 retrieving revision 1.287 diff -C2 -d -r1.286 -r1.287 *** Parser.jj 18 Dec 2004 19:40:57 -0000 1.286 --- Parser.jj 18 Dec 2004 22:04:55 -0000 1.287 *************** *** 790,794 **** | start="alike" [ "<" p=monotypes() ">" ] ! { res=new Alike(p, makeLocation(start)); } { res.nullness = res.absent; } | --- 790,794 ---- | start="alike" [ "<" p=monotypes() ">" ] ! { res=bossa.syntax.dispatch.createAlike(p, makeLocation(start)); } { res.nullness = res.absent; } | |
From: Arjan B. <ar...@us...> - 2004-12-18 19:41:20
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7828/F:/nice/src/bossa/syntax Modified Files: Monotype.java Pattern.java ai.nice customConstructor.nice dispatch.java.bootstrap enum.nice loop.nice methodbody.nice monotype.nice pattern.nice typedef.nice Added Files: typeIdent.nice Removed Files: TypeIdent.java Log Message: Converted TypeIdent. Index: Pattern.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Pattern.java,v retrieving revision 1.95 retrieving revision 1.96 diff -C2 -d -r1.95 -r1.96 *** Pattern.java 1 Dec 2004 02:00:31 -0000 1.95 --- Pattern.java 18 Dec 2004 19:41:00 -0000 1.96 *************** *** 35,40 **** { LocatedString name; ! TypeIdent typeConstructor; ! private TypeIdent additional; TypeConstructor tc; TypeConstructor tc2; --- 35,40 ---- { LocatedString name; ! /*TypeIdent*/bossa.syntax.Monotype typeConstructor; ! private /*TypeIdent*/bossa.syntax.Monotype additional; TypeConstructor tc; TypeConstructor tc2; *************** *** 60,64 **** } ! Pattern(TypeConstructor tc, TypeIdent add, Location loc) { this.tc = tc; --- 60,64 ---- } ! Pattern(TypeConstructor tc, /*TypeIdent*/bossa.syntax.Monotype add, Location loc) { this.tc = tc; *************** *** 67,71 **** } ! Pattern(LocatedString name, TypeIdent ti, TypeIdent add, Location loc) { this.name = name; --- 67,71 ---- } ! Pattern(LocatedString name, /*TypeIdent*/bossa.syntax.Monotype ti, /*TypeIdent*/bossa.syntax.Monotype add, Location loc) { this.name = name; --- NEW FILE: typeIdent.nice --- /**************************************************************************/ /* N I C E */ /* A high-level object-oriented research language */ /* (c) Daniel Bonniot 2004 */ /* */ /* This program is free software; you can redistribute it and/or modify */ /* it under the terms of the GNU General Public License as published by */ /* the Free Software Foundation; either version 2 of the License, or */ /* (at your option) any later version. */ /* */ /**************************************************************************/ package bossa.syntax; import bossa.util.*; /** A syntactic type identifier. After scoping, it will either reveal to be a TypeConstructor or a MonotypeVar. */ public final class TypeIdent extends bossa.syntax.Monotype implements Located { public LocatedString name; public TypeIdent cloneTypeIdent() { return new TypeIdent(name: name); } containsAlike() = false; isVoid() = "void".equals(name.toString()); substitute(map) { return map.get(name.toString()) || this; } resolveToTypeSymbol(scope) { let res = notNull(scope).lookup(name); if (res == null) throw unknownIdent(name); return res; } rawResolve(scope) { let res = this.resolveToTypeSymbol(scope); if (res instanceof mlsub.typing.Monotype) return res; if (res instanceof mlsub.typing.TypeConstructor) { try{ return nice.tools.typing.Types.zeroArgMonotype(res); } catch(mlsub.typing.BadSizeEx e){ // See if this is a class with default type parameters let type = getTypeWithTC(res); if (type != null) return type; throw User.error(this, name + Util.has(e.expected, "type parameter", e.actual)); } } if (res instanceof mlsub.typing.Interface) User.error(this, "This abstract interface cannot be used as a type"); throw Internal.error("Invalid type ident: " + res.getClass() + " = " + res); } public mlsub.typing.TypeConstructor resolveToTC(TypeMap scope) { let res = this.resolveToTypeSymbol(scope); if (res instanceof mlsub.typing.TypeConstructor) return res; throw User.error(this, this + " is not a class"); } public mlsub.typing.TypeSymbol resolvePreferablyToItf(TypeMap scope) { let res = this.resolveToTypeSymbol(scope); if (res instanceof mlsub.typing.Interface) return res; if (res instanceof TypeConstructor) { let def = getTypeDefinition(res); if (def != null) { let itf = def.getAssociatedInterface(); if (itf != null) return itf; } } return res; } public mlsub.typing.Interface resolveToItf(TypeMap scope) { let res = this.resolvePreferablyToItf(scope); if (res instanceof mlsub.typing.Interface) return res; throw User.error(this, res + " should be an interface"); } toString() = this.nullnessString() + name.toString(); public LocatedString getName() = name; public boolean hasName(LocatedString name) { return this.name.equals(name); } location() = notNull(name.location()); } public Monotype createTypeIdent(LocatedString name) { return new TypeIdent(name: name); } /* public mlsub.typing.Interface[?] resolveToItf(TypeMap scope, ?List<TypeIdent> idents) { if (idents==null || idents.size()==0) return null; return idents.mapToArray(TypeIdent ti => ti.resolveToItf(scope)); } */ Index: customConstructor.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/customConstructor.nice,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** customConstructor.nice 17 Dec 2004 17:38:01 -0000 1.3 --- customConstructor.nice 18 Dec 2004 19:41:01 -0000 1.4 *************** *** 151,155 **** private Monotype getCCReturnType(LocatedString className, Constraint cst) { ! let classe = new TypeIdent(className); classe.nullness = Monotype.sure; --- 151,155 ---- private Monotype getCCReturnType(LocatedString className, Constraint cst) { ! let classe = new TypeIdent(name: className); classe.nullness = Monotype.sure; Index: methodbody.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/methodbody.nice,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** methodbody.nice 4 Dec 2004 19:38:18 -0000 1.3 --- methodbody.nice 18 Dec 2004 19:41:01 -0000 1.4 *************** *** 501,505 **** List<Pattern> res = new ArrayList(); res.add(createPattern(new LocatedString("this", loc), ! new TypeIdent(container.getName()))); res.addAll(formals); return res.toArray(); --- 501,505 ---- List<Pattern> res = new ArrayList(); res.add(createPattern(new LocatedString("this", loc), ! new TypeIdent(name: container.getName()))); res.addAll(formals); return res.toArray(); --- TypeIdent.java DELETED --- Index: enum.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/enum.nice,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** enum.nice 16 Dec 2004 16:21:07 -0000 1.8 --- enum.nice 18 Dec 2004 19:41:01 -0000 1.9 *************** *** 67,71 **** let classDef = makeClass (name,true,false, null, new ArrayList(), ! createMonotypeConstructor(new TypeIdent(new LocatedString("nice.lang.Enum", name.location())), null, name.location()), interfaces, null); let impl = createNiceClass(classDef); --- 67,71 ---- let classDef = makeClass (name,true,false, null, new ArrayList(), ! createMonotypeConstructor(new TypeIdent(name: new LocatedString("nice.lang.Enum", name.location())), null, name.location()), interfaces, null); let impl = createNiceClass(classDef); *************** *** 173,177 **** List<Expression> argExps) { ! Monotype type = new TypeIdent(enumName); type.nullness = Monotype.absent; List<Arguments.Argument> args = new ArrayList(2 + fields.size()); --- 173,177 ---- List<Expression> argExps) { ! Monotype type = new TypeIdent(name: enumName); type.nullness = Monotype.absent; List<Arguments.Argument> args = new ArrayList(2 + fields.size()); *************** *** 185,188 **** return new EnumSymbol(name, type, definition: def, value: ! createNewExp(new TypeIdent(enumName), new Arguments(args))); } --- 185,188 ---- return new EnumSymbol(name, type, definition: def, value: ! createNewExp(new TypeIdent(name: enumName), new Arguments(args))); } Index: ai.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/ai.nice,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ai.nice 28 Nov 2004 01:00:47 -0000 1.1 --- ai.nice 18 Dec 2004 19:41:01 -0000 1.2 *************** *** 101,105 **** resolve() { ! classTC = new TypeIdent(className).resolveToTC(typeScope); if (TypeConstructors.isInterface(classTC)) --- 101,105 ---- resolve() { ! classTC = new TypeIdent(name: className).resolveToTC(notNull(typeScope)); if (TypeConstructors.isInterface(classTC)) *************** *** 113,119 **** let ident = new TypeIdent ! (new LocatedString(module.getName() + '.' + interfaceName.content, interfaceName.location())); ! interfaceITF = ident.resolveToItf(typeScope); let def = getTypeDefinition(notNull(classTC)); --- 113,119 ---- let ident = new TypeIdent ! (name: new LocatedString(module.getName() + '.' + interfaceName.content, interfaceName.location())); ! interfaceITF = ident.resolveToItf(notNull(typeScope)); let def = getTypeDefinition(notNull(classTC)); Index: loop.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/loop.nice,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** loop.nice 16 Dec 2004 16:21:07 -0000 1.7 --- loop.nice 18 Dec 2004 19:41:01 -0000 1.8 *************** *** 135,139 **** List<Monotype> tparams = new ArrayList(1); tparams.add(vartype); ! itertype = createMonotypeConstructor(new TypeIdent(new LocatedString("Iterator", loc)), new TypeParameters(tparams), loc); notNull(itertype).nullness = Monotype.sure; --- 135,139 ---- List<Monotype> tparams = new ArrayList(1); tparams.add(vartype); ! itertype = createMonotypeConstructor(new TypeIdent(name: new LocatedString("Iterator", loc)), new TypeParameters(tparams), loc); notNull(itertype).nullness = Monotype.sure; Index: typedef.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/typedef.nice,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** typedef.nice 17 Dec 2004 20:45:08 -0000 1.5 --- typedef.nice 18 Dec 2004 19:41:01 -0000 1.6 *************** *** 303,307 **** let name = notNull(parent.tc); ! let s = name.resolvePreferablyToItf(typeScope); if (s instanceof mlsub.typing.Interface) --- 303,307 ---- let name = notNull(parent.tc); ! let s = name.resolvePreferablyToItf(notNull(typeScope)); if (s instanceof mlsub.typing.Interface) *************** *** 484,488 **** { this.useInheritanceParams(this.resolveParams(s, this.getLocalScope())); ! let superClass = notNull(s.tc).resolveToTC(typeScope); let name = notNull(this.name); --- 484,488 ---- { this.useInheritanceParams(this.resolveParams(s, this.getLocalScope())); ! let superClass = notNull(s.tc).resolveToTC(notNull(typeScope)); let name = notNull(this.name); Index: pattern.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/pattern.nice,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** pattern.nice 8 Dec 2004 20:00:58 -0000 1.11 --- pattern.nice 18 Dec 2004 19:41:01 -0000 1.12 *************** *** 64,68 **** if (value instanceof StringConstantExp) ! return new StringPattern(null, new TypeIdent(new LocatedString("java.lang.String", value.location())), additional, value.location(), atValue: value); --- 64,68 ---- if (value instanceof StringConstantExp) ! return new StringPattern(null, new TypeIdent(name: new LocatedString("java.lang.String", value.location())), additional, value.location(), atValue: value); Index: Monotype.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Monotype.java,v retrieving revision 1.38 retrieving revision 1.39 diff -C2 -d -r1.38 -r1.39 *** Monotype.java 17 Dec 2004 20:45:10 -0000 1.38 --- Monotype.java 18 Dec 2004 19:40:59 -0000 1.39 *************** *** 45,49 **** static Monotype fresh(LocatedString associatedVariable) { ! return new TypeIdent(associatedVariable); } --- 45,49 ---- static Monotype fresh(LocatedString associatedVariable) { ! return dispatch.createTypeIdent(associatedVariable); } *************** *** 200,203 **** --- 200,209 ---- } + //temporarily method to call on TypeIdent's + public mlsub.typing.TypeSymbol resolveToTypeSymbol(TypeMap scope) + { + return null; + } + /**************************************************************** * Printing Index: dispatch.java.bootstrap =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/dispatch.java.bootstrap,v retrieving revision 1.34 retrieving revision 1.35 diff -C2 -d -r1.34 -r1.35 *** dispatch.java.bootstrap 16 Dec 2004 20:18:47 -0000 1.34 --- dispatch.java.bootstrap 18 Dec 2004 19:41:01 -0000 1.35 *************** *** 13,16 **** --- 13,19 ---- public class dispatch { + public static Monotype createTypeIdent(LocatedString name) + { return null;} + public static Definition createMethodWithDefault(LocatedString name, Constraint constraint, Monotype returnType, FormalParameters parameters, Statement body, Contract contract, boolean isOverride) { return null; } Index: monotype.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/monotype.nice,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** monotype.nice 18 Dec 2004 18:18:13 -0000 1.3 --- monotype.nice 18 Dec 2004 19:41:01 -0000 1.4 *************** *** 34,38 **** if (lowlevelTC == null) { ! let newTC = notNull(this.tc).resolveToTC(typeMap); if (! (newTC instanceof TypeConstructor)) throw User.error(notNull(this.tc), notNull(this.tc)+" should be a type constructor"); --- 34,38 ---- 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"); |
From: Arjan B. <ar...@us...> - 2004-12-18 19:41:08
|
Update of /cvsroot/nice/Nice/src/bossa/parser In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7828/F:/nice/src/bossa/parser Modified Files: Parser.jj Log Message: Converted TypeIdent. Index: Parser.jj =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/parser/Parser.jj,v retrieving revision 1.285 retrieving revision 1.286 diff -C2 -d -r1.285 -r1.286 *** Parser.jj 16 Dec 2004 20:18:46 -0000 1.285 --- Parser.jj 18 Dec 2004 19:40:57 -0000 1.286 *************** *** 674,678 **** last=getToken(0); ! return bossa.syntax.dispatch.createMonotypeConstructor(t,new TypeParameters(p), makeLocation(first, last)); } --- 674,678 ---- last=getToken(0); ! return bossa.syntax.fun.createMonotypeConstructor(t,new TypeParameters(p), makeLocation(first, last)); } *************** *** 761,765 **** tp.add(res); Location loc = res.location(); ! res = bossa.syntax.dispatch.createMonotypeConstructor (new TypeIdent(new LocatedString("nice.lang.Array", loc)), new TypeParameters(tp), --- 761,765 ---- tp.add(res); Location loc = res.location(); ! res = bossa.syntax.fun.createMonotypeConstructor (new TypeIdent(new LocatedString("nice.lang.Array", loc)), new TypeParameters(tp), *************** *** 935,939 **** // they should be checked [ "<" params = monotypes() ">" ] ! { return bossa.syntax.dispatch.createMonotypeConstructor(name, params == null ? null : new TypeParameters(params), name.location()); } } --- 935,939 ---- // they should be checked [ "<" params = monotypes() ">" ] ! { return bossa.syntax.fun.createMonotypeConstructor(name, params == null ? null : new TypeParameters(params), name.location()); } } *************** *** 1279,1288 **** ] name=ident() ! { return bossa.syntax.dispatch.createPattern(tc, name, false, additional, runtimeTC); } | "#" tc=typeIdent() [ "(" additional=typeIdent() ")" ] [ name=ident() ] ! { return bossa.syntax.dispatch.createPattern(tc, name, true, additional, null); } | ( --- 1279,1288 ---- ] name=ident() ! { return bossa.syntax.fun.createPattern(tc, name, false, additional, runtimeTC); } | "#" tc=typeIdent() [ "(" additional=typeIdent() ")" ] [ name=ident() ] ! { return bossa.syntax.fun.createPattern(tc, name, true, additional, null); } | ( *************** *** 1294,1298 **** [ "(" additional=typeIdent() ")" ] { User.warning(tc.location(), "This syntax is deprecated, use 'Type paramName' instead."); ! return bossa.syntax.dispatch.createPattern(tc, null, false, additional, null); } | --- 1294,1298 ---- [ "(" additional=typeIdent() ")" ] { User.warning(tc.location(), "This syntax is deprecated, use 'Type paramName' instead."); ! return bossa.syntax.fun.createPattern(tc, null, false, additional, null); } | *************** *** 1303,1312 **** [ ":" runtimeTC=typeConstructor() ] [ "(" additional=typeIdent() ")" ] ! { return bossa.syntax.dispatch.createPattern(tc, name, false, additional, runtimeTC); } | "#" tc=typeIdent() [ "(" additional=typeIdent() ")" ] { User.warning(name.location(), "This syntax is deprecated, use '#Type paramName' instead."); ! return bossa.syntax.dispatch.createPattern(tc, name, true, additional, null); } | --- 1303,1312 ---- [ ":" runtimeTC=typeConstructor() ] [ "(" additional=typeIdent() ")" ] ! { return bossa.syntax.fun.createPattern(tc, name, false, additional, runtimeTC); } | "#" tc=typeIdent() [ "(" additional=typeIdent() ")" ] { User.warning(name.location(), "This syntax is deprecated, use '#Type paramName' instead."); ! return bossa.syntax.fun.createPattern(tc, name, true, additional, null); } | *************** *** 1690,1694 **** { Arguments arguments; } arguments = arguments(false) ! { e = bossa.syntax.dispatch.createNewExp(classe, arguments); e.setLocation(makeLocation(t)); return e; --- 1690,1694 ---- { Arguments arguments; } arguments = arguments(false) ! { e = bossa.syntax.fun.createNewExp(classe, arguments); e.setLocation(makeLocation(t)); return e; |
From: Arjan B. <ar...@us...> - 2004-12-18 18:18:23
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23026/F:/nice/src/bossa/syntax Modified Files: monotype.nice tools.nice Log Message: Changed to String key in the Monotype.substitute Map. Index: tools.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/tools.nice,v retrieving revision 1.76 retrieving revision 1.77 diff -C2 -d -r1.76 -r1.77 *** tools.nice 17 Dec 2004 04:09:42 -0000 1.76 --- tools.nice 18 Dec 2004 18:18:13 -0000 1.77 *************** *** 272,277 **** ?String getParentFor(AtomicConstraint, mlsub.typing.TypeConstructor) = native String AtomicConstraint.getParentFor(mlsub.typing.TypeConstructor); mlsub.typing.AtomicConstraint resolve(AtomicConstraint, TypeScope) = native mlsub.typing.AtomicConstraint AtomicConstraint.resolve(TypeScope); ! bossa.syntax.Monotype substitute(bossa.syntax.Monotype,Map<TypeIdent,bossa.syntax.Monotype>) = native bossa.syntax.Monotype bossa.syntax.Monotype.substitute(Map); ! List<bossa.syntax.Monotype> substitute(Map<TypeIdent,bossa.syntax.Monotype>,Collection<bossa.syntax.Monotype>) = native List bossa.syntax.Monotype.substitute(Map,Collection); boolean containsAlike(List<bossa.syntax.Monotype>) = native boolean bossa.syntax.Monotype.containsAlike(List); mlsub.typing.Monotype[] rawResolve(TypeMap,Collection<bossa.syntax.Monotype>) = native mlsub.typing.Monotype[] bossa.syntax.Monotype.rawResolve(TypeMap, Collection); --- 272,277 ---- ?String getParentFor(AtomicConstraint, mlsub.typing.TypeConstructor) = native String AtomicConstraint.getParentFor(mlsub.typing.TypeConstructor); mlsub.typing.AtomicConstraint resolve(AtomicConstraint, TypeScope) = native mlsub.typing.AtomicConstraint AtomicConstraint.resolve(TypeScope); ! bossa.syntax.Monotype substitute(bossa.syntax.Monotype,Map<String,bossa.syntax.Monotype>) = native bossa.syntax.Monotype bossa.syntax.Monotype.substitute(Map); ! List<bossa.syntax.Monotype> substitute(Map<String,bossa.syntax.Monotype>,Collection<bossa.syntax.Monotype>) = native List bossa.syntax.Monotype.substitute(Map,Collection); boolean containsAlike(List<bossa.syntax.Monotype>) = native boolean bossa.syntax.Monotype.containsAlike(List); mlsub.typing.Monotype[] rawResolve(TypeMap,Collection<bossa.syntax.Monotype>) = native mlsub.typing.Monotype[] bossa.syntax.Monotype.rawResolve(TypeMap, Collection); *************** *** 281,285 **** List<FormalParameters.Parameter> asList(FormalParameters) = native List FormalParameters.asList(); boolean containsAlike(Monotype[]) = native boolean Monotype.containsAlike(Monotype[]); ! bossa.syntax.Monotype[] substitute(Map<TypeIdent,bossa.syntax.Monotype>,bossa.syntax.Monotype[]) = native bossa.syntax.Monotype[] bossa.syntax.Monotype.substitute(Map,bossa.syntax.Monotype[]); Monotype[?] types(FormalParameters) = native Monotype[] FormalParameters.types(); ?mlsub.typing.TypeSymbol lookup(TypeMap, LocatedString) = native mlsub.typing.TypeSymbol TypeMap.lookup(LocatedString); --- 281,285 ---- List<FormalParameters.Parameter> asList(FormalParameters) = native List FormalParameters.asList(); boolean containsAlike(Monotype[]) = native boolean Monotype.containsAlike(Monotype[]); ! bossa.syntax.Monotype[] substitute(Map<String,bossa.syntax.Monotype>,bossa.syntax.Monotype[]) = native bossa.syntax.Monotype[] bossa.syntax.Monotype.substitute(Map,bossa.syntax.Monotype[]); Monotype[?] types(FormalParameters) = native Monotype[] FormalParameters.types(); ?mlsub.typing.TypeSymbol lookup(TypeMap, LocatedString) = native mlsub.typing.TypeSymbol TypeMap.lookup(LocatedString); Index: monotype.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/monotype.nice,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** monotype.nice 16 Dec 2004 16:21:07 -0000 1.2 --- monotype.nice 18 Dec 2004 18:18:13 -0000 1.3 *************** *** 58,65 **** substitute(map) { - let TypeIdent newTC = cast(map.get(notNull(tc))) || notNull(tc); - Monotype res = createMonotypeConstructor ! (newTC, new TypeParameters(Monotype.substitute(map, notNull(parameters.content))), loc); --- 58,63 ---- substitute(map) { Monotype res = createMonotypeConstructor ! (notNull(tc), new TypeParameters(Monotype.substitute(map, notNull(parameters.content))), loc); |
From: Daniel B. <bo...@us...> - 2004-12-18 17:37:43
|
Update of /cvsroot/nice/Nice/testsuite/compiler/typing In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14077/testsuite/compiler/typing Modified Files: alike.testsuite Log Message: Additional testcase for alike, exercising substitution on constructed monotypes. Index: alike.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/typing/alike.testsuite,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** alike.testsuite 25 Jun 2002 07:06:05 -0000 1.1 --- alike.testsuite 18 Dec 2004 17:37:31 -0000 1.2 *************** *** 24,30 **** { f4(x, y); ! return x; } /// FAIL /// TOPLEVEL --- 24,39 ---- { f4(x, y); ! return x; } + /// PASS + /// Toplevel + abstract class A + { + alike foo(List<alike> bar); + } + + <A T> T bla(T a) = a.foo([a]); + /// FAIL /// TOPLEVEL |
From: Daniel B. <bo...@us...> - 2004-12-17 20:45:54
|
Update of /cvsroot/nice/Nice/testsuite/compiler/classes In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3596/testsuite/compiler/classes Modified Files: specialization.testsuite Log Message: Fix methods declared inside classes with less type parameters than their parents (fixes bug #1084559). Index: specialization.testsuite =================================================================== RCS file: /cvsroot/nice/Nice/testsuite/compiler/classes/specialization.testsuite,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** specialization.testsuite 14 Dec 2004 00:18:40 -0000 1.5 --- specialization.testsuite 17 Dec 2004 20:45:06 -0000 1.6 *************** *** 56,60 **** } ! /// PASS bug /// Toplevel class A<T> {} --- 56,60 ---- } ! /// PASS /// Toplevel class A<T> {} *************** *** 62,63 **** --- 62,73 ---- void foo() {} } + + /// PASS + // bug #1084559 + foo(new Aha()); + /// Toplevel + interface Buffer<Elem> {} + + class Aha implements Buffer<int> { + void foo() {} + } |
From: Daniel B. <bo...@us...> - 2004-12-17 20:45:24
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3596/src/bossa/syntax Modified Files: typedef.nice NiceMethod.java Monotype.java Log Message: Fix methods declared inside classes with less type parameters than their parents (fixes bug #1084559). Index: typedef.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/typedef.nice,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** typedef.nice 8 Dec 2004 23:03:37 -0000 1.4 --- typedef.nice 17 Dec 2004 20:45:08 -0000 1.5 *************** *** 719,728 **** if (def == null) return null; ! let params = def.parentParams; ! if (params == null) return null; ! // Look for missing type parameters int missing = 0; --- 719,728 ---- if (def == null) return null; ! let params = def.parentParams; ! if (params == null) return null; ! // Look for missing type parameters int missing = 0; *************** *** 742,746 **** requires exactly these type parameters because it specializes its parent. */ ! ?mlsub.typing.Monotype getTypeWithTC( TypeConstructor tc, mlsub.typing.Monotype[] sourceParams ) { ?CTypeDefinition def = cast(getTypeDefinition(tc)); --- 742,746 ---- requires exactly these type parameters because it specializes its parent. */ ! ?mlsub.typing.Monotype getTypeWithTC(TypeConstructor tc, mlsub.typing.Monotype[] sourceParams ) { ?CTypeDefinition def = cast(getTypeDefinition(tc)); *************** *** 767,771 **** fullParams[i] = params[i]; ! if (used < sourceParams.length) return null; --- 767,771 ---- fullParams[i] = params[i]; ! if (sourceParams != null && used < sourceParams.length) return null; Index: Monotype.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Monotype.java,v retrieving revision 1.37 retrieving revision 1.38 diff -C2 -d -r1.37 -r1.38 *** Monotype.java 1 Dec 2004 02:00:31 -0000 1.37 --- Monotype.java 17 Dec 2004 20:45:10 -0000 1.38 *************** *** 17,20 **** --- 17,21 ---- import mlsub.typing.MonotypeVar; + import mlsub.typing.TypeConstructor; import nice.tools.typing.PrimitiveType; *************** *** 279,282 **** --- 280,325 ---- /**************************************************************** + * 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 ****************************************************************/ Index: NiceMethod.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/NiceMethod.java,v retrieving revision 1.44 retrieving revision 1.45 diff -C2 -d -r1.44 -r1.45 *** NiceMethod.java 16 Dec 2004 20:18:46 -0000 1.44 --- NiceMethod.java 17 Dec 2004 20:45:10 -0000 1.45 *************** *** 89,93 **** constraint.addAtoms(thisConstraint.getAtoms()); ! mlsub.typing.Monotype thisType; // "alike" is not created for a non-abstract interface --- 89,93 ---- constraint.addAtoms(thisConstraint.getAtoms()); ! Monotype thisType; // "alike" is not created for a non-abstract interface *************** *** 109,115 **** atom = new mlsub.typing.TypeConstructorLeqCst(alikeTC, tc); constraint.addAtom(AtomicConstraint.create(atom)); ! ! thisType = new mlsub.typing.MonotypeConstructor(alikeTC, c.getTypeParameters()); ! if (hasAlike) { --- 109,118 ---- atom = new mlsub.typing.TypeConstructorLeqCst(alikeTC, tc); constraint.addAtom(AtomicConstraint.create(atom)); ! ! thisType = Monotype.create ! (Monotype.sure ! (new mlsub.typing.MonotypeConstructor ! (alikeTC, c.getTypeParameters()))); ! if (hasAlike) { *************** *** 121,131 **** } else ! thisType = ! new mlsub.typing.MonotypeConstructor(tc, c.getTypeParameters()); ! ! params.addThis(Monotype.create(Monotype.sure(thisType))); ! if (body == null) ! return new NiceMethod(name, constraint, returnType, params, contract, isOverride); else --- 124,134 ---- } else ! thisType = ! Monotype.createSure(tc, c.getTypeParameters()); ! ! params.addThis(thisType); ! if (body == null) ! return new NiceMethod(name, constraint, returnType, params, contract, isOverride); else |