summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpaltherr <paltherr@epfl.ch>2004-04-04 13:02:15 +0000
committerpaltherr <paltherr@epfl.ch>2004-04-04 13:02:15 +0000
commitc83874f3a2b02915c2e6bfa14a63714e956da423 (patch)
tree40868c49670af44451a0b8b022537f42c2deb906
parent7a5770aa1e4b149d2cc345232cad92826185b4cb (diff)
downloadscala-c83874f3a2b02915c2e6bfa14a63714e956da423.tar.gz
scala-c83874f3a2b02915c2e6bfa14a63714e956da423.tar.bz2
scala-c83874f3a2b02915c2e6bfa14a63714e956da423.zip
- Simplified and removed usage of Symbol.ERROR
-rw-r--r--sources/scala/tools/scalai/Interpreter.java62
1 files changed, 22 insertions, 40 deletions
diff --git a/sources/scala/tools/scalai/Interpreter.java b/sources/scala/tools/scalai/Interpreter.java
index 9c01dca041..8ba76db97f 100644
--- a/sources/scala/tools/scalai/Interpreter.java
+++ b/sources/scala/tools/scalai/Interpreter.java
@@ -55,9 +55,9 @@ public class Interpreter {
public EvaluatorResult invoke(String main, String[]args) {
Symbol module = getMainModule(main);
- if (module == Symbol.NONE) return EvaluatorResult.Void;
+ if (module == null) return EvaluatorResult.Void;
Symbol method = getMainMethod(main, module);
- if (method == Symbol.NONE) return EvaluatorResult.Void;
+ if (method == null) return EvaluatorResult.Void;
Variable variable = compiler.getModule(module);
Function function = compiler.getMethod(method);
try {
@@ -115,35 +115,28 @@ public class Interpreter {
String names = main.replace('/', '.') + (main.length() > 0 ? "." : "");
if (names.length() > 0 && names.charAt(0) == '.') {
error("illegal module name '" + main + "'");
- return Symbol.NONE;
+ return null;
}
Symbol module = global.definitions.ROOT_CLASS;
for (int i = 0, j; (j = names.indexOf('.', i)) >= 0; i = j + 1) {
Name name = Name.fromString(names.substring(i, j));
- module = getModule(module, name);
- if (module == Symbol.NONE) {
+ Symbol symbol = module.lookup(name);
+ if (symbol.isNone()) {
error("could not find module '" + main.substring(0, j) + "'");
- return Symbol.NONE;
+ return null;
}
- if (module == Symbol.ERROR) {
- error("term '" + main.substring(0, j) + "' is not a module");
- return Symbol.NONE;
+ if (symbol.isModule()) { module = symbol; continue; }
+ switch (symbol.type()) {
+ case OverloadedType(Symbol[] alts, _):
+ for (int k = 0; k < alts.length; k++)
+ if (alts[k].isModule()) { module = alts[k]; continue; }
}
+ error("term '" + main.substring(0, j) + "' is not a module");
+ return null;
}
return module;
}
- private Symbol getModule(Symbol owner, Name name) {
- Symbol symbol = owner.lookup(name);
- if (symbol == Symbol.NONE || symbol.isModule()) return symbol;
- switch (symbol.type()) {
- case OverloadedType(Symbol[] alts, _):
- for (int k = 0; k < alts.length; k++)
- if (alts[k].isModule()) return alts[k];
- }
- return Symbol.ERROR;
- }
-
//########################################################################
// Private Methods - Finding main method
@@ -161,32 +154,21 @@ public class Interpreter {
}
private Symbol getMainMethod(String main, Symbol module) {
- Symbol method = getMethod(module, MAIN_N, getMainMethodType(true));
- if (method == Symbol.NONE) {
+ Symbol symbol = module.moduleClass().lookup(MAIN_N);
+ if (symbol.isNone()) {
error("module '" + main + "' has no method '" + MAIN_N + "'");
- return Symbol.NONE;
+ return null;
}
- if (method == Symbol.ERROR) {
- error("module '" + main + "' has no method '" + MAIN_N +
- "' with type '" + getMainMethodType(false) + "'");
- return Symbol.NONE;
- }
- return method;
- }
-
- private Symbol getMethod(Symbol module, Name name, Type type) {
- Symbol symbol = module.moduleClass().lookup(name);
- if (symbol == Symbol.NONE || isMethod(symbol, type)) return symbol;
+ Type type = getMainMethodType(true);
+ if (symbol.type().equals(type)) return symbol;
switch (symbol.type()) {
case OverloadedType(Symbol[] alts, _):
for (int k = 0; k < alts.length; k++)
- if (isMethod(alts[k], type)) return alts[k];
+ if (alts[k].type().equals(type)) return alts[k];
}
- return Symbol.ERROR;
- }
-
- private boolean isMethod(Symbol symbol, Type type) {
- return symbol.isMethod() && symbol.type().equals(type);
+ error("module '" + main + "' has no method '" + MAIN_N +
+ "' with type '" + getMainMethodType(false) + "'");
+ return null;
}
//########################################################################