From f3f4a361d0438c25fb2d3ae30e8f6280c75890ef Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Thu, 30 Dec 2010 17:01:13 +0300 Subject: [PATCH] Examples fixed, some bugs found --- examples/src/AnonymousObjects.jetl | 5 +++-- examples/src/BinaryTree.jetl | 12 ++++++------ examples/src/BitArith.jetl | 6 +++--- examples/src/Builder.jetl | 12 ++++++------ examples/src/FunctionsAndTypes.jetl | 2 +- examples/src/Graph.jetl | 4 ++-- examples/src/IPushPop.jetl | 2 +- examples/src/LINQ.jetl | 5 +++-- examples/src/PolymorphicClassObjects.jetl | 4 ++-- examples/src/Queue.jetl | 6 +++--- examples/src/Stack.jetl | 6 +++--- examples/src/UnionFind.jetl | 3 +-- examples/src/array/MutableArray.jetl | 6 +++--- examples/src/collections/ArrayList.jetl | 14 +++++++------- examples/src/collections/HashMap.jetl | 10 +++++----- .../jet/lang/parsing/JetExpressionParsing.java | 4 ++++ .../org/jetbrains/jet/lang/parsing/JetParsing.java | 4 ++++ 17 files changed, 57 insertions(+), 48 deletions(-) diff --git a/examples/src/AnonymousObjects.jetl b/examples/src/AnonymousObjects.jetl index 0f844cf66df..6c5a97b66b1 100644 --- a/examples/src/AnonymousObjects.jetl +++ b/examples/src/AnonymousObjects.jetl @@ -1,3 +1,5 @@ +fun foo() { + addMouseListener(object MouseAdapter() { private var clickCount = 0; @@ -19,5 +21,4 @@ val GOD = object { }; -// Groovy like syntax: too many things to assume -addMouseListener([mouseClicked : {e => doFoo()}]); +} \ No newline at end of file diff --git a/examples/src/BinaryTree.jetl b/examples/src/BinaryTree.jetl index 8327a968db0..03a4f0a399f 100644 --- a/examples/src/BinaryTree.jetl +++ b/examples/src/BinaryTree.jetl @@ -11,16 +11,16 @@ class BinaryTree : IMutableSet { private var root : TreeNode private var version = 0 - override var size : Int { get; private set; } +// override var size : Int { get; private set; } this(compare : Comparison) { this.compare = asMatchableComparison(comparison) } - this() : this(naturalOrder) { + this() : this(naturalOrder()) { } - private extension [operator] fun T.compareTo(other : T) : Int = compare(this, other) + private [operator] fun T.compareTo(other : T) : Int = compare(this, other) override fun contains(item : T) : Boolean { return contains(root, item) @@ -129,7 +129,7 @@ class BinaryTree : IMutableSet { override fun iterator() : IIterator = mutableIterator() - override fun mutableIterator() : IMutableIterator = new IMutableIterator() { + override fun mutableIterator() : IMutableIterator = object IMutableIterator { val version = BinaryTree.this.version val down = Stack() val up = Stack() @@ -172,9 +172,9 @@ class BinaryTree : IMutableSet { } } - override val hasNext : Boolean { + override val hasNext : Boolean get() = !down.isEmpty || !up.isEmpty - } + override fun remove() { checkVersion() diff --git a/examples/src/BitArith.jetl b/examples/src/BitArith.jetl index 678554993d2..d9bdf1dbcc0 100644 --- a/examples/src/BitArith.jetl +++ b/examples/src/BitArith.jetl @@ -19,11 +19,11 @@ fun mostSignificantBit(x : INumber) = (x and oneBit(x.bits - 1) != 0) as Int fun countOnes(x : INumber) = if (x == 0) 0 else mostSignificantBit(x) + countOnes(x shl 1) -extension fun Int.matchMask(mask : Int) = this and mask == mask +fun Int.matchMask(mask : Int) = this and mask == mask -interface class INumber : IComparable { +virtual class INumber : IComparable { val bits : Int [operator] fun plus(other : T) : T [operator] fun shl(bits : Int) : T - ... + // ... } \ No newline at end of file diff --git a/examples/src/Builder.jetl b/examples/src/Builder.jetl index 51c542a67ce..ef3036b8e68 100644 --- a/examples/src/Builder.jetl +++ b/examples/src/Builder.jetl @@ -22,22 +22,22 @@ class AntBuilder { abstract class ClassPathEntry {} class Module : ClassPathEntry { - fun classpath(entries : ClassPathEntry...) { ... } + fun classpath(entries : ClassPathEntry/*...*/) { /*...*/ } var targetLevel : String - fun src(src : String) { ... } + fun src(src : String) { /*...*/ } } class Library : ClassPathEntry { - fun classpath(entries : ClassPathEntry...) { ... } + fun classpath(entries : ClassPathEntry/*...*/) { /*...*/ } } - fun library(initializer : Library.{ () : Library}) { + fun library(initializer : { Library.() : Library}) { val lib = new Library() lib.initializer() return lib } - fun classpath... + fun classpath(/*...*/) - fun module... + fun module(/*...*/) } \ No newline at end of file diff --git a/examples/src/FunctionsAndTypes.jetl b/examples/src/FunctionsAndTypes.jetl index 168b9eea6de..623e765c4ac 100644 --- a/examples/src/FunctionsAndTypes.jetl +++ b/examples/src/FunctionsAndTypes.jetl @@ -6,7 +6,7 @@ type f_tuple = {((T, E)) : X} //type f_tuple = {((T, E)) => X} type hof = { (X) : {(T) : Y} } //type hof = { (X) => {(T) => Y} } -type hof2 = { {(X) : Y} : {(Y) : Z} } +type hof2 = { ({(X) : Y}) : {(Y) : Z} } //type hof2 = { {(X) => Y} => {(Y) => Z} } diff --git a/examples/src/Graph.jetl b/examples/src/Graph.jetl index 9a8732d053e..225d387f10d 100644 --- a/examples/src/Graph.jetl +++ b/examples/src/Graph.jetl @@ -1,6 +1,6 @@ -sealed class Vertex(val data : V) +class Vertex(val data : V) -sealed class Edge(val from : V, val data : E, val to : V) +class Edge(val from : V, val data : E, val to : V) class Graph { diff --git a/examples/src/IPushPop.jetl b/examples/src/IPushPop.jetl index 9065c1e0d10..09b1f2d8267 100644 --- a/examples/src/IPushPop.jetl +++ b/examples/src/IPushPop.jetl @@ -1,4 +1,4 @@ -interface class IPushPop { +virtual class IPushPop { val isEmpty : Boolean fun push(item : T) fun pop() : T diff --git a/examples/src/LINQ.jetl b/examples/src/LINQ.jetl index 71746b49818..e492a0c22d3 100644 --- a/examples/src/LINQ.jetl +++ b/examples/src/LINQ.jetl @@ -1,2 +1,3 @@ -l filter {it.x} map {it.foo} aggregate {a, b => a + b} - +fun foo() { + l filter {it.x} map {it.foo} aggregate {(a, b) => a + b} +} \ No newline at end of file diff --git a/examples/src/PolymorphicClassObjects.jetl b/examples/src/PolymorphicClassObjects.jetl index d9810048d82..86fcb9ade5b 100644 --- a/examples/src/PolymorphicClassObjects.jetl +++ b/examples/src/PolymorphicClassObjects.jetl @@ -16,10 +16,10 @@ class List { } -extension Map for T +extension Map where T : Iterable, - class object T : Buildable { + class object T : Buildable for T { fun map(f : {(E) : R}) : T = { val builder = T.newBuilder() diff --git a/examples/src/Queue.jetl b/examples/src/Queue.jetl index bbbbe1dc8c2..375f9babd53 100644 --- a/examples/src/Queue.jetl +++ b/examples/src/Queue.jetl @@ -1,4 +1,4 @@ -sealed class Queue : IPushPop { +class Queue : IPushPop { private class Item(val data : T, var next : Item) private var head : Item = null @@ -26,8 +26,8 @@ sealed class Queue : IPushPop { result } - override val isEmpty { + override val isEmpty get() = head == null - } + } \ No newline at end of file diff --git a/examples/src/Stack.jetl b/examples/src/Stack.jetl index 2e0803f543a..426bc28c9a9 100644 --- a/examples/src/Stack.jetl +++ b/examples/src/Stack.jetl @@ -1,4 +1,4 @@ -sealed class Stack : IPushPop { +class Stack : IPushPop { private val data = new ArrayList(); override fun push(item : T) { @@ -7,7 +7,7 @@ sealed class Stack : IPushPop { override fun pop() = data.removeLast() - override val isEmpty { // TODO: This is UGLY :( + override val isEmpty get() = data.isEmpty - } + } \ No newline at end of file diff --git a/examples/src/UnionFind.jetl b/examples/src/UnionFind.jetl index a817d3383fe..917d724d9b0 100644 --- a/examples/src/UnionFind.jetl +++ b/examples/src/UnionFind.jetl @@ -29,6 +29,5 @@ class UnionFind { } } -extension val Int.isOdd : Boolean { +val Int.isOdd : Boolean get() = this % 2 != 0 -} \ No newline at end of file diff --git a/examples/src/array/MutableArray.jetl b/examples/src/array/MutableArray.jetl index a2c0dba2e90..311279c875c 100644 --- a/examples/src/array/MutableArray.jetl +++ b/examples/src/array/MutableArray.jetl @@ -2,12 +2,12 @@ These declarations are "shallow" in the sense that they are not really compiled, only the type-checker uses them */ -interface class ReadOnlyArray : ISized { +virtual class ReadOnlyArray : ISized { [operator] fun get(index : Int) : T } -interface class WriteOnlyArray : ISized { // This is needed to keep IIterator's covariant +virtual class WriteOnlyArray : ISized { // This is needed to keep IIterator's covariant [operator] fun set(index : Int, value : T) } -class MutableArray : ReadOnlyArray, WriteOnlyArray {...} \ No newline at end of file +class MutableArray : ReadOnlyArray, WriteOnlyArray {/*...*/} \ No newline at end of file diff --git a/examples/src/collections/ArrayList.jetl b/examples/src/collections/ArrayList.jetl index ef3575ecba9..2f076052068 100644 --- a/examples/src/collections/ArrayList.jetl +++ b/examples/src/collections/ArrayList.jetl @@ -5,7 +5,7 @@ class ArrayList : IMutableList { override fun iterator() : IIterator = mutableIterator() - override fun mutableIterator() : IMutableIterator = new IMutableIterator() { // T is inferred + override fun mutableIterator() : IMutableIterator = object IMutableIterator() { // T is inferred private val index = 0 private var myVersion = version @@ -21,9 +21,9 @@ class ArrayList : IMutableList { data[index++] } - override val hasNext { + override val hasNext get() = index < used - } + override fun remove() { checkVersion() @@ -43,13 +43,13 @@ class ArrayList : IMutableList { throw new IndexOutOfBoundsException(index) } - override val isEmpty { + override val isEmpty get() = used == 0 - } - override val size { + + override val size get() = used - } + override fun set(index : Int, value : T) { checkIndex(index) diff --git a/examples/src/collections/HashMap.jetl b/examples/src/collections/HashMap.jetl index 45feb068776..7839372b766 100644 --- a/examples/src/collections/HashMap.jetl +++ b/examples/src/collections/HashMap.jetl @@ -4,9 +4,9 @@ virtual class IEquality { } virtual class IHashable : IEquality { - val hashCode() : Integer { + val hashCode : Integer get() = (this as java.lang.Object).hashCode() - } + } virtual class IMap { @@ -16,7 +16,7 @@ virtual class IMap { fun containsKey(key : K) : Boolean } -class HashableWrapper(wraps val obj : Any) : IHashable +class HashableWrapper wraps (val obj : Any) : IHashable // equals and hashCode implementations are inherited [inline] fun Any.hashable() : HashableWrapper = new HashableWrapper(this) @@ -48,11 +48,11 @@ class HashMap : IMap { class StrategyHashMap(hashingStrategy : IHashingStrategy) : IMap { - this() where (K : IHashable) : this(new DefaultHashingStrategy()) {} - // where !(K : IHashable) + // where !(K : IHashable) this() : this(new JavaObjectHashingStrategy()) {} + this() where (K : IHashable) : this(new DefaultHashingStrategy()) {} //... } \ No newline at end of file diff --git a/idea/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java b/idea/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java index 5231a6de9b8..ddaa005c171 100644 --- a/idea/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java +++ b/idea/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java @@ -40,6 +40,7 @@ public class JetExpressionParsing extends AbstractJetParsing { } }, + // TODO: wrong priority for call: Random.nextInt().isOdd POSTFIX(PLUSPLUS, MINUSMINUS), // typeArguments? valueArguments : arrayAccess PREFIX(MINUS, PLUS, MINUSMINUS, PLUSPLUS, EXCL) { // attributes @@ -61,11 +62,13 @@ public class JetExpressionParsing extends AbstractJetParsing { RANGE(JetTokens.RANGE), SIMPLE_NAME(IDENTIFIER), ELVIS(JetTokens.ELVIS), + // TODO: RHS (type parameters) NAMED_INFIX_OR_TYPE(IN_KEYWORD, NOT_IN, IS_KEYWORD, NOT_IS, AS_KEYWORD, COLON), COMPARISON(LT, GT, LTEQ, GTEQ), EQUALITY(EQEQ, EXCLEQ, EQEQEQ, EXCLEQEQEQ), CONJUNCTION(ANDAND), DISJUNCTION(OROR), + // TODO: RHS MATCH(MATCH_KEYWORD), // TODO: don't build a binary tree, build a tuple ARROW(JetTokens.ARROW), @@ -170,6 +173,7 @@ public class JetExpressionParsing extends AbstractJetParsing { */ private void parsePostfixExpression() { // System.out.println("post at " + tt()); + // TODO: call with a closure outside parentheses PsiBuilder.Marker expression = mark(); parseBinaryExpression(Precedence.MEMBER_ACCESS); diff --git a/idea/src/org/jetbrains/jet/lang/parsing/JetParsing.java b/idea/src/org/jetbrains/jet/lang/parsing/JetParsing.java index 4364c1ed3b2..a1ac47b8641 100644 --- a/idea/src/org/jetbrains/jet/lang/parsing/JetParsing.java +++ b/idea/src/org/jetbrains/jet/lang/parsing/JetParsing.java @@ -702,6 +702,7 @@ public class JetParsing extends AbstractJetParsing { */ public JetNodeType parseProperty() { // TODO: var foo : Int { get; private set } + // TODO: accessors for local variables assert at(VAL_KEYWORD) || at(VAR_KEYWORD); @@ -1167,6 +1168,7 @@ public class JetParsing extends AbstractJetParsing { * ; */ public void parseTypeRef() { + // TODO: Self type PsiBuilder.Marker type = mark(); parseAttributeList(); @@ -1341,6 +1343,8 @@ public class JetParsing extends AbstractJetParsing { * ; */ public void parseValueParameterList(boolean isFunctionTypeContents, TokenSet recoverySet) { + // TODO: val a, b, c : Int + PsiBuilder.Marker parameters = mark(); myBuilder.disableEols();