Delete jet.runtime.Ranges intrinsics
All these "rangeTo" methods were pretty small and could be generated just right into "rangeTo" function calls
This commit is contained in:
@@ -27,6 +27,8 @@ import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.asm4.Type.*;
|
||||
|
||||
public class RangeTo extends IntrinsicMethod {
|
||||
@NotNull
|
||||
@Override
|
||||
@@ -38,24 +40,56 @@ public class RangeTo extends IntrinsicMethod {
|
||||
List<JetExpression> arguments,
|
||||
StackValue receiver
|
||||
) {
|
||||
Type leftType;
|
||||
Type rightType;
|
||||
v.anew(returnType);
|
||||
v.dup();
|
||||
|
||||
Type type;
|
||||
if (arguments.size() == 1) {
|
||||
leftType = receiver.type;
|
||||
rightType = codegen.expressionType(arguments.get(0));
|
||||
receiver.put(leftType, v);
|
||||
codegen.gen(arguments.get(0), rightType);
|
||||
assert receiver instanceof StackValue.CallReceiver :
|
||||
"Receiver in an intrinsic qualified expression should be CallReceiver: " + receiver + " on " + element.getText();
|
||||
type = parameterType(receiver.type, codegen.expressionType(arguments.get(0)));
|
||||
receiver.put(type, v);
|
||||
codegen.gen(arguments.get(0), type);
|
||||
}
|
||||
else {
|
||||
JetBinaryExpression expression = (JetBinaryExpression) element;
|
||||
leftType = codegen.expressionType(expression.getLeft());
|
||||
rightType = codegen.expressionType(expression.getRight());
|
||||
codegen.gen(expression.getLeft(), leftType);
|
||||
codegen.gen(expression.getRight(), rightType);
|
||||
type = parameterType(codegen.expressionType(expression.getLeft()), codegen.expressionType(expression.getRight()));
|
||||
codegen.gen(expression.getLeft(), type);
|
||||
codegen.gen(expression.getRight(), type);
|
||||
}
|
||||
|
||||
v.invokestatic("jet/runtime/Ranges", "rangeTo", Type.getMethodDescriptor(returnType, leftType, rightType));
|
||||
v.invokespecial(returnType.getInternalName(), "<init>", Type.getMethodDescriptor(Type.VOID_TYPE, type, type));
|
||||
|
||||
return returnType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Type parameterType(@NotNull Type leftType, @NotNull Type rightType) {
|
||||
int left = leftType.getSort();
|
||||
int right = rightType.getSort();
|
||||
if (left == DOUBLE || right == DOUBLE) {
|
||||
return DOUBLE_TYPE;
|
||||
}
|
||||
else if (left == FLOAT || right == FLOAT) {
|
||||
return FLOAT_TYPE;
|
||||
}
|
||||
else if (left == LONG || right == LONG) {
|
||||
return LONG_TYPE;
|
||||
}
|
||||
else if (left == INT || right == INT) {
|
||||
return INT_TYPE;
|
||||
}
|
||||
else if (left == SHORT || right == SHORT) {
|
||||
return SHORT_TYPE;
|
||||
}
|
||||
else if (left == CHAR || right == CHAR) {
|
||||
return CHAR_TYPE;
|
||||
}
|
||||
else if (left == BYTE || right == BYTE) {
|
||||
return BYTE_TYPE;
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("RangeTo intrinsic can only work for primitive types: " + leftType + ", " + rightType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,206 +16,9 @@
|
||||
|
||||
package jet.runtime;
|
||||
|
||||
import jet.*;
|
||||
import jet.IntRange;
|
||||
|
||||
/* This file is generated by org.jetbrains.jet.generators.builtins.GenerateRangeIntrinsics. DO NOT EDIT! */
|
||||
public class Ranges {
|
||||
public static ByteRange rangeTo(byte from, byte to) {
|
||||
return new ByteRange(from, to);
|
||||
}
|
||||
|
||||
public static ShortRange rangeTo(byte from, short to) {
|
||||
return new ShortRange(from, to);
|
||||
}
|
||||
|
||||
public static IntRange rangeTo(byte from, int to) {
|
||||
return new IntRange(from, to);
|
||||
}
|
||||
|
||||
public static LongRange rangeTo(byte from, long to) {
|
||||
return new LongRange(from, to);
|
||||
}
|
||||
|
||||
public static FloatRange rangeTo(byte from, float to) {
|
||||
return new FloatRange(from, to);
|
||||
}
|
||||
|
||||
public static DoubleRange rangeTo(byte from, double to) {
|
||||
return new DoubleRange(from, to);
|
||||
}
|
||||
|
||||
public static CharRange rangeTo(byte from, char to) {
|
||||
return new CharRange((char) from, to);
|
||||
}
|
||||
|
||||
public static ShortRange rangeTo(short from, byte to) {
|
||||
return new ShortRange(from, to);
|
||||
}
|
||||
|
||||
public static ShortRange rangeTo(short from, short to) {
|
||||
return new ShortRange(from, to);
|
||||
}
|
||||
|
||||
public static IntRange rangeTo(short from, int to) {
|
||||
return new IntRange(from, to);
|
||||
}
|
||||
|
||||
public static LongRange rangeTo(short from, long to) {
|
||||
return new LongRange(from, to);
|
||||
}
|
||||
|
||||
public static FloatRange rangeTo(short from, float to) {
|
||||
return new FloatRange(from, to);
|
||||
}
|
||||
|
||||
public static DoubleRange rangeTo(short from, double to) {
|
||||
return new DoubleRange(from, to);
|
||||
}
|
||||
|
||||
public static ShortRange rangeTo(short from, char to) {
|
||||
return new ShortRange(from, (short) to);
|
||||
}
|
||||
|
||||
public static IntRange rangeTo(int from, byte to) {
|
||||
return new IntRange(from, to);
|
||||
}
|
||||
|
||||
public static IntRange rangeTo(int from, short to) {
|
||||
return new IntRange(from, to);
|
||||
}
|
||||
|
||||
public static IntRange rangeTo(int from, int to) {
|
||||
return new IntRange(from, to);
|
||||
}
|
||||
|
||||
public static LongRange rangeTo(int from, long to) {
|
||||
return new LongRange(from, to);
|
||||
}
|
||||
|
||||
public static FloatRange rangeTo(int from, float to) {
|
||||
return new FloatRange(from, to);
|
||||
}
|
||||
|
||||
public static DoubleRange rangeTo(int from, double to) {
|
||||
return new DoubleRange(from, to);
|
||||
}
|
||||
|
||||
public static IntRange rangeTo(int from, char to) {
|
||||
return new IntRange(from, to);
|
||||
}
|
||||
|
||||
public static LongRange rangeTo(long from, byte to) {
|
||||
return new LongRange(from, to);
|
||||
}
|
||||
|
||||
public static LongRange rangeTo(long from, short to) {
|
||||
return new LongRange(from, to);
|
||||
}
|
||||
|
||||
public static LongRange rangeTo(long from, int to) {
|
||||
return new LongRange(from, to);
|
||||
}
|
||||
|
||||
public static LongRange rangeTo(long from, long to) {
|
||||
return new LongRange(from, to);
|
||||
}
|
||||
|
||||
public static FloatRange rangeTo(long from, float to) {
|
||||
return new FloatRange(from, to);
|
||||
}
|
||||
|
||||
public static DoubleRange rangeTo(long from, double to) {
|
||||
return new DoubleRange(from, to);
|
||||
}
|
||||
|
||||
public static LongRange rangeTo(long from, char to) {
|
||||
return new LongRange(from, to);
|
||||
}
|
||||
|
||||
public static FloatRange rangeTo(float from, byte to) {
|
||||
return new FloatRange(from, to);
|
||||
}
|
||||
|
||||
public static FloatRange rangeTo(float from, short to) {
|
||||
return new FloatRange(from, to);
|
||||
}
|
||||
|
||||
public static FloatRange rangeTo(float from, int to) {
|
||||
return new FloatRange(from, to);
|
||||
}
|
||||
|
||||
public static FloatRange rangeTo(float from, long to) {
|
||||
return new FloatRange(from, to);
|
||||
}
|
||||
|
||||
public static FloatRange rangeTo(float from, float to) {
|
||||
return new FloatRange(from, to);
|
||||
}
|
||||
|
||||
public static DoubleRange rangeTo(float from, double to) {
|
||||
return new DoubleRange(from, to);
|
||||
}
|
||||
|
||||
public static FloatRange rangeTo(float from, char to) {
|
||||
return new FloatRange(from, to);
|
||||
}
|
||||
|
||||
public static DoubleRange rangeTo(double from, byte to) {
|
||||
return new DoubleRange(from, to);
|
||||
}
|
||||
|
||||
public static DoubleRange rangeTo(double from, short to) {
|
||||
return new DoubleRange(from, to);
|
||||
}
|
||||
|
||||
public static DoubleRange rangeTo(double from, int to) {
|
||||
return new DoubleRange(from, to);
|
||||
}
|
||||
|
||||
public static DoubleRange rangeTo(double from, long to) {
|
||||
return new DoubleRange(from, to);
|
||||
}
|
||||
|
||||
public static DoubleRange rangeTo(double from, float to) {
|
||||
return new DoubleRange(from, to);
|
||||
}
|
||||
|
||||
public static DoubleRange rangeTo(double from, double to) {
|
||||
return new DoubleRange(from, to);
|
||||
}
|
||||
|
||||
public static DoubleRange rangeTo(double from, char to) {
|
||||
return new DoubleRange(from, to);
|
||||
}
|
||||
|
||||
public static CharRange rangeTo(char from, byte to) {
|
||||
return new CharRange(from, (char) to);
|
||||
}
|
||||
|
||||
public static ShortRange rangeTo(char from, short to) {
|
||||
return new ShortRange((short) from, to);
|
||||
}
|
||||
|
||||
public static IntRange rangeTo(char from, int to) {
|
||||
return new IntRange(from, to);
|
||||
}
|
||||
|
||||
public static LongRange rangeTo(char from, long to) {
|
||||
return new LongRange(from, to);
|
||||
}
|
||||
|
||||
public static FloatRange rangeTo(char from, float to) {
|
||||
return new FloatRange(from, to);
|
||||
}
|
||||
|
||||
public static DoubleRange rangeTo(char from, double to) {
|
||||
return new DoubleRange(from, to);
|
||||
}
|
||||
|
||||
public static CharRange rangeTo(char from, char to) {
|
||||
return new CharRange(from, to);
|
||||
}
|
||||
|
||||
public static IntRange arrayIndices(int length) {
|
||||
return new IntRange(0, length - 1);
|
||||
}
|
||||
|
||||
@@ -1,101 +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.generators.builtins;
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintStream;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class GenerateRangeIntrinsics {
|
||||
private static String castIfNecessary(String what, String thisType, String otherType) {
|
||||
if (thisType.equals("byte") && otherType.equals("char") || thisType.equals("char") && otherType.equals("short")) {
|
||||
return "(" + otherType + ") " + what;
|
||||
}
|
||||
return what;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException {
|
||||
PrintStream out = new PrintStream(new FileOutputStream("core/runtime.jvm/src/jet/runtime/Ranges.java"));
|
||||
try {
|
||||
String copyright = "injector-generator/copyright.txt";
|
||||
out.println(FileUtil.loadFile(new File(copyright)));
|
||||
|
||||
out.println("package jet.runtime;");
|
||||
out.println();
|
||||
|
||||
out.println("import jet.*;");
|
||||
out.println();
|
||||
|
||||
out.println("/* This file is generated by " + GenerateRangeIntrinsics.class.getName() + ". DO NOT EDIT! */");
|
||||
out.println("public class Ranges {");
|
||||
|
||||
List<String> strings = Arrays.asList("byte", "short", "int", "long", "float", "double", "char");
|
||||
for (String t1 : strings) {
|
||||
for (String t2 : strings) {
|
||||
String resType;
|
||||
if (t1.equals("double") || t2.equals("double")) {
|
||||
resType = "DoubleRange";
|
||||
}
|
||||
else if (t1.equals("float") || t2.equals("float")) {
|
||||
resType = "FloatRange";
|
||||
}
|
||||
else if (t1.equals("long") || t2.equals("long")) {
|
||||
resType = "LongRange";
|
||||
}
|
||||
else if (t1.equals("int") || t2.equals("int")) {
|
||||
resType = "IntRange";
|
||||
}
|
||||
else if (t1.equals("short") || t2.equals("short")) {
|
||||
resType = "ShortRange";
|
||||
}
|
||||
else if (t1.equals("char") || t2.equals("char")) {
|
||||
resType = "CharRange";
|
||||
}
|
||||
else {
|
||||
resType = "ByteRange";
|
||||
}
|
||||
|
||||
out.println(" public static " + resType + " rangeTo(" + t1 + " from, " + t2 + " to) {");
|
||||
out.println(" return new " + resType + "("
|
||||
+ castIfNecessary("from", t1, t2) + ", "
|
||||
+ castIfNecessary("to", t2, t1) + ");");
|
||||
out.println(" }");
|
||||
out.println();
|
||||
}
|
||||
}
|
||||
|
||||
out.println(" public static IntRange arrayIndices(int length) {");
|
||||
out.println(" return new IntRange(0, length - 1);");
|
||||
out.println(" }");
|
||||
out.println();
|
||||
|
||||
out.println(" private Ranges() {}");
|
||||
out.println("}");
|
||||
}
|
||||
finally {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
|
||||
private GenerateRangeIntrinsics() {
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user