Lazy intrinsic generation

#KT-6241 Fixed
This commit is contained in:
Michael Bogdanov
2014-11-20 16:34:51 +03:00
parent 4812564441
commit 3a70992d27
47 changed files with 744 additions and 559 deletions
@@ -433,10 +433,10 @@ public class AsmUtil {
v.invokevirtual("java/lang/StringBuilder", "append", "(" + type.getDescriptor() + ")Ljava/lang/StringBuilder;", false);
}
public static StackValue genToString(final InstructionAdapter v, final StackValue receiver, final Type receiverType) {
public static StackValue genToString(final StackValue receiver, final Type receiverType) {
return StackValue.operation(JAVA_STRING_TYPE, new Function1<InstructionAdapter, Unit>() {
@Override
public Unit invoke(InstructionAdapter adapter) {
public Unit invoke(InstructionAdapter v) {
Type type = stringValueOfType(receiverType);
receiver.put(type, v);
v.invokestatic("java/lang/String", "valueOf", "(" + type.getDescriptor() + ")Ljava/lang/String;", false);
@@ -545,9 +545,7 @@ public class AsmUtil {
}
public static Type genNegate(Type expectedType, InstructionAdapter v) {
if (expectedType == Type.BYTE_TYPE || expectedType == Type.SHORT_TYPE || expectedType == Type.CHAR_TYPE) {
expectedType = Type.INT_TYPE;
}
expectedType = numberFunctionOperandType(expectedType);
v.neg(expectedType);
return expectedType;
}
@@ -768,7 +766,7 @@ public class AsmUtil {
@NotNull
public static Type numberFunctionOperandType(@NotNull Type expectedType) {
if (expectedType == Type.SHORT_TYPE || expectedType == Type.BYTE_TYPE) {
if (expectedType == Type.SHORT_TYPE || expectedType == Type.BYTE_TYPE || expectedType == Type.CHAR_TYPE) {
return Type.INT_TYPE;
}
return expectedType;
@@ -1297,7 +1297,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
if (entries.length == 1 && entries[0] instanceof JetStringTemplateEntryWithExpression) {
JetExpression expr = entries[0].getExpression();
return genToString(v, gen(expr), expressionType(expr));
return genToString(gen(expr), expressionType(expr));
}
for (JetStringTemplateEntry entry : entries) {
@@ -3434,7 +3434,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
private StackValue generateNewArray(@NotNull JetCallExpression expression, @NotNull final JetType arrayType) {
final List < JetExpression > args = new ArrayList<JetExpression>();
final List<JetExpression> args = new ArrayList<JetExpression>();
for (ValueArgument va : expression.getValueArguments()) {
args.add(va.getArgumentExpression());
}
@@ -402,6 +402,9 @@ public abstract class StackValue {
}
public static StackValue coercion(@NotNull StackValue value, @NotNull Type castType) {
if (value.type.equals(castType)) {
return value;
}
return new CoercionValue(value, castType);
}
@@ -69,7 +69,11 @@ public class StackValueWithLeaveTask(
}
}
open class OperationStackValue(val resultType: Type, val lambda: (v: InstructionAdapter)-> Unit) : StackValue(resultType) {
fun operation(resultType: Type, lambda: (v: InstructionAdapter) -> Unit): StackValue {
return OperationStackValue(resultType, lambda)
}
open class OperationStackValue(val resultType: Type, val lambda: (v: InstructionAdapter) -> Unit) : StackValue(resultType) {
override fun putSelector(type: Type, v: InstructionAdapter) {
lambda(v)
@@ -77,5 +81,5 @@ open class OperationStackValue(val resultType: Type, val lambda: (v: Instruction
}
}
class FunctionCallStackValue(resultType: Type, lambda: (v: InstructionAdapter)-> Unit) : OperationStackValue(resultType, lambda)
class FunctionCallStackValue(resultType: Type, lambda: (v: InstructionAdapter) -> Unit) : OperationStackValue(resultType, lambda)
@@ -19,7 +19,6 @@ package org.jetbrains.jet.codegen.intrinsics;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
import org.jetbrains.jet.codegen.ExpressionCodegen;
import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.lang.psi.JetExpression;
@@ -28,12 +27,11 @@ import java.util.List;
import static org.jetbrains.jet.codegen.AsmUtil.correctElementType;
public class ArrayGet extends IntrinsicMethod {
public class ArrayGet extends LazyIntrinsicMethod {
@NotNull
@Override
public Type generateImpl(
public StackValue generateImpl(
@NotNull ExpressionCodegen codegen,
@NotNull InstructionAdapter v,
@NotNull Type returnType,
PsiElement element,
@NotNull List<JetExpression> arguments,
@@ -46,14 +44,8 @@ public class ArrayGet extends IntrinsicMethod {
} else {
argumentIndex = 0;
}
receiver.put(receiver.type, v);
Type type = correctElementType(receiver.type);
codegen.gen(arguments.get(argumentIndex), Type.INT_TYPE);
v.aload(type);
return type;
return StackValue.arrayElement(type, receiver, StackValue.coercion(codegen.gen(arguments.get(argumentIndex)), Type.INT_TYPE));
}
}
@@ -1,44 +0,0 @@
/*
* 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;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
import org.jetbrains.jet.codegen.ExpressionCodegen;
import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.lang.psi.JetExpression;
import java.util.List;
public class ArraySize extends IntrinsicMethod {
@NotNull
@Override
public Type generateImpl(
@NotNull ExpressionCodegen codegen,
@NotNull InstructionAdapter v,
@NotNull Type returnType,
PsiElement element,
@NotNull List<JetExpression> arguments,
@NotNull StackValue receiver
) {
receiver.put(receiver.type, v);
v.arraylength();
return Type.INT_TYPE;
}
}
@@ -0,0 +1,40 @@
/*
* Copyright 2010-2014 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.org.objectweb.asm.Type
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
import org.jetbrains.jet.codegen.ExpressionCodegen
import org.jetbrains.jet.codegen.StackValue
import org.jetbrains.jet.lang.psi.JetExpression
import org.jetbrains.jet.codegen.operation
public class ArraySize : LazyIntrinsicMethod() {
override fun generateImpl(
codegen: ExpressionCodegen,
returnType: Type,
element: PsiElement?,
arguments: List<JetExpression>,
receiver: StackValue
): StackValue {
return operation(Type.INT_TYPE) {
receiver.put(receiver.type, it)
it.arraylength()
}
}
}
@@ -1,72 +0,0 @@
/*
* 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;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
import org.jetbrains.jet.codegen.ExpressionCodegen;
import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.lang.psi.JetExpression;
import java.util.List;
import static org.jetbrains.org.objectweb.asm.Opcodes.*;
import static org.jetbrains.jet.codegen.AsmUtil.isPrimitive;
import static org.jetbrains.jet.codegen.AsmUtil.numberFunctionOperandType;
public class BinaryOp extends IntrinsicMethod {
private final int opcode;
public BinaryOp(int opcode) {
this.opcode = opcode;
}
@NotNull
@Override
public Type generateImpl(
@NotNull ExpressionCodegen codegen,
@NotNull InstructionAdapter v,
@NotNull Type returnType,
PsiElement element,
@NotNull List<JetExpression> arguments,
@NotNull StackValue receiver
) {
assert isPrimitive(returnType) : "Return type of BinaryOp intrinsic should be of primitive type : " + returnType;
Type operandType = numberFunctionOperandType(returnType);
if (arguments.size() == 1) {
// Intrinsic is called as an ordinary function
if (receiver != StackValue.none()) {
receiver.put(operandType, v);
}
codegen.gen(arguments.get(0), shift() ? Type.INT_TYPE : operandType);
}
else {
codegen.gen(arguments.get(0), operandType);
codegen.gen(arguments.get(1), shift() ? Type.INT_TYPE : operandType);
}
v.visitInsn(returnType.getOpcode(opcode));
return returnType;
}
private boolean shift() {
return opcode == ISHL || opcode == ISHR || opcode == IUSHR;
}
}
@@ -0,0 +1,55 @@
/*
* Copyright 2010-2014 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.org.objectweb.asm.Type
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
import org.jetbrains.jet.codegen.ExpressionCodegen
import org.jetbrains.jet.codegen.StackValue
import org.jetbrains.jet.lang.psi.JetExpression
import org.jetbrains.org.objectweb.asm.Opcodes.*
import org.jetbrains.jet.codegen.AsmUtil.isPrimitive
import org.jetbrains.jet.codegen.AsmUtil.numberFunctionOperandType
public class BinaryOp(private val opcode: Int) : IntrinsicMethod() {
override fun generateImpl(codegen: ExpressionCodegen, v: InstructionAdapter, returnType: Type, element: PsiElement?, arguments: List<JetExpression>, receiver: StackValue): Type {
assert(isPrimitive(returnType)) { "Return type of BinaryOp intrinsic should be of primitive type : " + returnType }
val operandType = numberFunctionOperandType(returnType)
if (arguments.size() == 1) {
// Intrinsic is called as an ordinary function
if (receiver != StackValue.none()) {
receiver.put(operandType, v)
}
codegen.gen(arguments.get(0), if (shift()) Type.INT_TYPE else operandType)
}
else {
codegen.gen(arguments.get(0), operandType)
codegen.gen(arguments.get(1), if (shift()) Type.INT_TYPE else operandType)
}
v.visitInsn(returnType.getOpcode(opcode))
return returnType
}
private fun shift(): Boolean {
return opcode == ISHL || opcode == ISHR || opcode == IUSHR
}
}
@@ -1,59 +0,0 @@
/*
* 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;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
import org.jetbrains.jet.codegen.ExpressionCodegen;
import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.lang.psi.JetCallExpression;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lexer.JetTokens;
import java.util.List;
import static org.jetbrains.jet.codegen.AsmUtil.genEqualsForExpressionsOnStack;
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE;
public class Equals extends IntrinsicMethod {
@NotNull
@Override
public Type generateImpl(
@NotNull ExpressionCodegen codegen,
@NotNull InstructionAdapter v,
@NotNull Type returnType,
PsiElement element,
@NotNull List<JetExpression> arguments,
@NotNull StackValue receiver
) {
StackValue leftExpr;
JetExpression rightExpr;
if (element instanceof JetCallExpression) {
leftExpr = StackValue.coercion(receiver, OBJECT_TYPE);
rightExpr = arguments.get(0);
}
else {
leftExpr = codegen.genLazy(arguments.get(0), OBJECT_TYPE);
rightExpr = arguments.get(1);
}
genEqualsForExpressionsOnStack(JetTokens.EQEQ, leftExpr, codegen.genLazy(rightExpr, OBJECT_TYPE)).put(returnType, v);
return returnType;
}
}
@@ -0,0 +1,50 @@
/*
* Copyright 2010-2014 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.org.objectweb.asm.Type
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
import org.jetbrains.jet.codegen.ExpressionCodegen
import org.jetbrains.jet.codegen.StackValue
import org.jetbrains.jet.lang.psi.JetCallExpression
import org.jetbrains.jet.lang.psi.JetExpression
import org.jetbrains.jet.lexer.JetTokens
import org.jetbrains.jet.codegen.AsmUtil.genEqualsForExpressionsOnStack
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE
public class Equals : LazyIntrinsicMethod() {
override fun generateImpl(codegen: ExpressionCodegen,
returnType: Type,
element: PsiElement?,
arguments: List<JetExpression>,
receiver: StackValue): StackValue {
val leftExpr: StackValue
val rightExpr: JetExpression
if (element is JetCallExpression) {
leftExpr = StackValue.coercion(receiver, OBJECT_TYPE)
rightExpr = arguments.get(0)
}
else {
leftExpr = codegen.genLazy(arguments.get(0), OBJECT_TYPE)
rightExpr = arguments.get(1)
}
return genEqualsForExpressionsOnStack(JetTokens.EQEQ, leftExpr, codegen.genLazy(rightExpr, OBJECT_TYPE))
}
}
@@ -0,0 +1,41 @@
/*
* Copyright 2010-2014 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.org.objectweb.asm.Opcodes
import org.jetbrains.org.objectweb.asm.Type
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
import org.jetbrains.jet.codegen.ExpressionCodegen
import org.jetbrains.jet.codegen.StackValue
import org.jetbrains.jet.lang.psi.JetExpression
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants
import org.jetbrains.jet.codegen.operation
public class HashCode : LazyIntrinsicMethod() {
override fun generateImpl(codegen: ExpressionCodegen,
returnType: Type,
element: PsiElement?,
arguments: List<JetExpression>,
receiver: StackValue): StackValue {
return operation(Type.INT_TYPE) {
receiver.put(AsmTypeConstants.OBJECT_TYPE, it)
it.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "hashCode", "()I", false)
}
}
}
@@ -18,25 +18,23 @@ package org.jetbrains.jet.codegen.intrinsics;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
import org.jetbrains.jet.codegen.ExpressionCodegen;
import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.lang.psi.JetBinaryExpression;
import org.jetbrains.jet.lang.psi.JetCallExpression;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.org.objectweb.asm.Type;
import java.util.List;
import static org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE;
public class IdentityEquals extends IntrinsicMethod {
public class IdentityEquals extends LazyIntrinsicMethod {
@NotNull
@Override
public Type generateImpl(
public StackValue generateImpl(
@NotNull ExpressionCodegen codegen,
@NotNull InstructionAdapter v,
@NotNull Type returnType,
PsiElement element,
@NotNull List<JetExpression> arguments,
@@ -54,7 +52,6 @@ public class IdentityEquals extends IntrinsicMethod {
left = codegen.gen(e.getLeft());
right = codegen.gen(e.getRight());
}
StackValue.cmp(JetTokens.EQEQEQ, OBJECT_TYPE, left, right).put(returnType, v);
return returnType;
return StackValue.cmp(JetTokens.EQEQEQ, OBJECT_TYPE, left, right);
}
}
@@ -1,69 +0,0 @@
/*
* 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;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.codegen.ExpressionCodegen;
import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
import java.util.List;
import static org.jetbrains.jet.codegen.AsmUtil.genIncrement;
import static org.jetbrains.jet.codegen.AsmUtil.isPrimitive;
public class Increment extends IntrinsicMethod {
private final int myDelta;
public Increment(int delta) {
myDelta = delta;
}
@NotNull
@Override
public Type generateImpl(
@NotNull ExpressionCodegen codegen,
@NotNull InstructionAdapter v,
@NotNull Type returnType,
PsiElement element,
@NotNull List<JetExpression> arguments,
@NotNull StackValue receiver
) {
assert isPrimitive(returnType) : "Return type of Increment intrinsic should be of primitive type : " + returnType;
if (arguments.size() > 0) {
JetExpression operand = arguments.get(0);
StackValue stackValue = codegen.genQualified(receiver, operand);
StackValue result;
if (stackValue instanceof StackValue.Local && Type.INT_TYPE.equals(stackValue.type)) {
result = StackValue.preIncrementForLocalVar(((StackValue.Local) stackValue).index, myDelta);
} else {
result = StackValue.preIncrement(returnType, stackValue, myDelta, this, null, codegen);
}
result.put(returnType, v);
}
else {
receiver.put(returnType, v);
genIncrement(returnType, myDelta, v);
}
return returnType;
}
}
@@ -0,0 +1,57 @@
/*
* Copyright 2010-2014 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.jet.codegen.ExpressionCodegen
import org.jetbrains.jet.codegen.StackValue
import org.jetbrains.jet.lang.psi.JetExpression
import org.jetbrains.jet.lang.psi.JetPsiUtil
import org.jetbrains.jet.lang.psi.JetReferenceExpression
import org.jetbrains.jet.lang.types.JetType
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
import org.jetbrains.org.objectweb.asm.Type
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
import org.jetbrains.jet.codegen.AsmUtil.genIncrement
import org.jetbrains.jet.codegen.AsmUtil.isPrimitive
import org.jetbrains.jet.lang.resolve.BindingContext.EXPRESSION_TYPE
import org.jetbrains.jet.codegen.operation
public class Increment(private val myDelta: Int) : LazyIntrinsicMethod() {
override fun generateImpl(codegen: ExpressionCodegen, returnType: Type, element: PsiElement?, arguments: List<JetExpression>, receiver: StackValue): StackValue {
assert(isPrimitive(returnType)) { "Return type of Increment intrinsic should be of primitive type : " + returnType }
if (arguments.size() > 0) {
val operand = arguments.get(0)
val stackValue = codegen.genQualified(receiver, operand)
if (stackValue is StackValue.Local && Type.INT_TYPE == stackValue.type) {
return StackValue.preIncrementForLocalVar((stackValue as StackValue.Local).index, myDelta)
}
else {
return StackValue.preIncrement(returnType, stackValue, myDelta, this, null, codegen)
}
}
else {
return operation(returnType) {
receiver.put(returnType, it)
genIncrement(returnType, myDelta, it)
}
}
}
}
@@ -31,7 +31,7 @@ import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
import java.util.List;
public abstract class IntrinsicMethod implements Callable {
public final StackValue generate(
public StackValue generate(
@NotNull final ExpressionCodegen codegen,
@NotNull final Type returnType,
@Nullable final PsiElement element,
@@ -39,7 +39,6 @@ public abstract class IntrinsicMethod implements Callable {
@NotNull final StackValue receiver
) {
return StackValue.operation(returnType, new Function1<InstructionAdapter, Unit>() {
@Override
public Unit invoke(InstructionAdapter v) {
Type actualType = generateImpl(codegen, v, returnType, element, arguments, receiver);
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
* Copyright 2010-2014 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.
@@ -19,20 +19,30 @@ package org.jetbrains.jet.codegen.intrinsics;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.org.objectweb.asm.Opcodes;
import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
import org.jetbrains.jet.codegen.ExpressionCodegen;
import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
import java.util.List;
public class HashCode extends IntrinsicMethod {
public abstract class LazyIntrinsicMethod extends IntrinsicMethod {
@Override
public final StackValue generate(
@NotNull ExpressionCodegen codegen,
@NotNull Type returnType,
@Nullable PsiElement element,
@NotNull List<JetExpression> arguments,
@NotNull StackValue receiver
) {
return StackValue.coercion(generateImpl(codegen, returnType, element, arguments, receiver), returnType);
}
@NotNull
@Override
public Type generateImpl(
protected Type generateImpl(
@NotNull ExpressionCodegen codegen,
@NotNull InstructionAdapter v,
@NotNull Type returnType,
@@ -40,8 +50,14 @@ public class HashCode extends IntrinsicMethod {
@NotNull List<JetExpression> arguments,
@NotNull StackValue receiver
) {
receiver.put(AsmTypeConstants.OBJECT_TYPE, v);
v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "hashCode", "()I", false);
return Type.INT_TYPE;
throw new UnsupportedOperationException();
}
public abstract StackValue generateImpl(
@NotNull ExpressionCodegen codegen,
@NotNull Type returnType,
@Nullable PsiElement element,
@NotNull List<JetExpression> arguments,
@NotNull StackValue receiver
);
}
@@ -18,27 +18,24 @@ package org.jetbrains.jet.codegen.intrinsics;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
import org.jetbrains.jet.codegen.ExpressionCodegen;
import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.lang.psi.JetCallExpression;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.org.objectweb.asm.Type;
import java.util.List;
public class NewArray extends IntrinsicMethod {
public class NewArray extends LazyIntrinsicMethod {
@NotNull
@Override
public Type generateImpl(
public StackValue generateImpl(
@NotNull ExpressionCodegen codegen,
@NotNull InstructionAdapter v,
@NotNull Type returnType,
PsiElement element,
@NotNull List<JetExpression> arguments,
@NotNull StackValue receiver
) {
codegen.generateNewArray((JetCallExpression) element).put(returnType, v);
return returnType;
return codegen.generateNewArray((JetCallExpression) element);
}
}
@@ -19,19 +19,17 @@ package org.jetbrains.jet.codegen.intrinsics;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
import org.jetbrains.jet.codegen.ExpressionCodegen;
import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.lang.psi.JetExpression;
import java.util.List;
public class Not extends IntrinsicMethod {
public class Not extends LazyIntrinsicMethod {
@NotNull
@Override
public Type generateImpl(
public StackValue generateImpl(
@NotNull ExpressionCodegen codegen,
@NotNull InstructionAdapter v,
@NotNull Type returnType,
PsiElement element,
@NotNull List<JetExpression> arguments,
@@ -44,7 +42,6 @@ public class Not extends IntrinsicMethod {
else {
stackValue = receiver;
}
StackValue.not(StackValue.coercion(stackValue, Type.BOOLEAN_TYPE)).put(returnType, v);
return returnType;
return StackValue.not(StackValue.coercion(stackValue, Type.BOOLEAN_TYPE));
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
* Copyright 2010-2014 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.
@@ -18,26 +18,23 @@ package org.jetbrains.jet.codegen.intrinsics;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
import org.jetbrains.jet.codegen.ExpressionCodegen;
import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.org.objectweb.asm.Type;
import java.util.List;
public class NumberCast extends IntrinsicMethod {
public class NumberCast extends LazyIntrinsicMethod {
@NotNull
@Override
public Type generateImpl(
public StackValue generateImpl(
@NotNull ExpressionCodegen codegen,
@NotNull InstructionAdapter v,
@NotNull Type returnType,
PsiElement element,
@NotNull List<JetExpression> arguments,
@NotNull StackValue receiver
) {
receiver.put(returnType, v);
return returnType;
return StackValue.coercion(receiver, returnType);
}
}
@@ -1,49 +0,0 @@
/*
* 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;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
import org.jetbrains.jet.codegen.ExpressionCodegen;
import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.lang.psi.JetExpression;
import java.util.List;
public class StringGetChar extends IntrinsicMethod {
@NotNull
@Override
public Type generateImpl(
@NotNull ExpressionCodegen codegen,
@NotNull InstructionAdapter v,
@NotNull Type returnType,
PsiElement element,
@NotNull List<JetExpression> arguments,
@NotNull StackValue receiver
) {
if (receiver != StackValue.none()) {
receiver.put(receiver.type, v);
}
if (!arguments.isEmpty()) {
codegen.gen(arguments.get(0)).put(Type.INT_TYPE, v);
}
v.invokeinterface("java/lang/CharSequence", "charAt", "(I)C");
return Type.CHAR_TYPE;
}
}
@@ -0,0 +1,44 @@
/*
* Copyright 2010-2014 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.org.objectweb.asm.Type
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
import org.jetbrains.jet.codegen.ExpressionCodegen
import org.jetbrains.jet.codegen.StackValue
import org.jetbrains.jet.lang.psi.JetExpression
import org.jetbrains.jet.codegen.operation
public class StringGetChar : LazyIntrinsicMethod() {
override fun generateImpl(codegen: ExpressionCodegen,
returnType: Type,
element: PsiElement?,
arguments: List<JetExpression>,
receiver: StackValue): StackValue {
return operation(Type.CHAR_TYPE) {
if (receiver != StackValue.none()) {
receiver.put(receiver.type, it)
}
if (!arguments.isEmpty()) {
codegen.gen(arguments.get(0)).put(Type.INT_TYPE, it)
}
it.invokeinterface("java/lang/CharSequence", "charAt", "(I)C")
}
}
}
@@ -1,44 +0,0 @@
/*
* 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;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
import org.jetbrains.jet.codegen.ExpressionCodegen;
import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.lang.psi.JetExpression;
import java.util.List;
public class StringLength extends IntrinsicMethod {
@NotNull
@Override
public Type generateImpl(
@NotNull ExpressionCodegen codegen,
@NotNull InstructionAdapter v,
@NotNull Type returnType,
PsiElement element,
List<JetExpression> arguments,
StackValue receiver
) {
receiver.put(receiver.type, v);
v.invokeinterface("java/lang/CharSequence", "length", "()I");
return Type.INT_TYPE;
}
}
@@ -0,0 +1,40 @@
/*
* Copyright 2010-2014 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.org.objectweb.asm.Type
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
import org.jetbrains.jet.codegen.ExpressionCodegen
import org.jetbrains.jet.codegen.StackValue
import org.jetbrains.jet.lang.psi.JetExpression
import org.jetbrains.jet.codegen.operation
public class StringLength : LazyIntrinsicMethod() {
override fun generateImpl(
codegen: ExpressionCodegen,
returnType: Type,
element: PsiElement?,
arguments: List<JetExpression>,
receiver: StackValue
): StackValue {
return operation(Type.INT_TYPE) {
receiver.put(receiver.type, it)
it.invokeinterface("java/lang/CharSequence", "length", "()I")
}
}
}
@@ -1,54 +0,0 @@
/*
* 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;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.codegen.ExpressionCodegen;
import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
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.OBJECT_TYPE;
public class StringPlus extends IntrinsicMethod {
@NotNull
@Override
public Type generateImpl(
@NotNull ExpressionCodegen codegen,
@NotNull InstructionAdapter v,
@NotNull Type returnType,
PsiElement element,
@NotNull List<JetExpression> arguments,
@NotNull StackValue receiver
) {
if (receiver == StackValue.none()) {
codegen.gen(arguments.get(0)).put(JAVA_STRING_TYPE, v);
codegen.gen(arguments.get(1)).put(OBJECT_TYPE, v);
}
else {
receiver.put(JAVA_STRING_TYPE, v);
codegen.gen(arguments.get(0)).put(OBJECT_TYPE, v);
}
v.invokestatic(IntrinsicMethods.INTRINSICS_CLASS_NAME, "stringPlus", "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/String;", false);
return JAVA_STRING_TYPE;
}
}
@@ -0,0 +1,50 @@
/*
* Copyright 2010-2014 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.jet.codegen.ExpressionCodegen
import org.jetbrains.jet.codegen.StackValue
import org.jetbrains.jet.lang.psi.JetExpression
import org.jetbrains.org.objectweb.asm.Type
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.JAVA_STRING_TYPE
import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants.OBJECT_TYPE
import org.jetbrains.jet.codegen.operation
public class StringPlus : LazyIntrinsicMethod() {
override fun generateImpl(
codegen: ExpressionCodegen,
returnType: Type,
element: PsiElement?,
arguments: List<JetExpression>,
receiver: StackValue
): StackValue {
return operation(JAVA_STRING_TYPE) {
if (receiver == StackValue.none()) {
codegen.gen(arguments.get(0)).put(JAVA_STRING_TYPE, it)
codegen.gen(arguments.get(1)).put(OBJECT_TYPE, it)
}
else {
receiver.put(JAVA_STRING_TYPE, it)
codegen.gen(arguments.get(0)).put(OBJECT_TYPE, it)
}
it.invokestatic(IntrinsicMethods.INTRINSICS_CLASS_NAME, "stringPlus", "(Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/String;", false)
}
}
}
@@ -1,45 +0,0 @@
/*
* 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;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
import org.jetbrains.jet.codegen.ExpressionCodegen;
import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.lang.psi.JetExpression;
import java.util.List;
import static org.jetbrains.jet.codegen.AsmUtil.genToString;
public class ToString extends IntrinsicMethod {
@NotNull
@Override
public Type generateImpl(
@NotNull ExpressionCodegen codegen,
@NotNull InstructionAdapter v,
@NotNull Type returnType,
PsiElement element,
@NotNull List<JetExpression> arguments,
@NotNull StackValue receiver
) {
genToString(v, receiver, receiver.type).put(returnType, v);
return returnType;
}
}
@@ -0,0 +1,36 @@
/*
* 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
import com.intellij.psi.PsiElement
import org.jetbrains.org.objectweb.asm.Type
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
import org.jetbrains.jet.codegen.ExpressionCodegen
import org.jetbrains.jet.codegen.StackValue
import org.jetbrains.jet.lang.psi.JetExpression
import org.jetbrains.jet.codegen.AsmUtil.genToString
public class ToString : LazyIntrinsicMethod() {
override fun generateImpl(codegen: ExpressionCodegen,
returnType: Type,
element: PsiElement?,
arguments: List<JetExpression>,
receiver: StackValue): StackValue {
return genToString(receiver, receiver.type)
}
}
@@ -1,54 +0,0 @@
/*
* 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;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
import org.jetbrains.jet.codegen.ExpressionCodegen;
import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.lang.psi.JetExpression;
import java.util.List;
import static org.jetbrains.jet.codegen.AsmUtil.*;
public class UnaryMinus extends IntrinsicMethod {
@NotNull
@Override
public Type generateImpl(
@NotNull ExpressionCodegen codegen,
@NotNull InstructionAdapter v,
@NotNull Type returnType,
PsiElement element,
List<JetExpression> arguments,
StackValue receiver
) {
assert isPrimitive(returnType) : "Return type of UnaryMinus intrinsic should be of primitive type: " + returnType;
Type operandType = numberFunctionOperandType(returnType);
if (arguments.size() == 1) {
codegen.gen(arguments.get(0), operandType);
}
else {
receiver.put(operandType, v);
}
return genNegate(returnType, v);
}
}
@@ -0,0 +1,47 @@
/*
* Copyright 2010-2014 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.org.objectweb.asm.Type
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
import org.jetbrains.jet.codegen.ExpressionCodegen
import org.jetbrains.jet.codegen.StackValue
import org.jetbrains.jet.lang.psi.JetExpression
import org.jetbrains.jet.codegen.AsmUtil.*
import org.jetbrains.jet.codegen.operation
public class UnaryMinus : LazyIntrinsicMethod() {
override fun generateImpl(codegen: ExpressionCodegen,
returnType: Type,
element: PsiElement?,
arguments: List<JetExpression>,
receiver: StackValue): StackValue {
assert(isPrimitive(returnType)) { "Return type of UnaryMinus intrinsic should be of primitive type: " + returnType }
val operandType = numberFunctionOperandType(returnType)
val newreceiver = if (arguments.size() == 1) codegen.gen(arguments.get(0)) else receiver
return operation(operandType) {
newreceiver.put(operandType, it)
genNegate(operandType, it)
}
}
}
@@ -20,7 +20,6 @@ import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
import org.jetbrains.jet.codegen.ExpressionCodegen;
import org.jetbrains.jet.codegen.StackValue;
import org.jetbrains.jet.lang.psi.JetExpression;
@@ -29,12 +28,11 @@ import java.util.List;
import static org.jetbrains.jet.codegen.AsmUtil.isPrimitive;
public class UnaryPlus extends IntrinsicMethod {
public class UnaryPlus extends LazyIntrinsicMethod {
@NotNull
@Override
public Type generateImpl(
public StackValue generateImpl(
@NotNull ExpressionCodegen codegen,
@NotNull InstructionAdapter v,
@NotNull Type returnType,
@Nullable PsiElement element,
@NotNull List<JetExpression> arguments,
@@ -43,12 +41,11 @@ public class UnaryPlus extends IntrinsicMethod {
assert isPrimitive(returnType) : "Return type of UnaryPlus intrinsic should be of primitive type : " + returnType;
if (receiver != StackValue.none()) {
receiver.put(returnType, v);
return receiver;
}
else {
assert !arguments.isEmpty();
codegen.gen(arguments.get(0), returnType);
return codegen.gen(arguments.get(0));
}
return returnType;
}
}
@@ -0,0 +1,7 @@
fun box(): String {
if (!(1 < 2)) {
return "fail"
}
return "OK"
}
@@ -0,0 +1,7 @@
fun box(): String {
if (!false) {
return "OK"
} else {
return "fail"
}
}
@@ -0,0 +1,8 @@
fun box(): String {
var p = 2 < 1;
if (!p) {
return "OK"
} else {
return "fail"
}
}
@@ -0,0 +1,8 @@
fun box(): String {
val p = 2 < 1;
if (!!!!!p) {
return "OK"
} else {
return "fail"
}
}
@@ -0,0 +1,9 @@
val p: Int? = 1;
val z: Int? = 2;
fun box(): String {
if (!(p!! == z!!)) {
return "OK"
}
return "fail"
}
@@ -0,0 +1,9 @@
val p: Int? = 1;
val z: Int? = 2;
fun box(): String {
if (!(p!! < z!!)) {
return "fail"
}
return "OK"
}
@@ -0,0 +1,7 @@
fun box(): String {
if (!true) {
return "fail"
} else {
return "OK"
}
}
@@ -0,0 +1,8 @@
fun box(): String {
var p = 1 < 2;
if (!p) {
return "fail"
} else {
return "OK"
}
}
@@ -0,0 +1,12 @@
fun test4() {
if (!false) {
val p = 1
}
}
fun test5() {
if (!true) {
val p = 1
}
}
// 0 IF
@@ -0,0 +1,6 @@
fun test1() {
if (!(1 < 2)) {
val p = 1
}
}
// 1 IF
@@ -0,0 +1,10 @@
val p: Int? = 1;
val z: Int? = 2;
fun test3() {
if (!(p!! < z!!)) {
val p = 1
}
}
// 2 IFNONNULL
// 3 IF
@@ -0,0 +1,10 @@
val p: Int? = 1;
val z: Int? = 2;
fun test3() {
if (!!!(p!! < z!!)) {
val p = 1
}
}
// 2 IFNONNULL
// 3 IF
@@ -0,0 +1,7 @@
fun test2() {
val p = 1 < 2;
if (!p) {
val p = 1
}
}
// 2 IF
@@ -0,0 +1,7 @@
fun test2() {
val p = 1 < 2;
if (!!!!!!p) {
val p = 1
}
}
// 2 IF
@@ -30,7 +30,7 @@ import java.util.regex.Pattern;
@SuppressWarnings("all")
@TestMetadata("compiler/testData/codegen/bytecodeText")
@TestDataPath("$PROJECT_ROOT")
@InnerTestClasses({BytecodeTextTestGenerated.BoxingOptimization.class, BytecodeTextTestGenerated.Constants.class, BytecodeTextTestGenerated.DirectInvoke.class, BytecodeTextTestGenerated.Inline.class, BytecodeTextTestGenerated.LineNumbers.class, BytecodeTextTestGenerated.Statements.class, BytecodeTextTestGenerated.StaticFields.class, BytecodeTextTestGenerated.StoreStackBeforeInline.class, BytecodeTextTestGenerated.When.class, BytecodeTextTestGenerated.WhenEnumOptimization.class, BytecodeTextTestGenerated.WhenStringOptimization.class})
@InnerTestClasses({BytecodeTextTestGenerated.BoxingOptimization.class, BytecodeTextTestGenerated.Constants.class, BytecodeTextTestGenerated.DirectInvoke.class, BytecodeTextTestGenerated.Inline.class, BytecodeTextTestGenerated.LazyCodegen.class, BytecodeTextTestGenerated.LineNumbers.class, BytecodeTextTestGenerated.Statements.class, BytecodeTextTestGenerated.StaticFields.class, BytecodeTextTestGenerated.StoreStackBeforeInline.class, BytecodeTextTestGenerated.When.class, BytecodeTextTestGenerated.WhenEnumOptimization.class, BytecodeTextTestGenerated.WhenStringOptimization.class})
@RunWith(JUnit3RunnerWithInners.class)
public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
@TestMetadata("accessorForProtected.kt")
@@ -349,6 +349,51 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
}
}
@TestMetadata("compiler/testData/codegen/bytecodeText/lazyCodegen")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class LazyCodegen extends AbstractBytecodeTextTest {
public void testAllFilesPresentInLazyCodegen() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/bytecodeText/lazyCodegen"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("negateConst.kt")
public void testNegateConst() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/lazyCodegen/negateConst.kt");
doTest(fileName);
}
@TestMetadata("negateConstantCompare.kt")
public void testNegateConstantCompare() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/lazyCodegen/negateConstantCompare.kt");
doTest(fileName);
}
@TestMetadata("negateObjectComp.kt")
public void testNegateObjectComp() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/lazyCodegen/negateObjectComp.kt");
doTest(fileName);
}
@TestMetadata("negateObjectCompChaing.kt")
public void testNegateObjectCompChaing() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/lazyCodegen/negateObjectCompChaing.kt");
doTest(fileName);
}
@TestMetadata("negateVar.kt")
public void testNegateVar() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/lazyCodegen/negateVar.kt");
doTest(fileName);
}
@TestMetadata("negateVarChain.kt")
public void testNegateVarChain() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/lazyCodegen/negateVarChain.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/bytecodeText/lineNumbers")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -1466,6 +1466,7 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
@TestMetadata("compiler/testData/codegen/boxWithStdlib/lazyCodegen")
@TestDataPath("$PROJECT_ROOT")
@InnerTestClasses({LazyCodegen.Optimizations.class})
@RunWith(JUnit3RunnerWithInners.class)
public static class LazyCodegen extends AbstractBlackBoxCodegenTest {
public void testAllFilesPresentInLazyCodegen() throws Exception {
@@ -1525,6 +1526,63 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/lazyCodegen/when.kt");
doTestWithStdlib(fileName);
}
@TestMetadata("compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class Optimizations extends AbstractBlackBoxCodegenTest {
public void testAllFilesPresentInOptimizations() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("negateConstantCompare.kt")
public void testNegateConstantCompare() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateConstantCompare.kt");
doTestWithStdlib(fileName);
}
@TestMetadata("negateFalse.kt")
public void testNegateFalse() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateFalse.kt");
doTestWithStdlib(fileName);
}
@TestMetadata("negateFalseVar.kt")
public void testNegateFalseVar() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateFalseVar.kt");
doTestWithStdlib(fileName);
}
@TestMetadata("negateFalseVarChain.kt")
public void testNegateFalseVarChain() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateFalseVarChain.kt");
doTestWithStdlib(fileName);
}
@TestMetadata("negateObjectComp.kt")
public void testNegateObjectComp() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateObjectComp.kt");
doTestWithStdlib(fileName);
}
@TestMetadata("negateObjectComp2.kt")
public void testNegateObjectComp2() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateObjectComp2.kt");
doTestWithStdlib(fileName);
}
@TestMetadata("negateTrue.kt")
public void testNegateTrue() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateTrue.kt");
doTestWithStdlib(fileName);
}
@TestMetadata("negateTrueVar.kt")
public void testNegateTrueVar() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateTrueVar.kt");
doTestWithStdlib(fileName);
}
}
}
@TestMetadata("compiler/testData/codegen/boxWithStdlib/localFunInLambda")