KT-846: better (and correct) names for shared vars
This commit is contained in:
committed by
Nikolay Krasko
parent
fb27805c68
commit
a984b609bc
@@ -23,6 +23,7 @@ import org.objectweb.asm.commons.InstructionAdapter;
|
|||||||
import org.objectweb.asm.commons.Method;
|
import org.objectweb.asm.commons.Method;
|
||||||
import org.objectweb.asm.signature.SignatureWriter;
|
import org.objectweb.asm.signature.SignatureWriter;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -213,9 +214,12 @@ public class ClosureCodegen extends ObjectOrClosureCodegen {
|
|||||||
int argCount = captureThis ? 1 : 0;
|
int argCount = captureThis ? 1 : 0;
|
||||||
argCount += (captureReceiver != null ? 1 : 0);
|
argCount += (captureReceiver != null ? 1 : 0);
|
||||||
|
|
||||||
|
ArrayList<VariableDescriptor> variableDescriptors = new ArrayList<VariableDescriptor>();
|
||||||
|
|
||||||
for (DeclarationDescriptor descriptor : closure.keySet()) {
|
for (DeclarationDescriptor descriptor : closure.keySet()) {
|
||||||
if(descriptor instanceof VariableDescriptor && !(descriptor instanceof PropertyDescriptor)) {
|
if(descriptor instanceof VariableDescriptor && !(descriptor instanceof PropertyDescriptor)) {
|
||||||
argCount++;
|
argCount++;
|
||||||
|
variableDescriptors.add((VariableDescriptor) descriptor);
|
||||||
}
|
}
|
||||||
else if(descriptor instanceof FunctionDescriptor) {
|
else if(descriptor instanceof FunctionDescriptor) {
|
||||||
assert captureReceiver != null;
|
assert captureReceiver != null;
|
||||||
@@ -271,7 +275,8 @@ public class ClosureCodegen extends ObjectOrClosureCodegen {
|
|||||||
k++;
|
k++;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fieldName = "$" + (i-k);
|
VariableDescriptor removed = variableDescriptors.remove(0);
|
||||||
|
fieldName = "$" + removed.getName();
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -494,7 +494,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
iv.load(0, JetTypeMapper.TYPE_OBJECT);
|
iv.load(0, JetTypeMapper.TYPE_OBJECT);
|
||||||
iv.load(k, StackValue.refType(sharedVarType));
|
iv.load(k, StackValue.refType(sharedVarType));
|
||||||
k += StackValue.refType(sharedVarType).getSize();
|
k += StackValue.refType(sharedVarType).getSize();
|
||||||
iv.putfield(typeMapper.mapType(descriptor.getDefaultType(), OwnerKind.IMPLEMENTATION).getInternalName(), "$" + (l+1), sharedVarType.getDescriptor());
|
iv.putfield(typeMapper.mapType(descriptor.getDefaultType(), OwnerKind.IMPLEMENTATION).getInternalName(), "$" + varDescr.getName(), sharedVarType.getDescriptor());
|
||||||
l++;
|
l++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ public class ObjectOrClosureCodegen {
|
|||||||
final Type type = sharedVarType != null ? sharedVarType : localType;
|
final Type type = sharedVarType != null ? sharedVarType : localType;
|
||||||
|
|
||||||
StackValue outerValue = StackValue.local(idx, type);
|
StackValue outerValue = StackValue.local(idx, type);
|
||||||
final String fieldName = "$" + (closure.size() + 1); // + "$" + vd.getName();
|
final String fieldName = "$" + vd.getName();
|
||||||
StackValue innerValue = sharedVarType != null ? StackValue.fieldForSharedVar(localType, name, fieldName) : StackValue.field(type, name, fieldName, false);
|
StackValue innerValue = sharedVarType != null ? StackValue.fieldForSharedVar(localType, name, fieldName) : StackValue.field(type, name, fieldName, false);
|
||||||
|
|
||||||
cv.newField(null, Opcodes.ACC_PUBLIC, fieldName, type.getDescriptor(), null, null);
|
cv.newField(null, Opcodes.ACC_PUBLIC, fieldName, type.getDescriptor(), null, null);
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
fun <T> T.mustBe(t : T) {
|
||||||
|
assert("$this must be $t") {this == t}
|
||||||
|
}
|
||||||
|
|
||||||
|
inline fun assert(message : String, condition : fun() : Boolean) {
|
||||||
|
if (!condition())
|
||||||
|
throw AssertionError(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box() : String {
|
||||||
|
"lala" mustBe "lala"
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
/*
|
|
||||||
fun s0() : Boolean {
|
fun s0() : Boolean {
|
||||||
val y = "222"
|
val y = "222"
|
||||||
val foo = {
|
val foo = {
|
||||||
@@ -127,7 +126,7 @@ fun t8() : Boolean {
|
|||||||
return x == 30.sht
|
return x == 30.sht
|
||||||
}
|
}
|
||||||
|
|
||||||
fun t9(x: Int) : Boolean {
|
fun t9(var x: Int) : Boolean {
|
||||||
while(x < 100) {
|
while(x < 100) {
|
||||||
x++
|
x++
|
||||||
}
|
}
|
||||||
@@ -146,7 +145,7 @@ fun t10() : Boolean {
|
|||||||
return y == 2
|
return y == 2
|
||||||
}
|
}
|
||||||
|
|
||||||
fun t11(x: Int) : Int {
|
fun t11(var x: Int) : Int {
|
||||||
val foo = {
|
val foo = {
|
||||||
x = x + 1
|
x = x + 1
|
||||||
val bar = {
|
val bar = {
|
||||||
@@ -160,7 +159,7 @@ fun t11(x: Int) : Int {
|
|||||||
}
|
}
|
||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
fun t12(x: Int) : Int {
|
fun t12(x: Int) : Int {
|
||||||
var y = x
|
var y = x
|
||||||
val runnable = object : Runnable {
|
val runnable = object : Runnable {
|
||||||
@@ -175,7 +174,6 @@ fun t12(x: Int) : Int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
/*
|
|
||||||
if (!s0()) return "s0 fail"
|
if (!s0()) return "s0 fail"
|
||||||
if (!s1()) return "s1 fail"
|
if (!s1()) return "s1 fail"
|
||||||
if (!t1()) return "t1 fail"
|
if (!t1()) return "t1 fail"
|
||||||
@@ -189,7 +187,6 @@ fun box(): String {
|
|||||||
if (!t9(0)) return "t9 fail"
|
if (!t9(0)) return "t9 fail"
|
||||||
if (!t10()) return "t10 fail"
|
if (!t10()) return "t10 fail"
|
||||||
if (t11(1) != 104) return "t11 fail"
|
if (t11(1) != 104) return "t11 fail"
|
||||||
*/
|
|
||||||
if (t12(0) != 100) return "t12 fail"
|
if (t12(0) != 100) return "t12 fail"
|
||||||
|
|
||||||
return "OK"
|
return "OK"
|
||||||
|
|||||||
@@ -34,6 +34,11 @@ public class ExtensionFunctionsTest extends CodegenTestCase {
|
|||||||
blackBoxFile("extensionFunctions/virtual.jet");
|
blackBoxFile("extensionFunctions/virtual.jet");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testShared() throws Exception {
|
||||||
|
blackBoxFile("extensionFunctions/shared.kt");
|
||||||
|
System.out.println(generateToText());
|
||||||
|
}
|
||||||
|
|
||||||
public void testKt475() throws Exception {
|
public void testKt475() throws Exception {
|
||||||
blackBoxFile("regressions/kt475.jet");
|
blackBoxFile("regressions/kt475.jet");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,12 +40,13 @@ inline fun FloatArray.binarySearch(fromIndex: Int, toIndex: Int, key: Float) =
|
|||||||
inline fun DoubleArray.binarySearch(fromIndex: Int, toIndex: Int, key: Double) = Arrays.binarySearch(this, fromIndex, toIndex, key)
|
inline fun DoubleArray.binarySearch(fromIndex: Int, toIndex: Int, key: Double) = Arrays.binarySearch(this, fromIndex, toIndex, key)
|
||||||
inline fun CharArray.binarySearch(fromIndex: Int, toIndex: Int, key: Char) = Arrays.binarySearch(this, fromIndex, toIndex, key)
|
inline fun CharArray.binarySearch(fromIndex: Int, toIndex: Int, key: Char) = Arrays.binarySearch(this, fromIndex, toIndex, key)
|
||||||
|
|
||||||
|
/*
|
||||||
inline fun <T> Array<T>.binarySearch(key: T, comparator: fun(T,T):Int) = Arrays.binarySearch(this, key, object: java.util.Comparator<T> {
|
inline fun <T> Array<T>.binarySearch(key: T, comparator: fun(T,T):Int) = Arrays.binarySearch(this, key, object: java.util.Comparator<T> {
|
||||||
override fun compare(a: T, b: T) = comparator(a, b)
|
override fun compare(a: T, b: T) = comparator(a, b)
|
||||||
|
|
||||||
override fun equals(obj: Any?) = obj.identityEquals(this)
|
override fun equals(obj: Any?) = obj.identityEquals(this)
|
||||||
})
|
})
|
||||||
|
*/
|
||||||
inline fun BooleanArray.fill(value: Boolean) = Arrays.fill(this, value)
|
inline fun BooleanArray.fill(value: Boolean) = Arrays.fill(this, value)
|
||||||
inline fun ByteArray.fill(value: Byte) = Arrays.fill(this, value)
|
inline fun ByteArray.fill(value: Byte) = Arrays.fill(this, value)
|
||||||
inline fun ShortArray.fill(value: Short) = Arrays.fill(this, value)
|
inline fun ShortArray.fill(value: Short) = Arrays.fill(this, value)
|
||||||
|
|||||||
Reference in New Issue
Block a user