diff options
author | paltherr <paltherr@epfl.ch> | 2003-06-11 13:48:15 +0000 |
---|---|---|
committer | paltherr <paltherr@epfl.ch> | 2003-06-11 13:48:15 +0000 |
commit | 39f22e7351900793142c44882db8ffecb8bd6038 (patch) | |
tree | 743a34c12770819ddfe56dc82579738da88948ce | |
parent | 2fc1837fcc41be01f0f5e7507e23a8ab83a9ab1c (diff) | |
download | scala-39f22e7351900793142c44882db8ffecb8bd6038.tar.gz scala-39f22e7351900793142c44882db8ffecb8bd6038.tar.bz2 scala-39f22e7351900793142c44882db8ffecb8bd6038.zip |
- Added InterpreterPrinter.java
-rw-r--r-- | config/list/interpreter.lst | 1 | ||||
-rw-r--r-- | sources/scala/tools/scalai/InterpreterPrinter.java | 77 |
2 files changed, 78 insertions, 0 deletions
diff --git a/config/list/interpreter.lst b/config/list/interpreter.lst index 4373944faa..d9cd925b3f 100644 --- a/config/list/interpreter.lst +++ b/config/list/interpreter.lst @@ -19,6 +19,7 @@ ExpressionContext.java Function.java Interpreter.java InterpreterCommand.java +InterpreterPrinter.java InterpreterShell.java JavaMirror.java Main.java diff --git a/sources/scala/tools/scalai/InterpreterPrinter.java b/sources/scala/tools/scalai/InterpreterPrinter.java new file mode 100644 index 0000000000..a8591d8db6 --- /dev/null +++ b/sources/scala/tools/scalai/InterpreterPrinter.java @@ -0,0 +1,77 @@ +/* ____ ____ ____ ____ ______ *\ +** / __// __ \/ __// __ \/ ____/ SOcos COmpiles Scala ** +** __\_ \/ /_/ / /__/ /_/ /\_ \ (c) 2002, LAMP/EPFL ** +** /_____/\____/\___/\____/____/ ** +\* */ + +// $Id$ + +package scalai; + +import java.io.PrintWriter; + +import scala.runtime.InterpreterSupport.DefinitionPrinter; + +import scalac.util.Debug; + +public class InterpreterPrinter implements DefinitionPrinter { + + //######################################################################## + // Private State + + private final Interpreter interpreter; + private final PrintWriter writer; + + //######################################################################## + // Public Constructors + + public InterpreterPrinter(Interpreter interpreter, PrintWriter writer) { + this.interpreter = interpreter; + this.writer = writer; + } + + //######################################################################## + // Public Methods + + public void showDefinition(String signature) { + writer.println(signature); + } + + public void showValueDefinition(String signature, Object value) { + EvaluatorResult result = interpreter.toString(value, null); + switch (result) { + case Value(Object string, _): + writer.println(signature + " = " + string); + return; + case Error(EvaluatorException exception): + writer.print(signature + " = "); + writer.println(exception.getScalaErrorMessage(true)); + return; + default: + throw Debug.abort("illegal case", result); + } + } + + public void showResult(EvaluatorResult result, boolean interactive) { + switch (result) { + case Void: + return; + case Value(Object value, String type): + if (interactive) + if (value instanceof String) + writer.println(value + ": " + type); + else + showResult(interpreter.toString(value, type), interactive); + return; + case Error(EvaluatorException exception): + String name = Thread.currentThread().getName(); + writer.print("Exception in thread \"" + name + "\" "); + writer.println(exception.getScalaErrorMessage(true)); + return; + default: + throw Debug.abort("illegal case", result); + } + } + + //######################################################################## +} |