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
Imports, AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. IMain
  2. Imports
  3. AnyRef
  4. Any
Implicitly
  1. by any2stringfmt
  2. by any2stringadd
  3. by any2ArrowAssoc
  4. 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. class ReadEvalPrint extends AnyRef

    Here is where we:

  3. implicit class ReplTypeOps extends AnyRef

  4. 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 addImports(ids: String*): Result

  9. def aliasForType(path: String): Option[String]

    Parse the ScalaSig to find type aliases

  10. def allDefHandlers: List[MemberDefHandler]

  11. def allDefSymbols: List[Symbol]

  12. def allDefinedNames: List[Name]

  13. def allHandlers: List[MemberHandler]

  14. def allImplicits: List[Name { ... /* 5 definitions in type refinement */ }]

  15. def allImportedNames: List[Name]

    Definition Classes
    Imports
  16. def allSeenTypes: List[String]

  17. def apply[T](implicit arg0: ClassTag[T]): Symbol

  18. def apply(name: String): Symbol

    Translate a repl-defined identifier into a Symbol.

  19. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  20. def beQuietDuring[T](body: ⇒ T): T

    Temporarily be quiet

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

  22. def bind[T](name: String, value: T)(implicit arg0: TypeTag[T]): Result

  23. def bind(p: NamedParam): Result

  24. 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

  25. def bindSyntheticValue(x: Any): Result

  26. def bindValue(name: String, x: Any): Result

  27. def bindValue(x: Any): Result

  28. def classLoader: AbstractFileClassLoader

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

  30. def classSymbols: List[ClassSymbol]

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

  32. def clearExecutionWrapper(): Unit

  33. def clone(): AnyRef

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  34. 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.

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

    Compile an nsc SourceFile.

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

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

  37. def compileString(code: String): Boolean

    Compile a string.

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

  38. lazy val compiler: IMain.this.global.type

  39. def compilerClasspath: Seq[URL]

  40. def createLineManager(classLoader: ClassLoader): Manager

    Attributes
    protected
  41. def debugging[T](msg: String)(res: T): T

  42. object deconstruct extends StructuredTypeStrings

  43. def definedSymbolList: List[Symbol]

  44. def definedSymbols: Set[Symbol]

  45. def definedTerms: List[TermName]

  46. def definedTypes: List[TypeName]

  47. def definitionForName(name: Name): Option[MemberHandler]

  48. def directBind[T](name: String, value: T)(implicit arg0: ClassTag[T]): Result

  49. def directBind(p: NamedParam): Result

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

  51. final def ensureClassLoader(): Unit

  52. 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
  53. 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
  54. 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
  55. 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
  56. final def eq(arg0: AnyRef): Boolean

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

    Definition Classes
    AnyRef → Any
  58. def executionWrapper: String

  59. object exprTyper extends ExprTyper

  60. def finalize(): Unit

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  61. def flatName(id: String): String

  62. 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()
  63. lazy val formatting: Formatting

  64. def generatedName(simpleName: String): Option[String]

    Given a simple repl-defined name, returns the real name of the class representing it, e.

    Given a simple repl-defined name, returns the real name of the class representing it, e.g. for "Bippy" it may return

    $line19.$read$$iw$$iw$$iw$$iw$$iw$$iw$$iw$$iw$Bippy
  65. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  66. def getInterpreterClassLoader(): AbstractFileClassLoader

  67. lazy val global: Global

    the public, go through the future compiler

  68. def handleTermRedefinition(name: TermName, old: Request, req: Request): Unit

  69. def handleTypeRedefinition(name: TypeName, old: Request, req: Request): Unit

    Stubs for work in progress.

  70. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  71. def implicitSymbols: List[Symbol]

    Definition Classes
    Imports
  72. def implicitSymbolsBySource: List[(Symbol, List[Symbol])]

    Definition Classes
    Imports
  73. def importHandlers: List[ImportHandler]

  74. def importedSymbols: List[Symbol]

    Definition Classes
    Imports
  75. def importedSymbolsBySource: List[(Symbol, List[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
  76. def importedTermNamed(name: String): Symbol

    Definition Classes
    Imports
  77. def importedTermSymbols: List[TermSymbol]

    Definition Classes
    Imports
  78. def importedTerms: List[TermName]

    Definition Classes
    Imports
  79. def importedTypeSymbols: List[TypeSymbol]

    Definition Classes
    Imports
  80. def importedTypes: List[TypeName]

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

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

  83. def initializeSynchronous(): Unit

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

  85. 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.

  86. def interpretSynthetic(line: String): Result

  87. def isInitializeComplete: Boolean

  88. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  89. def isNoImports: Boolean

    Definition Classes
    Imports
  90. def isNoPredef: Boolean

    Definition Classes
    Imports
  91. def isParseable(line: String): Boolean

  92. lazy val isettings: ISettings

    interpreter settings

  93. def languageSymbols: List[Symbol]

    Definition Classes
    Imports
  94. def languageWildcardHandlers: List[ImportHandler]

    Definition Classes
    Imports
  95. def languageWildcardSyms: List[Symbol]

    Symbols whose contents are language-defined to be imported.

    Symbols whose contents are language-defined to be imported.

    Definition Classes
    Imports
  96. def languageWildcards: List[Type]

    Definition Classes
    Imports
  97. def lastRequest: Request

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

  99. def lineManager: Manager

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

  101. def methodSymbols: List[MethodSymbol]

  102. def mostRecentLine: String

  103. 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.

  104. def namedDefinedTerms: List[TermName]

  105. object naming extends Naming

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

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

    Instantiate a compiler.

    Instantiate a compiler. Overridable.

    Attributes
    protected
  108. def noLineManager: Boolean

    Create a line manager.

    Create a line manager. Overridable.

    Attributes
    protected
  109. def normalizeNonPublic(tp: Type): Type

  110. final def notify(): Unit

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

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

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

    Attributes
    protected
  114. def optFlatName(id: String): Option[String]

  115. val out: JPrintWriter

    Attributes
    protected
  116. def parentClassLoader: ClassLoader

    Parent classloader.

    Parent classloader. Overridable.

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

  118. def pathToName(name: Name): String

  119. def pathToTerm(id: String): String

  120. def pathToType(id: String): String

  121. def prettyPrint(code: String): Unit

  122. def prevRequestList: List[Request]

  123. def quietBind(p: NamedParam): Result

  124. def quietImport(ids: String*): Result

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

  126. def rebind(p: NamedParam): Result

  127. def recordRequest(req: Request): Unit

  128. object replTokens extends ReplTokens

  129. lazy val repllog: Logger

  130. lazy val reporter: ReplReporter

  131. def requestForIdent(line: String): Option[Request]

  132. def requestForName(name: Name): Option[Request]

  133. def requestForReqId(id: Int): Option[Request]

  134. def requestHistoryForName(name: Name): List[Request]

  135. def rerunForWarnings: Result

  136. def rerunWith(names: String*): Result

  137. def reset(): Unit

    Reset this interpreter, forgetting all user-specified requests.

  138. def resetClassLoader(): Unit

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

  140. def runtimeTypeOfTerm(id: String): Type

  141. def savingSettings[T](fn: (Settings) ⇒ Unit)(body: ⇒ T): T

  142. val self: Any

    Implicit information
    This member is added by an implicit conversion from IMain to StringFormat performed by method any2stringfmt in scala.Predef.
    Definition Classes
    StringFormat
  143. val self: Any

    Implicit information
    This member is added by an implicit conversion from IMain to StringAdd performed by method any2stringadd in scala.Predef.
    Definition Classes
    StringAdd
  144. def sessionImportedSymbols: List[Symbol]

    Definition Classes
    Imports
  145. def sessionWildcards: List[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
  146. def setContextClassLoader(): Unit

  147. def setExecutionWrapper(code: String): Unit

  148. def settings: Settings

  149. def showCodeIfDebugging(code: String): Unit

  150. def symbolDefString(sym: Symbol): String

  151. def symbolOfLine(code: String): Symbol

  152. def symbolOfTerm(id: String): Symbol

  153. def symbolOfType(id: String): Symbol

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

    Definition Classes
    AnyRef
  155. def terms[T](implicit arg0: ClassTag[T]): Symbol

  156. def terms(name: String): Symbol

  157. def toString(): String

    Definition Classes
    AnyRef → Any
  158. def treesForRequestId(id: Int): List[Tree]

  159. def typeOfExpression(expr: String, silent: Boolean = true): Type

  160. def typeOfTerm(id: String): Type

  161. def types[T](implicit arg0: ClassTag[T]): Symbol

  162. def types(name: String): Symbol

  163. def unqualifiedIds: List[String]

    Another entry point for tab-completion, ids in scope

  164. def valueOfTerm(id: String): Option[AnyRef]

  165. val virtualDirectory: VirtualDirectory

    Leading with the eagerly evaluated.

  166. def visibleTermNames: List[Name]

  167. final def wait(): Unit

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

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

    Definition Classes
    AnyRef
    Annotations
    @throws()
  170. def wildcardTypes: List[Type]

    Definition Classes
    Imports
  171. def withoutUnwrapping(op: ⇒ Unit): Unit

  172. 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

Deprecated Value Members

  1. 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.
    Definition Classes
    ArrowAssoc
    Annotations
    @deprecated
    Deprecated

    (Since version 2.10.0) Use leftOfArrow instead

  2. 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.
    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 any2stringfmt from IMain to StringFormat

Inherited by implicit conversion any2stringadd from IMain to StringAdd

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

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