diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/AsmUtil.java b/compiler/backend/src/org/jetbrains/jet/codegen/AsmUtil.java index 323582ae938..c233b5c9e79 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/AsmUtil.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/AsmUtil.java @@ -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() { @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; diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index d0e031ca5da..d3b99320834 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -1297,7 +1297,7 @@ public class ExpressionCodegen extends JetVisitor 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 implem private StackValue generateNewArray(@NotNull JetCallExpression expression, @NotNull final JetType arrayType) { - final List < JetExpression > args = new ArrayList(); + final List args = new ArrayList(); for (ValueArgument va : expression.getValueArguments()) { args.add(va.getArgumentExpression()); } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java index 4e7ca3420f9..5e36caf6b3d 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.java @@ -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); } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.kt b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.kt index ed553b3905c..6a0256a73eb 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.kt +++ b/compiler/backend/src/org/jetbrains/jet/codegen/StackValue.kt @@ -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) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArrayGet.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArrayGet.java index c87850e12d6..74e3ec177e9 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArrayGet.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArrayGet.java @@ -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 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)); } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArraySize.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArraySize.java deleted file mode 100644 index 12df917ec35..00000000000 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArraySize.java +++ /dev/null @@ -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 arguments, - @NotNull StackValue receiver - ) { - receiver.put(receiver.type, v); - v.arraylength(); - return Type.INT_TYPE; - } -} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArraySize.kt b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArraySize.kt new file mode 100644 index 00000000000..dc4527de696 --- /dev/null +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ArraySize.kt @@ -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, + receiver: StackValue + ): StackValue { + return operation(Type.INT_TYPE) { + receiver.put(receiver.type, it) + it.arraylength() + } + } +} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/BinaryOp.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/BinaryOp.java deleted file mode 100644 index f9a794fa57c..00000000000 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/BinaryOp.java +++ /dev/null @@ -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 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; - } -} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/BinaryOp.kt b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/BinaryOp.kt new file mode 100644 index 00000000000..33c048f77cf --- /dev/null +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/BinaryOp.kt @@ -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, 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 + } +} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Equals.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Equals.java deleted file mode 100644 index a7dcaddecf9..00000000000 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Equals.java +++ /dev/null @@ -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 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; - } -} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Equals.kt b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Equals.kt new file mode 100644 index 00000000000..f1054c0e073 --- /dev/null +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Equals.kt @@ -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, + 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)) + } +} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/HashCode.kt b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/HashCode.kt new file mode 100644 index 00000000000..30cf40837ec --- /dev/null +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/HashCode.kt @@ -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, + receiver: StackValue): StackValue { + + return operation(Type.INT_TYPE) { + receiver.put(AsmTypeConstants.OBJECT_TYPE, it) + it.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "hashCode", "()I", false) + } + } +} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IdentityEquals.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IdentityEquals.java index 4a80f29ae89..838967dff3d 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IdentityEquals.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IdentityEquals.java @@ -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 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); } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Increment.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Increment.java deleted file mode 100644 index 0ce4dd90be2..00000000000 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Increment.java +++ /dev/null @@ -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 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; - } -} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Increment.kt b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Increment.kt new file mode 100644 index 00000000000..565cfbf4776 --- /dev/null +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Increment.kt @@ -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, 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) + } + } + } +} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethod.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethod.java index a8746647975..c0dddf791f3 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethod.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/IntrinsicMethod.java @@ -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() { - @Override public Unit invoke(InstructionAdapter v) { Type actualType = generateImpl(codegen, v, returnType, element, arguments, receiver); diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/HashCode.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/LazyIntrinsicMethod.java similarity index 60% rename from compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/HashCode.java rename to compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/LazyIntrinsicMethod.java index 5762faedae5..17db4c20e78 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/HashCode.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/LazyIntrinsicMethod.java @@ -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 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 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 arguments, + @NotNull StackValue receiver + ); } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/NewArray.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/NewArray.java index 60f81656953..2830e5d4f4c 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/NewArray.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/NewArray.java @@ -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 arguments, @NotNull StackValue receiver ) { - codegen.generateNewArray((JetCallExpression) element).put(returnType, v); - return returnType; + return codegen.generateNewArray((JetCallExpression) element); } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Not.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Not.java index 344646f68b7..0dfffb3a8df 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Not.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/Not.java @@ -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 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)); } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/NumberCast.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/NumberCast.java index e0b9855fa56..e56f84e7efa 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/NumberCast.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/NumberCast.java @@ -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 arguments, @NotNull StackValue receiver ) { - receiver.put(returnType, v); - return returnType; + return StackValue.coercion(receiver, returnType); } } diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/StringGetChar.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/StringGetChar.java deleted file mode 100644 index dd2682f6acf..00000000000 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/StringGetChar.java +++ /dev/null @@ -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 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; - } -} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/StringGetChar.kt b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/StringGetChar.kt new file mode 100644 index 00000000000..7e7e34e6f74 --- /dev/null +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/StringGetChar.kt @@ -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, + 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") + } + } +} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/StringLength.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/StringLength.java deleted file mode 100644 index c477206dd03..00000000000 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/StringLength.java +++ /dev/null @@ -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 arguments, - StackValue receiver - ) { - receiver.put(receiver.type, v); - v.invokeinterface("java/lang/CharSequence", "length", "()I"); - return Type.INT_TYPE; - } -} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/StringLength.kt b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/StringLength.kt new file mode 100644 index 00000000000..771cde2bb21 --- /dev/null +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/StringLength.kt @@ -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, + receiver: StackValue + ): StackValue { + return operation(Type.INT_TYPE) { + receiver.put(receiver.type, it) + it.invokeinterface("java/lang/CharSequence", "length", "()I") + } + } +} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/StringPlus.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/StringPlus.java deleted file mode 100644 index e09cefc2330..00000000000 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/StringPlus.java +++ /dev/null @@ -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 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; - } -} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/StringPlus.kt b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/StringPlus.kt new file mode 100644 index 00000000000..553795617f9 --- /dev/null +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/StringPlus.kt @@ -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, + 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) + } + } +} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ToString.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ToString.java deleted file mode 100644 index adbecc5aff2..00000000000 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ToString.java +++ /dev/null @@ -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 arguments, - @NotNull StackValue receiver - ) { - genToString(v, receiver, receiver.type).put(returnType, v); - return returnType; - } -} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ToString.kt b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ToString.kt new file mode 100644 index 00000000000..ef5b09f380a --- /dev/null +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/ToString.kt @@ -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, + receiver: StackValue): StackValue { + return genToString(receiver, receiver.type) + } +} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnaryMinus.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnaryMinus.java deleted file mode 100644 index 07c2c3a40b1..00000000000 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnaryMinus.java +++ /dev/null @@ -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 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); - } -} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnaryMinus.kt b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnaryMinus.kt new file mode 100644 index 00000000000..d3ec209c39e --- /dev/null +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnaryMinus.kt @@ -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, + 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) + } + } +} diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnaryPlus.java b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnaryPlus.java index 0bd6fa8ed7b..7fc15b9aead 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnaryPlus.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/intrinsics/UnaryPlus.java @@ -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 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; } } diff --git a/compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateConstantCompare.kt b/compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateConstantCompare.kt new file mode 100644 index 00000000000..f68757d7588 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateConstantCompare.kt @@ -0,0 +1,7 @@ +fun box(): String { + if (!(1 < 2)) { + return "fail" + } + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateFalse.kt b/compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateFalse.kt new file mode 100644 index 00000000000..fd5ef04626e --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateFalse.kt @@ -0,0 +1,7 @@ +fun box(): String { + if (!false) { + return "OK" + } else { + return "fail" + } +} diff --git a/compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateFalseVar.kt b/compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateFalseVar.kt new file mode 100644 index 00000000000..c4ad074824a --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateFalseVar.kt @@ -0,0 +1,8 @@ +fun box(): String { + var p = 2 < 1; + if (!p) { + return "OK" + } else { + return "fail" + } +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateFalseVarChain.kt b/compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateFalseVarChain.kt new file mode 100644 index 00000000000..8f89b14fe90 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateFalseVarChain.kt @@ -0,0 +1,8 @@ +fun box(): String { + val p = 2 < 1; + if (!!!!!p) { + return "OK" + } else { + return "fail" + } +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateObjectComp.kt b/compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateObjectComp.kt new file mode 100644 index 00000000000..58e15f4de93 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateObjectComp.kt @@ -0,0 +1,9 @@ +val p: Int? = 1; +val z: Int? = 2; + +fun box(): String { + if (!(p!! == z!!)) { + return "OK" + } + return "fail" +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateObjectComp2.kt b/compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateObjectComp2.kt new file mode 100644 index 00000000000..e1a13f17cc9 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateObjectComp2.kt @@ -0,0 +1,9 @@ +val p: Int? = 1; +val z: Int? = 2; + +fun box(): String { + if (!(p!! < z!!)) { + return "fail" + } + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateTrue.kt b/compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateTrue.kt new file mode 100644 index 00000000000..487ec8c27a8 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateTrue.kt @@ -0,0 +1,7 @@ +fun box(): String { + if (!true) { + return "fail" + } else { + return "OK" + } +} diff --git a/compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateTrueVar.kt b/compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateTrueVar.kt new file mode 100644 index 00000000000..2c651614453 --- /dev/null +++ b/compiler/testData/codegen/boxWithStdlib/lazyCodegen/optimizations/negateTrueVar.kt @@ -0,0 +1,8 @@ +fun box(): String { + var p = 1 < 2; + if (!p) { + return "fail" + } else { + return "OK" + } +} \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/lazyCodegen/negateConst.kt b/compiler/testData/codegen/bytecodeText/lazyCodegen/negateConst.kt new file mode 100644 index 00000000000..43b2f2875c6 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/lazyCodegen/negateConst.kt @@ -0,0 +1,12 @@ +fun test4() { + if (!false) { + val p = 1 + } +} + +fun test5() { + if (!true) { + val p = 1 + } +} +// 0 IF \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/lazyCodegen/negateConstantCompare.kt b/compiler/testData/codegen/bytecodeText/lazyCodegen/negateConstantCompare.kt new file mode 100644 index 00000000000..931738dd0f7 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/lazyCodegen/negateConstantCompare.kt @@ -0,0 +1,6 @@ +fun test1() { + if (!(1 < 2)) { + val p = 1 + } +} +// 1 IF \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/lazyCodegen/negateObjectComp.kt b/compiler/testData/codegen/bytecodeText/lazyCodegen/negateObjectComp.kt new file mode 100644 index 00000000000..97a4da19884 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/lazyCodegen/negateObjectComp.kt @@ -0,0 +1,10 @@ +val p: Int? = 1; +val z: Int? = 2; + +fun test3() { + if (!(p!! < z!!)) { + val p = 1 + } +} +// 2 IFNONNULL +// 3 IF diff --git a/compiler/testData/codegen/bytecodeText/lazyCodegen/negateObjectCompChaing.kt b/compiler/testData/codegen/bytecodeText/lazyCodegen/negateObjectCompChaing.kt new file mode 100644 index 00000000000..697e7bc0927 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/lazyCodegen/negateObjectCompChaing.kt @@ -0,0 +1,10 @@ +val p: Int? = 1; +val z: Int? = 2; + +fun test3() { + if (!!!(p!! < z!!)) { + val p = 1 + } +} +// 2 IFNONNULL +// 3 IF diff --git a/compiler/testData/codegen/bytecodeText/lazyCodegen/negateVar.kt b/compiler/testData/codegen/bytecodeText/lazyCodegen/negateVar.kt new file mode 100644 index 00000000000..2c2c757fd7f --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/lazyCodegen/negateVar.kt @@ -0,0 +1,7 @@ +fun test2() { + val p = 1 < 2; + if (!p) { + val p = 1 + } +} +// 2 IF \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeText/lazyCodegen/negateVarChain.kt b/compiler/testData/codegen/bytecodeText/lazyCodegen/negateVarChain.kt new file mode 100644 index 00000000000..67566965af8 --- /dev/null +++ b/compiler/testData/codegen/bytecodeText/lazyCodegen/negateVarChain.kt @@ -0,0 +1,7 @@ +fun test2() { + val p = 1 < 2; + if (!!!!!!p) { + val p = 1 + } +} +// 2 IF \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/BytecodeTextTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/BytecodeTextTestGenerated.java index 938133a759d..6bc8037d783 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/BytecodeTextTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/BytecodeTextTestGenerated.java @@ -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) diff --git a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java index e6a1a29c4bb..21ca4eae3b0 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/codegen/generated/BlackBoxWithStdlibCodegenTestGenerated.java @@ -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")