summaryrefslogtreecommitdiff
path: root/src/compiler/scala
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-02-23 06:57:53 +0000
committerPaul Phillips <paulp@improving.org>2010-02-23 06:57:53 +0000
commit7cfbc47200119bb0d30f0d24d362f83d2cd2bd01 (patch)
tree87952646c0732be785fc0ddf76860c584ee2cb74 /src/compiler/scala
parent1558069de5a2af1163857ae06d7334f5cae537f7 (diff)
downloadscala-7cfbc47200119bb0d30f0d24d362f83d2cd2bd01.tar.gz
scala-7cfbc47200119bb0d30f0d24d362f83d2cd2bd01.tar.bz2
scala-7cfbc47200119bb0d30f0d24d362f83d2cd2bd01.zip
Abstracting out a few more platform specific el...
Abstracting out a few more platform specific elements now that we have a facility for doing so. Review by rytz.
Diffstat (limited to 'src/compiler/scala')
-rw-r--r--src/compiler/scala/tools/nsc/backend/JavaPlatform.scala17
-rw-r--r--src/compiler/scala/tools/nsc/backend/MSILPlatform.scala17
-rw-r--r--src/compiler/scala/tools/nsc/backend/Platform.scala19
-rw-r--r--src/compiler/scala/tools/nsc/backend/icode/GenICode.scala13
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Definitions.scala14
-rw-r--r--src/compiler/scala/tools/nsc/transform/CleanUp.scala2
-rw-r--r--src/compiler/scala/tools/nsc/util/MsilClassPath.scala14
7 files changed, 51 insertions, 45 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/JavaPlatform.scala b/src/compiler/scala/tools/nsc/backend/JavaPlatform.scala
index 88651220f6..129a747e64 100644
--- a/src/compiler/scala/tools/nsc/backend/JavaPlatform.scala
+++ b/src/compiler/scala/tools/nsc/backend/JavaPlatform.scala
@@ -13,10 +13,10 @@ import scala.tools.util.PathResolver
trait JavaPlatform extends Platform[AbstractFile] {
import global._
+ import definitions.{ BoxesRunTimeClass, getMember }
- lazy val classPath = new PathResolver(settings).result
-
- def rootLoader = new loaders.JavaPackageLoader(classPath)
+ lazy val classPath = new PathResolver(settings).result
+ def rootLoader = new loaders.JavaPackageLoader(classPath)
private def depAnalysisPhase = if (settings.make.value != "all") List(dependencyAnalysis) else Nil
def platformPhases = List(
@@ -24,4 +24,15 @@ trait JavaPlatform extends Platform[AbstractFile] {
liftcode, // generate reified trees
genJVM // generate .class files
) ::: depAnalysisPhase
+
+ lazy val externalEquals = getMember(BoxesRunTimeClass, nme.equals_)
+
+ def isMaybeBoxed(sym: Symbol): Boolean = {
+ import definitions._
+ (sym == ObjectClass) ||
+ (sym == SerializableClass) ||
+ (sym == ComparableClass) ||
+ (sym isNonBottomSubClass BoxedNumberClass) ||
+ (sym isNonBottomSubClass BoxedCharacterClass)
+ }
}
diff --git a/src/compiler/scala/tools/nsc/backend/MSILPlatform.scala b/src/compiler/scala/tools/nsc/backend/MSILPlatform.scala
index 99878cc842..cf3be7c8cd 100644
--- a/src/compiler/scala/tools/nsc/backend/MSILPlatform.scala
+++ b/src/compiler/scala/tools/nsc/backend/MSILPlatform.scala
@@ -8,12 +8,11 @@ package backend
import ch.epfl.lamp.compiler.msil.{ Type => MSILType }
import util.MsilClassPath
-import util.MsilClassPath.MsilContext
-import util.ClassPath.{ isTraitImplementation }
import msil.GenMSIL
trait MSILPlatform extends Platform[MSILType] {
import global._
+ import definitions.{ ComparatorClass, BoxedNumberClass, getMember, getClass }
if (settings.verbose.value)
inform("[AssemRefs = " + settings.assemrefs.value + "]")
@@ -25,19 +24,13 @@ trait MSILPlatform extends Platform[MSILType] {
val runsRightAfter = None
} with GenMSIL
- lazy val classPath: MsilClassPath = {
- val context =
- if (isInlinerOn) new MsilContext
- else new MsilContext {
- override def isValidName(name: String) = !isTraitImplementation(name)
- }
-
- new MsilClassPath(settings.assemextdirs.value, settings.assemrefs.value, settings.sourcepath.value, context)
- }
-
+ lazy val classPath = MsilClassPath.fromSettings(settings)
def rootLoader = new loaders.NamespaceLoader(classPath)
def platformPhases = List(
genMSIL // generate .msil files
)
+
+ lazy val externalEquals = getMember(ComparatorClass.linkedModuleOfClass, nme.equals_)
+ def isMaybeBoxed(sym: Symbol) = sym isNonBottomSubClass BoxedNumberClass
}
diff --git a/src/compiler/scala/tools/nsc/backend/Platform.scala b/src/compiler/scala/tools/nsc/backend/Platform.scala
index 3ab0e4e8a7..90075687c6 100644
--- a/src/compiler/scala/tools/nsc/backend/Platform.scala
+++ b/src/compiler/scala/tools/nsc/backend/Platform.scala
@@ -6,19 +6,26 @@
package scala.tools.nsc
package backend
-import util.{ ClassPath }
+import util.ClassPath
/** The platform dependent pieces of Global.
*/
-
trait Platform[T] {
val global: Global
import global._
- // Unless inlining is on, we can exclude $class.class files from the classpath.
- protected def isInlinerOn = settings.inline.value
-
+ /** The compiler classpath. */
def classPath: ClassPath[T]
- def rootLoader: global.LazyType
+
+ /** The root symbol loader. */
+ def rootLoader: LazyType
+
+ /** Any platform-specific phases. */
def platformPhases: List[SubComponent]
+
+ /** Symbol for a method which compares two objects. */
+ def externalEquals: Symbol
+
+ /** The various ways a boxed primitive might materialize at runtime. */
+ def isMaybeBoxed(sym: Symbol): Boolean
}
diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
index c3430f8006..048d0b7bec 100644
--- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
+++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala
@@ -27,13 +27,13 @@ abstract class GenICode extends SubComponent {
import icodes.opcodes._
import definitions.{
ArrayClass, ObjectClass, ThrowableClass,
- Object_equals, Object_isInstanceOf, Object_asInstanceOf,
- isMaybeBoxed
+ Object_equals, Object_isInstanceOf, Object_asInstanceOf
}
import scalaPrimitives.{
isArrayOp, isComparisonOp, isLogicalOp,
isUniversalEqualityOp, isReferenceEqualityOp
}
+ import platform.isMaybeBoxed
val phaseName = "icode"
@@ -58,13 +58,6 @@ abstract class GenICode extends SubComponent {
val SCALA_ALLREF = REFERENCE(definitions.NullClass)
val THROWABLE = REFERENCE(ThrowableClass)
- lazy val BoxesRunTime_equals =
- if (!forMSIL)
- definitions.getMember(definitions.BoxesRunTimeClass, nme.equals_)
- else
- definitions.getMember(definitions.getClass("scala.runtime.Comparator").linkedModuleOfClass, nme.equals_)
-
-
override def run {
scalaPrimitives.init
classes.clear
@@ -1360,7 +1353,7 @@ abstract class GenICode extends SubComponent {
if (mustUseAnyComparator) {
// when -optimise is on we call the @inline-version of equals, found in ScalaRunTime
val equalsMethod =
- if (!settings.XO.value) BoxesRunTime_equals
+ if (!settings.XO.value) platform.externalEquals
else {
ctx.bb.emit(LOAD_MODULE(definitions.ScalaRunTimeModule))
definitions.getMember(definitions.ScalaRunTimeModule, nme.inlinedEquals)
diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala
index 026b6c3e25..9c3739aa91 100644
--- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala
@@ -352,6 +352,8 @@ trait Definitions extends reflect.generic.StandardDefinitions {
//
// .NET backend
//
+
+ lazy val ComparatorClass = getClass("scala.runtime.Comparator")
// System.ValueType
lazy val ValueTypeClass: Symbol = getClass(sn.ValueType)
// System.MulticastDelegate
@@ -423,18 +425,6 @@ trait Definitions extends reflect.generic.StandardDefinitions {
lazy val BoxedFloatClass = getClass("java.lang.Float")
lazy val BoxedDoubleClass = getClass("java.lang.Double")
- /** The various ways a boxed primitive might materialize at runtime. */
- def isMaybeBoxed(sym: Symbol) =
- if (forMSIL)
- sym isNonBottomSubClass BoxedNumberClass
- else {
- (sym == ObjectClass) ||
- (sym == SerializableClass) ||
- (sym == ComparableClass) ||
- (sym isNonBottomSubClass BoxedNumberClass) ||
- (sym isNonBottomSubClass BoxedCharacterClass)
- }
-
lazy val BoxedUnitClass = getClass("scala.runtime.BoxedUnit")
lazy val BoxedUnitModule = getModule("scala.runtime.BoxedUnit")
def BoxedUnit_UNIT = getMember(BoxedUnitModule, "UNIT")
diff --git a/src/compiler/scala/tools/nsc/transform/CleanUp.scala b/src/compiler/scala/tools/nsc/transform/CleanUp.scala
index 6626ca56cd..66b66299b9 100644
--- a/src/compiler/scala/tools/nsc/transform/CleanUp.scala
+++ b/src/compiler/scala/tools/nsc/transform/CleanUp.scala
@@ -357,7 +357,7 @@ abstract class CleanUp extends Transform with ast.TreeDSL {
}
def useValueOperator =
- isMaybeBoxed(qualSym) && // may be a boxed value class
+ platform.isMaybeBoxed(qualSym) && // may be a boxed value class
(getPrimitiveReplacementForStructuralCall isDefinedAt methSym.name) &&
((resType :: paramTypes) forall (x => isJavaValueClass(x.typeSymbol))) // issue #1110
diff --git a/src/compiler/scala/tools/nsc/util/MsilClassPath.scala b/src/compiler/scala/tools/nsc/util/MsilClassPath.scala
index b61fffafaf..c5d991b892 100644
--- a/src/compiler/scala/tools/nsc/util/MsilClassPath.scala
+++ b/src/compiler/scala/tools/nsc/util/MsilClassPath.scala
@@ -17,7 +17,7 @@ import scala.collection.mutable.{ ListBuffer, HashSet => MutHashSet }
import scala.tools.nsc.io.AbstractFile
import ch.epfl.lamp.compiler.msil.{ Type => MSILType, Assembly }
-import ClassPath.ClassPathContext
+import ClassPath.{ ClassPathContext, isTraitImplementation }
/** Keeping the MSIL classpath code in its own file is important to make sure
* we don't accidentally introduce a dependency on msil.jar in the jvm.
@@ -35,6 +35,18 @@ object MsilClassPath {
res
}
+ /** On the java side this logic is in PathResolver, but as I'm not really
+ * up to folding MSIL into that, I am encapsulating it here.
+ */
+ def fromSettings(settings: Settings): MsilClassPath = {
+ val context =
+ if (settings.inline.value) new MsilContext
+ else new MsilContext { override def isValidName(name: String) = !isTraitImplementation(name) }
+
+ import settings._
+ new MsilClassPath(assemextdirs.value, assemrefs.value, sourcepath.value, context)
+ }
+
class MsilContext extends ClassPathContext[MSILType] {
def toBinaryName(rep: MSILType) = rep.Name
def newClassPath(assemFile: AbstractFile) = new AssemblyClassPath(MsilClassPath collectTypes assemFile, "", this)