From d685921271007d7a10d3b17ef39eb68c0b318751 Mon Sep 17 00:00:00 2001 From: Michael Bogdanov Date: Wed, 19 Nov 2014 15:13:06 +0300 Subject: [PATCH] Review fixes --- .../org/jetbrains/jet/codegen/AsmUtil.java | 8 +++- .../jet/codegen/ExpressionCodegen.java | 12 ++--- .../org/jetbrains/jet/codegen/StackValue.java | 47 ++++++++++--------- .../org/jetbrains/jet/codegen/StackValue.kt | 13 +---- 4 files changed, 36 insertions(+), 44 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/AsmUtil.java b/compiler/backend/src/org/jetbrains/jet/codegen/AsmUtil.java index e3856eb1ab1..323582ae938 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/AsmUtil.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/AsmUtil.java @@ -784,12 +784,16 @@ public class AsmUtil { } public static void dup(@NotNull InstructionAdapter v, @NotNull Type type) { - if (type.getSize() == 2) { + int size = type.getSize(); + if (size == 2) { v.dup2(); } - else { + else if (size == 1) { v.dup(); } + else { + throw new UnsupportedOperationException(); + } } public static void writeKotlinSyntheticClassAnnotation(@NotNull ClassBuilder v, @NotNull KotlinSyntheticClass.Kind kind) { diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index 147daa340bf..9f3c15f19c9 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -1603,16 +1603,10 @@ public class ExpressionCodegen extends JetVisitor implem int index = myFrameMap.leave(variableDescriptor); if (sharedVarType != null) { - /*if (answer instanceof StackValue.Shared && index == ((StackValue.Shared) answer).getIndex()) { - ((StackValue.Shared) answer).releaseOnPut(); - } - else {*/ - v.aconst(null); - v.store(index, OBJECT_TYPE); - //} + v.aconst(null); + v.store(index, OBJECT_TYPE); } - v.visitLocalVariable(variableDescriptor.getName().asString(), type.getDescriptor(), null, scopeStart, blockEnd, - index); + v.visitLocalVariable(variableDescriptor.getName().asString(), type.getDescriptor(), null, scopeStart, blockEnd, index); return null; } }); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java index b41ec94256b..5634cb9e447 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java @@ -104,15 +104,15 @@ public abstract class StackValue { return false; } - public void putReceiver(@NotNull InstructionAdapter v, boolean isRead) {} + + public void putReceiver(@NotNull InstructionAdapter v, boolean isRead) { + //by default there is no receiver + //if you have it inherit StackValueWithSimpleReceiver + } public void dup(@NotNull InstructionAdapter v, boolean withReceiver) { - switch (type.getSize()) { - case 0: break; - case 1: v.dup(); break; - case 2: v.dup2(); break; - default: - throw new UnsupportedOperationException(); + if (!Type.VOID_TYPE.equals(type)) { + AsmUtil.dup(v, type); } } @@ -132,8 +132,8 @@ public abstract class StackValue { storeSelector(value.type, v); } - public void storeSelector(@NotNull Type topOfStackType, @NotNull InstructionAdapter v) { - throw new UnsupportedOperationException("cannot store to value " + this); + protected void storeSelector(@NotNull Type topOfStackType, @NotNull InstructionAdapter v) { + throw new UnsupportedOperationException("Cannot store to value " + this); } public void condJump(@NotNull Label label, boolean jumpIfFalse, @NotNull InstructionAdapter v) { @@ -1482,8 +1482,9 @@ public abstract class StackValue { @Override public void dup(@NotNull InstructionAdapter v, boolean withWriteReceiver) { if (!withWriteReceiver) { - super.dup(v, withWriteReceiver); - } else { + super.dup(v, false); + } + else { int receiverSize = isNonStaticAccess(false) ? receiverSize() : 0; switch (receiverSize) { case 0: @@ -1529,9 +1530,9 @@ public abstract class StackValue { static class ComplexReceiver extends StackValue { private final StackValueWithSimpleReceiver originalValueWithReceiver; - private final boolean [] isReadOperations; + private final boolean[] isReadOperations; - public ComplexReceiver(StackValueWithSimpleReceiver value, boolean [] isReadOperations) { + public ComplexReceiver(StackValueWithSimpleReceiver value, boolean[] isReadOperations) { super(value.type, value.receiver.hasSideEffects()); this.originalValueWithReceiver = value; this.isReadOperations = isReadOperations; @@ -1541,20 +1542,21 @@ public abstract class StackValue { public void putSelector( @NotNull Type type, @NotNull InstructionAdapter v ) { - boolean wasPutted = false; + boolean wasPut = false; StackValue receiver = originalValueWithReceiver.receiver; for (boolean operation : isReadOperations) { if (originalValueWithReceiver.isNonStaticAccess(operation)) { - if (!wasPutted) { + if (!wasPut) { receiver.put(receiver.type, v); - wasPutted = true; - } else { + wasPut = true; + } + else { receiver.dup(v, false); } } } - if (!wasPutted && receiver.hasSideEffects()) { + if (!wasPut && receiver.hasSideEffects()) { receiver.put(Type.VOID_TYPE, v); } } @@ -1564,7 +1566,7 @@ public abstract class StackValue { private final StackValue[] instructions; - protected Receiver(@NotNull Type type, StackValue ... receiverInstructions) { + protected Receiver(@NotNull Type type, StackValue... receiverInstructions) { super(type); instructions = receiverInstructions; } @@ -1586,7 +1588,7 @@ public abstract class StackValue { public DelegatedForComplexReceiver( @NotNull Type type, @NotNull StackValueWithSimpleReceiver originalValue, - @NotNull StackValue receiver + @NotNull ComplexReceiver receiver ) { super(type, bothReceiverStatic(originalValue), bothReceiverStatic(originalValue), receiver, originalValue.hasSideEffects()); this.originalValue = originalValue; @@ -1620,11 +1622,12 @@ public abstract class StackValue { return complexReceiver(stackValue, false, true); } - private static StackValue complexReceiver(StackValue stackValue, boolean ... isReadOperations) { + private static StackValue complexReceiver(StackValue stackValue, boolean... isReadOperations) { if (stackValue instanceof StackValueWithSimpleReceiver) { return new DelegatedForComplexReceiver(stackValue.type, (StackValueWithSimpleReceiver) stackValue, new ComplexReceiver((StackValueWithSimpleReceiver) stackValue, isReadOperations)); - } else { + } + else { return stackValue; } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.kt b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.kt index 0c1cd909980..54e985d2ae5 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.kt +++ b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.kt @@ -54,11 +54,6 @@ public class StackValueWithLeaveTask( val leaveTasks: StackValueWithLeaveTask.() -> Unit ) : StackValue(stackValue.type) { - override fun put(type: Type, v: InstructionAdapter, skipReceiver: Boolean) { - stackValue.put(type, v, skipReceiver) - leaveTasks() - } - override fun condJump(label: Label, jumpIfFalse: Boolean, v: InstructionAdapter) { stackValue.condJump(label, jumpIfFalse, v) leaveTasks() @@ -69,12 +64,8 @@ public class StackValueWithLeaveTask( } override fun putSelector(type: Type, v: InstructionAdapter) { - throw UnsupportedOperationException() - } - - - override fun storeSelector(topOfStackType: Type, v: InstructionAdapter) { - throw UnsupportedOperationException(); + stackValue.putSelector(type, v) + leaveTasks() } }