aboutsummaryrefslogtreecommitdiff
path: root/src/comp/front/ast.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/comp/front/ast.rs')
-rw-r--r--src/comp/front/ast.rs179
1 files changed, 166 insertions, 13 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs
index fb068dba..f9d609d1 100644
--- a/src/comp/front/ast.rs
+++ b/src/comp/front/ast.rs
@@ -5,6 +5,7 @@ import std._vec;
import util.common.span;
import util.common.spanned;
import util.common.ty_mach;
+import util.common.filename;
type ident = str;
@@ -36,11 +37,29 @@ tag def {
def_ty_arg(def_id);
def_binding(def_id);
def_use(def_id);
+ def_native_ty(def_id);
+ def_native_fn(def_id);
}
type crate = spanned[crate_];
type crate_ = rec(_mod module);
+tag crate_directive_ {
+ cdir_expr(@expr);
+ // 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]);
+ cdir_dir_mod(ident, option.t[filename], vec[@crate_directive]);
+ cdir_view_item(@view_item);
+ cdir_meta(vec[@meta_item]);
+ cdir_syntax(path);
+ cdir_auth(path, effect);
+}
+type crate_directive = spanned[crate_directive_];
+
+
type meta_item = spanned[meta_item_];
type meta_item_ = rec(ident name, str value);
@@ -55,6 +74,7 @@ type pat = spanned[pat_];
tag pat_ {
pat_wild(ann);
pat_bind(ident, def_id, ann);
+ pat_lit(@lit, ann);
pat_tag(path, vec[@pat], option.t[variant_def], ann);
}
@@ -63,6 +83,11 @@ tag mutability {
imm;
}
+tag opacity {
+ op_abstract;
+ op_transparent;
+}
+
tag layer {
layer_value;
layer_state;
@@ -75,6 +100,11 @@ tag effect {
eff_unsafe;
}
+tag proto {
+ proto_iter;
+ proto_fn;
+}
+
tag binop {
add;
sub;
@@ -97,12 +127,49 @@ tag binop {
gt;
}
+fn binop_to_str(binop op) -> str {
+ alt (op) {
+ case (add) {ret "+";}
+ case (sub) {ret "-";}
+ case (mul) {ret "*";}
+ case (div) {ret "/";}
+ case (rem) {ret "%";}
+ case (and) {ret "&&";}
+ case (or) {ret "||";}
+ case (bitxor) {ret "^";}
+ case (bitand) {ret "&";}
+ case (bitor) {ret "|";}
+ case (lsl) {ret "<<";}
+ case (lsr) {ret ">>";}
+ case (asr) {ret ">>>";}
+ case (eq) {ret "==";}
+ case (lt) {ret "<";}
+ case (le) {ret "<=";}
+ case (ne) {ret "!=";}
+ case (ge) {ret ">=";}
+ case (gt) {ret ">";}
+ }
+}
+
+
tag unop {
box;
deref;
bitnot;
not;
neg;
+ _mutable;
+}
+
+fn unop_to_str(unop op) -> str {
+ alt (op) {
+ case (box) {ret "@";}
+ case (deref) {ret "*";}
+ case (bitnot) {ret "~";}
+ case (not) {ret "!";}
+ case (neg) {ret "-";}
+ case (_mutable) {ret "mutable";}
+ }
}
tag mode {
@@ -113,11 +180,9 @@ tag mode {
type stmt = spanned[stmt_];
tag stmt_ {
stmt_decl(@decl);
- stmt_ret(option.t[@expr]);
- stmt_log(@expr);
- stmt_check_expr(@expr);
- stmt_fail;
stmt_expr(@expr);
+ // These only exist in crate-level blocks.
+ stmt_crate_directive(@crate_directive);
}
type local = rec(option.t[@ty] ty,
@@ -142,7 +207,7 @@ type expr = spanned[expr_];
tag expr_ {
expr_vec(vec[@expr], ann);
expr_tup(vec[elt], ann);
- expr_rec(vec[field], ann);
+ expr_rec(vec[field], option.t[@expr], ann);
expr_call(@expr, vec[@expr], ann);
expr_bind(@expr, vec[option.t[@expr]], ann);
expr_binary(binop, @expr, @expr, ann);
@@ -152,6 +217,7 @@ tag expr_ {
expr_if(@expr, block, option.t[@expr], ann);
expr_while(@expr, block, ann);
expr_for(@decl, @expr, block, ann);
+ expr_for_each(@decl, @expr, block, ann);
expr_do_while(block, @expr, ann);
expr_alt(@expr, vec[arm], ann);
expr_block(block, ann);
@@ -160,6 +226,13 @@ tag expr_ {
expr_field(@expr, ident, ann);
expr_index(@expr, @expr, ann);
expr_path(path, option.t[def], ann);
+ expr_ext(path, vec[@expr], option.t[@expr], @expr, ann);
+ expr_fail;
+ expr_ret(option.t[@expr]);
+ expr_put(option.t[@expr]);
+ expr_be(@expr);
+ expr_log(@expr);
+ expr_check_expr(@expr);
}
type lit = spanned[lit_];
@@ -179,7 +252,8 @@ tag lit_ {
type ty_field = rec(ident ident, @ty ty);
type ty_arg = rec(mode mode, @ty ty);
// TODO: effect
-type ty_method = rec(ident ident, vec[ty_arg] inputs, @ty output);
+type ty_method = rec(proto proto, ident ident,
+ vec[ty_arg] inputs, @ty output);
type ty = spanned[ty_];
tag ty_ {
ty_nil;
@@ -193,17 +267,28 @@ tag ty_ {
ty_vec(@ty);
ty_tup(vec[@ty]);
ty_rec(vec[ty_field]);
- ty_fn(vec[ty_arg], @ty); // TODO: effect
+ ty_fn(proto, vec[ty_arg], @ty); // TODO: effect
ty_obj(vec[ty_method]);
ty_path(path, option.t[def]);
ty_mutable(@ty);
+ ty_type;
+ ty_constr(@ty, vec[@constr]);
+}
+
+tag constr_arg_ {
+ carg_base;
+ carg_ident(ident);
}
+type constr_arg = spanned[constr_arg_];
+type constr_ = rec(path path, vec[@constr_arg] args);
+type constr = spanned[constr_];
type arg = rec(mode mode, @ty ty, ident ident, def_id id);
-type _fn = rec(effect effect,
- bool is_iter,
- vec[arg] inputs,
- @ty output,
+type fn_decl = rec(effect effect,
+ vec[arg] inputs,
+ @ty output);
+type _fn = rec(fn_decl decl,
+ proto proto,
block body);
@@ -212,8 +297,8 @@ type method = spanned[method_];
type obj_field = rec(@ty ty, ident ident, def_id id, ann ann);
type _obj = rec(vec[obj_field] fields,
- vec[@method] methods);
-
+ vec[@method] methods,
+ option.t[block] dtor);
tag mod_index_entry {
mie_view_item(@view_item);
@@ -221,11 +306,28 @@ tag mod_index_entry {
mie_tag_variant(@item /* tag item */, uint /* variant index */);
}
+tag native_mod_index_entry {
+ nmie_view_item(@view_item);
+ nmie_item(@native_item);
+}
+
type mod_index = hashmap[ident,mod_index_entry];
type _mod = rec(vec[@view_item] view_items,
vec[@item] items,
mod_index index);
+tag native_abi {
+ native_abi_rust;
+ native_abi_cdecl;
+}
+
+type native_mod = rec(str native_name,
+ native_abi abi,
+ vec[@view_item] view_items,
+ vec[@native_item] items,
+ native_mod_index index);
+type native_mod_index = hashmap[ident,native_mod_index_entry];
+
type variant_arg = rec(@ty ty, def_id id);
type variant = rec(str name, vec[variant_arg] args, def_id id, ann ann);
@@ -233,6 +335,7 @@ type view_item = spanned[view_item_];
tag view_item_ {
view_item_use(ident, vec[@meta_item], def_id);
view_item_import(ident, vec[ident], def_id, option.t[def]);
+ view_item_export(ident);
}
type item = spanned[item_];
@@ -240,11 +343,18 @@ tag item_ {
item_const(ident, @ty, @expr, def_id, ann);
item_fn(ident, _fn, vec[ty_param], def_id, ann);
item_mod(ident, _mod, def_id);
+ item_native_mod(ident, native_mod, def_id);
item_ty(ident, @ty, vec[ty_param], def_id, ann);
item_tag(ident, vec[variant], vec[ty_param], def_id);
item_obj(ident, _obj, vec[ty_param], def_id, ann);
}
+type native_item = spanned[native_item_];
+tag native_item_ {
+ native_item_ty(ident, def_id);
+ native_item_fn(ident, fn_decl, vec[ty_param], def_id, ann);
+}
+
fn index_view_item(mod_index index, @view_item it) {
alt (it.node) {
case(ast.view_item_use(?id, _, _)) {
@@ -253,6 +363,11 @@ fn index_view_item(mod_index index, @view_item it) {
case(ast.view_item_import(?def_ident,_,_,_)) {
index.insert(def_ident, ast.mie_view_item(it));
}
+ case(ast.view_item_export(_)) {
+ // NB: don't index these, they might collide with
+ // the import or use that they're exporting. Have
+ // to do linear search for exports.
+ }
}
}
@@ -267,6 +382,9 @@ fn index_item(mod_index index, @item it) {
case (ast.item_mod(?id, _, _)) {
index.insert(id, ast.mie_item(it));
}
+ case (ast.item_native_mod(?id, _, _)) {
+ index.insert(id, ast.mie_item(it));
+ }
case (ast.item_ty(?id, _, _, _, _)) {
index.insert(id, ast.mie_item(it));
}
@@ -285,6 +403,41 @@ fn index_item(mod_index index, @item it) {
}
}
+fn index_native_item(native_mod_index index, @native_item it) {
+ alt (it.node) {
+ case (ast.native_item_ty(?id, _)) {
+ index.insert(id, ast.nmie_item(it));
+ }
+ case (ast.native_item_fn(?id, _, _, _, _)) {
+ index.insert(id, ast.nmie_item(it));
+ }
+ }
+}
+
+fn index_native_view_item(native_mod_index index, @view_item it) {
+ alt (it.node) {
+ case(ast.view_item_import(?def_ident,_,_,_)) {
+ index.insert(def_ident, ast.nmie_view_item(it));
+ }
+ case(ast.view_item_export(_)) {
+ // NB: don't index these, they might collide with
+ // the import or use that they're exporting. Have
+ // to do linear search for exports.
+ }
+ }
+}
+
+fn is_call_expr(@expr e) -> bool {
+ alt (e.node) {
+ case (expr_call(_, _, _)) {
+ ret true;
+ }
+ case (_) {
+ ret false;
+ }
+ }
+}
+
//
// Local Variables:
// mode: rust