Update of /cvsroot/nice/Nice/src/bossa/syntax
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19198/F:/nice/src/bossa/syntax
Modified Files:
Module.java niceMethod.nice
Log Message:
Make the Module interface not depend on NiceMethod.
Index: niceMethod.nice
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/niceMethod.nice,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** niceMethod.nice 29 Dec 2004 23:10:48 -0000 1.4
--- niceMethod.nice 31 Dec 2004 20:23:32 -0000 1.5
***************
*** 183,187 ****
getFullName() = module.getName() + '.' + name + ':' + this.getType();
! computeCode() = module.getDispatchMethod(this);
getLambda() = nice.tools.code.Gen.dereference(this.getCode());
--- 183,187 ----
getFullName() = module.getName() + '.' + name + ':' + this.getType();
! computeCode() = getDispatchMethod(this, module);
getLambda() = nice.tools.code.Gen.dereference(this.getCode());
***************
*** 313,314 ****
--- 313,380 ----
(name, constraint, returnType, params, body, contract, isOverride);
}
+
+ public gnu.expr.Expression getDispatchMethod(NiceMethod def, Module module)
+ {
+ String name = def.getName().toString();
+ gnu.expr.LambdaExp res;
+ gnu.bytecode.Type[] argTypes;
+ gnu.bytecode.Type retType;
+
+ /*
+ If this package is not recompiled,
+ we fetch the bytecode type information
+ from the previous dispatch class.
+ Benefits: we get the most precise bytecode type for methods,
+ as computed during the initial compilation.
+ This would not be the case if we recomputed it,
+ as the precise types are found during typechecking.
+ */
+ ?gnu.bytecode.Method meth = module.lookupDispatchClassMethod(name, "id", def.getFullName());
+ if (meth != null) // Reuse existing dispatch method header
+ {
+ // The dispatch code will have to be regenerated anyway
+ meth.eraseCode();
+
+ argTypes = notNull(meth.arg_types);
+ retType = notNull(meth.return_type);
+ // Make sure we use the same bytecode name, since compiled code
+ // can rely on it.
+ name = meth.getName();
+ }
+ else // Get type information from the nice declaration
+ {
+ argTypes = def.javaArgTypes();
+ retType = def.javaReturnType();
+ }
+
+ // Try to compile the dispatch method as a member method if possible.
+ ?NiceClass receiver;
+ if (argTypes.length == 0)
+ receiver = null;
+ else
+ {
+ receiver = NiceClass.get(def.getArgTypes()[0]);
+
+ // JVM interfaces cannot contain code.
+ if (receiver != null && receiver.isInterface())
+ receiver = null;
+
+ // Special treatment for serialization at the moment.
+ if (def.getArity() == 2 &&
+ (name.equals("writeObject")||name.equals("readObject")))
+ receiver = null;
+ }
+
+ res = nice.tools.code.Gen.createMethod
+ (name, argTypes, retType, def.getSymbols(), true, receiver != null);
+ res.parameterCopies = def.formalParameters().getParameterCopies();
+
+ // add unique information to disambiguate which method this represents
+ res.addBytecodeAttribute
+ (new gnu.bytecode.MiscAttr("id", def.getFullName().getBytes()));
+
+ if (receiver != null)
+ return receiver.addJavaMethod(res);
+ else
+ return module.addMethod(res, false);
+ }
Index: Module.java
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/Module.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -C2 -d -r1.21 -r1.22
*** Module.java 19 Dec 2004 19:58:28 -0000 1.21
--- Module.java 31 Dec 2004 20:23:31 -0000 1.22
***************
*** 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);
--- 32,36 ----
gnu.bytecode.ClassType createClass(String name);
void addGlobalVar(gnu.expr.Declaration declaration, boolean constant);
! gnu.bytecode.Method lookupDispatchClassMethod(String name, String attribute, String value);
gnu.expr.ReferenceExp addMethod(gnu.expr.LambdaExp method,
boolean packageMethod);
|