Skip to content

Commit

Permalink
WIP: partial implementation of bignums, pushed for multi-dev debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
ianbotsf committed Dec 17, 2024
1 parent 523dba9 commit 66c7e83
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 26 deletions.
3 changes: 2 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ kotlin.code.style=official
kotlin.incremental.js=true
kotlin.incremental.multiplatform=true
kotlin.mpp.stability.nowarn=true
kotlin.native.binary.sourceInfoType=libbacktrace
kotlin.native.ignoreDisabledTargets=true

# atomicfu
Expand All @@ -16,4 +17,4 @@ org.gradle.jvmargs=-Xmx2G -XX:MaxMetaspaceSize=1G
sdkVersion=1.3.30-SNAPSHOT

# codegen
codegenVersion=0.33.30-SNAPSHOT
codegenVersion=0.33.30-SNAPSHOT
3 changes: 3 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ slf4j-version = "2.0.16"
slf4j-v1x-version = "1.7.36"
crt-kotlin-version = "0.8.10"
micrometer-version = "1.13.6"
kotlin-multiplatform-bignum-version = "0.3.10"

# codegen
smithy-version = "1.51.0"
Expand Down Expand Up @@ -101,6 +102,8 @@ ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor-ve
kaml = { module = "com.charleskorn.kaml:kaml", version.ref = "kaml-version" }
jsoup = { module = "org.jsoup:jsoup", version.ref = "jsoup-version" }

kotlin-multiplatform-bignum = { module = "com.ionspin.kotlin:bignum", version.ref = "kotlin-multiplatform-bignum-version" }

[plugins]
dokka = { id = "org.jetbrains.dokka", version.ref = "dokka-version"}
kotlin-jvm = {id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin-version" }
Expand Down
8 changes: 8 additions & 0 deletions runtime/runtime-core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.gradle.api.tasks.testing.logging.TestExceptionFormat

/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
Expand Down Expand Up @@ -43,6 +45,12 @@ kotlin {
}
}

nativeMain {
dependencies {
implementation(libs.kotlin.multiplatform.bignum)
}
}

all {
languageSettings.optIn("aws.smithy.kotlin.runtime.InternalApi")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class BigIntegerTest {
"0x123456789abcdef0" to "1311768467463790320",
"0x00ffffffffffffffffffffffffffffffec" to "340282366920938463463374607431768211436",
"0x81445edf51ddc07216da5621c727bfd379d400f3da08018d45749a" to "-52134902384590238490284023839028330923830129830129301234239834982",

)

tests.forEach { (hex, expected) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,38 @@
*/
package aws.smithy.kotlin.runtime.content

public actual class BigInteger actual constructor(value: String) :
import com.ionspin.kotlin.bignum.integer.util.fromTwosComplementByteArray
import com.ionspin.kotlin.bignum.integer.util.toTwosComplementByteArray
import com.ionspin.kotlin.bignum.integer.BigInteger as IonSpinBigInteger

public actual class BigInteger private constructor(private val delegate: IonSpinBigInteger) :
Number(),
Comparable<BigInteger> {
public actual constructor(bytes: ByteArray) : this("Not yet implemented")

actual override fun toByte(): Byte {
TODO("Not yet implemented")
private companion object {
fun coalesceOrCreate(value: IonSpinBigInteger, left: BigInteger, right: BigInteger): BigInteger = when (value) {
left.delegate -> left
right.delegate -> right
else -> BigInteger(value)
}
}

actual override fun toDouble(): Double {
TODO("Not yet implemented")
}
public actual constructor(value: String) : this(IonSpinBigInteger.parseString(value, 10))
public actual constructor(bytes: ByteArray) : this(IonSpinBigInteger.fromTwosComplementByteArray(bytes))

actual override fun toFloat(): Float {
TODO("Not yet implemented")
}
actual override fun toByte(): Byte = delegate.byteValue(exactRequired = false)
actual override fun toDouble(): Double = delegate.doubleValue(exactRequired = false)
actual override fun toFloat(): Float = delegate.floatValue(exactRequired = false)
actual override fun toInt(): Int = delegate.intValue(exactRequired = false)
actual override fun toLong(): Long = delegate.longValue(exactRequired = false)
actual override fun toShort(): Short = delegate.shortValue(exactRequired = false)

actual override fun toInt(): Int {
TODO("Not yet implemented")
}
public actual operator fun plus(other: BigInteger): BigInteger =
coalesceOrCreate(delegate + other.delegate, this, other)

actual override fun toLong(): Long {
TODO("Not yet implemented")
}

actual override fun toShort(): Short {
TODO("Not yet implemented")
}
public actual operator fun minus(other: BigInteger): BigInteger =
coalesceOrCreate(delegate - other.delegate, this, other)

public actual operator fun plus(other: BigInteger): BigInteger = TODO("Not yet implemented")
public actual operator fun minus(other: BigInteger): BigInteger = TODO("Not yet implemented")
public actual fun toByteArray(): ByteArray = TODO("Not yet implemented")
actual override fun compareTo(other: BigInteger): Int = TODO("Not yet implemented")
public actual fun toByteArray(): ByteArray = delegate.toTwosComplementByteArray()
actual override fun compareTo(other: BigInteger): Int = delegate.compare(other.delegate)
}

0 comments on commit 66c7e83

Please sign in to comment.