summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2007-04-24 17:57:36 +0000
committerMartin Odersky <odersky@gmail.com>2007-04-24 17:57:36 +0000
commit47070250999ab94deffec0397c62a419c1e25992 (patch)
tree378ebd02cac3ee8fa94c066aa06444b0dfdb400d /src
parent437535a2dee7b85143d8bf438c88965a6ce0393c (diff)
downloadscala-47070250999ab94deffec0397c62a419c1e25992.tar.gz
scala-47070250999ab94deffec0397c62a419c1e25992.tar.bz2
scala-47070250999ab94deffec0397c62a419c1e25992.zip
removed actors & freinds from concurrent
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/CompileServer.scala2
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala256
-rw-r--r--src/library/scala/concurrent/Actor.scala48
-rw-r--r--src/library/scala/concurrent/NameServer.scala46
-rw-r--r--src/library/scala/concurrent/Pid.scala48
-rw-r--r--src/library/scala/concurrent/Process.scala93
6 files changed, 130 insertions, 363 deletions
diff --git a/src/compiler/scala/tools/nsc/CompileServer.scala b/src/compiler/scala/tools/nsc/CompileServer.scala
index 4e4f37ee0c..cefb1ffa60 100644
--- a/src/compiler/scala/tools/nsc/CompileServer.scala
+++ b/src/compiler/scala/tools/nsc/CompileServer.scala
@@ -9,7 +9,7 @@ package scala.tools.nsc
import java.io.{BufferedOutputStream, File, FileOutputStream, PrintStream}
import java.lang.{Runtime, System, Thread}
-import scala.concurrent.Process.spawn
+import scala.concurrent.ops.spawn
import scala.tools.nsc.doc.DocGenerator
import scala.tools.nsc.reporters.{Reporter, ConsoleReporter}
import scala.tools.nsc.util.FakePos //Position
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index bdbc3532b4..bc8f39908c 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -863,130 +863,145 @@ trait Parsers {
def expr(): Tree = expr(Local)
/** XXX: Hook for IDE */
- def expr(location: int): Tree = in.token match {
- case IF =>
- val pos = in.skipToken
- accept(LPAREN)
- val cond = expr()
- accept(RPAREN)
- newLinesOpt()
- val thenp = expr()
- val elsep =
- if (in.token == ELSE) { in.nextToken; expr() }
- else EmptyTree
- atPos(pos) { If(cond, thenp, elsep) }
- case TRY =>
- atPos(in.skipToken) {
- accept(LBRACE)
- val body = block()
- accept(RBRACE)
- val catches =
- if (in.token == CATCH) {
- in.nextToken
- accept(LBRACE)
- val cases = caseClauses()
- accept(RBRACE)
- cases
- } else List()
- val finalizer =
- if (in.token == FINALLY) { in.nextToken; expr() }
+ def expr(location: int): Tree = {
+ var savedImplicitParams = implicitParams
+ implicitParams = List()
+ var res = in.token match {
+ case IF =>
+ val pos = in.skipToken
+ accept(LPAREN)
+ val cond = expr()
+ accept(RPAREN)
+ newLinesOpt()
+ val thenp = expr()
+ val elsep =
+ if (in.token == ELSE) { in.nextToken; expr() }
else EmptyTree
- Try(body, catches, finalizer)
- }
- case WHILE =>
- val lname: Name = freshName("while$")
- val pos = in.skipToken
- accept(LPAREN)
- val cond = expr()
- accept(RPAREN)
- newLinesOpt()
- val body = expr()
- atPos(pos) { makeWhile(lname, cond, body) }
- case DO =>
- val lname: Name = freshName("doWhile$")
- val pos = in.skipToken
- val body = expr()
- if (isStatSep) in.nextToken
- accept(WHILE)
- accept(LPAREN)
- val cond = expr()
- accept(RPAREN)
- atPos(pos) { makeDoWhile(lname, body, cond) }
- case FOR =>
- atPos(in.skipToken) {
- val startToken = in.token
- accept(if (startToken == LBRACE) LBRACE else LPAREN)
- val enums = enumerators()
- accept(if (startToken == LBRACE) RBRACE else RPAREN)
+ atPos(pos) { If(cond, thenp, elsep) }
+ case TRY =>
+ atPos(in.skipToken) {
+ accept(LBRACE)
+ val body = block()
+ accept(RBRACE)
+ val catches =
+ if (in.token == CATCH) {
+ in.nextToken
+ accept(LBRACE)
+ val cases = caseClauses()
+ accept(RBRACE)
+ cases
+ } else List()
+ val finalizer =
+ if (in.token == FINALLY) { in.nextToken; expr() }
+ else EmptyTree
+ Try(body, catches, finalizer)
+ }
+ case WHILE =>
+ val lname: Name = freshName("while$")
+ val pos = in.skipToken
+ accept(LPAREN)
+ val cond = expr()
+ accept(RPAREN)
newLinesOpt()
- if (in.token == YIELD) {
- in.nextToken; makeForYield(enums, expr())
- } else makeFor(enums, expr())
- }
- case RETURN =>
- atPos(in.skipToken) {
- Return(if (isExprIntro) expr() else Literal(()))
- }
- case THROW =>
- atPos(in.skipToken) {
- Throw(expr())
- }
- case DOT =>
- //todo: deprecate
- atPos(in.skipToken) {
- if (isIdent) {
- makeDotClosure(stripParens(simpleExpr()))
- } else {
- syntaxErrorOrIncomplete("identifier expected", true)
- errorTermTree
+ val body = expr()
+ atPos(pos) { makeWhile(lname, cond, body) }
+ case DO =>
+ val lname: Name = freshName("doWhile$")
+ val pos = in.skipToken
+ val body = expr()
+ if (isStatSep) in.nextToken
+ accept(WHILE)
+ accept(LPAREN)
+ val cond = expr()
+ accept(RPAREN)
+ atPos(pos) { makeDoWhile(lname, body, cond) }
+ case FOR =>
+ atPos(in.skipToken) {
+ val startToken = in.token
+ accept(if (startToken == LBRACE) LBRACE else LPAREN)
+ val enums = enumerators()
+ accept(if (startToken == LBRACE) RBRACE else RPAREN)
+ newLinesOpt()
+ if (in.token == YIELD) {
+ in.nextToken; makeForYield(enums, expr())
+ } else makeFor(enums, expr())
}
- }
- case _ =>
- var t = postfixExpr()
- if (in.token == EQUALS) {
- t match {
- case Ident(_) | Select(_, _) | Apply(_, _) =>
- t = atPos(in.skipToken) { makeAssign(t, expr()) }
- case _ =>
+ case RETURN =>
+ atPos(in.skipToken) {
+ Return(if (isExprIntro) expr() else Literal(()))
}
- } else if (in.token == COLON) {
- t = stripParens(t)
- val pos = in.skipToken
- val annots = annotations()
- if (in.token == USCORE) {
- val pos1 = in.skipToken
- if (isIdent && in.name == nme.STAR) {
- in.nextToken
+ case THROW =>
+ atPos(in.skipToken) {
+ Throw(expr())
+ }
+ case DOT =>
+ //todo: deprecate
+ atPos(in.skipToken) {
+ if (isIdent) {
+ makeDotClosure(stripParens(simpleExpr()))
+ } else {
+ syntaxErrorOrIncomplete("identifier expected", true)
+ errorTermTree
+ }
+ }
+ case _ =>
+ var t = postfixExpr()
+ if (in.token == EQUALS) {
+ t match {
+ case Ident(_) | Select(_, _) | Apply(_, _) =>
+ t = atPos(in.skipToken) { makeAssign(t, expr()) }
+ case _ =>
+ }
+ } else if (in.token == COLON) {
+ t = stripParens(t)
+ val pos = in.skipToken
+ val annots = annotations()
+ if (in.token == USCORE) {
+ val pos1 = in.skipToken
+ if (isIdent && in.name == nme.STAR) {
+ in.nextToken
+ t = atPos(pos) {
+ Typed(t, atPos(pos1) { Ident(nme.WILDCARD_STAR.toTypeName) })
+ }
+ } else {
+ syntaxErrorOrIncomplete("`*' expected", true)
+ }
+ } else if (annots.isEmpty || isTypeIntro) {
t = atPos(pos) {
- Typed(t, atPos(pos1) { Ident(nme.WILDCARD_STAR.toTypeName) })
+ val tpt = if (location != Local) compoundType(false) else typ()
+ // this does not correspond to syntax, but is necessary to
+ // accept closures. We might restrict closures to be between {...} only!
+ Typed(t, (tpt /: annots) (makeAnnotated))
}
} else {
- syntaxErrorOrIncomplete("`*' expected", true)
+ t = (t /: annots) (makeAnnotated)
}
- } else if (annots.isEmpty || isTypeIntro) {
- t = atPos(pos) {
- val tpt = if (location != Local) compoundType(false) else typ()
- // this does not correspond to syntax, but is necessary to
- // accept closures. We might restrict closures to be between {...} only!
- Typed(t, (tpt /: annots) (makeAnnotated))
+ } else if (in.token == MATCH) {
+ t = atPos(in.skipToken) {
+ accept(LBRACE)
+ val cases = caseClauses()
+ accept(RBRACE)
+ Match(stripParens(t), cases)
}
- } else {
- t = (t /: annots) (makeAnnotated)
}
- } else if (in.token == MATCH) {
- t = atPos(in.skipToken) {
- accept(LBRACE)
- val cases = caseClauses()
- accept(RBRACE)
- Match(stripParens(t), cases)
- }
- }
- if (in.token == ARROW && location != InTemplate) {
- t = atPos(in.skipToken) {
- Function(convertToParams(t), if (location == Local) expr() else block())
+ if (in.token == ARROW && location != InTemplate) {
+ t = atPos(in.skipToken) {
+ Function(convertToParams(t), if (location == Local) expr() else block())
+ }
}
- }
- stripParens(t)
+ stripParens(t)
+ }
+ def isWildcard(t: Tree): boolean = t match {
+ case Ident(name1) if name1 == implicitParams.head.name => true
+ case Typed(t1, _) => isWildcard(t1)
+ case Annotated(t1, _) => isWildcard(t1)
+ case _ => false
+ }
+ if (!implicitParams.isEmpty)
+ if (isWildcard(res)) savedImplicitParams = savedImplicitParams ::: implicitParams
+ else res = Function(implicitParams.reverse, res)
+ implicitParams = savedImplicitParams
+ res
}
/** PostfixExpr ::= InfixExpr [Id [nl]]
@@ -994,8 +1009,6 @@ trait Parsers {
* | InfixExpr Id [nl] InfixExpr
*/
def postfixExpr(): Tree = {
- var savedImplicitParams = implicitParams
- implicitParams = List()
val base = opstack
var top = prefixExpr()
while (isIdent) {
@@ -1015,18 +1028,7 @@ trait Parsers {
topinfo.operator.encode).setPos(topinfo.pos)
}
}
- var res = reduceStack(true, base, top, 0, true)
- def isWildcard(t: Tree): boolean = t match {
- case Ident(name1) if name1 == implicitParams.head.name => true
- case Typed(t1, _) => isWildcard(t1)
- case Annotated(t1, _) => isWildcard(t1)
- case _ => false
- }
- if (!implicitParams.isEmpty)
- if (isWildcard(res)) savedImplicitParams = savedImplicitParams ::: implicitParams
- else res = Function(implicitParams.reverse, res)
- implicitParams = savedImplicitParams
- res
+ reduceStack(true, base, top, 0, true)
}
/** PrefixExpr ::= [`-' | `+' | `~' | `!' | `&'] SimpleExpr
diff --git a/src/library/scala/concurrent/Actor.scala b/src/library/scala/concurrent/Actor.scala
deleted file mode 100644
index 54f3d37a0a..0000000000
--- a/src/library/scala/concurrent/Actor.scala
+++ /dev/null
@@ -1,48 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id: Actor.scala 9235 2006-11-13 14:59:18 +0000 (Mon, 13 Nov 2006) mihaylov $
-
-
-package scala.concurrent
-
-
-import java.lang.Thread
-
-/**
- * The class <code>Actor</code> ...
- *
- * @author Martin Odersky
- * @version 1.0
- */
-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 (currentThread == this) in.receive(f)
- else throw new IllegalArgumentException("receive called not on own process")
-
- def receiveWithin[a](msec: long)(f: PartialFunction[in.Message, a]): a =
- if (currentThread == this) in.receiveWithin(msec)(f)
- else throw new IllegalArgumentException("receiveWithin called not on own process")
-
- private var pid: Pid = null
-
- def self = {
- if (pid eq null) pid = new Pid(this)
- pid
- }
-
- def self_= (p: Pid) = pid = p
-}
-
-
-
diff --git a/src/library/scala/concurrent/NameServer.scala b/src/library/scala/concurrent/NameServer.scala
deleted file mode 100644
index bb15def799..0000000000
--- a/src/library/scala/concurrent/NameServer.scala
+++ /dev/null
@@ -1,46 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-
-package scala.concurrent
-
-
-/**
- * @author Erik Stenman
- * @version 1.0, 01/10/2003
- */
-object NameServer {
-
- val names = new scala.collection.mutable.HashMap[Symbol, Process]
-
- /**
- * @param name ...
- * @param proc ...
- */
- def register(name: Symbol, proc: Process) = {
- if (names contains name) throw new IllegalArgumentException("Name:" + name + " already registred")
- names += name -> proc
- }
-
- def unregister(name: Symbol) =
- if (names contains name) names -= name
- else throw new IllegalArgumentException("Name:" + name + " not registred")
-
- /**
- * @param name ...
- * @return ...
- */
- def whereis(name: Symbol): Option[Process] =
- names.get(name)
-
- def send(name: Symbol, msg: MailBox#Message) =
- names(name).send(msg)
-
-}
diff --git a/src/library/scala/concurrent/Pid.scala b/src/library/scala/concurrent/Pid.scala
deleted file mode 100644
index 6fa1f24123..0000000000
--- a/src/library/scala/concurrent/Pid.scala
+++ /dev/null
@@ -1,48 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2006, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-
-package scala.concurrent
-
-/**
- * The class <code>Pid</code> provides process identifiers
- * to thread-based actors.
- *
- * @author Philipp Haller
- * @version 1.0
- */
-class Pid(actor: Actor) {
- private var target = actor
-
- def !(msg: MailBox#Message) = target send msg
-
- def spawn(body: Actor => Unit): Pid = {
- val a = new Actor {
- override def run: Unit = body(this)
- }
- a.start
- a.self
- }
-
- def spawnReceive(cases: PartialFunction[MailBox#Message, Unit]) = {
- val a = new Actor {
- override def run: Unit = receive(cases)
- }
- a.start
- a.self
- }
-
- override def hashCode() = target.hashCode()
-
- override def equals(that: Any) =
- this.hashCode() == that.hashCode()
-
- override def toString() = "Pid(" + target + ")"
-}
diff --git a/src/library/scala/concurrent/Process.scala b/src/library/scala/concurrent/Process.scala
deleted file mode 100644
index 8140433ce8..0000000000
--- a/src/library/scala/concurrent/Process.scala
+++ /dev/null
@@ -1,93 +0,0 @@
-/* __ *\
-** ________ ___ / / ___ Scala API **
-** / __/ __// _ | / / / _ | (c) 2003-2007, LAMP/EPFL **
-** __\ \/ /__/ __ |/ /__/ __ | **
-** /____/\___/_/ |_/____/_/ | | **
-** |/ **
-\* */
-
-// $Id$
-
-
-package scala.concurrent
-
-
-/** This object ...
- *
- * @author Erik Stenman
- * @version 1.0, 01/10/2003
- */
-object Process {
-
- def spawn(body: => Unit): Process = {
- val p = new Process(body)
- p.start()
- p
- }
-
- def spawn_link(body: => Unit): Process =
- self.spawn_link(body)
-
- def send(p: Process, msg: MailBox#Message) =
- p.send(msg)
-
- def receive[a](f: PartialFunction[MailBox#Message, a]): a =
- self.receive(f)
-
- def receiveWithin[a](msec: long)(f: PartialFunction[MailBox#Message, a]): a =
- self.receiveWithin(msec)(f)
-
- /**
- * @return the self process
- * @throws Predef.UnsupportedOperationException if self called outside a process.
- */
- def self: Process =
- if (currentThread.isInstanceOf[Process])
- currentThread.asInstanceOf[Process]
- else
- throw new UnsupportedOperationException("Self called outside a process")
-
- def exit(p: Process, reason: AnyRef) =
- p.exit(reason)
-
-}
-
-class Process(body: => Unit) extends Actor() {
- private var exitReason: AnyRef = null
- private var links: List[Process] = Nil
-
- override def run() =
- try {
- body
- }
- catch {
- case _: java.lang.InterruptedException =>
- signal(exitReason)
- case (exitSignal) =>
- signal(exitSignal)
- }
-
- private def signal(s: MailBox#Message) =
- links.foreach { p: Process => p.send(('EXIT, this, s)) }
-
- def !(msg: MailBox#Message) =
- send(msg)
-
- def link(p: Process) =
- links = p::links
-
- def spawn_link(body: => Unit) = {
- val p = new Process(body)
- p.link(this)
- p.start()
- p
- }
-
- //def self = this
-
- def exit(reason: AnyRef): Unit = {
- exitReason = reason
- interrupt()
- }
-
-}