diff options
Diffstat (limited to 'sources')
-rw-r--r-- | sources/scala/CaseClass.scala | 4 | ||||
-rw-r--r-- | sources/scala/Predef.scala | 10 | ||||
-rw-r--r-- | sources/scala/concurrent/Actor.scala | 15 | ||||
-rw-r--r-- | sources/scala/concurrent/MailBox.scala | 2 | ||||
-rw-r--r-- | sources/scala/concurrent/NameServer.scala | 2 | ||||
-rw-r--r-- | sources/scala/concurrent/Process.scala | 10 | ||||
-rw-r--r-- | sources/scala/runtime/ScalaRunTime.scala | 2 | ||||
-rw-r--r-- | sources/scala/tools/nsc/symtab/Flags.scala | 29 | ||||
-rwxr-xr-x | sources/scala/tools/nsc/symtab/Symbols.scala | 8 | ||||
-rwxr-xr-x | sources/scala/tools/nsc/transform/AddInterfaces.scala | 2 | ||||
-rwxr-xr-x | sources/scala/tools/nsc/transform/Mixin.scala | 20 | ||||
-rwxr-xr-x | sources/scala/tools/nsc/typechecker/RefChecks.scala | 10 | ||||
-rwxr-xr-x | sources/scala/tools/nsc/typechecker/SuperAccessors.scala | 32 |
13 files changed, 95 insertions, 51 deletions
diff --git a/sources/scala/CaseClass.scala b/sources/scala/CaseClass.scala index 9b31387599..1b8e7f62a7 100644 --- a/sources/scala/CaseClass.scala +++ b/sources/scala/CaseClass.scala @@ -20,6 +20,10 @@ trait CaseClass extends AnyRef { */ def caseElement(n: Int): Any ; + /** need also, for reflection + def setCaseElement(n: Int, v: Any): unit + */ + /** for a case class A(x_0,...,x_(k-1)), returns k */ def caseArity: Int ; diff --git a/sources/scala/Predef.scala b/sources/scala/Predef.scala index 75c6a5e3fa..5005e3df3e 100644 --- a/sources/scala/Predef.scala +++ b/sources/scala/Predef.scala @@ -144,6 +144,16 @@ object Predef { throw new Error("assertion failed: " + message); } + def assume(assumption: Boolean): Unit = { + if (!assumption) + throw new Error("assumption failed"); + } + + def assume(assumption: Boolean, message: Any): Unit = { + if (!assumption) + throw new Error("assumption failed: " + message); + } + // views ------------------------------------------------------------- implicit def identity[a](x: a): a = x; diff --git a/sources/scala/concurrent/Actor.scala b/sources/scala/concurrent/Actor.scala index 1ac6420f12..4ba4ab3078 100644 --- a/sources/scala/concurrent/Actor.scala +++ b/sources/scala/concurrent/Actor.scala @@ -10,7 +10,20 @@ package scala.concurrent; +abstract class Actor extends Thread { + private val in = new MailBox; + + def send(msg: in.Message) = + in.send(msg); + + def receive[a](f: PartialFunction[in.Message, a]): a = + if (Thread.currentThread() == this) in.receive(f); + else error("receive called not on own process"); + + def receiveWithin[a](msec: long)(f: PartialFunction[in.Message, a]): a = + if (Thread.currentThread() == this) in.receiveWithin(msec)(f); + else error("receiveWithin called not on own process"); +} -abstract class Actor extends Thread with MailBox; diff --git a/sources/scala/concurrent/MailBox.scala b/sources/scala/concurrent/MailBox.scala index 74935cf638..427d424b28 100644 --- a/sources/scala/concurrent/MailBox.scala +++ b/sources/scala/concurrent/MailBox.scala @@ -11,7 +11,7 @@ package scala.concurrent; //class MailBox with Monitor with LinkedListQueueCreator { -[_trait_] abstract class MailBox extends AnyRef with ListQueueCreator { +class MailBox extends AnyRef with ListQueueCreator { type Message = AnyRef; diff --git a/sources/scala/concurrent/NameServer.scala b/sources/scala/concurrent/NameServer.scala index b15d5d9dd9..b7646e6deb 100644 --- a/sources/scala/concurrent/NameServer.scala +++ b/sources/scala/concurrent/NameServer.scala @@ -29,7 +29,7 @@ object NameServer { def whereis(name: Symbol): Option[Process] = names.get(name); - def send(name: Symbol, msg: Actor#Message) = + def send(name: Symbol, msg: MailBox#Message) = names(name).send(msg); } diff --git a/sources/scala/concurrent/Process.scala b/sources/scala/concurrent/Process.scala index 5273f2a25e..950220da35 100644 --- a/sources/scala/concurrent/Process.scala +++ b/sources/scala/concurrent/Process.scala @@ -20,12 +20,12 @@ object Process { self.spawn_link(body); } - def send(p: Process,msg: Actor#Message) = + def send(p: Process,msg: MailBox#Message) = p.send(msg); - def receive[a](f: PartialFunction[Actor#Message, a]): a = + def receive[a](f: PartialFunction[MailBox#Message, a]): a = self.receive(f); - def receiveWithin[a](msec: long)(f: PartialFunction[Actor#Message, a]): a = + def receiveWithin[a](msec: long)(f: PartialFunction[MailBox#Message, a]): a = self.receiveWithin(msec)(f); def self: Process = { @@ -51,11 +51,11 @@ class Process(body: => Unit) extends Actor() { } } - private def signal(s: Actor#Message) = { + private def signal(s: MailBox#Message) = { links.foreach((p:Process) => p.send(Tuple3('EXIT,this,s))); } - def !(msg: Actor#Message) = + def !(msg: MailBox#Message) = send(msg); def link(p: Process) = { diff --git a/sources/scala/runtime/ScalaRunTime.scala b/sources/scala/runtime/ScalaRunTime.scala index fbd205efd7..8fe69a2f31 100644 --- a/sources/scala/runtime/ScalaRunTime.scala +++ b/sources/scala/runtime/ScalaRunTime.scala @@ -12,7 +12,7 @@ package scala.runtime; object ScalaRunTime { - /** Names for primitive typesm, used by array unboxing */ + /** Names for primitive types, used by array unboxing */ val ByteTag = ".Byte"; val ShortTag = ".Short"; val CharTag = ".Char"; diff --git a/sources/scala/tools/nsc/symtab/Flags.scala b/sources/scala/tools/nsc/symtab/Flags.scala index f0360b1809..3ea837bab2 100644 --- a/sources/scala/tools/nsc/symtab/Flags.scala +++ b/sources/scala/tools/nsc/symtab/Flags.scala @@ -52,25 +52,26 @@ object Flags { // for parameters: is a val parameter final val LABEL = 0x40000000; // symbol is a label. Set by TailCall - final val CAPTURED = 0x80000000l; // variable is accessed from nested function. Set by LambdaLift + final val CAPTURED = 0x80000000L; // variable is accessed from nested function. Set by LambdaLift - final val IS_ERROR = 0x100000000l; // symbol is an error symbol - final val OVERLOADED = 0x200000000l; // symbol is overloaded - final val LIFTED = 0x400000000l; // class has been lifted out to package level + final val IS_ERROR = 0x100000000L; // symbol is an error symbol + final val OVERLOADED = 0x200000000L; // symbol is overloaded + final val LIFTED = 0x400000000L; // class has been lifted out to package level // local value has been lifted out to class level - final val MIXEDIN = 0x800000000l; // member has been mixed in + final val MIXEDIN = 0x800000000L; // member has been mixed in - final val EXPANDEDNAME = 0x1000000000l; // name has been expanded with class suffix - final val TRANS_FLAG = 0x2000000000l; // transient flag guaranteed to be reset after each phase. - final val INCONSTRUCTOR = TRANS_FLAG; // transient flag for analyzer + final val EXPANDEDNAME = 0x1000000000L; // name has been expanded with class suffix + final val IMPLCLASS = 0x2000000000L; // symbol is an implementation class + final val TRANS_FLAG = 0x4000000000L; // transient flag guaranteed to be reset after each phase. + final val INCONSTRUCTOR = TRANS_FLAG; // transient flag for analyzer - final val LOCKED = 0x8000000000l; // temporary flag to catch cyclic dependencies + final val LOCKED = 0x8000000000L; // temporary flag to catch cyclic dependencies - final val InitialFlags = 0x000000FFFFFFFFFFl; // flags that are enabled from phase 1. - final val LateFlags = 0x000FFF0000000000l; // flags that override flags in 0xFFF. - final val AntiFlags = 0x7FF0000000000000l; // flags that cancel flags in 0x7FF - final val LateShift = 40l; - final val AntiShift = 52l; + final val InitialFlags = 0x000000FFFFFFFFFFL; // flags that are enabled from phase 1. + final val LateFlags = 0x000FFF0000000000L; // flags that override flags in 0xFFF. + final val AntiFlags = 0x7FF0000000000000L; // flags that cancel flags in 0x7FF + final val LateShift = 40L; + final val AntiShift = 52L; // late flags (set by a transformer phase) final val lateDEFERRED = (DEFERRED: long) << LateShift; diff --git a/sources/scala/tools/nsc/symtab/Symbols.scala b/sources/scala/tools/nsc/symtab/Symbols.scala index 3437459c15..c17af0d51f 100755 --- a/sources/scala/tools/nsc/symtab/Symbols.scala +++ b/sources/scala/tools/nsc/symtab/Symbols.scala @@ -155,7 +155,7 @@ import Flags._; isConstructor && owner.primaryConstructor == this; /** Is this symbol an implementation class for a trait ? */ - final def isImplClass: boolean = isClass && nme.isImplClassName(name); + final def isImplClass: boolean = isClass && hasFlag(IMPLCLASS); final def needsImplClass: boolean = isTrait && (!hasFlag(INTERFACE) || hasFlag(lateINTERFACE)) && !isImplClass; @@ -542,9 +542,7 @@ import Flags._; final def toInterface: Symbol = if (isImplClass) { assert(!tpe.parents.isEmpty, this); - val iface = tpe.parents.last.symbol; - assert(nme.implClassName(iface.name) == name, this); - iface + tpe.parents.last.symbol } else this; /** The module corresponding to this module class (note that this @@ -745,7 +743,7 @@ import Flags._; /** String representation of symbol's definition */ final def defString: String = - compose(List(flagsToString(flags & ExplicitFlags), + compose(List(flagsToString(if (settings.debug.value) flags else flags & ExplicitFlags), keyString, varianceString + nameString + infoString(rawInfo))); diff --git a/sources/scala/tools/nsc/transform/AddInterfaces.scala b/sources/scala/tools/nsc/transform/AddInterfaces.scala index 2319346f8b..8969e26865 100755 --- a/sources/scala/tools/nsc/transform/AddInterfaces.scala +++ b/sources/scala/tools/nsc/transform/AddInterfaces.scala @@ -52,7 +52,7 @@ abstract class AddInterfaces extends InfoTransform { if (iface.owner.isClass) iface.owner.info.decls enter impl } impl setPos iface.pos; - impl.flags = iface.flags & ~(INTERFACE | lateINTERFACE); + impl.flags = iface.flags & ~(INTERFACE | lateINTERFACE) | IMPLCLASS; impl setInfo new LazyImplClassType(iface); implClassMap(iface) = impl; if (settings.debug.value) log("generating impl class " + impl + " in " + iface.owner);//debug diff --git a/sources/scala/tools/nsc/transform/Mixin.scala b/sources/scala/tools/nsc/transform/Mixin.scala index 77c32aeab5..f694732875 100755 --- a/sources/scala/tools/nsc/transform/Mixin.scala +++ b/sources/scala/tools/nsc/transform/Mixin.scala @@ -319,7 +319,7 @@ abstract class Mixin extends InfoTransform { case Apply(Select(qual, _), args) => def staticCall(target: Symbol) = { if (target == NoSymbol) - assert(false, "" + sym + " " + sym.owner + " " + sym.owner.implClass + " " + sym.owner.owner + atPhase(phase.prev)(sym.owner.owner.info.decls.toList));//debug + assert(false, "" + sym + " " + sym.owner + " " + implClass(sym.owner) + " " + sym.owner.owner + atPhase(phase.prev)(sym.owner.owner.info.decls.toList));//debug localTyper.typed { atPos(tree.pos) { val qual1 = @@ -341,20 +341,12 @@ abstract class Mixin extends InfoTransform { assert(false, "illegal super in mixin class: " + currentOwner.enclClass + " " + tree); } if (sym.owner hasFlag lateINTERFACE) - staticCall(atPhase(phase.prev)(sym.overridingSymbol(sym.owner.implClass))) + staticCall(atPhase(phase.prev)(sym.overridingSymbol(implClass(sym.owner)))) else { assert(!(sym.owner hasFlag INTERFACE)); assert(!currentOwner.enclClass.isImplClass); tree } -/* - } else { - var sym1 = sym; - if (sym.owner hasFlag lateINTERFACE) - sym1 = atPhase(phase.prev)(sym.overridingSymbol(sym.owner.implClass)); - staticCall(sym1) - } -*/ case _ => tree } @@ -380,14 +372,6 @@ abstract class Mixin extends InfoTransform { } } } -/* - case Ident(_) => - if (sym.owner.isClass) { - assert(sym.isModuleVar, sym); - assert(!sym.owner.isImplClass, sym); - atPos(tree.pos) { - gen.SelectThis( -*/ case Assign(Apply(lhs @ Select(qual, _), List()), rhs) => localTyper.typed { atPos(tree.pos) { diff --git a/sources/scala/tools/nsc/typechecker/RefChecks.scala b/sources/scala/tools/nsc/typechecker/RefChecks.scala index 9f3bb56d3c..b6becf5972 100755 --- a/sources/scala/tools/nsc/typechecker/RefChecks.scala +++ b/sources/scala/tools/nsc/typechecker/RefChecks.scala @@ -81,6 +81,10 @@ abstract class RefChecks extends InfoTransform { mvarRef)) } + // def m: T; + def newModuleAccessDcl(accessor: Symbol) = + DefDef(accessor setFlag lateDEFERRED, vparamss => EmptyTree); + class RefCheckTransformer(unit: CompilationUnit) extends Transformer { var localTyper: analyzer.Typer = typer; @@ -450,10 +454,12 @@ abstract class RefChecks extends InfoTransform { val ddef = atPhase(phase.next) { localTyper.typed { - newModuleAccessDef(sym, vdef.symbol) + if (sym.owner.isTrait) newModuleAccessDcl(sym) + else newModuleAccessDef(sym, vdef.symbol) } } - if (sym.owner.isTrait) List(transform(cdef)) + + if (sym.owner.isTrait) transformTrees(List(cdef, ddef)) else transformTrees(List(cdef, vdef, ddef)) } diff --git a/sources/scala/tools/nsc/typechecker/SuperAccessors.scala b/sources/scala/tools/nsc/typechecker/SuperAccessors.scala index 16c8348be7..e5c0194ca0 100755 --- a/sources/scala/tools/nsc/typechecker/SuperAccessors.scala +++ b/sources/scala/tools/nsc/typechecker/SuperAccessors.scala @@ -23,10 +23,19 @@ abstract class SuperAccessors extends transform.Transform { protected def newTransformer(unit: CompilationUnit): Transformer = new SuperAccTransformer; class SuperAccTransformer extends Transformer { - var accDefs: List[Pair[Symbol, ListBuffer[Tree]]] = List(); + private var validCurrentOwner = true; + private var accDefs: List[Pair[Symbol, ListBuffer[Tree]]] = List(); private def accDefBuf(clazz: Symbol) = accDefs.dropWhile(._1.!=(clazz)).head._2; + private def transformArgs(args: List[Tree], formals: List[Type]) = { + if (!formals.isEmpty && formals.last.symbol == definitions.ByNameParamClass) + (args take (formals.length - 1) map transform) ::: + withInvalidOwner { args drop (formals.length - 1) map transform } + else + args map transform + } + override def transform(tree: Tree): Tree = tree match { case Template(parents, body) => val ownAccDefs = new ListBuffer[Tree]; @@ -37,7 +46,7 @@ abstract class SuperAccessors extends transform.Transform { case Select(sup @ Super(_, mix), name) => val clazz = sup.symbol; if (tree.isTerm && mix == nme.EMPTY.toTypeName && - (clazz.isTrait || clazz != currentOwner.enclClass)) { + (clazz.isTrait || clazz != currentOwner.enclClass || !validCurrentOwner)) { val supername = nme.superName(tree.symbol.name); var superAcc = clazz.info.decl(supername).suchThat(.alias.==(tree.symbol)); if (superAcc == NoSymbol) { @@ -54,8 +63,27 @@ abstract class SuperAccessors extends transform.Transform { Select(gen.This(clazz), superAcc) setType tree.tpe; } } else tree + case Apply(fn, args) => + copy.Apply(tree, transform(fn), transformArgs(args, fn.tpe.paramTypes)) + case Function(vparams, body) => + withInvalidOwner { + copy.Function(tree, vparams, transform(body)) + } case _ => super.transform(tree) } + + override def atOwner[A](owner: Symbol)(trans: => A): A = { + if (owner.isClass) validCurrentOwner = true; + super.atOwner(owner)(trans) + } + + private def withInvalidOwner[A](trans: => A): A = { + val prevValidCurrentOwner = validCurrentOwner; + validCurrentOwner = false; + val result = trans; + validCurrentOwner = prevValidCurrentOwner; + result + } } } |