Optimize constant pooling #112
@ -19,11 +19,11 @@ fun <T : Any> MST.compileWith(type: KClass<T>, algebra: Algebra<T>): Expression<
|
||||
when (node) {
|
||||
is MST.Symbolic -> loadVariable(node.value)
|
||||
is MST.Numeric -> {
|
||||
val constant = if (algebra is NumericAlgebra<T>) {
|
||||
val constant = if (algebra is NumericAlgebra<T>)
|
||||
algebra.number(node.value)
|
||||
} else {
|
||||
else
|
||||
error("Number literals are not supported in $algebra")
|
||||
}
|
||||
|
||||
loadTConstant(constant)
|
||||
}
|
||||
is MST.Unary -> {
|
||||
|
@ -257,9 +257,12 @@ internal class AsmBuilder<T> internal constructor(
|
||||
|
||||
if (sigLetter != null) {
|
||||
when (value) {
|
||||
is Byte -> invokeMethodVisitor.visitLdcOrIntConstant(value.toInt())
|
||||
is Short -> invokeMethodVisitor.visitLdcOrIntConstant(value.toInt())
|
||||
is Int -> invokeMethodVisitor.visitLdcOrIntConstant(value)
|
||||
is Double -> invokeMethodVisitor.visitLdcOrDoubleConstant(value)
|
||||
is Float -> invokeMethodVisitor.visitLdcOrFloatConstant(value)
|
||||
is Long -> invokeMethodVisitor.visitLdcOrLongConstant(value)
|
||||
else -> invokeMethodVisitor.visitLdcInsn(value)
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,8 @@ internal fun MethodVisitor.visitLdcOrIntConstant(value: Int): Unit = when (value
|
||||
3 -> visitInsn(ICONST_3)
|
||||
4 -> visitInsn(ICONST_4)
|
||||
5 -> visitInsn(ICONST_5)
|
||||
in -128..127 -> visitIntInsn(BIPUSH, value)
|
||||
in -32768..32767 -> visitIntInsn(SIPUSH, value)
|
||||
else -> visitLdcInsn(value)
|
||||
}
|
||||
|
||||
@ -20,6 +22,12 @@ internal fun MethodVisitor.visitLdcOrDoubleConstant(value: Double): Unit = when
|
||||
else -> visitLdcInsn(value)
|
||||
}
|
||||
|
||||
internal fun MethodVisitor.visitLdcOrLongConstant(value: Long): Unit = when (value) {
|
||||
0L -> visitInsn(LCONST_0)
|
||||
1L -> visitInsn(LCONST_1)
|
||||
else -> visitLdcInsn(value)
|
||||
}
|
||||
|
||||
internal fun MethodVisitor.visitLdcOrFloatConstant(value: Float): Unit = when (value) {
|
||||
0f -> visitInsn(FCONST_0)
|
||||
1f -> visitInsn(FCONST_1)
|
||||
|
Loading…
Reference in New Issue
Block a user