@@ -48,20 +48,20 @@ pub struct Prog(pub Box<[Fundef]>, pub Closure);
48
48
impl Closure {
49
49
fn fmt2 ( & self , f : & mut fmt:: Formatter , level : usize ) -> fmt:: Result {
50
50
use self :: Closure :: * ;
51
- match * self {
51
+ match self {
52
52
Unit => write ! ( f, "()" ) ,
53
53
Int ( v) => write ! ( f, "{}" , v) ,
54
54
Float ( fv) => write ! ( f, "{}" , fv) ,
55
- Neg ( ref x) => write ! ( f, "-{}" , x) ,
56
- IntBin ( op, ref x , ref y) => {
55
+ Neg ( x) => write ! ( f, "-{}" , x) ,
56
+ IntBin ( op, x , y) => {
57
57
let op_str = match op {
58
58
self :: IntBin :: Add => "+" ,
59
59
self :: IntBin :: Sub => "-" ,
60
60
} ;
61
61
write ! ( f, "{} {} {}" , x, op_str, y)
62
62
} ,
63
- FNeg ( ref x) => write ! ( f, "-.{}" , x) ,
64
- FloatBin ( op, ref x , ref y) => {
63
+ FNeg ( x) => write ! ( f, "-.{}" , x) ,
64
+ FloatBin ( op, x , y) => {
65
65
let op_str = match op {
66
66
self :: FloatBin :: FAdd => "+." ,
67
67
self :: FloatBin :: FSub => "-." ,
@@ -70,7 +70,7 @@ impl Closure {
70
70
} ;
71
71
write ! ( f, "{} {} {}" , x, op_str, y)
72
72
} ,
73
- IfComp ( op, ref x, ref y, ref e1, ref e2) => {
73
+ IfComp ( op, x, y, e1, e2) => {
74
74
let op_str = match op {
75
75
self :: CompBin :: Eq => "=" ,
76
76
self :: CompBin :: LE => "<=" ,
@@ -90,7 +90,7 @@ impl Closure {
90
90
}
91
91
e2. fmt2 ( f, level + 2 )
92
92
} ,
93
- Let ( ( ref x, ref t) , ref e1, ref e2) => {
93
+ Let ( ( x, t) , e1, e2) => {
94
94
if let Type :: Unit = * t {
95
95
if x. len ( ) >= 6 && & x[ 0 ..6 ] == "_dummy" {
96
96
// this let expression is actually "e1; e2"
@@ -110,31 +110,31 @@ impl Closure {
110
110
}
111
111
e2. fmt2 ( f, level)
112
112
} ,
113
- Var ( ref x) => write ! ( f, "{}" , x) ,
114
- MakeCls ( ref x, ref t, ref cls, ref e) => {
113
+ Var ( x) => write ! ( f, "{}" , x) ,
114
+ MakeCls ( x, t, cls, e) => {
115
115
write ! ( f, "MakeCls {}: {} (" , x, t) ?;
116
- let Cls { entry : id:: L ( ref l) , actual_fv : ref fv } = * cls;
116
+ let Cls { entry : id:: L ( l) , actual_fv : fv } = cls;
117
117
write ! ( f, "{} {:?}) in\n " , l, fv) ?;
118
118
for _ in 0 .. level {
119
119
write ! ( f, " " ) ?;
120
120
}
121
121
e. fmt2 ( f, level)
122
122
} ,
123
- AppDir ( id:: L ( ref func) , ref args) => {
123
+ AppDir ( id:: L ( func) , args) => {
124
124
write ! ( f, "{}" , func) ?;
125
125
for v in args. iter ( ) {
126
126
write ! ( f, " {}" , v) ?;
127
127
}
128
128
Ok ( ( ) )
129
129
} ,
130
- AppCls ( ref func, ref args) => {
130
+ AppCls ( func, args) => {
131
131
write ! ( f, "[{}]" , func) ?;
132
132
for v in args. iter ( ) {
133
133
write ! ( f, " {}" , v) ?;
134
134
}
135
135
Ok ( ( ) )
136
136
} ,
137
- Tuple ( ref elems) => {
137
+ Tuple ( elems) => {
138
138
write ! ( f, "(" ) ?;
139
139
for i in 0 .. elems. len ( ) {
140
140
write ! ( f, "{}" , elems[ i] ) ?;
@@ -144,7 +144,7 @@ impl Closure {
144
144
}
145
145
write ! ( f, ")" )
146
146
} ,
147
- LetTuple ( ref xts, ref y , ref e) => {
147
+ LetTuple ( xts, y , e) => {
148
148
write ! ( f, "let (" ) ?;
149
149
for i in 0 .. xts. len ( ) {
150
150
write ! ( f, "{}: {}" , xts[ i] . 0 , xts[ i] . 1 ) ?;
@@ -158,11 +158,11 @@ impl Closure {
158
158
}
159
159
e. fmt2 ( f, level)
160
160
} ,
161
- Get ( ref x , ref y) =>
161
+ Get ( x , y) =>
162
162
write ! ( f, "{}.({})" , x, y) ,
163
- Put ( ref x, ref y , ref z) =>
163
+ Put ( x, y , z) =>
164
164
write ! ( f, "{}.({}) <- {}" , x, y, z) ,
165
- ExtArray ( id:: L ( ref a) ) => write ! ( f, "(extarr:{})" , a) ,
165
+ ExtArray ( id:: L ( a) ) => write ! ( f, "(extarr:{})" , a) ,
166
166
}
167
167
}
168
168
}
@@ -175,15 +175,15 @@ impl fmt::Display for Closure {
175
175
176
176
impl fmt:: Display for Fundef {
177
177
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
178
- let Fundef { name : ( id:: L ( ref x) , ref t) , args : ref yts, body : ref e1,
179
- formal_fv : ref fv } = * self ;
178
+ let Fundef { name : ( id:: L ( x) , t) , args : yts, body : e1,
179
+ formal_fv : fv } = self ;
180
180
write ! ( f, "define ({}: {})" , x, t) ?;
181
- for & ( ref y , ref t) in yts. iter ( ) {
181
+ for ( y , t) in yts. iter ( ) {
182
182
write ! ( f, " ({}: {})" , y, t) ?;
183
183
}
184
184
if !fv. is_empty ( ) {
185
185
write ! ( f, " freevar:" ) ?;
186
- for & ( ref x , ref t) in fv. iter ( ) {
186
+ for ( x , t) in fv. iter ( ) {
187
187
write ! ( f, " ({}: {})" , x, t) ?;
188
188
}
189
189
}
@@ -196,7 +196,7 @@ impl fmt::Display for Fundef {
196
196
197
197
impl fmt:: Display for Prog {
198
198
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
199
- let Prog ( ref fundefs, ref e) = * self ;
199
+ let Prog ( fundefs, e) = self ;
200
200
for fundef in fundefs. iter ( ) {
201
201
write ! ( f, "{}\n " , fundef) ?;
202
202
}
@@ -210,35 +210,35 @@ pub fn fv(e: &Closure) -> HashSet<String> {
210
210
macro_rules! invoke {
211
211
( $e: expr) => ( fv( $e) ) ;
212
212
}
213
- match * e {
213
+ match e {
214
214
Unit | Int ( _) | Float ( _) | ExtArray ( _) => HashSet :: new ( ) ,
215
- Neg ( ref x) | FNeg ( ref x) => build_set ! ( x) ,
216
- IntBin ( _, ref x, ref y) | FloatBin ( _, ref x , ref y) |
217
- Get ( ref x , ref y) =>
215
+ Neg ( x) | FNeg ( x) => build_set ! ( x) ,
216
+ IntBin ( _, x, y) | FloatBin ( _, x , y) |
217
+ Get ( x , y) =>
218
218
build_set ! ( x, y) ,
219
- IfComp ( _, ref x, ref y, ref e1, ref e2) => {
219
+ IfComp ( _, x, y, e1, e2) => {
220
220
let h = build_set ! ( x, y) ;
221
221
let s1 = invoke ! ( e1) ;
222
222
let s2 = invoke ! ( e2) ;
223
223
& ( & h | & s1) | & s2
224
224
} ,
225
- Let ( ( ref x, _) , ref e1, ref e2) => {
225
+ Let ( ( x, _) , e1, e2) => {
226
226
let s1 = invoke ! ( e1) ;
227
227
let s2 = & invoke ! ( e2) - & build_set ! ( x) ;
228
228
& s1 | & s2
229
229
}
230
- Var ( ref x) => build_set ! ( x) ,
231
- MakeCls ( ref x, _, Cls { entry : _, actual_fv : ref ys } , ref e) =>
230
+ Var ( x) => build_set ! ( x) ,
231
+ MakeCls ( x, _, Cls { entry : _, actual_fv : ys } , e) =>
232
232
& ( & ys. iter ( ) . cloned ( ) . collect ( ) | & invoke ! ( e) ) - & build_set ! ( x) ,
233
- AppCls ( ref x , ref ys) =>
233
+ AppCls ( x , ys) =>
234
234
& build_set ! ( x) | & ys. iter ( ) . cloned ( ) . collect :: < HashSet < _ > > ( ) ,
235
- AppDir ( _, ref xs) | Tuple ( ref xs) => xs. iter ( ) . cloned ( ) . collect ( ) ,
236
- LetTuple ( ref xs, ref y , ref e) => {
235
+ AppDir ( _, xs) | Tuple ( xs) => xs. iter ( ) . cloned ( ) . collect ( ) ,
236
+ LetTuple ( xs, y , e) => {
237
237
let tmp: HashSet < String > = xs. iter ( ) . map ( |x| x. 0 . clone ( ) )
238
238
. collect ( ) ; // S.of_list (List.map fst xs)
239
239
& build_set ! ( y) | & ( & invoke ! ( e) - & tmp)
240
240
} ,
241
- Put ( ref x, ref y , ref z) => build_set ! ( x, y, z) ,
241
+ Put ( x, y , z) => build_set ! ( x, y, z) ,
242
242
}
243
243
}
244
244
@@ -272,13 +272,13 @@ fn g(env: &HashMap<String, Type>, known: &HashSet<String>,
272
272
let mut known_p = known. clone ( ) ;
273
273
known_p. insert ( x. clone ( ) ) ;
274
274
let mut env_p2 = env_p. clone ( ) ;
275
- for & ( ref y , ref t) in yts. iter ( ) {
275
+ for ( y , t) in yts. iter ( ) {
276
276
env_p2. insert ( y. clone ( ) , t. clone ( ) ) ;
277
277
}
278
278
let e1p = g ( & env_p2, & known_p, ( * e1) . clone ( ) , & mut toplevel_cp) ;
279
279
/* Check if e1p contains free variables */
280
280
let zs =
281
- & fv ( & e1p) - & yts. iter ( ) . map ( |& ( ref y, _) | y. clone ( ) ) . collect ( ) ;
281
+ & fv ( & e1p) - & yts. iter ( ) . map ( |( y, _) | y. clone ( ) ) . collect ( ) ;
282
282
let ( known_p, e1p) = if zs. is_empty ( ) {
283
283
* toplevel = toplevel_cp;
284
284
( & known_p, e1p)
@@ -290,7 +290,7 @@ fn g(env: &HashMap<String, Type>, known: &HashSet<String>,
290
290
( known, e1p)
291
291
} ;
292
292
let zs: Vec < String > = ( & zs - & build_set ! ( x) ) . into_iter ( ) . collect ( ) ;
293
- let zts: Vec < ( String , Type ) > = zs. iter ( ) . map ( |& ref z| ( z. clone ( ) , env. get ( z) . unwrap ( ) . clone ( ) ) ) . collect ( ) ;
293
+ let zts: Vec < ( String , Type ) > = zs. iter ( ) . map ( |z| ( z. clone ( ) , env. get ( z) . unwrap ( ) . clone ( ) ) ) . collect ( ) ;
294
294
toplevel. push ( Fundef { name : ( id:: L ( x. clone ( ) ) , t. clone ( ) ) ,
295
295
args : yts,
296
296
formal_fv : zts. into_boxed_slice ( ) ,
@@ -315,7 +315,7 @@ fn g(env: &HashMap<String, Type>, known: &HashSet<String>,
315
315
KNormal :: Tuple ( xs) => Tuple ( xs) ,
316
316
KNormal :: LetTuple ( xts, y, e) => {
317
317
let mut cp_env = env. clone ( ) ;
318
- for & ( ref x , ref t) in xts. iter ( ) {
318
+ for ( x , t) in xts. iter ( ) {
319
319
cp_env. insert ( x. clone ( ) , t. clone ( ) ) ;
320
320
}
321
321
LetTuple ( xts, y, Box :: new ( g ( & cp_env, known, * e, toplevel) ) )
0 commit comments