[Nice-commit] Nice/src/bossa/syntax compilation.nice,1.8,1.9 modifiers.nice,1.1,1.2
Brought to you by:
bonniot
From: Artem Gr K. <ar...@us...> - 2005-05-21 16:25:07
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14762/src/bossa/syntax Modified Files: compilation.nice modifiers.nice Log Message: Emit method signatures into Nice interface classes. Index: compilation.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/compilation.nice,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** compilation.nice 26 Mar 2005 15:33:02 -0000 1.8 --- compilation.nice 21 May 2005 16:24:58 -0000 1.9 *************** *** 23,32 **** [cast(gnu.bytecode.Type.string_type)]); ! public void compileNiceMethod(NiceMethod m, ! Stack<Alternative> sortedAlternatives, ! bossa.modules.Package module) ! { ! gnu.expr.LambdaExp lexp = m.getLambda(); ! // parameters of the alternative function are the same in each case, // so we compute them just once --- 23,30 ---- [cast(gnu.bytecode.Type.string_type)]); ! private void makeBody(NiceMethod m, ! gnu.expr.LambdaExp lexp, ! Stack<Alternative> sortedAlternatives){ ! // parameters of the alternative function are the same in each case, // so we compute them just once *************** *** 40,52 **** gnu.expr.Expression body = dispatchNiceMethod ! (sortedAlternatives.iterator(), ! m.javaReturnType(), m.javaReturnType().isVoid(), params); if (m.isMain()) body = beautifyUncaughtExceptions(body); ! nice.tools.code.Gen.setMethodBody(lexp, m.getContract().compile(body)); } ! private gnu.expr.Expression dispatchNiceMethod(Iterator<Alternative> sortedAlternatives, gnu.bytecode.Type returnType, --- 38,95 ---- gnu.expr.Expression body = dispatchNiceMethod ! (sortedAlternatives.iterator(), ! m.javaReturnType(), m.javaReturnType().isVoid(), params); if (m.isMain()) body = beautifyUncaughtExceptions(body); ! body = m.getContract().compile(body); ! nice.tools.code.Gen.setMethodBody(lexp, body); } ! ! public void compileNiceMethod(NiceMethod m, ! Stack<Alternative> sortedAlternatives, ! bossa.modules.Package module) ! { ! gnu.expr.LambdaExp lexp = m.getLambda(); ! ! makeBody( m, lexp, sortedAlternatives ); ! ! if(m.getArity() != 0){ ! ?NiceClass iface = getNiceClass(m.getArgTypes()[0]); ! if(iface != null && iface.isInterface() && ! ( m instanceof MethodWithDefault )){ ! ! // If alternative method is implementing an interface, ! // then generate a dispatch method as a class member, ! // for Java interface invocations to find the implementation. ! ! if(bossa.util.Debug.codeGeneration) ! bossa.util.Debug.println("Generating Nice interface signature for " iface ); ! String name = m.getName().toString(); ! let argTypes = m.javaArgTypes(); ! let retType = m.javaReturnType(); ! let fullName = m.getFullName(); ! gnu.expr.LambdaExp res = generateMethod ! (name, argTypes, retType, m.getSymbols(), toplevel: true, member: true); ! res.parameterCopies = cast(notNull(m.formalParameters()).getParameterCopies()); ! iface.addJavaMethod(res); ! ! for(alt : sortedAlternatives){ ! ?NiceClass cl = declaringClass(alt); ! if(cl == null) continue; ! if(bossa.util.Debug.codeGeneration) ! bossa.util.Debug.println("Generating Nice dispatch function (interface implementation) for " alt); ! ! res = generateMethod ! (name, argTypes, retType, m.getSymbols(), toplevel: true, member: true); ! res.parameterCopies = cast(notNull(m.formalParameters()).getParameterCopies()); ! res.addBytecodeAttribute(new gnu.bytecode.MiscAttr("id", fullName.getBytes())); ! makeBody( m, res, sortedAlternatives ); ! cl.addJavaMethod(res); ! } ! } ! } ! } ! private gnu.expr.Expression dispatchNiceMethod(Iterator<Alternative> sortedAlternatives, gnu.bytecode.Type returnType, *************** *** 146,150 **** } ! private NiceClass declaringClass(JavaMethod m, Alternative alt) { ?mlsub.typing.TypeConstructor firstArgument = alt.getPatterns()[0].getTC(); --- 189,193 ---- } ! private ?NiceClass declaringClass(Alternative alt) { ?mlsub.typing.TypeConstructor firstArgument = alt.getPatterns()[0].getTC(); *************** *** 153,161 **** if (def != null && def.getImplementation() instanceof NiceClass) return cast(def.getImplementation()); // Explain that this cannot be done. String msg = m + " is a native method.\n"; ! if (firstArgument == null) msg += "It cannot be implemented without dispatch on the first argument"; else --- 196,210 ---- if (def != null && def.getImplementation() instanceof NiceClass) return cast(def.getImplementation()); + return null; + } + + private NiceClass declaringClass(JavaMethod m, Alternative alt) + { + let cl = declaringClass(alt); if(cl != null) return cl; // Explain that this cannot be done. String msg = m + " is a native method.\n"; ! if (maybeNull(firstArgument) == null) msg += "It cannot be implemented without dispatch on the first argument"; else Index: modifiers.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/modifiers.nice,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** modifiers.nice 25 Nov 2004 19:28:18 -0000 1.1 --- modifiers.nice 21 May 2005 16:24:58 -0000 1.2 *************** *** 126,129 **** --- 126,132 ---- { this.setModifier( INTERFACE ); + // "Every interface is implicitly abstract", + // The Java⢠Language Specification Third Edition, 9.1.1.1 + this.setModifier( ABSTRACT ); } *************** *** 152,156 **** if( this.getModifier( TRANSIENT ) ) buf.append(" transient"); if( this.getModifier( NATIVE ) ) buf.append(" native"); ! if( this.getModifier( ABSTRACT ) ) buf.append(" abstract"); return buf.toString(); } --- 155,160 ---- if( this.getModifier( TRANSIENT ) ) buf.append(" transient"); if( this.getModifier( NATIVE ) ) buf.append(" native"); ! if( ! this.getModifier( INTERFACE ) ) ! if( this.getModifier( ABSTRACT ) ) buf.append(" abstract"); return buf.toString(); } |