From a02f860355f188a43a27a341d9c7edb6cecd3e13 Mon Sep 17 00:00:00 2001 From: Antonio Cunei Date: Thu, 12 Nov 2009 19:06:32 +0000 Subject: Merged revisions 19578,19582-19583 via svnmerge... Merged revisions 19578,19582-19583 via svnmerge from https://lampsvn.epfl.ch/svn-repos/scala/scala/trunk ........ r19578 | odersky | 2009-11-12 18:22:51 +0100 (Thu, 12 Nov 2009) | 1 line added hooks so that BigInt, BigDecimal can do the right thign for equality. ........ r19582 | odersky | 2009-11-12 19:23:21 +0100 (Thu, 12 Nov 2009) | 1 line Fixed #2482 ........ r19583 | odersky | 2009-11-12 19:29:43 +0100 (Thu, 12 Nov 2009) | 1 line Slight opimization of previous checkin. ........ --- .../scala/tools/nsc/symtab/classfile/Pickler.scala | 10 +++++++++- src/library/scala/math/BigDecimal.scala | 15 +-------------- src/library/scala/math/BigInt.scala | 3 +-- src/library/scala/math/ScalaNumber.java | 20 ++++++++++++++++++++ .../scala/math/ScalaNumericConversions.scala | 22 ++++++++++++++++++++++ src/library/scala/runtime/BoxesRunTime.java | 6 ++++++ 6 files changed, 59 insertions(+), 17 deletions(-) create mode 100644 src/library/scala/math/ScalaNumber.java create mode 100644 src/library/scala/math/ScalaNumericConversions.scala (limited to 'src') diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala b/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala index 796ff4584a..2d1855dc84 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/Pickler.scala @@ -10,9 +10,11 @@ package classfile import java.lang.{Float, Double} import scala.tools.nsc.util.{Position, NoPosition, ShowPickled} +import scala.collection.mutable.Set import Flags._ import PickleFormat._ + /** * Serialize a top-level module and/or class. * @@ -65,6 +67,8 @@ abstract class Pickler extends SubComponent { private var ep = 0 private val index = new LinkedHashMap[AnyRef, Int] + private var locals: Set[Symbol] = Set() + // private var boundSyms: List[Symbol] = Nil /** Returns usually symbol's owner, but picks classfile root instead @@ -84,7 +88,8 @@ abstract class Pickler extends SubComponent { (sym.name.toTermName == rootName && sym.owner == rootOwner || sym != NoSymbol && isLocal(sym.owner) || sym.isRefinementClass || - sym.isAbstractType && sym.hasFlag(EXISTENTIAL)) + sym.isAbstractType && sym.hasFlag(EXISTENTIAL) || + (locals contains sym)) private def staticAnnotations(annots: List[AnnotationInfo]) = annots filter(ann => @@ -185,6 +190,9 @@ abstract class Pickler extends SubComponent { case MethodType(params, restpe) => putType(restpe); putSymbols(params) case PolyType(tparams, restpe) => + tparams foreach { tparam => + if (!isLocal(tparam)) locals += tparam + } putType(restpe); putSymbols(tparams) case ExistentialType(tparams, restpe) => // val savedBoundSyms = boundSyms diff --git a/src/library/scala/math/BigDecimal.scala b/src/library/scala/math/BigDecimal.scala index 677dfa7e17..c379b83abf 100644 --- a/src/library/scala/math/BigDecimal.scala +++ b/src/library/scala/math/BigDecimal.scala @@ -14,19 +14,6 @@ import java.{ lang => jl } import java.math.{ MathContext, BigDecimal => BigDec } import scala.collection.immutable.NumericRange -/** Conversions which present a consistent conversion interface - * across all the numeric types. - */ -trait ScalaNumericConversions extends jl.Number { - def toChar = intValue.toChar - def toByte = byteValue - def toShort = shortValue - def toInt = intValue - def toLong = longValue - def toFloat = floatValue - def toDouble = doubleValue -} - /** * @author Stephane Micheloud * @version 1.0 @@ -164,7 +151,7 @@ object BigDecimal class BigDecimal( val bigDecimal: BigDec, val mc: MathContext) -extends jl.Number with ScalaNumericConversions +extends ScalaNumber with ScalaNumericConversions { def this(bigDecimal: BigDec) = this(bigDecimal, BigDecimal.defaultMathContext) import BigDecimal.RoundingMode._ diff --git a/src/library/scala/math/BigInt.scala b/src/library/scala/math/BigInt.scala index 5415a29489..f1e89f4f53 100644 --- a/src/library/scala/math/BigInt.scala +++ b/src/library/scala/math/BigInt.scala @@ -12,7 +12,6 @@ package scala.math import java.math.BigInteger -import java.{ lang => jl } /** * @author Martin Odersky @@ -110,7 +109,7 @@ object BigInt { * @version 1.0, 15/07/2003 */ @serializable -class BigInt(val bigInteger: BigInteger) extends jl.Number with ScalaNumericConversions +class BigInt(val bigInteger: BigInteger) extends ScalaNumber with ScalaNumericConversions { /** Returns the hash code for this BigInt. */ override def hashCode(): Int = this.bigInteger.hashCode() diff --git a/src/library/scala/math/ScalaNumber.java b/src/library/scala/math/ScalaNumber.java new file mode 100644 index 0000000000..bb54a5d9c0 --- /dev/null +++ b/src/library/scala/math/ScalaNumber.java @@ -0,0 +1,20 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2006-2009, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id: ScalaNumber.java 19428 2009-11-06 23:59:26Z extempore $ + + +package scala.math; + +/** A marker class for Number types introduced by Scala + * @author Martin Odersky, Paul Phillips + * @version 2.8 + * @since 2.8 + */ +public abstract class ScalaNumber extends java.lang.Number { +} diff --git a/src/library/scala/math/ScalaNumericConversions.scala b/src/library/scala/math/ScalaNumericConversions.scala new file mode 100644 index 0000000000..53465c7438 --- /dev/null +++ b/src/library/scala/math/ScalaNumericConversions.scala @@ -0,0 +1,22 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2007-2009, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +package scala.math + +/** Conversions which present a consistent conversion interface + * across all the numeric types. + */ +trait ScalaNumericConversions extends java.lang.Number { + def toChar = intValue.toChar + def toByte = byteValue + def toShort = shortValue + def toInt = intValue + def toLong = longValue + def toFloat = floatValue + def toDouble = doubleValue +} diff --git a/src/library/scala/runtime/BoxesRunTime.java b/src/library/scala/runtime/BoxesRunTime.java index b4252ed647..39ea9abcdd 100644 --- a/src/library/scala/runtime/BoxesRunTime.java +++ b/src/library/scala/runtime/BoxesRunTime.java @@ -12,6 +12,7 @@ package scala.runtime; import java.io.*; +import scala.math.ScalaNumber; /** An object (static class) that defines methods used for creating, * reverting, and calculating with, boxed values. There are four classes @@ -145,6 +146,9 @@ public class BoxesRunTime Number xn = (Number)x; if (y instanceof Number) { Number yn = (Number)y; + if ((y instanceof ScalaNumber) && !(x instanceof ScalaNumber)) { + return y.equals(x); + } if ((xn instanceof Double) || (yn instanceof Double)) return xn.doubleValue() == yn.doubleValue(); if ((xn instanceof Float) || (yn instanceof Float)) @@ -175,6 +179,8 @@ public class BoxesRunTime return x.floatValue() == ch; if (x instanceof Long) return x.longValue() == ch; + if (x instanceof ScalaNumber) + return x.equals(y); return x.intValue() == ch; } -- cgit v1.2.3