Minor refactor and encapsulation

This commit is contained in:
Iaroslav 2020-06-13 15:50:21 +07:00
parent 36ad1fcf58
commit fec8c7f9d1
No known key found for this signature in database
GPG Key ID: 46E15E4A31B3BCD7
2 changed files with 5 additions and 3 deletions

View File

@ -11,7 +11,7 @@ interface AsmExpression<T> {
fun invoke(gen: AsmGenerationContext<T>) fun invoke(gen: AsmGenerationContext<T>)
} }
internal val methodNameAdapters = mapOf("+" to "add", "*" to "multiply", "/" to "divide") private val methodNameAdapters: Map<String, String> = 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 {
val aName = methodNameAdapters[name] ?: name val aName = methodNameAdapters[name] ?: name
@ -137,7 +137,9 @@ internal class AsmConstProductExpression<T>(
gen.visitAlgebraOperation( gen.visitAlgebraOperation(
owner = AsmGenerationContext.SPACE_OPERATIONS_CLASS, owner = AsmGenerationContext.SPACE_OPERATIONS_CLASS,
method = "multiply", method = "multiply",
descriptor = "(L${AsmGenerationContext.OBJECT_CLASS};L${AsmGenerationContext.NUMBER_CLASS};)L${AsmGenerationContext.OBJECT_CLASS};" descriptor = "(L${AsmGenerationContext.OBJECT_CLASS};" +
"L${AsmGenerationContext.NUMBER_CLASS};)" +
"L${AsmGenerationContext.OBJECT_CLASS};"
) )
} }
} }

View File

@ -2,7 +2,7 @@ package scientifik.kmath.expressions
import scientifik.kmath.operations.* import scientifik.kmath.operations.*
internal class FunctionalUnaryOperation<T>(val context: Algebra<T>, val name: String, val expr: Expression<T>) : internal class FunctionalUnaryOperation<T>(val context: Algebra<T>, val name: String, private val expr: Expression<T>) :
Expression<T> { Expression<T> {
override fun invoke(arguments: Map<String, T>): T = context.unaryOperation(name, expr.invoke(arguments)) override fun invoke(arguments: Map<String, T>): T = context.unaryOperation(name, expr.invoke(arguments))
} }