From 339b74629196e1c1a81f78924c09dc77b12c147a Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Thu, 27 Nov 2014 16:25:47 +0100 Subject: Add test for backend. --- tests/pos/HelloWorld.scala | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tests/pos/HelloWorld.scala (limited to 'tests/pos') diff --git a/tests/pos/HelloWorld.scala b/tests/pos/HelloWorld.scala new file mode 100644 index 000000000..0f260a77d --- /dev/null +++ b/tests/pos/HelloWorld.scala @@ -0,0 +1,3 @@ +object HelloWorld { + def main(args: Array[String]): Unit = println("hello world") +} -- cgit v1.2.3 From f78ef2ca72a1b70db98fa9f6a44bf81d33f3ff28 Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Mon, 1 Dec 2014 15:40:33 +0100 Subject: Label test with nested cycles and simple patterns. --- test/dotc/tests.scala | 1 + tests/pos/Labels.scala | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 tests/pos/Labels.scala (limited to 'tests/pos') diff --git a/test/dotc/tests.scala b/test/dotc/tests.scala index fc15d3a30..2fe6be757 100644 --- a/test/dotc/tests.scala +++ b/test/dotc/tests.scala @@ -130,6 +130,7 @@ class tests extends CompilerTest { @Test def tools_io = compileDir(dotcDir + "tools/io", twice) @Test def helloWorld = compileFile(posDir, "HelloWorld", doEmitBytecode) + @Test def labels = compileFile(posDir, "Labels", doEmitBytecode) //@Test def tools = compileDir(dotcDir + "tools", "-deep" :: Nil)(allowDeepSubtypes) @Test def testNonCyclic = compileArgs(Array( diff --git a/tests/pos/Labels.scala b/tests/pos/Labels.scala new file mode 100644 index 000000000..4a84175af --- /dev/null +++ b/tests/pos/Labels.scala @@ -0,0 +1,21 @@ +object Labels { + def main(args: Array[String]): Unit = { + var i = 10 + while(i>0) { + var j = 0 + while(j0) => println("one") + case t@2 => println("two" + t) + case _ => println("default") + } +} -- cgit v1.2.3 From d23cab1dcff8c28d4817f3dccfefbc8cb58f017f Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Mon, 1 Dec 2014 16:58:53 +0100 Subject: Handle Arrays in backend. --- .../tools/backend/jvm/DottyBackendInterface.scala | 7 ++++++- src/dotty/tools/backend/jvm/scalaPrimitives.scala | 23 ++++++++++++++++++---- tests/pos/Arrays.scala | 8 ++++++++ 3 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 tests/pos/Arrays.scala (limited to 'tests/pos') 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} + } } diff --git a/tests/pos/Arrays.scala b/tests/pos/Arrays.scala new file mode 100644 index 000000000..751652002 --- /dev/null +++ b/tests/pos/Arrays.scala @@ -0,0 +1,8 @@ +object Arrays{ + def main(a: Array[String]) = { + val stringArr = new Array[String](1) + stringArr(0) = "foo" + val intArr = new Array[Int](1) + stringArr(0) = intArr(0).toString + } +} -- cgit v1.2.3