Skip to content

Commit

Permalink
Cleanup ConsoleInterface
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed May 4, 2017
1 parent 07647b9 commit 1abf6ca
Showing 1 changed file with 12 additions and 29 deletions.
41 changes: 12 additions & 29 deletions internal/compiler-bridge/src/main/scala/xsbt/ConsoleInterface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
package xsbt

import xsbti.Logger
import scala.tools.nsc.{ GenericRunnerCommand, Settings }
import scala.tools.nsc.interpreter.{ IMain, InteractiveReader, ILoop }
import scala.tools.nsc.interpreter.{ ILoop, IMain, InteractiveReader }
import scala.tools.nsc.reporters.Reporter
import scala.tools.nsc.{ GenericRunnerCommand, Settings }

class ConsoleInterface {
def commandArguments(
Expand All @@ -35,58 +35,48 @@ class ConsoleInterface {
lazy val interpreterSettings = MakeSettings.sync(args.toList, log)
val compilerSettings = MakeSettings.sync(args, bootClasspathString, classpathString, log)

if (!bootClasspathString.isEmpty)
compilerSettings.bootclasspath.value = bootClasspathString
compilerSettings.classpath.value = classpathString
log.info(Message("Starting scala interpreter..."))
log.info(Message(""))
val loop = new ILoop {

val loop = new ILoop {
override def createInterpreter() = {

if (loader ne null) {
in = InteractiveReader.apply()
intp = new IMain(settings) {
override protected def parentClassLoader =
if (loader eq null) super.parentClassLoader else loader

override protected def newCompiler(settings: Settings, reporter: Reporter) =
super.newCompiler(compilerSettings, reporter)
}
intp.setContextClassLoader()
} else
super.createInterpreter()

def bind(values: Seq[(String, Any)]): Unit = {
// for 2.8 compatibility
final class Compat {
def bindValue(id: String, value: Any) =
intp.bind(id, value.asInstanceOf[AnyRef].getClass.getName, value)
}
implicit def compat(a: AnyRef): Compat = new Compat

for ((id, value) <- values)
intp.beQuietDuring(intp.bindValue(id, value))
}

bind(bindNames zip bindValues)
for ((id, value) <- bindNames zip bindValues)
intp.beQuietDuring(intp.bind(id, value))

if (!initialCommands.isEmpty)
intp.interpret(initialCommands)

()
}

override def closeInterpreter(): Unit = {
if (!cleanupCommands.isEmpty)
intp.interpret(cleanupCommands)
super.closeInterpreter()
}
}

loop.process(if (loader eq null) compilerSettings else interpreterSettings)

()
}
}

object MakeSettings {
def apply(args: List[String], log: Logger) = {
def apply(args: List[String], log: Logger): Settings = {
val command = new GenericRunnerCommand(args, message => log.error(Message(message)))
if (command.ok)
command.settings
Expand All @@ -107,15 +97,8 @@ object MakeSettings {
compilerSettings
}

def sync(options: List[String], log: Logger) = {
def sync(options: List[String], log: Logger): Settings = {
val settings = apply(options, log)

// -Yrepl-sync is only in 2.9.1+
final class Compat {
def Yreplsync = settings.BooleanSetting("-Yrepl-sync", "For compatibility only.")
}
implicit def compat(s: Settings): Compat = new Compat

settings.Yreplsync.value = true
settings
}
Expand Down

0 comments on commit 1abf6ca

Please sign in to comment.