Int#downto

This commit is contained in:
Pavel V. Talanov
2012-07-20 12:38:07 +04:00
parent ad94786555
commit 8eb0fb31ca
4 changed files with 21 additions and 1 deletions
@@ -48,4 +48,8 @@ public final class RangeTest extends SingleFileTranslationTest {
public void testIntUpTo() throws Exception { public void testIntUpTo() throws Exception {
fooBoxTest(); fooBoxTest();
} }
public void testIntDownTo() throws Exception {
fooBoxTest();
}
} }
@@ -31,5 +31,6 @@ public final class RangesFIF extends CompositeFIF {
private RangesFIF() { private RangesFIF() {
add(pattern("Int.upto"), new CallStandardMethodIntrinsic("Kotlin.intUpto", true, 1)); add(pattern("Int.upto"), new CallStandardMethodIntrinsic("Kotlin.intUpto", true, 1));
add(pattern("Int.downto"), new CallStandardMethodIntrinsic("Kotlin.intDownto", true, 1));
} }
} }
+5 -1
View File
@@ -43,7 +43,11 @@ var kotlin = {set:function (receiver, key, value) {
}; };
Kotlin.intUpto = function (from, limit) { Kotlin.intUpto = function (from, limit) {
return Kotlin.$new(Kotlin.NumberRange)(from, limit - from + 1); return Kotlin.$new(Kotlin.NumberRange)(from, limit - from + 1, false);
};
Kotlin.intDownto = function (from, limit) {
return Kotlin.$new(Kotlin.NumberRange)(from, from - limit + 1, true);
}; };
Kotlin.modules = {}; Kotlin.modules = {};
@@ -0,0 +1,11 @@
package foo
import java.util.ArrayList
fun box() : Boolean {
var elems = ArrayList<Int>()
for (i in 4 downto 0) {
elems.add(i)
}
return elems[0] == 4 && elems[1] == 3 && elems[2] == 2 && elems[3] == 1 && elems[4] == 0
}