From d9a4410fb10f24cdfcb9d2e17ca0c4bf7e30f418 Mon Sep 17 00:00:00 2001 From: Alex Tkachman Date: Sat, 7 Jan 2012 18:56:22 +0200 Subject: [PATCH] KT-932 split Library.jet to separate files --- compiler/frontend/src/jet/Arrays.jet | 84 ++ compiler/frontend/src/jet/Iterables.jet | 37 + compiler/frontend/src/jet/Iterators.jet | 73 ++ compiler/frontend/src/jet/Library.jet | 759 ------------------ compiler/frontend/src/jet/Numbers.jet | 474 +++++++++++ compiler/frontend/src/jet/Ranges.jet | 99 +++ .../jet/lang/resolve/TopDownAnalyzer.java | 15 +- .../jet/lang/types/JetStandardLibrary.java | 27 +- 8 files changed, 797 insertions(+), 771 deletions(-) create mode 100644 compiler/frontend/src/jet/Arrays.jet create mode 100644 compiler/frontend/src/jet/Iterables.jet create mode 100644 compiler/frontend/src/jet/Iterators.jet create mode 100644 compiler/frontend/src/jet/Numbers.jet create mode 100644 compiler/frontend/src/jet/Ranges.jet diff --git a/compiler/frontend/src/jet/Arrays.jet b/compiler/frontend/src/jet/Arrays.jet new file mode 100644 index 00000000000..be3608b03ef --- /dev/null +++ b/compiler/frontend/src/jet/Arrays.jet @@ -0,0 +1,84 @@ +package jet + +fun Array(val size : Int) : Array + +class Array(val size : Int, init : (Int) -> T) { + fun get(index : Int) : T + fun set(index : Int, value : T) : Unit + + fun iterator() : Iterator + + val indices : IntRange +} + +class ByteArray(val size : Int) { + fun get(index : Int) : Byte + fun set(index : Int, value : Byte) : Unit + + fun iterator() : ByteIterator + + val indices : IntRange +} + +class ShortArray(val size : Int) { + fun get(index : Int) : Short + fun set(index : Int, value : Short) : Unit + + fun iterator() : ShortIterator + + val indices : IntRange +} + +class IntArray(val size : Int) { + fun get(index : Int) : Int + fun set(index : Int, value : Int) : Unit + + fun iterator() : IntIterator + + val indices : IntRange +} + +class LongArray(val size : Int) { + fun get(index : Int) : Long + fun set(index : Int, value : Long) : Unit + + fun iterator() : LongIterator + + val indices : IntRange +} + +class FloatArray(val size : Int) { + fun get(index : Int) : Float + fun set(index : Int, value : Float) : Unit + + fun iterator() : FloatIterator + + val indices : IntRange +} + +class DoubleArray(val size : Int) { + fun get(index : Int) : Double + fun set(index : Int, value : Double) : Unit + + fun iterator() : DoubleIterator + + val indices : IntRange +} + +class CharArray(val size : Int) { + fun get(index : Int) : Char + fun set(index : Int, value : Char) : Unit + + fun iterator() : CharIterator + + val indices : IntRange +} + +class BooleanArray(val size : Int) { + fun get(index : Int) : Boolean + fun set(index : Int, value : Boolean) : Unit + + fun iterator() : BooleanIterator + + val indices : IntRange +} diff --git a/compiler/frontend/src/jet/Iterables.jet b/compiler/frontend/src/jet/Iterables.jet new file mode 100644 index 00000000000..900ed28a17b --- /dev/null +++ b/compiler/frontend/src/jet/Iterables.jet @@ -0,0 +1,37 @@ +package jet + +trait Iterable { + fun iterator() : Iterator +} + +trait ByteIterable : Iterable { + override fun iterator() : ByteIterator +} + +trait ShortIterable : Iterable { + override fun iterator() : ShortIterator +} + +trait IntIterable : Iterable { + override fun iterator() : IntIterator +} + +trait LongIterable : Iterable { + override fun iterator() : LongIterator +} + +trait FloatIterable : Iterable { + override fun iterator() : FloatIterator +} + +trait DoubleIterable : Iterable { + override fun iterator() : DoubleIterator +} + +trait BooleanIterable : Iterable { + override fun iterator() : BooleanIterator +} + +trait CharIterable : Iterable { + override fun iterator() : CharIterator +} diff --git a/compiler/frontend/src/jet/Iterators.jet b/compiler/frontend/src/jet/Iterators.jet new file mode 100644 index 00000000000..d96b8e3bad6 --- /dev/null +++ b/compiler/frontend/src/jet/Iterators.jet @@ -0,0 +1,73 @@ +package.jet + +trait Iterator { + fun next() : T + val hasNext : Boolean +} + +abstract open class ByteIterator() : Iterator { + abstract open fun nextByte() : Byte + + override fun next() : Byte +} + +abstract open class ShortIterator() : Iterator { + abstract open fun nextShort() : Short + + override fun next() : Short +} + +abstract open class CharIterator() : Iterator { + abstract open fun nextChar() : Char + + override fun next() : Char +} + +abstract open class IntIterator() : Iterator { + abstract open fun nextInt() : Int + + override fun next() : Int +} + +abstract open class LongIterator() : Iterator { + abstract open fun nextLong() : Long + + override fun next() : Long +} + +abstract open class FloatIterator() : Iterator { + abstract open fun nextFloat() : Float + + override fun next() : Float +} + +abstract open class DoubleIterator() : Iterator { + abstract open fun nextDouble() : Double + + override fun next() : Double +} + +abstract open class BooleanIterator() : Iterator { + abstract open fun nextBoolean() : Boolean + + override fun next() : Boolean +} + +fun Iterator.iterator() : Iterator + +fun ByteIterator.iterator() : ByteIterator + +fun ShortIterator.iterator() : ShortIterator + +fun CharIterator.iterator() : CharIterator + +fun IntIterator.iterator() : IntIterator + +fun BooleanIterator.iterator() : BooleanIterator + +fun DoubleIterator.iterator() : DoubleIterator + +fun FloatIterator.iterator() : FloatIterator + +fun LongIterator.iterator() : LongIterator + diff --git a/compiler/frontend/src/jet/Library.jet b/compiler/frontend/src/jet/Library.jet index f782b5e0473..91afe33923d 100644 --- a/compiler/frontend/src/jet/Library.jet +++ b/compiler/frontend/src/jet/Library.jet @@ -22,196 +22,6 @@ fun T?.sure() : T fun String?.plus(other: Any?) : String -fun Iterator.iterator() : Iterator - -trait Iterator { - fun next() : T - val hasNext : Boolean -} - -fun ByteIterator.iterator() : ByteIterator - -abstract open class ByteIterator() : Iterator { - abstract open fun nextByte() : Byte - - override fun next() : Byte -} - -fun ShortIterator.iterator() : ShortIterator - -abstract open class ShortIterator() : Iterator { - abstract open fun nextShort() : Short - - override fun next() : Short -} - -fun CharIterator.iterator() : CharIterator - -abstract open class CharIterator() : Iterator { - abstract open fun nextChar() : Char - - override fun next() : Char -} - -fun IntIterator.iterator() : IntIterator - -abstract open class IntIterator() : Iterator { - abstract open fun nextInt() : Int - - override fun next() : Int -} - -fun LongIterator.iterator() : LongIterator - -abstract open class LongIterator() : Iterator { - abstract open fun nextLong() : Long - - override fun next() : Long -} - -fun FloatIterator.iterator() : FloatIterator - -abstract open class FloatIterator() : Iterator { - abstract open fun nextFloat() : Float - - override fun next() : Float -} - -fun DoubleIterator.iterator() : DoubleIterator - -abstract open class DoubleIterator() : Iterator { - abstract open fun nextDouble() : Double - - override fun next() : Double -} - -fun BooleanIterator.iterator() : BooleanIterator - -abstract open class BooleanIterator() : Iterator { - abstract open fun nextBoolean() : Boolean - - override fun next() : Boolean -} - -trait Iterable { - fun iterator() : Iterator -} - -trait ByteIterable : Iterable { - override fun iterator() : ByteIterator -} - -trait ShortIterable : Iterable { - override fun iterator() : ShortIterator -} - -trait IntIterable : Iterable { - override fun iterator() : IntIterator -} - -trait LongIterable : Iterable { - override fun iterator() : LongIterator -} - -trait FloatIterable : Iterable { - override fun iterator() : FloatIterator -} - -trait DoubleIterable : Iterable { - override fun iterator() : DoubleIterator -} - -trait BooleanIterable : Iterable { - override fun iterator() : BooleanIterator -} - -trait CharIterable : Iterable { - override fun iterator() : CharIterator -} - -fun Array(val size : Int) : Array - -class Array(val size : Int, init : (Int) -> T) { - fun get(index : Int) : T - fun set(index : Int, value : T) : Unit - - fun iterator() : Iterator - - val indices : IntRange -} - -class ByteArray(val size : Int) { - fun get(index : Int) : Byte - fun set(index : Int, value : Byte) : Unit - - fun iterator() : ByteIterator - - val indices : IntRange -} - -class ShortArray(val size : Int) { - fun get(index : Int) : Short - fun set(index : Int, value : Short) : Unit - - fun iterator() : ShortIterator - - val indices : IntRange -} - -class IntArray(val size : Int) { - fun get(index : Int) : Int - fun set(index : Int, value : Int) : Unit - - fun iterator() : IntIterator - - val indices : IntRange -} - -class LongArray(val size : Int) { - fun get(index : Int) : Long - fun set(index : Int, value : Long) : Unit - - fun iterator() : LongIterator - - val indices : IntRange -} - -class FloatArray(val size : Int) { - fun get(index : Int) : Float - fun set(index : Int, value : Float) : Unit - - fun iterator() : FloatIterator - - val indices : IntRange -} - -class DoubleArray(val size : Int) { - fun get(index : Int) : Double - fun set(index : Int, value : Double) : Unit - - fun iterator() : DoubleIterator - - val indices : IntRange -} - -class CharArray(val size : Int) { - fun get(index : Int) : Char - fun set(index : Int, value : Char) : Unit - - fun iterator() : CharIterator - - val indices : IntRange -} - -class BooleanArray(val size : Int) { - fun get(index : Int) : Boolean - fun set(index : Int, value : Boolean) : Unit - - fun iterator() : BooleanIterator - - val indices : IntRange -} - trait Comparable { fun compareTo(other : T) : Int } @@ -252,573 +62,4 @@ class String() : Comparable { fun trim(): String } -trait Range> { - fun contains(item : T) : Boolean -} -class IntRange(val start : Int, val size : Int) : Range, IntIterable { - fun iterator () : IntIterator - - fun contains (elem: Int) : Boolean - - val end : Int - - fun minus() : IntRange - - fun step(step: Int) : IntIterator - - val isReversed : Boolean -} - -class LongRange(val start : Long, val size : Long) : Range, LongIterable { - fun iterator () : LongIterator - - fun contains (elem: Long) : Boolean - - val end : Long - - fun minus() : LongRange - - fun step(step: Long) : LongIterator - - val isReversed : Boolean -} - -class ByteRange(val start : Byte, val size : Int) : Range, ByteIterable { - fun iterator () : ByteIterator - - fun contains (elem: Byte) : Boolean - - val end : Byte - - fun minus() : ByteRange - - fun step(step: Int) : ByteIterator - - val isReversed : Boolean -} - -class ShortRange(val start : Short, val size : Int) : Range, ShortIterable { - fun iterator () : ShortIterator - - fun contains (elem: Byte) : Boolean - - val end : Short - - fun minus() : ShortRange - - fun step(step: Int) : ShortIterator - - val isReversed : Boolean -} - -class CharRange(val start : Char, val size : Int) : Range, CharIterable { - fun iterator () : CharIterator - - fun contains (elem: Char) : Boolean - - val end : Char - - fun minus() : CharRange - - fun step(step: Int) : CharIterator - - val isReversed : Boolean -} - -class FloatRange(val start : Float, val size : Float) : Range { - fun contains (elem: Float) : Boolean - - val end : Float - - fun minus() : FloatRange - - fun step(step: Float) : FloatIterator - - val isReversed : Boolean -} - -class DoubleRange(val start : Double, val size : Double) : Range { - fun contains (elem: Double) : Boolean - - val end : Double - - fun minus() : DoubleRange - - fun step(step: Double) : DoubleIterator - - val isReversed : Boolean -} - -abstract class Number : Hashable { - abstract val dbl : Double - abstract val flt : Float - abstract val lng : Long - abstract val int : Int - abstract val chr : Char - abstract val sht : Short - abstract val byt : Byte -// fun equals(other : Double) : Boolean -// fun equals(other : Float) : Boolean -// fun equals(other : Long) : Boolean -// fun equals(other : Byte) : Boolean -// fun equals(other : Int) : Boolean -// fun equals(other : Short) : Boolean -// fun equals(other : Char) : Boolean -} - -class Double : Number, Comparable { - override fun compareTo(other : Double) : Int - fun compareTo(other : Float) : Int - fun compareTo(other : Long) : Int - fun compareTo(other : Int) : Int - fun compareTo(other : Short) : Int - fun compareTo(other : Byte) : Int - fun compareTo(other : Char) : Int - - fun plus(other : Double) : Double - fun plus(other : Float) : Double - fun plus(other : Long) : Double - fun plus(other : Int) : Double - fun plus(other : Short) : Double - fun plus(other : Byte) : Double - fun plus(other : Char) : Double - - fun minus(other : Double) : Double - fun minus(other : Float) : Double - fun minus(other : Long) : Double - fun minus(other : Int) : Double - fun minus(other : Short) : Double - fun minus(other : Byte) : Double - fun minus(other : Char) : Double - - fun times(other : Double) : Double - fun times(other : Float) : Double - fun times(other : Long) : Double - fun times(other : Int) : Double - fun times(other : Short) : Double - fun times(other : Byte) : Double - fun times(other : Char) : Double - - fun div(other : Double) : Double - fun div(other : Float) : Double - fun div(other : Long) : Double - fun div(other : Int) : Double - fun div(other : Short) : Double - fun div(other : Byte) : Double - fun div(other : Char) : Double - - fun mod(other : Double) : Double - fun mod(other : Float) : Double - fun mod(other : Long) : Double - fun mod(other : Int) : Double - fun mod(other : Short) : Double - fun mod(other : Byte) : Double - - fun rangeTo(other : Double) : DoubleRange - fun rangeTo(other : Float) : DoubleRange - fun rangeTo(other : Long) : DoubleRange - fun rangeTo(other : Int) : DoubleRange - fun rangeTo(other : Short) : DoubleRange - fun rangeTo(other : Byte) : DoubleRange - fun rangeTo(other : Char) : DoubleRange - - fun inc() : Double - fun dec() : Double - fun plus() : Double - fun minus() : Double -} - -class Float : Number, Comparable { - fun compareTo(other : Double) : Int - override fun compareTo(other : Float) : Int - fun compareTo(other : Long) : Int - fun compareTo(other : Int) : Int - fun compareTo(other : Short) : Int - fun compareTo(other : Byte) : Int - fun compareTo(other : Char) : Int - - fun plus(other : Double) : Double - fun plus(other : Float) : Float - fun plus(other : Long) : Float - fun plus(other : Int) : Float - fun plus(other : Short) : Float - fun plus(other : Byte) : Float - fun plus(other : Char) : Float - - fun minus(other : Double) : Double - fun minus(other : Float) : Float - fun minus(other : Long) : Float - fun minus(other : Int) : Float - fun minus(other : Short) : Float - fun minus(other : Byte) : Float - fun minus(other : Char) : Float - - fun times(other : Double) : Double - fun times(other : Float) : Float - fun times(other : Long) : Float - fun times(other : Int) : Float - fun times(other : Short) : Float - fun times(other : Byte) : Float - fun times(other : Char) : Float - - fun div(other : Double) : Double - fun div(other : Float) : Float - fun div(other : Long) : Float - fun div(other : Int) : Float - fun div(other : Short) : Float - fun div(other : Byte) : Float - fun div(other : Char) : Float - - fun mod(other : Double) : Double - fun mod(other : Float) : Float - fun mod(other : Long) : Float - fun mod(other : Int) : Float - fun mod(other : Short) : Float - fun mod(other : Byte) : Float - fun mod(other : Char) : Float - - fun rangeTo(other : Double) : DoubleRange - fun rangeTo(other : Float) : FloatRange - fun rangeTo(other : Long) : DoubleRange - fun rangeTo(other : Int) : DoubleRange - fun rangeTo(other : Short) : FloatRange - fun rangeTo(other : Byte) : FloatRange - fun rangeTo(other : Char) : FloatRange - - fun inc() : Float - fun dec() : Float - fun plus() : Float - fun minus() : Float -} - -class Long : Number, Comparable { - fun compareTo(other : Double) : Int - fun compareTo(other : Float) : Int - override fun compareTo(other : Long) : Int - fun compareTo(other : Int) : Int - fun compareTo(other : Short) : Int - fun compareTo(other : Byte) : Int - fun compareTo(other : Char) : Int - - fun plus(other : Double) : Double - fun plus(other : Float) : Float - fun plus(other : Long) : Long - fun plus(other : Int) : Long - fun plus(other : Short) : Long - fun plus(other : Byte) : Long - fun plus(other : Char) : Long - - fun minus(other : Double) : Double - fun minus(other : Float) : Float - fun minus(other : Long) : Long - fun minus(other : Int) : Long - fun minus(other : Short) : Long - fun minus(other : Byte) : Long - fun minus(other : Char) : Long - - fun times(other : Double) : Double - fun times(other : Float) : Float - fun times(other : Long) : Long - fun times(other : Int) : Long - fun times(other : Short) : Long - fun times(other : Byte) : Long - fun times(other : Char) : Long - - fun div(other : Double) : Double - fun div(other : Float) : Float - fun div(other : Long) : Long - fun div(other : Int) : Long - fun div(other : Short) : Long - fun div(other : Byte) : Long - fun div(other : Char) : Long - - fun mod(other : Double) : Double - fun mod(other : Float) : Float - fun mod(other : Long) : Long - fun mod(other : Int) : Long - fun mod(other : Short) : Long - fun mod(other : Byte) : Long - fun mod(other : Char) : Long - - fun rangeTo(other : Double) : DoubleRange - fun rangeTo(other : Float) : FloatRange - fun rangeTo(other : Long) : LongRange - fun rangeTo(other : Int) : LongRange - fun rangeTo(other : Short) : LongRange - fun rangeTo(other : Byte) : LongRange - fun rangeTo(other : Char) : LongRange - - fun inc() : Long - fun dec() : Long - fun plus() : Long - fun minus() : Long - - fun shl(bits : Int) : Long - fun shr(bits : Int) : Long - fun ushr(bits : Int) : Long - fun and(other : Long) : Long - fun or(other : Long) : Long - fun xor(other : Long) : Long - fun inv() : Long -} - -class Int : Number, Comparable { - fun compareTo(other : Double) : Int - fun compareTo(other : Float) : Int - fun compareTo(other : Long) : Int - override fun compareTo(other : Int) : Int - fun compareTo(other : Short) : Int - fun compareTo(other : Byte) : Int - fun compareTo(other : Char) : Int - - fun plus(other : Double) : Double - fun plus(other : Float) : Float - fun plus(other : Long) : Long - fun plus(other : Int) : Int - fun plus(other : Short) : Int - fun plus(other : Byte) : Int - fun plus(other : Char) : Int - - fun minus(other : Double) : Double - fun minus(other : Float) : Float - fun minus(other : Long) : Long - fun minus(other : Int) : Int - fun minus(other : Short) : Int - fun minus(other : Byte) : Int - fun minus(other : Char) : Int - - fun times(other : Double) : Double - fun times(other : Float) : Float - fun times(other : Long) : Long - fun times(other : Int) : Int - fun times(other : Short) : Int - fun times(other : Byte) : Int - fun times(other : Char) : Int - - fun div(other : Double) : Double - fun div(other : Float) : Float - fun div(other : Long) : Long - fun div(other : Int) : Int - fun div(other : Short) : Int - fun div(other : Byte) : Int - fun div(other : Char) : Int - - fun mod(other : Double) : Double - fun mod(other : Float) : Float - fun mod(other : Long) : Long - fun mod(other : Int) : Int - fun mod(other : Short) : Int - fun mod(other : Byte) : Int - fun mod(other : Char) : Int - - fun rangeTo(other : Double) : DoubleRange - fun rangeTo(other : Float) : FloatRange - fun rangeTo(other : Long) : LongRange - fun rangeTo(other : Int) : IntRange - fun rangeTo(other : Short) : IntRange - fun rangeTo(other : Byte) : IntRange - fun rangeTo(other : Char) : IntRange - - fun inc() : Int - fun dec() : Int - fun plus() : Int - fun minus() : Int - - fun shl(bits : Int) : Int - fun shr(bits : Int) : Int - fun ushr(bits : Int) : Int - fun and(other : Int) : Int - fun or(other : Int) : Int - fun xor(other : Int) : Int - fun inv() : Int -} - -class Char : Number, Comparable { - fun compareTo(other : Double) : Int - fun compareTo(other : Float) : Int - fun compareTo(other : Long) : Int - fun compareTo(other : Int) : Int - fun compareTo(other : Short) : Int - override fun compareTo(other : Char) : Int - fun compareTo(other : Byte) : Int - - fun plus(other : Double) : Double - fun plus(other : Float) : Float - fun plus(other : Long) : Long - fun plus(other : Int) : Int - fun plus(other : Short) : Int - fun plus(other : Byte) : Int -// fun plus(other : Char) : Int - - fun minus(other : Double) : Double - fun minus(other : Float) : Float - fun minus(other : Long) : Long - fun minus(other : Int) : Int - fun minus(other : Short) : Int - fun minus(other : Byte) : Int - fun minus(other : Char) : Int - - fun times(other : Double) : Double - fun times(other : Float) : Float - fun times(other : Long) : Long - fun times(other : Int) : Int - fun times(other : Short) : Int - fun times(other : Byte) : Int -// fun times(other : Char) : Int - - fun div(other : Double) : Double - fun div(other : Float) : Float - fun div(other : Long) : Long - fun div(other : Int) : Int - fun div(other : Short) : Int - fun div(other : Byte) : Int -// fun div(other : Char) : Int - - fun mod(other : Double) : Double - fun mod(other : Float) : Float - fun mod(other : Long) : Long - fun mod(other : Int) : Int - fun mod(other : Short) : Int - fun mod(other : Byte) : Int -// fun mod(other : Char) : Int - - fun rangeTo(other : Double) : DoubleRange - fun rangeTo(other : Float) : FloatRange - fun rangeTo(other : Long) : LongRange - fun rangeTo(other : Int) : IntRange - fun rangeTo(other : Short) : ShortRange - fun rangeTo(other : Byte) : CharRange - fun rangeTo(other : Char) : CharRange - - fun inc() : Char - fun dec() : Char - fun plus() : Int - fun minus() : Int -} - -class Short : Number, Comparable { - fun compareTo(other : Double) : Int - fun compareTo(other : Float) : Int - fun compareTo(other : Long) : Int - fun compareTo(other : Int) : Int - override fun compareTo(other : Short) : Int - fun compareTo(other : Byte) : Int - fun compareTo(other : Char) : Int - - fun plus(other : Double) : Double - fun plus(other : Float) : Float - fun plus(other : Long) : Long - fun plus(other : Int) : Int - fun plus(other : Short) : Int - fun plus(other : Byte) : Int - fun plus(other : Char) : Int - - fun minus(other : Double) : Double - fun minus(other : Float) : Float - fun minus(other : Long) : Long - fun minus(other : Int) : Int - fun minus(other : Short) : Int - fun minus(other : Byte) : Int - fun minus(other : Char) : Int - - fun times(other : Double) : Double - fun times(other : Float) : Float - fun times(other : Long) : Long - fun times(other : Int) : Int - fun times(other : Short) : Int - fun times(other : Byte) : Int - fun times(other : Char) : Int - - fun div(other : Double) : Double - fun div(other : Float) : Float - fun div(other : Long) : Long - fun div(other : Int) : Int - fun div(other : Short) : Int - fun div(other : Byte) : Int - fun div(other : Char) : Int - - fun mod(other : Double) : Double - fun mod(other : Float) : Float - fun mod(other : Long) : Long - fun mod(other : Int) : Int - fun mod(other : Short) : Int - fun mod(other : Byte) : Int - fun mod(other : Char) : Int - - fun rangeTo(other : Double) : DoubleRange - fun rangeTo(other : Float) : FloatRange - fun rangeTo(other : Long) : LongRange - fun rangeTo(other : Int) : IntRange - fun rangeTo(other : Short) : ShortRange - fun rangeTo(other : Byte) : ShortRange - fun rangeTo(other : Char) : IntRange - - fun inc() : Short - fun dec() : Short - fun plus() : Short - fun minus() : Short -} - -class Byte : Number, Comparable { - fun compareTo(other : Double) : Int - fun compareTo(other : Float) : Int - fun compareTo(other : Long) : Int - fun compareTo(other : Int) : Int - fun compareTo(other : Short) : Int - fun compareTo(other : Char) : Int - override fun compareTo(other : Byte) : Int - - fun plus(other : Double) : Double - fun plus(other : Float) : Float - fun plus(other : Long) : Long - fun plus(other : Int) : Int - fun plus(other : Short) : Int - fun plus(other : Byte) : Int - fun plus(other : Char) : Int - - fun minus(other : Double) : Double - fun minus(other : Float) : Float - fun minus(other : Long) : Long - fun minus(other : Int) : Int - fun minus(other : Short) : Int - fun minus(other : Byte) : Int - fun minus(other : Char) : Int - - fun times(other : Double) : Double - fun times(other : Float) : Float - fun times(other : Long) : Long - fun times(other : Int) : Int - fun times(other : Short) : Int - fun times(other : Byte) : Int - fun times(other : Char) : Int - - fun div(other : Double) : Double - fun div(other : Float) : Float - fun div(other : Long) : Long - fun div(other : Int) : Int - fun div(other : Short) : Int - fun div(other : Byte) : Int - fun div(other : Char) : Int - - fun mod(other : Double) : Double - fun mod(other : Float) : Float - fun mod(other : Long) : Long - fun mod(other : Int) : Int - fun mod(other : Short) : Int - fun mod(other : Byte) : Int - fun mod(other : Char) : Int - - fun rangeTo(other : Double) : DoubleRange - fun rangeTo(other : Float) : FloatRange - fun rangeTo(other : Long) : LongRange - fun rangeTo(other : Int) : IntRange - fun rangeTo(other : Short) : ShortRange - fun rangeTo(other : Byte) : ByteRange - fun rangeTo(other : Char) : IntRange - - fun inc() : Byte - fun dec() : Byte - fun plus() : Byte - fun minus() : Byte -} \ No newline at end of file diff --git a/compiler/frontend/src/jet/Numbers.jet b/compiler/frontend/src/jet/Numbers.jet new file mode 100644 index 00000000000..21e7265bd66 --- /dev/null +++ b/compiler/frontend/src/jet/Numbers.jet @@ -0,0 +1,474 @@ +package jet + +abstract class Number : Hashable { + abstract val dbl : Double + abstract val flt : Float + abstract val lng : Long + abstract val int : Int + abstract val chr : Char + abstract val sht : Short + abstract val byt : Byte +// fun equals(other : Double) : Boolean +// fun equals(other : Float) : Boolean +// fun equals(other : Long) : Boolean +// fun equals(other : Byte) : Boolean +// fun equals(other : Int) : Boolean +// fun equals(other : Short) : Boolean +// fun equals(other : Char) : Boolean +} + +class Double : Number, Comparable { + override fun compareTo(other : Double) : Int + fun compareTo(other : Float) : Int + fun compareTo(other : Long) : Int + fun compareTo(other : Int) : Int + fun compareTo(other : Short) : Int + fun compareTo(other : Byte) : Int + fun compareTo(other : Char) : Int + + fun plus(other : Double) : Double + fun plus(other : Float) : Double + fun plus(other : Long) : Double + fun plus(other : Int) : Double + fun plus(other : Short) : Double + fun plus(other : Byte) : Double + fun plus(other : Char) : Double + + fun minus(other : Double) : Double + fun minus(other : Float) : Double + fun minus(other : Long) : Double + fun minus(other : Int) : Double + fun minus(other : Short) : Double + fun minus(other : Byte) : Double + fun minus(other : Char) : Double + + fun times(other : Double) : Double + fun times(other : Float) : Double + fun times(other : Long) : Double + fun times(other : Int) : Double + fun times(other : Short) : Double + fun times(other : Byte) : Double + fun times(other : Char) : Double + + fun div(other : Double) : Double + fun div(other : Float) : Double + fun div(other : Long) : Double + fun div(other : Int) : Double + fun div(other : Short) : Double + fun div(other : Byte) : Double + fun div(other : Char) : Double + + fun mod(other : Double) : Double + fun mod(other : Float) : Double + fun mod(other : Long) : Double + fun mod(other : Int) : Double + fun mod(other : Short) : Double + fun mod(other : Byte) : Double + + fun rangeTo(other : Double) : DoubleRange + fun rangeTo(other : Float) : DoubleRange + fun rangeTo(other : Long) : DoubleRange + fun rangeTo(other : Int) : DoubleRange + fun rangeTo(other : Short) : DoubleRange + fun rangeTo(other : Byte) : DoubleRange + fun rangeTo(other : Char) : DoubleRange + + fun inc() : Double + fun dec() : Double + fun plus() : Double + fun minus() : Double +} + +class Float : Number, Comparable { + fun compareTo(other : Double) : Int + override fun compareTo(other : Float) : Int + fun compareTo(other : Long) : Int + fun compareTo(other : Int) : Int + fun compareTo(other : Short) : Int + fun compareTo(other : Byte) : Int + fun compareTo(other : Char) : Int + + fun plus(other : Double) : Double + fun plus(other : Float) : Float + fun plus(other : Long) : Float + fun plus(other : Int) : Float + fun plus(other : Short) : Float + fun plus(other : Byte) : Float + fun plus(other : Char) : Float + + fun minus(other : Double) : Double + fun minus(other : Float) : Float + fun minus(other : Long) : Float + fun minus(other : Int) : Float + fun minus(other : Short) : Float + fun minus(other : Byte) : Float + fun minus(other : Char) : Float + + fun times(other : Double) : Double + fun times(other : Float) : Float + fun times(other : Long) : Float + fun times(other : Int) : Float + fun times(other : Short) : Float + fun times(other : Byte) : Float + fun times(other : Char) : Float + + fun div(other : Double) : Double + fun div(other : Float) : Float + fun div(other : Long) : Float + fun div(other : Int) : Float + fun div(other : Short) : Float + fun div(other : Byte) : Float + fun div(other : Char) : Float + + fun mod(other : Double) : Double + fun mod(other : Float) : Float + fun mod(other : Long) : Float + fun mod(other : Int) : Float + fun mod(other : Short) : Float + fun mod(other : Byte) : Float + fun mod(other : Char) : Float + + fun rangeTo(other : Double) : DoubleRange + fun rangeTo(other : Float) : FloatRange + fun rangeTo(other : Long) : DoubleRange + fun rangeTo(other : Int) : DoubleRange + fun rangeTo(other : Short) : FloatRange + fun rangeTo(other : Byte) : FloatRange + fun rangeTo(other : Char) : FloatRange + + fun inc() : Float + fun dec() : Float + fun plus() : Float + fun minus() : Float +} + +class Long : Number, Comparable { + fun compareTo(other : Double) : Int + fun compareTo(other : Float) : Int + override fun compareTo(other : Long) : Int + fun compareTo(other : Int) : Int + fun compareTo(other : Short) : Int + fun compareTo(other : Byte) : Int + fun compareTo(other : Char) : Int + + fun plus(other : Double) : Double + fun plus(other : Float) : Float + fun plus(other : Long) : Long + fun plus(other : Int) : Long + fun plus(other : Short) : Long + fun plus(other : Byte) : Long + fun plus(other : Char) : Long + + fun minus(other : Double) : Double + fun minus(other : Float) : Float + fun minus(other : Long) : Long + fun minus(other : Int) : Long + fun minus(other : Short) : Long + fun minus(other : Byte) : Long + fun minus(other : Char) : Long + + fun times(other : Double) : Double + fun times(other : Float) : Float + fun times(other : Long) : Long + fun times(other : Int) : Long + fun times(other : Short) : Long + fun times(other : Byte) : Long + fun times(other : Char) : Long + + fun div(other : Double) : Double + fun div(other : Float) : Float + fun div(other : Long) : Long + fun div(other : Int) : Long + fun div(other : Short) : Long + fun div(other : Byte) : Long + fun div(other : Char) : Long + + fun mod(other : Double) : Double + fun mod(other : Float) : Float + fun mod(other : Long) : Long + fun mod(other : Int) : Long + fun mod(other : Short) : Long + fun mod(other : Byte) : Long + fun mod(other : Char) : Long + + fun rangeTo(other : Double) : DoubleRange + fun rangeTo(other : Float) : FloatRange + fun rangeTo(other : Long) : LongRange + fun rangeTo(other : Int) : LongRange + fun rangeTo(other : Short) : LongRange + fun rangeTo(other : Byte) : LongRange + fun rangeTo(other : Char) : LongRange + + fun inc() : Long + fun dec() : Long + fun plus() : Long + fun minus() : Long + + fun shl(bits : Int) : Long + fun shr(bits : Int) : Long + fun ushr(bits : Int) : Long + fun and(other : Long) : Long + fun or(other : Long) : Long + fun xor(other : Long) : Long + fun inv() : Long +} + +class Int : Number, Comparable { + fun compareTo(other : Double) : Int + fun compareTo(other : Float) : Int + fun compareTo(other : Long) : Int + override fun compareTo(other : Int) : Int + fun compareTo(other : Short) : Int + fun compareTo(other : Byte) : Int + fun compareTo(other : Char) : Int + + fun plus(other : Double) : Double + fun plus(other : Float) : Float + fun plus(other : Long) : Long + fun plus(other : Int) : Int + fun plus(other : Short) : Int + fun plus(other : Byte) : Int + fun plus(other : Char) : Int + + fun minus(other : Double) : Double + fun minus(other : Float) : Float + fun minus(other : Long) : Long + fun minus(other : Int) : Int + fun minus(other : Short) : Int + fun minus(other : Byte) : Int + fun minus(other : Char) : Int + + fun times(other : Double) : Double + fun times(other : Float) : Float + fun times(other : Long) : Long + fun times(other : Int) : Int + fun times(other : Short) : Int + fun times(other : Byte) : Int + fun times(other : Char) : Int + + fun div(other : Double) : Double + fun div(other : Float) : Float + fun div(other : Long) : Long + fun div(other : Int) : Int + fun div(other : Short) : Int + fun div(other : Byte) : Int + fun div(other : Char) : Int + + fun mod(other : Double) : Double + fun mod(other : Float) : Float + fun mod(other : Long) : Long + fun mod(other : Int) : Int + fun mod(other : Short) : Int + fun mod(other : Byte) : Int + fun mod(other : Char) : Int + + fun rangeTo(other : Double) : DoubleRange + fun rangeTo(other : Float) : FloatRange + fun rangeTo(other : Long) : LongRange + fun rangeTo(other : Int) : IntRange + fun rangeTo(other : Short) : IntRange + fun rangeTo(other : Byte) : IntRange + fun rangeTo(other : Char) : IntRange + + fun inc() : Int + fun dec() : Int + fun plus() : Int + fun minus() : Int + + fun shl(bits : Int) : Int + fun shr(bits : Int) : Int + fun ushr(bits : Int) : Int + fun and(other : Int) : Int + fun or(other : Int) : Int + fun xor(other : Int) : Int + fun inv() : Int +} + +class Char : Number, Comparable { + fun compareTo(other : Double) : Int + fun compareTo(other : Float) : Int + fun compareTo(other : Long) : Int + fun compareTo(other : Int) : Int + fun compareTo(other : Short) : Int + override fun compareTo(other : Char) : Int + fun compareTo(other : Byte) : Int + + fun plus(other : Double) : Double + fun plus(other : Float) : Float + fun plus(other : Long) : Long + fun plus(other : Int) : Int + fun plus(other : Short) : Int + fun plus(other : Byte) : Int +// fun plus(other : Char) : Int + + fun minus(other : Double) : Double + fun minus(other : Float) : Float + fun minus(other : Long) : Long + fun minus(other : Int) : Int + fun minus(other : Short) : Int + fun minus(other : Byte) : Int + fun minus(other : Char) : Int + + fun times(other : Double) : Double + fun times(other : Float) : Float + fun times(other : Long) : Long + fun times(other : Int) : Int + fun times(other : Short) : Int + fun times(other : Byte) : Int +// fun times(other : Char) : Int + + fun div(other : Double) : Double + fun div(other : Float) : Float + fun div(other : Long) : Long + fun div(other : Int) : Int + fun div(other : Short) : Int + fun div(other : Byte) : Int +// fun div(other : Char) : Int + + fun mod(other : Double) : Double + fun mod(other : Float) : Float + fun mod(other : Long) : Long + fun mod(other : Int) : Int + fun mod(other : Short) : Int + fun mod(other : Byte) : Int +// fun mod(other : Char) : Int + + fun rangeTo(other : Double) : DoubleRange + fun rangeTo(other : Float) : FloatRange + fun rangeTo(other : Long) : LongRange + fun rangeTo(other : Int) : IntRange + fun rangeTo(other : Short) : ShortRange + fun rangeTo(other : Byte) : CharRange + fun rangeTo(other : Char) : CharRange + + fun inc() : Char + fun dec() : Char + fun plus() : Int + fun minus() : Int +} + +class Short : Number, Comparable { + fun compareTo(other : Double) : Int + fun compareTo(other : Float) : Int + fun compareTo(other : Long) : Int + fun compareTo(other : Int) : Int + override fun compareTo(other : Short) : Int + fun compareTo(other : Byte) : Int + fun compareTo(other : Char) : Int + + fun plus(other : Double) : Double + fun plus(other : Float) : Float + fun plus(other : Long) : Long + fun plus(other : Int) : Int + fun plus(other : Short) : Int + fun plus(other : Byte) : Int + fun plus(other : Char) : Int + + fun minus(other : Double) : Double + fun minus(other : Float) : Float + fun minus(other : Long) : Long + fun minus(other : Int) : Int + fun minus(other : Short) : Int + fun minus(other : Byte) : Int + fun minus(other : Char) : Int + + fun times(other : Double) : Double + fun times(other : Float) : Float + fun times(other : Long) : Long + fun times(other : Int) : Int + fun times(other : Short) : Int + fun times(other : Byte) : Int + fun times(other : Char) : Int + + fun div(other : Double) : Double + fun div(other : Float) : Float + fun div(other : Long) : Long + fun div(other : Int) : Int + fun div(other : Short) : Int + fun div(other : Byte) : Int + fun div(other : Char) : Int + + fun mod(other : Double) : Double + fun mod(other : Float) : Float + fun mod(other : Long) : Long + fun mod(other : Int) : Int + fun mod(other : Short) : Int + fun mod(other : Byte) : Int + fun mod(other : Char) : Int + + fun rangeTo(other : Double) : DoubleRange + fun rangeTo(other : Float) : FloatRange + fun rangeTo(other : Long) : LongRange + fun rangeTo(other : Int) : IntRange + fun rangeTo(other : Short) : ShortRange + fun rangeTo(other : Byte) : ShortRange + fun rangeTo(other : Char) : IntRange + + fun inc() : Short + fun dec() : Short + fun plus() : Short + fun minus() : Short +} + +class Byte : Number, Comparable { + fun compareTo(other : Double) : Int + fun compareTo(other : Float) : Int + fun compareTo(other : Long) : Int + fun compareTo(other : Int) : Int + fun compareTo(other : Short) : Int + fun compareTo(other : Char) : Int + override fun compareTo(other : Byte) : Int + + fun plus(other : Double) : Double + fun plus(other : Float) : Float + fun plus(other : Long) : Long + fun plus(other : Int) : Int + fun plus(other : Short) : Int + fun plus(other : Byte) : Int + fun plus(other : Char) : Int + + fun minus(other : Double) : Double + fun minus(other : Float) : Float + fun minus(other : Long) : Long + fun minus(other : Int) : Int + fun minus(other : Short) : Int + fun minus(other : Byte) : Int + fun minus(other : Char) : Int + + fun times(other : Double) : Double + fun times(other : Float) : Float + fun times(other : Long) : Long + fun times(other : Int) : Int + fun times(other : Short) : Int + fun times(other : Byte) : Int + fun times(other : Char) : Int + + fun div(other : Double) : Double + fun div(other : Float) : Float + fun div(other : Long) : Long + fun div(other : Int) : Int + fun div(other : Short) : Int + fun div(other : Byte) : Int + fun div(other : Char) : Int + + fun mod(other : Double) : Double + fun mod(other : Float) : Float + fun mod(other : Long) : Long + fun mod(other : Int) : Int + fun mod(other : Short) : Int + fun mod(other : Byte) : Int + fun mod(other : Char) : Int + + fun rangeTo(other : Double) : DoubleRange + fun rangeTo(other : Float) : FloatRange + fun rangeTo(other : Long) : LongRange + fun rangeTo(other : Int) : IntRange + fun rangeTo(other : Short) : ShortRange + fun rangeTo(other : Byte) : ByteRange + fun rangeTo(other : Char) : IntRange + + fun inc() : Byte + fun dec() : Byte + fun plus() : Byte + fun minus() : Byte +} \ No newline at end of file diff --git a/compiler/frontend/src/jet/Ranges.jet b/compiler/frontend/src/jet/Ranges.jet new file mode 100644 index 00000000000..ff1140ec275 --- /dev/null +++ b/compiler/frontend/src/jet/Ranges.jet @@ -0,0 +1,99 @@ +package jet + +trait Range> { + fun contains(item : T) : Boolean +} + +class IntRange(val start : Int, val size : Int) : Range, IntIterable { + fun iterator () : IntIterator + + fun contains (elem: Int) : Boolean + + val end : Int + + fun minus() : IntRange + + fun step(step: Int) : IntIterator + + val isReversed : Boolean +} + +class LongRange(val start : Long, val size : Long) : Range, LongIterable { + fun iterator () : LongIterator + + fun contains (elem: Long) : Boolean + + val end : Long + + fun minus() : LongRange + + fun step(step: Long) : LongIterator + + val isReversed : Boolean +} + +class ByteRange(val start : Byte, val size : Int) : Range, ByteIterable { + fun iterator () : ByteIterator + + fun contains (elem: Byte) : Boolean + + val end : Byte + + fun minus() : ByteRange + + fun step(step: Int) : ByteIterator + + val isReversed : Boolean +} + +class ShortRange(val start : Short, val size : Int) : Range, ShortIterable { + fun iterator () : ShortIterator + + fun contains (elem: Byte) : Boolean + + val end : Short + + fun minus() : ShortRange + + fun step(step: Int) : ShortIterator + + val isReversed : Boolean +} + +class CharRange(val start : Char, val size : Int) : Range, CharIterable { + fun iterator () : CharIterator + + fun contains (elem: Char) : Boolean + + val end : Char + + fun minus() : CharRange + + fun step(step: Int) : CharIterator + + val isReversed : Boolean +} + +class FloatRange(val start : Float, val size : Float) : Range { + fun contains (elem: Float) : Boolean + + val end : Float + + fun minus() : FloatRange + + fun step(step: Float) : FloatIterator + + val isReversed : Boolean +} + +class DoubleRange(val start : Double, val size : Double) : Range { + fun contains (elem: Double) : Boolean + + val end : Double + + fun minus() : DoubleRange + + fun step(step: Double) : DoubleIterator + + val isReversed : Boolean +} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java index e6155266c1e..934452b32dd 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java @@ -9,13 +9,16 @@ import org.jetbrains.jet.lang.Configuration; import org.jetbrains.jet.lang.JetSemanticServices; import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory; import org.jetbrains.jet.lang.descriptors.*; +import org.jetbrains.jet.lang.psi.JetDeclaration; import org.jetbrains.jet.lang.psi.JetFile; import org.jetbrains.jet.lang.psi.JetObjectDeclaration; import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.WritableScope; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.List; /** * @author abreslav @@ -93,14 +96,18 @@ public class TopDownAnalyzer { @NotNull BindingTrace trace, @NotNull WritableScope outerScope, @NotNull NamespaceDescriptorImpl standardLibraryNamespace, - @NotNull JetFile file) { + @NotNull List files) { TopDownAnalysisContext context = new TopDownAnalysisContext(semanticServices, trace, Predicates.alwaysTrue(), Configuration.EMPTY, false); - context.getNamespaceDescriptors().put(file, standardLibraryNamespace); - context.getNamespaceScopes().put(file, standardLibraryNamespace.getMemberScope()); + ArrayList toAnalyze = new ArrayList(); + for(JetFile file : files) { + context.getNamespaceDescriptors().put(file, standardLibraryNamespace); + context.getNamespaceScopes().put(file, standardLibraryNamespace.getMemberScope()); + toAnalyze.addAll(file.getDeclarations()); + } // context.getDeclaringScopes().put(file, outerScope); context.setAnalyzingBootstrapLibrary(true); - doProcess(context, outerScope, standardLibraryNamespace, file.getDeclarations(), JetControlFlowDataTraceFactory.EMPTY); + doProcess(context, outerScope, standardLibraryNamespace, toAnalyze, JetControlFlowDataTraceFactory.EMPTY); } public static void processObject( diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java index 6c23f5d6422..8ae62f01cee 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java @@ -21,9 +21,7 @@ import org.jetbrains.jet.plugin.JetFileType; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.util.Collections; -import java.util.List; -import java.util.Set; +import java.util.*; /** * @author abreslav @@ -126,11 +124,24 @@ public class JetStandardLibrary { private JetStandardLibrary(@NotNull Project project) { // TODO : review - InputStream stream = JetStandardClasses.class.getClassLoader().getResourceAsStream("jet/Library.jet"); + List libraryFiles = Arrays.asList( + "Library.jet", + "Numbers.jet", + "Ranges.jet", + "Iterables.jet", + "Iterators.jet", + "Arrays.jet" + ); try { - //noinspection IOResourceOpenedButNotSafelyClosed - JetFile file = (JetFile) PsiFileFactory.getInstance(project).createFileFromText("Library.jet", - JetFileType.INSTANCE, FileUtil.loadTextAndClose(new InputStreamReader(stream))); + List files = new LinkedList(); + for(String fileName : libraryFiles) { + InputStream stream = JetStandardClasses.class.getClassLoader().getResourceAsStream("jet/" + fileName); + + //noinspection IOResourceOpenedButNotSafelyClosed + JetFile file = (JetFile) PsiFileFactory.getInstance(project).createFileFromText(fileName, + JetFileType.INSTANCE, FileUtil.loadTextAndClose(new InputStreamReader(stream))); + files.add(file); + } JetSemanticServices bootstrappingSemanticServices = JetSemanticServices.createSemanticServices(this); BindingTraceContext bindingTraceContext = new BindingTraceContext(); @@ -138,7 +149,7 @@ public class JetStandardLibrary { writableScope.changeLockLevel(WritableScope.LockLevel.BOTH); // this.libraryScope = bootstrappingTDA.process(JetStandardClasses.STANDARD_CLASSES, file.getRootNamespace().getDeclarations()); // bootstrappingTDA.process(writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file.getRootNamespace().getDeclarations()); - TopDownAnalyzer.processStandardLibraryNamespace(bootstrappingSemanticServices, bindingTraceContext, writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, file); + TopDownAnalyzer.processStandardLibraryNamespace(bootstrappingSemanticServices, bindingTraceContext, writableScope, JetStandardClasses.STANDARD_CLASSES_NAMESPACE, files); // this.libraryScope = JetStandardClasses.STANDARD_CLASSES_NAMESPACE.getMemberScope(); AnalyzingUtils.throwExceptionOnErrors(bindingTraceContext.getBindingContext());