diff --git a/generators/builtins/common.kt b/generators/builtins/common.kt index a54f469db0d..b92994b7d90 100644 --- a/generators/builtins/common.kt +++ b/generators/builtins/common.kt @@ -36,6 +36,16 @@ enum class PrimitiveType { } } +enum class UnsignedType { + UBYTE, + USHORT, + UINT, + ULONG; + + val capitalized: String get() = name.substring(0, 2) + name.substring(2).toLowerCase() + val asSigned: PrimitiveType = PrimitiveType.valueOf(name.substring(1)) +} + enum class ProgressionKind { CHAR, INT, @@ -53,3 +63,4 @@ fun areEqualNumbers(v: String) = "$v == other.$v" fun hashLong(v: String) = "($v xor ($v ushr 32))" +fun convert(v: String, from: UnsignedType, to: UnsignedType) = if (from == to) v else "$v.to${to.capitalized}()" \ No newline at end of file diff --git a/generators/builtins/generateBuiltIns.kt b/generators/builtins/generateBuiltIns.kt index d6be5e95910..ef97b08e31e 100644 --- a/generators/builtins/generateBuiltIns.kt +++ b/generators/builtins/generateBuiltIns.kt @@ -13,6 +13,7 @@ import org.jetbrains.kotlin.generators.builtins.progressionIterators.GeneratePro import org.jetbrains.kotlin.generators.builtins.progressions.GenerateProgressions import org.jetbrains.kotlin.generators.builtins.ranges.GeneratePrimitives import org.jetbrains.kotlin.generators.builtins.ranges.GenerateRanges +import org.jetbrains.kotlin.generators.builtins.unsigned.generateUnsignedTypes import org.xml.sax.InputSource import java.io.File import java.io.PrintWriter @@ -25,6 +26,7 @@ fun assertExists(file: File) { val BUILT_INS_NATIVE_DIR = File("core/builtins/native/") val BUILT_INS_SRC_DIR = File("core/builtins/src/") val RUNTIME_JVM_DIR = File("libraries/stdlib/jvm/runtime/") +val UNSIGNED_TYPES_DIR = File("libraries/stdlib/unsigned/src") abstract class BuiltInsSourceGenerator(val out: PrintWriter) { protected abstract fun generateBody(): Unit @@ -65,6 +67,7 @@ fun generateBuiltIns(generate: (File, (PrintWriter) -> BuiltInsSourceGenerator) assertExists(BUILT_INS_NATIVE_DIR) assertExists(BUILT_INS_SRC_DIR) assertExists(RUNTIME_JVM_DIR) + assertExists(UNSIGNED_TYPES_DIR) generate(File(RUNTIME_JVM_DIR, "kotlin/jvm/functions/Functions.kt")) { GenerateFunctions(it) } generate(File(BUILT_INS_NATIVE_DIR, "kotlin/Arrays.kt")) { GenerateArrays(it) } @@ -74,6 +77,8 @@ fun generateBuiltIns(generate: (File, (PrintWriter) -> BuiltInsSourceGenerator) generate(File(BUILT_INS_SRC_DIR, "kotlin/ProgressionIterators.kt")) { GenerateProgressionIterators(it) } generate(File(BUILT_INS_SRC_DIR, "kotlin/Progressions.kt")) { GenerateProgressions(it) } generate(File(BUILT_INS_SRC_DIR, "kotlin/Ranges.kt")) { GenerateRanges(it) } + + generateUnsignedTypes(UNSIGNED_TYPES_DIR, generate) } fun main(args: Array) { diff --git a/generators/builtins/primitives.kt b/generators/builtins/primitives.kt index 1b69eb80049..531a29fc41e 100644 --- a/generators/builtins/primitives.kt +++ b/generators/builtins/primitives.kt @@ -10,27 +10,29 @@ import org.jetbrains.kotlin.generators.builtins.generateBuiltIns.BuiltInsSourceG import java.io.PrintWriter class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) { - private val binaryOperators: Map = mapOf( + companion object { + internal val binaryOperators: Map = mapOf( "plus" to "Adds the other value to this value.", "minus" to "Subtracts the other value from this value.", "times" to "Multiplies this value by the other value.", "div" to "Divides this value by the other value.", "mod" to "Calculates the remainder of dividing this value by the other value.", "rem" to "Calculates the remainder of dividing this value by the other value." - ) - private val unaryOperators: Map = mapOf( + ) + internal val unaryOperators: Map = mapOf( "inc" to "Increments this value.", "dec" to "Decrements this value.", "unaryPlus" to "Returns this value.", "unaryMinus" to "Returns the negative of this value.") - private val shiftOperators: Map = mapOf( + internal val shiftOperators: Map = mapOf( "shl" to "Shifts this value left by the [bitCount] number of bits.", "shr" to "Shifts this value right by the [bitCount] number of bits, filling the leftmost bits with copies of the sign bit.", "ushr" to "Shifts this value right by the [bitCount] number of bits, filling the leftmost bits with zeros.") - private val bitwiseOperators: Map = mapOf( + internal val bitwiseOperators: Map = mapOf( "and" to "Performs a bitwise AND operation between the two values.", "or" to "Performs a bitwise OR operation between the two values.", "xor" to "Performs a bitwise XOR operation between the two values.") + } private val typeDescriptions: Map = mapOf( PrimitiveType.DOUBLE to "double-precision 64-bit IEEE 754 floating point number", PrimitiveType.FLOAT to "single-precision 32-bit IEEE 754 floating point number", diff --git a/generators/builtins/unsignedTypes.kt b/generators/builtins/unsignedTypes.kt new file mode 100644 index 00000000000..544fdfcb80d --- /dev/null +++ b/generators/builtins/unsignedTypes.kt @@ -0,0 +1,173 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.generators.builtins.unsigned + + +import org.jetbrains.kotlin.generators.builtins.UnsignedType +import org.jetbrains.kotlin.generators.builtins.generateBuiltIns.BuiltInsSourceGenerator +import org.jetbrains.kotlin.generators.builtins.ranges.GeneratePrimitives +import java.io.File +import java.io.PrintWriter + + +fun generateUnsignedTypes( + targetDir: File, + generate: (File, (PrintWriter) -> BuiltInsSourceGenerator) -> Unit +) { + for (type in UnsignedType.values()) { + generate(File(targetDir, "kotlin/${type.capitalized}.kt")) { UnsignedTypeGenerator(type, it) } + } + + +} + +class UnsignedTypeGenerator(val type: UnsignedType, out: PrintWriter) : BuiltInsSourceGenerator(out) { + val className = type.capitalized + val storageType = type.asSigned.capitalized + + override fun generateBody() { + + out.println("import kotlin.experimental.*") + out.println() + + out.println("public inline class $className internal constructor(private val data: $storageType) : Comparable<$className> {") + out.println() + out.println(""" companion object { + /** + * A constant holding the minimum value an instance of $className can have. + */ + public /*const*/ val MIN_VALUE: $className = $className(0) + + /** + * A constant holding the maximum value an instance of $className can have. + */ + public /*const*/ val MAX_VALUE: $className = $className(-1) + }""") + + generateCompareTo() + + generateBinaryOperators() + generateUnaryOperators() + generateRangeTo() + + if (type == UnsignedType.UINT || type == UnsignedType.ULONG) { + generateBitShiftOperators() + } + + generateBitwiseOperators() + + generateMemberConversions() + + out.println("}") + out.println() + + + generateExtensionConversions() + } + + + private fun generateCompareTo() { + for (otherType in UnsignedType.values()) { + out.println(""" + /** + * Compares this value with the specified value for order. + * Returns zero if this value is equal to the specified other value, a negative number if it's less than other, + * or a positive number if it's greater than other. + */""") + out.print(" public ") + if (otherType == type) out.print("override ") + out.println("operator fun compareTo(other: ${otherType.capitalized}): Int = TODO()") + } + out.println() + } + + private fun generateBinaryOperators() { + for ((name, doc) in GeneratePrimitives.binaryOperators) { + if (name != "mod") { + generateOperator(name, doc) + } + } + } + + private fun generateOperator(name: String, doc: String) { + for (otherType in UnsignedType.values()) { + val returnType = getOperatorReturnType(type, otherType) + + out.println(" /** $doc */") + out.println(" public operator fun $name(other: ${otherType.capitalized}): ${returnType.capitalized} = TODO()") + } + out.println() + } + + + private fun generateUnaryOperators() { + for ((name, doc) in GeneratePrimitives.unaryOperators) { + if (name in listOf("unaryPlus", "unaryMinus")) continue // TODO: Decide if unaryPlus and unaryMinus are needed + out.println(" /** $doc */") + out.println(" public operator fun $name(): $className = TODO()") + } + out.println() + } + + private fun generateRangeTo() { + // TODO("not implemented") + } + + + private fun generateBitShiftOperators() { + + fun generateShiftOperator(name: String, implementation: String = name) { + val doc = GeneratePrimitives.shiftOperators[implementation]!! + out.println(" /** $doc */") + out.println(" public infix fun $name(bitCount: Int): $className = $className(data $implementation bitCount)") + } + + generateShiftOperator("shl") + generateShiftOperator("shr", "ushr") + } + + private fun generateBitwiseOperators() { + for ((name, doc) in GeneratePrimitives.bitwiseOperators) { + out.println(" /** $doc */") + out.println(" public infix fun $name(other: $className): $className = $className(this.data $name other.data)") + } + out.println(" /** Inverts the bits in this value. */") + out.println(" public fun inv(): $className = $className(data.inv())") + out.println() + } + + private fun generateMemberConversions() { + for (otherType in UnsignedType.values()) { + val signed = otherType.asSigned.capitalized + out.println(" public fun to$signed(): $signed = TODO()") + } + out.println() + + for (otherType in UnsignedType.values()) { + val name = otherType.capitalized + out.println(" public fun to$name(): $name = TODO()") + } + out.println() + } + + private fun generateExtensionConversions() { + for (otherType in UnsignedType.values()) { + val otherSigned = otherType.asSigned.capitalized + val thisSigned = type.asSigned.capitalized + out.println("public fun $otherSigned.to$className(): $className = $className(this.to$thisSigned())") + } + } + + + private fun maxByDomainCapacity(type1: UnsignedType, type2: UnsignedType): UnsignedType = + if (type1.ordinal > type2.ordinal) type1 else type2 + + + private fun getOperatorReturnType(type1: UnsignedType, type2: UnsignedType): UnsignedType { + return maxByDomainCapacity(maxByDomainCapacity(type1, type2), UnsignedType.UINT) + } + +} diff --git a/libraries/stdlib/unsigned/src/kotlin/UByte.kt b/libraries/stdlib/unsigned/src/kotlin/UByte.kt new file mode 100644 index 00000000000..eddb12ccd75 --- /dev/null +++ b/libraries/stdlib/unsigned/src/kotlin/UByte.kt @@ -0,0 +1,128 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +// Auto-generated file. DO NOT EDIT! + +package kotlin + +import kotlin.experimental.* + +public inline class UByte internal constructor(private val data: Byte) : Comparable { + + companion object { + /** + * A constant holding the minimum value an instance of UByte can have. + */ + public /*const*/ val MIN_VALUE: UByte = UByte(0) + + /** + * A constant holding the maximum value an instance of UByte can have. + */ + public /*const*/ val MAX_VALUE: UByte = UByte(-1) + } + + /** + * Compares this value with the specified value for order. + * Returns zero if this value is equal to the specified other value, a negative number if it's less than other, + * or a positive number if it's greater than other. + */ + public override operator fun compareTo(other: UByte): Int = TODO() + + /** + * Compares this value with the specified value for order. + * Returns zero if this value is equal to the specified other value, a negative number if it's less than other, + * or a positive number if it's greater than other. + */ + public operator fun compareTo(other: UShort): Int = TODO() + + /** + * Compares this value with the specified value for order. + * Returns zero if this value is equal to the specified other value, a negative number if it's less than other, + * or a positive number if it's greater than other. + */ + public operator fun compareTo(other: UInt): Int = TODO() + + /** + * Compares this value with the specified value for order. + * Returns zero if this value is equal to the specified other value, a negative number if it's less than other, + * or a positive number if it's greater than other. + */ + public operator fun compareTo(other: ULong): Int = TODO() + + /** Adds the other value to this value. */ + public operator fun plus(other: UByte): UInt = TODO() + /** Adds the other value to this value. */ + public operator fun plus(other: UShort): UInt = TODO() + /** Adds the other value to this value. */ + public operator fun plus(other: UInt): UInt = TODO() + /** Adds the other value to this value. */ + public operator fun plus(other: ULong): ULong = TODO() + + /** Subtracts the other value from this value. */ + public operator fun minus(other: UByte): UInt = TODO() + /** Subtracts the other value from this value. */ + public operator fun minus(other: UShort): UInt = TODO() + /** Subtracts the other value from this value. */ + public operator fun minus(other: UInt): UInt = TODO() + /** Subtracts the other value from this value. */ + public operator fun minus(other: ULong): ULong = TODO() + + /** Multiplies this value by the other value. */ + public operator fun times(other: UByte): UInt = TODO() + /** Multiplies this value by the other value. */ + public operator fun times(other: UShort): UInt = TODO() + /** Multiplies this value by the other value. */ + public operator fun times(other: UInt): UInt = TODO() + /** Multiplies this value by the other value. */ + public operator fun times(other: ULong): ULong = TODO() + + /** Divides this value by the other value. */ + public operator fun div(other: UByte): UInt = TODO() + /** Divides this value by the other value. */ + public operator fun div(other: UShort): UInt = TODO() + /** Divides this value by the other value. */ + public operator fun div(other: UInt): UInt = TODO() + /** Divides this value by the other value. */ + public operator fun div(other: ULong): ULong = TODO() + + /** Calculates the remainder of dividing this value by the other value. */ + public operator fun rem(other: UByte): UInt = TODO() + /** Calculates the remainder of dividing this value by the other value. */ + public operator fun rem(other: UShort): UInt = TODO() + /** Calculates the remainder of dividing this value by the other value. */ + public operator fun rem(other: UInt): UInt = TODO() + /** Calculates the remainder of dividing this value by the other value. */ + public operator fun rem(other: ULong): ULong = TODO() + + /** Increments this value. */ + public operator fun inc(): UByte = TODO() + /** Decrements this value. */ + public operator fun dec(): UByte = TODO() + + /** Performs a bitwise AND operation between the two values. */ + public infix fun and(other: UByte): UByte = UByte(this.data and other.data) + /** Performs a bitwise OR operation between the two values. */ + public infix fun or(other: UByte): UByte = UByte(this.data or other.data) + /** Performs a bitwise XOR operation between the two values. */ + public infix fun xor(other: UByte): UByte = UByte(this.data xor other.data) + /** Inverts the bits in this value. */ + public fun inv(): UByte = UByte(data.inv()) + + public fun toByte(): Byte = TODO() + public fun toShort(): Short = TODO() + public fun toInt(): Int = TODO() + public fun toLong(): Long = TODO() + + public fun toUByte(): UByte = TODO() + public fun toUShort(): UShort = TODO() + public fun toUInt(): UInt = TODO() + public fun toULong(): ULong = TODO() + +} + +public fun Byte.toUByte(): UByte = UByte(this.toByte()) +public fun Short.toUByte(): UByte = UByte(this.toByte()) +public fun Int.toUByte(): UByte = UByte(this.toByte()) +public fun Long.toUByte(): UByte = UByte(this.toByte()) diff --git a/libraries/stdlib/unsigned/src/kotlin/UInt.kt b/libraries/stdlib/unsigned/src/kotlin/UInt.kt new file mode 100644 index 00000000000..ef11e5c55ca --- /dev/null +++ b/libraries/stdlib/unsigned/src/kotlin/UInt.kt @@ -0,0 +1,132 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +// Auto-generated file. DO NOT EDIT! + +package kotlin + +import kotlin.experimental.* + +public inline class UInt internal constructor(private val data: Int) : Comparable { + + companion object { + /** + * A constant holding the minimum value an instance of UInt can have. + */ + public /*const*/ val MIN_VALUE: UInt = UInt(0) + + /** + * A constant holding the maximum value an instance of UInt can have. + */ + public /*const*/ val MAX_VALUE: UInt = UInt(-1) + } + + /** + * Compares this value with the specified value for order. + * Returns zero if this value is equal to the specified other value, a negative number if it's less than other, + * or a positive number if it's greater than other. + */ + public operator fun compareTo(other: UByte): Int = TODO() + + /** + * Compares this value with the specified value for order. + * Returns zero if this value is equal to the specified other value, a negative number if it's less than other, + * or a positive number if it's greater than other. + */ + public operator fun compareTo(other: UShort): Int = TODO() + + /** + * Compares this value with the specified value for order. + * Returns zero if this value is equal to the specified other value, a negative number if it's less than other, + * or a positive number if it's greater than other. + */ + public override operator fun compareTo(other: UInt): Int = TODO() + + /** + * Compares this value with the specified value for order. + * Returns zero if this value is equal to the specified other value, a negative number if it's less than other, + * or a positive number if it's greater than other. + */ + public operator fun compareTo(other: ULong): Int = TODO() + + /** Adds the other value to this value. */ + public operator fun plus(other: UByte): UInt = TODO() + /** Adds the other value to this value. */ + public operator fun plus(other: UShort): UInt = TODO() + /** Adds the other value to this value. */ + public operator fun plus(other: UInt): UInt = TODO() + /** Adds the other value to this value. */ + public operator fun plus(other: ULong): ULong = TODO() + + /** Subtracts the other value from this value. */ + public operator fun minus(other: UByte): UInt = TODO() + /** Subtracts the other value from this value. */ + public operator fun minus(other: UShort): UInt = TODO() + /** Subtracts the other value from this value. */ + public operator fun minus(other: UInt): UInt = TODO() + /** Subtracts the other value from this value. */ + public operator fun minus(other: ULong): ULong = TODO() + + /** Multiplies this value by the other value. */ + public operator fun times(other: UByte): UInt = TODO() + /** Multiplies this value by the other value. */ + public operator fun times(other: UShort): UInt = TODO() + /** Multiplies this value by the other value. */ + public operator fun times(other: UInt): UInt = TODO() + /** Multiplies this value by the other value. */ + public operator fun times(other: ULong): ULong = TODO() + + /** Divides this value by the other value. */ + public operator fun div(other: UByte): UInt = TODO() + /** Divides this value by the other value. */ + public operator fun div(other: UShort): UInt = TODO() + /** Divides this value by the other value. */ + public operator fun div(other: UInt): UInt = TODO() + /** Divides this value by the other value. */ + public operator fun div(other: ULong): ULong = TODO() + + /** Calculates the remainder of dividing this value by the other value. */ + public operator fun rem(other: UByte): UInt = TODO() + /** Calculates the remainder of dividing this value by the other value. */ + public operator fun rem(other: UShort): UInt = TODO() + /** Calculates the remainder of dividing this value by the other value. */ + public operator fun rem(other: UInt): UInt = TODO() + /** Calculates the remainder of dividing this value by the other value. */ + public operator fun rem(other: ULong): ULong = TODO() + + /** Increments this value. */ + public operator fun inc(): UInt = TODO() + /** Decrements this value. */ + public operator fun dec(): UInt = TODO() + + /** Shifts this value left by the [bitCount] number of bits. */ + public infix fun shl(bitCount: Int): UInt = UInt(data shl bitCount) + /** Shifts this value right by the [bitCount] number of bits, filling the leftmost bits with zeros. */ + public infix fun shr(bitCount: Int): UInt = UInt(data ushr bitCount) + /** Performs a bitwise AND operation between the two values. */ + public infix fun and(other: UInt): UInt = UInt(this.data and other.data) + /** Performs a bitwise OR operation between the two values. */ + public infix fun or(other: UInt): UInt = UInt(this.data or other.data) + /** Performs a bitwise XOR operation between the two values. */ + public infix fun xor(other: UInt): UInt = UInt(this.data xor other.data) + /** Inverts the bits in this value. */ + public fun inv(): UInt = UInt(data.inv()) + + public fun toByte(): Byte = TODO() + public fun toShort(): Short = TODO() + public fun toInt(): Int = TODO() + public fun toLong(): Long = TODO() + + public fun toUByte(): UByte = TODO() + public fun toUShort(): UShort = TODO() + public fun toUInt(): UInt = TODO() + public fun toULong(): ULong = TODO() + +} + +public fun Byte.toUInt(): UInt = UInt(this.toInt()) +public fun Short.toUInt(): UInt = UInt(this.toInt()) +public fun Int.toUInt(): UInt = UInt(this.toInt()) +public fun Long.toUInt(): UInt = UInt(this.toInt()) diff --git a/libraries/stdlib/unsigned/src/kotlin/ULong.kt b/libraries/stdlib/unsigned/src/kotlin/ULong.kt new file mode 100644 index 00000000000..aeb8d472bdc --- /dev/null +++ b/libraries/stdlib/unsigned/src/kotlin/ULong.kt @@ -0,0 +1,132 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +// Auto-generated file. DO NOT EDIT! + +package kotlin + +import kotlin.experimental.* + +public inline class ULong internal constructor(private val data: Long) : Comparable { + + companion object { + /** + * A constant holding the minimum value an instance of ULong can have. + */ + public /*const*/ val MIN_VALUE: ULong = ULong(0) + + /** + * A constant holding the maximum value an instance of ULong can have. + */ + public /*const*/ val MAX_VALUE: ULong = ULong(-1) + } + + /** + * Compares this value with the specified value for order. + * Returns zero if this value is equal to the specified other value, a negative number if it's less than other, + * or a positive number if it's greater than other. + */ + public operator fun compareTo(other: UByte): Int = TODO() + + /** + * Compares this value with the specified value for order. + * Returns zero if this value is equal to the specified other value, a negative number if it's less than other, + * or a positive number if it's greater than other. + */ + public operator fun compareTo(other: UShort): Int = TODO() + + /** + * Compares this value with the specified value for order. + * Returns zero if this value is equal to the specified other value, a negative number if it's less than other, + * or a positive number if it's greater than other. + */ + public operator fun compareTo(other: UInt): Int = TODO() + + /** + * Compares this value with the specified value for order. + * Returns zero if this value is equal to the specified other value, a negative number if it's less than other, + * or a positive number if it's greater than other. + */ + public override operator fun compareTo(other: ULong): Int = TODO() + + /** Adds the other value to this value. */ + public operator fun plus(other: UByte): ULong = TODO() + /** Adds the other value to this value. */ + public operator fun plus(other: UShort): ULong = TODO() + /** Adds the other value to this value. */ + public operator fun plus(other: UInt): ULong = TODO() + /** Adds the other value to this value. */ + public operator fun plus(other: ULong): ULong = TODO() + + /** Subtracts the other value from this value. */ + public operator fun minus(other: UByte): ULong = TODO() + /** Subtracts the other value from this value. */ + public operator fun minus(other: UShort): ULong = TODO() + /** Subtracts the other value from this value. */ + public operator fun minus(other: UInt): ULong = TODO() + /** Subtracts the other value from this value. */ + public operator fun minus(other: ULong): ULong = TODO() + + /** Multiplies this value by the other value. */ + public operator fun times(other: UByte): ULong = TODO() + /** Multiplies this value by the other value. */ + public operator fun times(other: UShort): ULong = TODO() + /** Multiplies this value by the other value. */ + public operator fun times(other: UInt): ULong = TODO() + /** Multiplies this value by the other value. */ + public operator fun times(other: ULong): ULong = TODO() + + /** Divides this value by the other value. */ + public operator fun div(other: UByte): ULong = TODO() + /** Divides this value by the other value. */ + public operator fun div(other: UShort): ULong = TODO() + /** Divides this value by the other value. */ + public operator fun div(other: UInt): ULong = TODO() + /** Divides this value by the other value. */ + public operator fun div(other: ULong): ULong = TODO() + + /** Calculates the remainder of dividing this value by the other value. */ + public operator fun rem(other: UByte): ULong = TODO() + /** Calculates the remainder of dividing this value by the other value. */ + public operator fun rem(other: UShort): ULong = TODO() + /** Calculates the remainder of dividing this value by the other value. */ + public operator fun rem(other: UInt): ULong = TODO() + /** Calculates the remainder of dividing this value by the other value. */ + public operator fun rem(other: ULong): ULong = TODO() + + /** Increments this value. */ + public operator fun inc(): ULong = TODO() + /** Decrements this value. */ + public operator fun dec(): ULong = TODO() + + /** Shifts this value left by the [bitCount] number of bits. */ + public infix fun shl(bitCount: Int): ULong = ULong(data shl bitCount) + /** Shifts this value right by the [bitCount] number of bits, filling the leftmost bits with zeros. */ + public infix fun shr(bitCount: Int): ULong = ULong(data ushr bitCount) + /** Performs a bitwise AND operation between the two values. */ + public infix fun and(other: ULong): ULong = ULong(this.data and other.data) + /** Performs a bitwise OR operation between the two values. */ + public infix fun or(other: ULong): ULong = ULong(this.data or other.data) + /** Performs a bitwise XOR operation between the two values. */ + public infix fun xor(other: ULong): ULong = ULong(this.data xor other.data) + /** Inverts the bits in this value. */ + public fun inv(): ULong = ULong(data.inv()) + + public fun toByte(): Byte = TODO() + public fun toShort(): Short = TODO() + public fun toInt(): Int = TODO() + public fun toLong(): Long = TODO() + + public fun toUByte(): UByte = TODO() + public fun toUShort(): UShort = TODO() + public fun toUInt(): UInt = TODO() + public fun toULong(): ULong = TODO() + +} + +public fun Byte.toULong(): ULong = ULong(this.toLong()) +public fun Short.toULong(): ULong = ULong(this.toLong()) +public fun Int.toULong(): ULong = ULong(this.toLong()) +public fun Long.toULong(): ULong = ULong(this.toLong()) diff --git a/libraries/stdlib/unsigned/src/kotlin/UShort.kt b/libraries/stdlib/unsigned/src/kotlin/UShort.kt new file mode 100644 index 00000000000..4c19cf0188c --- /dev/null +++ b/libraries/stdlib/unsigned/src/kotlin/UShort.kt @@ -0,0 +1,128 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +// Auto-generated file. DO NOT EDIT! + +package kotlin + +import kotlin.experimental.* + +public inline class UShort internal constructor(private val data: Short) : Comparable { + + companion object { + /** + * A constant holding the minimum value an instance of UShort can have. + */ + public /*const*/ val MIN_VALUE: UShort = UShort(0) + + /** + * A constant holding the maximum value an instance of UShort can have. + */ + public /*const*/ val MAX_VALUE: UShort = UShort(-1) + } + + /** + * Compares this value with the specified value for order. + * Returns zero if this value is equal to the specified other value, a negative number if it's less than other, + * or a positive number if it's greater than other. + */ + public operator fun compareTo(other: UByte): Int = TODO() + + /** + * Compares this value with the specified value for order. + * Returns zero if this value is equal to the specified other value, a negative number if it's less than other, + * or a positive number if it's greater than other. + */ + public override operator fun compareTo(other: UShort): Int = TODO() + + /** + * Compares this value with the specified value for order. + * Returns zero if this value is equal to the specified other value, a negative number if it's less than other, + * or a positive number if it's greater than other. + */ + public operator fun compareTo(other: UInt): Int = TODO() + + /** + * Compares this value with the specified value for order. + * Returns zero if this value is equal to the specified other value, a negative number if it's less than other, + * or a positive number if it's greater than other. + */ + public operator fun compareTo(other: ULong): Int = TODO() + + /** Adds the other value to this value. */ + public operator fun plus(other: UByte): UInt = TODO() + /** Adds the other value to this value. */ + public operator fun plus(other: UShort): UInt = TODO() + /** Adds the other value to this value. */ + public operator fun plus(other: UInt): UInt = TODO() + /** Adds the other value to this value. */ + public operator fun plus(other: ULong): ULong = TODO() + + /** Subtracts the other value from this value. */ + public operator fun minus(other: UByte): UInt = TODO() + /** Subtracts the other value from this value. */ + public operator fun minus(other: UShort): UInt = TODO() + /** Subtracts the other value from this value. */ + public operator fun minus(other: UInt): UInt = TODO() + /** Subtracts the other value from this value. */ + public operator fun minus(other: ULong): ULong = TODO() + + /** Multiplies this value by the other value. */ + public operator fun times(other: UByte): UInt = TODO() + /** Multiplies this value by the other value. */ + public operator fun times(other: UShort): UInt = TODO() + /** Multiplies this value by the other value. */ + public operator fun times(other: UInt): UInt = TODO() + /** Multiplies this value by the other value. */ + public operator fun times(other: ULong): ULong = TODO() + + /** Divides this value by the other value. */ + public operator fun div(other: UByte): UInt = TODO() + /** Divides this value by the other value. */ + public operator fun div(other: UShort): UInt = TODO() + /** Divides this value by the other value. */ + public operator fun div(other: UInt): UInt = TODO() + /** Divides this value by the other value. */ + public operator fun div(other: ULong): ULong = TODO() + + /** Calculates the remainder of dividing this value by the other value. */ + public operator fun rem(other: UByte): UInt = TODO() + /** Calculates the remainder of dividing this value by the other value. */ + public operator fun rem(other: UShort): UInt = TODO() + /** Calculates the remainder of dividing this value by the other value. */ + public operator fun rem(other: UInt): UInt = TODO() + /** Calculates the remainder of dividing this value by the other value. */ + public operator fun rem(other: ULong): ULong = TODO() + + /** Increments this value. */ + public operator fun inc(): UShort = TODO() + /** Decrements this value. */ + public operator fun dec(): UShort = TODO() + + /** Performs a bitwise AND operation between the two values. */ + public infix fun and(other: UShort): UShort = UShort(this.data and other.data) + /** Performs a bitwise OR operation between the two values. */ + public infix fun or(other: UShort): UShort = UShort(this.data or other.data) + /** Performs a bitwise XOR operation between the two values. */ + public infix fun xor(other: UShort): UShort = UShort(this.data xor other.data) + /** Inverts the bits in this value. */ + public fun inv(): UShort = UShort(data.inv()) + + public fun toByte(): Byte = TODO() + public fun toShort(): Short = TODO() + public fun toInt(): Int = TODO() + public fun toLong(): Long = TODO() + + public fun toUByte(): UByte = TODO() + public fun toUShort(): UShort = TODO() + public fun toUInt(): UInt = TODO() + public fun toULong(): ULong = TODO() + +} + +public fun Byte.toUShort(): UShort = UShort(this.toShort()) +public fun Short.toUShort(): UShort = UShort(this.toShort()) +public fun Int.toUShort(): UShort = UShort(this.toShort()) +public fun Long.toUShort(): UShort = UShort(this.toShort())