summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config/list/interpreter.lst1
-rw-r--r--sources/scala/tools/scalai/InterpreterPrinter.java77
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);
+ }
+ }
+
+ //########################################################################
+}