scala.tools.nsc.interpreter

IMain

class IMain extends Imports

An interpreter for Scala code.

The main public entry points are compile(), interpret(), and bind(). The compile() method loads a complete Scala file. The interpret() method executes one line of Scala code at the request of the user. The bind() method binds an object to a variable that can then be used by later interpreted code.

The overall approach is based on compiling the requested code and then using a Java classloader and Java reflection to run the code and access its results.

In more detail, a single compiler instance is used to accumulate all successfully compiled or interpreted Scala code. To "interpret" a line of code, the compiler generates a fresh object that includes the line of code and which has public member(s) to export all variables defined by that code. To extract the result of an interpreted line to show the user, a second "result object" is created which imports the variables exported by the above object and then exports members called "$eval" and "$print". To accomodate user expressions that read from variables or methods defined in previous statements, "import" statements are used.

This interpreter shares the strengths and weaknesses of using the full compiler-to-Java. The main strength is that interpreted code behaves exactly as does compiled code, including running at full speed. The main weakness is that redefining classes and methods is not handled properly, because rebinding at the Java level is technically difficult.

Self Type
IMain
Source
IMain.scala
Linear Supertypes
Known Subclasses
Type Hierarchy Learn more about scaladoc diagrams
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. IMain
  2. Imports
  3. AnyRef
  4. Any
Implicitly
  1. by IMainOps
  2. by any2stringadd
  3. by any2stringfmt
  4. by any2ArrowAssoc
  5. by any2Ensuring
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new IMain()

  2. new IMain(settings: Settings)

    construct an interpreter that reports to Console

  3. new IMain(initialSettings: Settings, out: JPrintWriter)

