Update of /cvsroot/nice/Nice/src/bossa/syntax
In directory sc8-pr-cvs1:/tmp/cvs-serv14314/src/bossa/syntax
Modified Files:
PrimitiveType.java LiteralArrayExp.java
Log Message:
Allow inhomogenous literal arrays (with type Object[]).
Index: PrimitiveType.java
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/PrimitiveType.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** PrimitiveType.java 5 Dec 2003 17:52:30 -0000 1.8
--- PrimitiveType.java 8 Dec 2003 19:42:37 -0000 1.9
***************
*** 172,175 ****
--- 172,185 ----
static Polytype voidPolytype, boolPolytype, bytePolytype, shortPolytype, intPolytype, longPolytype;
+ private static Polytype objectPolytype;
+ static Polytype objectPolytype()
+ {
+ if (objectPolytype == null)
+ objectPolytype = new Polytype(mlsub.typing.Constraint.True,
+ Monotype.sure(TopMonotype.instance));
+
+ return objectPolytype;
+ }
+
public static TypeConstructor maybeTC, sureTC, nullTC;
Index: LiteralArrayExp.java
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/syntax/LiteralArrayExp.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -C2 -d -r1.15 -r1.16
*** LiteralArrayExp.java 28 May 2003 12:57:26 -0000 1.15
--- LiteralArrayExp.java 8 Dec 2003 19:42:37 -0000 1.16
***************
*** 41,53 ****
{
Polytype elementType = Polytype.union(getType(elements));
! this.type = new Polytype
(elementType.getConstraint(),
bossa.syntax.Monotype.sure(new MonotypeConstructor
(PrimitiveType.arrayTC, new Monotype[]{elementType.getMonotype()})));
!
! nice.tools.code.Types.setBytecodeType(this.type);
}
!
/****************************************************************
* Code generation
--- 41,66 ----
{
Polytype elementType = Polytype.union(getType(elements));
+
+ type = array(elementType);
+
+ // If the type cannot be simplified, it must be because elements
+ // have incomparable types. In this case, we give the array the type
+ // Object[].
+ if (! type.trySimplify())
+ type = array(PrimitiveType.objectPolytype());
! nice.tools.code.Types.setBytecodeType(type);
! }
!
! private Polytype array(Polytype elementType)
! {
! Polytype res = new Polytype
(elementType.getConstraint(),
bossa.syntax.Monotype.sure(new MonotypeConstructor
(PrimitiveType.arrayTC, new Monotype[]{elementType.getMonotype()})));
! res.setNotSimplified();
! return res;
}
!
/****************************************************************
* Code generation
|