Dev #127
@ -3,8 +3,7 @@ package scientifik.kmath.expressions
|
|||||||
import org.objectweb.asm.MethodVisitor
|
import org.objectweb.asm.MethodVisitor
|
||||||
import org.objectweb.asm.Opcodes.*
|
import org.objectweb.asm.Opcodes.*
|
||||||
|
|
||||||
fun MethodVisitor.visitLdcOrIConstInsn(value: Int) {
|
fun MethodVisitor.visitLdcOrIConstInsn(value: Int) = when (value) {
|
||||||
when (value) {
|
|
||||||
-1 -> visitInsn(ICONST_M1)
|
-1 -> visitInsn(ICONST_M1)
|
||||||
0 -> visitInsn(ICONST_0)
|
0 -> visitInsn(ICONST_0)
|
||||||
1 -> visitInsn(ICONST_1)
|
1 -> visitInsn(ICONST_1)
|
||||||
@ -14,6 +13,18 @@ fun MethodVisitor.visitLdcOrIConstInsn(value: Int) {
|
|||||||
5 -> visitInsn(ICONST_5)
|
5 -> visitInsn(ICONST_5)
|
||||||
else -> visitLdcInsn(value)
|
else -> visitLdcInsn(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun MethodVisitor.visitLdcOrDConstInsn(value: Double) = when (value) {
|
||||||
|
0.0 -> visitInsn(DCONST_0)
|
||||||
|
1.0 -> visitInsn(DCONST_1)
|
||||||
|
else -> visitLdcInsn(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun MethodVisitor.visitLdcOrFConstInsn(value: Float) = when (value) {
|
||||||
|
0f -> visitInsn(FCONST_0)
|
||||||
|
1f -> visitInsn(FCONST_1)
|
||||||
|
2f -> visitInsn(FCONST_2)
|
||||||
|
else -> visitLdcInsn(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val signatureLetters = mapOf(
|
private val signatureLetters = mapOf(
|
||||||
@ -29,6 +40,13 @@ private val signatureLetters = mapOf(
|
|||||||
fun MethodVisitor.visitBoxedNumberConstant(number: Number) {
|
fun MethodVisitor.visitBoxedNumberConstant(number: Number) {
|
||||||
val clazz = number.javaClass
|
val clazz = number.javaClass
|
||||||
val c = clazz.name.replace('.', '/')
|
val c = clazz.name.replace('.', '/')
|
||||||
visitLdcInsn(number)
|
|
||||||
|
when (number) {
|
||||||
|
is Int -> visitLdcOrIConstInsn(number)
|
||||||
|
is Double -> visitLdcOrDConstInsn(number)
|
||||||
|
is Float -> visitLdcOrFConstInsn(number)
|
||||||
|
else -> visitLdcInsn(number)
|
||||||
|
}
|
||||||
|
|
||||||
visitMethodInsn(INVOKESTATIC, c, "valueOf", "(${signatureLetters[clazz]})L${c};", false)
|
visitMethodInsn(INVOKESTATIC, c, "valueOf", "(${signatureLetters[clazz]})L${c};", false)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user