v0.3.0-dev-18 #459

Merged
altavir merged 64 commits from dev into master 2022-02-13 17:50:34 +03:00
2 changed files with 7 additions and 4 deletions
Showing only changes of commit a9779fe38b - Show all commits

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))