summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2003-11-11 14:06:09 +0000
committerMartin Odersky <odersky@gmail.com>2003-11-11 14:06:09 +0000
commitab3ba403efdb2c4ab829e526c8fe21783c44ef27 (patch)
tree43b30f20b1a6a9cdbe0f58a8d876f89562da4b42
parent8f126982806efc1c68ac717c7fd9dba70d85e787 (diff)
downloadscala-ab3ba403efdb2c4ab829e526c8fe21783c44ef27.tar.gz
scala-ab3ba403efdb2c4ab829e526c8fe21783c44ef27.tar.bz2
scala-ab3ba403efdb2c4ab829e526c8fe21783c44ef27.zip
*** empty log message ***
-rw-r--r--doc/reference/ScalaByExample.tex24
-rw-r--r--sources/scala/Array.java2
-rw-r--r--sources/scala/Predef.scala1
-rw-r--r--sources/scalac/ast/TreeGen.java3
-rw-r--r--sources/scalac/ast/parser/PatternNormalizer.java18
-rw-r--r--sources/scalac/ast/parser/Scanner.java2
-rw-r--r--sources/scalac/symtab/Type.java30
-rw-r--r--sources/scalac/typechecker/Infer.java14
8 files changed, 48 insertions, 46 deletions
diff --git a/doc/reference/ScalaByExample.tex b/doc/reference/ScalaByExample.tex
index 7849be4882..55065ceb9c 100644
--- a/doc/reference/ScalaByExample.tex
+++ b/doc/reference/ScalaByExample.tex
@@ -470,7 +470,7 @@ simplification steps.
\item apply the operator to the operand values.
\end{itemize}
A name defined by \code{def}\ is evaluated by replacing the name by the
-definition's right hand side. A name defined by \code{val} is
+(unevaluated) definition's right hand side. A name defined by \code{val} is
evaluated by replacing the name by the value of the definitions's
right-hand side. The evaluation process stops once we have reached a
value. A value is some data item such as a string, a number, an array,
@@ -599,8 +599,9 @@ constOne(x: int, def y: int): int
Scala's \code{if-else} lets one choose between two alternatives. Its
syntax is like Java's \code{if-else}. But where Java's \code{if-else}
can be used only as an alternative of statements, Scala allows the
-same syntax to choose between two expressions. Scala's \code{if-else}
-hence also replaces Java's conditional expression \code{ ... ? ... : ...}.
+same syntax to choose between two expressions. That's why Scala's
+\code{if-else} serves also as a substitute for Java's conditional
+expression \code{ ... ? ... : ...}.
\example\
@@ -627,10 +628,10 @@ which computes the square root of \code{x}.
A common way to compute square roots is by Newton's method of
successive approximations. One starts with an initial guess \code{y}
(say: \code{y = 1}). One then repeatedly improves the current guess
-\code{y} by taking the average of \code{y} and \code{x/y}.
-As an example, the next three columns indicate the guess \code{y}, the
+\code{y} by taking the average of \code{y} and \code{x/y}. As an
+example, the next three columns indicate the guess \code{y}, the
quotient \code{x/y}, and their average for the first approximations of
-$\sqrt 2$.
+$\sqrt 2$.
\begin{lstlisting}
1 2/1 = 2 1.5
1.5 2/1.5 = 1.3333 1.4167
@@ -830,13 +831,10 @@ both functions. Such calls are called ``tail calls''. In principle,
tail calls can always re-use the stack frame of the calling function.
However, some run-time environments (such as the Java VM) lack the
primititives to make stack frame re-use for tail calls efficient. A
-production quality Scala implementation is therefore only required to re-use
-the stack frame of a directly tail-recursive function whose last
-action is a call to itself. Other tail calls might be optimized also,
-but one should not rely on this across
-implementations\footnote{The current Scala implementation is not yet
-production quality; it never optimizes tail calls, not even directly
-recursive ones}.
+production quality Scala implementation is therefore only required to
+re-use the stack frame of a directly tail-recursive function whose
+last action is a call to itself. Other tail calls might be optimized
+also, but one should not rely on this across implementations.
\exercise Design a tail-recursive version of
\code{factorial}.
diff --git a/sources/scala/Array.java b/sources/scala/Array.java
index 0ff31e9acb..53ee7c242c 100644
--- a/sources/scala/Array.java
+++ b/sources/scala/Array.java
@@ -11,7 +11,7 @@
package scala;
-/** @meta class [+ ?T] extends scala.Function1[scala.Int, ?T];
+/** @meta class [?T] extends scala.Function1[scala.Int, ?T];
*/
public abstract class Array
extends scala.Object
diff --git a/sources/scala/Predef.scala b/sources/scala/Predef.scala
index fb9386896c..fdea7c5b78 100644
--- a/sources/scala/Predef.scala
+++ b/sources/scala/Predef.scala
@@ -54,4 +54,5 @@ object Predef {
def id[a](x: a): a = x;
def fst[a](x: a, y: Any): a = x;
def scd[a](x: Any, y: a): a = y;
+
}
diff --git a/sources/scalac/ast/TreeGen.java b/sources/scalac/ast/TreeGen.java
index 0dc210e2ae..987bf8b743 100644
--- a/sources/scalac/ast/TreeGen.java
+++ b/sources/scalac/ast/TreeGen.java
@@ -262,6 +262,7 @@ public class TreeGen implements Kinds, Modifiers, TypeTags {
/** Builds a reference corresponding to given symbol. */
public Tree mkRef(int pos, Symbol sym) {
+ //System.out.println("mkref " + sym.owner().thisType() + " . " + sym);//DEBUG
return mkRef(pos, sym.owner().thisType(), sym);
}
@@ -405,7 +406,7 @@ public class TreeGen implements Kinds, Modifiers, TypeTags {
global.prevPhase();
return mkApplyTV(pos, mkRef(pos, constr), targs, vargs);
}
- public Tree mkPrimaryConstr(int pos, Symbol clazz,Type[]targs,Tree[]vargs){
+ public Tree mkPrimaryConstr(int pos, Symbol clazz, Type[]targs, Tree[]vargs){
return mkPrimaryConstr(pos,clazz.owner().thisType(),clazz,targs,vargs);
}
diff --git a/sources/scalac/ast/parser/PatternNormalizer.java b/sources/scalac/ast/parser/PatternNormalizer.java
index 8b69ef84ae..f2a35829df 100644
--- a/sources/scalac/ast/parser/PatternNormalizer.java
+++ b/sources/scalac/ast/parser/PatternNormalizer.java
@@ -200,7 +200,7 @@ public class PatternNormalizer {
*/
// apply `flattenAlternative' to each tree in ts
- Tree[] flattenAlternatives( Tree[] ts ) {
+ public Tree[] flattenAlternatives( Tree[] ts ) {
Tree[] res = new Tree[ ts.length ];
for( int i = 0; i < ts.length; i++ )
res[ i ] = flattenAlternative( ts[ i ] );
@@ -208,7 +208,7 @@ public class PatternNormalizer {
}
// main algo for (1)
- Tree flattenAlternative( Tree tree ) {
+ public Tree flattenAlternative( Tree tree ) {
switch( tree ) {
case Alternative( Tree[] choices ):
TreeList cs = new TreeList();
@@ -244,7 +244,7 @@ public class PatternNormalizer {
}
// main algo for (1), precondition: choices are children of an Alternative node
- TreeList flattenAlternativeChildren( Tree[] choices ) {
+ public TreeList flattenAlternativeChildren( Tree[] choices ) {
boolean allEmpty = true;
TreeList cs = new TreeList();
for( int j = 0; j < choices.length; j++ ) {
@@ -275,14 +275,14 @@ public class PatternNormalizer {
*/
// apply `flattenSequence' to each tree in trees
- Tree[] flattenSequences( Tree[] trees ) {
+ public Tree[] flattenSequences( Tree[] trees ) {
Tree[] res = new Tree[ trees.length ];
for( int i = 0; i < trees.length; i++ )
res[ i ] = flattenSequence( trees[ i ] );
return res;
}
// main algo for (2)
- Tree flattenSequence( Tree tree ) {
+ public Tree flattenSequence( Tree tree ) {
//System.out.println("flattenSequence of "+tree);
switch( tree ) {
/*
@@ -347,14 +347,14 @@ public class PatternNormalizer {
/** applies `elimSequence' to each tree is ts
*/
- Tree[] elimSequences( Tree[] ts ) {
+ public Tree[] elimSequences( Tree[] ts ) {
Tree[] res = new Tree[ ts.length ];
for( int i = 0; i < ts.length; i++ )
res[ i ] = elimSequence( ts[ i ] );
return res;
}
- Tree elimSequence( Tree tree ) {
+ public Tree elimSequence( Tree tree ) {
switch( tree ) {
case Sequence( Tree[] trees ):
// might be empty ...
@@ -457,7 +457,7 @@ public class PatternNormalizer {
/** applies `warpAlternative' to each tree is ts
*/
- Tree[] wrapAlternatives( Tree[] trees ) {
+ public Tree[] wrapAlternatives( Tree[] trees ) {
Tree[] newts = new Tree[ trees.length ];
for( int i = 0; i < trees.length; i++ )
newts[ i ] = wrapAlternative( trees[ i ] );
@@ -466,7 +466,7 @@ public class PatternNormalizer {
/** main algo for (4)
*/
- Tree wrapAlternative( Tree tree ) {
+ public Tree wrapAlternative( Tree tree ) {
switch( tree ) {
case Alternative( Tree[] choices ):
return make.Alternative( tree.pos, wrapAlternativeChildren( choices ));
diff --git a/sources/scalac/ast/parser/Scanner.java b/sources/scalac/ast/parser/Scanner.java
index 7d5910588b..ae8a9ba187 100644
--- a/sources/scalac/ast/parser/Scanner.java
+++ b/sources/scalac/ast/parser/Scanner.java
@@ -24,7 +24,7 @@ public class Scanner extends TokenData {
/** buffer for the documentation comment
*/
- protected StringBuffer docBuffer = null;
+ public StringBuffer docBuffer = null;
/** add the given character to the documentation buffer
*/
diff --git a/sources/scalac/symtab/Type.java b/sources/scalac/symtab/Type.java
index b419a83e7c..632900eea4 100644
--- a/sources/scalac/symtab/Type.java
+++ b/sources/scalac/symtab/Type.java
@@ -152,21 +152,21 @@ public class Type implements Modifiers, Kinds, TypeTags, EntryTags {
}
private static Type value2type(Object value) {
- if (value instanceof Character)
- return Global.instance.definitions.CHAR_TYPE();
- else if (value instanceof Integer)
- return Global.instance.definitions.INT_TYPE();
- else if (value instanceof Long)
- return Global.instance.definitions.LONG_TYPE();
- else if (value instanceof Float)
- return Global.instance.definitions.FLOAT_TYPE();
- else if (value instanceof Double)
- return Global.instance.definitions.DOUBLE_TYPE();
- else if (value instanceof String)
- return Global.instance.definitions.JAVA_STRING_TYPE();
- else if (value instanceof Boolean)
- return Global.instance.definitions.BOOLEAN_TYPE();
- else throw new ApplicationError();
+ if (value instanceof Character)
+ return Global.instance.definitions.CHAR_CLASS.typeConstructor();
+ else if (value instanceof Integer)
+ return Global.instance.definitions.INT_CLASS.typeConstructor();
+ else if (value instanceof Long)
+ return Global.instance.definitions.LONG_CLASS.typeConstructor();
+ else if (value instanceof Float)
+ return Global.instance.definitions.FLOAT_CLASS.typeConstructor();
+ else if (value instanceof Double)
+ return Global.instance.definitions.DOUBLE_CLASS.typeConstructor();
+ else if (value instanceof String)
+ return Global.instance.definitions.JAVA_STRING_CLASS.typeConstructor();
+ else if (value instanceof Boolean)
+ return Global.instance.definitions.BOOLEAN_CLASS.typeConstructor();
+ else throw new ApplicationError();
}
public static Type singleTypeMethod(Type pre, Symbol sym) {
diff --git a/sources/scalac/typechecker/Infer.java b/sources/scalac/typechecker/Infer.java
index 0ad12d6cd2..29acd44100 100644
--- a/sources/scalac/typechecker/Infer.java
+++ b/sources/scalac/typechecker/Infer.java
@@ -337,13 +337,15 @@ public class Infer implements Modifiers, Kinds {
Type[] result;
if (params.length == 1 && (params[0].flags & REPEATED) != 0) {
Type[] formals = new Type[length];
- Type ft = params[0].type().typeArgs()[0];
- // params[0] has type Seq[T], we need T here
- for (int i = 0; i < length; i++) formals[i] = ft;
- return formals;
- } else {
- return Symbol.type(params);
+ Type[] args = params[0].type().typeArgs();
+ if (args.length == 1) {
+ Type ft = args[0];
+ // params[0] has type Seq[T], we need T here
+ for (int i = 0; i < length; i++) formals[i] = ft;
+ return formals;
+ }
}
+ return Symbol.type(params);
}
/** Is type fully defined, i.e. no embedded anytypes or typevars in it?