implement native type compilation

This commit is contained in:
Alex Zenla
2025-07-20 19:57:09 -07:00
parent f7ff896f81
commit 837e0c1b38
19 changed files with 133 additions and 20 deletions

View File

@ -8,16 +8,35 @@ class InternalNativeProvider(val quiet: Boolean = false) : NativeProvider {
"listInitWith" to NativeFunction(::listInitWith)
)
private val types = mutableMapOf(
"int32" to NativeType { Int::class.java },
"int64" to NativeType { Long::class.java },
"string" to NativeType { String::class.java },
"float32" to NativeType { Float::class.java },
"float64" to NativeType { Double::class.java },
"bool" to NativeType { Boolean::class.java },
)
fun add(name: String, function: NativeFunction) {
functions[name] = function
}
fun add(name: String, type: NativeType) {
types[name] = type
}
override fun provideNativeFunction(definitions: List<String>): NativeFunction {
val definition = definitions[0]
return functions[definition] ?:
throw RuntimeException("Unknown internal function: $definition")
}
override fun provideNativeType(definitions: List<String>): NativeType {
val definition = definitions[0]
return types[definition] ?:
throw RuntimeException("Unknown internal type: $definition")
}
private fun printValues(arguments: ArgumentList): Any {
if (quiet || arguments.isEmpty()) return None
print(arguments.at<List<*>>(0).joinToString(" ") { it.toString() })

View File

@ -2,4 +2,5 @@ package gay.pizza.pork.execution
interface NativeProvider {
fun provideNativeFunction(definitions: List<String>): NativeFunction
fun provideNativeType(definitions: List<String>): NativeType
}

View File

@ -0,0 +1,5 @@
package gay.pizza.pork.execution
fun interface NativeType {
fun value(): Any
}