Skip to content

Commit

Permalink
Remove the concept of crate directive let statements. Issue #604
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed Jul 1, 2011
1 parent d8fe0d7 commit 91b87b3
Show file tree
Hide file tree
Showing 6 changed files with 0 additions and 123 deletions.
4 changes: 0 additions & 4 deletions src/comp/front/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ type crate_ = rec(vec[@crate_directive] directives,
crate_cfg config);

tag crate_directive_ {
// FIXME: cdir_let should be eliminated
// and redirected to the use of const stmt_decls inside
// crate directive blocks.
cdir_let(ident, @expr, vec[@crate_directive]);
cdir_src_mod(ident, option::t[filename], vec[attribute]);
cdir_dir_mod(ident, option::t[filename],
vec[@crate_directive], vec[attribute]);
Expand Down
92 changes: 0 additions & 92 deletions src/comp/front/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,94 +65,6 @@ fn eval_lit(ctx cx, span sp, @ast::lit lit) -> val {
}
}

fn eval_expr(ctx cx, @ast::expr x) -> val {
alt (x.node) {
case (ast::expr_path(?pth)) {
cx.sess.span_fatal(x.span, "evaluating structured path-name");
}
case (ast::expr_lit(?lit)) { ret eval_lit(cx, x.span, lit); }
case (ast::expr_unary(?op, ?a)) {
auto av = eval_expr(cx, a);
alt (op) {
case (ast::not) {
if (val_is_bool(av)) { ret val_bool(!val_as_bool(av)); }
cx.sess.span_fatal(x.span, "bad types in '!' expression");
}
case (_) {
cx.sess.span_fatal(x.span, "evaluating unsupported unop");
}
}
}
case (ast::expr_binary(?op, ?a, ?b)) {
auto av = eval_expr(cx, a);
auto bv = eval_expr(cx, b);
alt (op) {
case (ast::add) {
if (val_is_int(av) && val_is_int(bv)) {
ret val_int(val_as_int(av) + val_as_int(bv));
}
if (val_is_str(av) && val_is_str(bv)) {
ret val_str(val_as_str(av) + val_as_str(bv));
}
cx.sess.span_fatal(x.span, "bad types in '+' expression");
}
case (ast::sub) {
if (val_is_int(av) && val_is_int(bv)) {
ret val_int(val_as_int(av) - val_as_int(bv));
}
cx.sess.span_fatal(x.span, "bad types in '-' expression");
}
case (ast::mul) {
if (val_is_int(av) && val_is_int(bv)) {
ret val_int(val_as_int(av) * val_as_int(bv));
}
cx.sess.span_fatal(x.span, "bad types in '*' expression");
}
case (ast::div) {
if (val_is_int(av) && val_is_int(bv)) {
ret val_int(val_as_int(av) / val_as_int(bv));
}
cx.sess.span_fatal(x.span, "bad types in '/' expression");
}
case (ast::rem) {
if (val_is_int(av) && val_is_int(bv)) {
ret val_int(val_as_int(av) % val_as_int(bv));
}
cx.sess.span_fatal(x.span, "bad types in '%' expression");
}
case (ast::and) {
if (val_is_bool(av) && val_is_bool(bv)) {
ret val_bool(val_as_bool(av) && val_as_bool(bv));
}
cx.sess.span_fatal(x.span,
"bad types in '&&' expression");
}
case (ast::or) {
if (val_is_bool(av) && val_is_bool(bv)) {
ret val_bool(val_as_bool(av) || val_as_bool(bv));
}
cx.sess.span_fatal(x.span,
"bad types in '||' expression");
}
case (ast::eq) {
ret val_bool(val_eq(cx.sess, x.span, av, bv));
}
case (ast::ne) {
ret val_bool(!val_eq(cx.sess, x.span, av, bv));
}
case (_) {
cx.sess.span_fatal(x.span,
"evaluating unsupported binop");
}
}
}
case (_) {
cx.sess.span_fatal(x.span, "evaluating unsupported expression");
}
}
fail;
}

