Minor, add helper StackValue.constant(int)

This commit is contained in:
Alexander Udalov
2018-04-19 17:24:12 +02:00
parent 22a9cecfe0
commit 285912f556
7 changed files with 11 additions and 9 deletions
@@ -2937,7 +2937,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
v.dup();
StackValue rightSide = gen(arguments.get(i).getArgumentExpression());
StackValue
.arrayElement(elementType, elementKotlinType, StackValue.onStack(type, outType), StackValue.constant(i, Type.INT_TYPE))
.arrayElement(elementType, elementKotlinType, StackValue.onStack(type, outType), StackValue.constant(i))
.store(rightSide, v);
}
return Unit.INSTANCE;
@@ -603,7 +603,7 @@ public class PropertyCodegen {
StackValue.Field array = StackValue.field(
Type.getType("[" + K_PROPERTY_TYPE), owner, JvmAbi.DELEGATED_PROPERTIES_ARRAY_NAME, true, StackValue.none()
);
return StackValue.arrayElement(K_PROPERTY_TYPE, null, array, StackValue.constant(index, Type.INT_TYPE));
return StackValue.arrayElement(K_PROPERTY_TYPE, null, array, StackValue.constant(index));
}
private static class DelegatedPropertyAccessorStrategy extends FunctionGenerationStrategy.CodegenBased {
@@ -213,6 +213,11 @@ public abstract class StackValue {
}
}
@NotNull
public static StackValue constant(int value) {
return constant(value, Type.INT_TYPE);
}
@NotNull
public static StackValue constant(@Nullable Object value, @NotNull Type type) {
return constant(value, type, null);
@@ -47,8 +47,7 @@ class ArrayWithIndexForLoopGenerator(
v.arraylength()
v.store(arrayLengthVar, Type.INT_TYPE)
StackValue.local(indexVar, indexType)
.store(StackValue.constant(0, Type.INT_TYPE), v)
StackValue.local(indexVar, indexType).store(StackValue.constant(0), v)
}
override fun checkPreCondition(loopExit: Label) {
@@ -44,8 +44,7 @@ class CharSequenceWithIndexForLoopGenerator(
indexVar = indexLoopComponent?.parameterVar ?: createLoopTempVariable(Type.INT_TYPE)
indexType = indexLoopComponent?.parameterType ?: Type.INT_TYPE
StackValue.local(indexVar, indexType)
.store(StackValue.constant(0, Type.INT_TYPE), v)
StackValue.local(indexVar, indexType).store(StackValue.constant(0), v)
}
private fun evalCharSeqLengthOnStack() {
@@ -34,8 +34,7 @@ class IteratorWithIndexForLoopGenerator(
indexVar = indexLoopComponent?.parameterVar ?: createLoopTempVariable(Type.INT_TYPE)
indexType = indexLoopComponent?.parameterType ?: Type.INT_TYPE
StackValue.local(indexVar, indexType)
.store(StackValue.constant(0, Type.INT_TYPE), v)
StackValue.local(indexVar, indexType).store(StackValue.constant(0), v)
iteratorVar = createLoopTempVariable(asmTypeForIterator)
codegen.generateCallReceiver(rangeCall).put(iteratorOwnerType, v)
@@ -507,7 +507,7 @@ class ExpressionCodegen(
val elementKotlinType = classCodegen.context.builtIns.getArrayElementType(outType.toKotlinType()!!)
for ((i, element) in expression.elements.withIndex()) {
mv.dup()
StackValue.constant(i, Type.INT_TYPE).put(Type.INT_TYPE, mv)
StackValue.constant(i).put(Type.INT_TYPE, mv)
val rightSide = gen(element, elementType, data)
StackValue
.arrayElement(