native: pass argument specs in order to support varadic ffi

This commit is contained in:
2023-09-11 01:12:32 -04:00
parent 8d310e337a
commit 2ee1565fb5
7 changed files with 33 additions and 9 deletions

View File

@ -9,7 +9,7 @@ class FunctionContext(val compilationUnitContext: CompilationUnitContext, val no
val native = node.native!!
val nativeFunctionProvider =
compilationUnitContext.evaluator.nativeFunctionProvider(native.form.id)
nativeFunctionProvider.provideNativeFunction(native.definition.text)
nativeFunctionProvider.provideNativeFunction(native.definition.text, node.arguments)
}
private val nativeCached by lazy { resolveMaybeNative() }

View File

@ -1,12 +1,14 @@
package gay.pizza.pork.evaluator
import gay.pizza.pork.ast.ArgumentSpec
class InternalNativeProvider(val quiet: Boolean = false) : NativeProvider {
private val functions = mutableMapOf(
"print" to CallableFunction(::printValues),
"println" to CallableFunction(::printLine)
)
override fun provideNativeFunction(definition: String): CallableFunction {
override fun provideNativeFunction(definition: String, arguments: List<ArgumentSpec>): CallableFunction {
return functions[definition] ?: throw RuntimeException("Unknown Internal Function: $definition")
}

View File

@ -1,5 +1,7 @@
package gay.pizza.pork.evaluator
import gay.pizza.pork.ast.ArgumentSpec
interface NativeProvider {
fun provideNativeFunction(definition: String): CallableFunction
fun provideNativeFunction(definition: String, arguments: List<ArgumentSpec>): CallableFunction
}