diff options
Diffstat (limited to 'src/dotnet-library')
-rw-r--r-- | src/dotnet-library/scala/Console.scala | 39 | ||||
-rw-r--r-- | src/dotnet-library/scala/Math.scala | 5 | ||||
-rw-r--r-- | src/dotnet-library/scala/Predef.scala | 36 | ||||
-rw-r--r-- | src/dotnet-library/scala/compat/Platform.scala | 22 | ||||
-rw-r--r-- | src/dotnet-library/scala/runtime/RichChar.scala | 20 | ||||
-rw-r--r-- | src/dotnet-library/scala/runtime/RichDouble.scala | 2 | ||||
-rw-r--r-- | src/dotnet-library/scala/runtime/RichFloat.scala | 2 | ||||
-rw-r--r-- | src/dotnet-library/scala/runtime/RichString.scala | 4 | ||||
-rw-r--r-- | src/dotnet-library/scala/runtime/ScalaRunTime.scala | 149 | ||||
-rw-r--r-- | src/dotnet-library/scala/util/Fluid.scala | 1 |
10 files changed, 98 insertions, 182 deletions
diff --git a/src/dotnet-library/scala/Console.scala b/src/dotnet-library/scala/Console.scala index b599a0151e..900f8f18e3 100644 --- a/src/dotnet-library/scala/Console.scala +++ b/src/dotnet-library/scala/Console.scala @@ -12,10 +12,9 @@ package scala +import Predef._ import scala.util.Fluid import System.IO.{TextReader,TextWriter} -import compat.Platform -import Predef._ /** The <code>Console</code> object implements functionality for * printing Scala values on the terminal. There are also functions @@ -108,11 +107,11 @@ object Console { * output (i.e. output not terminated by a new line character) has * to be made visible on the terminal. */ - def flush: Unit = out.Flush() + def flush(): Unit = out.Flush() /** Print a new line character on the terminal. */ - def println: Unit = out.WriteLine() + def println(): Unit = out.WriteLine() /** Print out an object followed by a new line character. * @@ -152,7 +151,7 @@ object Console { * * @return the string read from the terminal. */ - def readLine: String = in.ReadLine(); + def readLine(): String = in.ReadLine(); /** Print a formatted text and read a full line from the terminal * @@ -162,7 +161,7 @@ object Console { */ def readLine(text: String, args: Any*): String = { format(text, args: _*) - readLine + readLine() } @@ -170,7 +169,7 @@ object Console { * * @return the boolean value read from the terminal. */ - def readBoolean: Boolean = readLine.toLowerCase() match { + def readBoolean(): Boolean = readLine().toLowerCase() match { case "true" => true case "t" => true case "yes" => true @@ -180,27 +179,31 @@ object Console { /** Read a byte value from the terminal. */ - def readByte: Byte = readLine.toByte + def readByte(): Byte = readLine().toByte /** Read a short value from the terminal. */ - def readShort: Short = readLine.toShort + def readShort(): Short = readLine.toShort /** Read a char value from the terminal. */ - def readChar: Char = readLine charAt 0 + def readChar(): Char = readLine() charAt 0 + + /** Read an int value from the terminal. + */ + def readInt(): Int = readLine().toInt /** Read an int value from the terminal. */ - def readInt: Int = readLine.toInt + def readLong(): Long = readLine().toLong /** Read a float value from the terminal. */ - def readFloat: Float = readLine.toFloat + def readFloat(): Float = readLine().toFloat /** Read a double value from the terminal. */ - def readDouble: Double = readLine.toDouble + def readDouble(): Double = readLine().toDouble // /** Read in some structured input, specified by a format specifier. // * See class <code>java.text.MessageFormat</code> for details of @@ -210,7 +213,7 @@ object Console { // * @return a list of all extracted values. // */ // def readf(format: String): List[Any] = -// textComponents(new MessageFormat(format).parse(in.readLine())) +// textComponents(new MessageFormat(format).parse(readLine())) // /** Read in some structured input, specified by a format specifier. // * Opposed to <code>readf</code>, this function only returns the @@ -230,9 +233,9 @@ object Console { // * @param format ... // * @return ... // */ -// def readf2(format: String): Pair[Any, Any] = { +// def readf2(format: String): (Any, Any) = { // val res = readf(format) -// Pair(res.head, res.tail.head) +// (res.head, res.tail.head) // } // /** Read in some structured input, specified by a format specifier. @@ -243,9 +246,9 @@ object Console { // * @param format ... // * @return ... // */ -// def readf3(format: String): Triple[Any, Any, Any] = { +// def readf3(format: String): (Any, Any, Any) = { // val res = readf(format) -// Triple(res.head, res.tail.head, res.tail.tail.head) +// (res.head, res.tail.head, res.tail.tail.head) // } // private def textComponents(a: Array[AnyRef]): List[Any] = { diff --git a/src/dotnet-library/scala/Math.scala b/src/dotnet-library/scala/Math.scala index d653aa2d25..731b4c001d 100644 --- a/src/dotnet-library/scala/Math.scala +++ b/src/dotnet-library/scala/Math.scala @@ -11,6 +11,9 @@ package scala + +import Predef._ + object Math { val E = System.Math.E @@ -35,7 +38,7 @@ object Math { //def rint(x: Double): Double = System.Math.rint(x) def atan2(x: Double, y: Double): Double = System.Math.Atan2(x, y) def pow(x: Double, y: Double): Double = System.Math.Pow(x, y) - //def round(x: Float): Int = System.Math.Round(x).toSingle + def round(x: Float): Int = System.Math.Round(x).toInt def round(x: Double): Long = System.Math.Round(x).toLong def abs(x: Int): Int = System.Math.Abs(x) def abs(x: Long): Long = System.Math.Abs(x) diff --git a/src/dotnet-library/scala/Predef.scala b/src/dotnet-library/scala/Predef.scala index 485e2474c7..142181d91f 100644 --- a/src/dotnet-library/scala/Predef.scala +++ b/src/dotnet-library/scala/Predef.scala @@ -1,7 +1,7 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2006, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** +** / __/ __// _ | / / / _ | (c) 2002-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ @@ -41,6 +41,7 @@ object Predef { type String = System.String type StringBuilder = compat.StringBuilder type Class = System.Type + type Runnable = scala.runtime.Runnable type Throwable = System.Exception type Exception = System.Exception @@ -79,22 +80,22 @@ object Predef { throw new Throwable() } - def assert(assertion: Boolean): Unit = { + def assert(assertion: Boolean) { if (!assertion) throw new Error("assertion failed") } - def assert(assertion: Boolean, message: Any): Unit = { + def assert(assertion: Boolean, message: Any) { if (!assertion) throw new Error("assertion failed: " + message) } - def assume(assumption: Boolean): Unit = { + def assume(assumption: Boolean) { if (!assumption) throw new Error("assumption failed") } - def assume(assumption: Boolean, message: Any): Unit = { + def assume(assumption: Boolean, message: Any) { if (!assumption) throw new Error("assumption failed: " + message) } @@ -128,6 +129,29 @@ object Predef { def Tuple[a1, a2, a3, a4, a5, a6, a7, a8](x1: a1, x2: a2, x3: a3, x4: a4, x5: a5, x6: a6, x7: a7, x8: a8) = Tuple8(x1, x2, x3, x4, x5, x6, x7, x8) def Tuple[a1, a2, a3, a4, a5, a6, a7, a8, a9](x1: a1, x2: a2, x3: a3, x4: a4, x5: a5, x6: a6, x7: a7, x8: a8, x9: a9) = Tuple9(x1, x2, x3, x4, x5, x6, x7, x8, x9) + // printing and reading ---------------------------------------------- + + def print(x: Any) = Console.print(x) + def println() = Console.println() + def println(x: Any) = Console.println(x) + //def printf(text: String, xs: Any*) = Console.printf(text, xs: _*) + //def format(text: String, xs: Any*) = Console.format(text, xs) + + def readLine(): String = Console.readLine() + def readLine(text: String, args: Any*) = Console.readLine(text, args) + def readBoolean() = Console.readBoolean() + def readByte() = Console.readByte() + def readShort() = Console.readShort() + def readChar() = Console.readChar() + def readInt() = Console.readInt() + def readLong() = Console.readLong() + def readFloat() = Console.readFloat() + def readDouble() = Console.readDouble() + //def readf(format: String) = Console.readf(format) + //def readf1(format: String) = Console.readf1(format) + //def readf2(format: String) = Console.readf2(format) + //def readf3(format: String) = Console.readf3(format) + // views ------------------------------------------------------------- implicit def identity[a](x: a): a = x diff --git a/src/dotnet-library/scala/compat/Platform.scala b/src/dotnet-library/scala/compat/Platform.scala index 0e3ddee96b..161423bedb 100644 --- a/src/dotnet-library/scala/compat/Platform.scala +++ b/src/dotnet-library/scala/compat/Platform.scala @@ -1,7 +1,7 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2006, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** +** / __/ __// _ | / / / _ | (c) 2002-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ @@ -12,19 +12,32 @@ package scala.compat -import Predef.Class +import Predef._ object Platform { type StackOverflowError = System.StackOverflowException + /** + * @param src .. + * @param srcPos .. + * @param dest .. + * @param destPos .. + * @param length .. + */ def arraycopy(src: AnyRef, srcPos: Int, dest: AnyRef, destPos: Int, length: Int): Unit = { if (!src.isInstanceOf[System.Array]) throw new Exception("src for arraycopy is not an Array; use scala.Array.copy for boxed arrays"); if (!dest.isInstanceOf[System.Array]) throw new Exception("dest for arraycopy is not an Array; use scala.Array.copy for boxed arrays"); System.Array.Copy(src.asInstanceOf[System.Array], srcPos, dest.asInstanceOf[System.Array], destPos, length) } - /** create array of the same type as arrayInstance with the given length */ + /** Create array of the same type as arrayInstance with the given + * length. + * + * @param elemClass .. + * @param length .. + * @return .. + */ def createArray(elemClass: Class, length: Int): AnyRef = System.Array.CreateInstance(elemClass, length); @@ -37,3 +50,4 @@ object Platform { def collectGarbage: Unit = System.GC.Collect() } + diff --git a/src/dotnet-library/scala/runtime/RichChar.scala b/src/dotnet-library/scala/runtime/RichChar.scala index 687dd644c2..27633065d3 100644 --- a/src/dotnet-library/scala/runtime/RichChar.scala +++ b/src/dotnet-library/scala/runtime/RichChar.scala @@ -1,7 +1,7 @@ /* __ *\ ** ________ ___ / / ___ Scala API ** ** / __/ __// _ | / / / _ | (c) 2006-2007, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** ** /____/\___/_/ |_/____/_/ | | ** ** |/ ** \* */ @@ -13,6 +13,22 @@ package scala.runtime import Predef.NoSuchElementException +/** <p> + * For example, in the following code + * </p> + * <pre> + * <b>object</b> test <b>extends</b> Application { + * Console.println(<chr>'\40'</chr>.isWhitespace) + * Console.println('\011'.isWhitespace) + * Console.println('1'.asDigit == 1) + * Console.println('A'.asDigit == 10) + * }</pre> + * <p> + * the implicit conversions are performed using the predefined view + * <a href="../Predef$object.html#charWrapper(scala.Char)" + * target="contentFrame"><code>Predef.charWrapper</code></a>. + * </p> + */ final class RichChar(x: Char) extends Proxy with Ordered[Char] { // Proxy.self def self: Any = x @@ -35,7 +51,7 @@ final class RichChar(x: Char) extends Proxy with Ordered[Char] { def to(y: Char): Iterator[Char] = new BufferedIterator[Char] { private var ch = x def hasNext: Boolean = ch < y - def next: Char = + def next(): Char = if (hasNext) { val j = ch; ch = (ch + 1).toChar; j } else throw new NoSuchElementException("next on empty iterator") def head: Char = diff --git a/src/dotnet-library/scala/runtime/RichDouble.scala b/src/dotnet-library/scala/runtime/RichDouble.scala index ebe61ead50..77ae930cd4 100644 --- a/src/dotnet-library/scala/runtime/RichDouble.scala +++ b/src/dotnet-library/scala/runtime/RichDouble.scala @@ -24,6 +24,8 @@ final class RichDouble(x: Double) extends Proxy with Ordered[Double] { def max(y: Double): Double = Math.max(x, y) def abs: Double = Math.abs(x) + def round: Long = Math.round(x) + def isNaN: Boolean = System.Double.IsNaN(x) def isInfinity: Boolean = System.Double.IsInfinity(x) def isPosInfinity: Boolean = System.Double.IsPositiveInfinity(x) diff --git a/src/dotnet-library/scala/runtime/RichFloat.scala b/src/dotnet-library/scala/runtime/RichFloat.scala index 6c58d92910..a480cc5b9b 100644 --- a/src/dotnet-library/scala/runtime/RichFloat.scala +++ b/src/dotnet-library/scala/runtime/RichFloat.scala @@ -24,6 +24,8 @@ final class RichFloat(x: Float) extends Proxy with Ordered[Float] { def max(y: Float) = Math.max(x, y) def abs: Float = Math.abs(x) + def round: Int = Math.round(x) + def isNaN: Boolean = System.Single.IsNaN(x) def isInfinity: Boolean = System.Single.IsInfinity(x) def isPosInfinity: Boolean = System.Single.IsPositiveInfinity(x) diff --git a/src/dotnet-library/scala/runtime/RichString.scala b/src/dotnet-library/scala/runtime/RichString.scala index a8fd5b7411..0e0fc90ab1 100644 --- a/src/dotnet-library/scala/runtime/RichString.scala +++ b/src/dotnet-library/scala/runtime/RichString.scala @@ -79,8 +79,8 @@ final class RichString(val self: String) extends Proxy with Seq[Char] with Order def linesWithSeparators = new Iterator[String] { val len = self.length var index = 0 - def hasNext: Boolean = index <= len - def next: String = { + def hasNext: Boolean = index < len + def next(): String = { if (index >= len) throw new NoSuchElementException("next on empty iterator") val start = index while (index < len && !isLineBreak(apply(index))) index = index + 1 diff --git a/src/dotnet-library/scala/runtime/ScalaRunTime.scala b/src/dotnet-library/scala/runtime/ScalaRunTime.scala deleted file mode 100644 index 6a94c4f56e..0000000000 --- a/src/dotnet-library/scala/runtime/ScalaRunTime.scala +++ /dev/null @@ -1,149 +0,0 @@ -/* __ *\ -** ________ ___ / / ___ Scala API ** -** / __/ __// _ | / / / _ | (c) 2002-2007, LAMP/EPFL ** -** __\ \/ /__/ __ |/ /__/ __ | ** -** /____/\___/_/ |_/____/_/ | | ** -** |/ ** -\* */ - -// $Id$ - - -package scala.runtime - - -import Predef._ - -/* The object <code>ScalaRunTime</code> provides ... - */ -object ScalaRunTime { - - /** Names for primitive types, used by array unboxing */ - val ByteTag = ".Byte" - val ShortTag = ".Short" - val CharTag = ".Char" - val IntTag = ".Int" - val LongTag = ".Long" - val FloatTag = ".Float" - val DoubleTag = ".Double" - val BooleanTag = ".Boolean" - - import Predef.classOf; - - val ByteTYPE = classOf[System.Byte] - val ShortTYPE = classOf[System.Int16] - val CharTYPE = classOf[System.Char] - val IntTYPE = classOf[System.Int32] - val LongTYPE = classOf[System.Int64] - val FloatTYPE = classOf[System.Single] - val DoubleTYPE = classOf[System.Double] - val BooleanTYPE = classOf[System.Boolean] - val UnitTYPE = classOf[System.Void] - - def isArray(x:AnyRef): Boolean = x.getClass().isArray() - def isValueTag(tag: String) = tag.charAt(0) == '.' - def isValueClass(clazz: Class) = clazz.isPrimitive() - - abstract class Try[a] { - def Catch[b >: a](handler: PartialFunction[Throwable, b]): b - def Finally(handler: Unit): a - } - - def Try[a](block: => a): Try[a] = new Try[a] with Runnable { - var result: a = _ - var exception: Throwable = ExceptionHandling.tryCatch(this) - - def run(): Unit = result = block - - def Catch[b >: a](handler: PartialFunction[Exception, b]): b = - if (exception eq null) - result.asInstanceOf[b] - // !!! else if (exception is LocalReturn) - // !!! // ... - else if (handler isDefinedAt exception) - handler(exception) - else - throw exception - - def Finally(handler: Unit): a = - if (exception eq null) - result.asInstanceOf[a] - else - throw exception - } - - def caseFields(x: Product): List[Any] = { - val arity = x.arity - def fields(from: Int): List[Any] = - if (from == arity) List() - else x.element(from) :: fields(from + 1) - fields(0) - } - - def _toString(x: Product): String = - caseFields(x).mkString(x.productPrefix + "(", ",", ")") - - def _hashCode(x: Product): Int = { - var code = x.getClass().hashCode() - val arr = x.arity - var i = 0 - while (i < arr) { - code = code * 41 + x.element(i).hashCode() - i = i + 1 - } - code - } - - def _equals(x: Product, y: Any): Boolean = y match { - case y1: Product if x.arity == y1.arity => - val arity = x.arity - var i = 0 - while (i < arity && x.element(i) == y1.element(i)) - i = i + 1 - i == arity - case _ => - false - } - - def _equalsWithVarArgs(x: Product, y: Any): Boolean = y match { - case y1: Product if x.arity == y1.arity => - val arity = x.arity - var i = 0 - while (i < arity - 1 && x.element(i) == y1.element(i)) - i = i + 1; - i == arity - 1 && { - x.element(i) match { - case xs: Seq[_] => - y1.element(i) match { - case ys: Seq[_] => xs sameElements ys - } - } - } - case _ => - false - } - - //def checkDefined[T >: Null](x: T): T = - // if (x == null) throw new UndefinedException else x - - def Seq[a](xs: a*): Seq[a] = null // interpreted specially by new backend. - - def arrayValue(x: BoxedArray, elemTag: String): AnyRef = - if (x eq null) null else x.unbox(elemTag) - - def arrayValue(x: BoxedArray, elemClass: Class): AnyRef = - if (x eq null) null else x.unbox(elemClass) - - def boxArray(value: AnyRef): BoxedArray = value match { - case x: Array[Byte] => new BoxedByteArray(x) - case x: Array[Short] => new BoxedShortArray(x) - case x: Array[Char] => new BoxedCharArray(x) - case x: Array[Int] => new BoxedIntArray(x) - case x: Array[Long] => new BoxedLongArray(x) - case x: Array[Float] => new BoxedFloatArray(x) - case x: Array[Double] => new BoxedDoubleArray(x) - case x: Array[Boolean] => new BoxedBooleanArray(x) - case x: Array[AnyRef] => new BoxedObjectArray(x) - case x: BoxedArray => x - } -} diff --git a/src/dotnet-library/scala/util/Fluid.scala b/src/dotnet-library/scala/util/Fluid.scala index d5e446edca..824ac373bc 100644 --- a/src/dotnet-library/scala/util/Fluid.scala +++ b/src/dotnet-library/scala/util/Fluid.scala @@ -12,6 +12,7 @@ package scala.util +import Predef._ import System.Threading.Thread import System.LocalDataStoreSlot |