diff --git a/gradle.properties b/gradle.properties index 2b92450e0a3..dc6d76a256d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,11 +16,11 @@ # A version of the Kotlin "toolchain" (compiler, runtime, stdlib etc) used by the build script. buildKotlinVersion=1.3-M1-eap-77 -buildKotlinCompilerRepo=https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:Kotlin_13M1_Compiler),number:1.3-M1-eap-77,branch:default:any/artifacts/content/maven/ +buildKotlinCompilerRepo=https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:Kotlin_13M1_Compiler),number:1.3-M1-eap-77,branch:default:any/artifacts/content/maven remoteRoot=konan_tests testDataVersion=1226829:id -kotlinCompilerRepo=https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:Kotlin_13M2_CompilerAllPlugins),number:1.3-M2-eap-33,tag:kotlin-native,pinned:true/artifacts/content/maven -kotlinVersion=1.3-M2-eap-33 +kotlinCompilerRepo=https://teamcity.jetbrains.com/guestAuth/app/rest/builds/buildType:(id:Kotlin_13M2_CompilerAllPlugins),number:1.3-M2-eap-82,tag:kotlin-native,pinned:true/artifacts/content/maven +kotlinVersion=1.3-M2-eap-82 testKotlinVersion=1.3-M2-eap-33 konanVersion=0.9 org.gradle.jvmargs='-Dfile.encoding=UTF-8' diff --git a/runtime/src/main/cpp/KString.cpp b/runtime/src/main/cpp/KString.cpp index 3629ad93938..798a938392b 100644 --- a/runtime/src/main/cpp/KString.cpp +++ b/runtime/src/main/cpp/KString.cpp @@ -737,6 +737,29 @@ KInt Kotlin_String_compareTo(KString thiz, KString other) { return diff < 0 ? -1 : 1; } +KInt Kotlin_String_compareToIgnoreCase(KString thiz, KConstRef other) { + RuntimeAssert(thiz->type_info() == theStringTypeInfo && + other->type_info() == theStringTypeInfo, "Must be strings"); + // Important, due to literal internalization. + KString otherString = other->array(); + if (thiz == otherString) return 0; + auto count = thiz->count_ < otherString->count_ ? thiz->count_ : otherString->count_; + const KChar* thizRaw = CharArrayAddressOfElementAt(thiz, 0); + const KChar* otherRaw = CharArrayAddressOfElementAt(otherString, 0); + for (KInt index = 0; index < count; ++index) { + int diff = towlower_Konan(*thizRaw++) - towlower_Konan(*otherRaw++); + if (diff != 0) + return diff < 0 ? -1 : 1; + } + if (otherString->count_ == thiz->count_) + return 0; + else if (otherString->count_ > thiz->count_) + return -1; + else + return 1; +} + + KChar Kotlin_String_get(KString thiz, KInt index) { if (static_cast(index) >= thiz->count_) { ThrowArrayIndexOutOfBoundsException(); diff --git a/runtime/src/main/cpp/Natives.h b/runtime/src/main/cpp/Natives.h index 8e5b0f40734..59a4a09b615 100644 --- a/runtime/src/main/cpp/Natives.h +++ b/runtime/src/main/cpp/Natives.h @@ -122,6 +122,7 @@ OBJ_GETTER(Kotlin_Int_toString, KInt value); KInt Kotlin_String_hashCode(KString thiz); KBoolean Kotlin_String_equals(KString thiz, KConstRef other); KInt Kotlin_String_compareTo(KString thiz, KString other); +KInt Kotlin_String_compareToIgnoreCase(KString thiz, KConstRef other); KChar Kotlin_String_get(KString thiz, KInt index); OBJ_GETTER(Kotlin_String_fromUtf8Array, KConstRef array, KInt start, KInt size); OBJ_GETTER(Kotlin_String_fromCharArray, KConstRef array, KInt start, KInt size); diff --git a/runtime/src/main/kotlin/kotlin/Exceptions.kt b/runtime/src/main/kotlin/kotlin/Exceptions.kt index fa77f467de0..e01d6f747e8 100644 --- a/runtime/src/main/kotlin/kotlin/Exceptions.kt +++ b/runtime/src/main/kotlin/kotlin/Exceptions.kt @@ -124,10 +124,10 @@ public open class TypeCastException : ClassCastException { constructor(message: String?) : super(message) } -public open class ArithmeticException : RuntimeException { - constructor() : super() +public actual open class ArithmeticException : RuntimeException { + actual constructor() : super() - constructor(message: String?) : super(message) + actual constructor(message: String?) : super(message) } public actual open class AssertionError : Error { diff --git a/runtime/src/main/kotlin/kotlin/collections/Collections.kt b/runtime/src/main/kotlin/kotlin/collections/Collections.kt index adab827884a..c6130ac0e1a 100644 --- a/runtime/src/main/kotlin/kotlin/collections/Collections.kt +++ b/runtime/src/main/kotlin/kotlin/collections/Collections.kt @@ -17,6 +17,7 @@ package kotlin.collections import kotlin.comparisons.* +import kotlin.internal.InlineOnly import kotlin.random.* // Copies typed varargs array to an array of objects @@ -246,3 +247,24 @@ public actual fun MutableList.shuffle(): Unit { @SinceKotlin("1.2") public actual fun Iterable.shuffled(): List = toMutableList().apply { shuffle() } +@PublishedApi +@SinceKotlin("1.3") +@InlineOnly +internal actual inline fun checkIndexOverflow(index: Int): Int { + if (index < 0) { + // TODO: api version check? + throwIndexOverflow() + } + return index +} + +@PublishedApi +@SinceKotlin("1.3") +@InlineOnly +internal actual inline fun checkCountOverflow(count: Int): Int { + if (count < 0) { + // TODO: api version check? + throwCountOverflow() + } + return count +} diff --git a/runtime/src/main/kotlin/kotlin/native/internal/NativePtr.kt b/runtime/src/main/kotlin/kotlin/native/internal/NativePtr.kt index 4932d169176..b1227a7d283 100644 --- a/runtime/src/main/kotlin/kotlin/native/internal/NativePtr.kt +++ b/runtime/src/main/kotlin/kotlin/native/internal/NativePtr.kt @@ -38,4 +38,10 @@ class NativePtr @PublishedApi internal constructor(private val value: NonNullNat internal inline class NonNullNativePtr(val value: NotNullPointerValue) { // TODO: refactor to use this type widely. @Suppress("NOTHING_TO_INLINE") inline fun toNativePtr() = NativePtr(this) + // TODO: fixme. + override fun toString() = "" + + override fun hashCode() = 0 + + override fun equals(other: Any?) = false } diff --git a/runtime/src/main/kotlin/kotlin/text/Strings.kt b/runtime/src/main/kotlin/kotlin/text/Strings.kt index 15a41f4f040..617c035d7e4 100644 --- a/runtime/src/main/kotlin/kotlin/text/Strings.kt +++ b/runtime/src/main/kotlin/kotlin/text/Strings.kt @@ -55,3 +55,16 @@ public actual fun String(chars: CharArray): String = fromCharArray(chars, 0, cha * Converts the characters from a portion of the specified array to a string. */ public actual fun String(chars: CharArray, offset: Int, length: Int): String = fromCharArray(chars, offset, length) + +@SymbolName("Kotlin_String_compareToIgnoreCase") +external fun compareToIgnoreCase(thiz:String, other:String):Int + +actual fun String.compareTo(other: String, ignoreCase: Boolean): Int { + return if (!ignoreCase) this.compareTo(other) + else compareToIgnoreCase(this, other) +} + +private val STRING_CASE_INSENSITIVE_ORDER = Comparator { a, b -> a.compareTo(b, ignoreCase = true) } + +actual val String.Companion.CASE_INSENSITIVE_ORDER: Comparator + get() = STRING_CASE_INSENSITIVE_ORDER \ No newline at end of file