Parse layer and effect annotations.
This commit is contained in:
parent
afd3af9bb5
commit
0c19c8e18f
@ -55,6 +55,18 @@ tag mutability {
|
||||
imm;
|
||||
}
|
||||
|
||||
tag layer {
|
||||
layer_value;
|
||||
layer_state;
|
||||
layer_gc;
|
||||
}
|
||||
|
||||
tag effect {
|
||||
eff_pure;
|
||||
eff_impure;
|
||||
eff_unsafe;
|
||||
}
|
||||
|
||||
tag binop {
|
||||
add;
|
||||
sub;
|
||||
@ -85,6 +97,11 @@ tag unop {
|
||||
neg;
|
||||
}
|
||||
|
||||
tag mode {
|
||||
val;
|
||||
alias;
|
||||
}
|
||||
|
||||
type stmt = spanned[stmt_];
|
||||
tag stmt_ {
|
||||
stmt_decl(@decl);
|
||||
@ -146,7 +163,9 @@ tag lit_ {
|
||||
|
||||
// NB: If you change this, you'll probably want to change the corresponding
|
||||
// type structure in middle/typeck.rs as well.
|
||||
|
||||
type ty_field = rec(ident ident, @ty ty);
|
||||
type ty_arg = rec(mode mode, @ty ty);
|
||||
type ty = spanned[ty_];
|
||||
tag ty_ {
|
||||
ty_nil;
|
||||
@ -160,18 +179,14 @@ tag ty_ {
|
||||
ty_vec(@ty);
|
||||
ty_tup(vec[@ty]);
|
||||
ty_rec(vec[ty_field]);
|
||||
ty_fn(vec[rec(mode mode, @ty ty)], @ty); // TODO: effect
|
||||
ty_fn(vec[ty_arg], @ty); // TODO: effect
|
||||
ty_path(path, option.t[def]);
|
||||
ty_mutable(@ty);
|
||||
}
|
||||
|
||||
tag mode {
|
||||
val;
|
||||
alias;
|
||||
}
|
||||
|
||||
type arg = rec(mode mode, @ty ty, ident ident, def_id id);
|
||||
type _fn = rec(vec[arg] inputs,
|
||||
type _fn = rec(effect effect,
|
||||
vec[arg] inputs,
|
||||
@ty output,
|
||||
block body);
|
||||
|
||||
|
@ -1161,7 +1161,7 @@ impure fn parse_ty_params(parser p) -> vec[ast.ty_param] {
|
||||
ret ty_params;
|
||||
}
|
||||
|
||||
impure fn parse_item_fn(parser p) -> @ast.item {
|
||||
impure fn parse_item_fn(parser p, ast.effect eff) -> @ast.item {
|
||||
auto lo = p.get_span();
|
||||
expect(p, token.FN);
|
||||
auto id = parse_ident(p);
|
||||
@ -1187,7 +1187,8 @@ impure fn parse_item_fn(parser p) -> @ast.item {
|
||||
|
||||
auto body = parse_block(p);
|
||||
|
||||
let ast._fn f = rec(inputs = inputs.node,
|
||||
let ast._fn f = rec(effect = eff,
|
||||
inputs = inputs.node,
|
||||
output = output,
|
||||
body = body);
|
||||
|
||||
@ -1305,18 +1306,61 @@ impure fn parse_item_tag(parser p) -> @ast.item {
|
||||
ret @spanned(lo, hi, item);
|
||||
}
|
||||
|
||||
impure fn parse_layer(parser p) -> ast.layer {
|
||||
alt (p.peek()) {
|
||||
case (token.STATE) {
|
||||
p.bump();
|
||||
ret ast.layer_state;
|
||||
}
|
||||
case (token.GC) {
|
||||
p.bump();
|
||||
ret ast.layer_gc;
|
||||
}
|
||||
case (_) {
|
||||
ret ast.layer_value;
|
||||
}
|
||||
}
|
||||
fail;
|
||||
}
|
||||
|
||||
|
||||
impure fn parse_effect(parser p) -> ast.effect {
|
||||
alt (p.peek()) {
|
||||
case (token.IMPURE) {
|
||||
p.bump();
|
||||
ret ast.eff_impure;
|
||||
}
|
||||
case (token.UNSAFE) {
|
||||
p.bump();
|
||||
ret ast.eff_unsafe;
|
||||
}
|
||||
case (_) {
|
||||
ret ast.eff_pure;
|
||||
}
|
||||
}
|
||||
fail;
|
||||
}
|
||||
|
||||
impure fn parse_item(parser p) -> @ast.item {
|
||||
let ast.effect eff = parse_effect(p);
|
||||
let ast.layer lyr = parse_layer(p);
|
||||
|
||||
alt (p.peek()) {
|
||||
case (token.FN) {
|
||||
ret parse_item_fn(p);
|
||||
check (lyr == ast.layer_value);
|
||||
ret parse_item_fn(p, eff);
|
||||
}
|
||||
case (token.MOD) {
|
||||
check (eff == ast.eff_pure);
|
||||
check (lyr == ast.layer_value);
|
||||
ret parse_item_mod(p);
|
||||
}
|
||||
case (token.TYPE) {
|
||||
check (eff == ast.eff_pure);
|
||||
ret parse_item_type(p);
|
||||
}
|
||||
case (token.TAG) {
|
||||
check (eff == ast.eff_pure);
|
||||
ret parse_item_tag(p);
|
||||
}
|
||||
case (?t) {
|
||||
|
@ -185,7 +185,8 @@ type ast_fold[ENV] =
|
||||
(fn(&ENV e, &span sp,
|
||||
&ast.block_) -> block) fold_block,
|
||||
|
||||
(fn(&ENV e, vec[arg] inputs,
|
||||
(fn(&ENV e, ast.effect effect,
|
||||
vec[arg] inputs,
|
||||
@ty output, &block body) -> ast._fn) fold_fn,
|
||||
|
||||
(fn(&ENV e, &ast._mod m) -> ast._mod) fold_mod,
|
||||
@ -570,7 +571,7 @@ fn fold_fn[ENV](&ENV env, ast_fold[ENV] fld, &ast._fn f) -> ast._fn {
|
||||
auto output = fold_ty[ENV](env, fld, f.output);
|
||||
auto body = fold_block[ENV](env, fld, f.body);
|
||||
|
||||
ret fld.fold_fn(env, inputs, output, body);
|
||||
ret fld.fold_fn(env, f.effect, inputs, output, body);
|
||||
}
|
||||
|
||||
fn fold_item[ENV](&ENV env, ast_fold[ENV] fld, @item i) -> @item {
|
||||
@ -891,10 +892,11 @@ fn identity_fold_block[ENV](&ENV e, &span sp, &ast.block_ blk) -> block {
|
||||
}
|
||||
|
||||
fn identity_fold_fn[ENV](&ENV e,
|
||||
ast.effect effect,
|
||||
vec[arg] inputs,
|
||||
@ast.ty output,
|
||||
&block body) -> ast._fn {
|
||||
ret rec(inputs=inputs, output=output, body=body);
|
||||
ret rec(effect=effect, inputs=inputs, output=output, body=body);
|
||||
}
|
||||
|
||||
fn identity_fold_mod[ENV](&ENV e, &ast._mod m) -> ast._mod {
|
||||
@ -1007,7 +1009,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
|
||||
fold_item_tag = bind identity_fold_item_tag[ENV](_,_,_,_,_,_),
|
||||
|
||||
fold_block = bind identity_fold_block[ENV](_,_,_),
|
||||
fold_fn = bind identity_fold_fn[ENV](_,_,_,_),
|
||||
fold_fn = bind identity_fold_fn[ENV](_,_,_,_,_),
|
||||
fold_mod = bind identity_fold_mod[ENV](_,_),
|
||||
fold_crate = bind identity_fold_crate[ENV](_,_,_),
|
||||
|
||||
|
@ -1643,7 +1643,8 @@ fn check_fn(&@crate_ctxt ccx, &span sp, ast.ident ident, &ast._fn f,
|
||||
auto block_t = check_block(fcx, f.body);
|
||||
auto block_wb = writeback(fcx, block_t);
|
||||
|
||||
auto fn_t = rec(inputs=f.inputs, output=f.output, body=block_wb);
|
||||
auto fn_t = rec(effect=f.effect, inputs=f.inputs, output=f.output,
|
||||
body=block_wb);
|
||||
auto item = ast.item_fn(ident, fn_t, ty_params, id, fn_ann);
|
||||
ret @fold.respan[ast.item_](sp, item);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user