Get rid of store
This commit is contained in:
@@ -656,7 +656,7 @@ public class AsmUtil {
|
|||||||
return new StackValue.StackValueWithoutReceiver(stackValue.type) {
|
return new StackValue.StackValueWithoutReceiver(stackValue.type) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void put(Type type, InstructionAdapter v) {
|
public void put(@NotNull Type type, @NotNull InstructionAdapter v) {
|
||||||
stackValue.put(type, v);
|
stackValue.put(type, v);
|
||||||
if (type.getSort() == Type.OBJECT || type.getSort() == Type.ARRAY) {
|
if (type.getSort() == Type.OBJECT || type.getSort() == Type.ARRAY) {
|
||||||
v.dup();
|
v.dup();
|
||||||
|
|||||||
@@ -3140,7 +3140,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
if (Boolean.TRUE.equals(bindingContext.get(VARIABLE_REASSIGNMENT, expression))) {
|
if (Boolean.TRUE.equals(bindingContext.get(VARIABLE_REASSIGNMENT, expression))) {
|
||||||
if (callable instanceof IntrinsicMethod) {
|
if (callable instanceof IntrinsicMethod) {
|
||||||
StackValue value = gen(lhs); // receiver
|
StackValue value = gen(lhs); // receiver
|
||||||
value = StackValue.complexReceiver(value, StackValue.RECEIVER_WRITE, StackValue.RECEIVER_READ);
|
value = StackValue.complexWriteReadReceiver(value);
|
||||||
|
|
||||||
value.put(lhsType, v); // receiver lhs
|
value.put(lhsType, v); // receiver lhs
|
||||||
Type returnType = typeMapper.mapType(descriptor);
|
Type returnType = typeMapper.mapType(descriptor);
|
||||||
@@ -3171,7 +3171,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
) {
|
) {
|
||||||
StackValue value = gen(expression.getLeft());
|
StackValue value = gen(expression.getLeft());
|
||||||
if (keepReturnValue) {
|
if (keepReturnValue) {
|
||||||
value = StackValue.complexReceiver(value, StackValue.RECEIVER_WRITE, StackValue.RECEIVER_READ);
|
value = StackValue.complexWriteReadReceiver(value);
|
||||||
//value.putWriteReadReceiver(v);
|
//value.putWriteReadReceiver(v);
|
||||||
}
|
}
|
||||||
value.put(lhsType, v);
|
value.put(lhsType, v);
|
||||||
@@ -3180,7 +3180,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
invokeMethodWithArguments(callable, resolvedCall, receiver);
|
invokeMethodWithArguments(callable, resolvedCall, receiver);
|
||||||
|
|
||||||
if (keepReturnValue) {
|
if (keepReturnValue) {
|
||||||
value.store(callable.getReturnType(), v);
|
value.store(StackValue.onStack(callable.getReturnType()), v, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3307,12 +3307,12 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
@Override
|
@Override
|
||||||
public Unit invoke(InstructionAdapter adapter) {
|
public Unit invoke(InstructionAdapter adapter) {
|
||||||
StackValue value = gen(expression.getBaseExpression());
|
StackValue value = gen(expression.getBaseExpression());
|
||||||
value = StackValue.complexReceiver(value, StackValue.RECEIVER_WRITE, StackValue.RECEIVER_READ);
|
value = StackValue.complexWriteReadReceiver(value);
|
||||||
|
|
||||||
Type type = expressionType(expression.getBaseExpression());
|
Type type = expressionType(expression.getBaseExpression());
|
||||||
value.put(type, v); // old value
|
value.put(type, v); // old value
|
||||||
|
|
||||||
pushReceiverAndValueViaDup(value, type); // receiver and new value
|
value.dup(v, true);
|
||||||
|
|
||||||
Type storeType;
|
Type storeType;
|
||||||
if (isPrimitiveNumberClassDescriptor && AsmUtil.isPrimitive(asmBaseType)) {
|
if (isPrimitiveNumberClassDescriptor && AsmUtil.isPrimitive(asmBaseType)) {
|
||||||
@@ -3325,16 +3325,12 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
storeType = result.type;
|
storeType = result.type;
|
||||||
}
|
}
|
||||||
|
|
||||||
value.store(storeType, v);
|
value.store(StackValue.onStack(storeType), v, true);
|
||||||
return Unit.INSTANCE$;
|
return Unit.INSTANCE$;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pushReceiverAndValueViaDup(StackValue value, Type type) {
|
|
||||||
value.dup(v, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StackValue visitProperty(@NotNull JetProperty property, StackValue receiver) {
|
public StackValue visitProperty(@NotNull JetProperty property, StackValue receiver) {
|
||||||
final JetExpression initializer = property.getInitializer();
|
final JetExpression initializer = property.getInitializer();
|
||||||
|
|||||||
@@ -917,7 +917,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
property.put(property.type, iv);
|
property.put(property.type, iv);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
property.store(property.type, iv);
|
property.store(StackValue.onStack(property.type), iv, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
iv.areturn(signature.getReturnType());
|
iv.areturn(signature.getReturnType());
|
||||||
@@ -1072,7 +1072,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
ExpressionCodegen codegen = createOrGetClInitCodegen();
|
ExpressionCodegen codegen = createOrGetClInitCodegen();
|
||||||
FunctionDescriptor constructor = codegen.accessibleFunctionDescriptor(KotlinPackage.single(classObject.getConstructors()));
|
FunctionDescriptor constructor = codegen.accessibleFunctionDescriptor(KotlinPackage.single(classObject.getConstructors()));
|
||||||
generateMethodCallTo(constructor, codegen.v);
|
generateMethodCallTo(constructor, codegen.v);
|
||||||
StackValue.singleton(classObject, typeMapper).store(typeMapper.mapClass(classObject), codegen.v);
|
StackValue.singleton(classObject, typeMapper).store(StackValue.onStack(typeMapper.mapClass(classObject)), codegen.v, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void generatePrimaryConstructor(final DelegationFieldsInfo delegationFieldsInfo) {
|
private void generatePrimaryConstructor(final DelegationFieldsInfo delegationFieldsInfo) {
|
||||||
|
|||||||
@@ -433,7 +433,7 @@ public abstract class StackValue implements StackValueI {
|
|||||||
|
|
||||||
public static Field singleton(ClassDescriptor classDescriptor, JetTypeMapper typeMapper) {
|
public static Field singleton(ClassDescriptor classDescriptor, JetTypeMapper typeMapper) {
|
||||||
FieldInfo info = FieldInfo.createForSingleton(classDescriptor, typeMapper);
|
FieldInfo info = FieldInfo.createForSingleton(classDescriptor, typeMapper);
|
||||||
return field(info.getFieldType(), Type.getObjectType(info.getOwnerInternalName()), info.getFieldName(), true, StackValue.none());
|
return field(info.getFieldType(), Type.getObjectType(info.getOwnerInternalName()), info.getFieldName(), true, none());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StackValue operation(Type type, Function1<InstructionAdapter, Unit> lambda) {
|
public static StackValue operation(Type type, Function1<InstructionAdapter, Unit> lambda) {
|
||||||
@@ -552,7 +552,7 @@ public abstract class StackValue implements StackValueI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void condJump(Label label, boolean jumpIfFalse, InstructionAdapter v) {
|
public void condJump(@NotNull Label label, boolean jumpIfFalse, @NotNull InstructionAdapter v) {
|
||||||
if (value instanceof Boolean) {
|
if (value instanceof Boolean) {
|
||||||
boolean boolValue = (Boolean) value;
|
boolean boolValue = (Boolean) value;
|
||||||
if (boolValue ^ jumpIfFalse) {
|
if (boolValue ^ jumpIfFalse) {
|
||||||
@@ -586,7 +586,7 @@ public abstract class StackValue implements StackValueI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void condJump(Label label, boolean jumpIfFalse, InstructionAdapter v) {
|
public void condJump(@NotNull Label label, boolean jumpIfFalse, @NotNull InstructionAdapter v) {
|
||||||
left.put(this.operandType, v);
|
left.put(this.operandType, v);
|
||||||
right.put(this.operandType, v);
|
right.put(this.operandType, v);
|
||||||
int opcode;
|
int opcode;
|
||||||
@@ -635,7 +635,7 @@ public abstract class StackValue implements StackValueI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void condJump(Label label, boolean jumpIfFalse, InstructionAdapter v) {
|
public void condJump(@NotNull Label label, boolean jumpIfFalse, @NotNull InstructionAdapter v) {
|
||||||
left.put(this.operandType, v);
|
left.put(this.operandType, v);
|
||||||
right.put(this.operandType, v);
|
right.put(this.operandType, v);
|
||||||
int opcode;
|
int opcode;
|
||||||
@@ -670,7 +670,7 @@ public abstract class StackValue implements StackValueI {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void condJump(Label label, boolean jumpIfFalse, InstructionAdapter v) {
|
public void condJump(@NotNull Label label, boolean jumpIfFalse, @NotNull InstructionAdapter v) {
|
||||||
myOperand.condJump(label, !jumpIfFalse, v);
|
myOperand.condJump(label, !jumpIfFalse, v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1278,9 +1278,9 @@ public abstract class StackValue implements StackValueI {
|
|||||||
|
|
||||||
private static class PrefixIncrement extends StackValueWithoutReceiver {
|
private static class PrefixIncrement extends StackValueWithoutReceiver {
|
||||||
private final int delta;
|
private final int delta;
|
||||||
private Callable callable;
|
private final Callable callable;
|
||||||
private ResolvedCall resolvedCall;
|
private final ResolvedCall resolvedCall;
|
||||||
private ExpressionCodegen codegen;
|
private final ExpressionCodegen codegen;
|
||||||
private StackValue value;
|
private StackValue value;
|
||||||
|
|
||||||
public PrefixIncrement(
|
public PrefixIncrement(
|
||||||
@@ -1309,10 +1309,10 @@ public abstract class StackValue implements StackValueI {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
genIncrement(this.type, delta, v);
|
genIncrement(this.type, delta, v);
|
||||||
value.store(this.type, v);
|
value.store(StackValue.onStack(this.type), v, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
StackValue.putNoReceiver(value, this.type, v);
|
putNoReceiver(value, this.type, v);
|
||||||
coerceTo(type, v);
|
coerceTo(type, v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1460,6 +1460,7 @@ public abstract class StackValue implements StackValueI {
|
|||||||
@Override
|
@Override
|
||||||
public abstract void putNoReceiver(@NotNull Type type, @NotNull InstructionAdapter v);
|
public abstract void putNoReceiver(@NotNull Type type, @NotNull InstructionAdapter v);
|
||||||
|
|
||||||
|
@Override
|
||||||
public void putReceiver(@NotNull InstructionAdapter v, boolean isRead) {
|
public void putReceiver(@NotNull InstructionAdapter v, boolean isRead) {
|
||||||
if (hasReceiver(isRead)) {
|
if (hasReceiver(isRead)) {
|
||||||
receiver.put(receiver.type, v);
|
receiver.put(receiver.type, v);
|
||||||
@@ -1498,7 +1499,7 @@ public abstract class StackValue implements StackValueI {
|
|||||||
@Override
|
@Override
|
||||||
public void dup(@NotNull InstructionAdapter v, boolean withReceiver) {
|
public void dup(@NotNull InstructionAdapter v, boolean withReceiver) {
|
||||||
if (!withReceiver) {
|
if (!withReceiver) {
|
||||||
super.dup(v, withReceiver);
|
super.dup(v, false);
|
||||||
} else {
|
} else {
|
||||||
int receiverSize = hasReceiver(false) && hasReceiver(true) ? receiverSize() : 0;
|
int receiverSize = hasReceiver(false) && hasReceiver(true) ? receiverSize() : 0;
|
||||||
switch (receiverSize) {
|
switch (receiverSize) {
|
||||||
@@ -1646,7 +1647,11 @@ public abstract class StackValue implements StackValueI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static StackValue complexReceiver(StackValue stackValue, int ... operations) {
|
public static StackValue complexWriteReadReceiver(StackValue stackValue) {
|
||||||
|
return complexReceiver(stackValue, RECEIVER_WRITE, RECEIVER_READ);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static StackValue complexReceiver(StackValue stackValue, int ... operations) {
|
||||||
if (stackValue instanceof StackValueWithoutReceiver) {
|
if (stackValue instanceof StackValueWithoutReceiver) {
|
||||||
return stackValue;
|
return stackValue;
|
||||||
} else {
|
} else {
|
||||||
@@ -1659,7 +1664,7 @@ public abstract class StackValue implements StackValueI {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void putNoReceiver(StackValue value, Type type, InstructionAdapter iv) {
|
private static void putNoReceiver(StackValue value, Type type, InstructionAdapter iv) {
|
||||||
if (value instanceof StackValueWithSimpleReceiver) {
|
if (value instanceof StackValueWithSimpleReceiver) {
|
||||||
((StackValueWithSimpleReceiver) value).putNoReceiver(type, iv);
|
((StackValueWithSimpleReceiver) value).putNoReceiver(type, iv);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public class TailRecursionCodegen {
|
|||||||
if (callable.getReceiverClass() != null) {
|
if (callable.getReceiverClass() != null) {
|
||||||
if (resolvedCall.getExtensionReceiver() != fd.getExtensionReceiverParameter().getValue()) {
|
if (resolvedCall.getExtensionReceiver() != fd.getExtensionReceiverParameter().getValue()) {
|
||||||
StackValue expression = context.getReceiverExpression(codegen.typeMapper);
|
StackValue expression = context.getReceiverExpression(codegen.typeMapper);
|
||||||
expression.store(callable.getReceiverClass(), v);
|
expression.store(StackValue.onStack(callable.getReceiverClass()), v, true);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
AsmUtil.pop(v, callable.getReceiverClass());
|
AsmUtil.pop(v, callable.getReceiverClass());
|
||||||
|
|||||||
Reference in New Issue
Block a user