From 39907a1da239d0eba4f7affbb3438ddcfeb89b1f Mon Sep 17 00:00:00 2001 From: Iaroslav Date: Fri, 12 Jun 2020 19:50:28 +0700 Subject: [PATCH] Add name adapting of *, +, / --- .../kmath/expressions/asm/AsmExpressions.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/kmath-asm/src/main/kotlin/scientifik/kmath/expressions/asm/AsmExpressions.kt b/kmath-asm/src/main/kotlin/scientifik/kmath/expressions/asm/AsmExpressions.kt index 662e1279e..70f1fc28e 100644 --- a/kmath-asm/src/main/kotlin/scientifik/kmath/expressions/asm/AsmExpressions.kt +++ b/kmath-asm/src/main/kotlin/scientifik/kmath/expressions/asm/AsmExpressions.kt @@ -12,15 +12,21 @@ interface AsmExpression { fun invoke(gen: AsmGenerationContext) } +internal val methodNameAdapters = mapOf("+" to "add", "*" to "multiply", "/" to "divide") + internal fun hasSpecific(context: Algebra, 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 true } internal fun AsmGenerationContext.tryInvokeSpecific(context: Algebra, 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 val owner = context::class.jvmName.replace('.', '/') @@ -32,7 +38,7 @@ internal fun AsmGenerationContext.tryInvokeSpecific(context: Algebra, append("L${AsmGenerationContext.OBJECT_CLASS};") } - visitAlgebraOperation(owner = owner, method = name, descriptor = sig) + visitAlgebraOperation(owner = owner, method = aName, descriptor = sig) return true }