|
| 1 | +integral_types = [ |
| 2 | + "int(8)", "int(16)", "int(32)", "int(64)", |
| 3 | + "uint(8)", "uint(16)", "uint(32)", "uint(64)" |
| 4 | +] |
| 5 | + |
| 6 | +boolean_values = [True, False] |
| 7 | + |
| 8 | +output_file = "integralTests.chpl" |
| 9 | + |
| 10 | +with open(output_file, "w") as f: |
| 11 | + for bool_val in boolean_values: |
| 12 | + str_bool = str(bool_val).lower() |
| 13 | + for type1 in integral_types: |
| 14 | + for type2 in integral_types: |
| 15 | + f.write("{\n") |
| 16 | + f.write(f" proc testProcCastZero(arg: bool) {{\n") |
| 17 | + f.write(f" if arg then return 0:{type1}; else return 0:{type2};\n") |
| 18 | + f.write(" }\n") |
| 19 | + f.write(f" var x = testProcCastZero({str_bool});\n") |
| 20 | + f.write(f" writeln(\"testProcCastZero: when {str_bool} {type1} {type2} then \", x.type:string);\n") |
| 21 | + f.write("}\n\n") |
| 22 | + |
| 23 | + f.write("{\n") |
| 24 | + f.write(f" proc testProcZero(arg: bool) {{\n") |
| 25 | + f.write(f" var i: {type1} = 0;\n") |
| 26 | + f.write(f" var u: {type2} = 0;\n") |
| 27 | + f.write(f" if arg then return i; else return u;\n") |
| 28 | + f.write(" }\n") |
| 29 | + f.write(f" var x = testProcZero({str_bool});\n") |
| 30 | + f.write(f" writeln(\"testProcZero: when {str_bool} {type1} {type2} then \", x.type:string);\n") |
| 31 | + f.write("}\n\n") |
| 32 | + |
| 33 | + f.write("{\n") |
| 34 | + f.write(f" proc testProcCastMax(arg: bool) {{\n") |
| 35 | + f.write(f" if arg then return max({type1}):{type1}; else return max({type2}):{type2};\n") |
| 36 | + f.write(" }\n") |
| 37 | + f.write(f" var x = testProcCastMax({str_bool});\n") |
| 38 | + f.write(f" writeln(\"testProcCastMax: when {str_bool} {type1} {type2} then \", x.type:string);\n") |
| 39 | + f.write("}\n\n") |
| 40 | + |
| 41 | + f.write("{\n") |
| 42 | + f.write(f" proc testProcMax(arg: bool) {{\n") |
| 43 | + f.write(f" var i: {type1} = max({type1});\n") |
| 44 | + f.write(f" var u: {type2} = max({type2});\n") |
| 45 | + f.write(f" if arg then return i; else return u;\n") |
| 46 | + f.write(" }\n") |
| 47 | + f.write(f" var x = testProcMax({str_bool});\n") |
| 48 | + f.write(f" writeln(\"testProcMax: when {str_bool} {type1} {type2} then \", x.type:string);\n") |
| 49 | + f.write("}\n\n") |
| 50 | + |
| 51 | + f.write("{\n") |
| 52 | + f.write(f" proc testParamProcCastZero(param arg: bool) param {{\n") |
| 53 | + f.write(f" if arg then return 0:{type1}; else return 0:{type2};\n") |
| 54 | + f.write(" }\n") |
| 55 | + f.write(f" param x = testParamProcCastZero({str_bool});\n") |
| 56 | + f.write(f" writeln(\"testParamProcCastZero: when {str_bool} {type1} {type2} then \", x.type:string);\n") |
| 57 | + f.write("}\n\n") |
| 58 | + |
| 59 | + f.write("{\n") |
| 60 | + f.write(f" proc testParamProcZero(param arg: bool) param {{\n") |
| 61 | + f.write(f" param i: {type1} = 0;\n") |
| 62 | + f.write(f" param u: {type2} = 0;\n") |
| 63 | + f.write(f" if arg then return i; else return u;\n") |
| 64 | + f.write(" }\n") |
| 65 | + f.write(f" param x = testParamProcZero({str_bool});\n") |
| 66 | + f.write(f" writeln(\"testParamProcZero: when {str_bool} {type1} {type2} then \", x.type:string);\n") |
| 67 | + f.write("}\n\n") |
| 68 | + |
| 69 | + f.write("{\n") |
| 70 | + f.write(f" proc testParamProcCastMax(param arg: bool) param {{\n") |
| 71 | + f.write(f" if arg then return max({type1}):{type1}; else return max({type2}):{type2};\n") |
| 72 | + f.write(" }\n") |
| 73 | + f.write(f" param x = testParamProcCastMax({str_bool});\n") |
| 74 | + f.write(f" writeln(\"testParamProcCastMax: when {str_bool} {type1} {type2} then \", x.type:string);\n") |
| 75 | + f.write("}\n\n") |
| 76 | + |
| 77 | + f.write("{\n") |
| 78 | + f.write(f" proc testParamProcMax(param arg: bool) param {{\n") |
| 79 | + f.write(f" param i: {type1} = max({type1});\n") |
| 80 | + f.write(f" param u: {type2} = max({type2});\n") |
| 81 | + f.write(f" if arg then return i; else return u;\n") |
| 82 | + f.write(" }\n") |
| 83 | + f.write(f" param x = testParamProcMax({str_bool});\n") |
| 84 | + f.write(f" writeln(\"testParamProcMax: when {str_bool} {type1} {type2} then \", x.type:string);\n") |
| 85 | + f.write("}\n\n") |
| 86 | + |
| 87 | + f.write("{\n") |
| 88 | + f.write(f" var b: bool = {str_bool};\n") |
| 89 | + f.write(f" var x = if b then 0:{type1} else 0:{type2};\n") |
| 90 | + f.write(f" writeln(\"testExpressionZero: when {str_bool} {type1} {type2} then \", x.type:string);\n") |
| 91 | + f.write("}\n\n") |
| 92 | + |
| 93 | + f.write("{\n") |
| 94 | + f.write(f" var b: bool = {str_bool};\n") |
| 95 | + f.write(f" var x = if b then max({type1}):{type1} else max({type2}):{type2};\n") |
| 96 | + f.write(f" writeln(\"testExpressionMax: when {str_bool} {type1} {type2} then \", x.type:string);\n") |
| 97 | + f.write("}\n\n") |
| 98 | + |
| 99 | + f.write("{\n") |
| 100 | + f.write(f" param x = if {str_bool} then 0:{type1} else 0:{type2};\n") |
| 101 | + f.write(f" writeln(\"testParamExpressionZero: when {str_bool} {type1} {type2} then \", x.type:string);\n") |
| 102 | + f.write("}\n\n") |
| 103 | + |
| 104 | + f.write("{\n") |
| 105 | + f.write(f" param x = if {str_bool} then max({type1}):{type1} else max({type2}):{type2};\n") |
| 106 | + f.write(f" writeln(\"testParamExpressionMax: when {str_bool} {type1} {type2} then \", x.type:string);\n") |
| 107 | + f.write("}\n\n") |
0 commit comments