[Nice-commit] Nice/src/gnu/expr InstantiateProc.java,1.2,1.3 InitializeProc.java,1.1,1.2 Constructor
Brought to you by:
bonniot
From: <bo...@us...> - 2003-12-14 16:52:36
|
Update of /cvsroot/nice/Nice/src/gnu/expr In directory sc8-pr-cvs1:/tmp/cvs-serv3719/src/gnu/expr Modified Files: InstantiateProc.java InitializeProc.java ConstructorExp.java Log Message: Resolve, typecheck and generate code for custom constructors. Index: InstantiateProc.java =================================================================== RCS file: /cvsroot/nice/Nice/src/gnu/expr/InstantiateProc.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** InstantiateProc.java 2 Sep 2002 16:11:53 -0000 1.2 --- InstantiateProc.java 14 Dec 2003 16:52:32 -0000 1.3 *************** *** 54,57 **** --- 54,62 ---- args[i].compile(comp, types[i]); + // Add dummy arguments to match the bytecode constructor. + if (method !=null) + for (int i = 0; i < method.dummyArgs; i++) + code.emitPushInt(0); + code.emitInvokeSpecial(constructor); target.compileFromStack(comp, type); Index: InitializeProc.java =================================================================== RCS file: /cvsroot/nice/Nice/src/gnu/expr/InitializeProc.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** InitializeProc.java 2 Sep 2002 11:46:51 -0000 1.1 --- InitializeProc.java 14 Dec 2003 16:52:32 -0000 1.2 *************** *** 27,40 **** public InitializeProc (Method constructor) { this.constructor = constructor; } public InitializeProc (ConstructorExp method) { ! this.method = method; } private Method constructor; private ConstructorExp method; public void compile (ApplyExp exp, Compilation comp, Target target) --- 27,61 ---- public InitializeProc (Method constructor) { + this(constructor, false); + } + + /** + @param implicitThis true if a 'this' argument should be added + during the call. + */ + public InitializeProc (Method constructor, boolean implicitThis) + { this.constructor = constructor; + this.implicitThis = implicitThis; } public InitializeProc (ConstructorExp method) { ! this(method, false); ! } ! ! /** ! @param implicitThis true if a 'this' argument should be added ! during the call. ! */ ! public InitializeProc (ConstructorExp method, boolean implicitThis) ! { ! this.method = method; ! this.implicitThis = implicitThis; } private Method constructor; private ConstructorExp method; + private boolean implicitThis; public void compile (ApplyExp exp, Compilation comp, Target target) *************** *** 47,53 **** Type[] types = constructor.getParameterTypes(); ! args[0].compile(comp, Target.pushObject); ! for (int i = 1; i < args.length; i++) ! args[i].compile(comp, types[i - 1]); code.emitInvokeSpecial(constructor); --- 68,84 ---- Type[] types = constructor.getParameterTypes(); ! int arg = 0; ! int type = 0; ! if (implicitThis) ! code.emitPushThis(); ! else ! args[arg++].compile(comp, Target.pushObject); ! for (; arg < args.length; arg++) ! args[arg].compile(comp, types[type++]); ! ! // Add dummy arguments to match the bytecode constructor. ! if (method != null) ! for (int i = 0; i < method.dummyArgs; i++) ! code.emitPushInt(0); code.emitInvokeSpecial(constructor); Index: ConstructorExp.java =================================================================== RCS file: /cvsroot/nice/Nice/src/gnu/expr/ConstructorExp.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ConstructorExp.java 13 Dec 2003 17:52:01 -0000 1.4 --- ConstructorExp.java 14 Dec 2003 16:52:32 -0000 1.5 *************** *** 69,76 **** --- 69,94 ---- args[itype++] = var.getType().getImplementationType(); + // Make sure the signature is unique + if (! primary) + { + do + { + Type[] newArgs = new Type[args.length + 1]; + System.arraycopy(args, 0, newArgs, 0, args.length); + newArgs[args.length] = Type.int_type; + args = newArgs; + dummyArgs++; + addDeclaration("dummy"); + } + while (ctype.getDeclaredMethod("<init>", args) != null); + } + Method method = ctype.addMethod ("<init>", args, Type.void_type, Access.PUBLIC); primMethods = new Method[] { method }; } + + /** Number of dummy arguments added to make the signature unique. */ + int dummyArgs = 0; void enterFunction (Compilation comp) |