summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2006-01-03 13:34:58 +0000
committerMartin Odersky <odersky@gmail.com>2006-01-03 13:34:58 +0000
commitec25a32375121896a054a3428c3a7f5b1c867cee (patch)
tree729afdb00deee056567b5512233c3e3ac5b0e31f
parent4f8cb21ef3123f74b9344f4dde07ed9abe800a42 (diff)
downloadscala-ec25a32375121896a054a3428c3a7f5b1c867cee.tar.gz
scala-ec25a32375121896a054a3428c3a7f5b1c867cee.tar.bz2
scala-ec25a32375121896a054a3428c3a7f5b1c867cee.zip
-rw-r--r--src/compiler/scala/tools/nsc/Global.scala3
-rw-r--r--src/compiler/scala/tools/nsc/Settings.scala213
-rw-r--r--src/compiler/scala/tools/nsc/symtab/StdNames.scala2
-rw-r--r--src/compiler/scala/tools/nsc/transform/Erasure.scala13
-rw-r--r--src/library/scala/Array.scala16
-rw-r--r--src/library/scala/collection/mutable/PriorityQueue.scala2
-rw-r--r--src/library/scala/runtime/BoxedAnyArray.scala111
-rw-r--r--src/library/scala/runtime/BoxedArray.scala12
-rw-r--r--src/library/scala/runtime/ScalaRunTime.scala2
-rw-r--r--src/library/scala/runtime/compat/Platform.scala2
10 files changed, 239 insertions, 137 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala
index 8c2429985b..66b264a4ce 100644
--- a/src/compiler/scala/tools/nsc/Global.scala
+++ b/src/compiler/scala/tools/nsc/Global.scala
@@ -421,7 +421,8 @@ class Global(val settings: Settings, val reporter: Reporter) extends SymbolTable
val unit = new CompilationUnit(getSourceFile(file));
addUnit(unit);
var localPhase = firstPhase.asInstanceOf[GlobalPhase];
- while (localPhase.id < globalPhase.id || localPhase.id <= namerPhase.id) {
+ while ((localPhase.id < globalPhase.id || localPhase.id <= namerPhase.id) &&
+ reporter.errors == 0) {
atPhase(localPhase)(localPhase.applyPhase(unit));
localPhase = localPhase.next.asInstanceOf[GlobalPhase];
}
diff --git a/src/compiler/scala/tools/nsc/Settings.scala b/src/compiler/scala/tools/nsc/Settings.scala
index 9b76db2b9b..9cb74fd726 100644
--- a/src/compiler/scala/tools/nsc/Settings.scala
+++ b/src/compiler/scala/tools/nsc/Settings.scala
@@ -2,94 +2,95 @@
* Copyright 2005 LAMP/EPFL
* @author Martin Odersky
*/
-// $Id$
-package scala.tools.nsc;
+// $Id: Settings.scala
+package scala.tools.nsc
-import java.io.File;
+import java.io.File
+import System.getProperty
class Settings(error: String => unit) {
- private var allsettings: List[Setting] = List();
-
- private val classpathDefault = {
- val scalaCp = System.getProperty("scala.class.path");
- if (scalaCp != null) scalaCp + File.pathSeparator + "."
- else "."
- }
- private val bootclasspathDefault = {
- val javaBcp = System.getProperty("sun.boot.class.path");
- val scalaBcp = {
- val explicit = System.getProperty("scala.boot.class.path");
- if(explicit != null)
- explicit
- else {
- val scalaHome = System.getProperty("scala.home");
- if(scalaHome != null) {
- val guess = new File(new File(new File(scalaHome), "lib"), "scala-library.jar");
- if(guess.exists())
- guess.getPath()
- else
- null
- }
- else
- null
- }
- }
-
- if (javaBcp != null && scalaBcp != null) javaBcp + File.pathSeparator + scalaBcp
- else if (javaBcp != null) javaBcp
- else if (scalaBcp != null) scalaBcp
- else ""
- }
- private val extdirsDefault = {
- val javaExt = System.getProperty("java.ext.dirs");
- val scalaExt = System.getProperty("scala.ext.dirs");
- if (javaExt != null && scalaExt != null) javaExt + File.pathSeparator + scalaExt
- else if (javaExt != null) javaExt
- else if (scalaExt != null) scalaExt
- else ""
+ private var allsettings: List[Setting] = List()
+
+ private val classpathDefault =
+ alternatePath(
+ concatPath(
+ getProperty("java.class.path"),
+ getProperty("scala.class.path")),
+ ".")
+
+ private val bootclasspathDefault =
+ alternatePath(
+ concatPath(
+ getProperty("sun.boot.class.path"),
+ alternatePath(
+ getProperty("scala.boot.class.path"),
+ guessedScalaBootClassPath)),
+ "")
+
+ private val extdirsDefault =
+ alternatePath(
+ concatPath(
+ getProperty("java.ext.dirs"),
+ getProperty("scala.ext.dirs")),
+ "")
+
+ private def alternatePath(p1: String, p2: => String) =
+ if (p1 != null) p1 else p2
+
+ private def concatPath(p1: String, p2: String) =
+ if (p1 != null && p2 != null) p1 + File.pathSeparator + p2
+ else if (p1 != null) p1
+ else p2
+
+ private def guessedScalaBootClassPath = {
+ val scalaHome = System.getProperty("scala.home")
+ if (scalaHome != null) {
+ val guess = new File(new File(new File(scalaHome), "lib"), "scala-library.jar")
+ if (guess.exists()) guess.getPath() else null
+ } else null
}
- val debuginfo = BooleanSetting("-g", "Generate debugging info");
- val nowarnings = BooleanSetting("-nowarn", "Generate no warnings");
- val noassertions = BooleanSetting("-noassert", "Generate no assertions and assumptions");
- val verbose = BooleanSetting("-verbose", "Output messages about what the compiler is doing");
- val classpath = StringSetting ("-classpath", "path", "Specify where to find user class files", classpathDefault);
- val sourcepath = StringSetting ("-sourcepath", "path", "Specify where to find input source files", "");
- val bootclasspath = StringSetting ("-bootclasspath", "path", "Override location of bootstrap class files", bootclasspathDefault);
- val extdirs = StringSetting ("-extdirs", "dirs", "Override location of installed extensions", extdirsDefault);
- val outdir = StringSetting ("-d", "directory", "Specify where to place generated class files", "");
- val encoding = StringSetting ("-encoding", "encoding", "Specify character encoding used by source files", "ISO-8859-1");
- val separate = ChoiceSetting ("-separate", "Read symbol files for separate compilation", List("yes","no"), "default");
- val target = ChoiceSetting ("-target", "Specify which backend to use", List("jvm", "msil"), "jvm");
- val debug = BooleanSetting("-debug", "Output debugging messages");
- val statistics = BooleanSetting("-statistics", "Print compiler statistics");
- val explaintypes = BooleanSetting("-explaintypes", "Explain type errors in more detail");
- val resident = BooleanSetting("-resident", "Compiler stays resident, files to compile are read from standard input");
- val uniqid = BooleanSetting("-uniqid", "Print identifiers with unique names (debugging option)");
- val printtypes = BooleanSetting("-printtypes", "Print tree types (debugging option)");
- val prompt = BooleanSetting("-prompt", "Display a prompt after each error (debugging option)");
- val noimports = BooleanSetting("-noimports", "Compile without any implicit imports");
- val nopredefs = BooleanSetting("-nopredefs", "Compile without any implicit predefined values");
- val skip = PhasesSetting ("-skip", "Skip");
- val check = PhasesSetting ("-check", "Check the tree at start of");
- val print = PhasesSetting ("-print", "Print out program after");
- val printer = ChoiceSetting ("-printer", "Printer to use", List("text", "html"), "text");
- val printfile = StringSetting ("-printfile", "file", "Specify file in which to print trees", "-");
- val graph = PhasesSetting ("-graph", "Graph the program after");
- val browse = PhasesSetting ("-browse", "Browse the abstract syntax tree after");
- val stop = PhasesSetting ("-stop", "Stop after phase");
- val log = PhasesSetting ("-log", "Log operations in");
- val version = BooleanSetting("-version", "Print product version and exit");
- val help = BooleanSetting("-help", "Print a synopsis of standard options");
-
- val Xshowcls = StringSetting ("-Xshowcls", "class", "Show class info", "");
- val Xshowobj = StringSetting ("-Xshowobj", "object", "Show object info", "");
- val Xshowicode = BooleanSetting("-Xshowicode", "Print the generated ICode");
- val Xgadt = BooleanSetting("-Xgadt", "enable gadt for classes");
+ val debuginfo = BooleanSetting("-g", "Generate debugging info")
+ val nowarnings = BooleanSetting("-nowarn", "Generate no warnings")
+ val noassertions = BooleanSetting("-noassert", "Generate no assertions and assumptions")
+ val verbose = BooleanSetting("-verbose", "Output messages about what the compiler is doing")
+ val classpath = StringSetting ("-classpath", "path", "Specify where to find user class files", classpathDefault)
+ val sourcepath = StringSetting ("-sourcepath", "path", "Specify where to find input source files", "")
+ val bootclasspath = StringSetting ("-bootclasspath", "path", "Override location of bootstrap class files", bootclasspathDefault)
+ val extdirs = StringSetting ("-extdirs", "dirs", "Override location of installed extensions", extdirsDefault)
+ val outdir = StringSetting ("-d", "directory", "Specify where to place generated class files", "")
+ val encoding = StringSetting ("-encoding", "encoding", "Specify character encoding used by source files", "ISO-8859-1")
+ val separate = ChoiceSetting ("-separate", "Read symbol files for separate compilation", List("yes","no"), "default")
+ val target = ChoiceSetting ("-target", "Specify which backend to use", List("jvm", "msil"), "jvm")
+ val debug = BooleanSetting("-debug", "Output debugging messages")
+ val statistics = BooleanSetting("-statistics", "Print compiler statistics")
+ val explaintypes = BooleanSetting("-explaintypes", "Explain type errors in more detail")
+ val resident = BooleanSetting("-resident", "Compiler stays resident, files to compile are read from standard input")
+ val uniqid = BooleanSetting("-uniqid", "Print identifiers with unique names (debugging option)")
+ val printtypes = BooleanSetting("-printtypes", "Print tree types (debugging option)")
+ val prompt = BooleanSetting("-prompt", "Display a prompt after each error (debugging option)")
+ val noimports = BooleanSetting("-noimports", "Compile without any implicit imports")
+ val nopredefs = BooleanSetting("-nopredefs", "Compile without any implicit predefined values")
+ val skip = PhasesSetting ("-skip", "Skip")
+ val check = PhasesSetting ("-check", "Check the tree at start of")
+ val print = PhasesSetting ("-print", "Print out program after")
+ val printer = ChoiceSetting ("-printer", "Printer to use", List("text", "html"), "text")
+ val printfile = StringSetting ("-printfile", "file", "Specify file in which to print trees", "-")
+ val graph = PhasesSetting ("-graph", "Graph the program after")
+ val browse = PhasesSetting ("-browse", "Browse the abstract syntax tree after")
+ val stop = PhasesSetting ("-stop", "Stop after phase")
+ val log = PhasesSetting ("-log", "Log operations in")
+ val version = BooleanSetting("-version", "Print product version and exit")
+ val help = BooleanSetting("-help", "Print a synopsis of standard options")
+
+ val Xshowcls = StringSetting ("-Xshowcls", "class", "Show class info", "")
+ val Xshowobj = StringSetting ("-Xshowobj", "object", "Show object info", "")
+ val Xshowicode = BooleanSetting("-Xshowicode", "Print the generated ICode")
+ val Xgadt = BooleanSetting("-Xgadt", "enable gadt for classes")
/** A list of all settings */
- def allSettings: List[Setting] = allsettings.reverse;
+ def allSettings: List[Setting] = allsettings.reverse
/** A base class for settings of all types.
* Subclasses each define a `value' field of the appropriate type.
@@ -102,22 +103,22 @@ class Settings(error: String => unit) {
* issue error message and return empty.
* If first arg does not define this setting return args unchanged.
*/
- def tryToSet(args: List[String]): List[String];
+ def tryToSet(args: List[String]): List[String]
/** The syntax defining this setting in a help string */
- def helpSyntax: String = name;
+ def helpSyntax: String = name
/** A description of the purpose of this setting in a help string */
- def helpDescription = descr;
+ def helpDescription = descr
// initialization
- allsettings = this :: allsettings;
+ allsettings = this :: allsettings
}
/** A setting represented by a boolean flag (false, unless set) */
case class BooleanSetting(name: String, descr: String)
extends Setting(name, descr) {
- var value: boolean = false;
+ var value: boolean = false
def tryToSet(args: List[String]): List[String] = args match {
case n :: rest if (n == name) => value = true; rest
@@ -128,21 +129,21 @@ class Settings(error: String => unit) {
/** A setting represented by a string, (`default' unless set) */
case class StringSetting(name: String, arg: String, descr: String, default: String)
extends Setting(name, descr) {
- var value: String = default;
+ var value: String = default
def tryToSet(args: List[String]): List[String] = args match {
case n :: rest if (n == name) =>
if (rest.isEmpty) {
- error("missing argument");
+ error("missing argument")
List()
} else {
- value = rest.head;
+ value = rest.head
rest.tail
}
case _ => args
}
- override def helpSyntax = name + " <" + arg + ">";
+ override def helpSyntax = name + " <" + arg + ">"
}
/** A setting represented by a string in a given set of `choices',
@@ -150,26 +151,26 @@ class Settings(error: String => unit) {
*/
case class ChoiceSetting(name: String, descr: String, choices: List[String], default: String)
extends Setting(name, descr + choices.mkString(" (", ",", ")")) {
- var value: String = default;
+ var value: String = default
- private def argument: String = name.substring(1);
+ private def argument: String = name.substring(1)
def tryToSet(args: List[String]): List[String] = args match {
case n :: rest if (n startsWith (name + ":")) =>
- val choice = n.substring(name.length() + 1);
+ val choice = n.substring(name.length() + 1)
if (!(choices contains choice)) {
error(
if (choice == "") "missing " + argument
- else "unknown " + argument + " '" + choice + "'");
- List()
- } else {
- value = choice;
+ else "unknown " + argument + " '" + choice + "'")
+ List()
+ } else {
+ value = choice
rest
- }
+ }
case _ => args
}
- override def helpSyntax = name + ":<" + argument + ">";
+ override def helpSyntax = name + ":<" + argument + ">"
}
/** A setting represented by a list of strings which should be prefixes of
@@ -178,22 +179,22 @@ class Settings(error: String => unit) {
*/
case class PhasesSetting(name: String, descr: String)
extends Setting(name, descr + " <phases> (see below)") {
- var value: List[String] = List();
+ var value: List[String] = List()
def tryToSet(args: List[String]): List[String] = args match {
case n :: rest if (n startsWith (name + ":")) =>
- val phase = n.substring(name.length() + 1);
+ val phase = n.substring(name.length() + 1)
if (phase == "") {
- error("missing phase");
- List()
- } else {
- value = value ::: List(phase);
+ error("missing phase")
+ List()
+ } else {
+ value = value ::: List(phase)
rest
- }
+ }
case _ => args
}
- override def helpSyntax = name + ":<phase>";
+ override def helpSyntax = name + ":<phase>"
def contains(phasename: String): boolean =
value exists (str => phasename startsWith str)
diff --git a/src/compiler/scala/tools/nsc/symtab/StdNames.scala b/src/compiler/scala/tools/nsc/symtab/StdNames.scala
index 2b8b8692f5..d0bf3da3ac 100644
--- a/src/compiler/scala/tools/nsc/symtab/StdNames.scala
+++ b/src/compiler/scala/tools/nsc/symtab/StdNames.scala
@@ -202,6 +202,7 @@ import scala.tools.nsc.util.NameTransformer;
val String = newTermName("String");
val Symbol = newTermName("Symbol");
val Synthetic = newTermName("Synthetic");
+ val System = newTermName("System");
val Text = newTermName("Text");
val Throwable = newTermName("Throwable");
@@ -213,6 +214,7 @@ import scala.tools.nsc.util.NameTransformer;
val While = newTermName("While");
val apply = newTermName("apply");
val array = newTermName("array");
+ val arraycopy = newTermName("arraycopy");
val assert_ = newTermName("assert");
val assume_ = newTermName("assume");
val asInstanceOf = newTermName("asInstanceOf");
diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala
index ce2e17e149..8971d5787b 100644
--- a/src/compiler/scala/tools/nsc/transform/Erasure.scala
+++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala
@@ -531,6 +531,19 @@ abstract class Erasure extends AddInterfaces with typechecker.Analyzer {
case TypeApply(fun, args) if (fun.symbol.owner != AnyClass) =>
// leave all other type tests/type casts, remove all other type applications
fun
+ case Apply(fn, args) =>
+ def isGenericArray(tpe: Type): boolean = erasure(tpe).symbol == BoxedArrayClass
+ if (fn.hasSymbol &&
+ fn.symbol.name == nme.arraycopy &&
+ fn.symbol.owner.name == nme.System.toTypeName &&
+ fn.symbol.owner.owner == JavaLangPackage.tpe.symbol &&
+ args.length == 5 &&
+ (isGenericArray(args(0).tpe) || isGenericArray(args(2).tpe)))
+ unit.warning(tree.pos,
+ "System.arraycopy should be applied only to arrays with fixed element types;\n" +
+ "use Array.copy instead")
+ tree
+
case Template(parents, body) =>
assert(!currentOwner.isImplClass);
//System.out.println("checking no dble defs " + tree);//DEBUG
diff --git a/src/library/scala/Array.scala b/src/library/scala/Array.scala
index b1f15e1b6d..3a7ee2b575 100644
--- a/src/library/scala/Array.scala
+++ b/src/library/scala/Array.scala
@@ -10,6 +10,22 @@
package scala;
+import runtime._
+
+object Array {
+ def copy(src: AnyRef, srcPos: Int, dest: AnyRef, destPos: Int, length: Int): Unit = src match {
+ case xs: BoxedArray =>
+ xs.copyTo(srcPos, dest, destPos, length)
+ case _ =>
+ dest match {
+ case xs: BoxedArray =>
+ xs.copyFrom(src, srcPos, destPos, length)
+ case _ =>
+ System.arraycopy(src, srcPos, dest, destPos, length)
+ }
+ }
+}
+
final class Array[A](_length: Int) extends Cloneable with java.io.Serializable with Seq[A] {
def length: Int = throw new Error();
def apply(i: Int): A = throw new Error();
diff --git a/src/library/scala/collection/mutable/PriorityQueue.scala b/src/library/scala/collection/mutable/PriorityQueue.scala
index 83552417cc..e256d2dc5a 100644
--- a/src/library/scala/collection/mutable/PriorityQueue.scala
+++ b/src/library/scala/collection/mutable/PriorityQueue.scala
@@ -119,7 +119,7 @@ class PriorityQueue[A <% Ordered[A]] extends ResizableArray[A] with java.io.Seri
*/
override def elements: Iterator[A] = new Iterator[A] {
val as: Array[A] = new Array[A](size);
- java.lang.System.arraycopy(array, 0, as, 0, size);
+ Array.copy(array, 0, as, 0, size);
var i = size - 1;
def hasNext: Boolean = i > 0;
def next: A = {
diff --git a/src/library/scala/runtime/BoxedAnyArray.scala b/src/library/scala/runtime/BoxedAnyArray.scala
index ac37a62427..22d8a08385 100644
--- a/src/library/scala/runtime/BoxedAnyArray.scala
+++ b/src/library/scala/runtime/BoxedAnyArray.scala
@@ -23,21 +23,21 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray {
def apply(index: Int): Object = synchronized {
if (unboxed == null)
boxed(index);
- else if (elemTag == ScalaRunTime.IntTag)
+ else if (elemTag eq ScalaRunTime.IntTag)
BoxedInt.box(unboxed.asInstanceOf[Array[Int]](index))
- else if (elemTag == ScalaRunTime.DoubleTag)
+ else if (elemTag eq ScalaRunTime.DoubleTag)
BoxedDouble.box(unboxed.asInstanceOf[Array[Double]](index))
- else if (elemTag == ScalaRunTime.FloatTag)
+ else if (elemTag eq ScalaRunTime.FloatTag)
BoxedFloat.box(unboxed.asInstanceOf[Array[Float]](index))
- else if (elemTag == ScalaRunTime.LongTag)
+ else if (elemTag eq ScalaRunTime.LongTag)
BoxedLong.box(unboxed.asInstanceOf[Array[Long]](index))
- else if (elemTag == ScalaRunTime.CharTag)
+ else if (elemTag eq ScalaRunTime.CharTag)
BoxedChar.box(unboxed.asInstanceOf[Array[Char]](index))
- else if (elemTag == ScalaRunTime.ByteTag)
+ else if (elemTag eq ScalaRunTime.ByteTag)
BoxedByte.box(unboxed.asInstanceOf[Array[Byte]](index))
- else if (elemTag == ScalaRunTime.ShortTag)
+ else if (elemTag eq ScalaRunTime.ShortTag)
BoxedShort.box(unboxed.asInstanceOf[Array[Short]](index))
- else if (elemTag == ScalaRunTime.BooleanTag)
+ else if (elemTag eq ScalaRunTime.BooleanTag)
BoxedBoolean.box(unboxed.asInstanceOf[Array[Boolean]](index))
else
unboxed.asInstanceOf[Array[Object]](index)
@@ -46,21 +46,21 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray {
def update(index: Int, elem: Object): Unit = synchronized {
if (unboxed == null)
boxed(index) = elem;
- else if (elemTag == ScalaRunTime.IntTag)
+ else if (elemTag eq ScalaRunTime.IntTag)
unboxed.asInstanceOf[Array[Int]](index) = elem.asInstanceOf[BoxedNumber].intValue()
- else if (elemTag == ScalaRunTime.DoubleTag)
+ else if (elemTag eq ScalaRunTime.DoubleTag)
unboxed.asInstanceOf[Array[Double]](index) = elem.asInstanceOf[BoxedNumber].doubleValue()
- else if (elemTag == ScalaRunTime.FloatTag)
+ else if (elemTag eq ScalaRunTime.FloatTag)
unboxed.asInstanceOf[Array[Float]](index) = elem.asInstanceOf[BoxedNumber].floatValue()
- else if (elemTag == ScalaRunTime.LongTag)
+ else if (elemTag eq ScalaRunTime.LongTag)
unboxed.asInstanceOf[Array[Long]](index) = elem.asInstanceOf[BoxedNumber].longValue()
- else if (elemTag == ScalaRunTime.CharTag)
+ else if (elemTag eq ScalaRunTime.CharTag)
unboxed.asInstanceOf[Array[Char]](index) = elem.asInstanceOf[BoxedNumber].charValue()
- else if (elemTag == ScalaRunTime.ByteTag)
+ else if (elemTag eq ScalaRunTime.ByteTag)
unboxed.asInstanceOf[Array[Byte]](index) = elem.asInstanceOf[BoxedNumber].byteValue()
- else if (elemTag == ScalaRunTime.ShortTag)
+ else if (elemTag eq ScalaRunTime.ShortTag)
unboxed.asInstanceOf[Array[Short]](index) = elem.asInstanceOf[BoxedNumber].shortValue()
- else if (elemTag == ScalaRunTime.BooleanTag)
+ else if (elemTag eq ScalaRunTime.BooleanTag)
unboxed.asInstanceOf[Array[Boolean]](index) = elem.asInstanceOf[BoxedBoolean].value
else
unboxed.asInstanceOf[Array[Object]](index) = elem
@@ -69,7 +69,7 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray {
def unbox(elemTag: String): Object = synchronized {
if (unboxed == null) {
this.elemTag = elemTag;
- if (elemTag == ScalaRunTime.IntTag) {
+ if (elemTag eq ScalaRunTime.IntTag) {
val newvalue = new Array[Int](length);
var i = 0;
while (i < length) {
@@ -77,7 +77,7 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray {
i = i + 1
}
unboxed = newvalue;
- } else if (elemTag == ScalaRunTime.DoubleTag) {
+ } else if (elemTag eq ScalaRunTime.DoubleTag) {
val newvalue = new Array[Double](length);
var i = 0;
while (i < length) {
@@ -85,7 +85,7 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray {
i = i + 1
}
unboxed = newvalue;
- } else if (elemTag == ScalaRunTime.FloatTag) {
+ } else if (elemTag eq ScalaRunTime.FloatTag) {
val newvalue = new Array[Float](length);
var i = 0;
while (i < length) {
@@ -93,7 +93,7 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray {
i = i + 1
}
unboxed = newvalue;
- } else if (elemTag == ScalaRunTime.LongTag) {
+ } else if (elemTag eq ScalaRunTime.LongTag) {
val newvalue = new Array[Long](length);
var i = 0;
while (i < length) {
@@ -101,7 +101,7 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray {
i = i + 1
}
unboxed = newvalue;
- } else if (elemTag == ScalaRunTime.CharTag) {
+ } else if (elemTag eq ScalaRunTime.CharTag) {
val newvalue = new Array[Char](length);
var i = 0;
while (i < length) {
@@ -109,7 +109,7 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray {
i = i + 1
}
unboxed = newvalue;
- } else if (elemTag == ScalaRunTime.ByteTag) {
+ } else if (elemTag eq ScalaRunTime.ByteTag) {
val newvalue = new Array[Byte](length);
var i = 0;
while (i < length) {
@@ -117,7 +117,7 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray {
i = i + 1
}
unboxed = newvalue;
- } else if (elemTag == ScalaRunTime.ShortTag) {
+ } else if (elemTag eq ScalaRunTime.ShortTag) {
val newvalue = new Array[Short](length);
var i = 0;
while (i < length) {
@@ -125,7 +125,7 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray {
i = i + 1
}
unboxed = newvalue;
- } else if (elemTag == ScalaRunTime.BooleanTag) {
+ } else if (elemTag eq ScalaRunTime.BooleanTag) {
val newvalue = new Array[Boolean](length);
var i = 0;
while (i < length) {
@@ -147,8 +147,65 @@ final class BoxedAnyArray(val length: Int) extends BoxedArray {
override def equals(other: Any): Boolean = (
other.isInstanceOf[BoxedAnyArray] && (this eq (other.asInstanceOf[BoxedAnyArray])) ||
(if (unboxed == null) boxed == other else unboxed == other)
- );
+ )
- override def hashCode(): Int = hash;
-}
+ override def hashCode(): Int = hash
+
+ def value: Object = {
+ if (unboxed == null) throw new NotDefinedError("BoxedAnyArray.value")
+ unboxed
+ }
+
+ private def adapt(other: Object): Object =
+ if (this.unboxed == null)
+ other match {
+ case that: BoxedAnyArray =>
+ if (that.unboxed == null) {
+ that.boxed
+ } else {
+ if (ScalaRunTime.isValueTag(that.elemTag)) unbox(that.elemTag);
+ that.unboxed
+ }
+ case that: BoxedArray =>
+ adapt(that.value)
+ case that: Array[Int] =>
+ unbox(ScalaRunTime.IntTag); that
+ case that: Array[Double] =>
+ unbox(ScalaRunTime.DoubleTag); that
+ case that: Array[Float] =>
+ unbox(ScalaRunTime.FloatTag); that
+ case that: Array[Long] =>
+ unbox(ScalaRunTime.LongTag); that
+ case that: Array[Char] =>
+ unbox(ScalaRunTime.CharTag); that
+ case that: Array[Short] =>
+ unbox(ScalaRunTime.ShortTag); that
+ case that: Array[Byte] =>
+ unbox(ScalaRunTime.ByteTag); that
+ case that: Array[Boolean] =>
+ unbox(ScalaRunTime.BooleanTag); that
+ case _ =>
+ other
+ }
+ else
+ other match {
+ case that: BoxedAnyArray =>
+ if (that.unboxed != null) that.unboxed
+ else if (ScalaRunTime.isValueTag(this.elemTag)) that.unbox(this.elemTag)
+ else that.boxed
+ case that: BoxedArray =>
+ adapt(that.value)
+ case _ =>
+ other
+ }
+
+ override def copyFrom(src: Object, from: Int, to: Int, len: Int): Unit = {
+ val src1 = adapt(src)
+ Array.copy(src1, from, if (unboxed != null) unboxed else boxed, to, len)
+ }
+ override def copyTo(from: Int, dest: Object, to: Int, len: Int): Unit = {
+ var dest1 = adapt(dest)
+ Array.copy(if (unboxed != null) unboxed else boxed, from, dest1, to, len)
+ }
+}
diff --git a/src/library/scala/runtime/BoxedArray.scala b/src/library/scala/runtime/BoxedArray.scala
index 29b4ccf0e2..f33d62fc9b 100644
--- a/src/library/scala/runtime/BoxedArray.scala
+++ b/src/library/scala/runtime/BoxedArray.scala
@@ -1,7 +1,7 @@
/* __ *\
** ________ ___ / / ___ Scala API **
** / __/ __// _ | / / / _ | (c) 2002-2005, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | **
+** __\ \/ /__/ __ |/ /__/ __ | 2 **
** /____/\___/_/ |_/____/_/ | | **
** |/ **
\* */
@@ -42,4 +42,14 @@ abstract class BoxedArray extends PartialFunction[Int, Object] with Seq[Object]
def hasNext: Boolean = index < length;
def next: Object = { val i = index; index = i + 1; apply(i) }
}
+
+ /** The underlying array value
+ */
+ def value: Object;
+
+ def copyFrom(src: Object, from: Int, to: Int, len: Int): Unit =
+ Array.copy(src, from, value, to, len)
+
+ def copyTo(from: Int, dest: Object, to: Int, len: Int): Unit =
+ Array.copy(value, from, dest, to, len)
}
diff --git a/src/library/scala/runtime/ScalaRunTime.scala b/src/library/scala/runtime/ScalaRunTime.scala
index 8bdabef3c0..64bcbda839 100644
--- a/src/library/scala/runtime/ScalaRunTime.scala
+++ b/src/library/scala/runtime/ScalaRunTime.scala
@@ -22,6 +22,8 @@ object ScalaRunTime {
val DoubleTag = ".Double";
val BooleanTag = ".Boolean";
+ def isValueTag(tag: String) = tag.charAt(0) == '.'
+
trait Try[a] {
def Catch[b >: a](handler: PartialFunction[Throwable, b]): b;
def Finally(handler: Unit): a;
diff --git a/src/library/scala/runtime/compat/Platform.scala b/src/library/scala/runtime/compat/Platform.scala
index 7aa3870669..82ccf26065 100644
--- a/src/library/scala/runtime/compat/Platform.scala
+++ b/src/library/scala/runtime/compat/Platform.scala
@@ -13,7 +13,7 @@ package scala.runtime.compat;
object Platform {
def arraycopy(src: AnyRef, srcPos: Int, dest: AnyRef, destPos: Int, length: Int): Unit =
- System.arraycopy(src, srcPos, dest, destPos, length);
+ Array.copy(src, srcPos, dest, destPos, length)
def getClass(obj: AnyRef) = obj.getClass();
def getClassName(obj: AnyRef) = obj.getClass().getName();
def printStackTrace(exc: java.lang.Throwable) = exc.printStackTrace();