Merge pull request #447 from mipt-npm/commandertvis/fixbuild

Do numeric type conversion in JS MST compilers
This commit is contained in:
Alexander Nozik 2021-12-30 16:54:27 +03:00 committed by GitHub
commit 4b4c878e21
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -28,11 +28,14 @@ internal fun <T> MST.compileWith(algebra: Algebra<T>): Expression<T> {
variable(node.identity)
}
is Numeric -> constant(node.value)
is Numeric -> constant(
(algebra as? NumericAlgebra<T>)?.number(node.value) ?: error("Numeric nodes are not supported by $this")
)
is Unary -> when {
algebra is NumericAlgebra && node.value is Numeric -> constant(
algebra.unaryOperationFunction(node.operation)(algebra.number((node.value as Numeric).value)))
algebra.unaryOperationFunction(node.operation)(algebra.number((node.value as Numeric).value))
)
else -> call(algebra.unaryOperationFunction(node.operation), visit(node.value))
}

View File

@ -114,7 +114,7 @@ internal class DoubleWasmBuilder(target: MST) : WasmBuilder<Double, DoubleExpres
override fun createModule() = readBinary(f64StandardFunctions)
override fun visitNumeric(node: Numeric) = ctx.f64.const(node.value)
override fun visitNumeric(node: Numeric) = ctx.f64.const(node.value.toDouble())
override fun visitUnary(node: Unary): ExpressionRef = when (node.operation) {
GroupOps.MINUS_OPERATION -> ctx.f64.neg(visit(node.value))
@ -157,7 +157,7 @@ internal class IntWasmBuilder(target: MST) : WasmBuilder<Int, IntExpression>(i32
}
}
override fun visitNumeric(node: Numeric) = ctx.i32.const(node.value)
override fun visitNumeric(node: Numeric) = ctx.i32.const(node.value.toInt())
override fun visitUnary(node: Unary): ExpressionRef = when (node.operation) {
GroupOps.MINUS_OPERATION -> ctx.i32.sub(ctx.i32.const(0), visit(node.value))