dotty.tools.dotc.repl

CompilingInterpreter

Related Docs: object CompilingInterpreter | package repl

class CompilingInterpreter extends Compiler with Interpreter

An interpreter for Scala code which is based on the dotc compiler.

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 definition(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 a single definition named "result". To accommodate 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.

Linear Supertypes
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. CompilingInterpreter
  2. Interpreter
  3. Compiler
  4. AnyRef
  5. Any
  1. Hide All
  2. Show all
Learn more about member selection
Visibility
  1. Public
  2. All

Instance Constructors

  1. new CompilingInterpreter(out: PrintWriter, ictx: Context, parentClassLoader: Option[ClassLoader])

    out

    The output to use for diagnostics

    ictx

    The context to use for initialization of the interpreter, needed to access the current classpath.

Value Members

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

    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

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

    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  5. def beQuietDuring[T](operation: ⇒ T): T

    Temporarily be quiet

    Temporarily be quiet

    Definition Classes
    CompilingInterpreterInterpreter
  6. def bind(id: String, boundType: String, value: AnyRef)(implicit ctx: Context): Result

    This bind is implemented by creating an object with a set method and a field value.

    This bind is implemented by creating an object with a set method and a field value. The value is then set via Java reflection.

    Example: We want to bind a value List(1,2,3) to identifier list from sbt. The bind method accomplishes this by creating the following:

    object ContainerObjectWithUniqueID {
      var value: List[Int] = _
      def set(x: Any) = value = x.asInstanceOf[List[Int]]
    }
    val list = ContainerObjectWithUniqueID.value

    Between the object being created and the value being assigned, the value inside the object is set via reflection.

    Definition Classes
    CompilingInterpreterInterpreter
  7. val classLoader: ClassLoader

    class loader used to load compiled code

  8. def clone(): AnyRef

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  9. def compileSources(sources: List[SourceFile])(implicit ctx: Context): Context

    Compile a SourceFile.

    Compile a SourceFile. Returns the root context of the run that compiled the file.

  10. def compileString(code: String)(implicit ctx: Context): Boolean

    Compile a string.

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

  11. val compilerClasspath: List[URL]

    the compiler's classpath, as URL's

  12. def delayOutputDuring[T](operation: ⇒ T): T

    Suppresses output and saves it for lastOutput to collect

    Suppresses output and saves it for lastOutput to collect

    Definition Classes
    CompilingInterpreterInterpreter
  13. final def eq(arg0: AnyRef): Boolean

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

    Definition Classes
    AnyRef → Any
  15. def finalize(): Unit

    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  16. final def getClass(): Class[_]

    Definition Classes
    AnyRef → Any
  17. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  18. def interpret(line: String)(implicit ctx: Context): Result

    Interpret one line of input.

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

    Definition Classes
    CompilingInterpreterInterpreter
  19. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  20. def lastOutput(): List[String]

    Gets the last output not printed immediately

    Gets the last output not printed immediately

    Definition Classes
    CompilingInterpreterInterpreter
  21. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  22. def newRun(implicit ctx: Context): Run

    Definition Classes
    Compiler
  23. def nextRunId: Int

    Definition Classes
    Compiler
  24. final def notify(): Unit

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

    Definition Classes
    AnyRef
  26. def phases: List[List[Phase]]

    Phases of this compiler use REPLGenBCode instead of GenBCode.

    Phases of this compiler use REPLGenBCode instead of GenBCode.

    Definition Classes
    CompilingInterpreterCompiler
  27. val previousOutput: ListBuffer[String]

  28. def reset()(implicit ctx: Context): Unit

    Definition Classes
    Compiler
  29. def rootContext(implicit ctx: Context): Context

    Produces the following contexts, from outermost to innermost

    Produces the following contexts, from outermost to innermost

    bootStrap: A context with next available runId and a scope consisting of the RootPackage _root_ start A context with RootClass as owner and the necessary initializations for type checking. imports For each element of RootImports, an import context

    Definition Classes
    Compiler
  30. var runId: Int

    Definition Classes
    Compiler
  31. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  32. def toString(): String

    Definition Classes
    AnyRef → Any
  33. val virtualDirectory: AbstractFile { ... /* 3 definitions in type refinement */ }

    directory to save .class files to

  34. final def wait(): Unit

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

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

    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from Interpreter

Inherited from Compiler

Inherited from AnyRef

Inherited from Any

Ungrouped