Skip to content

Commit eea0754

Browse files
committed
3.4.0
1 parent cb0c04c commit eea0754

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+5452
-1652
lines changed

.idea/gradle.xml

Lines changed: 12 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/kotlinc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.kotlintest/spec_failures

Whitespace-only changes.

.travis.yml

Lines changed: 0 additions & 3 deletions
This file was deleted.

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,16 @@ To have a quick idea what this library offers, take a look at the [tests](https:
1717

1818
### Differences with kotlin stdlib:
1919

20-
- this project uses classes instead inline classes. To address this in critical scenarios where allocations may have a sensitive impact, primitive variable holding the utype value is a `var`, so you can re-use the same istance over and over again
21-
- utypes extend `Number` abstract class
20+
- this project uses classes instead inline classes. To address this in critical scenarios where allocations may have a sensitive impact, primitive variable holding the unsigned
21+
type value is a `var`, so you can re-use the same instance over and over again
22+
- unsigned types extend `Number` abstract class
2223
- automatic conversions
2324
- it is possible to string format by calling the corresponding `format()` method, eg: `ubyte.format("%08x")`
24-
- all the utypes implement all the function, including `shl` and `shr` for `Ubyte` and `Ushort`
25-
- if you add an `Ushort` to another `Ushort` you get an `Ushort` (and not an `Uint`)
25+
- all the unsigned types implement all the function, including `shl` and `shr` for `Ubyte` and `Ushort`
26+
- there is no automatic padding to integer for unsigned bytes and shorts, so if you add an `Ushort` to another `Ushort` you get an `Ushort` (and not an `Uint`)
2627

2728
### Install:
2829

29-
With Gradle `kx.util` plugin, everything is nicely aligned and the boilerplate code is gone
30-
3130
#### mary
3231
```kotlin
3332
repositories {

build.gradle.kts

Lines changed: 53 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,75 @@
11
import magik.createGithubPublication
22
import magik.github
33
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile
4+
import uns.gen.GenerateCode
45
import java.util.*
56

67
plugins {
7-
kotlin("jvm") version embeddedKotlinVersion
8+
kotlin("multiplatform") version embeddedKotlinVersion
89
id("elect86.magik") version "0.3.3"
910
`maven-publish`
1011
signing
1112
`jvm-test-suite`
12-
// id("com.github.johnrengelman.shadow") version "8.1.1"
13+
// id("com.github.johnrengelman.shadow") version "8.1.1"
1314
}
1415

1516
repositories { mavenCentral() }
1617

17-
dependencies {
18-
testImplementation("io.kotest:kotest-runner-junit5:5.7.1")
19-
testImplementation("io.kotest:kotest-assertions-core:5.7.1")
18+
kotlin {
19+
jvm {
20+
jvmToolchain(11)
21+
withJava()
22+
}
23+
val hostOs = System.getProperty("os.name")
24+
val isArm64 = System.getProperty("os.arch") == "aarch64"
25+
val isMingwX64 = hostOs.startsWith("Windows")
26+
val nativeTarget = when {
27+
hostOs == "Mac OS X" && isArm64 -> macosArm64("native")
28+
hostOs == "Mac OS X" && !isArm64 -> macosX64("native")
29+
hostOs == "Linux" && isArm64 -> linuxArm64("native")
30+
hostOs == "Linux" && !isArm64 -> linuxX64("native")
31+
isMingwX64 -> mingwX64("native")
32+
else -> throw GradleException("Host OS is not supported in Kotlin/Native.")
33+
}
34+
sourceSets {
35+
val commonMain by getting {
36+
dependencies {
37+
implementation("com.ionspin.kotlin:bignum:0.3.8")
38+
}
39+
}
40+
val commonTest by getting {
41+
dependencies {
42+
implementation(kotlin("test"))
43+
}
44+
}
45+
val jvmMain by getting
46+
val jvmTest by getting
47+
// val jsMain by getting
48+
// val jsTest by getting
49+
val nativeMain by getting
50+
val nativeTest by getting
51+
}
2052
}
2153

22-
kotlin.jvmToolchain { languageVersion.set(JavaLanguageVersion.of(11)) }
23-
2454
tasks {
55+
val generateCode by registering(GenerateCode::class)
56+
kotlin.sourceSets.commonMain { kotlin.srcDir(generateCode) }
2557
withType<KotlinCompile<*>>().all { kotlinOptions { freeCompilerArgs += listOf("-opt-in=kotlin.RequiresOptIn") } }
2658
}
2759

2860
testing.suites {
2961
val test by getting(JvmTestSuite::class) { useJUnitJupiter() }
3062
}
3163

32-
java {
33-
withJavadocJar()
34-
withSourcesJar()
35-
}
64+
//java {
65+
// withJavadocJar()
66+
// withSourcesJar()
67+
//}
3668

3769

3870
configure<PublishingExtension> {
3971
publications {
40-
createGithubPublication("Github") {
72+
createGithubPublication {
4173
from(components["java"])
4274
suppressAllPomMetadataWarnings()
4375
}
@@ -50,31 +82,18 @@ configure<PublishingExtension> {
5082
usage("java-runtime") { fromResolutionResult() }
5183
}
5284
pom {
53-
name.set("kotlin-unsigned")
54-
description.set("unsigned support for Kotlin via boxed types and unsigned operators")
55-
url.set("https://github.com/kotlin-graphics/kotlin-unsigned")
56-
licenses {
57-
license {
58-
name.set("MIT")
59-
url.set("https://choosealicense.com/licenses/mit/")
60-
}
61-
}
85+
name = "kotlin-unsigned"
86+
description = "unsigned support for Kotlin via boxed types and unsigned operators"
87+
url = "https://github.com/kotlin-graphics/kotlin-unsigned"
88+
licenses { license { name = "MIT"; url = "https://choosealicense.com/licenses/mit/" } }
6289
developers {
63-
developer {
64-
id.set("elect86")
65-
name.set("Giuseppe Barbieri")
66-
email.set("[email protected]")
67-
}
68-
developer {
69-
id.set("bixilon")
70-
name.set("Moritz Zwerger")
71-
email.set("[email protected]")
72-
}
90+
developer { id = "elect86"; name = "Giuseppe Barbieri"; email = "[email protected]" }
91+
developer { id = "bixilon"; name = "Moritz Zwerger"; email = "[email protected]" }
7392
}
7493
scm {
75-
connection.set("scm:git:https://github.com/kotlin-graphics/kotlin-unsigned.git")
76-
developerConnection.set("scm:git:ssh://[email protected]:kotlin-graphics/kotlin-unsigned.git")
77-
url.set("https://github.com/kotlin-graphics/kotlin-unsigned")
94+
connection = "scm:git:https://github.com/kotlin-graphics/kotlin-unsigned.git"
95+
developerConnection = "scm:git:ssh://[email protected]:kotlin-graphics/kotlin-unsigned.git"
96+
url = "https://github.com/kotlin-graphics/kotlin-unsigned"
7897
}
7998
}
8099
}

buildSrc/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
`kotlin-dsl`
3+
}
4+
5+
repositories {
6+
gradlePluginPortal()
7+
}

buildSrc/settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = "buildSrc"
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package uns
2+
3+
import uns.gen.Generator
4+
import uns.gen.generate
5+
6+
fun arrays() {
7+
generate("arrays") {
8+
imports += "kotlin.jvm.JvmInline"
9+
imports += "kotlin.jvm.JvmName"
10+
imports += "kotlin.experimental.ExperimentalTypeInference"
11+
experimentals += Generator.Experimentals.UnsignedTypes
12+
experimentals += Generator.Experimentals.TypeInference
13+
for (info in unsInfos) {
14+
val Type = info.type
15+
val TypeArray = Type + "Array"
16+
val CounterArray = info.counterType + "Array"
17+
val CounterType = info.counterType
18+
+"""
19+
@JvmInline
20+
value class $TypeArray(val data: $CounterArray) {
21+
22+
operator fun get(index: I32): $Type = $Type(data[index])
23+
24+
operator fun set(index: I32, value: $Type) { data[index] = value.v }
25+
26+
val indices: IntRange
27+
get() = data.indices
28+
}
29+
30+
fun $TypeArray(size: I32): $TypeArray = $TypeArray($CounterArray(size))
31+
@OverloadResolutionByLambdaReturnType
32+
@JvmName("$TypeArray$CounterType")
33+
inline fun $TypeArray(size: I32, init: (I32) -> $CounterType): $TypeArray = $TypeArray($CounterArray(size, init))
34+
@OverloadResolutionByLambdaReturnType
35+
@JvmName("$TypeArray$Type")
36+
inline fun $TypeArray(size: I32, init: (I32) -> $Type): $TypeArray {
37+
val array = $TypeArray($CounterArray(size))
38+
for (i in array.indices)
39+
array[i] = init(i)
40+
return array
41+
}"""
42+
if (info.bits != 32)
43+
+"""
44+
@OverloadResolutionByLambdaReturnType
45+
@JvmName("${TypeArray}I32")
46+
inline fun $TypeArray(size: I32, init: (I32) -> I32): $TypeArray {
47+
val array = $TypeArray($CounterArray(size))
48+
for (i in array.indices)
49+
array.data[i] = init(i).to$CounterType()
50+
return array
51+
}
52+
@OverloadResolutionByLambdaReturnType
53+
@JvmName("${TypeArray}U32")
54+
inline fun $TypeArray(size: I32, init: (I32) -> U32): $TypeArray {
55+
val array = $TypeArray($CounterArray(size))
56+
for (i in array.indices)
57+
array.data[i] = init(i).to$CounterType()
58+
return array
59+
}"""
60+
}
61+
}
62+
}
63+

0 commit comments

Comments
 (0)