Merge pull request #270 from mipt-npm/commandertvis/fix-binding
Remove redundant try-catch expressions
This commit is contained in:
commit
ae5ca44dc0
@ -58,7 +58,7 @@ public fun <T> Algebra<T>.evaluate(node: MST): T = when (node) {
|
|||||||
is MST.Numeric -> (this as? NumericAlgebra<T>)?.number(node.value)
|
is MST.Numeric -> (this as? NumericAlgebra<T>)?.number(node.value)
|
||||||
?: error("Numeric nodes are not supported by $this")
|
?: error("Numeric nodes are not supported by $this")
|
||||||
|
|
||||||
is MST.Symbolic -> bindSymbol(node.value) ?: error("Symbol '${node.value}' is not supported in $this")
|
is MST.Symbolic -> bindSymbol(node.value)
|
||||||
|
|
||||||
is MST.Unary -> when {
|
is MST.Unary -> when {
|
||||||
this is NumericAlgebra && node.value is MST.Numeric -> unaryOperationFunction(node.operation)(number(node.value.value))
|
this is NumericAlgebra && node.value is MST.Numeric -> unaryOperationFunction(node.operation)(number(node.value.value))
|
||||||
|
@ -14,11 +14,7 @@ import space.kscience.kmath.operations.NumericAlgebra
|
|||||||
internal fun <T> MST.compileWith(algebra: Algebra<T>): Expression<T> {
|
internal fun <T> MST.compileWith(algebra: Algebra<T>): Expression<T> {
|
||||||
fun ESTreeBuilder<T>.visit(node: MST): BaseExpression = when (node) {
|
fun ESTreeBuilder<T>.visit(node: MST): BaseExpression = when (node) {
|
||||||
is Symbolic -> {
|
is Symbolic -> {
|
||||||
val symbol = try {
|
val symbol = algebra.bindSymbolOrNull(node.value)
|
||||||
algebra.bindSymbol(node.value)
|
|
||||||
} catch (ignored: IllegalStateException) {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
|
|
||||||
if (symbol != null)
|
if (symbol != null)
|
||||||
constant(symbol)
|
constant(symbol)
|
||||||
|
@ -22,11 +22,7 @@ import space.kscience.kmath.operations.NumericAlgebra
|
|||||||
internal fun <T : Any> MST.compileWith(type: Class<T>, algebra: Algebra<T>): Expression<T> {
|
internal fun <T : Any> MST.compileWith(type: Class<T>, algebra: Algebra<T>): Expression<T> {
|
||||||
fun AsmBuilder<T>.visit(node: MST): Unit = when (node) {
|
fun AsmBuilder<T>.visit(node: MST): Unit = when (node) {
|
||||||
is Symbolic -> {
|
is Symbolic -> {
|
||||||
val symbol = try {
|
val symbol = algebra.bindSymbolOrNull(node.value)
|
||||||
algebra.bindSymbol(node.value)
|
|
||||||
} catch (ignored: IllegalStateException) {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
|
|
||||||
if (symbol != null)
|
if (symbol != null)
|
||||||
loadObjectConstant(symbol as Any)
|
loadObjectConstant(symbol as Any)
|
||||||
|
Loading…
Reference in New Issue
Block a user