From 5438ab13a944a0721816012a9be99a9d3141d7a9 Mon Sep 17 00:00:00 2001 From: Iulian Dragos Date: Tue, 13 Nov 2007 08:13:05 +0000 Subject: Fixed minor bugs in icode. --- src/compiler/scala/tools/ant/Scalac.scala | 13 +++++++++++++ src/compiler/scala/tools/nsc/backend/icode/Checkers.scala | 10 ++++++++++ src/compiler/scala/tools/nsc/backend/icode/Printers.scala | 4 ++-- src/compiler/scala/tools/nsc/backend/icode/TypeKinds.scala | 7 +++++-- .../tools/nsc/backend/icode/analysis/TypeFlowAnalysis.scala | 3 ++- src/compiler/scala/tools/nsc/backend/opt/Inliners.scala | 2 +- 6 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/compiler/scala/tools/ant/Scalac.scala b/src/compiler/scala/tools/ant/Scalac.scala index 4d4116d1d2..a804c526ff 100644 --- a/src/compiler/scala/tools/ant/Scalac.scala +++ b/src/compiler/scala/tools/ant/Scalac.scala @@ -49,6 +49,7 @@ import scala.tools.nsc.reporters.{Reporter, ConsoleReporter} *
  • addparams,
  • *
  • scalacdebugging,
  • *
  • deprecation,
  • + *
  • optimise,
  • *
  • unchecked,
  • *
  • failonerror.
  • * @@ -140,6 +141,8 @@ class Scalac extends MatchingTask { private var addParams: String = "" /** Instruct the compiler to generate deprecation information. */ private var deprecation: Option[Boolean] = None + /** Instruct the compiler to run optimizations. */ + private var optimise: Option[Boolean] = None /** Instruct the compiler to generate unchecked information. */ private var unchecked: Option[Boolean] = None /** Indicates whether compilation errors will fail the build; defaults to true. */ @@ -320,6 +323,15 @@ class Scalac extends MatchingTask { error("Unknown deprecation flag '" + input + "'") } + /** Set the optimise info attribute. + * @param input One of the flags yes/no or on/off. */ + def setOptimise(input: String) { + if (Flag.isPermissible(input)) + optimise = Some("yes" == input || "on" == input) + else + error("Unknown optimisation flag '" + input + "'") + } + /** Set the unchecked info attribute. * @param input One of the flags yes/no or on/off. */ def setUnchecked(input: String) { @@ -538,6 +550,7 @@ class Scalac extends MatchingTask { if (!usepredefs.isEmpty) settings.nopredefs.value = !usepredefs.get if (!debugInfo.isEmpty) settings.debuginfo.value = debugInfo.get if (!deprecation.isEmpty) settings.deprecation.value = deprecation.get + if (!optimise.isEmpty) settings.XO.value = optimise.get if (!unchecked.isEmpty) settings.unchecked.value = unchecked.get if (!assemname.isEmpty) settings.assemname.value = assemname.get diff --git a/src/compiler/scala/tools/nsc/backend/icode/Checkers.scala b/src/compiler/scala/tools/nsc/backend/icode/Checkers.scala index 0c467f1279..da80fe148a 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/Checkers.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/Checkers.scala @@ -537,6 +537,16 @@ abstract class Checkers { checkBool(stack.pop.isReferenceType, "MONITOR_EXIT on non-reference type") + case BOX(kind) => + checkStack(1) + checkType(stack.pop, kind) + stack.push(icodes.AnyRefReference) + + case UNBOX(kind) => + checkStack(1) + stack.pop + stack.push(kind) + case _ => abort("Unknown instruction: " + instr) } diff --git a/src/compiler/scala/tools/nsc/backend/icode/Printers.scala b/src/compiler/scala/tools/nsc/backend/icode/Printers.scala index d74b77efd6..0bb634485c 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/Printers.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/Printers.scala @@ -124,8 +124,8 @@ trait Printers { self: ICodes => } def printInstruction(i: Instruction): Unit = { - if (settings.Xdce.value) - print(if (i.useful) " " else " * "); +// if (settings.Xdce.value) +// print(if (i.useful) " " else " * "); if (settings.debug.value) print(i.pos.line.map(_.toString).getOrElse("No line")) println(i.toString()); diff --git a/src/compiler/scala/tools/nsc/backend/icode/TypeKinds.scala b/src/compiler/scala/tools/nsc/backend/icode/TypeKinds.scala index 71295a8ea2..5518781403 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/TypeKinds.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/TypeKinds.scala @@ -72,14 +72,14 @@ trait TypeKinds { self: ICodes => def maxType(other: TypeKind): TypeKind /** Simple subtyping check */ - def <:<(other: TypeKind): Boolean = this match { + def <:<(other: TypeKind): Boolean = (this eq other) || (this match { case BOOL | BYTE | SHORT | CHAR => other match { case INT | LONG => true case _ => false } case _ => this eq other - } + }) override def equals(other: Any): Boolean = this eq other.asInstanceOf[AnyRef] @@ -117,6 +117,9 @@ trait TypeKinds { self: ICodes => else (a, b) match { case (BOXED(a1), BOXED(b1)) => if (a1 == b1) a else REFERENCE(definitions.AnyRefClass) case (BOXED(_), REFERENCE(_)) | (REFERENCE(_), BOXED(_)) => REFERENCE(definitions.AnyRefClass) + case (BYTE, INT) | (INT, BYTE) => INT + case (SHORT, INT) | (INT, SHORT) => INT + case (CHAR, INT) | (INT, CHAR) => INT case _ => throw new CheckerError("Incompatible types: " + a + " with " + b) } } diff --git a/src/compiler/scala/tools/nsc/backend/icode/analysis/TypeFlowAnalysis.scala b/src/compiler/scala/tools/nsc/backend/icode/analysis/TypeFlowAnalysis.scala index e8dd927156..2ea2461a0e 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/analysis/TypeFlowAnalysis.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/analysis/TypeFlowAnalysis.scala @@ -187,7 +187,8 @@ abstract class TypeFlowAnalysis { stack push toTypeKind(const.tpe) case LOAD_ARRAY_ITEM(kind) => - val Pair(INT, ARRAY(elem)) = stack.pop2 + val Pair(idxKind, ARRAY(elem)) = stack.pop2 + assert(idxKind == INT || idxKind == CHAR || idxKind == SHORT || idxKind == BYTE) stack.push(elem) case LOAD_LOCAL(local) => diff --git a/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala b/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala index c37c2b48cb..a2cae2146e 100644 --- a/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala +++ b/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala @@ -492,7 +492,7 @@ abstract class Inliners extends SubComponent { /** Is the given class a subtype of a function trait? */ def isClosureClass(cls: Symbol): Boolean = { - val res = cls.isFinal && + val res = cls.isFinal && cls.hasFlag(Flags.SYNTHETIC) && cls.tpe.parents.exists { t => val TypeRef(_, sym, _) = t; definitions.FunctionClass exists sym.== -- cgit v1.2.3