Update of /cvsroot/nice/Nice/src/bossa/syntax
In directory sc8-pr-cvs1:/tmp/cvs-serv27562/src/bossa/syntax
Modified Files:
CustomConstructor.java
Log Message:
Allow custom constructors to call other custom constructors.
Index: CustomConstructor.java
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/CustomConstructor.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** CustomConstructor.java 15 Dec 2003 02:40:17 -0000 1.7
--- CustomConstructor.java 15 Dec 2003 16:19:47 -0000 1.8
***************
*** 41,51 ****
}
CustomConstructor(NiceClass def, FormalParameters parameters)
{
! super(new LocatedString("<init>", def.definition.location()),
! Constraint.True,
! returnType(def.definition.getName()),
! parameters,
! Contract.noContract);
classe = def;
}
--- 41,61 ----
}
+ void addConstructorCallSymbol()
+ {
+ mlsub.typing.Polytype type = new mlsub.typing.Polytype
+ (getType().getConstraint(),
+ new mlsub.typing.FunType(getArgTypes(), PrimitiveType.voidType));
+ classe.addConstructorCallSymbol
+ (new MethodDeclaration.Symbol(name, type) {
+ gnu.expr.Expression compileInCallPosition()
+ {
+ return getInitializationCode();
+ }
+ });
+ }
+
CustomConstructor(NiceClass def, FormalParameters parameters)
{
! this(def.definition.getName(), parameters);
classe = def;
}
***************
*** 69,72 ****
--- 79,84 ----
}
+ abstract gnu.expr.Expression getInitializationCode();
+
NiceClass classe;
***************
*** 92,95 ****
--- 104,109 ----
classe = NiceClass.get(tc);
+ addConstructorCallSymbol();
+
// Save the scopes, since we need them later, but they get null'ed.
thisScope = scope;
***************
*** 149,158 ****
--- 163,180 ----
classe.getClassExp().addMethod(lambda);
lambda.addBytecodeAttribute(parameters.asBytecodeAttribute());
+ initializationCode = new QuoteExp(new InitializeProc(lambda, true));
return new QuoteExp(new InstantiateProc(lambda));
}
+ gnu.expr.Expression getInitializationCode()
+ {
+ getCode();
+ return initializationCode;
+ }
+
LocatedString className;
Statement body;
+ gnu.expr.Expression initializationCode;
}
***************
*** 184,187 ****
--- 206,210 ----
{
TypeConstructors.addConstructor(classe.definition.tc, this);
+ addConstructorCallSymbol();
}
***************
*** 190,193 ****
--- 213,222 ----
int dummyArgs = method.arg_types.length - arity;
return new QuoteExp(new InstantiateProc(method, dummyArgs));
+ }
+
+ gnu.expr.Expression getInitializationCode()
+ {
+ int dummyArgs = method.arg_types.length - arity;
+ return new QuoteExp(new InitializeProc(method, true, dummyArgs));
}
|