diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/ArrayGet.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/ArrayGet.kt index 93d9ab6f17c..7cbe3c1dbe3 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/ArrayGet.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/ArrayGet.kt @@ -24,7 +24,7 @@ import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter public class ArrayGet : IntrinsicMethod() { override fun toCallable(method: CallableMethod): Callable = - createMappedCallable(method) { + createIntrinsicCallable(method) { val type = correctElementType(calcReceiverType()) it.aload(type) } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/ArrayIterator.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/ArrayIterator.kt index b6f517603b5..74234de4910 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/ArrayIterator.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/ArrayIterator.kt @@ -44,7 +44,7 @@ import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter public class ArrayIterator : IntrinsicMethod() { override fun toCallable(method: CallableMethod): Callable { - return createUnaryCallable(method) { + return createUnaryIntrinsicCallable(method, needPrimitiveCheck = false) { val methodSignature = "(${method.owner.getDescriptor()})${returnType.getDescriptor()}" it.invokestatic("kotlin/jvm/internal/InternalPackage", "iterator", methodSignature, false) } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/ArraySize.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/ArraySize.kt index d2dcf66cc55..08becf136d5 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/ArraySize.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/ArraySize.kt @@ -22,7 +22,7 @@ import org.jetbrains.kotlin.codegen.CallableMethod public class ArraySize : IntrinsicMethod() { public override fun toCallable(method: CallableMethod): Callable { - return createUnaryCallable(method) { adapter -> + return createUnaryIntrinsicCallable(method) { adapter -> adapter.arraylength() } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/BinaryOp.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/BinaryOp.kt index d9f1d11ff6a..095d329f0d3 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/BinaryOp.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/BinaryOp.kt @@ -36,7 +36,7 @@ public class BinaryOp(private val opcode: Int) : IntrinsicMethod() { val operandType = numberFunctionOperandType(returnType) val paramType = if (shift()) Type.INT_TYPE else operandType - return binaryIntrinsic(operandType, paramType, operandType) { + return createBinaryIntrinsicCallable(operandType, paramType, operandType) { v -> v.visitInsn(returnType.getOpcode(opcode)) } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/Clone.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/Clone.kt index f61c851da77..42ea2d1e8df 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/Clone.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/Clone.kt @@ -24,7 +24,7 @@ import org.jetbrains.org.objectweb.asm.Opcodes public class Clone : IntrinsicMethod() { override fun toCallable(method: CallableMethod, isSuperCall: Boolean): Callable { - return createUnaryCallable(method, OBJECT_TYPE) { + return createUnaryIntrinsicCallable(method, OBJECT_TYPE, needPrimitiveCheck = false) { val opcodes: Int = if (isSuperCall) Opcodes.INVOKESPECIAL else Opcodes.INVOKEVIRTUAL it.visitMethodInsn(opcodes, "java/lang/Object", "clone", "()Ljava/lang/Object;", false) } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/CompareTo.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/CompareTo.kt index 9edc646b5f6..94cd9ba4d02 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/CompareTo.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/CompareTo.kt @@ -35,8 +35,8 @@ public class CompareTo : IntrinsicMethod() { } override fun toCallable(method: CallableMethod): Callable { - val parameterType = comparisonOperandType(method.thisType ?: method.receiverType, method.parameterTypes.single()) - return binaryIntrinsic(method.returnType, parameterType, parameterType, null) { + val parameterType = comparisonOperandType(method.thisType ?: method.receiverType, method.argumentTypes.single()) + return createBinaryIntrinsicCallable(method.returnType, parameterType, parameterType, null) { genInvoke(parameterType, it) } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/Equals.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/Equals.kt index 7b5f7ee1f37..38744a7739e 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/Equals.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/Equals.kt @@ -24,7 +24,7 @@ import org.jetbrains.kotlin.resolve.jvm.AsmTypes.OBJECT_TYPE public class Equals : IntrinsicMethod() { override fun toCallable(method: CallableMethod): Callable { - return binaryIntrinsic(method.returnType, OBJECT_TYPE, nullOrObject(method.thisType), nullOrObject(method.receiverType)) { + return createBinaryIntrinsicCallable(method.returnType, OBJECT_TYPE, nullOrObject(method.thisType), nullOrObject(method.receiverType)) { AsmUtil.genAreEqualCall(it) } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/Increment.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/Increment.kt index cdcbfb503c4..a147002bcea 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/Increment.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/Increment.kt @@ -27,7 +27,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall public class Increment(private val myDelta: Int) : IntrinsicMethod() { override fun toCallable(method: CallableMethod, isSuper: Boolean, resolvedCall: ResolvedCall<*>): Callable { - return createMappedCallable(method) { + return createIntrinsicCallable(method) { val jetExpression = resolvedCall.getCall().getCalleeExpression() assert(jetExpression !is JetPrefixExpression) { "There should be postfix increment ${jetExpression!!.getText()}" } genIncrement(returnType, myDelta, it) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/IntrinsicCallable.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/IntrinsicCallable.kt index 5e3f9739426..62ddce21b44 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/IntrinsicCallable.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/IntrinsicCallable.kt @@ -64,7 +64,7 @@ public abstract class IntrinsicCallable(override val returnType: Type, } } -fun binaryIntrinsic(returnType: Type, valueParameterType: Type, thisType: Type? = null, receiverType: Type? = null, lambda: IntrinsicCallable.(i: InstructionAdapter) -> Unit): IntrinsicCallable { +fun createBinaryIntrinsicCallable(returnType: Type, valueParameterType: Type, thisType: Type? = null, receiverType: Type? = null, lambda: IntrinsicCallable.(i: InstructionAdapter) -> Unit): IntrinsicCallable { assert(AsmUtil.isPrimitive(returnType)) { "Return type of BinaryOp intrinsic should be of primitive type : " + returnType } return object : IntrinsicCallable(returnType, listOf(valueParameterType), thisType, receiverType) { @@ -74,14 +74,19 @@ fun binaryIntrinsic(returnType: Type, valueParameterType: Type, thisType: Type? } } -public class UnaryIntrinsic(val callable: CallableMethod, val newReturnType: Type? = null, needPrimitiveCheck: Boolean = false, val newThisType: Type? = null, val invoke: UnaryIntrinsic.(v: InstructionAdapter) -> Unit) : - IntrinsicCallable(newReturnType ?: callable.returnType, callable.valueParameterTypes, newThisType ?: callable.thisType, callable.receiverType) { +public class UnaryIntrinsic( + callable: CallableMethod, + newReturnType: Type? = null, + needPrimitiveCheck: Boolean = true, + newThisType: Type? = null, + private val invoke: UnaryIntrinsic.(v: InstructionAdapter) -> Unit +) : IntrinsicCallable(newReturnType ?: callable.returnType, callable.valueParameterTypes, newThisType ?: callable.thisType, callable.receiverType) { init { if (needPrimitiveCheck) { - assert(AsmUtil.isPrimitive(returnType)) { "Return type of UnaryPlus intrinsic should be of primitive type : " + returnType } + assert(AsmUtil.isPrimitive(returnType)) { "Return type of UnaryPlus intrinsic should be of primitive type: $returnType" } } - assert(valueParameterTypes.isEmpty(), "Unary operation should not have any parameters") + assert(valueParameterTypes.isEmpty()) { "Unary operation should not have any parameters" } } override fun invokeIntrinsic(v: InstructionAdapter) { @@ -89,8 +94,14 @@ public class UnaryIntrinsic(val callable: CallableMethod, val newReturnType: Typ } } -public fun createUnaryCallable(callable: CallableMethod, newReturnType: Type? = null, needPrimitiveCheck: Boolean = false, invoke: IntrinsicCallable.(v: InstructionAdapter) -> Unit) : IntrinsicCallable { - return UnaryIntrinsic(callable, newReturnType, needPrimitiveCheck, invoke = invoke) +public fun createUnaryIntrinsicCallable( + callable: CallableMethod, + newReturnType: Type? = null, + needPrimitiveCheck: Boolean = true, + newThisType: Type? = null, + invoke: IntrinsicCallable.(v: InstructionAdapter) -> Unit +) : IntrinsicCallable { + return UnaryIntrinsic(callable, newReturnType, needPrimitiveCheck, newThisType, invoke = invoke) } public open class MappedCallable(val callable: CallableMethod, val invoke: IntrinsicCallable.(v: InstructionAdapter) -> Unit = {}) : @@ -101,6 +112,6 @@ public open class MappedCallable(val callable: CallableMethod, val invoke: Intri } } -public fun createMappedCallable(callable: CallableMethod, invoke: IntrinsicCallable.(v: InstructionAdapter) -> Unit) : IntrinsicCallable { +public fun createIntrinsicCallable(callable: CallableMethod, invoke: IntrinsicCallable.(v: InstructionAdapter) -> Unit) : IntrinsicCallable { return MappedCallable(callable, invoke) } \ No newline at end of file diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/Inv.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/Inv.kt index d29bb0a6d32..582e3564eea 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/Inv.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/Inv.kt @@ -25,7 +25,7 @@ public class Inv : IntrinsicMethod() { override fun toCallable(method: CallableMethod): Callable { val type = numberFunctionOperandType(method.returnType) - return UnaryIntrinsic(method, newThisType = type) { + return createUnaryIntrinsicCallable(method, newThisType = type) { if (returnType == Type.LONG_TYPE) { it.lconst(-1) } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/JavaClassArray.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/JavaClassArray.kt index edbbe8dd77f..e8a814126a7 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/JavaClassArray.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/JavaClassArray.kt @@ -21,7 +21,7 @@ import org.jetbrains.kotlin.codegen.CallableMethod public class JavaClassArray : IntrinsicMethod() { override fun toCallable(method: CallableMethod): Callable { - return createMappedCallable(method) { + return createIntrinsicCallable(method) { //do nothing all generated as vararg } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/NumberCast.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/NumberCast.kt index dcc1e41dda4..e961288dd37 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/NumberCast.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/NumberCast.kt @@ -23,7 +23,7 @@ import org.jetbrains.kotlin.codegen.StackValue public class NumberCast : IntrinsicMethod() { override fun toCallable(method: CallableMethod): Callable { - return createUnaryCallable(method) { + return createUnaryIntrinsicCallable(method) { StackValue.coerce(calcReceiverType()!!, returnType, it) } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/StringGetChar.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/StringGetChar.kt index d56849cf0f9..f57345e1272 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/StringGetChar.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/StringGetChar.kt @@ -22,7 +22,7 @@ import org.jetbrains.kotlin.codegen.CallableMethod public class StringGetChar : IntrinsicMethod() { override fun toCallable(method: CallableMethod): Callable { - return createMappedCallable(method) { + return createIntrinsicCallable(method) { it.invokevirtual("java/lang/String", "charAt", "(I)C", false) } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/StringPlus.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/StringPlus.kt index f699d64d866..b92c6a8af25 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/StringPlus.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/StringPlus.kt @@ -22,7 +22,7 @@ import org.jetbrains.kotlin.codegen.CallableMethod public class StringPlus : IntrinsicMethod() { override fun toCallable(method: CallableMethod): Callable { - return createMappedCallable(method) { + return createIntrinsicCallable(method) { it.invokestatic("kotlin/jvm/internal/Intrinsics", "stringPlus", "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/String;", false) } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/ToString.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/ToString.kt index 753047595e3..339e18552cf 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/ToString.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/ToString.kt @@ -24,7 +24,7 @@ public class ToString : IntrinsicMethod() { override fun toCallable(method: CallableMethod): Callable { val type = AsmUtil.stringValueOfType(method.thisType ?: method.receiverType) - return UnaryIntrinsic(method, newThisType = type) { + return createUnaryIntrinsicCallable(method, newThisType = type) { it.invokestatic("java/lang/String", "valueOf", "(" + type.getDescriptor() + ")Ljava/lang/String;", false) } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/UnaryMinus.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/UnaryMinus.kt index 1d4040d201e..88adc938b9f 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/UnaryMinus.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/UnaryMinus.kt @@ -23,7 +23,7 @@ import org.jetbrains.kotlin.codegen.CallableMethod public class UnaryMinus : IntrinsicMethod() { override fun toCallable(method: CallableMethod): Callable { - return createUnaryCallable(method, numberFunctionOperandType(method.returnType), needPrimitiveCheck = true) { + return createUnaryIntrinsicCallable(method, numberFunctionOperandType(method.returnType), needPrimitiveCheck = true) { it.neg(returnType) } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/UnaryPlus.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/UnaryPlus.kt index 650c8e0f0bb..8f721f0680b 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/UnaryPlus.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/UnaryPlus.kt @@ -22,7 +22,7 @@ import org.jetbrains.kotlin.codegen.CallableMethod public class UnaryPlus : IntrinsicMethod() { override fun toCallable(method: CallableMethod): Callable { - return createUnaryCallable(method, needPrimitiveCheck = true) { + return createUnaryIntrinsicCallable(method, needPrimitiveCheck = true) { //nothing } }