Skip to content

Commit 32ffb87

Browse files
committed
---
yaml --- r: 886 b: refs/heads/master c: 35eb088 h: refs/heads/master v: v3
1 parent 33c702c commit 32ffb87

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 91b1885ba2a82cd1ac3701a71bb47bf6b7ddd8e9
2+
refs/heads/master: 35eb088ae3a5a530880a77d32798b22639ec6cdd

trunk/src/comp/front/ast.rs

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ tag ty_ {
130130
ty_box(@ty);
131131
ty_vec(@ty);
132132
ty_tup(vec[tup(bool /* mutability */, @ty)]);
133+
ty_fn(vec[rec(mode mode, @ty ty)], @ty); // TODO: effect
133134
ty_path(path, option.t[def]);
134135
}
135136

trunk/src/comp/front/parser.rs

+43
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,45 @@ impure fn parse_possibly_mutable_ty(parser p) -> tup(bool, @ast.ty) {
108108
ret tup(mut, parse_ty(p));
109109
}
110110

111+
impure fn parse_ty_fn(parser p) -> ast.ty_ {
112+
impure fn parse_fn_input_ty(parser p) -> rec(ast.mode mode, @ast.ty ty) {
113+
auto mode;
114+
if (p.peek() == token.BINOP(token.AND)) {
115+
p.bump();
116+
mode = ast.alias;
117+
} else {
118+
mode = ast.val;
119+
}
120+
121+
auto t = parse_ty(p);
122+
123+
alt (p.peek()) {
124+
case (token.IDENT(_)) { p.bump(); /* ignore the param name */ }
125+
case (_) { /* no param name present */ }
126+
}
127+
128+
ret rec(mode=mode, ty=t);
129+
}
130+
131+
auto lo = p.get_span();
132+
133+
expect(p, token.FN);
134+
135+
auto f = parse_fn_input_ty; // FIXME: trans_const_lval bug
136+
auto inputs = parse_seq[rec(ast.mode mode, @ast.ty ty)](token.LPAREN,
137+
token.RPAREN, some(token.COMMA), f, p);
138+
139+
let @ast.ty output;
140+
if (p.peek() == token.RARROW) {
141+
p.bump();
142+
output = parse_ty(p);
143+
} else {
144+
output = @spanned(lo, inputs.span, ast.ty_nil);
145+
}
146+
147+
ret ast.ty_fn(inputs.node, output);
148+
}
149+
111150
impure fn parse_ty(parser p) -> @ast.ty {
112151
auto lo = p.get_span();
113152
let ast.ty_ t;
@@ -135,6 +174,10 @@ impure fn parse_ty(parser p) -> @ast.ty {
135174
t = ast.ty_tup(elems.node);
136175
}
137176

177+
case (token.FN) {
178+
t = parse_ty_fn(p);
179+
}
180+
138181
case (_) {
139182
p.err("expecting type");
140183
t = ast.ty_nil;

trunk/src/comp/middle/fold.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,12 @@ type ast_fold[ENV] =
4646
(fn(&ENV e, &span sp,
4747
vec[tup(bool, @ty)] elts) -> @ty) fold_ty_tup,
4848

49+
(fn(&ENV e, &span sp,
50+
vec[rec(ast.mode mode, @ty ty)] inputs,
51+
@ty output) -> @ty) fold_ty_fn,
52+
4953
(fn(&ENV e, &span sp, ast.path p,
50-
&option.t[def] d) -> @ty) fold_ty_path,
54+
&option.t[def] d) -> @ty) fold_ty_path,
5155

5256
// Expr folds.
5357
(fn(&ENV e, &span sp,
@@ -226,6 +230,10 @@ fn fold_ty[ENV](&ENV env, ast_fold[ENV] fld, @ty t) -> @ty {
226230
}
227231
ret fld.fold_ty_path(env_, t.span, path, ref_opt);
228232
}
233+
234+
case (ast.ty_fn(?inputs, ?output)) {
235+
ret fld.fold_ty_fn(env_, t.span, inputs, output);
236+
}
229237
}
230238
}
231239

@@ -567,6 +575,12 @@ fn identity_fold_ty_tup[ENV](&ENV env, &span sp, vec[tup(bool,@ty)] elts)
567575
ret @respan(sp, ast.ty_tup(elts));
568576
}
569577

578+
fn identity_fold_ty_fn[ENV](&ENV env, &span sp,
579+
vec[rec(ast.mode mode, @ty ty)] inputs,
580+
@ty output) -> @ty {
581+
ret @respan(sp, ast.ty_fn(inputs, output));
582+
}
583+
570584
fn identity_fold_ty_path[ENV](&ENV env, &span sp, ast.path p,
571585
&option.t[def] d) -> @ty {
572586
ret @respan(sp, ast.ty_path(p, d));
@@ -785,6 +799,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
785799
fold_ty_box = bind identity_fold_ty_box[ENV](_,_,_),
786800
fold_ty_vec = bind identity_fold_ty_vec[ENV](_,_,_),
787801
fold_ty_tup = bind identity_fold_ty_tup[ENV](_,_,_),
802+
fold_ty_fn = bind identity_fold_ty_fn[ENV](_,_,_,_),
788803
fold_ty_path = bind identity_fold_ty_path[ENV](_,_,_,_),
789804

790805
fold_expr_vec = bind identity_fold_expr_vec[ENV](_,_,_,_),

0 commit comments

Comments
 (0)