diff --git a/compiler/frontend/frontend.iml b/compiler/frontend/frontend.iml index 8d22f8caf8f..921ffcfc8f7 100644 --- a/compiler/frontend/frontend.iml +++ b/compiler/frontend/frontend.iml @@ -4,6 +4,7 @@ + diff --git a/compiler/frontend/generator/TuplesAndFunctionsGenerator.java b/compiler/frontend/generator/TuplesAndFunctionsGenerator.java new file mode 100644 index 00000000000..f450390b0e5 --- /dev/null +++ b/compiler/frontend/generator/TuplesAndFunctionsGenerator.java @@ -0,0 +1,103 @@ +/* + * Copyright 2000-2012 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintStream; + +/** + * @author abreslav + */ +public class TuplesAndFunctionsGenerator { + private static int TUPLE_COUNT = 23; + + private static void generateTuples(PrintStream out, int count) { + generated(out); + out.println("class Tuple0() {}"); + for (int i = 1; i < count; i++) { + out.print("class Tuple" + i); + out.print("<"); + for (int j = 1; j <= i; j++) { + out.print("out T" + j); + if (j < i) { + out.print(", "); + } + } + out.print(">"); + out.print("("); + for (int j = 1; j <= i; j++) { + out.print("_" + j + ": " + "T" + j); + if (j < i) { + out.print(", "); + } + } + out.print(") {}"); + out.println(); + } + } + + private static void generateFunctions(PrintStream out, int count, boolean extension) { + generated(out); + for (int i = 0; i < count; i++) { + out.print("trait Function" + i); + out.print("<"); + if (extension) { + out.print("in T"); + if (count > 0) { + out.print(", "); + } + } + for (int j = 1; j <= i; j++) { + out.print("in P" + j); + out.print(", "); + } + out.print("out R> {\n"); + out.print(" fun " + (extension ? "T." : "") + + "invoke("); + for (int j = 1; j <= i; j++) { + out.print("p" + j + ": " + "P" + j); + if (j < i) { + out.print(", "); + } + } + out.print(") : R\n"); + out.println("}"); + } + } + + private static void generated(PrintStream out) { + out.println("// Generated by " + TuplesAndFunctionsGenerator.class.getCanonicalName()); + out.println("// NOTE: this code is not loaded for JetStandardLibrary, but its equivalent is manually created in JetStandardClasses"); + out.println(); + } + + public static void main(String[] args) throws FileNotFoundException { + File baseDir = new File("compiler/frontend/src/jet/"); + assert baseDir.exists() : "Base dir does not exist: " + baseDir.getAbsolutePath(); + + PrintStream tuples = new PrintStream(new File(baseDir, "Tuples.jet.src")); + generateTuples(tuples, TUPLE_COUNT); + tuples.close(); + + PrintStream functions = new PrintStream(new File(baseDir, "Functions.jet.src")); + generateFunctions(functions, TUPLE_COUNT, false); + functions.close(); + + PrintStream extensionFunctions = new PrintStream(new File(baseDir, "ExtensionFunctions.jet.src")); + generateFunctions(extensionFunctions, TUPLE_COUNT, true); + extensionFunctions.close(); + } +} diff --git a/compiler/frontend/src/jet/ExtensionFunctions.jet.src b/compiler/frontend/src/jet/ExtensionFunctions.jet.src new file mode 100644 index 00000000000..a4c9768d097 --- /dev/null +++ b/compiler/frontend/src/jet/ExtensionFunctions.jet.src @@ -0,0 +1,72 @@ +// Generated by TuplesAndFunctionsGenerator +// NOTE: this code is not loaded for JetStandardLibrary, but its equivalent is manually created in JetStandardClasses + +trait Function0 { + fun T.invoke() : R +} +trait Function1 { + fun T.invoke(p1: P1) : R +} +trait Function2 { + fun T.invoke(p1: P1, p2: P2) : R +} +trait Function3 { + fun T.invoke(p1: P1, p2: P2, p3: P3) : R +} +trait Function4 { + fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4) : R +} +trait Function5 { + fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) : R +} +trait Function6 { + fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) : R +} +trait Function7 { + fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) : R +} +trait Function8 { + fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8) : R +} +trait Function9 { + fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9) : R +} +trait Function10 { + fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10) : R +} +trait Function11 { + fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11) : R +} +trait Function12 { + fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12) : R +} +trait Function13 { + fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13) : R +} +trait Function14 { + fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14) : R +} +trait Function15 { + fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15) : R +} +trait Function16 { + fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16) : R +} +trait Function17 { + fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17) : R +} +trait Function18 { + fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18) : R +} +trait Function19 { + fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19) : R +} +trait Function20 { + fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20) : R +} +trait Function21 { + fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21) : R +} +trait Function22 { + fun T.invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21, p22: P22) : R +} diff --git a/compiler/frontend/src/jet/Functions.jet.src b/compiler/frontend/src/jet/Functions.jet.src new file mode 100644 index 00000000000..857603314d5 --- /dev/null +++ b/compiler/frontend/src/jet/Functions.jet.src @@ -0,0 +1,72 @@ +// Generated by TuplesAndFunctionsGenerator +// NOTE: this code is not loaded for JetStandardLibrary, but its equivalent is manually created in JetStandardClasses + +trait Function0 { + fun invoke() : R +} +trait Function1 { + fun invoke(p1: P1) : R +} +trait Function2 { + fun invoke(p1: P1, p2: P2) : R +} +trait Function3 { + fun invoke(p1: P1, p2: P2, p3: P3) : R +} +trait Function4 { + fun invoke(p1: P1, p2: P2, p3: P3, p4: P4) : R +} +trait Function5 { + fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5) : R +} +trait Function6 { + fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6) : R +} +trait Function7 { + fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7) : R +} +trait Function8 { + fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8) : R +} +trait Function9 { + fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9) : R +} +trait Function10 { + fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10) : R +} +trait Function11 { + fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11) : R +} +trait Function12 { + fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12) : R +} +trait Function13 { + fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13) : R +} +trait Function14 { + fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14) : R +} +trait Function15 { + fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15) : R +} +trait Function16 { + fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16) : R +} +trait Function17 { + fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17) : R +} +trait Function18 { + fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18) : R +} +trait Function19 { + fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19) : R +} +trait Function20 { + fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20) : R +} +trait Function21 { + fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21) : R +} +trait Function22 { + fun invoke(p1: P1, p2: P2, p3: P3, p4: P4, p5: P5, p6: P6, p7: P7, p8: P8, p9: P9, p10: P10, p11: P11, p12: P12, p13: P13, p14: P14, p15: P15, p16: P16, p17: P17, p18: P18, p19: P19, p20: P20, p21: P21, p22: P22) : R +} diff --git a/compiler/frontend/src/jet/Tuples.jet.src b/compiler/frontend/src/jet/Tuples.jet.src new file mode 100644 index 00000000000..e122ecbdeea --- /dev/null +++ b/compiler/frontend/src/jet/Tuples.jet.src @@ -0,0 +1,26 @@ +// Generated by TuplesAndFunctionsGenerator +// NOTE: this code is not loaded for JetStandardLibrary, but its equivalent is manually created in JetStandardClasses + +class Tuple0() {} +class Tuple1(_1: T1) {} +class Tuple2(_1: T1, _2: T2) {} +class Tuple3(_1: T1, _2: T2, _3: T3) {} +class Tuple4(_1: T1, _2: T2, _3: T3, _4: T4) {} +class Tuple5(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5) {} +class Tuple6(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6) {} +class Tuple7(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7) {} +class Tuple8(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8) {} +class Tuple9(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9) {} +class Tuple10(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9, _10: T10) {} +class Tuple11(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9, _10: T10, _11: T11) {} +class Tuple12(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9, _10: T10, _11: T11, _12: T12) {} +class Tuple13(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9, _10: T10, _11: T11, _12: T12, _13: T13) {} +class Tuple14(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9, _10: T10, _11: T11, _12: T12, _13: T13, _14: T14) {} +class Tuple15(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9, _10: T10, _11: T11, _12: T12, _13: T13, _14: T14, _15: T15) {} +class Tuple16(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9, _10: T10, _11: T11, _12: T12, _13: T13, _14: T14, _15: T15, _16: T16) {} +class Tuple17(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9, _10: T10, _11: T11, _12: T12, _13: T13, _14: T14, _15: T15, _16: T16, _17: T17) {} +class Tuple18(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9, _10: T10, _11: T11, _12: T12, _13: T13, _14: T14, _15: T15, _16: T16, _17: T17, _18: T18) {} +class Tuple19(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9, _10: T10, _11: T11, _12: T12, _13: T13, _14: T14, _15: T15, _16: T16, _17: T17, _18: T18, _19: T19) {} +class Tuple20(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9, _10: T10, _11: T11, _12: T12, _13: T13, _14: T14, _15: T15, _16: T16, _17: T17, _18: T18, _19: T19, _20: T20) {} +class Tuple21(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9, _10: T10, _11: T11, _12: T12, _13: T13, _14: T14, _15: T15, _16: T16, _17: T17, _18: T18, _19: T19, _20: T20, _21: T21) {} +class Tuple22(_1: T1, _2: T2, _3: T3, _4: T4, _5: T5, _6: T6, _7: T7, _8: T8, _9: T9, _10: T10, _11: T11, _12: T12, _13: T13, _14: T14, _15: T15, _16: T16, _17: T17, _18: T18, _19: T19, _20: T20, _21: T21, _22: T22) {}