[Nice-commit] Nice/src/bossa/syntax pattern.nice,1.5,1.6 NiceClass.java,1.86,1.87 DefaultConstructor
Brought to you by:
bonniot
From: Daniel B. <bo...@us...> - 2004-10-09 09:29:06
|
Update of /cvsroot/nice/Nice/src/bossa/syntax In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18206/src/bossa/syntax Modified Files: pattern.nice NiceClass.java DefaultConstructor.java Log Message: Compile initializers in a $init method that is called after all constructors have been executed so that the instance is valid. (This implies that code in proper constructors cannot capture 'this' anymore, hence the simplification of gnu.expr.ConstructorExp) Index: NiceClass.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/NiceClass.java,v retrieving revision 1.86 retrieving revision 1.87 diff -C2 -d -r1.86 -r1.87 *** NiceClass.java 7 Oct 2004 15:29:28 -0000 1.86 --- NiceClass.java 9 Oct 2004 09:28:41 -0000 1.87 *************** *** 476,480 **** } ! public int nbInitializers() { return initializers.length; } private void resolveIntitializers() --- 476,480 ---- } ! private int nbInitializers() { return initializers.length; } private void resolveIntitializers() *************** *** 511,522 **** private gnu.expr.Expression thisExp; ! void setThisExp(gnu.expr.Expression thisExp) ! { ! this.thisExp = thisExp; ! } ! gnu.expr.Expression compileInitializer(int index) { ! return initializers[index].generateCode(); } --- 511,556 ---- private gnu.expr.Expression thisExp; ! /** ! Reference to the method performing instance initialization for this class. ! */ ! private gnu.expr.Expression initializer; ! gnu.expr.Expression getInitializer() { ! if (initializer != null) ! return initializer; ! ! gnu.expr.Expression parentInitializer = null; ! NiceClass parent = this.getParent(); ! if (parent != null) ! { ! parentInitializer = parent.getInitializer(); ! } ! ! if (nbInitializers() == 0 && parentInitializer == null) ! return null; ! ! gnu.expr.Expression[] params = new gnu.expr.Expression[1]; ! gnu.expr.LambdaExp lambda = Gen.createMemberMethod ! ("$init", classe.getType(), null, gnu.bytecode.Type.void_type, params); ! thisExp = params[0]; ! ! int nPrefix = parentInitializer == null ? 0 : 1; ! gnu.expr.Expression[] body = new gnu.expr.Expression ! [nPrefix + nbInitializers()]; ! ! // Call the parent initializer if present ! if (parentInitializer != null) ! body[0] = Gen.superCall ! (parentInitializer, new gnu.expr.Expression[]{ thisExp }); ! ! // Compile the initializers of this class ! for (int i = 0; i < nbInitializers(); i++) ! body[nPrefix + i] = initializers[i].generateCode(); ! ! Gen.setMethodBody(lambda, new gnu.expr.BeginExp(body)); ! initializer = addJavaMethod(lambda); ! ! return initializer; } *************** *** 626,632 **** gnu.expr.Expression[] params = new gnu.expr.Expression[1]; gnu.expr.LambdaExp lambda = createJavaMethod("clone", cloneMethod, params); ! Gen.setMethodBody(lambda, ! new gnu.expr.ApplyExp(new gnu.expr.QuoteExp(gnu.expr.PrimProcedure.specialCall(cloneMethod)), params)); ! addJavaMethod(lambda); } --- 660,666 ---- gnu.expr.Expression[] params = new gnu.expr.Expression[1]; gnu.expr.LambdaExp lambda = createJavaMethod("clone", cloneMethod, params); ! Gen.setMethodBody ! (lambda, new gnu.expr.ApplyExp(Gen.superCaller(cloneMethod), params)); ! addJavaMethod(lambda); } *************** *** 1019,1022 **** --- 1053,1070 ---- } + public Definition importMethod(gnu.bytecode.Method method) + { + if (method.isConstructor()) + return ImportedConstructor.load(this, method); + + if (method.getArity() == 0 && method.getName().equals("$init")) + { + initializer = Gen.superCaller(method); + return null; + } + + return null; + } + /**************************************************************** * Misc. Index: pattern.nice =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/pattern.nice,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** pattern.nice 7 Oct 2004 22:03:44 -0000 1.5 --- pattern.nice 9 Oct 2004 09:28:41 -0000 1.6 *************** *** 409,413 **** if (p.exactlyAt) ! return nice.tools.code.Gen.isOfClass(parameter, ct); return nice.tools.code.Gen.instanceOfExp(parameter, ct); --- 409,413 ---- if (p.exactlyAt) ! return nice.tools.code.Gen.isOfClass(parameter, ct, true); return nice.tools.code.Gen.instanceOfExp(parameter, ct); Index: DefaultConstructor.java =================================================================== RCS file: /cvsroot/nice/Nice/src/bossa/syntax/DefaultConstructor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** DefaultConstructor.java 7 Oct 2004 15:29:29 -0000 1.1 --- DefaultConstructor.java 9 Oct 2004 09:28:41 -0000 1.2 *************** *** 180,184 **** MonoSymbol[] fullArgs, boolean omitDefaults) { ! int len = fields.length + classe.nbInitializers(); if (len == 0) --- 180,185 ---- MonoSymbol[] fullArgs, boolean omitDefaults) { ! Expression initializer = classe.getInitializer(); ! int len = fields.length + (initializer == null ? 0 : 1); if (len == 0) *************** *** 204,210 **** } ! classe.setThisExp(thisExp); ! for (int i = 0; i < classe.nbInitializers(); i++) ! body[fields.length + i] = classe.compileInitializer(i); return new BeginExp(body); --- 205,220 ---- } ! if (initializer != null) ! { ! Expression isDirectInstance = ! Gen.isOfClass(thisExp, classe.classe.getType(), false); ! ! body[fields.length] = ! new gnu.expr.IfExp ! (isDirectInstance, ! new gnu.expr.ApplyExp ! (initializer, new Expression[]{ thisExp }), ! QuoteExp.voidExp); ! } return new BeginExp(body); |