summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-12-13 05:22:43 +0000
committerPaul Phillips <paulp@improving.org>2010-12-13 05:22:43 +0000
commitf033bc401a524cd14a49730df74a62ab9acbf586 (patch)
treec54f8728f05e69ba47394c0093a714f5c0af1577
parent1e6c122c44af3d29f8c0f55e7bc3318a9d1b87a6 (diff)
downloadscala-f033bc401a524cd14a49730df74a62ab9acbf586.tar.gz
scala-f033bc401a524cd14a49730df74a62ab9acbf586.tar.bz2
scala-f033bc401a524cd14a49730df74a62ab9acbf586.zip
Hardening the repl against my own lack of ept.
-rw-r--r--src/compiler/scala/tools/nsc/Interpreter.scala24
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/History.scala4
-rw-r--r--src/compiler/scala/tools/nsc/interpreter/JLineReader.scala4
3 files changed, 15 insertions, 17 deletions
diff --git a/src/compiler/scala/tools/nsc/Interpreter.scala b/src/compiler/scala/tools/nsc/Interpreter.scala
index 96c2900776..f9eddd2eda 100644
--- a/src/compiler/scala/tools/nsc/Interpreter.scala
+++ b/src/compiler/scala/tools/nsc/Interpreter.scala
@@ -148,7 +148,7 @@ class Interpreter(val settings: Settings, out: PrintWriter) {
else null
}
- import compiler.{ Traverser, CompilationUnit, Symbol, Name, Type, TypeRef, PolyType }
+ import compiler.{ Traverser, CompilationUnit, Symbol, Name, TermName, TypeName, Type, TypeRef, PolyType }
import compiler.{
Tree, TermTree, ValOrDefDef, ValDef, DefDef, Assign, ClassDef,
ModuleDef, Ident, BackQuotedIdent, Select, TypeDef, Import, MemberDef, DocDef,
@@ -268,12 +268,16 @@ class Interpreter(val settings: Settings, out: PrintWriter) {
}
/** Stubs for work in progress. */
- def handleTypeRedefinition(name: Name, old: Request, req: Request) = {
- DBG("Redefining type '%s'\n %s -> %s".format(name, old simpleNameOfType name, req simpleNameOfType name))
+ def handleTypeRedefinition(name: TypeName, old: Request, req: Request) = {
+ for (t1 <- old.simpleNameOfType(name) ; t2 <- req.simpleNameOfType(name)) {
+ DBG("Redefining type '%s'\n %s -> %s".format(name, t1, t2))
+ }
}
- def handleTermRedefinition(name: Name, old: Request, req: Request) = {
- DBG("Redefining term '%s'\n %s -> %s".format(name, old compilerTypeOf name, req compilerTypeOf name))
+ def handleTermRedefinition(name: TermName, old: Request, req: Request) = {
+ for (t1 <- old.compilerTypeOf get name ; t2 <- req.compilerTypeOf get name) {
+ DBG("Redefining term '%s'\n %s -> %s".format(name, t1, t2))
+ }
}
def recordRequest(req: Request) {
@@ -287,8 +291,8 @@ class Interpreter(val settings: Settings, out: PrintWriter) {
req.boundNames foreach { name =>
if (boundNameMap contains name) {
- if (name.isTypeName) handleTypeRedefinition(name, boundNameMap(name), req)
- else handleTermRedefinition(name, boundNameMap(name), req)
+ if (name.isTypeName) handleTypeRedefinition(name.toTypeName, boundNameMap(name), req)
+ else handleTermRedefinition(name.toTermName, boundNameMap(name), req)
}
boundNameMap(name) = req
}
@@ -986,8 +990,7 @@ class Interpreter(val settings: Settings, out: PrintWriter) {
/* typeOf lookup with encoding */
def lookupTypeOf(name: Name) = typeOf.getOrElse(name, typeOf(compiler encode name))
-
- def simpleNameOfType(name: Name) = compilerTypeOf(name).typeSymbol.simpleName
+ def simpleNameOfType(name: TypeName) = (compilerTypeOf get name) map (_.typeSymbol.simpleName)
private def typeMap[T](f: Type => T): Map[Name, T] = {
def toType(name: Name): T = {
@@ -1291,9 +1294,8 @@ class Interpreter(val settings: Settings, out: PrintWriter) {
// }
// debugging
- def isReplDebug = settings.Yrepldebug.value
def isCompletionDebug = settings.Ycompletion.value
- def DBG(s: String) = if (isReplDebug) out println s else ()
+ def DBG(s: String) = repldbg(s)
}
/** Utility methods for the Interpreter. */
diff --git a/src/compiler/scala/tools/nsc/interpreter/History.scala b/src/compiler/scala/tools/nsc/interpreter/History.scala
index 4750b8ec60..426c1f6c35 100644
--- a/src/compiler/scala/tools/nsc/interpreter/History.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/History.scala
@@ -33,10 +33,6 @@ class History(val jhistory: JHistory) {
object History {
val ScalaHistoryFile = ".scala_history"
- def apply(reader: ConsoleReader): History =
- if (reader == null) apply()
- else new History(reader.getHistory)
-
def apply(): History = new History(
try new FileHistory(new File(userHome, ScalaHistoryFile))
catch {
diff --git a/src/compiler/scala/tools/nsc/interpreter/JLineReader.scala b/src/compiler/scala/tools/nsc/interpreter/JLineReader.scala
index 153c0b42ed..7e3746963f 100644
--- a/src/compiler/scala/tools/nsc/interpreter/JLineReader.scala
+++ b/src/compiler/scala/tools/nsc/interpreter/JLineReader.scala
@@ -16,7 +16,7 @@ class JLineReader(interpreter: Interpreter) extends InteractiveReader {
def this() = this(null)
override lazy val history = {
- val h = History(consoleReader)
+ val h = History()
system addShutdownHook {
repldbg("Flushing history")
h.flush()
@@ -33,8 +33,8 @@ class JLineReader(interpreter: Interpreter) extends InteractiveReader {
val consoleReader = {
val r = new ConsoleReader()
- r setHistory (History().jhistory) // placeholder
r setBellEnabled false
+ history foreach { r setHistory _.jhistory }
completion foreach { c =>
r addCompleter c.jline
r setAutoprintThreshold 250 // max completion candidates without warning