summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2003-03-04 12:10:52 +0000
committerMartin Odersky <odersky@gmail.com>2003-03-04 12:10:52 +0000
commit91c9a415e380539da3c6acabda2cf70afbf2cc47 (patch)
treeaff5d4ff5c546d3f5228cd1bd6b1151211a7ae07
parentfc497536ed884b4d18860f6db644d4143412c2f5 (diff)
downloadscala-91c9a415e380539da3c6acabda2cf70afbf2cc47.tar.gz
scala-91c9a415e380539da3c6acabda2cf70afbf2cc47.tar.bz2
scala-91c9a415e380539da3c6acabda2cf70afbf2cc47.zip
*** empty log message ***
-rw-r--r--config/list/library.lst1
-rw-r--r--config/list/runtime.lst1
-rw-r--r--sources/scala/Predef.scala14
-rw-r--r--sources/scala/runtime/RunTime.java13
-rw-r--r--sources/scalac/ast/TreeGen.java10
-rw-r--r--sources/scalac/symtab/Symbol.java2
-rw-r--r--sources/scalac/symtab/Type.java6
-rw-r--r--sources/scalac/symtab/classfile/AttributeParser.java8
-rw-r--r--sources/scalac/transformer/LambdaLiftPhase.java15
-rw-r--r--sources/scalac/typechecker/Analyzer.java4
-rw-r--r--sources/scalac/typechecker/DeSugarize.java36
-rw-r--r--test/files/pos/exceptions.scala19
-rw-r--r--test/pos/exceptions.scala19
13 files changed, 118 insertions, 30 deletions
diff --git a/config/list/library.lst b/config/list/library.lst
index 90662438a8..760ed5473e 100644
--- a/config/list/library.lst
+++ b/config/list/library.lst
@@ -29,5 +29,6 @@ Tuple6.scala
Tuple7.scala
Tuple8.scala
Tuple9.scala
+PartialFunction.scala
##############################################################################
diff --git a/config/list/runtime.lst b/config/list/runtime.lst
index c67792269a..2fdea8b322 100644
--- a/config/list/runtime.lst
+++ b/config/list/runtime.lst
@@ -30,5 +30,6 @@ Short.java
Unit.java
runtime/RunTime.java
+runtime/ResultOrException.java
##############################################################################
diff --git a/sources/scala/Predef.scala b/sources/scala/Predef.scala
index bde0ab3b05..cdd2eee20f 100644
--- a/sources/scala/Predef.scala
+++ b/sources/scala/Predef.scala
@@ -14,7 +14,10 @@ package scala {
mkList(x.elements);
}
- def error[err](x: String):err = (new java.lang.RuntimeException(x)).throw;
+ def error[err](x: String):err = new java.lang.RuntimeException(x).throw;
+
+ def try[a](def block: a): Except[a] =
+ new Except(scala.runtime.ResultOrException.tryBlock(block));
def range(lo: Int, hi: Int): List[Int] =
if (lo > hi) List() else lo :: range(lo + 1, hi);
@@ -44,6 +47,15 @@ package scala {
type Triple = Tuple3;
def Triple[a, b, c](x: a, y: b, z: c) = Tuple3(x, y, z);
}
+
+ class Except[a](r: scala.runtime.ResultOrException[a]) {
+ def except(handler: PartialFunction[Throwable, a]): a =
+ if (r.exc == null) r.result
+ else if (handler isDefinedAt r.exc) handler(r.exc)
+ else r.exc.throw;
+ def finally(def handler: Unit): a =
+ if (r.exc == null) r.result else { handler; r.exc.throw }
+ }
}
diff --git a/sources/scala/runtime/RunTime.java b/sources/scala/runtime/RunTime.java
index 383d2d00a4..c7f9ad88a4 100644
--- a/sources/scala/runtime/RunTime.java
+++ b/sources/scala/runtime/RunTime.java
@@ -23,11 +23,15 @@ import scala.Double;
import scala.Array;
import java.lang.Object;
-/**
+/** @meta class extends java.lang.Object;
* Run-time support functions for Scala.
*/
-
public abstract class RunTime {
+
+ /** @meta method () scala.Unit;
+ */
+ public void test() {}
+
public static final Unit UNIT_VAL = new Unit() {};
private static ClassLoader loader = ClassLoader.getSystemClassLoader();
@@ -548,5 +552,8 @@ public abstract class RunTime {
public static void oarray_set(Object[] array, int index, Object value) {
array[index] = value;
}
-
}
+
+
+
+
diff --git a/sources/scalac/ast/TreeGen.java b/sources/scalac/ast/TreeGen.java
index 4154710822..29bb0d6d8a 100644
--- a/sources/scalac/ast/TreeGen.java
+++ b/sources/scalac/ast/TreeGen.java
@@ -70,6 +70,10 @@ public class TreeGen implements Kinds, Modifiers {
return Select(pos, mkStableId(pos, pre), sym);
}
+ public Tree mkRef(int pos, Symbol sym) {
+ return mkRef(pos, sym.owner().thisType(), sym);
+ }
+
/** Build and attribute stable identifier tree corresponding to given prefix.
*/
public Tree mkStableId(int pos, Type pre) {
@@ -131,6 +135,12 @@ public class TreeGen implements Kinds, Modifiers {
return res;
}
+ /** Build a boolean constant tree.
+ */
+ public Tree mkBoolean(int pos, boolean bool) {
+ return mkRef(pos, bool ? definitions.TRUE() : definitions.FALSE());
+ }
+
/** Build a tree to be used as a base class constructor for a template.
*/
public Tree mkParentConstr(int pos, Type parentType) {
diff --git a/sources/scalac/symtab/Symbol.java b/sources/scalac/symtab/Symbol.java
index 2b8145f8fa..e77de471a9 100644
--- a/sources/scalac/symtab/Symbol.java
+++ b/sources/scalac/symtab/Symbol.java
@@ -965,7 +965,7 @@ public class TypeSymbol extends Symbol {
/** Return a fresh symbol with the same fields as this one.
*/
public Symbol cloneSymbol() {
- if (Global.instance.debug) System.out.println("cloning " + this + this.locationString());
+ if (Global.instance.debug) System.out.println("cloning " + this + this.locationString() + " in phase " + Global.instance.currentPhase.name());
TypeSymbol other = new TypeSymbol(kind, pos, name, owner(), flags);
other.setInfo(info());
return other;
diff --git a/sources/scalac/symtab/Type.java b/sources/scalac/symtab/Type.java
index 3a95a2805d..e7a701ce6d 100644
--- a/sources/scalac/symtab/Type.java
+++ b/sources/scalac/symtab/Type.java
@@ -838,7 +838,7 @@ public class Type implements Modifiers, Kinds, TypeTags {
return ErrorType;
}
throw new ApplicationError(
- this + " in " + ownclass + " cannot be instantiated from " + pre);
+ this + " in " + ownclass + " cannot be instantiated from " + pre.widen());
} else {
return toInstance(
pre.baseType(clazz).prefix(), clazz.owner());
@@ -2032,7 +2032,7 @@ public class Type implements Modifiers, Kinds, TypeTags {
return "<notype>";
case ThisType(Symbol sym):
if (sym.isRoot()) return "<root>.this.type";
- else if (isSameAs(localThisType)) return "<local>.this.type";
+ else if (this == localThisType) return "<local>.this.type";
else {
Type this1 = (Global.instance.debug) ? this : expandModuleThis();
if (this1 == this) return sym.nameString() + ".this.type";
@@ -2115,7 +2115,7 @@ public class Type implements Modifiers, Kinds, TypeTags {
}
private String prefixString() {
- if ((isSameAs(localThisType) || symbol().isRoot()) && !Global.instance.debug) {
+ if ((this == localThisType || symbol().isRoot()) && !Global.instance.debug) {
return "";
} else {
String spre = toString();
diff --git a/sources/scalac/symtab/classfile/AttributeParser.java b/sources/scalac/symtab/classfile/AttributeParser.java
index a9e0790889..8cc8e296d0 100644
--- a/sources/scalac/symtab/classfile/AttributeParser.java
+++ b/sources/scalac/symtab/classfile/AttributeParser.java
@@ -150,7 +150,6 @@ public class AttributeParser implements ClassfileConstants {
//System.out.println("parsing meta data for " + sym);
String meta = pool.readPool(in.nextChar()).toString().trim();
sym.setInfo(new MetaParser(meta, tvars, sym, type).parse(), parser.phaseId);
-
return;
}
throw new RuntimeException("unknown classfile attribute");
@@ -361,11 +360,16 @@ public class AttributeParser implements ClassfileConstants {
nextToken();
if (")".equals(token))
break;
+ int flags = Modifiers.PARAM;
+ if ("def".equals(token)) {
+ nextToken();
+ flags |= Modifiers.DEF;
+ }
params.add(new TermSymbol(
Position.NOPOS,
Name.fromString("x" + (i++)),
owner,
- Modifiers.PARAM).setInfo(parseType(), parser.phaseId));
+ flags).setInfo(parseType(), parser.phaseId));
//System.out.println(" + " + token);
} while (token.equals(","));
assert ")".equals(token);
diff --git a/sources/scalac/transformer/LambdaLiftPhase.java b/sources/scalac/transformer/LambdaLiftPhase.java
index 7dff375d6a..35e3e44ff0 100644
--- a/sources/scalac/transformer/LambdaLiftPhase.java
+++ b/sources/scalac/transformer/LambdaLiftPhase.java
@@ -43,8 +43,19 @@ public class LambdaLiftPhase extends PhaseDescriptor implements Kinds, Modifiers
}
public Type transformInfo(Symbol sym, Type tp) {
+ if (global.debug)
+ global.log("transform info for " + sym + sym.locationString());
Type tp1 = tp;
- if (sym != Symbol.NONE) tp1 = transform(tp, sym.owner());
+ if (sym != Symbol.NONE) {
+ switch (sym.type()) {
+ case MethodType(_, _):
+ case PolyType(_, _):
+ tp1 = transform(tp, sym);
+ break;
+ default:
+ tp1 = transform(tp, sym.owner());
+ }
+ }
if ((sym.flags & Modifiers.CAPTURED) != 0) return refType(tp1);
else return tp1;
}
@@ -55,7 +66,7 @@ public class LambdaLiftPhase extends PhaseDescriptor implements Kinds, Modifiers
return transformTypeMap.setOwner(owner).apply(tp);
}
- private class TransformTypeMap extends Type.Map {
+ private class TransformTypeMap extends Type.MapOnlyTypes {
Symbol owner;
Type.Map setOwner(Symbol owner) { this.owner = owner; return this; }
diff --git a/sources/scalac/typechecker/Analyzer.java b/sources/scalac/typechecker/Analyzer.java
index 5434867311..68aef668de 100644
--- a/sources/scalac/typechecker/Analyzer.java
+++ b/sources/scalac/typechecker/Analyzer.java
@@ -31,12 +31,12 @@ public class Analyzer extends Transformer implements Modifiers, Kinds {
public Analyzer(Global global, AnalyzerPhase descr) {
super(global, descr);
+ this.duplicator = new Transformer(
+ global, descr, make, new StrictTreeFactory(make));
this.definitions = global.definitions;
this.descr = descr;
this.infer = new Infer(this);
this.desugarize = new DeSugarize(this, global);
- this.duplicator = new Transformer(
- global, descr, make, new StrictTreeFactory(make));
}
/** Phase variables, used and set in transformers;
diff --git a/sources/scalac/typechecker/DeSugarize.java b/sources/scalac/typechecker/DeSugarize.java
index cc6654232f..228c94b286 100644
--- a/sources/scalac/typechecker/DeSugarize.java
+++ b/sources/scalac/typechecker/DeSugarize.java
@@ -263,13 +263,14 @@ public class DeSugarize implements Kinds, Modifiers {
tree.pos, 0, Names.isDefinedAt, Tree.ExtTypeDef.EMPTY_ARRAY,
duplicator.transform(vparams),
gen.mkType(tree.pos, global.definitions.BOOLEAN_TYPE), body1);
- Tree newTree = make.New(tree.pos,
+ Tree result = make.New(tree.pos,
make.Template(
tree.pos, new Tree[]{constr}, new Tree[]{applyDef, isDefinedAtDef}));
- Tree result = make.Typed(tree.pos,
- tree,
- gen.mkType(tree.pos,
- global.definitions.partialFunctionType(targs[0], targs[1])));
+
+ //Tree result = make.Typed(tree.pos,
+ // newTree,
+ // gen.mkType(tree.pos,
+ // global.definitions.partialFunctionType(targs[0], targs[1])));
print(tree, "partialfun", result);
return result;
}
@@ -277,22 +278,33 @@ public class DeSugarize implements Kinds, Modifiers {
private Tree isDefinedAtVisitor(Tree tree) {
switch (tree) {
case Visitor(CaseDef[] cases):
+ CaseDef lastCase = cases[cases.length - 1];
+ switch (lastCase) {
+ case CaseDef(Ident(Name name), Tree.Empty, Tree expr):
+ if (name.isVariable())
+ return make.Visitor(tree.pos,
+ new CaseDef[]{
+ make.CaseDef(lastCase.pos,
+ duplicator.transform(lastCase.pat),
+ Tree.Empty,
+ gen.mkBoolean(lastCase.body.pos, true))});
+ }
CaseDef[] cases1 = new CaseDef[cases.length + 1];
for (int i = 0; i < cases.length; i++) {
switch (cases[i]) {
case CaseDef(Tree pat, Tree guard, _):
- cases1[i] = (CaseDef) make.CaseDef(cases[i].pos,
+ cases1[i] = (CaseDef) make.CaseDef(
+ cases[i].pos,
duplicator.transform(pat),
duplicator.transform(guard),
- make.Select(tree.pos,
- make.Ident(tree.pos, Names.scala), Names.True));
+ gen.mkBoolean(tree.pos, true));
}
}
- cases1[cases.length] = (CaseDef) make.CaseDef(tree.pos,
+ cases1[cases.length] = (CaseDef) make.CaseDef(
+ tree.pos,
make.Ident(tree.pos, Names.WILDCARD),
- Tree.Empty,
- make.Select(tree.pos,
- make.Ident(tree.pos, Names.scala), Names.False));
+ Tree.Empty,
+ gen.mkBoolean(tree.pos, false));
return make.Visitor(tree.pos, cases1);
default:
throw new ApplicationError("visitor expected", tree);
diff --git a/test/files/pos/exceptions.scala b/test/files/pos/exceptions.scala
index 93140ddbbe..50d84d3d30 100644
--- a/test/files/pos/exceptions.scala
+++ b/test/files/pos/exceptions.scala
@@ -1,6 +1,21 @@
+import java.io._;
+
module test {
- def error[a](x: String):a = new java.lang.RuntimeException(x) throw;
+ //def error[a](x: String):a = new java.lang.RuntimeException(x) throw;
+
+ def main(): Unit {
+ try {
+ try {
+ error[Unit]("hi!");
+ } finally {
+ System.out.println("ho!")
+ }
+ } except {
+ case ex: IOException => System.out.println("io exception!");
+ case ex => System.out.println(ex);
+ }
+ }
- def main = error("hi!");
+ main();
} \ No newline at end of file
diff --git a/test/pos/exceptions.scala b/test/pos/exceptions.scala
index 93140ddbbe..50d84d3d30 100644
--- a/test/pos/exceptions.scala
+++ b/test/pos/exceptions.scala
@@ -1,6 +1,21 @@
+import java.io._;
+
module test {
- def error[a](x: String):a = new java.lang.RuntimeException(x) throw;
+ //def error[a](x: String):a = new java.lang.RuntimeException(x) throw;
+
+ def main(): Unit {
+ try {
+ try {
+ error[Unit]("hi!");
+ } finally {
+ System.out.println("ho!")
+ }
+ } except {
+ case ex: IOException => System.out.println("io exception!");
+ case ex => System.out.println(ex);
+ }
+ }
- def main = error("hi!");
+ main();
} \ No newline at end of file