-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
63 changed files
with
5,452 additions
and
1,652 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,75 @@ | ||
import magik.createGithubPublication | ||
import magik.github | ||
import org.jetbrains.kotlin.gradle.dsl.KotlinCompile | ||
import uns.gen.GenerateCode | ||
import java.util.* | ||
|
||
plugins { | ||
kotlin("jvm") version embeddedKotlinVersion | ||
kotlin("multiplatform") version embeddedKotlinVersion | ||
id("elect86.magik") version "0.3.3" | ||
`maven-publish` | ||
signing | ||
`jvm-test-suite` | ||
// id("com.github.johnrengelman.shadow") version "8.1.1" | ||
// id("com.github.johnrengelman.shadow") version "8.1.1" | ||
} | ||
|
||
repositories { mavenCentral() } | ||
|
||
dependencies { | ||
testImplementation("io.kotest:kotest-runner-junit5:5.7.1") | ||
testImplementation("io.kotest:kotest-assertions-core:5.7.1") | ||
kotlin { | ||
jvm { | ||
jvmToolchain(11) | ||
withJava() | ||
} | ||
val hostOs = System.getProperty("os.name") | ||
val isArm64 = System.getProperty("os.arch") == "aarch64" | ||
val isMingwX64 = hostOs.startsWith("Windows") | ||
val nativeTarget = when { | ||
hostOs == "Mac OS X" && isArm64 -> macosArm64("native") | ||
hostOs == "Mac OS X" && !isArm64 -> macosX64("native") | ||
hostOs == "Linux" && isArm64 -> linuxArm64("native") | ||
hostOs == "Linux" && !isArm64 -> linuxX64("native") | ||
isMingwX64 -> mingwX64("native") | ||
else -> throw GradleException("Host OS is not supported in Kotlin/Native.") | ||
} | ||
sourceSets { | ||
val commonMain by getting { | ||
dependencies { | ||
implementation("com.ionspin.kotlin:bignum:0.3.8") | ||
} | ||
} | ||
val commonTest by getting { | ||
dependencies { | ||
implementation(kotlin("test")) | ||
} | ||
} | ||
val jvmMain by getting | ||
val jvmTest by getting | ||
// val jsMain by getting | ||
// val jsTest by getting | ||
val nativeMain by getting | ||
val nativeTest by getting | ||
} | ||
} | ||
|
||
kotlin.jvmToolchain { languageVersion.set(JavaLanguageVersion.of(11)) } | ||
|
||
tasks { | ||
val generateCode by registering(GenerateCode::class) | ||
kotlin.sourceSets.commonMain { kotlin.srcDir(generateCode) } | ||
withType<KotlinCompile<*>>().all { kotlinOptions { freeCompilerArgs += listOf("-opt-in=kotlin.RequiresOptIn") } } | ||
} | ||
|
||
testing.suites { | ||
val test by getting(JvmTestSuite::class) { useJUnitJupiter() } | ||
} | ||
|
||
java { | ||
withJavadocJar() | ||
withSourcesJar() | ||
} | ||
//java { | ||
// withJavadocJar() | ||
// withSourcesJar() | ||
//} | ||
|
||
|
||
configure<PublishingExtension> { | ||
publications { | ||
createGithubPublication("Github") { | ||
createGithubPublication { | ||
from(components["java"]) | ||
suppressAllPomMetadataWarnings() | ||
} | ||
|
@@ -50,31 +82,18 @@ configure<PublishingExtension> { | |
usage("java-runtime") { fromResolutionResult() } | ||
} | ||
pom { | ||
name.set("kotlin-unsigned") | ||
description.set("unsigned support for Kotlin via boxed types and unsigned operators") | ||
url.set("https://github.com/kotlin-graphics/kotlin-unsigned") | ||
licenses { | ||
license { | ||
name.set("MIT") | ||
url.set("https://choosealicense.com/licenses/mit/") | ||
} | ||
} | ||
name = "kotlin-unsigned" | ||
description = "unsigned support for Kotlin via boxed types and unsigned operators" | ||
url = "https://github.com/kotlin-graphics/kotlin-unsigned" | ||
licenses { license { name = "MIT"; url = "https://choosealicense.com/licenses/mit/" } } | ||
developers { | ||
developer { | ||
id.set("elect86") | ||
name.set("Giuseppe Barbieri") | ||
email.set("[email protected]") | ||
} | ||
developer { | ||
id.set("bixilon") | ||
name.set("Moritz Zwerger") | ||
email.set("[email protected]") | ||
} | ||
developer { id = "elect86"; name = "Giuseppe Barbieri"; email = "[email protected]" } | ||
developer { id = "bixilon"; name = "Moritz Zwerger"; email = "[email protected]" } | ||
} | ||
scm { | ||
connection.set("scm:git:https://github.com/kotlin-graphics/kotlin-unsigned.git") | ||
developerConnection.set("scm:git:ssh://[email protected]:kotlin-graphics/kotlin-unsigned.git") | ||
url.set("https://github.com/kotlin-graphics/kotlin-unsigned") | ||
connection = "scm:git:https://github.com/kotlin-graphics/kotlin-unsigned.git" | ||
developerConnection = "scm:git:ssh://[email protected]:kotlin-graphics/kotlin-unsigned.git" | ||
url = "https://github.com/kotlin-graphics/kotlin-unsigned" | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
plugins { | ||
`kotlin-dsl` | ||
} | ||
|
||
repositories { | ||
gradlePluginPortal() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rootProject.name = "buildSrc" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package uns | ||
|
||
import uns.gen.Generator | ||
import uns.gen.generate | ||
|
||
fun arrays() { | ||
generate("arrays") { | ||
imports += "kotlin.jvm.JvmInline" | ||
imports += "kotlin.jvm.JvmName" | ||
imports += "kotlin.experimental.ExperimentalTypeInference" | ||
experimentals += Generator.Experimentals.UnsignedTypes | ||
experimentals += Generator.Experimentals.TypeInference | ||
for (info in unsInfos) { | ||
val Type = info.type | ||
val TypeArray = Type + "Array" | ||
val CounterArray = info.counterType + "Array" | ||
val CounterType = info.counterType | ||
+""" | ||
@JvmInline | ||
value class $TypeArray(val data: $CounterArray) { | ||
operator fun get(index: I32): $Type = $Type(data[index]) | ||
operator fun set(index: I32, value: $Type) { data[index] = value.v } | ||
val indices: IntRange | ||
get() = data.indices | ||
} | ||
fun $TypeArray(size: I32): $TypeArray = $TypeArray($CounterArray(size)) | ||
@OverloadResolutionByLambdaReturnType | ||
@JvmName("$TypeArray$CounterType") | ||
inline fun $TypeArray(size: I32, init: (I32) -> $CounterType): $TypeArray = $TypeArray($CounterArray(size, init)) | ||
@OverloadResolutionByLambdaReturnType | ||
@JvmName("$TypeArray$Type") | ||
inline fun $TypeArray(size: I32, init: (I32) -> $Type): $TypeArray { | ||
val array = $TypeArray($CounterArray(size)) | ||
for (i in array.indices) | ||
array[i] = init(i) | ||
return array | ||
}""" | ||
if (info.bits != 32) | ||
+""" | ||
@OverloadResolutionByLambdaReturnType | ||
@JvmName("${TypeArray}I32") | ||
inline fun $TypeArray(size: I32, init: (I32) -> I32): $TypeArray { | ||
val array = $TypeArray($CounterArray(size)) | ||
for (i in array.indices) | ||
array.data[i] = init(i).to$CounterType() | ||
return array | ||
} | ||
@OverloadResolutionByLambdaReturnType | ||
@JvmName("${TypeArray}U32") | ||
inline fun $TypeArray(size: I32, init: (I32) -> U32): $TypeArray { | ||
val array = $TypeArray($CounterArray(size)) | ||
for (i in array.indices) | ||
array.data[i] = init(i).to$CounterType() | ||
return array | ||
}""" | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package uns | ||
|
||
import org.gradle.configurationcache.extensions.capitalized | ||
import uns.gen.generate | ||
|
||
fun extensions() { | ||
|
||
generate("extensions") { | ||
|
||
imports += "com.ionspin.kotlin.bignum.integer.toBigInteger" | ||
|
||
for (receiver in intTypeInfos + kotlinUnsTypeInfo) { | ||
val ReceiverType = receiver.type | ||
for (extInfo in intTypeInfos + kotlinUnsTypeInfo + floatingTypes) { | ||
val ext = extInfo.extension | ||
val extType = extInfo.type | ||
val ExtType = when { | ||
extInfo.isKotlinUns -> extInfo.type | ||
else -> ext.capitalized() | ||
} | ||
val toType = when { | ||
ReceiverType == "BigInt" -> when { | ||
extInfo.isUx -> "$ExtType(${extInfo.counterType.lowercase()}Value())" | ||
else -> extInfo.type.lowercase() + "Value()" | ||
} | ||
extInfo.isUx -> "$ExtType(this)" | ||
extInfo.type == "BigInt" -> if (receiver.isUx) "toBigInt()" else "toBigInteger()" | ||
else -> "to$extType()" | ||
} | ||
if (ReceiverType != extType) { | ||
+""" | ||
inline val $ReceiverType.$ext: $ExtType | ||
get() = $toType | ||
""" | ||
fun alias(alias: Char) = +""" | ||
inline val $ReceiverType.$alias: $ExtType | ||
get() = $ext""" | ||
when (ext) { | ||
"i32" -> alias('i') | ||
"i64" -> alias('L') | ||
"f32" -> alias('f') | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package uns.gen | ||
|
||
import org.gradle.api.DefaultTask | ||
import org.gradle.api.file.Directory | ||
import org.gradle.api.file.FileSystemOperations | ||
import org.gradle.api.file.ProjectLayout | ||
import org.gradle.api.tasks.OutputDirectory | ||
import org.gradle.api.tasks.TaskAction | ||
import uns.arrays | ||
import uns.extensions | ||
import uns.operators | ||
import uns.types | ||
import javax.inject.Inject | ||
|
||
abstract class GenerateCode : DefaultTask() { | ||
|
||
init { | ||
group = "build" | ||
description = "Generate uns code" | ||
} | ||
|
||
@get:Inject | ||
abstract val layout: ProjectLayout | ||
|
||
@get:Inject | ||
abstract val files: FileSystemOperations | ||
|
||
@get:OutputDirectory | ||
val targetDir: Directory = layout.projectDirectory.dir("src/genCommonMain/kotlin") | ||
|
||
@TaskAction | ||
fun generate() { | ||
Generator.targetDir = targetDir.asFile | ||
|
||
files.delete { delete(Generator.targetDir) } | ||
// val targetJvm = targetJvmDir.get().asFile | ||
// val targetNonJvm = targetNonJvmDir.get().asFile | ||
arrays() | ||
types() | ||
extensions() | ||
operators() | ||
} | ||
} | ||
|
||
fun generate(file: String, block: Generator.() -> Unit) { | ||
Generator().apply { | ||
block() | ||
if (imports.isNotEmpty()) | ||
builder.insert(0, '\n') | ||
for (import in imports) | ||
builder.insert(0, "import $import\n") | ||
// if (`package`.isNotEmpty()) | ||
val f = file.replace('/', '.').substringBefore('.', "") | ||
val pack = if (f.isEmpty()) "uns" else "uns.$f" | ||
builder.insert(0, "package $pack\n\n") | ||
if (experimentals.isNotEmpty()) { | ||
val list = experimentals.joinToString { "${it.pkg}.Experimental${it.name}::class" } | ||
builder.insert(0, "@file:OptIn($list)\n") | ||
} | ||
if (disableNameShadowing) builder.insert(0, "@file:Suppress(\"NAME_SHADOWING\")\n") | ||
if (nothingToInline) builder.insert(0, "@file:Suppress(\"NOTHING_TO_INLINE\")\n") | ||
write(file) | ||
} | ||
} | ||
|
Oops, something went wrong.