|
6 | 6 | :interpIR
|
7 | 7 | class True
|
8 | 8 | class False
|
9 |
| -fun f(n) = g(n) |
10 |
| -fun g(m) = f(m) |
11 |
| -fun h() = h() |
12 |
| -2 |
13 |
| -//│ |#class| |True|↵|#class| |False|↵|#fun| |f|(|n|)| |#=| |g|(|n|)|↵|#fun| |g|(|m|)| |#=| |f|(|m|)|↵|#fun| |h|(||)| |#=| |h|(||)|↵|2| |
14 |
| -//│ Parsed: {class True {}; class False {}; fun f = (n,) => g(n,); fun g = (m,) => f(m,); fun h = () => h(); 2} |
| 9 | +fun f(n) = if n == 0 then 0 else g(n - 1) |
| 10 | +fun g(m) = if m == 0 then 1 else f(m - 1) |
| 11 | +f(4) |
| 12 | +//│ |#class| |True|↵|#class| |False|↵|#fun| |f|(|n|)| |#=| |#if| |n| |==| |0| |#then| |0| |#else| |g|(|n| |-| |1|)|↵|#fun| |g|(|m|)| |#=| |#if| |m| |==| |0| |#then| |1| |#else| |f|(|m| |-| |1|)|↵|f|(|4|)| |
| 13 | +//│ Parsed: {class True {}; class False {}; fun f = (n,) => if (==(n,)(0,)) then 0 else g(-(n,)(1,),); fun g = (m,) => if (==(m,)(0,)) then 1 else f(-(m,)(1,),); f(4,)} |
15 | 14 | //│
|
16 | 15 | //│
|
17 | 16 | //│ IR:
|
18 | 17 | //│ Program({ClassInfo(0, True, []),ClassInfo(1, False, [])}, {
|
19 | 18 | //│ Def(0, f, [n$0],
|
20 | 19 | //│ 1,
|
21 |
| -//│ let* (x$0) = g(n$0) in -- #5 |
22 |
| -//│ x$0 -- #4 |
| 20 | +//│ let x$0 = ==(n$0,0) in -- #17 |
| 21 | +//│ if x$0 -- #16 |
| 22 | +//│ true => |
| 23 | +//│ jump j$0(0) -- #5 |
| 24 | +//│ false => |
| 25 | +//│ let x$2 = -(n$0,1) in -- #15 |
| 26 | +//│ let* (x$3) = g(x$2) in -- #14 |
| 27 | +//│ jump j$0(x$3) -- #13 |
| 28 | +//│ ) |
| 29 | +//│ Def(1, j$0, [x$1], |
| 30 | +//│ 1, |
| 31 | +//│ x$1 -- #3 |
23 | 32 | //│ )
|
24 |
| -//│ Def(1, g, [m$0], |
| 33 | +//│ Def(2, g, [m$0], |
25 | 34 | //│ 1,
|
26 |
| -//│ let* (x$1) = f(m$0) in -- #11 |
27 |
| -//│ x$1 -- #10 |
| 35 | +//│ let x$4 = ==(m$0,0) in -- #35 |
| 36 | +//│ if x$4 -- #34 |
| 37 | +//│ true => |
| 38 | +//│ jump j$1(1) -- #23 |
| 39 | +//│ false => |
| 40 | +//│ let x$6 = -(m$0,1) in -- #33 |
| 41 | +//│ let* (x$7) = f(x$6) in -- #32 |
| 42 | +//│ jump j$1(x$7) -- #31 |
28 | 43 | //│ )
|
29 |
| -//│ Def(2, h, [], |
| 44 | +//│ Def(3, j$1, [x$5], |
30 | 45 | //│ 1,
|
31 |
| -//│ let* (x$2) = h() in -- #15 |
32 |
| -//│ x$2 -- #14 |
| 46 | +//│ x$5 -- #21 |
33 | 47 | //│ )
|
34 | 48 | //│ },
|
35 |
| -//│ 2 -- #16) |
| 49 | +//│ let* (x$8) = f(4) in -- #41 |
| 50 | +//│ x$8 -- #40) |
36 | 51 | //│ Program({ClassInfo(0, True, []),ClassInfo(1, False, [])}, {
|
37 | 52 | //│ Def(0, f, [n$0],
|
38 | 53 | //│ 1,
|
39 |
| -//│ let* (x$0) = g(n$0) in -- #5 |
40 |
| -//│ x$0 -- #4 |
| 54 | +//│ let x$0 = ==(n$0,0) in -- #17 |
| 55 | +//│ if x$0 -- #16 |
| 56 | +//│ true => |
| 57 | +//│ jump j$0(0) -- #5 |
| 58 | +//│ false => |
| 59 | +//│ let x$2 = -(n$0,1) in -- #15 |
| 60 | +//│ let* (x$3) = g(x$2) in -- #14 |
| 61 | +//│ jump j$0(x$3) -- #13 |
| 62 | +//│ ) |
| 63 | +//│ Def(1, j$0, [x$1], |
| 64 | +//│ 1, |
| 65 | +//│ x$1 -- #3 |
41 | 66 | //│ )
|
42 |
| -//│ Def(1, g, [m$0], |
| 67 | +//│ Def(2, g, [m$0], |
43 | 68 | //│ 1,
|
44 |
| -//│ let* (x$1) = f(m$0) in -- #11 |
45 |
| -//│ x$1 -- #10 |
| 69 | +//│ let x$4 = ==(m$0,0) in -- #35 |
| 70 | +//│ if x$4 -- #34 |
| 71 | +//│ true => |
| 72 | +//│ jump j$1(1) -- #23 |
| 73 | +//│ false => |
| 74 | +//│ let x$6 = -(m$0,1) in -- #33 |
| 75 | +//│ let* (x$7) = f(x$6) in -- #32 |
| 76 | +//│ jump j$1(x$7) -- #31 |
46 | 77 | //│ )
|
47 |
| -//│ Def(2, h, [], |
| 78 | +//│ Def(3, j$1, [x$5], |
48 | 79 | //│ 1,
|
49 |
| -//│ let* (x$2) = h() in -- #15 |
50 |
| -//│ x$2 -- #14 |
| 80 | +//│ x$5 -- #21 |
51 | 81 | //│ )
|
52 | 82 | //│ },
|
53 |
| -//│ 2 -- #16) |
| 83 | +//│ let* (x$8) = f(4) in -- #41 |
| 84 | +//│ x$8 -- #40) |
54 | 85 | //│
|
55 | 86 | //│ Promoted:
|
56 | 87 | //│ Program({ClassInfo(0, True, []),ClassInfo(1, False, [])}, {
|
57 | 88 | //│ Def(0, f, [n$0],
|
58 | 89 | //│ 1,
|
59 |
| -//│ let* (x$0) = g(n$0) in -- #5 |
60 |
| -//│ x$0 -- #4 |
| 90 | +//│ let x$0 = ==(n$0,0) in -- #17 |
| 91 | +//│ if x$0 -- #16 |
| 92 | +//│ true => |
| 93 | +//│ jump j$0(0) -- #5 |
| 94 | +//│ false => |
| 95 | +//│ let x$2 = -(n$0,1) in -- #15 |
| 96 | +//│ let* (x$3) = g(x$2) in -- #14 |
| 97 | +//│ jump j$0(x$3) -- #13 |
| 98 | +//│ ) |
| 99 | +//│ Def(1, j$0, [x$1], |
| 100 | +//│ 1, |
| 101 | +//│ x$1 -- #3 |
61 | 102 | //│ )
|
62 |
| -//│ Def(1, g, [m$0], |
| 103 | +//│ Def(2, g, [m$0], |
63 | 104 | //│ 1,
|
64 |
| -//│ let* (x$1) = f(m$0) in -- #11 |
65 |
| -//│ x$1 -- #10 |
| 105 | +//│ let x$4 = ==(m$0,0) in -- #35 |
| 106 | +//│ if x$4 -- #34 |
| 107 | +//│ true => |
| 108 | +//│ jump j$1(1) -- #23 |
| 109 | +//│ false => |
| 110 | +//│ let x$6 = -(m$0,1) in -- #33 |
| 111 | +//│ let* (x$7) = f(x$6) in -- #32 |
| 112 | +//│ jump j$1(x$7) -- #31 |
66 | 113 | //│ )
|
67 |
| -//│ Def(2, h, [], |
| 114 | +//│ Def(3, j$1, [x$5], |
68 | 115 | //│ 1,
|
69 |
| -//│ let* (x$2) = h() in -- #15 |
70 |
| -//│ x$2 -- #14 |
| 116 | +//│ x$5 -- #21 |
71 | 117 | //│ )
|
72 | 118 | //│ },
|
73 |
| -//│ 2 -- #16) |
| 119 | +//│ let* (x$8) = f(4) in -- #41 |
| 120 | +//│ x$8 -- #40) |
74 | 121 | //│
|
75 | 122 | //│ Interpreted:
|
76 |
| -//│ 2 |
| 123 | +//│ 0 |
77 | 124 |
|
78 |
| -// remark: this really should be changed so we don't need to add `class True` every time we want to use conditionals |
79 | 125 | :interpIR
|
80 | 126 | class True
|
81 | 127 | class False
|
82 |
| -fun f(n) = g(n) |
83 |
| -fun g(m) = f(m) |
84 |
| -fun h() = h() |
85 |
| -2 |
86 |
| -//│ |#class| |True|↵|#class| |False|↵|#fun| |f|(|n|)| |#=| |g|(|n|)|↵|#fun| |g|(|m|)| |#=| |f|(|m|)|↵|#fun| |h|(||)| |#=| |h|(||)|↵|2| |
87 |
| -//│ Parsed: {class True {}; class False {}; fun f = (n,) => g(n,); fun g = (m,) => f(m,); fun h = () => h(); 2} |
| 128 | +fun f(n) = if n == 0 then 0 else g(n - 1) |
| 129 | +fun g(m) = if m == 0 then 1 else f(m - 1) |
| 130 | +f(4) |
| 131 | +//│ |#class| |True|↵|#class| |False|↵|#fun| |f|(|n|)| |#=| |#if| |n| |==| |0| |#then| |0| |#else| |g|(|n| |-| |1|)|↵|#fun| |g|(|m|)| |#=| |#if| |m| |==| |0| |#then| |1| |#else| |f|(|m| |-| |1|)|↵|f|(|4|)| |
| 132 | +//│ Parsed: {class True {}; class False {}; fun f = (n,) => if (==(n,)(0,)) then 0 else g(-(n,)(1,),); fun g = (m,) => if (==(m,)(0,)) then 1 else f(-(m,)(1,),); f(4,)} |
88 | 133 | //│
|
89 | 134 | //│
|
90 | 135 | //│ IR:
|
91 | 136 | //│ Program({ClassInfo(0, True, []),ClassInfo(1, False, [])}, {
|
92 | 137 | //│ Def(0, f, [n$0],
|
93 | 138 | //│ 1,
|
94 |
| -//│ let* (x$0) = g(n$0) in -- #5 |
95 |
| -//│ x$0 -- #4 |
| 139 | +//│ let x$0 = ==(n$0,0) in -- #17 |
| 140 | +//│ if x$0 -- #16 |
| 141 | +//│ true => |
| 142 | +//│ jump j$0(0) -- #5 |
| 143 | +//│ false => |
| 144 | +//│ let x$2 = -(n$0,1) in -- #15 |
| 145 | +//│ let* (x$3) = g(x$2) in -- #14 |
| 146 | +//│ jump j$0(x$3) -- #13 |
| 147 | +//│ ) |
| 148 | +//│ Def(1, j$0, [x$1], |
| 149 | +//│ 1, |
| 150 | +//│ x$1 -- #3 |
96 | 151 | //│ )
|
97 |
| -//│ Def(1, g, [m$0], |
| 152 | +//│ Def(2, g, [m$0], |
98 | 153 | //│ 1,
|
99 |
| -//│ let* (x$1) = f(m$0) in -- #11 |
100 |
| -//│ x$1 -- #10 |
| 154 | +//│ let x$4 = ==(m$0,0) in -- #35 |
| 155 | +//│ if x$4 -- #34 |
| 156 | +//│ true => |
| 157 | +//│ jump j$1(1) -- #23 |
| 158 | +//│ false => |
| 159 | +//│ let x$6 = -(m$0,1) in -- #33 |
| 160 | +//│ let* (x$7) = f(x$6) in -- #32 |
| 161 | +//│ jump j$1(x$7) -- #31 |
101 | 162 | //│ )
|
102 |
| -//│ Def(2, h, [], |
| 163 | +//│ Def(3, j$1, [x$5], |
103 | 164 | //│ 1,
|
104 |
| -//│ let* (x$2) = h() in -- #15 |
105 |
| -//│ x$2 -- #14 |
| 165 | +//│ x$5 -- #21 |
106 | 166 | //│ )
|
107 | 167 | //│ },
|
108 |
| -//│ 2 -- #16) |
| 168 | +//│ let* (x$8) = f(4) in -- #41 |
| 169 | +//│ x$8 -- #40) |
109 | 170 | //│
|
110 | 171 | //│ Strongly Connected Tail Calls:
|
111 |
| -//│ List(Set(h), Set(g, f)) |
| 172 | +//│ List(Set(g), Set(j$1), Set(f), Set(j$0)) |
112 | 173 | //│ Program({ClassInfo(0, True, []),ClassInfo(1, False, [])}, {
|
113 | 174 | //│ Def(0, f, [n$0],
|
114 | 175 | //│ 1,
|
115 |
| -//│ let* (r0) = _g_f_opt(0,n$0,0) in -- #26 |
116 |
| -//│ r0 -- #25 |
117 |
| -//│ ) |
118 |
| -//│ Def(1, g, [m$0], |
119 |
| -//│ 1, |
120 |
| -//│ let* (r0) = _g_f_opt(1,0,m$0) in -- #24 |
121 |
| -//│ r0 -- #23 |
| 176 | +//│ let x$0 = ==(n$0,0) in -- #17 |
| 177 | +//│ if x$0 -- #16 |
| 178 | +//│ true => |
| 179 | +//│ jump j$0(0) -- #5 |
| 180 | +//│ false => |
| 181 | +//│ let x$2 = -(n$0,1) in -- #15 |
| 182 | +//│ let* (x$3) = g(x$2) in -- #14 |
| 183 | +//│ jump j$0(x$3) -- #13 |
122 | 184 | //│ )
|
123 |
| -//│ Def(2, h, [], |
| 185 | +//│ Def(1, j$0, [x$1], |
124 | 186 | //│ 1,
|
125 |
| -//│ let* (x$2) = h() in -- #15 |
126 |
| -//│ x$2 -- #14 |
| 187 | +//│ x$1 -- #3 |
127 | 188 | //│ )
|
128 |
| -//│ Def(3, _g_f_opt_jp, [tailrecBranch,g_m$0,f_n$0], |
| 189 | +//│ Def(2, g, [m$0], |
129 | 190 | //│ 1,
|
130 |
| -//│ let scrut = ==(0,tailrecBranch) in -- #21 |
131 |
| -//│ if scrut -- #19 |
| 191 | +//│ let x$4 = ==(m$0,0) in -- #35 |
| 192 | +//│ if x$4 -- #34 |
132 | 193 | //│ true =>
|
133 |
| -//│ jump _g_f_opt_jp(0,f_n$0,f_n$0) -- #18 |
| 194 | +//│ jump j$1(1) -- #23 |
134 | 195 | //│ false =>
|
135 |
| -//│ jump _g_f_opt_jp(1,g_m$0,g_m$0) -- #17 |
| 196 | +//│ let x$6 = -(m$0,1) in -- #33 |
| 197 | +//│ let* (x$7) = f(x$6) in -- #32 |
| 198 | +//│ jump j$1(x$7) -- #31 |
136 | 199 | //│ )
|
137 |
| -//│ Def(4, _g_f_opt, [tailrecBranch,g_m$0,f_n$0], |
| 200 | +//│ Def(3, j$1, [x$5], |
138 | 201 | //│ 1,
|
139 |
| -//│ jump _g_f_opt_jp(tailrecBranch,g_m$0,f_n$0) -- #22 |
| 202 | +//│ x$5 -- #21 |
140 | 203 | //│ )
|
141 | 204 | //│ },
|
142 |
| -//│ 2 -- #16) |
| 205 | +//│ let* (x$8) = f(4) in -- #41 |
| 206 | +//│ x$8 -- #40) |
143 | 207 | //│
|
144 | 208 | //│ Promoted:
|
145 | 209 | //│ Program({ClassInfo(0, True, []),ClassInfo(1, False, [])}, {
|
146 | 210 | //│ Def(0, f, [n$0],
|
147 | 211 | //│ 1,
|
148 |
| -//│ let* (r0) = _g_f_opt(0,n$0,0) in -- #26 |
149 |
| -//│ r0 -- #25 |
150 |
| -//│ ) |
151 |
| -//│ Def(1, g, [m$0], |
152 |
| -//│ 1, |
153 |
| -//│ let* (r0) = _g_f_opt(1,0,m$0) in -- #24 |
154 |
| -//│ r0 -- #23 |
| 212 | +//│ let x$0 = ==(n$0,0) in -- #17 |
| 213 | +//│ if x$0 -- #16 |
| 214 | +//│ true => |
| 215 | +//│ jump j$0(0) -- #5 |
| 216 | +//│ false => |
| 217 | +//│ let x$2 = -(n$0,1) in -- #15 |
| 218 | +//│ let* (x$3) = g(x$2) in -- #14 |
| 219 | +//│ jump j$0(x$3) -- #13 |
155 | 220 | //│ )
|
156 |
| -//│ Def(2, h, [], |
| 221 | +//│ Def(1, j$0, [x$1], |
157 | 222 | //│ 1,
|
158 |
| -//│ let* (x$2) = h() in -- #15 |
159 |
| -//│ x$2 -- #14 |
| 223 | +//│ x$1 -- #3 |
160 | 224 | //│ )
|
161 |
| -//│ Def(3, _g_f_opt_jp, [tailrecBranch,g_m$0,f_n$0], |
| 225 | +//│ Def(2, g, [m$0], |
162 | 226 | //│ 1,
|
163 |
| -//│ let scrut = ==(0,tailrecBranch) in -- #21 |
164 |
| -//│ if scrut -- #19 |
| 227 | +//│ let x$4 = ==(m$0,0) in -- #35 |
| 228 | +//│ if x$4 -- #34 |
165 | 229 | //│ true =>
|
166 |
| -//│ jump _g_f_opt_jp(0,f_n$0,f_n$0) -- #18 |
| 230 | +//│ jump j$1(1) -- #23 |
167 | 231 | //│ false =>
|
168 |
| -//│ jump _g_f_opt_jp(1,g_m$0,g_m$0) -- #17 |
| 232 | +//│ let x$6 = -(m$0,1) in -- #33 |
| 233 | +//│ let* (x$7) = f(x$6) in -- #32 |
| 234 | +//│ jump j$1(x$7) -- #31 |
169 | 235 | //│ )
|
170 |
| -//│ Def(4, _g_f_opt, [tailrecBranch,g_m$0,f_n$0], |
| 236 | +//│ Def(3, j$1, [x$5], |
171 | 237 | //│ 1,
|
172 |
| -//│ jump _g_f_opt_jp(tailrecBranch,g_m$0,f_n$0) -- #22 |
| 238 | +//│ x$5 -- #21 |
173 | 239 | //│ )
|
174 | 240 | //│ },
|
175 |
| -//│ 2 -- #16) |
| 241 | +//│ let* (x$8) = f(4) in -- #41 |
| 242 | +//│ x$8 -- #40) |
176 | 243 | //│
|
177 | 244 | //│ Interpreted:
|
178 |
| -//│ 2 |
| 245 | +//│ 0 |
0 commit comments