summaryrefslogtreecommitdiff
path: root/sources
diff options
context:
space:
mode:
authorpaltherr <paltherr@epfl.ch>2003-05-13 11:52:20 +0000
committerpaltherr <paltherr@epfl.ch>2003-05-13 11:52:20 +0000
commit92e745e5374a4a2a21dfb3907c9c02feded457f6 (patch)
treebf277bfa550260ee0684df0a1f2b42ef5bbdbbb6 /sources
parentceda0125a9450e4d36f1eff9cc499cb8491c3a0d (diff)
downloadscala-92e745e5374a4a2a21dfb3907c9c02feded457f6.tar.gz
scala-92e745e5374a4a2a21dfb3907c9c02feded457f6.tar.bz2
scala-92e745e5374a4a2a21dfb3907c9c02feded457f6.zip
- Fixed to use scala.runtime.InterpreterSupport
Diffstat (limited to 'sources')
-rw-r--r--sources/scala/tools/scalai/Interpreter.java54
1 files changed, 39 insertions, 15 deletions
diff --git a/sources/scala/tools/scalai/Interpreter.java b/sources/scala/tools/scalai/Interpreter.java
index b9ed4358e2..df92fa362a 100644
--- a/sources/scala/tools/scalai/Interpreter.java
+++ b/sources/scala/tools/scalai/Interpreter.java
@@ -18,6 +18,10 @@ import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
+import scala.runtime.InterpreterSupport;
+import scala.runtime.InterpreterSupport.DefinitionPrinter;
+import scala.runtime.InterpreterSupport.EvaluationResult;
+
import scalac.Global;
import scalac.ast.parser.Sourcefile;
import scalac.util.PrefixMatcher;
@@ -113,9 +117,10 @@ public class Interpreter {
if (interactive) showBanner();
if (program.length > 0) load(lfiles = program);
if (global.reporter.errors() == 0 && main != null) call(main, args);
+ // !!! can we remove that ?
// Compute something to force loading of Predef & Interpreter
- if (interactive && program.length == 0 && main == null)
- load("module $init$ { Interpreter.initialize }");
+ //if (interactive && program.length == 0 && main == null)
+ //load("module $init$ {}");
if (interactive) while (handle(read()));
global.stop("total");
if (!interactive) global.reporter.printSummary();
@@ -254,27 +259,32 @@ public class Interpreter {
}
public boolean interpret(boolean interactive) {
- if (global.reporter.errors() == 0) {
- CodeContainer code = compiler.compile(global.units, interactive);
- EvaluatorResult result;
- try {
- result = EvaluatorResult.Value(evaluator.evaluate(code));
- } catch (EvaluatorException exception) {
- result = EvaluatorResult.Error(exception);
- }
- show(result, interactive);
- }
+ if (global.reporter.errors() == 0)
+ show(interpret(new DefaultDefinitionPrinter()), interactive);
Sourcefile.flushSources();
return true;
}
+ public EvaluatorResult interpret(DefinitionPrinter printer) {
+ try {
+ CodeContainer code = compiler.compile(global.units, interactive);
+ InterpreterSupport.setDefinitionPrinter(printer);
+ evaluator.evaluate(code);
+ EvaluationResult result =
+ InterpreterSupport.getAndResetEvaluationResult();
+ if (result == null) return EvaluatorResult.Void;
+ return EvaluatorResult.Value(result.value, result.type);
+ } catch (EvaluatorException exception) {
+ return EvaluatorResult.Error(exception);
+ }
+ }
+
public void show(EvaluatorResult result, boolean interactive) {
- // !!! remove case Value from EvaluatorResult
switch (result) {
case Void:
return;
- case Value(Object value):
- // !!! if (interactive && value != null) writer.println(value);
+ case Value(Object value, String type):
+ if (interactive) writer.println(value + ": " + type);
return;
case Error(EvaluatorException exception):
writer.println(exception.mkString(global));
@@ -450,4 +460,18 @@ public class Interpreter {
}
//########################################################################
+ // Private Classes
+
+ private class DefaultDefinitionPrinter implements DefinitionPrinter {
+
+ public void showDefinition(String signature) {
+ writer.println(signature);
+ }
+
+ public void showValueDefinition(String signature, Object value) {
+ writer.println(signature + " = " + value);
+ }
+ }
+
+ //########################################################################
}