[Nice-commit] Nice/src/nice/tools/code MultiArrayNewProc.java,1.5,1.6 LiteralArrayProc.java,1.8,1.9
Brought to you by:
bonniot
From: Daniel B. <bo...@us...> - 2004-07-02 15:15:10
|
Update of /cvsroot/nice/Nice/src/nice/tools/code In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23127/src/nice/tools/code Modified Files: MultiArrayNewProc.java LiteralArrayProc.java Log Message: For literal arrays and tuples without a specified type, promote byte and short to int. Index: MultiArrayNewProc.java =================================================================== RCS file: /cvsroot/nice/Nice/src/nice/tools/code/MultiArrayNewProc.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** MultiArrayNewProc.java 20 Feb 2003 00:21:44 -0000 1.5 --- MultiArrayNewProc.java 2 Jul 2004 15:14:58 -0000 1.6 *************** *** 51,55 **** args[i].compile(comp, Type.int_type); ! arrayType = creationType(arrayType, target); comp.getCode().emitNewArray(arrayType.getComponentType(), nbDimensions); --- 51,55 ---- args[i].compile(comp, Type.int_type); ! arrayType = creationType(arrayType, target, false); comp.getCode().emitNewArray(arrayType.getComponentType(), nbDimensions); *************** *** 59,75 **** /** Decide the bytecode type to create a new array with, given its computed type and the target. */ ! static ArrayType creationType(ArrayType computedType, Target target) { if (target.getType() instanceof ArrayType) { ArrayType targetType = (ArrayType) target.getType(); ! /* ! By well-typing, we know the target type is a super-type of the computed type. If the target has primitive components, we might as well ! use that type to produce better code, since subsumption would need copying otherwise. ! On the other hand, it would be incorrect (and useless) for reference types, in case the arrays comes back in the value of a function. --- 59,78 ---- /** Decide the bytecode type to create a new array with, given its computed type and the target. + + @param promote whether promotion of component types is desired. */ ! static ArrayType creationType(ArrayType computedType, Target target, ! boolean promote) { if (target.getType() instanceof ArrayType) { ArrayType targetType = (ArrayType) target.getType(); ! /* ! By well-typing, we know the target type is a super-type of the computed type. If the target has primitive components, we might as well ! use that type to produce better code, since subsumption would need copying otherwise. ! On the other hand, it would be incorrect (and useless) for reference types, in case the arrays comes back in the value of a function. *************** *** 78,82 **** return targetType; } ! return computedType; } --- 81,91 ---- return targetType; } ! ! if (promote) ! // We don't have information about the context. The sensible thing to do ! // is to promote primitive types (those smaller than int). ! return promoteComponent(computedType); ! else ! return computedType; } *************** *** 89,92 **** --- 98,126 ---- } + /** Recursively promote the component of the given array. */ + private static ArrayType promoteComponent(ArrayType array) + { + Type type = array.getComponentType(); + + // Is the type subject to promotion? + Type promoted; + + if (type == Type.byte_type || type == Type.short_type) + promoted = Type.int_type; + + // If not directly, is it an array whose component type is? + else if (type.isArray()) + promoted = promoteComponent((ArrayType) type); + + else + promoted = type; + + // If the component is changed, return a new array. + if (promoted != type) + return SpecialArray.create(promoted); + + return array; + } + public Type getReturnType(Expression[] args) { Index: LiteralArrayProc.java =================================================================== RCS file: /cvsroot/nice/Nice/src/nice/tools/code/LiteralArrayProc.java,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** LiteralArrayProc.java 21 Jun 2004 17:08:37 -0000 1.8 --- LiteralArrayProc.java 2 Jul 2004 15:14:59 -0000 1.9 *************** *** 42,49 **** private int nbElements; private boolean wrapAsCollection; ! public void compile (ApplyExp exp, Compilation comp, Target target) { ! arrayType = MultiArrayNewProc.creationType(arrayType, target); Expression[] args = exp.getArgs(); --- 42,50 ---- private int nbElements; private boolean wrapAsCollection; ! public void compile (ApplyExp exp, Compilation comp, Target target) { ! // The type was not specified explicitely, so we allow promotion. ! arrayType = MultiArrayNewProc.creationType(arrayType, target, true); Expression[] args = exp.getArgs(); |