[Nice-commit] Nice/src/bossa/syntax codegen.nice,NONE,1.1 customConstructor.nice,1.15,1.16 defaultco
Brought to you by:
bonniot
From: Arjan B. <ar...@us...> - 2005-01-13 14:06:29
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3726/F:/nice/src/bossa/syntax Modified Files: customConstructor.nice defaultconstructor.nice funexp.nice methodImplementation.nice niceMethod.nice Added Files: codegen.nice Log Message: Moved a few methods from nice.tools.code.Gen to bossa.syntax. Index: defaultconstructor.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/defaultconstructor.nice,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** defaultconstructor.nice 3 Jan 2005 01:24:28 -0000 1.4 --- defaultconstructor.nice 13 Jan 2005 14:06:15 -0000 1.5 *************** *** 98,102 **** let argsArray = args.toArray(); ! let lambda = nice.tools.code.Gen.createConstructor (thisDecl, argTypesArray, argsArray); lambda.setSuperCall(this.callSuper(thisExp, fullArgs, omitDefaults)); --- 98,102 ---- let argsArray = args.toArray(); ! let lambda = generateConstructor (thisDecl, argTypesArray, argsArray); lambda.setSuperCall(this.callSuper(thisExp, fullArgs, omitDefaults)); Index: niceMethod.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/niceMethod.nice,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** niceMethod.nice 12 Jan 2005 22:06:53 -0000 1.14 --- niceMethod.nice 13 Jan 2005 14:06:15 -0000 1.15 *************** *** 372,377 **** } ! res = nice.tools.code.Gen.createMethod ! (name, argTypes, retType, cast(def.getSymbols()), true, receiver != null); res.parameterCopies = cast(notNull(def.formalParameters()).getParameterCopies()); --- 372,377 ---- } ! res = generateMethod ! (name, argTypes, retType, def.getSymbols(), toplevel: true, member: receiver != null); res.parameterCopies = cast(notNull(def.formalParameters()).getParameterCopies()); Index: methodImplementation.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/methodImplementation.nice,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** methodImplementation.nice 12 Jan 2005 18:50:37 -0000 1.9 --- methodImplementation.nice 13 Jan 2005 14:06:15 -0000 1.10 *************** *** 166,175 **** private void createMethod(String bytecodeName) { ! compiledMethod = ! nice.tools.code.Gen.createMethod(bytecodeName, this.javaArgTypes(), notNull(declaration).javaReturnType(), ! cast(parameters), ! true, false); notNull(compiledMethod).addBytecodeAttribute --- 166,174 ---- private void createMethod(String bytecodeName) { ! compiledMethod = generateMethod(bytecodeName, this.javaArgTypes(), notNull(declaration).javaReturnType(), ! parameters, ! toplevel: true, member: false); notNull(compiledMethod).addBytecodeAttribute --- NEW FILE: codegen.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; /** Create a lambda expression to generate code for the method. @param args can be null if there are no arguments @param member true iff this method is a non-static member of the class in argTypes[0] @param toplevel If the method can be called from foreign code. This forces its generation even if it is apparently never called. */ public gnu.expr.LambdaExp generateMethod(?String bytecodeName, gnu.bytecode.Type[] argTypes, gnu.bytecode.Type retType, MonoSymbol[?] args, boolean toplevel, boolean member = false) { let res = new gnu.expr.LambdaExp(); generateMethod(res, bytecodeName, argTypes, retType, args, toplevel, member, false); return res; } public gnu.expr.ConstructorExp generateConstructor (gnu.expr.Declaration thisDecl, gnu.bytecode.Type[] argTypes, MonoSymbol[?] args) { let res = new gnu.expr.ConstructorExp(thisDecl); generateMethod(res, "<init>", argTypes, gnu.bytecode.Type.void_type, args, true, false, true); return res; } public gnu.expr.ConstructorExp generateCustomConstructor (gnu.bytecode.ClassType classType, gnu.bytecode.Type[] argTypes, MonoSymbol[?] args) { let res = new gnu.expr.ConstructorExp(classType); generateMethod(res, "<init>", argTypes, gnu.bytecode.Type.void_type, args, true, false, true); return res; } /** Create a lambda expression to generate code for the method. @param args can be null if there are no arguments @param member true iff this method is a non-static member of the class in argTypes[0] @param toplevel If the method can be called from foreign code. This forces its generation even if it is apparently never called. */ void generateMethod (gnu.expr.LambdaExp lexp, ?String bytecodeName, gnu.bytecode.Type[] argTypes, gnu.bytecode.Type retType, MonoSymbol[?] args, boolean toplevel, boolean member, boolean constructor) { bytecodeName = nice.tools.code.Strings.escape(bytecodeName); int arity = args == null ? 0 : args.length; lexp.setReturnType(retType); lexp.setName(bytecodeName); lexp.min_args = lexp.max_args = member ? arity - 1 : arity; lexp.forceGeneration(); if (toplevel) lexp.setCanCall(true); if (member) lexp.setClassMethod(true); // Parameters for (int n = 0; n < arity; n++) { boolean isThis = member && n == 0; String parameterName = notNull(args)[n].getName() == null ? "anonymous_" + n : notNull(notNull(args)[n].getName()).toString(); gnu.expr.Declaration d; if (isThis) { d = new gnu.expr.Declaration(parameterName); d.context = lexp; } else d = lexp.addDeclaration(parameterName); if (argTypes != null) d.setType(argTypes[n]); d.noteValue(null); notNull(args)[n].setDeclaration(d, isThis); } } Index: funexp.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/funexp.nice,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** funexp.nice 12 Jan 2005 18:50:37 -0000 1.6 --- funexp.nice 13 Jan 2005 14:06:15 -0000 1.7 *************** *** 116,124 **** compile() { ! gnu.expr.LambdaExp res = nice.tools.code.Gen.createMethod ! (null, nice.tools.code.Types.javaType(getMonotypes(formals)), nice.tools.code.Types.javaType(this.inferredReturnType()), ! cast(formals), false); nice.tools.code.Gen.setMethodBody(res, body.generateCode()); return res; --- 116,124 ---- compile() { ! gnu.expr.LambdaExp res = generateMethod ! (bytecodeName: null, nice.tools.code.Types.javaType(getMonotypes(formals)), nice.tools.code.Types.javaType(this.inferredReturnType()), ! formals, toplevel: false); nice.tools.code.Gen.setMethodBody(res, body.generateCode()); return res; Index: customConstructor.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/customConstructor.nice,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** customConstructor.nice 12 Jan 2005 22:06:53 -0000 1.15 --- customConstructor.nice 13 Jan 2005 14:06:15 -0000 1.16 *************** *** 99,104 **** generatingCode = true; ! let lambda = nice.tools.code.Gen.createCustomConstructor ! (cast(this.javaReturnType()), this.javaArgTypes(), cast(this.getSymbols())); nice.tools.code.Gen.setMethodBody(lambda, body.generateCode()); --- 99,104 ---- generatingCode = true; ! let lambda = generateCustomConstructor ! (cast(this.javaReturnType()), this.javaArgTypes(), this.getSymbols()); nice.tools.code.Gen.setMethodBody(lambda, body.generateCode()); |