Add name adapting of *, +, /
This commit is contained in:
parent
1b20978f9c
commit
39907a1da2
@ -12,15 +12,21 @@ interface AsmExpression<T> {
|
|||||||
fun invoke(gen: AsmGenerationContext<T>)
|
fun invoke(gen: AsmGenerationContext<T>)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal val methodNameAdapters = mapOf("+" to "add", "*" to "multiply", "/" to "divide")
|
||||||
|
|
||||||
internal fun <T> hasSpecific(context: Algebra<T>, name: String, arity: Int): Boolean {
|
internal fun <T> hasSpecific(context: Algebra<T>, name: String, arity: Int): Boolean {
|
||||||
context::class.memberFunctions.find { it.name == name && it.parameters.size == arity }
|
val aName = methodNameAdapters[name] ?: name
|
||||||
|
|
||||||
|
context::class.memberFunctions.find { it.name == aName && it.parameters.size == arity }
|
||||||
?: return false
|
?: return false
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun <T> AsmGenerationContext<T>.tryInvokeSpecific(context: Algebra<T>, name: String, arity: Int): Boolean {
|
internal fun <T> AsmGenerationContext<T>.tryInvokeSpecific(context: Algebra<T>, name: String, arity: Int): Boolean {
|
||||||
context::class.memberFunctions.find { it.name == name && it.parameters.size == arity }
|
val aName = methodNameAdapters[name] ?: name
|
||||||
|
|
||||||
|
context::class.memberFunctions.find { it.name == aName && it.parameters.size == arity }
|
||||||
?: return false
|
?: return false
|
||||||
|
|
||||||
val owner = context::class.jvmName.replace('.', '/')
|
val owner = context::class.jvmName.replace('.', '/')
|
||||||
@ -32,7 +38,7 @@ internal fun <T> AsmGenerationContext<T>.tryInvokeSpecific(context: Algebra<T>,
|
|||||||
append("L${AsmGenerationContext.OBJECT_CLASS};")
|
append("L${AsmGenerationContext.OBJECT_CLASS};")
|
||||||
}
|
}
|
||||||
|
|
||||||
visitAlgebraOperation(owner = owner, method = name, descriptor = sig)
|
visitAlgebraOperation(owner = owner, method = aName, descriptor = sig)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user