diff options
author | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2014-12-01 16:58:53 +0100 |
---|---|---|
committer | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2014-12-16 13:15:01 +0100 |
commit | d23cab1dcff8c28d4817f3dccfefbc8cb58f017f (patch) | |
tree | c8807828b910bc8953079d1e00619d6cbb12e8b9 /src/dotty/tools/backend/jvm | |
parent | 6446bbb41c48c91388373e5221b9874c676ccbfd (diff) | |
download | dotty-d23cab1dcff8c28d4817f3dccfefbc8cb58f017f.tar.gz dotty-d23cab1dcff8c28d4817f3dccfefbc8cb58f017f.tar.bz2 dotty-d23cab1dcff8c28d4817f3dccfefbc8cb58f017f.zip |
Handle Arrays in backend.
Diffstat (limited to 'src/dotty/tools/backend/jvm')
-rw-r--r-- | src/dotty/tools/backend/jvm/DottyBackendInterface.scala | 7 | ||||
-rwxr-xr-x | src/dotty/tools/backend/jvm/scalaPrimitives.scala | 23 |
2 files changed, 25 insertions, 5 deletions
diff --git a/src/dotty/tools/backend/jvm/DottyBackendInterface.scala b/src/dotty/tools/backend/jvm/DottyBackendInterface.scala index eb82e010e..c4b86719d 100644 --- a/src/dotty/tools/backend/jvm/DottyBackendInterface.scala +++ b/src/dotty/tools/backend/jvm/DottyBackendInterface.scala @@ -134,12 +134,17 @@ class DottyBackendInterface()(implicit ctx: Context) extends BackendInterface{ (x, Erasure.Boxing.boxMethod(x.asClass)) }.toMap def unboxMethods: Map[Symbol, Symbol] = defn.ScalaValueClasses.map(x => (x, Erasure.Boxing.unboxMethod(x.asClass))).toMap + + private val mkArrayNames: Set[String] = Set("Byte", "Float", "Char", "Double", "Boolean", "Unit", "Long", "Int", "Short", "Ref") + + override lazy val syntheticArrayConstructors: Set[Symbol] = mkArrayNames.map(nm => ctx.requiredMethod(toDenot(defn.DottyArraysModule).moduleClass.asClass, s"new${nm}Array")) + def isBox(sym: Symbol): Boolean = Erasure.Boxing.isBox(sym) def isUnbox(sym: Symbol): Boolean = Erasure.Boxing.isUnbox(sym) val primitives: Primitives = new Primitives { val primitives = new DottyPrimitives(ctx) - def getPrimitive(methodSym: Symbol, reciever: Type): Int = primitives.getPrimitive(methodSym, reciever) + def getPrimitive(app: Apply, reciever: Type): Int = primitives.getPrimitive(app, reciever) def getPrimitive(sym: Symbol): Int = primitives.getPrimitive(sym) diff --git a/src/dotty/tools/backend/jvm/scalaPrimitives.scala b/src/dotty/tools/backend/jvm/scalaPrimitives.scala index 150e672c7..feb74faf5 100755 --- a/src/dotty/tools/backend/jvm/scalaPrimitives.scala +++ b/src/dotty/tools/backend/jvm/scalaPrimitives.scala @@ -7,8 +7,11 @@ package dotty.tools.dotc package backend.jvm import dotty.tools.backend.jvm.GenBCodePipeline +import dotty.tools.dotc.ast.Trees.{Select, Apply} +import dotty.tools.dotc.ast.tpd import dotty.tools.dotc.core.Names.TermName -import dotty.tools.dotc.core.Types.{ErrorType, Type} +import dotty.tools.dotc.core.StdNames._ +import dotty.tools.dotc.core.Types.{JavaArrayType, ErrorType, Type} import scala.collection.{ mutable, immutable } @@ -52,12 +55,22 @@ class DottyPrimitives(ctx: Context) { * @param tpe The type of the receiver object. It is used only for array * operations */ - def getPrimitive(fun: Symbol, tpe: Type)(implicit ctx: Context): Int = { + def getPrimitive(app: tpd.Apply, tpe: Type)(implicit ctx: Context): Int = { + val fun = app.fun.symbol val defn = ctx.definitions - val code = getPrimitive(fun) + val code = app.fun match { + case Select(_, nme.primitive.arrayLength) => + LENGTH + case Select(_, nme.primitive.arrayUpdate) => + UPDATE + case Select(_, nme.primitive.arrayApply) => + APPLY + case _ => getPrimitive(fun) + } def elementType: Type = tpe.widenDealias match { case defn.ArrayType(el) => el + case JavaArrayType(el) => el case _ => ctx.error(s"expected Array $tpe") ErrorType @@ -391,7 +404,9 @@ class DottyPrimitives(ctx: Context) { primitives.toMap } - def isPrimitive(sym: Symbol): Boolean = primitives contains sym + def isPrimitive(sym: Symbol): Boolean = { + (primitives contains sym) || sym == NoSymbol // the only trees that do not have a symbol assigned are array.{update,select,length} + } } |