fn val_eq(session::session sess, span sp, val av, val bv) -> bool {
if (val_is_bool(av) && val_is_bool(bv)) {
val_as_bool(av) == val_as_bool(bv)
Expand Down Expand Up @@ -200,10 +112,6 @@ fn eval_crate_directive(ctx cx, @ast::crate_directive cdir, str prefix,
&mutable vec[@ast::view_item] view_items,
&mutable vec[@ast::item] items) {
alt (cdir.node) {
case (ast::cdir_let(?id, ?x, ?cdirs)) {
auto v = eval_expr(cx, x);
eval_crate_directives(cx, cdirs, prefix, view_items, items);
}
case (ast::cdir_src_mod(?id, ?file_opt, ?attrs)) {
auto file_path = id + ".rs";
alt (file_opt) {
Expand Down
4 changes: 0 additions & 4 deletions src/comp/front/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,6 @@ fn noop_fold_crate(&crate_ c, ast_fold fld) -> crate_ {
fn noop_fold_crate_directive(&crate_directive_ cd, ast_fold fld)
-> crate_directive_ {
ret alt(cd) {
case(cdir_let(?id, ?e, ?cds)) {
cdir_let(fld.fold_ident(id), fld.fold_expr(e),
map(fld.fold_crate_directive, cds))
}
case(cdir_src_mod(?id,?fname,?attrs)) {
cdir_src_mod(fld.fold_ident(id), fname, attrs)
}
Expand Down
11 changes: 0 additions & 11 deletions src/comp/front/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2397,17 +2397,6 @@ fn parse_crate_directive(&parser p, vec[ast::attribute] first_outer_attr)
auto hi = p.get_hi_pos();
expect(p, token::SEMI);
ret spanned(lo, hi, ast::cdir_auth(n, a));
} else if (eat_word(p, "let")) {
expect(p, token::LPAREN);
auto id = parse_value_ident(p);
expect(p, token::EQ);
auto x = parse_expr(p);
expect(p, token::RPAREN);
expect(p, token::LBRACE);
auto v = parse_crate_directives(p, token::RBRACE, []);
auto hi = p.get_hi_pos();
expect(p, token::RBRACE);
ret spanned(lo, hi, ast::cdir_let(id, x, v));
} else if (is_view_item(p)) {
auto vi = parse_view_item(p);
ret spanned(lo, vi.span.hi, ast::cdir_view_item(vi));
Expand Down
6 changes: 0 additions & 6 deletions src/comp/middle/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ fn visit_crate[E](&crate c, &E e, &vt[E] v) {

fn visit_crate_directive[E](&@crate_directive cd, &E e, &vt[E] v) {
alt (cd.node) {
case (cdir_let(_, ?ex, ?cdirs)) {
vt(v).visit_expr(ex, e, v);
for (@crate_directive cdir in cdirs) {
visit_crate_directive(cdir, e, v);
}
}
case (cdir_src_mod(_, _, _)) { }
case (cdir_dir_mod(_, _, ?cdirs, _)) {
for (@crate_directive cdir in cdirs) {
Expand Down
6 changes: 0 additions & 6 deletions src/comp/middle/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,6 @@ fn walk_crate_directive(&ast_visitor v, @ast::crate_directive cd) {
if (!v.want_crate_directives()) { ret; }
v.visit_crate_directive_pre(cd);
alt (cd.node) {
case (ast::cdir_let(_, ?e, ?cdirs)) {
walk_expr(v, e);
for (@ast::crate_directive cdir in cdirs) {
walk_crate_directive(v, cdir);
}
}
case (ast::cdir_src_mod(_, _, _)) { }
case (ast::cdir_dir_mod(_, _, ?cdirs, _)) {
for (@ast::crate_directive cdir in cdirs) {
Expand Down

0 comments on commit 91b87b3

Please sign in to comment.