[Nice-commit] Nice/src/bossa/syntax TupleExp.java,1.15,1.16
Brought to you by:
bonniot
|
From: <bo...@us...> - 2003-03-17 20:12:18
|
Update of /cvsroot/nice/Nice/src/bossa/syntax
In directory sc8-pr-cvs1:/tmp/cvs-serv9380/src/bossa/syntax
Modified Files:
TupleExp.java
Log Message:
Correctly handle nested tuples involving primitive subtyping.
Index: TupleExp.java
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/TupleExp.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** TupleExp.java 7 Oct 2002 14:00:37 -0000 1.15
--- TupleExp.java 17 Mar 2003 20:11:43 -0000 1.16
***************
*** 82,85 ****
--- 82,86 ----
}
+ private Monotype[] components;
private Monotype[] expectedComponents;
***************
*** 90,104 ****
Constraint cst = Constraint.and(Polytype.getConstraint(types),
null, null);
! Monotype[] components = Polytype.getMonotype(types);
TupleType tupleType = new TupleType(components);
Types.setBytecodeType(components);
! this.componentType = Types.lowestCommonSupertype
! (expectedComponents != null ? expectedComponents : components);
type = new Polytype(cst, bossa.syntax.Monotype.sure(tupleType));
}
- private Type componentType;
-
/****************************************************************
* Code generation
--- 91,103 ----
Constraint cst = Constraint.and(Polytype.getConstraint(types),
null, null);
! components = Polytype.getMonotype(types);
TupleType tupleType = new TupleType(components);
Types.setBytecodeType(components);
! if (expectedComponents == null)
! expectedComponents = components;
type = new Polytype(cst, bossa.syntax.Monotype.sure(tupleType));
}
/****************************************************************
* Code generation
***************
*** 107,117 ****
protected gnu.expr.Expression compile()
{
! // force computation of componentType
getType();
int len = expressions.length;
! return new gnu.expr.ApplyExp
! (new nice.tools.code.LiteralArrayProc(new ArrayType(componentType), len),
bossa.syntax.Expression.compile(expressions));
}
--- 106,121 ----
protected gnu.expr.Expression compile()
{
! // Force computation of the component types.
getType();
int len = expressions.length;
! /*
! We base the array type on the expected type, but we record the
! real type of the components.
! */
! return nice.tools.code.TupleType.createExp
! (Types.lowestCommonSupertype(expectedComponents),
! Types.javaType(components),
bossa.syntax.Expression.compile(expressions));
}
***************
*** 119,125 ****
gnu.expr.Expression compileAssign(gnu.expr.Expression array)
{
- // force computation of componentType
- getType();
-
int len = expressions.length;
--- 123,126 ----
***************
*** 127,130 ****
--- 128,136 ----
Expression tupleExp;
+ Type arrayType = array.getType();
+ nice.tools.code.TupleType tupleType = null;
+ if (arrayType instanceof nice.tools.code.TupleType)
+ tupleType = (nice.tools.code.TupleType) arrayType;
+
// if array is a complex expression,
// we have to evaluate it and store the result
***************
*** 134,138 ****
let = new LetExp(new Expression[]{array});
Declaration tupleDecl = let.addDeclaration
! ("tupleRef", ArrayType.make(componentType));
//FIXME: CanRead should be set automatically.
--- 140,144 ----
let = new LetExp(new Expression[]{array});
Declaration tupleDecl = let.addDeclaration
! ("tupleRef", arrayType);
//FIXME: CanRead should be set automatically.
***************
*** 145,153 ****
Expression[] stmts = new Expression[len];
for (int i=0; i<len; i++)
! stmts[i] = expressions[i].compileAssign
! (new ApplyExp(new nice.lang.inline.ArrayGetOp(componentType),
! new Expression[]{
! tupleExp,
! intExp(i)}));
if (let != null)
--- 151,163 ----
Expression[] stmts = new Expression[len];
for (int i=0; i<len; i++)
! {
! Expression value = new ApplyExp
! (new nice.lang.inline.ArrayGetOp(null),
! new Expression[]{ tupleExp, intExp(i)});
! if (tupleType != null)
! value = nice.tools.code.EnsureTypeProc.ensure(value, tupleType.componentTypes[i]);
!
! stmts[i] = expressions[i].compileAssign(value);
! }
if (let != null)
|