ASM Bytecode Generation to unwrap Expressions of adv-expr API #94

Merged
CommanderTvis merged 44 commits from adv-expr into adv-expr 2020-06-13 21:07:15 +03:00
Showing only changes of commit 39907a1da2 - Show all commits

View File

@ -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
} }