Add StackValue.put(InstructionAdapter) for convenience
This commit is contained in:
@@ -420,8 +420,7 @@ public class ConstructorCodegen {
|
|||||||
// Super constructor requires OUTER parameter, but our OUTER instance may be different from what is expected by the super
|
// Super constructor requires OUTER parameter, but our OUTER instance may be different from what is expected by the super
|
||||||
// constructor. We need to traverse our outer classes from the bottom up, to find the needed class. See innerExtendsOuter.kt
|
// constructor. We need to traverse our outer classes from the bottom up, to find the needed class. See innerExtendsOuter.kt
|
||||||
ClassDescriptor outerForSuper = (ClassDescriptor) superConstructor.getContainingDeclaration().getContainingDeclaration();
|
ClassDescriptor outerForSuper = (ClassDescriptor) superConstructor.getContainingDeclaration().getContainingDeclaration();
|
||||||
StackValue outer = codegen.generateThisOrOuter(outerForSuper, true, true);
|
codegen.generateThisOrOuter(outerForSuper, true, true).put(codegen.v);
|
||||||
outer.put(outer.type, codegen.v);
|
|
||||||
superIndex++;
|
superIndex++;
|
||||||
}
|
}
|
||||||
else if (kind == JvmMethodParameterKind.SUPER_CALL_PARAM || kind == JvmMethodParameterKind.ENUM_NAME_OR_ORDINAL) {
|
else if (kind == JvmMethodParameterKind.SUPER_CALL_PARAM || kind == JvmMethodParameterKind.ENUM_NAME_OR_ORDINAL) {
|
||||||
|
|||||||
@@ -1556,7 +1556,7 @@ public class FunctionCodegen {
|
|||||||
iv.load(2, returnType);
|
iv.load(2, returnType);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
StackValue.constant(typeSafeBarrierDescription.getDefaultValue(), returnType).put(returnType, iv);
|
StackValue.constant(typeSafeBarrierDescription.getDefaultValue(), returnType).put(iv);
|
||||||
}
|
}
|
||||||
iv.areturn(returnType);
|
iv.areturn(returnType);
|
||||||
|
|
||||||
@@ -1619,7 +1619,7 @@ public class FunctionCodegen {
|
|||||||
|
|
||||||
InstructionAdapter iv = new InstructionAdapter(mv);
|
InstructionAdapter iv = new InstructionAdapter(mv);
|
||||||
iv.load(0, OBJECT_TYPE);
|
iv.load(0, OBJECT_TYPE);
|
||||||
field.put(field.type, iv);
|
field.put(iv);
|
||||||
for (int i = 0, reg = 1; i < argTypes.length; i++) {
|
for (int i = 0, reg = 1; i < argTypes.length; i++) {
|
||||||
StackValue.local(reg, argTypes[i]).put(originalArgTypes[i], iv);
|
StackValue.local(reg, argTypes[i]).put(originalArgTypes[i], iv);
|
||||||
//noinspection AssignmentToForLoopParameter
|
//noinspection AssignmentToForLoopParameter
|
||||||
|
|||||||
@@ -913,7 +913,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
if (state.getClassBuilderMode().generateBodies && info.defaultValue == null) {
|
if (state.getClassBuilderMode().generateBodies && info.defaultValue == null) {
|
||||||
ExpressionCodegen codegen = createOrGetClInitCodegen();
|
ExpressionCodegen codegen = createOrGetClInitCodegen();
|
||||||
int companionObjectIndex = putCompanionObjectInLocalVar(codegen);
|
int companionObjectIndex = putCompanionObjectInLocalVar(codegen);
|
||||||
StackValue.local(companionObjectIndex, OBJECT_TYPE).put(OBJECT_TYPE, codegen.v);
|
StackValue.local(companionObjectIndex, OBJECT_TYPE).put(codegen.v);
|
||||||
copyFieldFromCompanionObject(property);
|
copyFieldFromCompanionObject(property);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -49,8 +49,7 @@ class JvmStaticInCompanionObjectGenerator(
|
|||||||
override fun doGenerateBody(codegen: ExpressionCodegen, signature: JvmMethodSignature) {
|
override fun doGenerateBody(codegen: ExpressionCodegen, signature: JvmMethodSignature) {
|
||||||
val iv = codegen.v
|
val iv = codegen.v
|
||||||
val classDescriptor = descriptor.containingDeclaration as ClassDescriptor
|
val classDescriptor = descriptor.containingDeclaration as ClassDescriptor
|
||||||
val singletonValue = StackValue.singleton(classDescriptor, typeMapper)
|
StackValue.singleton(classDescriptor, typeMapper).put(iv)
|
||||||
singletonValue.put(singletonValue.type, iv)
|
|
||||||
var index = 0
|
var index = 0
|
||||||
val asmMethod = signature.asmMethod
|
val asmMethod = signature.asmMethod
|
||||||
for (paramType in asmMethod.argumentTypes) {
|
for (paramType in asmMethod.argumentTypes) {
|
||||||
|
|||||||
@@ -103,14 +103,18 @@ public abstract class StackValue {
|
|||||||
put(type, kotlinType, v);
|
put(type, kotlinType, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void put(@NotNull Type type, @Nullable KotlinType kotlinType, @NotNull InstructionAdapter v) {
|
public void put(@NotNull InstructionAdapter v) {
|
||||||
put(type, kotlinType, v, false);
|
put(type, null, v, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void put(@NotNull Type type, @NotNull InstructionAdapter v) {
|
public void put(@NotNull Type type, @NotNull InstructionAdapter v) {
|
||||||
put(type, null, v, false);
|
put(type, null, v, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void put(@NotNull Type type, @Nullable KotlinType kotlinType, @NotNull InstructionAdapter v) {
|
||||||
|
put(type, kotlinType, v, false);
|
||||||
|
}
|
||||||
|
|
||||||
public void put(@NotNull Type type, @Nullable KotlinType kotlinType, @NotNull InstructionAdapter v, boolean skipReceiver) {
|
public void put(@NotNull Type type, @Nullable KotlinType kotlinType, @NotNull InstructionAdapter v, boolean skipReceiver) {
|
||||||
if (!skipReceiver) {
|
if (!skipReceiver) {
|
||||||
putReceiver(v, true);
|
putReceiver(v, true);
|
||||||
|
|||||||
@@ -22,10 +22,9 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
|||||||
import org.jetbrains.org.objectweb.asm.Type
|
import org.jetbrains.org.objectweb.asm.Type
|
||||||
|
|
||||||
class ArraySize : IntrinsicPropertyGetter() {
|
class ArraySize : IntrinsicPropertyGetter() {
|
||||||
override fun generate(
|
override fun generate(resolvedCall: ResolvedCall<*>?, codegen: ExpressionCodegen, returnType: Type, receiver: StackValue) =
|
||||||
resolvedCall: ResolvedCall<*>?, codegen: ExpressionCodegen, returnType: Type, receiver: StackValue
|
StackValue.operation(returnType) { iv ->
|
||||||
) = StackValue.operation(returnType) {
|
receiver.put(iv)
|
||||||
receiver.put(receiver.type, it)
|
iv.arraylength()
|
||||||
it.arraylength()
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
|||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||||
import org.jetbrains.kotlin.resolve.isInlineClassType
|
import org.jetbrains.kotlin.resolve.isInlineClassType
|
||||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
||||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes.UNIT_TYPE
|
|
||||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes.getType
|
import org.jetbrains.kotlin.resolve.jvm.AsmTypes.getType
|
||||||
import org.jetbrains.org.objectweb.asm.Type
|
import org.jetbrains.org.objectweb.asm.Type
|
||||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
||||||
@@ -53,7 +52,7 @@ object JavaClassProperty : IntrinsicPropertyGetter() {
|
|||||||
when {
|
when {
|
||||||
type == Type.VOID_TYPE -> {
|
type == Type.VOID_TYPE -> {
|
||||||
receiver.put(Type.VOID_TYPE, v)
|
receiver.put(Type.VOID_TYPE, v)
|
||||||
StackValue.unit().put(UNIT_TYPE, v)
|
StackValue.unit().put(v)
|
||||||
invokeVirtualGetClassMethod()
|
invokeVirtualGetClassMethod()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -456,7 +456,7 @@ class ExpressionCodegen(
|
|||||||
override fun visitGetField(expression: IrGetField, data: BlockInfo): StackValue {
|
override fun visitGetField(expression: IrGetField, data: BlockInfo): StackValue {
|
||||||
expression.markLineNumber(startOffset = true)
|
expression.markLineNumber(startOffset = true)
|
||||||
val value = generateFieldValue(expression, data)
|
val value = generateFieldValue(expression, data)
|
||||||
value.put(value.type, mv)
|
value.put(mv)
|
||||||
return onStack(value.type)
|
return onStack(value.type)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -511,7 +511,7 @@ class ExpressionCodegen(
|
|||||||
|
|
||||||
private fun generateLocal(symbol: IrSymbol, type: Type): StackValue {
|
private fun generateLocal(symbol: IrSymbol, type: Type): StackValue {
|
||||||
val index = findLocalIndex(symbol)
|
val index = findLocalIndex(symbol)
|
||||||
StackValue.local(index, type).put(type, mv)
|
StackValue.local(index, type).put(mv)
|
||||||
return onStack(type)
|
return onStack(type)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -549,7 +549,7 @@ class ExpressionCodegen(
|
|||||||
expression.markLineNumber(startOffset = true)
|
expression.markLineNumber(startOffset = true)
|
||||||
val value = expression.value
|
val value = expression.value
|
||||||
val type = expression.asmType
|
val type = expression.asmType
|
||||||
StackValue.constant(value, type).put(type, mv)
|
StackValue.constant(value, type).put(mv)
|
||||||
return expression.onStack
|
return expression.onStack
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -643,7 +643,7 @@ class ExpressionCodegen(
|
|||||||
val elementKotlinType = classCodegen.context.builtIns.getArrayElementType(outType.toKotlinType()!!)
|
val elementKotlinType = classCodegen.context.builtIns.getArrayElementType(outType.toKotlinType()!!)
|
||||||
for ((i, element) in expression.elements.withIndex()) {
|
for ((i, element) in expression.elements.withIndex()) {
|
||||||
mv.dup()
|
mv.dup()
|
||||||
StackValue.constant(i).put(Type.INT_TYPE, mv)
|
StackValue.constant(i).put(mv)
|
||||||
val rightSide = gen(element, elementType, data)
|
val rightSide = gen(element, elementType, data)
|
||||||
StackValue
|
StackValue
|
||||||
.arrayElement(
|
.arrayElement(
|
||||||
@@ -822,7 +822,7 @@ class ExpressionCodegen(
|
|||||||
val type = boxType(asmType)
|
val type = boxType(asmType)
|
||||||
generateIsCheck(mv, expression.typeOperand.toKotlinType(), type, state.languageVersionSettings.isReleaseCoroutines())
|
generateIsCheck(mv, expression.typeOperand.toKotlinType(), type, state.languageVersionSettings.isReleaseCoroutines())
|
||||||
if (IrTypeOperator.NOT_INSTANCEOF == expression.operator) {
|
if (IrTypeOperator.NOT_INSTANCEOF == expression.operator) {
|
||||||
StackValue.not(StackValue.onStack(Type.BOOLEAN_TYPE)).put(Type.BOOLEAN_TYPE, mv)
|
StackValue.not(StackValue.onStack(Type.BOOLEAN_TYPE)).put(mv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.codegen.AsmUtil.boxType
|
|||||||
import org.jetbrains.kotlin.codegen.AsmUtil.isPrimitive
|
import org.jetbrains.kotlin.codegen.AsmUtil.isPrimitive
|
||||||
import org.jetbrains.kotlin.codegen.StackValue
|
import org.jetbrains.kotlin.codegen.StackValue
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||||
import org.jetbrains.kotlin.resolve.jvm.AsmTypes
|
|
||||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||||
import org.jetbrains.org.objectweb.asm.Type
|
import org.jetbrains.org.objectweb.asm.Type
|
||||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
||||||
@@ -38,7 +37,7 @@ object JavaClassProperty : IntrinsicMethod() {
|
|||||||
val type = value.type
|
val type = value.type
|
||||||
when {
|
when {
|
||||||
type == Type.VOID_TYPE -> {
|
type == Type.VOID_TYPE -> {
|
||||||
StackValue.unit().put(AsmTypes.UNIT_TYPE, v)
|
StackValue.unit().put(v)
|
||||||
v.invokevirtual("java/lang/Object", "getClass", "()Ljava/lang/Class;", false)
|
v.invokevirtual("java/lang/Object", "getClass", "()Ljava/lang/Class;", false)
|
||||||
}
|
}
|
||||||
isPrimitive(type) -> {
|
isPrimitive(type) -> {
|
||||||
|
|||||||
@@ -17,8 +17,10 @@
|
|||||||
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
package org.jetbrains.kotlin.backend.jvm.intrinsics
|
||||||
|
|
||||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||||
import org.jetbrains.kotlin.codegen.*
|
import org.jetbrains.kotlin.codegen.Callable
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrCall
|
import org.jetbrains.kotlin.codegen.CallableMethod
|
||||||
|
import org.jetbrains.kotlin.codegen.ExpressionCodegen
|
||||||
|
import org.jetbrains.kotlin.codegen.StackValue
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||||
import org.jetbrains.kotlin.psi.KtPrefixExpression
|
import org.jetbrains.kotlin.psi.KtPrefixExpression
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||||
@@ -28,7 +30,7 @@ import org.jetbrains.org.objectweb.asm.Type
|
|||||||
class Not : IntrinsicMethod() {
|
class Not : IntrinsicMethod() {
|
||||||
override fun toCallable(expression: IrMemberAccessExpression, signature: JvmMethodSignature, context: JvmBackendContext): IrIntrinsicFunction {
|
override fun toCallable(expression: IrMemberAccessExpression, signature: JvmMethodSignature, context: JvmBackendContext): IrIntrinsicFunction {
|
||||||
return IrIntrinsicFunction.create(expression, signature, context) {
|
return IrIntrinsicFunction.create(expression, signature, context) {
|
||||||
StackValue.not(StackValue.onStack(Type.BOOLEAN_TYPE)).put(Type.BOOLEAN_TYPE, it)
|
StackValue.not(StackValue.onStack(Type.BOOLEAN_TYPE)).put(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user