intrinsics for array constructors (half way for array annotations)
This commit is contained in:
@@ -1511,21 +1511,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
}
|
}
|
||||||
else if(resolvedValueArgument instanceof VarargValueArgument) {
|
else if(resolvedValueArgument instanceof VarargValueArgument) {
|
||||||
VarargValueArgument valueArgument = (VarargValueArgument) resolvedValueArgument;
|
VarargValueArgument valueArgument = (VarargValueArgument) resolvedValueArgument;
|
||||||
JetType outType = valueParameterDescriptor.getType();
|
genVarargs(valueParameterDescriptor, valueArgument);
|
||||||
|
|
||||||
Type type = asmType(outType);
|
|
||||||
assert type.getSort() == Type.ARRAY;
|
|
||||||
Type elementType = correctElementType(type);
|
|
||||||
int size = valueArgument.getArguments().size();
|
|
||||||
|
|
||||||
v.iconst(valueArgument.getArguments().size());
|
|
||||||
v.newarray(elementType);
|
|
||||||
for(int i = 0; i != size; ++i) {
|
|
||||||
v.dup();
|
|
||||||
v.iconst(i);
|
|
||||||
gen(valueArgument.getArguments().get(i).getArgumentExpression(), elementType);
|
|
||||||
StackValue.arrayElement(elementType, false).store(v);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
@@ -1535,6 +1521,24 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> {
|
|||||||
return mask;
|
return mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void genVarargs(ValueParameterDescriptor valueParameterDescriptor, VarargValueArgument valueArgument) {
|
||||||
|
JetType outType = valueParameterDescriptor.getType();
|
||||||
|
|
||||||
|
Type type = asmType(outType);
|
||||||
|
assert type.getSort() == Type.ARRAY;
|
||||||
|
Type elementType = correctElementType(type);
|
||||||
|
int size = valueArgument.getArguments().size();
|
||||||
|
|
||||||
|
v.iconst(valueArgument.getArguments().size());
|
||||||
|
v.newarray(elementType);
|
||||||
|
for(int i = 0; i != size; ++i) {
|
||||||
|
v.dup();
|
||||||
|
v.iconst(i);
|
||||||
|
gen(valueArgument.getArguments().get(i).getArgumentExpression(), elementType);
|
||||||
|
StackValue.arrayElement(elementType, false).store(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int pushMethodArguments(JetCallElement expression, List<Type> valueParameterTypes) {
|
public int pushMethodArguments(JetCallElement expression, List<Type> valueParameterTypes) {
|
||||||
ResolvedCall<? extends CallableDescriptor> resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, expression.getCalleeExpression());
|
ResolvedCall<? extends CallableDescriptor> resolvedCall = bindingContext.get(BindingContext.RESOLVED_CALL, expression.getCalleeExpression());
|
||||||
if(resolvedCall != null) {
|
if(resolvedCall != null) {
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ public class IntrinsicMethods {
|
|||||||
public void init() {
|
public void init() {
|
||||||
namedMethods.put("kotlin.javaClass.function", new JavaClassFunction());
|
namedMethods.put("kotlin.javaClass.function", new JavaClassFunction());
|
||||||
namedMethods.put("kotlin.javaClass.property", new JavaClassProperty());
|
namedMethods.put("kotlin.javaClass.property", new JavaClassProperty());
|
||||||
|
namedMethods.put("kotlin.arrays.array", new JavaClassArray());
|
||||||
|
|
||||||
List<String> primitiveCastMethods = OperatorConventions.NUMBER_CONVERSIONS.asList();
|
List<String> primitiveCastMethods = OperatorConventions.NUMBER_CONVERSIONS.asList();
|
||||||
for (String method : primitiveCastMethods) {
|
for (String method : primitiveCastMethods) {
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2012 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.jet.codegen.intrinsics;
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
|
import org.jetbrains.jet.codegen.GenerationState;
|
||||||
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
|
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
|
||||||
|
import org.jetbrains.jet.lang.resolve.calls.ResolvedValueArgument;
|
||||||
|
import org.jetbrains.jet.lang.resolve.calls.VarargValueArgument;
|
||||||
|
import org.objectweb.asm.Type;
|
||||||
|
import org.objectweb.asm.commons.InstructionAdapter;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author alex.tkachman
|
||||||
|
*/
|
||||||
|
public class JavaClassArray implements IntrinsicMethod {
|
||||||
|
@Override
|
||||||
|
public StackValue generate(ExpressionCodegen codegen,
|
||||||
|
InstructionAdapter v,
|
||||||
|
Type expectedType,
|
||||||
|
@Nullable PsiElement element,
|
||||||
|
@Nullable List<JetExpression> arguments,
|
||||||
|
StackValue receiver,
|
||||||
|
@NotNull GenerationState state) {
|
||||||
|
ResolvedCall<? extends CallableDescriptor> call =
|
||||||
|
codegen.getBindingContext().get(BindingContext.RESOLVED_CALL, ((JetCallExpression)element).getCalleeExpression());
|
||||||
|
Map.Entry<ValueParameterDescriptor,ResolvedValueArgument> next = call.getValueArguments().entrySet().iterator().next();
|
||||||
|
codegen.genVarargs(next.getKey(), (VarargValueArgument)next.getValue());
|
||||||
|
return StackValue.onStack(expectedType);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,25 +7,27 @@ import java.nio.charset.Charset
|
|||||||
import java.util.List
|
import java.util.List
|
||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
|
|
||||||
|
import jet.runtime.Intrinsic
|
||||||
|
|
||||||
// Array "constructor"
|
// Array "constructor"
|
||||||
public inline fun <T> array(vararg t : T) : Array<T> = t
|
[Intrinsic("kotlin.arrays.array")] public inline fun <T> array(vararg t : T) : Array<T> = t
|
||||||
|
|
||||||
// "constructors" for primitive types array
|
// "constructors" for primitive types array
|
||||||
public inline fun doubleArray(vararg content : Double) : DoubleArray = content
|
[Intrinsic("kotlin.arrays.array")] public inline fun doubleArray(vararg content : Double) : DoubleArray = content
|
||||||
|
|
||||||
public inline fun floatArray(vararg content : Float) : FloatArray = content
|
[Intrinsic("kotlin.arrays.array")] public inline fun floatArray(vararg content : Float) : FloatArray = content
|
||||||
|
|
||||||
public inline fun longArray(vararg content : Long) : LongArray = content
|
[Intrinsic("kotlin.arrays.array")] public inline fun longArray(vararg content : Long) : LongArray = content
|
||||||
|
|
||||||
public inline fun intArray(vararg content : Int) : IntArray = content
|
[Intrinsic("kotlin.arrays.array")] public inline fun intArray(vararg content : Int) : IntArray = content
|
||||||
|
|
||||||
public inline fun charArray(vararg content : Char) : CharArray = content
|
[Intrinsic("kotlin.arrays.array")] public inline fun charArray(vararg content : Char) : CharArray = content
|
||||||
|
|
||||||
public inline fun shortArray(vararg content : Short) : ShortArray = content
|
[Intrinsic("kotlin.arrays.array")] public inline fun shortArray(vararg content : Short) : ShortArray = content
|
||||||
|
|
||||||
public inline fun byteArray(vararg content : Byte) : ByteArray = content
|
[Intrinsic("kotlin.arrays.array")] public inline fun byteArray(vararg content : Byte) : ByteArray = content
|
||||||
|
|
||||||
public inline fun booleanArray(vararg content : Boolean) : BooleanArray = content
|
[Intrinsic("kotlin.arrays.array")] public inline fun booleanArray(vararg content : Boolean) : BooleanArray = content
|
||||||
|
|
||||||
public inline fun ByteArray.binarySearch(key: Byte) : Int = Arrays.binarySearch(this, key)
|
public inline fun ByteArray.binarySearch(key: Byte) : Int = Arrays.binarySearch(this, key)
|
||||||
public inline fun ShortArray.binarySearch(key: Short) : Int = Arrays.binarySearch(this, key)
|
public inline fun ShortArray.binarySearch(key: Short) : Int = Arrays.binarySearch(this, key)
|
||||||
|
|||||||
Reference in New Issue
Block a user