Skip to content

Commit

Permalink
Merge pull request #69 from Over-Run/feature
Browse files Browse the repository at this point in the history
  • Loading branch information
squid233 authored Jan 9, 2025
2 parents fe9f316 + 6a9522c commit 051d3b2
Show file tree
Hide file tree
Showing 357 changed files with 12,893 additions and 16,377 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class InstanceDowncall(
private val extends = mutableListOf<String>()
private val permits = mutableListOf<String>()
private val fields = mutableListOf<InstanceDowncallField>()
val handleFields = mutableListOf<InstanceDowncallField>()
val pfnFields = mutableListOf<InstanceDowncallField>()
private val methods = mutableListOf<InstanceDowncallMethod>()

init {
Expand Down Expand Up @@ -93,18 +95,23 @@ class InstanceDowncall(
sb.appendLine(" {")

// fields
fields.forEach {
sb.append(" public")
if (it.modifier != null) {
sb.append(" ")
sb.append(it.modifier)
fun writeFields(list: List<InstanceDowncallField>) {
list.forEach {
sb.append(" public")
if (it.modifier != null) {
sb.append(" ")
sb.append(it.modifier)
}
sb.append(" final ${it.type} ${it.name}")
if (it.value != null) {
sb.append(" = ${it.value}")
}
sb.appendLine(";")
}
sb.append(" final ${it.type} ${it.name}")
if (it.value != null) {
sb.append(" = ${it.value}")
}
sb.appendLine(";")
}
writeFields(fields)
writeFields(handleFields)
writeFields(pfnFields)

// constructor
sb.appendLine()
Expand All @@ -130,18 +137,17 @@ class InstanceDowncall(
sb.append(m.params.joinToString(", ") { p -> "${p.type.carrierWithC()} ${p.name}" })
sb.appendLine(") {")

sb.appendLine(" if (!Unmarshal.isNullPointer(PFN_${m.entrypoint})) { try {")
sb.append(" ")
sb.appendLine(""" if (Unmarshal.isNullPointer(PFN_${m.entrypoint})) throw new SymbolNotFoundError("Symbol not found: ${m.entrypoint}");""")
sb.append(" try { ")
if (m.returnType.carrier != TypeName.VOID) {
sb.append("return (${m.returnType.carrier}) ")
}
sb.append("MH_${m.entrypoint}.invokeExact(PFN_${m.entrypoint}")
m.params.forEach {
sb.append(", ${it.name}")
}
sb.appendLine(");")
sb.appendLine(""" } catch (Throwable e) { throw new RuntimeException("error in ${m.entrypoint}", e); }""")
sb.appendLine(""" } else { throw new SymbolNotFoundError("Symbol not found: ${m.entrypoint}"); }""")
sb.appendLine("); }")
sb.appendLine(""" catch (Throwable e) { throw new RuntimeException("error in ${m.entrypoint}", e); }""")

sb.appendLine(" }")
sb.appendLine()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ fun main() {
fun InstanceDowncall.addCommand(command: GLRequireCommand) {
val get = commandMap[command.name]!!
// handles
field(
handleFields.add(
InstanceDowncallField(
modifier = "static",
type = "MethodHandle",
Expand All @@ -649,7 +649,7 @@ fun main() {
)

// address
field(
pfnFields.add(
InstanceDowncallField(
type = "MemorySegment",
name = "PFN_${get.name}"
Expand Down
6 changes: 1 addition & 5 deletions generators/src/main/kotlin/overrungl/gen/StaticDowncall.kt
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class StaticDowncall(

// optional
if (m.optional) {
sb.appendLine(" if (Handles.MH_${m.entrypoint} != null) {")
sb.appendLine(""" if (Handles.MH_${m.entrypoint} == null) throw new SymbolNotFoundError("Symbol not found: ${m.entrypoint}");""")
}

// header
Expand Down Expand Up @@ -272,10 +272,6 @@ class StaticDowncall(
}

sb.appendLine(""" } catch (Throwable e) { throw new RuntimeException("error in ${m.entrypoint}", e); }""")

if (m.optional) {
sb.appendLine(""" } else { throw new SymbolNotFoundError("Symbol not found: ${m.entrypoint}"); }""")
}
}
sb.appendLine(" }")
sb.appendLine()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ class VkDowncall(
import overrungl.annotation.*;
import overrungl.internal.RuntimeHelper;
import overrungl.util.*;
import overrungl.vulkan.*;
""".trimIndent()
)
if (packageName != vulkanPackage) sb.appendLine("import overrungl.vulkan.*;")
imports.sorted().forEach { sb.appendLine("import $it;") }
sb.append("public class $className")
if (extends.isNotEmpty()) {
Expand Down
Loading

0 comments on commit 051d3b2

Please sign in to comment.