summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpaltherr <paltherr@epfl.ch>2003-12-03 11:58:05 +0000
committerpaltherr <paltherr@epfl.ch>2003-12-03 11:58:05 +0000
commit38d21f571cbea88c65fa3821605c06875d7b5f7a (patch)
treef08f53263cef271bf596308ae07171a5b7918c0c
parentc8437e055e2c499f558ed881e1c3cd2da33f0abd (diff)
downloadscala-38d21f571cbea88c65fa3821605c06875d7b5f7a.tar.gz
scala-38d21f571cbea88c65fa3821605c06875d7b5f7a.tar.bz2
scala-38d21f571cbea88c65fa3821605c06875d7b5f7a.zip
- Added compilation and evaluation of Switch nodes
-rw-r--r--sources/scala/tools/scalai/Evaluator.java8
-rw-r--r--sources/scala/tools/scalai/ExpressionCompiler.java4
2 files changed, 12 insertions, 0 deletions
diff --git a/sources/scala/tools/scalai/Evaluator.java b/sources/scala/tools/scalai/Evaluator.java
index 9255a02731..e940b7f194 100644
--- a/sources/scala/tools/scalai/Evaluator.java
+++ b/sources/scala/tools/scalai/Evaluator.java
@@ -158,6 +158,14 @@ public class Evaluator {
assert value instanceof Boolean : value.getClass();
return evaluate(((Boolean)value).booleanValue() ? thenp : elsep);
+ case Switch(Code test, int[] tags, Code[] bodies, Code otherwise):
+ Object value = evaluate(test);
+ assert value instanceof Integer : value.getClass();
+ int tag = ((Integer)value).intValue();
+ for (int i = 0; i < tags.length; i++)
+ if (tags[i] == tag) return evaluate(bodies[i]);
+ return evaluate(otherwise);
+
case Literal(Object value):
return value;
diff --git a/sources/scala/tools/scalai/ExpressionCompiler.java b/sources/scala/tools/scalai/ExpressionCompiler.java
index e8a3a88a7c..0edc0a525e 100644
--- a/sources/scala/tools/scalai/ExpressionCompiler.java
+++ b/sources/scala/tools/scalai/ExpressionCompiler.java
@@ -130,6 +130,10 @@ public class ExpressionCompiler {
// !!! can we remove this test ?
elsep == Tree.Empty ? Code.Literal(constants.literal()) : compute(elsep));
+ case Switch(Tree test, int[] tags, Tree[] bodies, Tree otherwise):
+ return Code.Switch(
+ compute(test), tags, compute(bodies), compute(otherwise));
+
case New(Tree.Template(Tree[] bases, Tree[] body)): // !!!
assert bases.length == 1 : Debug.show(tree);
assert body.length == 0 : Debug.show(tree);