diff options
author | Miguel Garcia <miguelalfredo.garcia@epfl.ch> | 2012-03-06 19:09:50 +0100 |
---|---|---|
committer | Miguel Garcia <miguelalfredo.garcia@epfl.ch> | 2012-03-06 19:09:50 +0100 |
commit | 0f24917e19a57cdf19075e36a06b8fd6c12d42ec (patch) | |
tree | 273e7028624e9adfecfee7fba26ec952901c8441 /src/compiler | |
parent | 97e78b8720f851a190ca001341e0d633eeae3120 (diff) | |
download | scala-0f24917e19a57cdf19075e36a06b8fd6c12d42ec.tar.gz scala-0f24917e19a57cdf19075e36a06b8fd6c12d42ec.tar.bz2 scala-0f24917e19a57cdf19075e36a06b8fd6c12d42ec.zip |
factoring out repetitive work
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/icode/Opcodes.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala | 47 |
2 files changed, 43 insertions, 6 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/icode/Opcodes.scala b/src/compiler/scala/tools/nsc/backend/icode/Opcodes.scala index 2bcfb9d4a9..ec6c631bd1 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/Opcodes.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/Opcodes.scala @@ -350,6 +350,7 @@ trait Opcodes { self: ICodes => } case class BOX(boxType: TypeKind) extends Instruction { + assert(boxType.isValueType && (boxType ne UNIT)) // documentation override def toString(): String = "BOX " + boxType override def consumed = 1 override def consumedTypes = boxType :: Nil @@ -357,6 +358,7 @@ trait Opcodes { self: ICodes => } case class UNBOX(boxType: TypeKind) extends Instruction { + assert(boxType.isValueType && (boxType ne UNIT)) // documentation override def toString(): String = "UNBOX " + boxType override def consumed = 1 override def consumedTypes = ObjectReference :: Nil diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala index e5392251b7..dda221e9b9 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala @@ -231,11 +231,47 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with vp } + private def helperBoxTo(kind: ValueTypeKind): Tuple2[String, JMethodType] = { + val boxedType = definitions.boxedClass(kind.toType.typeSymbol) + val mtype = new JMethodType(javaType(boxedType), Array(javaType(kind))) + + Pair("boxTo" + boxedType.decodedName, mtype) + } + + private val jBoxTo: Map[TypeKind, Tuple2[String, JMethodType]] = Map( + BOOL -> helperBoxTo(BOOL) , + BYTE -> helperBoxTo(BYTE) , + CHAR -> helperBoxTo(CHAR) , + SHORT -> helperBoxTo(SHORT) , + INT -> helperBoxTo(INT) , + LONG -> helperBoxTo(LONG) , + FLOAT -> helperBoxTo(FLOAT) , + DOUBLE -> helperBoxTo(DOUBLE) + ) + + private def helperUnboxTo(kind: ValueTypeKind): Tuple2[String, JMethodType] = { + val mtype = new JMethodType(javaType(kind), Array(JAVA_LANG_OBJECT)) + val mname = "unboxTo" + kind.toType.typeSymbol.decodedName + + Pair(mname, mtype) + } + + private val jUnboxTo: Map[TypeKind, Tuple2[String, JMethodType]] = Map( + BOOL -> helperUnboxTo(BOOL) , + BYTE -> helperUnboxTo(BYTE) , + CHAR -> helperUnboxTo(CHAR) , + SHORT -> helperUnboxTo(SHORT) , + INT -> helperUnboxTo(INT) , + LONG -> helperUnboxTo(LONG) , + FLOAT -> helperUnboxTo(FLOAT) , + DOUBLE -> helperUnboxTo(DOUBLE) + ) + var clasz: IClass = _ var method: IMethod = _ var jclass: JClass = _ var jmethod: JMethod = _ -// var jcode: JExtendedCode = _ + // var jcode: JExtendedCode = _ def isParcelableClass = isAndroidParcelableClass(clasz.symbol) def isRemoteClass = clasz.symbol hasAnnotation RemoteAttr @@ -1355,13 +1391,12 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with genCallMethod(call) case BOX(kind) => - val boxedType = definitions.boxedClass(kind.toType.typeSymbol) - val mtype = new JMethodType(javaType(boxedType), Array(javaType(kind))) - jcode.emitINVOKESTATIC(BoxesRunTime, "boxTo" + boxedType.decodedName, mtype) + val Pair(mname, mtype) = jBoxTo(kind) + jcode.emitINVOKESTATIC(BoxesRunTime, mname, mtype) case UNBOX(kind) => - val mtype = new JMethodType(javaType(kind), Array(JAVA_LANG_OBJECT)) - jcode.emitINVOKESTATIC(BoxesRunTime, "unboxTo" + kind.toType.typeSymbol.decodedName, mtype) + val Pair(mname, mtype) = jUnboxTo(kind) + jcode.emitINVOKESTATIC(BoxesRunTime, mname, mtype) case NEW(REFERENCE(cls)) => val className = javaName(cls) |