@@ -23,17 +23,14 @@ tag val { val_bool(bool); val_int(int); val_str(str); }
23
23
24
24
tag eval_mode { mode_depend; mode_parse; }
25
25
26
- type env = vec[ tup ( ident , val ) ] ;
27
-
28
26
type ctx =
29
27
@rec ( parser p,
30
28
eval_mode mode,
31
29
mutable vec[ str] deps ,
32
30
session:: session sess,
33
31
mutable uint chpos,
34
- mutable int next_id) ;
35
-
36
- fn mk_env ( ) -> env { ret [ ] ; }
32
+ mutable int next_id,
33
+ ast:: crate_cfg cfg) ;
37
34
38
35
fn val_is_bool ( val v) -> bool {
39
36
alt ( v) { case ( val_bool ( _) ) { true } case ( _) { false } }
@@ -59,13 +56,6 @@ fn val_as_str(val v) -> str {
59
56
alt ( v) { case ( val_str ( ?s) ) { s } case ( _) { fail } }
60
57
}
61
58
62
- fn lookup ( session:: session sess, env e, span sp, ident i) -> val {
63
- for ( tup( ident, val) pair in e) {
64
- if ( str:: eq ( i, pair. _0 ) ) { ret pair. _1 ; }
65
- }
66
- sess. span_fatal ( sp, "unknown variable: " + i)
67
- }
68
-
69
59
fn eval_lit ( ctx cx, span sp, @ast:: lit lit) -> val {
70
60
alt ( lit. node ) {
71
61
case ( ast:: lit_bool ( ?b) ) { val_bool ( b) }
@@ -75,18 +65,14 @@ fn eval_lit(ctx cx, span sp, @ast::lit lit) -> val {
75
65
}
76
66
}
77
67
78
- fn eval_expr ( ctx cx, env e , @ast:: expr x) -> val {
68
+ fn eval_expr ( ctx cx, @ast:: expr x) -> val {
79
69
alt ( x. node ) {
80
70
case ( ast:: expr_path ( ?pth) ) {
81
- if ( vec:: len[ ident] ( pth. node . idents ) == 1 u &&
82
- vec:: len[ @ast:: ty] ( pth. node . types ) == 0 u) {
83
- ret lookup ( cx. sess , e, x. span , pth. node . idents . ( 0 ) ) ;
84
- }
85
71
cx. sess . span_fatal ( x. span , "evaluating structured path-name" ) ;
86
72
}
87
73
case ( ast:: expr_lit ( ?lit) ) { ret eval_lit ( cx, x. span , lit) ; }
88
74
case ( ast:: expr_unary ( ?op, ?a) ) {
89
- auto av = eval_expr ( cx, e , a) ;
75
+ auto av = eval_expr ( cx, a) ;
90
76
alt ( op) {
91
77
case ( ast:: not) {
92
78
if ( val_is_bool ( av) ) { ret val_bool ( !val_as_bool ( av) ) ; }
@@ -98,8 +84,8 @@ fn eval_expr(ctx cx, env e, @ast::expr x) -> val {
98
84
}
99
85
}
100
86
case ( ast:: expr_binary ( ?op, ?a, ?b) ) {
101
- auto av = eval_expr ( cx, e , a) ;
102
- auto bv = eval_expr ( cx, e , b) ;
87
+ auto av = eval_expr ( cx, a) ;
88
+ auto bv = eval_expr ( cx, b) ;
103
89
alt ( op) {
104
90
case ( ast:: add) {
105
91
if ( val_is_int ( av) && val_is_int ( bv) ) {
@@ -177,30 +163,30 @@ fn val_eq(session::session sess, span sp, val av, val bv) -> bool {
177
163
} else { sess. span_fatal ( sp, "bad types in comparison" ) }
178
164
}
179
165
180
- fn eval_crate_directives ( ctx cx, env e , vec[ @ast:: crate_directive] cdirs,
166
+ fn eval_crate_directives ( ctx cx, vec[ @ast:: crate_directive] cdirs,
181
167
str prefix , & mutable vec[ @ast:: view_item] view_items ,
182
168
& mutable vec[ @ast:: item] items ) {
183
169
for ( @ast:: crate_directive sub_cdir in cdirs) {
184
- eval_crate_directive ( cx, e , sub_cdir, prefix, view_items, items) ;
170
+ eval_crate_directive ( cx, sub_cdir, prefix, view_items, items) ;
185
171
}
186
172
}
187
173
188
- fn eval_crate_directives_to_mod ( ctx cx, env e ,
174
+ fn eval_crate_directives_to_mod ( ctx cx,
189
175
vec[ @ast:: crate_directive] cdirs , str prefix )
190
176
-> ast:: _mod {
191
177
let vec[ @ast:: view_item] view_items = [ ] ;
192
178
let vec[ @ast:: item] items = [ ] ;
193
- eval_crate_directives ( cx, e , cdirs, prefix, view_items, items) ;
179
+ eval_crate_directives ( cx, cdirs, prefix, view_items, items) ;
194
180
ret rec( view_items=view_items, items=items) ;
195
181
}
196
182
197
- fn eval_crate_directive_block ( ctx cx, env e , & ast:: block blk, str prefix ,
183
+ fn eval_crate_directive_block ( ctx cx, & ast:: block blk, str prefix ,
198
184
& mutable vec[ @ast:: view_item] view_items ,
199
185
& mutable vec[ @ast:: item] items ) {
200
186
for ( @ast:: stmt s in blk. node. stmts) {
201
187
alt ( s. node ) {
202
188
case ( ast:: stmt_crate_directive ( ?cdir) ) {
203
- eval_crate_directive ( cx, e , cdir, prefix, view_items, items) ;
189
+ eval_crate_directive ( cx, cdir, prefix, view_items, items) ;
204
190
}
205
191
case ( _) {
206
192
cx. sess . span_fatal ( s. span ,
@@ -210,22 +196,22 @@ fn eval_crate_directive_block(ctx cx, env e, &ast::block blk, str prefix,
210
196
}
211
197
}
212
198
213
- fn eval_crate_directive_expr ( ctx cx, env e , @ast:: expr x, str prefix ,
199
+ fn eval_crate_directive_expr ( ctx cx, @ast:: expr x, str prefix ,
214
200
& mutable vec[ @ast:: view_item] view_items ,
215
201
& mutable vec[ @ast:: item] items ) {
216
202
alt ( x. node ) {
217
203
case ( ast:: expr_if ( ?cond, ?thn, ?elopt) ) {
218
- auto cv = eval_expr ( cx, e , cond) ;
204
+ auto cv = eval_expr ( cx, cond) ;
219
205
if ( !val_is_bool ( cv) ) {
220
206
cx. sess . span_fatal ( x. span , "bad cond type in 'if'" ) ;
221
207
}
222
208
if ( val_as_bool ( cv) ) {
223
- ret eval_crate_directive_block ( cx, e , thn, prefix, view_items,
209
+ ret eval_crate_directive_block ( cx, thn, prefix, view_items,
224
210
items) ;
225
211
}
226
212
alt ( elopt) {
227
213
case ( some ( ?els) ) {
228
- ret eval_crate_directive_expr ( cx, e , els, prefix,
214
+ ret eval_crate_directive_expr ( cx, els, prefix,
229
215
view_items, items) ;
230
216
}
231
217
case ( _) {
@@ -235,19 +221,19 @@ fn eval_crate_directive_expr(ctx cx, env e, @ast::expr x, str prefix,
235
221
}
236
222
}
237
223
case ( ast:: expr_alt ( ?v, ?arms) ) {
238
- auto vv = eval_expr ( cx, e , v) ;
224
+ auto vv = eval_expr ( cx, v) ;
239
225
for ( ast:: arm arm in arms) {
240
226
alt ( arm. pat . node ) {
241
227
case ( ast:: pat_lit ( ?lit, _) ) {
242
228
auto pv = eval_lit ( cx, arm. pat . span , lit) ;
243
229
if ( val_eq ( cx. sess , arm. pat . span , vv, pv) ) {
244
- ret eval_crate_directive_block ( cx, e , arm. block ,
230
+ ret eval_crate_directive_block ( cx, arm. block ,
245
231
prefix, view_items,
246
232
items) ;
247
233
}
248
234
}
249
235
case ( ast:: pat_wild ( _) ) {
250
- ret eval_crate_directive_block ( cx, e , arm. block ,
236
+ ret eval_crate_directive_block ( cx, arm. block ,
251
237
prefix, view_items,
252
238
items) ;
253
239
}
@@ -260,24 +246,23 @@ fn eval_crate_directive_expr(ctx cx, env e, @ast::expr x, str prefix,
260
246
cx. sess . span_fatal ( x. span , "no cases matched in 'alt'" ) ;
261
247
}
262
248
case ( ast:: expr_block ( ?block) ) {
263
- ret eval_crate_directive_block ( cx, e , block, prefix, view_items,
249
+ ret eval_crate_directive_block ( cx, block, prefix, view_items,
264
250
items) ;
265
251
}
266
252
case ( _) { cx. sess . span_fatal ( x. span , "unsupported expr type" ) ; }
267
253
}
268
254
}
269
255
270
- fn eval_crate_directive ( ctx cx, env e , @ast:: crate_directive cdir, str prefix ,
256
+ fn eval_crate_directive ( ctx cx, @ast:: crate_directive cdir, str prefix ,
271
257
& mutable vec[ @ast:: view_item] view_items ,
272
258
& mutable vec[ @ast:: item] items ) {
273
259
alt ( cdir. node ) {
274
260
case ( ast:: cdir_let ( ?id, ?x, ?cdirs) ) {
275
- auto v = eval_expr ( cx, e, x) ;
276
- auto e0 = [ tup ( id, v) ] + e;
277
- eval_crate_directives ( cx, e0, cdirs, prefix, view_items, items) ;
261
+ auto v = eval_expr ( cx, x) ;
262
+ eval_crate_directives ( cx, cdirs, prefix, view_items, items) ;
278
263
}
279
264
case ( ast:: cdir_expr ( ?x) ) {
280
- eval_crate_directive_expr ( cx, e , x, prefix, view_items, items) ;
265
+ eval_crate_directive_expr ( cx, x, prefix, view_items, items) ;
281
266
}
282
267
case ( ast:: cdir_src_mod ( ?id, ?file_opt, ?attrs) ) {
283
268
auto file_path = id + ".rs" ;
@@ -292,7 +277,7 @@ fn eval_crate_directive(ctx cx, env e, @ast::crate_directive cdir, str prefix,
292
277
} ;
293
278
if ( cx. mode == mode_depend) { cx. deps += [ full_path] ; ret; }
294
279
auto p0 =
295
- new_parser ( cx. sess , e , full_path, cx. chpos ,
280
+ new_parser ( cx. sess , cx . cfg , full_path, cx. chpos ,
296
281
cx. next_id ) ;
297
282
auto inner_attrs = parse_inner_attrs_and_next ( p0) ;
298
283
auto mod_attrs = attrs + inner_attrs. _0 ;
@@ -315,7 +300,7 @@ fn eval_crate_directive(ctx cx, env e, @ast::crate_directive cdir, str prefix,
315
300
} else {
316
301
prefix + std:: fs:: path_sep ( ) + path
317
302
} ;
318
- auto m0 = eval_crate_directives_to_mod ( cx, e , cdirs, full_path) ;
303
+ auto m0 = eval_crate_directives_to_mod ( cx, cdirs, full_path) ;
319
304
auto i = @rec ( ident=id,
320
305
attrs=attrs,
321
306
id=cx. next_id ,
0 commit comments