Add effect field to ast.ty_fn.
Still not used, except by the pretty-printer.
This commit is contained in:
parent
e7e6f396d8
commit
f8393cc572
5 changed files with 35 additions and 31 deletions
|
@ -305,8 +305,7 @@ tag lit_ {
|
|||
type mt = rec(@ty ty, mutability mut);
|
||||
type ty_field = rec(ident ident, mt mt);
|
||||
type ty_arg = rec(mode mode, @ty ty);
|
||||
// TODO: effect
|
||||
type ty_method = rec(proto proto, ident ident,
|
||||
type ty_method = rec(effect effect, proto proto, ident ident,
|
||||
vec[ty_arg] inputs, @ty output);
|
||||
type ty = spanned[ty_];
|
||||
tag ty_ {
|
||||
|
@ -324,7 +323,7 @@ tag ty_ {
|
|||
ty_chan(@ty);
|
||||
ty_tup(vec[mt]);
|
||||
ty_rec(vec[ty_field]);
|
||||
ty_fn(proto, vec[ty_arg], @ty); // TODO: effect
|
||||
ty_fn(effect, proto, vec[ty_arg], @ty);
|
||||
ty_obj(vec[ty_method]);
|
||||
ty_path(path, option.t[def]);
|
||||
ty_type;
|
||||
|
|
|
@ -184,7 +184,7 @@ impure fn parse_str_lit_or_env_ident(parser p) -> ast.ident {
|
|||
}
|
||||
|
||||
|
||||
impure fn parse_ty_fn(ast.proto proto, parser p,
|
||||
impure fn parse_ty_fn(ast.effect eff, ast.proto proto, parser p,
|
||||
ast.span lo) -> ast.ty_ {
|
||||
impure fn parse_fn_input_ty(parser p) -> rec(ast.mode mode, @ast.ty ty) {
|
||||
auto mode;
|
||||
|
@ -228,7 +228,7 @@ impure fn parse_ty_fn(ast.proto proto, parser p,
|
|||
output = @spanned(lo, inputs.span, ast.ty_nil);
|
||||
}
|
||||
|
||||
ret ast.ty_fn(proto, inputs.node, output);
|
||||
ret ast.ty_fn(eff, proto, inputs.node, output);
|
||||
}
|
||||
|
||||
impure fn parse_proto(parser p) -> ast.proto {
|
||||
|
@ -245,15 +245,14 @@ impure fn parse_ty_obj(parser p, &mutable ast.span hi) -> ast.ty_ {
|
|||
impure fn parse_method_sig(parser p) -> ast.ty_method {
|
||||
auto flo = p.get_span();
|
||||
|
||||
// FIXME: do something with this, currently it's dropped on the floor.
|
||||
let ast.effect eff = parse_effect(p);
|
||||
let ast.proto proto = parse_proto(p);
|
||||
auto ident = parse_ident(p);
|
||||
auto f = parse_ty_fn(proto, p, flo);
|
||||
auto f = parse_ty_fn(eff, proto, p, flo);
|
||||
expect(p, token.SEMI);
|
||||
alt (f) {
|
||||
case (ast.ty_fn(?proto, ?inputs, ?output)) {
|
||||
ret rec(proto=proto, ident=ident,
|
||||
case (ast.ty_fn(?eff, ?proto, ?inputs, ?output)) {
|
||||
ret rec(effect=eff, proto=proto, ident=ident,
|
||||
inputs=inputs, output=output);
|
||||
}
|
||||
}
|
||||
|
@ -342,9 +341,9 @@ impure fn parse_ty(parser p) -> @ast.ty {
|
|||
auto hi = lo;
|
||||
let ast.ty_ t;
|
||||
|
||||
// FIXME: do something with these; currently they're
|
||||
// dropped on the floor.
|
||||
// FIXME: make sure these are only used when valid
|
||||
let ast.effect eff = parse_effect(p);
|
||||
// FIXME: do something with this
|
||||
let ast.layer lyr = parse_layer(p);
|
||||
|
||||
alt (p.peek()) {
|
||||
|
@ -412,9 +411,9 @@ impure fn parse_ty(parser p) -> @ast.ty {
|
|||
case (token.FN) {
|
||||
auto flo = p.get_span();
|
||||
p.bump();
|
||||
t = parse_ty_fn(ast.proto_fn, p, flo);
|
||||
t = parse_ty_fn(eff, ast.proto_fn, p, flo);
|
||||
alt (t) {
|
||||
case (ast.ty_fn(_, _, ?out)) {
|
||||
case (ast.ty_fn(_, _, _, ?out)) {
|
||||
hi = out.span;
|
||||
}
|
||||
}
|
||||
|
@ -423,9 +422,9 @@ impure fn parse_ty(parser p) -> @ast.ty {
|
|||
case (token.ITER) {
|
||||
auto flo = p.get_span();
|
||||
p.bump();
|
||||
t = parse_ty_fn(ast.proto_iter, p, flo);
|
||||
t = parse_ty_fn(eff, ast.proto_iter, p, flo);
|
||||
alt (t) {
|
||||
case (ast.ty_fn(_, _, ?out)) {
|
||||
case (ast.ty_fn(_, _, _, ?out)) {
|
||||
hi = out.span;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@ type ast_fold[ENV] =
|
|||
vec[ast.ty_method] meths) -> @ty) fold_ty_obj,
|
||||
|
||||
(fn(&ENV e, &span sp,
|
||||
ast.effect eff,
|
||||
ast.proto proto,
|
||||
vec[rec(ast.mode mode, @ty ty)] inputs,
|
||||
@ty output) -> @ty) fold_ty_fn,
|
||||
|
@ -388,13 +389,13 @@ fn fold_ty[ENV](&ENV env, ast_fold[ENV] fld, @ty t) -> @ty {
|
|||
case (ast.ty_obj(?meths)) {
|
||||
let vec[ast.ty_method] meths_ = vec();
|
||||
for (ast.ty_method m in meths) {
|
||||
auto tfn = fold_ty_fn(env_, fld, t.span, m.proto,
|
||||
auto tfn = fold_ty_fn(env_, fld, t.span, m.effect, m.proto,
|
||||
m.inputs, m.output);
|
||||
alt (tfn.node) {
|
||||
case (ast.ty_fn(?p, ?ins, ?out)) {
|
||||
case (ast.ty_fn(?eff, ?p, ?ins, ?out)) {
|
||||
_vec.push[ast.ty_method]
|
||||
(meths_, rec(proto=p, inputs=ins, output=out
|
||||
with m));
|
||||
(meths_, rec(effect=eff, proto=p, inputs=ins,
|
||||
output=out with m));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -406,8 +407,8 @@ fn fold_ty[ENV](&ENV env, ast_fold[ENV] fld, @ty t) -> @ty {
|
|||
ret fld.fold_ty_path(env_, t.span, pth_, ref_opt);
|
||||
}
|
||||
|
||||
case (ast.ty_fn(?proto, ?inputs, ?output)) {
|
||||
ret fold_ty_fn(env_, fld, t.span, proto, inputs, output);
|
||||
case (ast.ty_fn(?eff, ?proto, ?inputs, ?output)) {
|
||||
ret fold_ty_fn(env_, fld, t.span, eff, proto, inputs, output);
|
||||
}
|
||||
|
||||
case (ast.ty_chan(?ty)) {
|
||||
|
@ -423,7 +424,7 @@ fn fold_ty[ENV](&ENV env, ast_fold[ENV] fld, @ty t) -> @ty {
|
|||
}
|
||||
|
||||
fn fold_ty_fn[ENV](&ENV env, ast_fold[ENV] fld, &span sp,
|
||||
ast.proto proto,
|
||||
ast.effect eff, ast.proto proto,
|
||||
vec[rec(ast.mode mode, @ty ty)] inputs,
|
||||
@ty output) -> @ty {
|
||||
auto output_ = fold_ty(env, fld, output);
|
||||
|
@ -433,7 +434,7 @@ fn fold_ty_fn[ENV](&ENV env, ast_fold[ENV] fld, &span sp,
|
|||
auto input_ = rec(ty=ty_ with input);
|
||||
inputs_ += vec(input_);
|
||||
}
|
||||
ret fld.fold_ty_fn(env, sp, proto, inputs_, output_);
|
||||
ret fld.fold_ty_fn(env, sp, eff, proto, inputs_, output_);
|
||||
}
|
||||
|
||||
fn fold_decl[ENV](&ENV env, ast_fold[ENV] fld, @decl d) -> @decl {
|
||||
|
@ -1131,10 +1132,10 @@ fn identity_fold_ty_obj[ENV](&ENV env, &span sp,
|
|||
}
|
||||
|
||||
fn identity_fold_ty_fn[ENV](&ENV env, &span sp,
|
||||
ast.proto proto,
|
||||
ast.effect eff, ast.proto proto,
|
||||
vec[rec(ast.mode mode, @ty ty)] inputs,
|
||||
@ty output) -> @ty {
|
||||
ret @respan(sp, ast.ty_fn(proto, inputs, output));
|
||||
ret @respan(sp, ast.ty_fn(eff, proto, inputs, output));
|
||||
}
|
||||
|
||||
fn identity_fold_ty_path[ENV](&ENV env, &span sp, ast.path p,
|
||||
|
@ -1569,7 +1570,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
|
|||
fold_ty_tup = bind identity_fold_ty_tup[ENV](_,_,_),
|
||||
fold_ty_rec = bind identity_fold_ty_rec[ENV](_,_,_),
|
||||
fold_ty_obj = bind identity_fold_ty_obj[ENV](_,_,_),
|
||||
fold_ty_fn = bind identity_fold_ty_fn[ENV](_,_,_,_,_),
|
||||
fold_ty_fn = bind identity_fold_ty_fn[ENV](_,_,_,_,_,_),
|
||||
fold_ty_path = bind identity_fold_ty_path[ENV](_,_,_,_),
|
||||
fold_ty_chan = bind identity_fold_ty_chan[ENV](_,_,_),
|
||||
fold_ty_port = bind identity_fold_ty_port[ENV](_,_,_),
|
||||
|
|
|
@ -337,7 +337,7 @@ fn ast_ty_to_ty(ty_getter getter, &@ast.ty ast_ty) -> @ty.t {
|
|||
sty = ty.ty_rec(flds);
|
||||
}
|
||||
|
||||
case (ast.ty_fn(?proto, ?inputs, ?output)) {
|
||||
case (ast.ty_fn(_, ?proto, ?inputs, ?output)) {
|
||||
auto f = bind ast_arg_to_arg(getter, _);
|
||||
auto i = _vec.map[ast.ty_arg, arg](f, inputs);
|
||||
sty = ty.ty_fn(proto, i, ast_ty_to_ty(getter, output));
|
||||
|
|
|
@ -127,7 +127,7 @@ impure fn print_type(ps s, &@ast.ty ty) {
|
|||
bopen(s);
|
||||
for (ast.ty_method m in methods) {
|
||||
hbox(s);
|
||||
print_ty_fn(s, m.proto, option.some[str](m.ident),
|
||||
print_ty_fn(s, m.effect, m.proto, option.some[str](m.ident),
|
||||
m.inputs, m.output);
|
||||
wrd(s.s, ";");
|
||||
end(s.s);
|
||||
|
@ -135,8 +135,8 @@ impure fn print_type(ps s, &@ast.ty ty) {
|
|||
}
|
||||
bclose_c(s, ty.span);
|
||||
}
|
||||
case (ast.ty_fn(?proto,?inputs,?output)) {
|
||||
print_ty_fn(s, proto, option.none[str], inputs, output);
|
||||
case (ast.ty_fn(?eff, ?proto,?inputs,?output)) {
|
||||
print_ty_fn(s, eff, proto, option.none[str], inputs, output);
|
||||
}
|
||||
case (ast.ty_path(?path,_)) {
|
||||
print_path(s, path);
|
||||
|
@ -843,8 +843,13 @@ impure fn print_string(ps s, str st) {
|
|||
wrd(s.s, "\""); wrd(s.s, escape_str(st, '"')); wrd(s.s, "\"");
|
||||
}
|
||||
|
||||
impure fn print_ty_fn(ps s, ast.proto proto, option.t[str] id,
|
||||
impure fn print_ty_fn(ps s, ast.effect eff, ast.proto proto, option.t[str] id,
|
||||
vec[ast.ty_arg] inputs, @ast.ty output) {
|
||||
alt (eff) {
|
||||
case (ast.eff_impure) {wrd1(s, "impure");}
|
||||
case (ast.eff_unsafe) {wrd1(s, "unsafe");}
|
||||
case (_) {}
|
||||
}
|
||||
if (proto == ast.proto_fn) {wrd(s.s, "fn");}
|
||||
else {wrd(s.s, "iter");}
|
||||
alt (id) {
|
||||
|
|
Loading…
Reference in a new issue