Thread: [Nice-commit] Nice/src/gnu/expr MemberLambdaExp.java,NONE,1.1 ConstructorExp.java,1.7,1.8 ApplyExp.j
Brought to you by:
bonniot
From: Daniel B. <bo...@us...> - 2004-10-09 09:29:05
|
Update of /cvsroot/nice/Nice/src/gnu/expr In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv18206/src/gnu/expr Modified Files: ConstructorExp.java ApplyExp.java Added Files: MemberLambdaExp.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: ApplyExp.java =================================================================== RCS file: /cvsroot/nice/Nice/src/gnu/expr/ApplyExp.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** ApplyExp.java 6 Nov 2003 14:30:31 -0000 1.10 --- ApplyExp.java 9 Oct 2004 09:28:41 -0000 1.11 *************** *** 14,17 **** --- 14,20 ---- boolean tailCall; + /** true if this is a special (super) call. */ + boolean special; + /** Containing LambdaExp. */ LambdaExp context; *************** *** 27,31 **** public final void setTailCall(boolean tailCall) { this.tailCall = tailCall; } ! public ApplyExp (Expression f, Expression[] a) { func = f; args = a; } public ApplyExp (Procedure p, Expression[] a) { func = new QuoteExp(p); args = a; } --- 30,37 ---- public final void setTailCall(boolean tailCall) { this.tailCall = tailCall; } ! public ApplyExp (Expression f, Expression[] a) { this(f, a, false); } ! ! public ApplyExp (Expression f, Expression[] a, boolean special) ! { func = f; args = a; this.special = special; } public ApplyExp (Procedure p, Expression[] a) { func = new QuoteExp(p); args = a; } *************** *** 237,241 **** argTypes, varArgs, func_name, func_lambda, comp); ! code.emitInvoke(method); target.compileFromStack(comp, func_lambda.getReturnType()); return; --- 243,250 ---- argTypes, varArgs, func_name, func_lambda, comp); ! if (exp.special) ! code.emitInvokeSpecial(method); ! else ! code.emitInvoke(method); target.compileFromStack(comp, func_lambda.getReturnType()); return; --- NEW FILE: MemberLambdaExp.java --- /**************************************************************************/ /* 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 gnu.expr; import gnu.bytecode.*; /** A LambdaExp member of a class (with a this argument). @author Daniel Bonniot (bo...@us...) */ public class MemberLambdaExp extends LambdaExp { public MemberLambdaExp(Declaration thisDecl) { this.thisDecl = thisDecl; thisDecl.context = this; } private Declaration thisDecl; void enterFunction (Compilation comp) { // Do the normal stuff. super.enterFunction(comp); // Save 'this' if it is captured if (thisDecl.field != null) { CodeAttr code = comp.getCode(); thisDecl.loadOwningObject(comp); code.emitPushThis(); code.emitPutField(thisDecl.field); } } } Index: ConstructorExp.java =================================================================== RCS file: /cvsroot/nice/Nice/src/gnu/expr/ConstructorExp.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ConstructorExp.java 22 Dec 2003 01:30:59 -0000 1.7 --- ConstructorExp.java 9 Oct 2004 09:28:41 -0000 1.8 *************** *** 93,117 **** { if (primary) ! { ! // The super call has to come before anything else. ! superCall.compile(comp, Target.Ignore); ! ! // Do the normal stuff. ! super.enterFunction(comp); ! ! // Save 'this' if it is captured ! if (thisDecl.field != null) ! { ! CodeAttr code = comp.getCode(); ! thisDecl.loadOwningObject(comp); ! code.emitPushThis(); ! code.emitPutField(thisDecl.field); ! } ! } ! else ! { ! // nothing special to do for custom constructors. ! super.enterFunction(comp); ! } } } --- 93,101 ---- { if (primary) ! // The super call has to come before anything else. ! superCall.compile(comp, Target.Ignore); ! ! // Do the normal stuff. ! super.enterFunction(comp); } } |