|
| 1 | +fun eq1<X>(value: X): X { return value; } |
| 2 | +fun eq2<X>(value: X) { return value; } |
| 3 | +fun eq3<X>(value: X): X { var cp: [X] = [eq1(value)]; var ((([v: X]))) = cp; return v; } |
| 4 | +fun eq4<X>(value: X) { return eq1<X>(value); } |
| 5 | + |
| 6 | +@method_id(101) |
| 7 | +fun test101(x: int) { |
| 8 | + var (a, b, c) = (x, (x,x), [x,x]); |
| 9 | + return (eq1(a), eq1(b), eq1(c), eq2(a), eq2(b), eq2(c), eq3(a), eq4(b), eq3(createEmptyTuple())); |
| 10 | +} |
| 11 | + |
| 12 | +fun getTwo<X>(): X { return 2 as X; } |
| 13 | + |
| 14 | +fun takeInt(a: int) { return a; } |
| 15 | + |
| 16 | +@method_id(102) |
| 17 | +fun test102(): (int, int, int, [(int, int)]) { |
| 18 | + var a: int = getTwo(); |
| 19 | + var _: int = getTwo(); |
| 20 | + var b = getTwo() as int; |
| 21 | + var c: int = 1 ? getTwo() : getTwo(); |
| 22 | + var c redef = getTwo(); |
| 23 | + return (eq1<int>(a), eq2<int>(b), takeInt(getTwo()), [(getTwo(), getTwo())]); |
| 24 | +} |
| 25 | + |
| 26 | +@method_id(103) |
| 27 | +fun test103(first: int): (int, int, int) { |
| 28 | + var t = createEmptyTuple(); |
| 29 | + var cs = beginCell().storeInt(100, 32).endCell().beginParse(); |
| 30 | + t.tuplePush(first); |
| 31 | + t.tuplePush(2); |
| 32 | + t.tuplePush(cs); |
| 33 | + cs = t.tupleAt(2); |
| 34 | + cs = t.tupleAt(2) as slice; |
| 35 | + return (t.tupleAt(0), cs.loadInt(32), t.tupleAt<slice>(2).loadInt(32)); |
| 36 | +} |
| 37 | + |
| 38 | +fun manyEq<T1, T2, T3>(a: T1, b: T2, c: T3): [T1, T2, T3] { |
| 39 | + return [a, b, c]; |
| 40 | +} |
| 41 | + |
| 42 | +@method_id(104) |
| 43 | +fun test104(f: int) { |
| 44 | + return ( |
| 45 | + manyEq(1 ? 1 : 1, f ? 0 : null, !f ? getTwo() as int : null), |
| 46 | + manyEq((f ? null as int : eq2(2), beginCell().storeBool(true).endCell().beginParse().loadBool()), 0, eq4(f)) |
| 47 | + ); |
| 48 | +} |
| 49 | + |
| 50 | +fun calcSum<X>(x: X, y: X) { return x + y; } |
| 51 | + |
| 52 | +@method_id(105) |
| 53 | +fun test105() { |
| 54 | + if (0) { calcSum(((0)), null); } |
| 55 | + return (calcSum(1, 2)); |
| 56 | +} |
| 57 | + |
| 58 | +fun calcYPlus1<Y>(value: Y) { return value + 1; } |
| 59 | +fun calcLoad32(cs: slice) { return cs.loadInt(32); } |
| 60 | +fun calcTensorPlus1(tens: (int, int)) { var (f, s) = tens; return (f + 1, s + 1); } |
| 61 | +fun calcTensorMul2(tens: (int, int)) { var (f, s) = tens; return (f * 2, s * 2); } |
| 62 | +fun cellToSlice(c: cell) { return c.beginParse(); } |
| 63 | +fun abstractTransform<X, Y, R>(xToY: (X) -> Y, yToR: (((Y))) -> R, initialX: X): R { |
| 64 | + var y = xToY(initialX); |
| 65 | + return yToR(y); |
| 66 | +} |
| 67 | + |
| 68 | +@method_id(106) |
| 69 | +fun test106() { |
| 70 | + var c = beginCell().storeInt(106, 32).endCell(); |
| 71 | + return [ |
| 72 | + abstractTransform(cellToSlice, calcLoad32, c), |
| 73 | + abstractTransform(calcYPlus1<int>, calcYPlus1<int>, 0), |
| 74 | + abstractTransform(calcTensorPlus1, calcTensorMul2, (2, 2)) |
| 75 | + ]; |
| 76 | +} |
| 77 | + |
| 78 | +fun callTupleFirst<X, Y>(t: X): Y { return t.tupleFirst(); } |
| 79 | +fun callTuplePush<T, V>(mutate self: T, v1: V, v2: V): self { self.tuplePush(v1); tuplePush(mutate self, v2); return self; } |
| 80 | +fun getTupleLastInt(t: tuple) { return t.tupleLast<int>(); } |
| 81 | +fun getTupleSize(t: tuple) { return t.tupleSize(); } |
| 82 | +fun callAnyFn<TObj, TResult>(f: (TObj) -> TResult, arg: TObj) { return f(arg); } |
| 83 | +fun callAnyFn2<TCallback>(f: TCallback, arg: tuple) { return f(arg); } |
| 84 | + |
| 85 | +global t107: tuple; |
| 86 | + |
| 87 | +@method_id(107) |
| 88 | +fun test107() { |
| 89 | + t107 = createEmptyTuple(); |
| 90 | + callTuplePush(mutate t107, 1, 2); |
| 91 | + t107.callTuplePush(3, 4).callTuplePush(5, 6); |
| 92 | + var first: int = t107.callTupleFirst(); |
| 93 | + return ( |
| 94 | + callAnyFn<tuple, int>(getTupleSize, t107), |
| 95 | + callAnyFn2(getTupleSize, t107), |
| 96 | + first, |
| 97 | + callTupleFirst(t107) as int, |
| 98 | + callAnyFn(getTupleLastInt, t107), |
| 99 | + callAnyFn2(getTupleLastInt, t107) |
| 100 | + ); |
| 101 | +} |
| 102 | + |
| 103 | +global g108: int; |
| 104 | + |
| 105 | +fun inc108(by: int) { g108 += by; } |
| 106 | +fun getInc108() { return inc108; } |
| 107 | +fun returnResult<RetT>(f: () -> RetT): RetT { return f(); } |
| 108 | +fun applyAndReturn<ArgT, RetT>(f: () -> (ArgT) -> RetT, arg: ArgT): () -> ArgT -> RetT { |
| 109 | + f()(arg); |
| 110 | + return f; |
| 111 | +} |
| 112 | + |
| 113 | +@method_id(108) |
| 114 | +fun test108() { |
| 115 | + g108 = 0; |
| 116 | + getInc108()(1); |
| 117 | + returnResult<(int) -> void>(getInc108)(2); |
| 118 | + applyAndReturn<int, void>(getInc108, 10)()(10); |
| 119 | + returnResult(getInc108)(2); |
| 120 | + applyAndReturn(getInc108, 10)()(10); |
| 121 | + return g108; |
| 122 | +} |
| 123 | + |
| 124 | +fun main(x: int): (int, [[int, int]]) { |
| 125 | + try { if(x) { throw (1, x); } } |
| 126 | + catch (excNo, arg) { return (arg as int, [[eq2(arg as int), getTwo()]]); } |
| 127 | + return (0, [[x, 1]]); |
| 128 | +} |
| 129 | + |
| 130 | +/** |
| 131 | +@testcase | 0 | 1 | 1 [ [ 1 2 ] ] |
| 132 | +@testcase | 101 | 0 | 0 0 0 [ 0 0 ] 0 0 0 [ 0 0 ] 0 0 0 [] |
| 133 | +@testcase | 102 | | 2 2 2 [ 2 2 ] |
| 134 | +@testcase | 103 | 0 | 0 100 100 |
| 135 | +@testcase | 104 | 0 | [ 1 (null) 2 ] [ 2 -1 0 0 ] |
| 136 | +@testcase | 105 | | 3 |
| 137 | +@testcase | 106 | | [ 106 2 6 6 ] |
| 138 | +@testcase | 107 | | 6 6 1 1 6 6 |
| 139 | +@testcase | 108 | | 45 |
| 140 | + |
| 141 | +@fif_codegen DECLPROC eq1<int> |
| 142 | +@fif_codegen DECLPROC eq1<tuple> |
| 143 | +@fif_codegen DECLPROC eq1<(int,int)> |
| 144 | +@fif_codegen DECLPROC eq1<[int,int]> |
| 145 | +@fif_codegen DECLPROC getTwo<int> |
| 146 | + |
| 147 | +@fif_codegen_avoid DECLPROC eq1 |
| 148 | +@fif_codegen_avoid DECLPROC eq2 |
| 149 | +@fif_codegen_avoid DECLPROC eq3 |
| 150 | + */ |
0 commit comments