summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config/list/runtime.lst3
-rw-r--r--sources/scala/runtime/InterpreterSupport.java106
2 files changed, 108 insertions, 1 deletions
diff --git a/config/list/runtime.lst b/config/list/runtime.lst
index c5cb73c222..f9aa23a103 100644
--- a/config/list/runtime.lst
+++ b/config/list/runtime.lst
@@ -29,7 +29,8 @@ Ref.java
Short.java
Unit.java
-runtime/RunTime.java
+runtime/InterpreterSupport.java
runtime/ResultOrException.java
+runtime/RunTime.java
##############################################################################
diff --git a/sources/scala/runtime/InterpreterSupport.java b/sources/scala/runtime/InterpreterSupport.java
new file mode 100644
index 0000000000..9388ec3814
--- /dev/null
+++ b/sources/scala/runtime/InterpreterSupport.java
@@ -0,0 +1,106 @@
+/* __ *\
+** ________ ___ / / ___ Scala API **
+** / __/ __// _ | / / / _ | (c) 2002, LAMP/EPFL **
+** __\ \/ /__/ __ |/ /__/ __ | **
+** /____/\___/_/ |_/____/_/ | | **
+** |/ **
+\* */
+
+// $Id$
+
+package scala.runtime;
+
+/** This class provides support methods for the interpreter. */
+public class InterpreterSupport {
+
+ //########################################################################
+ // Public classes
+
+ /** This interface provides method to show definitions. */
+ public static interface DefinitionPrinter {
+
+ /** This method is invoked for each non-value definition. */
+ public void showDefinition(String signature);
+
+ /** This method is invoked for each value definition. */
+ public void showValueDefinition(String signature, Object value);
+
+ }
+
+ /** This class describes an evaluation result. */
+ public static class EvaluationResult {
+
+ /** The value of the result */
+ public final Object value;
+
+ /** The type of the result */
+ public final String type;
+
+ /** Creates a new instance */
+ public EvaluationResult(Object value, String type) {
+ this.value = value;
+ this.type = type;
+ }
+ }
+
+ //########################################################################
+ // Private Variables
+
+ private static final ThreadLocal printer = new ThreadLocal();
+ private static final ThreadLocal result = new ThreadLocal();
+
+ //########################################################################
+ // Public Functions
+
+ /** Sets the definition printer of the current thread. */
+ public static void setDefinitionPrinter(DefinitionPrinter object) {
+ printer.set(object);
+ }
+
+ /** Returns the definition printer of the current thread. */
+ public static DefinitionPrinter getDefinitionPrinter() {
+ return (DefinitionPrinter)printer.get();
+ }
+
+ /**
+ * This function is invoked for each non-value definition. It
+ * forwards the call to the current thread's definition printer.
+ *
+ * @meta method (java.lang.String, scala.Any) scala.Unit;
+ */
+ public static void showDefinition(String signature) {
+ getDefinitionPrinter().showDefinition(signature);
+ }
+
+ /**
+ * This method is invoked for each value definition. It forwards
+ * the call to the current thread's definition printer.
+ *
+ * @meta method (java.lang.String, scala.Any) scala.Unit;
+ */
+ public static void showValueDefinition(String signature, Object value) {
+ getDefinitionPrinter().showValueDefinition(signature, value);
+ }
+
+ /**
+ * Sets the evaluation result of the current thread.
+ *
+ * @meta method (scala.Any, java.lang.String) scala.Unit;
+ */
+ public static void setEvaluationResult(Object value, String type) {
+ result.set(new EvaluationResult(value, type));
+ }
+
+ /**
+ * Returns and resets the evaluation result of the current
+ * thread. A null value indicates that the last evaluation had no
+ * result (only definitions).
+ */
+ public static EvaluationResult getAndResetEvaluationResult() {
+ Object object = result.get();
+ result.set(null);
+ return (EvaluationResult)object;
+ }
+
+ //########################################################################
+}