Type Members

  1. case class ComputedImports(prepend: String, append: String, access: String) extends Product with Serializable

    Compute imports that allow definitions from previous requests to be visible in a new request.

  2. abstract class PhaseDependentOps extends AnyRef

  3. class ReadEvalPrint extends AnyRef

    Here is where we:

  4. implicit class ReplTypeOps extends AnyRef

  5. class Request extends AnyRef

    One line of code submitted by the user for interpretation

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. def +(other: String): String

    Implicit information
    This member is added by an implicit conversion from IMain to StringAdd performed by method any2stringadd in scala.Predef.
    Definition Classes
    StringAdd
  5. def ->[B](y: B): (IMain, B)

    Implicit information
    This member is added by an implicit conversion from IMain to ArrowAssoc[IMain] performed by method any2ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  6. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  7. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  8. def allDefinedNames: List[Global.Name]

  9. def allHandlers: collection.immutable.List[(memberHandlers)#MemberHandler]

  10. def allImportedNames: collection.immutable.List[Global.Name]

    Definition Classes
    Imports
  11. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  12. def backticked(s: String): String

  13. def beQuietDuring[T](body: ⇒ T): T

    Temporarily be quiet

  14. def beSilentDuring[T](operation: ⇒ T): T

  15. def bind[T](name: String, value: T)(implicit arg0: reflect.api.JavaUniverse.TypeTag[T], arg1: ClassTag[T]): Result

  16. def bind(p: NamedParam): Result

  17. def bind(name: String, boundType: String, value: Any, modifiers: List[String] = Nil): Result

    Bind a specified name to a specified value.

    Bind a specified name to a specified value. The name may later be used by expressions passed to interpret.

    name

    the variable name to bind

    boundType

    the type of the variable, as a string

    value

    the object value to bind to it

    returns

    an indication of whether the binding succeeded

  18. def classLoader: AbstractFileClassLoader

  19. def classOfTerm(id: String): Option[JClass]

  20. def cleanMemberDecl(owner: Global.Symbol, member: Global.Name): Global.Type

  21. def cleanTypeAfterTyper(sym: ⇒ Global.Symbol): Global.Type

  22. def clearExecutionWrapper(): Unit

  23. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  24. def close(): Unit

    This instance is no longer needed, so release any resources it is using.

    This instance is no longer needed, so release any resources it is using. The reporter's output gets flushed.

  25. def compileSources(sources: SourceFile*): Boolean

    Compile an nsc SourceFile.

    Compile an nsc SourceFile. Returns true if there are no compilation errors, or false otherwise.

  26. def compileSourcesKeepingRun(sources: SourceFile*): (Boolean, Run)

  27. def compileString(code: String): Boolean

    Compile a string.

    Compile a string. Returns true if there are no compilation errors, or false otherwise.

  28. def compilerClasspath: Seq[URL]

  29. def debugging[T](msg: String)(res: T): T

  30. object deconstruct extends StructuredTypeStrings

  31. def definedSymbolList: collection.immutable.List[Global.Symbol]

  32. def definedTerms: collection.immutable.List[Global.TermName]

  33. def definedTypes: List[Global.TypeName]

  34. def directBind[T](name: String, value: T)(implicit arg0: reflect.api.JavaUniverse.TypeTag[T], arg1: ClassTag[T]): Result

  35. def directBind(p: NamedParam): Result

  36. def directBind(name: String, boundType: String, value: Any): Result

  37. def echoTypeSignature: ((sym: _1905.intp.global.Symbol, verbose: Boolean)Unit) forSome {val _1905: IMainOps}

    Implicit information
    This member is added by an implicit conversion from IMain to IMainOps performed by method IMainOps in scala.tools.nsc.interpreter.
    Definition Classes
    IMainOps
  38. def echoTypeStructure: ((sym: _1911.intp.global.Symbol)Unit) forSome {val _1911: IMainOps}

    Implicit information
    This member is added by an implicit conversion from IMain to IMainOps performed by method IMainOps in scala.tools.nsc.interpreter.
    Definition Classes
    IMainOps
  39. final def ensureClassLoader(): Unit

  40. def ensuring(cond: (IMain) ⇒ Boolean, msg: ⇒ Any): IMain

    Implicit information
    This member is added by an implicit conversion from IMain to Ensuring[IMain] performed by method any2Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  41. def ensuring(cond: (IMain) ⇒ Boolean): IMain

    Implicit information
    This member is added by an implicit conversion from IMain to Ensuring[IMain] performed by method any2Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  42. def ensuring(cond: Boolean, msg: ⇒ Any): IMain

    Implicit information
    This member is added by an implicit conversion from IMain to Ensuring[IMain] performed by method any2Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  43. def ensuring(cond: Boolean): IMain

    Implicit information
    This member is added by an implicit conversion from IMain to Ensuring[IMain] performed by method any2Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  44. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  45. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  46. def executionWrapper: String

  47. object exprTyper extends ExprTyper

  48. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  49. object flatOp extends PhaseDependentOps

  50. def flatPath(sym: Global.Symbol): String

  51. def formatted(fmtstr: String): String

    Implicit information
    This member is added by an implicit conversion from IMain to StringFormat performed by method any2stringfmt in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  52. lazy val formatting: Formatting

  53. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  54. def getClassIfDefined(path: String): Global.Symbol

  55. def getModuleIfDefined(path: String): Global.Symbol

  56. lazy val global: Global

    the public, go through the future compiler

  57. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  58. def implicitSymbolsBySource: List[(Global.Symbol, List[Global.Symbol])]

    Definition Classes
    Imports
  59. def implicitsCommand(line: String): String

    Implicit information
    This member is added by an implicit conversion from IMain to IMainOps performed by method IMainOps in scala.tools.nsc.interpreter.
    Definition Classes
    IMainOps
  60. def importHandlers: collection.immutable.List[(memberHandlers)#ImportHandler]

  61. def importedSymbols: collection.immutable.List[Global.Symbol]

    Definition Classes
    Imports
  62. def importedSymbolsBySource: List[(Global.Symbol, List[Global.Symbol])]

    Tuples of (source, imported symbols) in the order they were imported.

    Tuples of (source, imported symbols) in the order they were imported.

    Definition Classes
    Imports
  63. def importedTermSymbols: collection.immutable.List[Global.TermSymbol]

    Definition Classes
    Imports
  64. def importsCode(wanted: Set[Global.Name]): ComputedImports

    Attributes
    protected
    Definition Classes
    Imports
  65. def initialize(postInitSignal: ⇒ Unit): Unit

  66. def initializeSynchronous(): Unit

  67. def interpret(line: String, synthetic: Boolean): Result

  68. def interpret(line: String): Result

    Interpret one line of input.

    Interpret one line of input. All feedback, including parse errors and evaluation results, are printed via the supplied compiler's reporter. Values defined are available for future interpreted strings.

    The return value is whether the line was interpreter successfully, e.g. that there were no parse errors.

  69. def interpretSynthetic(line: String): Result

  70. val intp: IMain

    Implicit information
    This member is added by an implicit conversion from IMain to IMainOps performed by method IMainOps in scala.tools.nsc.interpreter.
    Definition Classes
    IMainOps
  71. def isInitializeComplete: Boolean

  72. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  73. lazy val isettings: ISettings

    interpreter settings

  74. def languageSymbols: collection.immutable.List[Global.Symbol]

    Definition Classes
    Imports
  75. def languageWildcardHandlers: collection.immutable.List[(memberHandlers)#ImportHandler]

    Definition Classes
    Imports
  76. def languageWildcardSyms: List[Global.Symbol]

    Symbols whose contents are language-defined to be imported.

    Symbols whose contents are language-defined to be imported.

    Definition Classes
    Imports
  77. def lastRequest: Request

  78. def lastWarnings: List[(Global.Position, String)]

  79. lazy val memberHandlers: MemberHandlers { val intp: IMain.this.type }

  80. def mostRecentVar: String

    Returns the name of the most recent interpreter result.

    Returns the name of the most recent interpreter result. Mostly this exists so you can conveniently invoke methods on the previous result.

  81. def namedDefinedTerms: collection.immutable.List[Global.TermName]

  82. object naming extends Naming

  83. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  84. def newCompiler(settings: Settings, reporter: Reporter): ReplGlobal

    Instantiate a compiler.

    Instantiate a compiler. Overridable.

    Attributes
    protected
  85. def normalizeNonPublic(tp: Global.Type): Global.Type

  86. final def notify(): Unit

    Definition Classes
    AnyRef
  87. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  88. def onlyTerms(xs: List[Global.Name]): List[Global.TermName]

    Attributes
    protected
  89. def onlyTypes(xs: List[Global.Name]): List[Global.TypeName]

    Attributes
    protected
  90. def originalPath(sym: Global.Symbol): String

  91. def originalPath(name: Global.Name): String

  92. def originalPath(name: String): String

  93. val out: JPrintWriter

    Attributes
    protected
  94. def parentClassLoader: ClassLoader

    Parent classloader.

    Parent classloader. Overridable.

    Attributes
    protected
  95. def parse(line: String): Option[List[Global.Tree]]

  96. def prevRequestList: collection.immutable.List[Request]

  97. def printAfterTyper(msg: ⇒ String): Unit

    Implicit information
    This member is added by an implicit conversion from IMain to IMainOps performed by method IMainOps in scala.tools.nsc.interpreter.
    Definition Classes
    IMainOps
  98. def quietBind(p: NamedParam): Result

  99. def quietRun[T](code: String): Result

  100. def rebind(p: NamedParam): Result

  101. def recordRequest(req: Request): Unit

  102. object replOutput extends ReplOutput

  103. def replScope: Global.Scope

  104. lazy val reporter: ReplReporter

  105. def reset(): Unit

    Reset this interpreter, forgetting all user-specified requests.

  106. def resetClassLoader(): Unit

  107. def runtimeClassAndTypeOfTerm(id: String): Option[(JClass, Global.Type)]

  108. lazy val runtimeMirror: reflect.api.JavaUniverse.Mirror

  109. def runtimeTypeOfTerm(id: String): Global.Type

  110. def sessionImportedSymbols: collection.immutable.List[Global.Symbol]

    Definition Classes
    Imports
  111. def sessionWildcards: List[Global.Type]

    Types which have been wildcard imported, such as: val x = "abc" ; import x.

    Types which have been wildcard imported, such as: val x = "abc" ; import x._ // type java.lang.String import java.lang.String._ // object java.lang.String

    Used by tab completion.

    XXX right now this gets import x._ and import java.lang.String._, but doesn't figure out import String._. There's a lot of ad hoc scope twiddling which should be swept away in favor of digging into the compiler scopes.

    Definition Classes
    Imports
  112. def setContextClassLoader(): Unit

  113. def setExecutionWrapper(code: String): Unit

  114. def settings: Settings

  115. def showCodeIfDebugging(code: String): Unit

  116. def showDirectory(): Unit

  117. def symbolDefString(sym: Global.Symbol): String

  118. def symbolOfIdent(id: String): Global.Symbol

  119. def symbolOfLine(code: String): Global.Symbol

  120. def symbolOfName(id: Global.Name): Global.Symbol

  121. def symbolOfTerm(id: String): Global.Symbol

  122. def symbolOfType(id: String): Global.Symbol

  123. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  124. def toString(): String

    Definition Classes
    AnyRef → Any
  125. def translateEnclosingClass(n: String): Option[String]

  126. def translatePath(path: String): Option[String]

  127. def tryTwice(op: ⇒ Global.Symbol): Global.Symbol

    It's a bit of a shotgun approach, but for now we will gain in robustness.

    It's a bit of a shotgun approach, but for now we will gain in robustness. Try a symbol-producing operation at phase typer, and if that is NoSymbol, try again at phase flatten. I'll be able to lose this and run only from exitingTyper as soon as I figure out exactly where a flat name is sneaking in when calculating imports.

  128. def typeCommandInternal(expr: String, verbose: Boolean): Unit

    TODO - -n normalize -l label with case class parameter names -c complete - leave nothing out

    TODO - -n normalize -l label with case class parameter names -c complete - leave nothing out

    Implicit information
    This member is added by an implicit conversion from IMain to IMainOps performed by method IMainOps in scala.tools.nsc.interpreter.
    Definition Classes
    IMainOps
  129. def typeOfExpression(expr: String, silent: Boolean = true): Global.Type

  130. def typeOfTerm(id: String): Global.Type

  131. object typerOp extends PhaseDependentOps

  132. def unqualifiedIds: List[String]

  133. def valueOfTerm(id: String): Option[Any]

  134. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  135. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  136. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  137. def withoutUnwrapping(op: ⇒ Unit): Unit

  138. def withoutWarnings[T](body: ⇒ T): T

  139. def [B](y: B): (IMain, B)

    Implicit information
    This member is added by an implicit conversion from IMain to ArrowAssoc[IMain] performed by method any2ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc

Shadowed Implict Value Members

  1. val self: Any

    Implicit information
    This member is added by an implicit conversion from IMain to StringAdd performed by method any2stringadd in scala.Predef.
    Shadowing
    This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
    To access this member you can use a type ascription:
    (iMain: StringAdd).self
    Definition Classes
    StringAdd
  2. val self: Any

    Implicit information
    This member is added by an implicit conversion from IMain to StringFormat performed by method any2stringfmt in scala.Predef.
    Shadowing
    This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
    To access this member you can use a type ascription:
    (iMain: StringFormat).self
    Definition Classes
    StringFormat

Deprecated Value Members

  1. def virtualDirectory: ReplDir

    Annotations
    @deprecated
    Deprecated

    (Since version 2.11.0) Use replOutput.dir instead

  2. def x: IMain

    Implicit information
    This member is added by an implicit conversion from IMain to ArrowAssoc[IMain] performed by method any2ArrowAssoc in scala.Predef.
    Shadowing
    This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
    To access this member you can use a type ascription:
    (iMain: ArrowAssoc[IMain]).x
    Definition Classes
    ArrowAssoc
    Annotations
    @deprecated
    Deprecated

    (Since version 2.10.0) Use leftOfArrow instead

  3. def x: IMain

    Implicit information
    This member is added by an implicit conversion from IMain to Ensuring[IMain] performed by method any2Ensuring in scala.Predef.
    Shadowing
    This implicitly inherited member is ambiguous. One or more implicitly inherited members have similar signatures, so calling this member may produce an ambiguous implicit conversion compiler error.
    To access this member you can use a type ascription:
    (iMain: Ensuring[IMain]).x
    Definition Classes
    Ensuring
    Annotations
    @deprecated
    Deprecated

    (Since version 2.10.0) Use resultOfEnsuring instead

Inherited from Imports

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion IMainOps from IMain to IMainOps

Inherited by implicit conversion any2stringadd from IMain to StringAdd

Inherited by implicit conversion any2stringfmt from IMain to StringFormat

Inherited by implicit conversion any2ArrowAssoc from IMain to ArrowAssoc[IMain]

Inherited by implicit conversion any2Ensuring from IMain to Ensuring[IMain]

Ungrouped