2010-08-18 09:00:10 -07:00
|
|
|
|
|
|
|
import std.map.hashmap;
|
2010-11-03 17:10:37 -07:00
|
|
|
import std.option;
|
2010-11-03 16:43:12 -07:00
|
|
|
import middle.typeck;
|
2010-09-01 13:24:14 -07:00
|
|
|
import util.common.span;
|
2010-10-05 18:21:44 -07:00
|
|
|
import util.common.spanned;
|
2010-11-22 17:41:26 -08:00
|
|
|
import util.common.ty_mach;
|
2010-08-18 09:00:10 -07:00
|
|
|
|
|
|
|
type ident = str;
|
|
|
|
|
2010-10-06 15:41:14 -07:00
|
|
|
type name_ = rec(ident ident, vec[@ty] types);
|
2010-10-05 18:21:44 -07:00
|
|
|
type name = spanned[name_];
|
2010-10-04 17:25:52 -07:00
|
|
|
type path = vec[name];
|
|
|
|
|
2010-10-05 18:21:44 -07:00
|
|
|
type crate_num = int;
|
2010-10-18 16:15:25 -07:00
|
|
|
type def_num = int;
|
|
|
|
type def_id = tup(crate_num, def_num);
|
|
|
|
|
2010-11-24 18:01:20 -08:00
|
|
|
type ty_param = rec(ident ident, def_id id);
|
|
|
|
|
2010-11-03 15:53:53 -07:00
|
|
|
// Annotations added during successive passes.
|
|
|
|
tag ann {
|
|
|
|
ann_none;
|
2010-11-03 16:43:12 -07:00
|
|
|
ann_type(@typeck.ty);
|
2010-11-03 15:53:53 -07:00
|
|
|
}
|
|
|
|
|
2010-10-18 16:15:25 -07:00
|
|
|
tag def {
|
|
|
|
def_fn(def_id);
|
|
|
|
def_mod(def_id);
|
|
|
|
def_const(def_id);
|
|
|
|
def_arg(def_id);
|
|
|
|
def_local(def_id);
|
|
|
|
def_ty(def_id);
|
|
|
|
def_ty_arg(def_id);
|
2010-10-05 18:21:44 -07:00
|
|
|
}
|
2010-10-04 17:25:52 -07:00
|
|
|
|
2010-10-05 18:21:44 -07:00
|
|
|
type crate = spanned[crate_];
|
|
|
|
type crate_ = rec(_mod module);
|
2010-08-18 09:00:10 -07:00
|
|
|
|
2010-10-05 18:21:44 -07:00
|
|
|
type block = spanned[block_];
|
2010-10-18 18:19:16 -07:00
|
|
|
type block_ = rec(vec[@stmt] stmts,
|
|
|
|
hashmap[ident,uint] index);
|
2010-08-18 09:00:10 -07:00
|
|
|
|
2010-11-24 14:42:01 -08:00
|
|
|
type pat = spanned[pat_];
|
|
|
|
tag pat_ {
|
2010-11-24 15:45:59 -08:00
|
|
|
pat_wild(ann);
|
|
|
|
pat_bind(ident, ann);
|
|
|
|
pat_tag(ident, vec[@pat], ann);
|
2010-11-24 14:42:01 -08:00
|
|
|
}
|
|
|
|
|
2010-09-27 18:25:02 -07:00
|
|
|
tag binop {
|
2010-09-28 10:30:34 -07:00
|
|
|
add;
|
|
|
|
sub;
|
|
|
|
mul;
|
|
|
|
div;
|
|
|
|
rem;
|
|
|
|
and;
|
|
|
|
or;
|
|
|
|
bitxor;
|
2010-09-27 18:25:02 -07:00
|
|
|
bitand;
|
|
|
|
bitor;
|
|
|
|
lsl;
|
|
|
|
lsr;
|
|
|
|
asr;
|
|
|
|
eq;
|
|
|
|
lt;
|
|
|
|
le;
|
|
|
|
ne;
|
|
|
|
ge;
|
|
|
|
gt;
|
|
|
|
}
|
|
|
|
|
|
|
|
tag unop {
|
2010-09-28 10:30:34 -07:00
|
|
|
box;
|
|
|
|
deref;
|
2010-09-27 18:25:02 -07:00
|
|
|
bitnot;
|
|
|
|
not;
|
|
|
|
neg;
|
|
|
|
}
|
|
|
|
|
2010-10-05 18:21:44 -07:00
|
|
|
type stmt = spanned[stmt_];
|
|
|
|
tag stmt_ {
|
2010-09-09 15:59:29 -07:00
|
|
|
stmt_decl(@decl);
|
2010-11-03 17:10:37 -07:00
|
|
|
stmt_ret(option.t[@expr]);
|
2010-09-27 18:25:02 -07:00
|
|
|
stmt_log(@expr);
|
2010-10-22 15:37:42 -07:00
|
|
|
stmt_check_expr(@expr);
|
2010-10-04 15:55:12 -07:00
|
|
|
stmt_expr(@expr);
|
2010-09-09 15:59:29 -07:00
|
|
|
}
|
|
|
|
|
2010-11-03 17:10:37 -07:00
|
|
|
type local = rec(option.t[@ty] ty,
|
2010-10-18 18:19:16 -07:00
|
|
|
bool infer,
|
|
|
|
ident ident,
|
2010-11-03 17:10:37 -07:00
|
|
|
option.t[@expr] init,
|
2010-11-12 16:11:33 -08:00
|
|
|
def_id id,
|
|
|
|
ann ann);
|
2010-10-18 18:19:16 -07:00
|
|
|
|
2010-10-05 18:21:44 -07:00
|
|
|
type decl = spanned[decl_];
|
|
|
|
tag decl_ {
|
2010-10-19 14:54:10 -07:00
|
|
|
decl_local(@local);
|
2010-10-18 18:19:16 -07:00
|
|
|
decl_item(@item);
|
2010-09-09 15:59:29 -07:00
|
|
|
}
|
|
|
|
|
2010-11-24 15:45:59 -08:00
|
|
|
type arm = rec(@pat pat, block block);
|
|
|
|
|
2010-10-05 18:21:44 -07:00
|
|
|
type expr = spanned[expr_];
|
|
|
|
tag expr_ {
|
2010-11-03 15:53:53 -07:00
|
|
|
expr_vec(vec[@expr], ann);
|
|
|
|
expr_tup(vec[tup(bool /* mutability */, @expr)], ann);
|
|
|
|
expr_rec(vec[tup(ident,@expr)], ann);
|
|
|
|
expr_call(@expr, vec[@expr], ann);
|
|
|
|
expr_binary(binop, @expr, @expr, ann);
|
|
|
|
expr_unary(unop, @expr, ann);
|
|
|
|
expr_lit(@lit, ann);
|
|
|
|
expr_cast(@expr, @ty, ann);
|
2010-11-03 17:10:37 -07:00
|
|
|
expr_if(@expr, block, option.t[block], ann);
|
2010-11-03 15:53:53 -07:00
|
|
|
expr_while(@expr, block, ann);
|
|
|
|
expr_do_while(block, @expr, ann);
|
2010-11-24 14:42:01 -08:00
|
|
|
expr_alt(@expr, vec[arm], ann);
|
2010-11-03 15:53:53 -07:00
|
|
|
expr_block(block, ann);
|
|
|
|
expr_assign(@expr /* TODO: @expr|is_lval */, @expr, ann);
|
|
|
|
expr_field(@expr, ident, ann);
|
|
|
|
expr_index(@expr, @expr, ann);
|
2010-11-03 17:10:37 -07:00
|
|
|
expr_name(name, option.t[def], ann);
|
2010-09-09 15:59:29 -07:00
|
|
|
}
|
|
|
|
|
2010-10-05 18:21:44 -07:00
|
|
|
type lit = spanned[lit_];
|
|
|
|
tag lit_ {
|
2010-09-27 18:25:02 -07:00
|
|
|
lit_str(str);
|
2010-09-09 15:59:29 -07:00
|
|
|
lit_char(char);
|
|
|
|
lit_int(int);
|
2010-09-21 16:22:32 -07:00
|
|
|
lit_uint(uint);
|
2010-11-22 17:41:26 -08:00
|
|
|
lit_mach_int(ty_mach, int);
|
2010-09-20 23:56:43 -07:00
|
|
|
lit_nil;
|
2010-09-09 15:59:29 -07:00
|
|
|
lit_bool(bool);
|
|
|
|
}
|
|
|
|
|
2010-11-03 16:43:12 -07:00
|
|
|
// NB: If you change this, you'll probably want to change the corresponding
|
|
|
|
// type structure in middle/typeck.rs as well.
|
2010-10-05 18:21:44 -07:00
|
|
|
type ty = spanned[ty_];
|
|
|
|
tag ty_ {
|
2010-09-20 23:56:43 -07:00
|
|
|
ty_nil;
|
|
|
|
ty_bool;
|
|
|
|
ty_int;
|
2010-09-21 16:22:32 -07:00
|
|
|
ty_uint;
|
|
|
|
ty_machine(util.common.ty_mach);
|
2010-09-20 23:56:43 -07:00
|
|
|
ty_char;
|
2010-09-21 16:22:32 -07:00
|
|
|
ty_str;
|
|
|
|
ty_box(@ty);
|
2010-10-13 10:55:20 -07:00
|
|
|
ty_vec(@ty);
|
2010-10-11 18:41:45 -07:00
|
|
|
ty_tup(vec[tup(bool /* mutability */, @ty)]);
|
2010-11-05 15:23:03 -07:00
|
|
|
ty_fn(vec[rec(mode mode, @ty ty)], @ty); // TODO: effect
|
2010-11-03 17:10:37 -07:00
|
|
|
ty_path(path, option.t[def]);
|
2010-09-09 15:59:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
tag mode {
|
2010-09-20 23:56:43 -07:00
|
|
|
val;
|
|
|
|
alias;
|
2010-09-09 15:59:29 -07:00
|
|
|
}
|
2010-08-18 09:00:10 -07:00
|
|
|
|
2010-10-18 16:15:25 -07:00
|
|
|
type arg = rec(mode mode, @ty ty, ident ident, def_id id);
|
|
|
|
type _fn = rec(vec[arg] inputs,
|
2010-10-18 18:19:16 -07:00
|
|
|
@ty output,
|
2010-08-18 09:00:10 -07:00
|
|
|
block body);
|
|
|
|
|
2010-10-18 18:19:16 -07:00
|
|
|
type _mod = rec(vec[@item] items,
|
|
|
|
hashmap[ident,uint] index);
|
2010-08-18 09:00:10 -07:00
|
|
|
|
2010-11-24 11:36:35 -08:00
|
|
|
type variant = rec(str name, vec[@ty] args);
|
|
|
|
|
2010-10-05 18:21:44 -07:00
|
|
|
type item = spanned[item_];
|
|
|
|
tag item_ {
|
2010-11-24 16:52:49 -08:00
|
|
|
item_fn(ident, _fn, vec[ty_param], def_id, ann);
|
2010-10-18 18:19:16 -07:00
|
|
|
item_mod(ident, _mod, def_id);
|
2010-11-24 17:36:22 -08:00
|
|
|
item_ty(ident, @ty, vec[ty_param], def_id, ann);
|
2010-11-24 17:15:54 -08:00
|
|
|
item_tag(ident, vec[variant], vec[ty_param], def_id);
|
2010-09-09 15:59:29 -07:00
|
|
|
}
|
2010-08-18 09:00:10 -07:00
|
|
|
|
2010-08-12 10:27:50 -07:00
|
|
|
|
|
|
|
//
|
|
|
|
// Local Variables:
|
|
|
|
// mode: rust
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// compile-command: "make -k -C ../.. 2>&1 | sed -e 's/\\/x\\//x:\\//g'";
|
|
|
|
// End:
|
|
|
|
//
|