diff options
author | Martin Odersky <odersky@gmail.com> | 2004-04-23 14:11:16 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2004-04-23 14:11:16 +0000 |
commit | 92fcc53be94a107f3b560b855564bc39ba8f2372 (patch) | |
tree | c1b8e40ef4d21e18741b9f286d6e9047d39cc44e /sources | |
parent | abe707d00a280e8f33cbc2a064cb970460c19d7d (diff) | |
download | scala-92fcc53be94a107f3b560b855564bc39ba8f2372.tar.gz scala-92fcc53be94a107f3b560b855564bc39ba8f2372.tar.bz2 scala-92fcc53be94a107f3b560b855564bc39ba8f2372.zip |
*** empty log message ***
Diffstat (limited to 'sources')
-rw-r--r-- | sources/scala/Ordered.scala | 1 | ||||
-rw-r--r-- | sources/scala/Predef.scala | 17 | ||||
-rw-r--r-- | sources/scalac/ast/TreeGen.java | 4 | ||||
-rw-r--r-- | sources/scalac/symtab/Definitions.java | 20 |
4 files changed, 33 insertions, 9 deletions
diff --git a/sources/scala/Ordered.scala b/sources/scala/Ordered.scala index 4ea0ce95a0..2a75d68923 100644 --- a/sources/scala/Ordered.scala +++ b/sources/scala/Ordered.scala @@ -30,3 +30,4 @@ trait Ordered[+a] { def >= [b >: a <% Ordered[b]](that: b): boolean = (this compareTo that) >= 0; } + diff --git a/sources/scala/Predef.scala b/sources/scala/Predef.scala index 217158cc56..f6cc14a52f 100644 --- a/sources/scala/Predef.scala +++ b/sources/scala/Predef.scala @@ -141,6 +141,23 @@ object Predef { case _ => -(y compareTo x) } } + def view[a <% Ordered[a]](x: Array[a]): Ordered[Array[a]] = new Ordered[Array[a]] { + def compareTo [b >: Array[a] <% Ordered[b]](y: b): int = y match { + case y1: Array[a] => compareArrays(x, y1); + case _ => -(y compareTo x) + } + private def compareArrays(xs: Array[a], ys: Array[a]): int = { + var i = 0; + while (i < xs.length && i < ys.length) { + if (xs(i) < ys(i)) return -1; + if (xs(i) > ys(i)) return 1; + i = i + 1 + } + if (i < xs.length) return 1 + else if (i < ys.length) return -1 + else 0 + } + } def view[A](xs: Array[A]): Seq[A] = new Seq[A] { def length = xs.length; diff --git a/sources/scalac/ast/TreeGen.java b/sources/scalac/ast/TreeGen.java index 405f14d618..9e08df3f56 100644 --- a/sources/scalac/ast/TreeGen.java +++ b/sources/scalac/ast/TreeGen.java @@ -838,7 +838,7 @@ public class TreeGen implements Kinds, Modifiers, TypeTags { /** Builds an empty list. */ public Tree mkNil(int pos) { - return mkGlobalRef(pos, definitions.NIL); + return mkGlobalRef(pos, definitions.NIL()); } /** Builds a list with given element type, head and tail. */ @@ -852,7 +852,7 @@ public class TreeGen implements Kinds, Modifiers, TypeTags { global.prevPhase(); return New( mkApplyTV( - mkPrimaryConstructorGlobalRef(pos, definitions.CONS_CLASS), + mkPrimaryConstructorGlobalRef(pos, definitions.CONS_CLASS()), new Type[]{element}, new Tree[]{head, tail})); } diff --git a/sources/scalac/symtab/Definitions.java b/sources/scalac/symtab/Definitions.java index 31a69e40be..f086914990 100644 --- a/sources/scalac/symtab/Definitions.java +++ b/sources/scalac/symtab/Definitions.java @@ -197,13 +197,21 @@ public class Definitions { return LIST_CLASS.staticType(element); } - /** The scala.Nil module */ - public final Symbol NIL; + /** The scala.Nil module + * evaluated on demand to make bootstrap possible. + */ + public final Symbol NIL() { + return getModule("scala.Nil"); + } - /** The scala.:: class */ - public final Symbol CONS_CLASS; + /** The scala.:: class + * evaluated on demand to make bootstrap possible. + */ + public final Symbol CONS_CLASS() { + return getClass("scala.$colon$colon"); + } public final Type CONS_TYPE(Type element) { - return CONS_CLASS.staticType(element); + return CONS_CLASS().staticType(element); } /** The scala.Array class */ @@ -628,8 +636,6 @@ public class Definitions { ITERATOR_CLASS = getClass("scala.Iterator"); SEQ_CLASS = getClass("scala.Seq"); LIST_CLASS = getClass("scala.List"); - NIL = getModule("scala.Nil"); - CONS_CLASS = getClass("scala.$colon$colon"); ARRAY_CLASS = getClass("scala.Array"); TYPE_CLASS = getClass("scala.Type"); CONSTRUCTEDTYPE_CLASS = getClass("scala.ConstructedType"); |