@@ -2,85 +2,112 @@ fun unsafe_tuple<X>(x: X): tuple
22 asm "NOP";
33
44fun inc(x: int, y: int): (int, int) {
5- return (x + y, y * 10);
5+ return (x + y, y * 10);
66}
77fun `~inc`(mutate self: int, y: int): int {
8- val (newX, newY) = inc(self, y);
9- self = newX;
10- return newY;
8+ val (newX, newY) = inc(self, y);
9+ self = newX;
10+ return newY;
1111}
1212
13+ fun eq<X>(v: X): X { return v; }
14+ fun eq2(v: (int, int)) { return v; }
15+ fun mul2(mutate dest: int, v: int): int { dest = v*2; return dest; }
16+ fun multens(mutate self: (int, int), v: (int, int)): (int, int) { var (f, s) = self; var (m1, m2) = v; self = (f*m1, s*m2); return self; }
17+
1318@method_id(11)
1419fun test_return(x: int): (int, int, int, int, int, int, int) {
15- return (x, x.`~inc`(x / 20), x, x = x * 2, x, x += 1, x);
20+ return (x, x.`~inc`(x / 20), x, x = x * 2, x, x += 1, x);
1621}
1722
1823@method_id(12)
1924fun test_assign(x: int): (int, int, int, int, int, int, int) {
20- var (x1: int, x2: int, x3: int, x4: int, x5: int, x6: int, x7: int) = (x, x.`~inc`(x / 20), x, x=x*2, x, x+=1, x);
21- return (x1, x2, x3, x4, x5, x6, x7);
25+ var (x1: int, x2: int, x3: int, x4: int, x5: int, x6: int, x7: int) = (x, x.`~inc`(x / 20), x, x=x*2, x, x+=1, x);
26+ return (x1, x2, x3, x4, x5, x6, x7);
2227}
2328
2429@method_id(13)
2530fun test_tuple(x: int): tuple {
26- var t: tuple = unsafe_tuple([x, x.`~inc`(x / 20), x, x = x * 2, x, x += 1, x]);
27- return t;
31+ var t: tuple = unsafe_tuple([x, x.`~inc`(x / 20), x, x = x * 2, x, x += 1, x]);
32+ return t;
2833}
2934
3035@method_id(14)
3136fun test_tuple_assign(x: int): (int, int, int, int, int, int, int) {
32- var [x1: int, x2: int, x3: int, x4: int, x5: int, x6: int, x7: int] = [x, x.`~inc`(x / 20), x, x = x * 2, x, x += 1, x];
33- return (x1, x2, x3, x4, x5, x6, x7);
37+ var [x1: int, x2: int, x3: int, x4: int, x5: int, x6: int, x7: int] = [x, x.`~inc`(x / 20), x, x = x * 2, x, x += 1, x];
38+ return (x1, x2, x3, x4, x5, x6, x7);
3439}
3540
3641fun foo1(x1: int, x2: int, x3: int, x4: int, x5: int, x6: int, x7: int): (int, int, int, int, int, int, int) {
37- return (x1, x2, x3, x4, x5, x6, x7);
42+ return (x1, x2, x3, x4, x5, x6, x7);
3843}
3944
4045@method_id(15)
4146fun test_call_1(x: int): (int, int, int, int, int, int, int) {
42- return foo1(x, x.`~inc`(x / 20), x, x = x * 2, x, x += 1, x);
47+ return foo1(x, x.`~inc`(x / 20), x, x = x * 2, x, x += 1, x);
4348}
4449
4550fun foo2(x1: int, x2: int, x3456: (int, int, int, int), x7: int): (int, int, int, int, int, int, int) {
46- var (x3: int, x4: int, x5: int, x6: int) = x3456;
47- return (x1, x2, x3, x4, x5, x6, x7);
51+ var (x3: int, x4: int, x5: int, x6: int) = x3456;
52+ return (x1, x2, x3, x4, x5, x6, x7);
4853}
4954
5055@method_id(16)
5156fun test_call_2(x: int): (int, int, int, int, int, int, int) {
52- return foo2(x, x.`~inc`(x / 20), (x, x = x * 2, x, x += 1), x);
57+ return foo2(x, x.`~inc`(x / 20), (x, x = x * 2, x, x += 1), x);
5358}
5459
5560fun asm_func(x1: int, x2: int, x3: int, x4: int, x5: int, x6: int, x7: int): (int, int, int, int, int, int, int)
56- asm
57- (x4 x5 x6 x7 x1 x2 x3->0 1 2 3 4 5 6) "NOP";
61+ asm (x4 x5 x6 x7 x1 x2 x3->0 1 2 3 4 5 6) "NOP";
5862
5963@method_id(17)
6064fun test_call_asm_old(x: int): (int, int, int, int, int, int, int) {
61- return asm_func(x, x += 1, x, x, x.`~inc`(x / 20), x, x = x * 2);
65+ return asm_func(x, x += 1, x, x, x.`~inc`(x / 20), x, x = x * 2);
6266}
6367
6468@method_id(18)
6569fun test_call_asm_new(x: int): (int, int, int, int, int, int, int) {
66- return asm_func(x, x.`~inc`(x / 20), x, x = x * 2, x, x += 1, x);
70+ return asm_func(x, x.`~inc`(x / 20), x, x = x * 2, x, x += 1, x);
6771}
6872
6973global xx: int;
7074@method_id(19)
71- fun test_global(x: int): (int, int, int, int, int, int, int) {
72- xx = x;
73- return (xx, xx.`~inc`(xx / 20), xx , xx = xx * 2, xx, xx += 1, xx);
75+ fun test_global(x: int) {
76+ xx = x;
77+ return (x, xx, xx.`~inc`(xx / 20), eq(xx += (x *= 0)) , xx = xx * 2, xx, xx += 1, xx, x );
7478}
7579
7680@method_id(20)
7781fun test_if_else(x: int): (int, int, int, int, int) {
78- if (x > 10) {
79- return (x.`~inc`(8), x + 1, x = 1, x <<= 3, x);
80- } else {
81- xx = 9;
82- return (x, x.`~inc`(-4), x.`~inc`(-1), x >= 1, x = x + xx);
83- }
82+ if (x > 10) {
83+ return (x.`~inc`(8), x + 1, x = 1, x <<= 3, x);
84+ } else {
85+ xx = 9;
86+ return (x, x.`~inc`(-4), x.`~inc`(-1), x >= 1, x = x + xx);
87+ }
88+ }
89+
90+ @method_id(21)
91+ fun test_assign_with_inner(x: int) {
92+ return (x, x += 10, [(x, x += 20, eq(x -= 50), x)], eq2((x, x *= eq(x /= 2))));
93+ }
94+
95+ @method_id(22)
96+ fun test_assign_with_mutate(x: int) {
97+ return (x, mul2(mutate x, x += 5), x.`~inc`(mul2(mutate x, x)), x);
98+ }
99+
100+ @method_id(23)
101+ fun test_assign_tensor(x: (int, int)) {
102+ var fs = (0, 0);
103+ return (x, x = (20, 30), fs = x.multens((1, 2)), fs.multens(multens(mutate x, (-1, -1))), x, fs);
104+ }
105+
106+ global fs: (int, int);
107+ @method_id(24)
108+ fun test_assign_tensor_global(x: (int, int)) {
109+ fs = (0, 0);
110+ return (x, x = (20, 30), fs = x.multens((1, 2)), fs.multens(multens(mutate x, (-1, -1))), x, fs);
84111}
85112
86113fun main() {
@@ -96,9 +123,13 @@ fun main() {
96123@testcase | 16 | 100 | 100 50 105 210 210 211 211
97124@testcase | 17 | 100 | 101 50 106 212 100 101 101
98125@testcase | 18 | 100 | 210 210 211 211 100 50 105
99- @testcase | 19 | 100 | 100 50 105 210 210 211 211
126+ @testcase | 19 | 100 | 100 100 50 105 210 210 211 211 0
100127@testcase | 20 | 80 | 80 89 1 8 8
101128@testcase | 20 | 9 | 9 -40 -10 -1 13
129+ @testcase | 21 | 100 | 100 110 [ 110 130 80 80 ] 80 3200
130+ @testcase | 22 | 100 | 100 210 4200 630
131+ @testcase | 23 | 1 1 | 1 1 20 30 20 60 -400 -3600 -20 -60 -400 -3600
132+ @testcase | 24 | 1 1 | 1 1 20 30 20 60 -400 -3600 -20 -60 -400 -3600
102133
103134@fif_codegen
104135"""
@@ -107,5 +138,5 @@ fun main() {
107138 inc CALLDICT // self newY
108139 }>
109140"""
110- @code_hash 97139400653362069936987769894397430077752335662822462908581556703209313861576
141+ @code_hash 33262590582878205026101577472505372101182291690814957175155528952950621243206
111142*/
0 commit comments