Skip to content

Commit

Permalink
Merge pull request #67 from Over-Run/feature
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 authored Jan 7, 2025
2 parents abf96d1 + f3660bc commit 07032b2
Show file tree
Hide file tree
Showing 96 changed files with 982 additions and 15,716 deletions.
11 changes: 0 additions & 11 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,6 @@ allprojects {
links("https://download.java.net/java/early_access/$jdkEarlyAccessDoc/docs/api/")
}

tags(
"glfw.callback_signature:m:Callback signature:",
"glfw.errors:m:Errors:",
"glfw.note:m:Note:",
"glfw.pointer_lifetime:m:Pointer lifetime:",
"glfw.remark:m:Remarks:",
"glfw.reentrancy:m:Reentrancy:",
"glfw.thread_safety:m:Thread safety:",
"glfw.warning:m:Warning:",
)

bottom =
"""<a href="https://github.com/Over-Run/overrungl/issues">Report a bug or suggest an enhancement</a><br>""" +
"Copyright © $projLicenseYear Overrun Organization<br>" +
Expand Down
6,304 changes: 398 additions & 5,906 deletions generators/glfw/src/main/kotlin/overrungl/glfw/GLFWGenerator.kt

Large diffs are not rendered by default.

243 changes: 32 additions & 211 deletions generators/nfd/src/main/kotlin/overrungl/nfd/NFDGenerator.kt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion generators/openal/src/main/kotlin/overrungl/openal/AL.kt
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fun AL() {

ALenum("AL_DISTANCE_MODEL" to "0xD000")

ALenum("Distance model values.") {
ALenum {
"AL_INVERSE_DISTANCE"("0xD001")
"AL_INVERSE_DISTANCE_CLAMPED"("0xD002")
"AL_LINEAR_DISTANCE"("0xD003")
Expand Down
2 changes: 1 addition & 1 deletion generators/openal/src/main/kotlin/overrungl/openal/ALC.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fun ALC() {
ALCenum("ALC_DEVICE_SPECIFIER" to "0x1005")
ALCenum("ALC_EXTENSIONS" to "0x1006")

ALCenum("ALC_EXT_CAPTURE" to "1", "Capture extension")
ALCenum("ALC_EXT_CAPTURE" to "1")
ALCenum("ALC_CAPTURE_DEVICE_SPECIFIER" to "0x310")
ALCenum("ALC_CAPTURE_DEFAULT_DEVICE_SPECIFIER" to "0x311")
ALCenum("ALC_CAPTURE_SAMPLES" to "0x312")
Expand Down
6 changes: 0 additions & 6 deletions generators/src/main/kotlin/overrungl/gen/DowncallMethod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,9 @@ data class DowncallMethod(
val name: String,
val parameters: List<DowncallParameter>,
val entrypoint: String?,
val javadoc: String?,
val code: String?,
val overload: Boolean,
val optional: Boolean,
val defaultCode: String?,
) {
val allocatorRequirement: AllocatorRequirement by lazy {
parameters.map { p ->
Expand Down Expand Up @@ -67,14 +65,10 @@ data class DowncallMethod(
fun overload(
name: String = this.name,
parameters: List<DowncallParameter> = this.parameters,
javadoc: String? = this.javadoc,
defaultCode: String? = this.defaultCode
): DowncallMethod = copy(
name = name,
parameters = parameters,
javadoc = javadoc,
overload = true,
defaultCode = defaultCode
)

private fun <T> List<T>.insertFirst(t: T): List<T> {
Expand Down
37 changes: 7 additions & 30 deletions generators/src/main/kotlin/overrungl/gen/StaticDowncall.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ class StaticDowncall(
class FieldGroupBuilder {
internal val fields = mutableListOf<FieldGroupMember>()

operator fun String.invoke(value: String, javadoc: String? = null) {
fields.add(FieldGroupMember(this, value, javadoc))
operator fun String.invoke(value: String) {
fields.add(FieldGroupMember(this, value))
}
}

operator fun CustomTypeSpec.invoke(nameAndValue: Pair<String, String>, javadoc: String? = null) {
fields.add(DowncallField(this, nameAndValue.first, nameAndValue.second, javadoc))
operator fun CustomTypeSpec.invoke(nameAndValue: Pair<String, String>) {
fields.add(DowncallField(this, nameAndValue.first, nameAndValue.second))
}

operator fun CustomTypeSpec.invoke(javadoc: String? = null, builder: FieldGroupBuilder.() -> Unit) {
fields.add(DowncallFieldGroup(this, javadoc, FieldGroupBuilder().also(builder).fields))
operator fun CustomTypeSpec.invoke(builder: FieldGroupBuilder.() -> Unit) {
fields.add(DowncallFieldGroup(this, FieldGroupBuilder().also(builder).fields))
}

operator fun CustomTypeSpec.invoke(name: String): DowncallParameter {
Expand All @@ -59,23 +59,19 @@ class StaticDowncall(
returnType: CustomTypeSpec,
vararg params: DowncallParameter,
entrypoint: String?,
javadoc: String? = null,
code: String? = null,
overload: Boolean = false,
optional: Boolean = false,
defaultCode: String? = null,
addNow: Boolean = true
): DowncallMethod {
val method = DowncallMethod(
returnType = returnType,
name = this,
parameters = params.toList(),
entrypoint = entrypoint,
javadoc = javadoc,
code = code,
overload = overload,
optional = optional,
defaultCode = defaultCode,
)
if (addNow) methods.add(method)
return method
Expand Down Expand Up @@ -164,9 +160,6 @@ class StaticDowncall(
methods.forEach { m ->
val chosenReturnType = m.returnType.selectTypeName(m.overload)
val returnVoid = chosenReturnType == TypeName.VOID
if (m.javadoc != null) {
sb.appendLine(m.javadoc.prependIndent(" ///"))
}
sb.appendLine(
" public static ${m.returnType.typeNameWithC(chosenReturnType)} ${m.name}(${
m.parameters.joinToString { p ->
Expand Down Expand Up @@ -303,33 +296,18 @@ sealed interface DowncallFieldSpec {
data class DowncallField(
val type: CustomTypeSpec,
val name: String,
val value: String,
val javadoc: String?
val value: String
) : DowncallFieldSpec {
override fun append(builder: StringBuilder) {
if (javadoc != null) {
builder.appendLine(javadoc.prependIndent(" ///"))
}
builder.appendLine(" public static final ${type.javaType} $name = $value;")
}
}

data class DowncallFieldGroup(
val type: CustomTypeSpec,
val javadoc: String?,
val members: List<FieldGroupMember>
) : DowncallFieldSpec {
override fun append(builder: StringBuilder) {
if (javadoc != null) {
builder.appendLine(javadoc.prependIndent(" ///"))
}
if (members.any { it.javadoc != null }) {
builder.appendLine(" ///#### Documentation of fields")
members.filter { it.javadoc != null }.forEach {
builder.appendLine(" ///##### ${it.name}")
builder.appendLine(it.javadoc!!.prependIndent(" ///"))
}
}
builder.appendLine(" public static final ${type.javaType}")
members.forEachIndexed { index, it ->
if (index != 0) {
Expand All @@ -344,5 +322,4 @@ data class DowncallFieldGroup(
data class FieldGroupMember(
val name: String,
val value: String,
val javadoc: String?
)
33 changes: 9 additions & 24 deletions generators/src/main/kotlin/overrungl/gen/Struct.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ class Struct(
private val packageName: String,
private val name: String,
private val cType: String? = null,
private val javadoc: String? = null,
private val opaque: Boolean = false,
action: Struct.() -> Unit
) {
Expand Down Expand Up @@ -65,16 +64,16 @@ class Struct(
doLast = action
}

operator fun CustomTypeSpec.invoke(name: String, javadoc: String? = null) {
members.add(ValueStructMember(this, name, javadoc))
operator fun CustomTypeSpec.invoke(name: String) {
members.add(ValueStructMember(this, name))
}

operator fun ByValueWrapper.invoke(name: String, javadoc: String? = null) {
members.add(ByValueStructStructMember(this.struct, name, javadoc))
operator fun ByValueWrapper.invoke(name: String) {
members.add(ByValueStructStructMember(this.struct, name))
}

fun fixedSize(type: CustomTypeSpec, name: String, size: Long, javadoc: String? = null) {
members.add(FixedSizeStructMember(type, size, name, javadoc))
fun fixedSize(type: CustomTypeSpec, name: String, size: Long) {
members.add(FixedSizeStructMember(type, size, name))
}

fun write() {
Expand All @@ -95,10 +94,6 @@ class Struct(
)

// javadoc
if (javadoc != null) {
sb.appendLine(javadoc.prependIndent("/// "))
sb.appendLine("///")
}
sb.appendLine("/// ## Members")
members.forEach {
sb.appendLine("/// ### ${it.name}")
Expand All @@ -111,12 +106,6 @@ class Struct(
}
)
}
if (it.javadoc != null) {
sb.appendLine("///")
sb.appendLine(it.javadoc!!.prependIndent("/// "))
sb.append("///")
sb.appendLine()
}
}
sb.appendLine(
"""
Expand Down Expand Up @@ -409,28 +398,24 @@ class Struct(
sealed interface StructMember {
val type: CustomTypeSpec
val name: String
val javadoc: String?
}

data class ValueStructMember(
override val type: CustomTypeSpec,
override val name: String,
override val javadoc: String?
override val name: String
) : StructMember

data class ByValueStructStructMember(
val struct: Struct,
override val name: String,
override val javadoc: String?
override val name: String
) : StructMember {
override val type: CustomTypeSpec = struct.byValueType
}

data class FixedSizeStructMember(
val componentType: CustomTypeSpec,
val size: Long,
override val name: String,
override val javadoc: String?
override val name: String
) : StructMember {
override val type: CustomTypeSpec
get() = CustomTypeSpec(
Expand Down
28 changes: 4 additions & 24 deletions generators/src/main/kotlin/overrungl/gen/Upcall.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ fun generateUpcallType(packageName: String, name: String): CustomTypeSpec {
class Upcall(
val packageName: String,
val name: String,
val javadoc: String? = null,
action: Upcall.() -> Unit
) {
var targetMethod: UpcallMethod? = null
Expand All @@ -55,15 +54,13 @@ class Upcall(
operator fun String.invoke(
returnType: CustomTypeSpec,
vararg parameters: UpcallMethodParameter,
javadoc: String? = null,
code: String? = null,
overload: String? = null
): UpcallMethod {
return UpcallMethod(
name = this,
returnType = returnType,
parameters = parameters.toList(),
javadoc = javadoc,
code = code,
overload = overload
)
Expand Down Expand Up @@ -94,10 +91,6 @@ class Upcall(
)
sb.appendLine()

// javadoc
if (javadoc != null) {
sb.appendLine(javadoc.prependIndent("/// "))
}
sb.appendLine("@FunctionalInterface")
sb.appendLine("public interface $name extends Upcall {")

Expand Down Expand Up @@ -132,11 +125,7 @@ class Upcall(

// interface method
interfaceMethod?.also { m ->
sb.appendLine(" ///The interface target method of the upcall.")
if (m.javadoc != null) {
sb.appendLine(" ///")
sb.appendLine(m.javadoc.prependIndent(" ///"))
}
sb.appendLine(" /// The interface target method of the upcall.")
sb.append(
" ",
m.returnType.javaTypeWithC(),
Expand All @@ -151,11 +140,7 @@ class Upcall(
}

// target method
sb.appendLine(" ///The target method of the upcall.")
if (targetMethodNotNull.javadoc != null) {
sb.appendLine(" ///")
sb.appendLine(targetMethodNotNull.javadoc.prependIndent(" ///"))
}
sb.appendLine(" /// The target method of the upcall.")
sb.append(" ")
if (targetMethodNotNull.code != null || targetMethodNotNull.overload != null) {
sb.append("default ")
Expand Down Expand Up @@ -208,12 +193,8 @@ class Upcall(
)

// invoker
sb.appendLine(" ///A static invoker of the target method.")
if (targetMethodNotNull.javadoc != null) {
sb.appendLine(" ///")
sb.appendLine(targetMethodNotNull.javadoc.prependIndent(" ///"))
}
sb.appendLine(" ///@param stub the upcall stub")
sb.appendLine(" /// A static invoker of the target method.")
sb.appendLine(" /// @param stub the upcall stub")
sb.append(""" static ${targetMethodNotNull.returnType.carrierWithC()} invoke(MemorySegment stub""")
targetMethodNotNull.parameters.forEach { sb.append(", ", it.type.carrierWithC(), " ", it.name) }
sb.appendLine(") {")
Expand Down Expand Up @@ -333,7 +314,6 @@ data class UpcallMethod(
val name: String,
val returnType: CustomTypeSpec,
val parameters: List<UpcallMethodParameter>,
val javadoc: String?,
val code: String?,
val overload: String?
)
Loading

0 comments on commit 07032b2

Please sign in to comment.