Reorganize JVM intrinsics
Make IntrinsicMethod an abstract class, coerce the resulting value of the intrinsic to the expected type
This commit is contained in:
@@ -1626,7 +1626,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
IntrinsicMethod intrinsic = state.getIntrinsics().getIntrinsic(memberDescriptor);
|
IntrinsicMethod intrinsic = state.getIntrinsics().getIntrinsic(memberDescriptor);
|
||||||
if (intrinsic != null) {
|
if (intrinsic != null) {
|
||||||
Type returnType = typeMapper.mapType(memberDescriptor);
|
Type returnType = typeMapper.mapType(memberDescriptor);
|
||||||
intrinsic.generate(this, v, returnType, expression, Collections.<JetExpression>emptyList(), receiver, state);
|
intrinsic.generate(this, v, returnType, expression, Collections.<JetExpression>emptyList(), receiver);
|
||||||
return StackValue.onStack(returnType);
|
return StackValue.onStack(returnType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2010,7 +2010,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
|
|
||||||
Type returnType = typeMapper.mapType(resolvedCall.getResultingDescriptor());
|
Type returnType = typeMapper.mapType(resolvedCall.getResultingDescriptor());
|
||||||
|
|
||||||
intrinsic.generate(this, v, returnType, call.getCallElement(), args, receiver, state);
|
intrinsic.generate(this, v, returnType, call.getCallElement(), args, receiver);
|
||||||
return StackValue.onStack(returnType);
|
return StackValue.onStack(returnType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -2650,7 +2650,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
Type returnType = typeMapper.mapType(resolvedCall.getResultingDescriptor());
|
Type returnType = typeMapper.mapType(resolvedCall.getResultingDescriptor());
|
||||||
((IntrinsicMethod) callable).generate(this, v, returnType, expression,
|
((IntrinsicMethod) callable).generate(this, v, returnType, expression,
|
||||||
Arrays.asList(expression.getLeft(), expression.getRight()), receiver, state);
|
Arrays.asList(expression.getLeft(), expression.getRight()), receiver);
|
||||||
return StackValue.onStack(returnType);
|
return StackValue.onStack(returnType);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -2897,7 +2897,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
JetExpression right = expression.getRight();
|
JetExpression right = expression.getRight();
|
||||||
assert right != null;
|
assert right != null;
|
||||||
Type returnType = typeMapper.mapType((FunctionDescriptor) op);
|
Type returnType = typeMapper.mapType((FunctionDescriptor) op);
|
||||||
intrinsic.generate(this, v, returnType, expression, Collections.singletonList(right), StackValue.onStack(lhsType), state);
|
intrinsic.generate(this, v, returnType, expression, Collections.singletonList(right), StackValue.onStack(lhsType));
|
||||||
value.store(lhsType, v);
|
value.store(lhsType, v);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -2984,7 +2984,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
|||||||
if (callable instanceof IntrinsicMethod) {
|
if (callable instanceof IntrinsicMethod) {
|
||||||
Type returnType = typeMapper.mapType((FunctionDescriptor) op);
|
Type returnType = typeMapper.mapType((FunctionDescriptor) op);
|
||||||
((IntrinsicMethod) callable).generate(this, v, returnType, expression,
|
((IntrinsicMethod) callable).generate(this, v, returnType, expression,
|
||||||
Collections.singletonList(expression.getBaseExpression()), receiver, state);
|
Collections.singletonList(expression.getBaseExpression()), receiver);
|
||||||
return StackValue.onStack(returnType);
|
return StackValue.onStack(returnType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -632,7 +632,7 @@ public abstract class StackValue {
|
|||||||
((CallableMethod) getter).invokeWithNotNullAssertion(v, state, resolvedGetCall);
|
((CallableMethod) getter).invokeWithNotNullAssertion(v, state, resolvedGetCall);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
((IntrinsicMethod) getter).generate(codegen, v, this.type, null, null, null, state);
|
((IntrinsicMethod) getter).generate(codegen, v, this.type, null, null, null);
|
||||||
}
|
}
|
||||||
coerceTo(type, v);
|
coerceTo(type, v);
|
||||||
}
|
}
|
||||||
@@ -655,7 +655,7 @@ public abstract class StackValue {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
((IntrinsicMethod) setter).generate(codegen, v, null, null, null, null, state);
|
((IntrinsicMethod) setter).generate(codegen, v, null, null, null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,24 +22,22 @@ import org.jetbrains.asm4.Type;
|
|||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.jet.codegen.AsmUtil.correctElementType;
|
import static org.jetbrains.jet.codegen.AsmUtil.correctElementType;
|
||||||
|
|
||||||
public class ArrayGet implements IntrinsicMethod {
|
public class ArrayGet extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
PsiElement element,
|
PsiElement element,
|
||||||
List<JetExpression> arguments,
|
List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
receiver.put(receiver.type, v);
|
receiver.put(receiver.type, v);
|
||||||
Type type = correctElementType(receiver.type);
|
Type type = correctElementType(receiver.type);
|
||||||
@@ -48,8 +46,6 @@ public class ArrayGet implements IntrinsicMethod {
|
|||||||
|
|
||||||
v.aload(type);
|
v.aload(type);
|
||||||
|
|
||||||
StackValue.coerce(type, returnType, v);
|
return type;
|
||||||
|
|
||||||
return StackValue.onStack(returnType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,28 +22,26 @@ import org.jetbrains.asm4.Type;
|
|||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.JET_INT_RANGE_TYPE;
|
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.JET_INT_RANGE_TYPE;
|
||||||
|
|
||||||
public class ArrayIndices implements IntrinsicMethod {
|
public class ArrayIndices extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
PsiElement element,
|
PsiElement element,
|
||||||
List<JetExpression> arguments,
|
List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
receiver.put(receiver.type, v);
|
receiver.put(receiver.type, v);
|
||||||
v.arraylength();
|
v.arraylength();
|
||||||
v.invokestatic("jet/runtime/Ranges", "arrayIndices", "(I)Ljet/IntRange;");
|
v.invokestatic("jet/runtime/Ranges", "arrayIndices", "(I)Ljet/IntRange;");
|
||||||
StackValue.coerce(JET_INT_RANGE_TYPE, returnType, v);
|
return JET_INT_RANGE_TYPE;
|
||||||
return StackValue.onStack(returnType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import org.jetbrains.asm4.Type;
|
|||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
||||||
@@ -34,22 +33,23 @@ import org.jetbrains.jet.lang.resolve.name.FqName;
|
|||||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||||
import org.jetbrains.jet.lang.types.lang.PrimitiveType;
|
import org.jetbrains.jet.lang.types.lang.PrimitiveType;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.jet.codegen.AsmUtil.asmDescByFqNameWithoutInnerClasses;
|
import static org.jetbrains.jet.codegen.AsmUtil.asmDescByFqNameWithoutInnerClasses;
|
||||||
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.JET_ITERATOR_TYPE;
|
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.getType;
|
||||||
import static org.jetbrains.jet.lang.resolve.java.mapping.PrimitiveTypesUtil.asmTypeForPrimitive;
|
import static org.jetbrains.jet.lang.resolve.java.mapping.PrimitiveTypesUtil.asmTypeForPrimitive;
|
||||||
|
|
||||||
public class ArrayIterator implements IntrinsicMethod {
|
public class ArrayIterator extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
PsiElement element,
|
PsiElement element,
|
||||||
List<JetExpression> arguments,
|
List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
receiver.put(receiver.type, v);
|
receiver.put(receiver.type, v);
|
||||||
JetCallExpression call = (JetCallExpression) element;
|
JetCallExpression call = (JetCallExpression) element;
|
||||||
@@ -59,8 +59,7 @@ public class ArrayIterator implements IntrinsicMethod {
|
|||||||
ClassDescriptor containingDeclaration = (ClassDescriptor) funDescriptor.getContainingDeclaration().getOriginal();
|
ClassDescriptor containingDeclaration = (ClassDescriptor) funDescriptor.getContainingDeclaration().getOriginal();
|
||||||
if (containingDeclaration.equals(KotlinBuiltIns.getInstance().getArray())) {
|
if (containingDeclaration.equals(KotlinBuiltIns.getInstance().getArray())) {
|
||||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([Ljava/lang/Object;)Ljava/util/Iterator;");
|
v.invokestatic("jet/runtime/ArrayIterator", "iterator", "([Ljava/lang/Object;)Ljava/util/Iterator;");
|
||||||
StackValue.coerce(JET_ITERATOR_TYPE, returnType, v);
|
return getType(Iterator.class);
|
||||||
return StackValue.onStack(returnType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
|
for (JvmPrimitiveType jvmPrimitiveType : JvmPrimitiveType.values()) {
|
||||||
@@ -70,8 +69,7 @@ public class ArrayIterator implements IntrinsicMethod {
|
|||||||
String iteratorDesc = asmDescByFqNameWithoutInnerClasses(new FqName("jet." + primitiveType.getTypeName() + "Iterator"));
|
String iteratorDesc = asmDescByFqNameWithoutInnerClasses(new FqName("jet." + primitiveType.getTypeName() + "Iterator"));
|
||||||
String methodSignature = "([" + asmTypeForPrimitive(jvmPrimitiveType) + ")" + iteratorDesc;
|
String methodSignature = "([" + asmTypeForPrimitive(jvmPrimitiveType) + ")" + iteratorDesc;
|
||||||
v.invokestatic("jet/runtime/ArrayIterator", "iterator", methodSignature);
|
v.invokestatic("jet/runtime/ArrayIterator", "iterator", methodSignature);
|
||||||
StackValue.coerce(Type.getType(iteratorDesc), returnType, v);
|
return Type.getType(iteratorDesc);
|
||||||
return StackValue.onStack(returnType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,23 +22,22 @@ import org.jetbrains.asm4.Type;
|
|||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.jet.codegen.AsmUtil.correctElementType;
|
import static org.jetbrains.jet.codegen.AsmUtil.correctElementType;
|
||||||
|
|
||||||
public class ArraySet implements IntrinsicMethod {
|
public class ArraySet extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
PsiElement element,
|
PsiElement element,
|
||||||
List<JetExpression> arguments,
|
List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
receiver.put(receiver.type, v);
|
receiver.put(receiver.type, v);
|
||||||
Type type = correctElementType(receiver.type);
|
Type type = correctElementType(receiver.type);
|
||||||
@@ -47,9 +46,6 @@ public class ArraySet implements IntrinsicMethod {
|
|||||||
codegen.gen(arguments.get(1), type);
|
codegen.gen(arguments.get(1), type);
|
||||||
|
|
||||||
v.astore(type);
|
v.astore(type);
|
||||||
|
return Type.VOID_TYPE;
|
||||||
StackValue.coerce(Type.VOID_TYPE, returnType, v);
|
|
||||||
|
|
||||||
return StackValue.onStack(returnType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,29 +20,25 @@ import com.intellij.psi.PsiElement;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.asm4.Type;
|
import org.jetbrains.asm4.Type;
|
||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ArraySize implements IntrinsicMethod {
|
public class ArraySize extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
PsiElement element,
|
PsiElement element,
|
||||||
List<JetExpression> arguments,
|
List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
receiver.put(receiver.type, v);
|
receiver.put(receiver.type, v);
|
||||||
v.arraylength();
|
v.arraylength();
|
||||||
|
return Type.INT_TYPE;
|
||||||
StackValue.coerce(Type.INT_TYPE, returnType, v);
|
|
||||||
return StackValue.onStack(returnType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,36 +22,32 @@ import org.jetbrains.asm4.Type;
|
|||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.asm4.Opcodes.*;
|
import static org.jetbrains.asm4.Opcodes.*;
|
||||||
import static org.jetbrains.jet.codegen.AsmUtil.boxType;
|
import static org.jetbrains.jet.codegen.AsmUtil.isPrimitive;
|
||||||
import static org.jetbrains.jet.codegen.AsmUtil.numberFunctionOperandType;
|
import static org.jetbrains.jet.codegen.AsmUtil.numberFunctionOperandType;
|
||||||
import static org.jetbrains.jet.codegen.AsmUtil.unboxType;
|
|
||||||
|
|
||||||
public class BinaryOp implements IntrinsicMethod {
|
public class BinaryOp extends IntrinsicMethod {
|
||||||
private final int opcode;
|
private final int opcode;
|
||||||
|
|
||||||
public BinaryOp(int opcode) {
|
public BinaryOp(int opcode) {
|
||||||
this.opcode = opcode;
|
this.opcode = opcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
PsiElement element,
|
PsiElement element,
|
||||||
List<JetExpression> arguments,
|
List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
|
assert isPrimitive(returnType) : "Return type of BinaryOp intrinsic should be of primitive type : " + returnType;
|
||||||
boolean nullable = returnType.getSort() == Type.OBJECT;
|
|
||||||
assert !nullable : "Return type of BinaryOp intrinsic should be of primitive type : " + returnType;
|
|
||||||
|
|
||||||
Type operandType = numberFunctionOperandType(returnType);
|
Type operandType = numberFunctionOperandType(returnType);
|
||||||
|
|
||||||
@@ -67,8 +63,7 @@ public class BinaryOp implements IntrinsicMethod {
|
|||||||
codegen.gen(arguments.get(1), shift() ? Type.INT_TYPE : operandType);
|
codegen.gen(arguments.get(1), shift() ? Type.INT_TYPE : operandType);
|
||||||
}
|
}
|
||||||
v.visitInsn(returnType.getOpcode(opcode));
|
v.visitInsn(returnType.getOpcode(opcode));
|
||||||
|
return returnType;
|
||||||
return StackValue.onStack(returnType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shift() {
|
private boolean shift() {
|
||||||
|
|||||||
@@ -23,23 +23,22 @@ import org.jetbrains.asm4.Type;
|
|||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.jet.codegen.AsmUtil.comparisonOperandType;
|
import static org.jetbrains.jet.codegen.AsmUtil.comparisonOperandType;
|
||||||
|
|
||||||
public class CompareTo implements IntrinsicMethod {
|
public class CompareTo extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
@Nullable PsiElement element,
|
@Nullable PsiElement element,
|
||||||
@Nullable List<JetExpression> arguments,
|
@Nullable List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
JetExpression argument;
|
JetExpression argument;
|
||||||
assert arguments != null;
|
assert arguments != null;
|
||||||
@@ -77,7 +76,6 @@ public class CompareTo implements IntrinsicMethod {
|
|||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
StackValue.coerce(Type.INT_TYPE, returnType, v);
|
return Type.INT_TYPE;
|
||||||
return StackValue.onStack(returnType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import org.jetbrains.asm4.Type;
|
|||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
||||||
|
|
||||||
@@ -30,17 +29,18 @@ import java.util.List;
|
|||||||
|
|
||||||
import static org.jetbrains.jet.codegen.AsmUtil.genInvokeAppendMethod;
|
import static org.jetbrains.jet.codegen.AsmUtil.genInvokeAppendMethod;
|
||||||
import static org.jetbrains.jet.codegen.AsmUtil.genStringBuilderConstructor;
|
import static org.jetbrains.jet.codegen.AsmUtil.genStringBuilderConstructor;
|
||||||
|
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.JAVA_STRING_TYPE;
|
||||||
|
|
||||||
public class Concat implements IntrinsicMethod {
|
public class Concat extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
PsiElement element,
|
PsiElement element,
|
||||||
List<JetExpression> arguments,
|
List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
if (receiver == null || receiver == StackValue.none()) { // LHS + RHS
|
if (receiver == null || receiver == StackValue.none()) { // LHS + RHS
|
||||||
genStringBuilderConstructor(v);
|
genStringBuilderConstructor(v);
|
||||||
@@ -56,7 +56,6 @@ public class Concat implements IntrinsicMethod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
v.invokevirtual("java/lang/StringBuilder", "toString", "()Ljava/lang/String;");
|
v.invokevirtual("java/lang/StringBuilder", "toString", "()Ljava/lang/String;");
|
||||||
StackValue.onStack(AsmTypeConstants.JAVA_STRING_TYPE).put(returnType, v);
|
return JAVA_STRING_TYPE;
|
||||||
return StackValue.onStack(returnType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,3 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2013 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;
|
package org.jetbrains.jet.codegen.intrinsics;
|
||||||
|
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
@@ -7,21 +23,22 @@ import org.jetbrains.asm4.Type;
|
|||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CopyToArray implements IntrinsicMethod {
|
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.getType;
|
||||||
|
|
||||||
|
public class CopyToArray extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
@Nullable PsiElement element,
|
@Nullable PsiElement element,
|
||||||
@Nullable List<JetExpression> arguments,
|
@Nullable List<JetExpression> arguments,
|
||||||
@Nullable StackValue receiver,
|
@Nullable StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
assert receiver != null;
|
assert receiver != null;
|
||||||
receiver.put(receiver.type, v);
|
receiver.put(receiver.type, v);
|
||||||
@@ -31,8 +48,6 @@ public class CopyToArray implements IntrinsicMethod {
|
|||||||
v.newarray(returnType.getElementType());
|
v.newarray(returnType.getElementType());
|
||||||
v.invokeinterface("java/util/Collection", "toArray", "([Ljava/lang/Object;)[Ljava/lang/Object;");
|
v.invokeinterface("java/util/Collection", "toArray", "([Ljava/lang/Object;)[Ljava/lang/Object;");
|
||||||
|
|
||||||
StackValue.coerce(Type.getType("[Ljava/lang/Object;"), returnType, v);
|
return getType(Object[].class);
|
||||||
|
|
||||||
return StackValue.onStack(returnType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,37 +21,24 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.asm4.Type;
|
import org.jetbrains.asm4.Type;
|
||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
|
||||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class EnumValueOf implements IntrinsicMethod {
|
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.JAVA_STRING_TYPE;
|
||||||
|
|
||||||
|
public class EnumValueOf extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen, InstructionAdapter v, @NotNull Type expectedType, @Nullable PsiElement element,
|
ExpressionCodegen codegen, InstructionAdapter v, @NotNull Type returnType, @Nullable PsiElement element,
|
||||||
@Nullable List<JetExpression> arguments, StackValue receiver, @NotNull GenerationState state
|
@Nullable List<JetExpression> arguments, StackValue receiver
|
||||||
) {
|
) {
|
||||||
JetCallExpression call = (JetCallExpression) element;
|
|
||||||
ResolvedCall<? extends CallableDescriptor> resolvedCall =
|
|
||||||
codegen.getBindingContext().get(BindingContext.RESOLVED_CALL, call.getCalleeExpression());
|
|
||||||
assert resolvedCall != null;
|
|
||||||
CallableDescriptor resultingDescriptor = resolvedCall.getResultingDescriptor();
|
|
||||||
JetType returnType = resultingDescriptor.getReturnType();
|
|
||||||
assert returnType != null;
|
|
||||||
Type type = state.getTypeMapper().mapType(returnType);
|
|
||||||
assert arguments != null;
|
assert arguments != null;
|
||||||
codegen.gen(arguments.get(0), AsmTypeConstants.JAVA_STRING_TYPE);
|
codegen.gen(arguments.get(0), JAVA_STRING_TYPE);
|
||||||
v.invokestatic(type.getInternalName(), "valueOf", "(Ljava/lang/String;)" + type.getDescriptor());
|
v.invokestatic(returnType.getInternalName(), "valueOf", "(Ljava/lang/String;)" + returnType.getDescriptor());
|
||||||
StackValue.onStack(type).put(expectedType, v);
|
return returnType;
|
||||||
return StackValue.onStack(expectedType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,32 +23,18 @@ import org.jetbrains.asm4.Type;
|
|||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
|
||||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class EnumValues implements IntrinsicMethod {
|
public class EnumValues extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen, InstructionAdapter v, @NotNull Type expectedType, @Nullable PsiElement element,
|
ExpressionCodegen codegen, InstructionAdapter v, @NotNull Type returnType, @Nullable PsiElement element,
|
||||||
@Nullable List<JetExpression> arguments, StackValue receiver, @NotNull GenerationState state
|
@Nullable List<JetExpression> arguments, StackValue receiver
|
||||||
) {
|
) {
|
||||||
JetCallExpression call = (JetCallExpression) element;
|
v.invokestatic(returnType.getElementType().getInternalName(), "values", "()" + returnType);
|
||||||
ResolvedCall<? extends CallableDescriptor> resolvedCall =
|
return returnType;
|
||||||
codegen.getBindingContext().get(BindingContext.RESOLVED_CALL, call.getCalleeExpression());
|
|
||||||
assert resolvedCall != null;
|
|
||||||
CallableDescriptor resultingDescriptor = resolvedCall.getResultingDescriptor();
|
|
||||||
JetType returnType = resultingDescriptor.getReturnType();
|
|
||||||
assert returnType != null;
|
|
||||||
Type type = state.getTypeMapper().mapType(returnType);
|
|
||||||
v.invokestatic(type.getElementType().getInternalName(), "values", "()" + type);
|
|
||||||
StackValue.onStack(type).put(expectedType, v);
|
|
||||||
return StackValue.onStack(expectedType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,26 +22,25 @@ import org.jetbrains.asm4.Type;
|
|||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
|
||||||
import org.jetbrains.jet.lexer.JetTokens;
|
import org.jetbrains.jet.lexer.JetTokens;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.jet.codegen.AsmUtil.genEqualsForExpressionsOnStack;
|
import static org.jetbrains.jet.codegen.AsmUtil.genEqualsForExpressionsOnStack;
|
||||||
|
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE;
|
||||||
|
|
||||||
public class Equals implements IntrinsicMethod {
|
public class Equals extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
PsiElement element,
|
PsiElement element,
|
||||||
List<JetExpression> arguments,
|
List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
StackValue leftExpr;
|
StackValue leftExpr;
|
||||||
JetExpression rightExpr;
|
JetExpression rightExpr;
|
||||||
@@ -54,11 +53,10 @@ public class Equals implements IntrinsicMethod {
|
|||||||
rightExpr = arguments.get(1);
|
rightExpr = arguments.get(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
leftExpr.put(AsmTypeConstants.OBJECT_TYPE, v);
|
leftExpr.put(OBJECT_TYPE, v);
|
||||||
codegen.gen(rightExpr).put(AsmTypeConstants.OBJECT_TYPE, v);
|
codegen.gen(rightExpr).put(OBJECT_TYPE, v);
|
||||||
|
|
||||||
StackValue value = genEqualsForExpressionsOnStack(v, JetTokens.EQEQ, AsmTypeConstants.OBJECT_TYPE, AsmTypeConstants.OBJECT_TYPE);
|
genEqualsForExpressionsOnStack(v, JetTokens.EQEQ, OBJECT_TYPE, OBJECT_TYPE).put(returnType, v);
|
||||||
value.put(returnType, v);
|
return returnType;
|
||||||
return StackValue.onStack(returnType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,26 +24,24 @@ import org.jetbrains.asm4.Type;
|
|||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class HashCode implements IntrinsicMethod {
|
public class HashCode extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
@Nullable PsiElement element,
|
@Nullable PsiElement element,
|
||||||
@Nullable List<JetExpression> arguments,
|
@Nullable List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
receiver.put(AsmTypeConstants.OBJECT_TYPE, v);
|
receiver.put(AsmTypeConstants.OBJECT_TYPE, v);
|
||||||
v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "hashCode", "()I");
|
v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "hashCode", "()I");
|
||||||
StackValue.coerce(Type.INT_TYPE, returnType, v);
|
return Type.INT_TYPE;
|
||||||
return StackValue.onStack(returnType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import org.jetbrains.asm4.Type;
|
|||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetBinaryExpression;
|
import org.jetbrains.jet.lang.psi.JetBinaryExpression;
|
||||||
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
@@ -32,16 +31,16 @@ import java.util.List;
|
|||||||
|
|
||||||
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE;
|
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE;
|
||||||
|
|
||||||
public class IdentityEquals implements IntrinsicMethod {
|
public class IdentityEquals extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
PsiElement element,
|
PsiElement element,
|
||||||
List<JetExpression> arguments,
|
List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
if (element instanceof JetCallExpression) {
|
if (element instanceof JetCallExpression) {
|
||||||
receiver.put(OBJECT_TYPE, v);
|
receiver.put(OBJECT_TYPE, v);
|
||||||
@@ -54,6 +53,6 @@ public class IdentityEquals implements IntrinsicMethod {
|
|||||||
codegen.gen(e.getRight()).put(OBJECT_TYPE, v);
|
codegen.gen(e.getRight()).put(OBJECT_TYPE, v);
|
||||||
}
|
}
|
||||||
StackValue.cmp(JetTokens.EQEQEQ, OBJECT_TYPE).put(returnType, v);
|
StackValue.cmp(JetTokens.EQEQEQ, OBJECT_TYPE).put(returnType, v);
|
||||||
return StackValue.onStack(returnType);
|
return returnType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import org.jetbrains.asm4.Type;
|
|||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
import org.jetbrains.jet.lang.psi.JetParenthesizedExpression;
|
import org.jetbrains.jet.lang.psi.JetParenthesizedExpression;
|
||||||
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
|
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
|
||||||
@@ -30,27 +29,26 @@ import org.jetbrains.jet.lang.psi.JetReferenceExpression;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.jet.codegen.AsmUtil.genIncrement;
|
import static org.jetbrains.jet.codegen.AsmUtil.genIncrement;
|
||||||
import static org.jetbrains.jet.codegen.AsmUtil.unboxType;
|
import static org.jetbrains.jet.codegen.AsmUtil.isPrimitive;
|
||||||
|
|
||||||
public class Increment implements IntrinsicMethod {
|
public class Increment extends IntrinsicMethod {
|
||||||
private final int myDelta;
|
private final int myDelta;
|
||||||
|
|
||||||
public Increment(int delta) {
|
public Increment(int delta) {
|
||||||
myDelta = delta;
|
myDelta = delta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
PsiElement element,
|
PsiElement element,
|
||||||
List<JetExpression> arguments,
|
List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
boolean nullable = returnType.getSort() == Type.OBJECT;
|
assert isPrimitive(returnType) : "Return type of Increment intrinsic should be of primitive type : " + returnType;
|
||||||
assert !nullable : "Return type of Increment intrinsic should be of primitive type : " + returnType;
|
|
||||||
|
|
||||||
if (arguments.size() > 0) {
|
if (arguments.size() > 0) {
|
||||||
JetExpression operand = arguments.get(0);
|
JetExpression operand = arguments.get(0);
|
||||||
@@ -61,7 +59,7 @@ public class Increment implements IntrinsicMethod {
|
|||||||
int index = codegen.indexOfLocal((JetReferenceExpression) operand);
|
int index = codegen.indexOfLocal((JetReferenceExpression) operand);
|
||||||
if (index >= 0) {
|
if (index >= 0) {
|
||||||
StackValue.preIncrement(index, myDelta).put(returnType, v);
|
StackValue.preIncrement(index, myDelta).put(returnType, v);
|
||||||
return StackValue.onStack(returnType);
|
return returnType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StackValue value = codegen.genQualified(receiver, operand);
|
StackValue value = codegen.genQualified(receiver, operand);
|
||||||
@@ -77,6 +75,7 @@ public class Increment implements IntrinsicMethod {
|
|||||||
receiver.put(returnType, v);
|
receiver.put(returnType, v);
|
||||||
genIncrement(returnType, myDelta, v);
|
genIncrement(returnType, myDelta, v);
|
||||||
}
|
}
|
||||||
return StackValue.onStack(returnType);
|
|
||||||
|
return returnType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,14 +24,30 @@ import org.jetbrains.asm4.commons.InstructionAdapter;
|
|||||||
import org.jetbrains.jet.codegen.Callable;
|
import org.jetbrains.jet.codegen.Callable;
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface IntrinsicMethod extends Callable {
|
public abstract class IntrinsicMethod implements Callable {
|
||||||
StackValue generate(
|
public final void generate(
|
||||||
ExpressionCodegen codegen, InstructionAdapter v, @NotNull Type returnType, @Nullable PsiElement element,
|
@NotNull ExpressionCodegen codegen,
|
||||||
@Nullable List<JetExpression> arguments, @Nullable StackValue receiver, @NotNull GenerationState state
|
@NotNull InstructionAdapter v,
|
||||||
|
@NotNull Type returnType,
|
||||||
|
@Nullable PsiElement element,
|
||||||
|
@Nullable List<JetExpression> arguments,
|
||||||
|
@Nullable StackValue receiver
|
||||||
|
) {
|
||||||
|
Type actualType = generateImpl(codegen, v, returnType, element, arguments, receiver);
|
||||||
|
StackValue.coerce(actualType, returnType, v);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
protected abstract Type generateImpl(
|
||||||
|
ExpressionCodegen codegen,
|
||||||
|
InstructionAdapter v,
|
||||||
|
@NotNull Type returnType,
|
||||||
|
@Nullable PsiElement element,
|
||||||
|
@Nullable List<JetExpression> arguments,
|
||||||
|
@Nullable StackValue receiver
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,27 +22,25 @@ import org.jetbrains.asm4.Type;
|
|||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.jetbrains.jet.codegen.AsmUtil.isPrimitive;
|
||||||
import static org.jetbrains.jet.codegen.AsmUtil.numberFunctionOperandType;
|
import static org.jetbrains.jet.codegen.AsmUtil.numberFunctionOperandType;
|
||||||
import static org.jetbrains.jet.codegen.AsmUtil.unboxType;
|
|
||||||
|
|
||||||
public class Inv implements IntrinsicMethod {
|
public class Inv extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
PsiElement element,
|
PsiElement element,
|
||||||
List<JetExpression> arguments,
|
List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
boolean nullable = returnType.getSort() == Type.OBJECT;
|
assert isPrimitive(returnType) : "Return type of Inv intrinsic should be of primitive type : " + returnType;
|
||||||
assert !nullable : "Return type of Inv intrinsic should be of primitive type : " + returnType;
|
|
||||||
|
|
||||||
receiver.put(numberFunctionOperandType(returnType), v);
|
receiver.put(numberFunctionOperandType(returnType), v);
|
||||||
if (returnType == Type.LONG_TYPE) {
|
if (returnType == Type.LONG_TYPE) {
|
||||||
@@ -52,6 +50,6 @@ public class Inv implements IntrinsicMethod {
|
|||||||
v.iconst(-1);
|
v.iconst(-1);
|
||||||
}
|
}
|
||||||
v.xor(returnType);
|
v.xor(returnType);
|
||||||
return StackValue.onStack(returnType);
|
return returnType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,23 +23,22 @@ import org.jetbrains.asm4.Type;
|
|||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class IteratorIterator implements IntrinsicMethod {
|
public class IteratorIterator extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
@Nullable PsiElement element,
|
@Nullable PsiElement element,
|
||||||
@Nullable List<JetExpression> arguments,
|
@Nullable List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
receiver.put(returnType, v);
|
receiver.put(returnType, v);
|
||||||
return StackValue.onStack(returnType);
|
return returnType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,24 +20,23 @@ import com.intellij.psi.PsiElement;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.asm4.Type;
|
import org.jetbrains.asm4.Type;
|
||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class IteratorNext implements IntrinsicMethod {
|
public class IteratorNext extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
PsiElement element,
|
PsiElement element,
|
||||||
List<JetExpression> arguments,
|
List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
String name;
|
String name;
|
||||||
if (returnType == Type.CHAR_TYPE) {
|
if (returnType == Type.CHAR_TYPE) {
|
||||||
@@ -69,6 +68,6 @@ public class IteratorNext implements IntrinsicMethod {
|
|||||||
}
|
}
|
||||||
receiver.put(AsmTypeConstants.OBJECT_TYPE, v);
|
receiver.put(AsmTypeConstants.OBJECT_TYPE, v);
|
||||||
v.invokevirtual("jet/" + name + "Iterator", "next" + name, "()" + returnType.getDescriptor());
|
v.invokevirtual("jet/" + name + "Iterator", "next" + name, "()" + returnType.getDescriptor());
|
||||||
return StackValue.onStack(returnType);
|
return returnType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import org.jetbrains.asm4.Type;
|
|||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
||||||
@@ -36,22 +35,22 @@ import org.jetbrains.jet.lang.resolve.calls.model.VarargValueArgument;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class JavaClassArray implements IntrinsicMethod {
|
public class JavaClassArray extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
@Nullable PsiElement element,
|
@Nullable PsiElement element,
|
||||||
@Nullable List<JetExpression> arguments,
|
@Nullable List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
ResolvedCall<? extends CallableDescriptor> call =
|
ResolvedCall<? extends CallableDescriptor> call =
|
||||||
codegen.getBindingContext().get(BindingContext.RESOLVED_CALL, ((JetCallExpression) element).getCalleeExpression());
|
codegen.getBindingContext().get(BindingContext.RESOLVED_CALL, ((JetCallExpression) element).getCalleeExpression());
|
||||||
assert call != null;
|
assert call != null;
|
||||||
Map.Entry<ValueParameterDescriptor, ResolvedValueArgument> next = call.getValueArguments().entrySet().iterator().next();
|
Map.Entry<ValueParameterDescriptor, ResolvedValueArgument> next = call.getValueArguments().entrySet().iterator().next();
|
||||||
codegen.genVarargs(next.getKey(), (VarargValueArgument) next.getValue());
|
codegen.genVarargs(next.getKey(), (VarargValueArgument) next.getValue());
|
||||||
return StackValue.onStack(returnType);
|
return returnType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import org.jetbrains.asm4.Type;
|
|||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
@@ -37,20 +36,20 @@ import static org.jetbrains.jet.codegen.AsmUtil.boxType;
|
|||||||
import static org.jetbrains.jet.codegen.AsmUtil.isPrimitive;
|
import static org.jetbrains.jet.codegen.AsmUtil.isPrimitive;
|
||||||
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.getType;
|
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.getType;
|
||||||
|
|
||||||
public class JavaClassFunction implements IntrinsicMethod {
|
public class JavaClassFunction extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen, InstructionAdapter v, @NotNull Type expectedType, @Nullable PsiElement element,
|
ExpressionCodegen codegen, InstructionAdapter v, @NotNull Type expectedType, @Nullable PsiElement element,
|
||||||
@Nullable List<JetExpression> arguments, StackValue receiver, @NotNull GenerationState state
|
@Nullable List<JetExpression> arguments, StackValue receiver
|
||||||
) {
|
) {
|
||||||
JetCallExpression call = (JetCallExpression) element;
|
JetCallExpression call = (JetCallExpression) element;
|
||||||
ResolvedCall<? extends CallableDescriptor> resolvedCall =
|
ResolvedCall<? extends CallableDescriptor> resolvedCall =
|
||||||
codegen.getBindingContext().get(BindingContext.RESOLVED_CALL, call.getCalleeExpression());
|
codegen.getBindingContext().get(BindingContext.RESOLVED_CALL, call.getCalleeExpression());
|
||||||
assert resolvedCall != null;
|
assert resolvedCall != null;
|
||||||
CallableDescriptor resultingDescriptor = resolvedCall.getResultingDescriptor();
|
JetType returnType = resolvedCall.getResultingDescriptor().getReturnType();
|
||||||
JetType returnType = resultingDescriptor.getReturnType();
|
|
||||||
assert returnType != null;
|
assert returnType != null;
|
||||||
Type type = state.getTypeMapper().mapType(returnType.getArguments().get(0).getType());
|
Type type = codegen.getState().getTypeMapper().mapType(returnType.getArguments().get(0).getType());
|
||||||
if (isPrimitive(type)) {
|
if (isPrimitive(type)) {
|
||||||
v.getstatic(boxType(type).getInternalName(), "TYPE", "Ljava/lang/Class;");
|
v.getstatic(boxType(type).getInternalName(), "TYPE", "Ljava/lang/Class;");
|
||||||
}
|
}
|
||||||
@@ -58,7 +57,6 @@ public class JavaClassFunction implements IntrinsicMethod {
|
|||||||
v.aconst(type);
|
v.aconst(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
StackValue.coerce(getType(Class.class), expectedType, v);
|
return getType(Class.class);
|
||||||
return StackValue.onStack(expectedType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import org.jetbrains.asm4.Type;
|
|||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -32,16 +31,16 @@ import static org.jetbrains.jet.codegen.AsmUtil.boxType;
|
|||||||
import static org.jetbrains.jet.codegen.AsmUtil.isPrimitive;
|
import static org.jetbrains.jet.codegen.AsmUtil.isPrimitive;
|
||||||
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.getType;
|
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.getType;
|
||||||
|
|
||||||
public class JavaClassProperty implements IntrinsicMethod {
|
public class JavaClassProperty extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
@Nullable PsiElement element,
|
@Nullable PsiElement element,
|
||||||
@Nullable List<JetExpression> arguments,
|
@Nullable List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
Type type = receiver.type;
|
Type type = receiver.type;
|
||||||
if (isPrimitive(type)) {
|
if (isPrimitive(type)) {
|
||||||
@@ -52,7 +51,6 @@ public class JavaClassProperty implements IntrinsicMethod {
|
|||||||
v.invokevirtual("java/lang/Object", "getClass", "()Ljava/lang/Class;");
|
v.invokevirtual("java/lang/Object", "getClass", "()Ljava/lang/Class;");
|
||||||
}
|
}
|
||||||
|
|
||||||
StackValue.coerce(getType(Class.class), returnType, v);
|
return getType(Class.class);
|
||||||
return StackValue.onStack(returnType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,24 +22,23 @@ import org.jetbrains.asm4.Type;
|
|||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class NewArray implements IntrinsicMethod {
|
public class NewArray extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
PsiElement element,
|
PsiElement element,
|
||||||
List<JetExpression> arguments,
|
List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
codegen.generateNewArray((JetCallExpression) element);
|
codegen.generateNewArray((JetCallExpression) element);
|
||||||
return StackValue.onStack(returnType);
|
return returnType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,21 +22,20 @@ import org.jetbrains.asm4.Type;
|
|||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Not implements IntrinsicMethod {
|
public class Not extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
PsiElement element,
|
PsiElement element,
|
||||||
List<JetExpression> arguments,
|
List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
StackValue stackValue;
|
StackValue stackValue;
|
||||||
if (arguments.size() == 1) {
|
if (arguments.size() == 1) {
|
||||||
@@ -47,6 +46,6 @@ public class Not implements IntrinsicMethod {
|
|||||||
}
|
}
|
||||||
stackValue.put(Type.BOOLEAN_TYPE, v);
|
stackValue.put(Type.BOOLEAN_TYPE, v);
|
||||||
StackValue.not(StackValue.onStack(Type.BOOLEAN_TYPE)).put(returnType, v);
|
StackValue.not(StackValue.onStack(Type.BOOLEAN_TYPE)).put(returnType, v);
|
||||||
return StackValue.onStack(returnType);
|
return returnType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,23 +22,22 @@ import org.jetbrains.asm4.Type;
|
|||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class NumberCast implements IntrinsicMethod {
|
public class NumberCast extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
PsiElement element,
|
PsiElement element,
|
||||||
List<JetExpression> arguments,
|
List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
receiver.put(returnType, v);
|
receiver.put(returnType, v);
|
||||||
return StackValue.onStack(returnType);
|
return returnType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-8
@@ -23,7 +23,6 @@ import org.jetbrains.asm4.commons.InstructionAdapter;
|
|||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.PropertyCodegen;
|
import org.jetbrains.jet.codegen.PropertyCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
@@ -33,7 +32,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import static org.jetbrains.jet.codegen.AsmUtil.boxType;
|
import static org.jetbrains.jet.codegen.AsmUtil.boxType;
|
||||||
|
|
||||||
public class PropertyOfProgressionOrRange implements IntrinsicMethod {
|
public class PropertyOfProgressionOrRange extends IntrinsicMethod {
|
||||||
private final FqName ownerClass;
|
private final FqName ownerClass;
|
||||||
private final Name propertyName;
|
private final Name propertyName;
|
||||||
|
|
||||||
@@ -42,23 +41,22 @@ public class PropertyOfProgressionOrRange implements IntrinsicMethod {
|
|||||||
this.propertyName = propertyName;
|
this.propertyName = propertyName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
PsiElement element,
|
PsiElement element,
|
||||||
List<JetExpression> arguments,
|
List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
String ownerInternalName = JvmClassName.byFqNameWithoutInnerClasses(this.ownerClass).getInternalName();
|
String ownerInternalName = JvmClassName.byFqNameWithoutInnerClasses(ownerClass).getInternalName();
|
||||||
Type boxedType = boxType(returnType);
|
Type boxedType = boxType(returnType);
|
||||||
String getterName = PropertyCodegen.getterName(propertyName);
|
String getterName = PropertyCodegen.getterName(propertyName);
|
||||||
|
|
||||||
receiver.put(receiver.type, v);
|
receiver.put(receiver.type, v);
|
||||||
v.invokevirtual(ownerInternalName, getterName, "()" + boxedType.getDescriptor());
|
v.invokevirtual(ownerInternalName, getterName, "()" + boxedType.getDescriptor());
|
||||||
StackValue.coerce(boxedType, returnType, v);
|
return boxedType;
|
||||||
return StackValue.onStack(returnType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,22 +22,21 @@ import org.jetbrains.asm4.Type;
|
|||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetBinaryExpression;
|
import org.jetbrains.jet.lang.psi.JetBinaryExpression;
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class RangeTo implements IntrinsicMethod {
|
public class RangeTo extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
PsiElement element,
|
PsiElement element,
|
||||||
List<JetExpression> arguments,
|
List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
if (arguments.size() == 1) {
|
if (arguments.size() == 1) {
|
||||||
Type leftType = receiver.type;
|
Type leftType = receiver.type;
|
||||||
@@ -56,7 +55,6 @@ public class RangeTo implements IntrinsicMethod {
|
|||||||
v.invokestatic("jet/runtime/Ranges", "rangeTo",
|
v.invokestatic("jet/runtime/Ranges", "rangeTo",
|
||||||
"(" + leftType.getDescriptor() + rightType.getDescriptor() + ")" + returnType.getDescriptor());
|
"(" + leftType.getDescriptor() + rightType.getDescriptor() + ")" + returnType.getDescriptor());
|
||||||
}
|
}
|
||||||
|
return returnType;
|
||||||
return StackValue.onStack(returnType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,6 @@ import org.jetbrains.asm4.Type;
|
|||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
|
||||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||||
@@ -31,27 +30,26 @@ import org.jetbrains.jet.lang.resolve.name.Name;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class StaticField implements IntrinsicMethod {
|
public class StaticField extends IntrinsicMethod {
|
||||||
private final FqName ownerClass;
|
private final FqName ownerClass;
|
||||||
private final Name propertyName;
|
private final Name propertyName;
|
||||||
|
|
||||||
|
|
||||||
public StaticField(FqName ownerClass, Name propertyName) {
|
public StaticField(FqName ownerClass, Name propertyName) {
|
||||||
this.ownerClass = ownerClass;
|
this.ownerClass = ownerClass;
|
||||||
this.propertyName = propertyName;
|
this.propertyName = propertyName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
@Nullable PsiElement element,
|
@Nullable PsiElement element,
|
||||||
@Nullable List<JetExpression> arguments,
|
@Nullable List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
v.getstatic(JvmClassName.byFqNameWithoutInnerClasses(ownerClass).getInternalName(), propertyName.asString(), returnType.getDescriptor());
|
v.getstatic(JvmClassName.byFqNameWithoutInnerClasses(ownerClass).getInternalName(), propertyName.asString(), returnType.getDescriptor());
|
||||||
return StackValue.onStack(returnType);
|
return returnType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,24 +20,22 @@ import com.intellij.psi.PsiElement;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.asm4.Type;
|
import org.jetbrains.asm4.Type;
|
||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class StringGetChar implements IntrinsicMethod {
|
public class StringGetChar extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
PsiElement element,
|
PsiElement element,
|
||||||
List<JetExpression> arguments,
|
List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
if (receiver != null) {
|
if (receiver != null) {
|
||||||
receiver.put(receiver.type, v);
|
receiver.put(receiver.type, v);
|
||||||
@@ -46,7 +44,6 @@ public class StringGetChar implements IntrinsicMethod {
|
|||||||
codegen.gen(arguments.get(0)).put(Type.INT_TYPE, v);
|
codegen.gen(arguments.get(0)).put(Type.INT_TYPE, v);
|
||||||
}
|
}
|
||||||
v.invokeinterface("java/lang/CharSequence", "charAt", "(I)C");
|
v.invokeinterface("java/lang/CharSequence", "charAt", "(I)C");
|
||||||
StackValue.coerce(Type.CHAR_TYPE, returnType, v);
|
return Type.CHAR_TYPE;
|
||||||
return StackValue.onStack(returnType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,28 +20,25 @@ import com.intellij.psi.PsiElement;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.asm4.Type;
|
import org.jetbrains.asm4.Type;
|
||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class StringLength implements IntrinsicMethod {
|
public class StringLength extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
PsiElement element,
|
PsiElement element,
|
||||||
List<JetExpression> arguments,
|
List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
receiver.put(receiver.type, v);
|
receiver.put(receiver.type, v);
|
||||||
v.invokeinterface("java/lang/CharSequence", "length", "()I");
|
v.invokeinterface("java/lang/CharSequence", "length", "()I");
|
||||||
StackValue.coerce(Type.INT_TYPE, returnType, v);
|
return Type.INT_TYPE;
|
||||||
return StackValue.onStack(returnType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ import org.jetbrains.asm4.Type;
|
|||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@@ -30,16 +29,16 @@ import java.util.List;
|
|||||||
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.JAVA_STRING_TYPE;
|
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.JAVA_STRING_TYPE;
|
||||||
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE;
|
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE;
|
||||||
|
|
||||||
public class StringPlus implements IntrinsicMethod {
|
public class StringPlus extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
PsiElement element,
|
PsiElement element,
|
||||||
List<JetExpression> arguments,
|
List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
if (receiver == null || receiver == StackValue.none()) {
|
if (receiver == null || receiver == StackValue.none()) {
|
||||||
codegen.gen(arguments.get(0)).put(JAVA_STRING_TYPE, v);
|
codegen.gen(arguments.get(0)).put(JAVA_STRING_TYPE, v);
|
||||||
@@ -50,8 +49,6 @@ public class StringPlus implements IntrinsicMethod {
|
|||||||
codegen.gen(arguments.get(0)).put(OBJECT_TYPE, v);
|
codegen.gen(arguments.get(0)).put(OBJECT_TYPE, v);
|
||||||
}
|
}
|
||||||
v.invokestatic("jet/runtime/Intrinsics", "stringPlus", "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/String;");
|
v.invokestatic("jet/runtime/Intrinsics", "stringPlus", "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/String;");
|
||||||
|
return JAVA_STRING_TYPE;
|
||||||
StackValue.coerce(JAVA_STRING_TYPE, returnType, v);
|
|
||||||
return StackValue.onStack(returnType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,30 +21,30 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.asm4.Type;
|
import org.jetbrains.asm4.Type;
|
||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
|
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
import org.jetbrains.jet.lang.psi.JetCallExpression;
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class StupidSync implements IntrinsicMethod {
|
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.JET_FUNCTION0_TYPE;
|
||||||
|
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE;
|
||||||
|
|
||||||
|
public class StupidSync extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
@Nullable PsiElement element,
|
@Nullable PsiElement element,
|
||||||
@Nullable List<JetExpression> arguments,
|
@Nullable List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
codegen.pushMethodArguments((JetCallExpression) element, Arrays.asList(AsmTypeConstants.OBJECT_TYPE, AsmTypeConstants.JET_FUNCTION0_TYPE));
|
codegen.pushMethodArguments((JetCallExpression) element, Arrays.asList(OBJECT_TYPE, JET_FUNCTION0_TYPE));
|
||||||
v.invokestatic("jet/runtime/Intrinsics", "stupidSync", "(Ljava/lang/Object;Ljet/Function0;)Ljava/lang/Object;");
|
v.invokestatic("jet/runtime/Intrinsics", "stupidSync", "(Ljava/lang/Object;Ljet/Function0;)Ljava/lang/Object;");
|
||||||
StackValue.onStack(AsmTypeConstants.OBJECT_TYPE).put(returnType, v);
|
return OBJECT_TYPE;
|
||||||
return StackValue.onStack(returnType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,25 +22,24 @@ import org.jetbrains.asm4.Type;
|
|||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.jet.codegen.AsmUtil.genToString;
|
import static org.jetbrains.jet.codegen.AsmUtil.genToString;
|
||||||
|
|
||||||
public class ToString implements IntrinsicMethod {
|
public class ToString extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
PsiElement element,
|
PsiElement element,
|
||||||
List<JetExpression> arguments,
|
List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
genToString(v, receiver, receiver.type).put(returnType, v);
|
genToString(v, receiver, receiver.type).put(returnType, v);
|
||||||
return StackValue.onStack(returnType);
|
return returnType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,28 +22,24 @@ import org.jetbrains.asm4.Type;
|
|||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.jet.codegen.AsmUtil.genNegate;
|
import static org.jetbrains.jet.codegen.AsmUtil.*;
|
||||||
import static org.jetbrains.jet.codegen.AsmUtil.numberFunctionOperandType;
|
|
||||||
import static org.jetbrains.jet.codegen.AsmUtil.unboxType;
|
|
||||||
|
|
||||||
public class UnaryMinus implements IntrinsicMethod {
|
public class UnaryMinus extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
PsiElement element,
|
PsiElement element,
|
||||||
List<JetExpression> arguments,
|
List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
boolean nullable = returnType.getSort() == Type.OBJECT;
|
assert isPrimitive(returnType) : "Return type of UnaryMinus intrinsic should be of primitive type: " + returnType;
|
||||||
assert !nullable : "Return type of UnaryMinus intrinsic should be of primitive type : " + returnType;
|
|
||||||
|
|
||||||
Type operandType = numberFunctionOperandType(returnType);
|
Type operandType = numberFunctionOperandType(returnType);
|
||||||
|
|
||||||
@@ -53,8 +49,6 @@ public class UnaryMinus implements IntrinsicMethod {
|
|||||||
else {
|
else {
|
||||||
receiver.put(operandType, v);
|
receiver.put(operandType, v);
|
||||||
}
|
}
|
||||||
Type negatedValue = genNegate(returnType, v);
|
return genNegate(returnType, v);
|
||||||
StackValue.coerce(negatedValue, returnType, v);
|
|
||||||
return StackValue.onStack(returnType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,26 +23,24 @@ import org.jetbrains.asm4.Type;
|
|||||||
import org.jetbrains.asm4.commons.InstructionAdapter;
|
import org.jetbrains.asm4.commons.InstructionAdapter;
|
||||||
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
import org.jetbrains.jet.codegen.ExpressionCodegen;
|
||||||
import org.jetbrains.jet.codegen.StackValue;
|
import org.jetbrains.jet.codegen.StackValue;
|
||||||
import org.jetbrains.jet.codegen.state.GenerationState;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.jetbrains.jet.codegen.AsmUtil.unboxType;
|
import static org.jetbrains.jet.codegen.AsmUtil.isPrimitive;
|
||||||
|
|
||||||
public class UnaryPlus implements IntrinsicMethod {
|
public class UnaryPlus extends IntrinsicMethod {
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public StackValue generate(
|
public Type generateImpl(
|
||||||
ExpressionCodegen codegen,
|
ExpressionCodegen codegen,
|
||||||
InstructionAdapter v,
|
InstructionAdapter v,
|
||||||
@NotNull Type returnType,
|
@NotNull Type returnType,
|
||||||
@Nullable PsiElement element,
|
@Nullable PsiElement element,
|
||||||
@Nullable List<JetExpression> arguments,
|
@Nullable List<JetExpression> arguments,
|
||||||
StackValue receiver,
|
StackValue receiver
|
||||||
@NotNull GenerationState state
|
|
||||||
) {
|
) {
|
||||||
boolean nullable = returnType.getSort() == Type.OBJECT;
|
assert isPrimitive(returnType) : "Return type of UnaryPlus intrinsic should be of primitive type : " + returnType;
|
||||||
assert !nullable : "Return type of UnaryPlus intrinsic should be of primitive type : " + returnType;
|
|
||||||
|
|
||||||
if (receiver != null && receiver != StackValue.none()) {
|
if (receiver != null && receiver != StackValue.none()) {
|
||||||
receiver.put(returnType, v);
|
receiver.put(returnType, v);
|
||||||
@@ -51,6 +49,6 @@ public class UnaryPlus implements IntrinsicMethod {
|
|||||||
assert arguments != null;
|
assert arguments != null;
|
||||||
codegen.gen(arguments.get(0), returnType);
|
codegen.gen(arguments.get(0), returnType);
|
||||||
}
|
}
|
||||||
return StackValue.onStack(returnType);
|
return returnType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,6 @@ public class AsmTypeConstants {
|
|||||||
public static final Type JET_UNIT_TYPE = Type.getObjectType("jet/Unit");
|
public static final Type JET_UNIT_TYPE = Type.getObjectType("jet/Unit");
|
||||||
public static final Type JET_FUNCTION0_TYPE = Type.getObjectType("jet/Function0");
|
public static final Type JET_FUNCTION0_TYPE = Type.getObjectType("jet/Function0");
|
||||||
public static final Type JET_FUNCTION1_TYPE = Type.getObjectType("jet/Function1");
|
public static final Type JET_FUNCTION1_TYPE = Type.getObjectType("jet/Function1");
|
||||||
public static final Type JET_ITERATOR_TYPE = Type.getObjectType("jet/Iterator");
|
|
||||||
public static final Type JET_INT_RANGE_TYPE = Type.getObjectType("jet/IntRange");
|
public static final Type JET_INT_RANGE_TYPE = Type.getObjectType("jet/IntRange");
|
||||||
public static final Type JET_SHARED_VAR_TYPE = Type.getObjectType("jet/runtime/SharedVar$Object");
|
public static final Type JET_SHARED_VAR_TYPE = Type.getObjectType("jet/runtime/SharedVar$Object");
|
||||||
public static final Type JET_SHARED_INT_TYPE = Type.getObjectType("jet/runtime/SharedVar$Int");
|
public static final Type JET_SHARED_INT_TYPE = Type.getObjectType("jet/runtime/SharedVar$Int");
|
||||||
|
|||||||
Reference in New Issue
Block a user