Skip to content

Commit d8b9668

Browse files
committed
---
yaml --- r: 950 b: refs/heads/master c: c1916ad h: refs/heads/master v: v3
1 parent ec8a2bc commit d8b9668

File tree

7 files changed

+39
-19
lines changed

7 files changed

+39
-19
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 80d099c59ab1a9ce4ef24087c2c17c42b686e66c
2+
refs/heads/master: c1916adc7e16bd7ecd3ca8dbbe985ec75d0c825a

trunk/src/comp/front/ast.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import util.common.spanned;
77
import util.common.ty_mach;
88

99
type ident = str;
10+
type ty_param = ident;
1011

1112
type name_ = rec(ident ident, vec[@ty] types);
1213
type name = spanned[name_];
@@ -167,7 +168,7 @@ type variant = rec(str name, vec[@ty] args);
167168

168169
type item = spanned[item_];
169170
tag item_ {
170-
item_fn(ident, _fn, def_id, ann);
171+
item_fn(ident, _fn, vec[ty_param], def_id, ann);
171172
item_mod(ident, _mod, def_id);
172173
item_ty(ident, @ty, def_id, ann);
173174
item_tag(ident, vec[variant], def_id);

trunk/src/comp/front/parser.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ impure fn parse_block(parser p) -> ast.block {
10201020
}
10211021
case (ast.decl_item(?it)) {
10221022
alt (it.node) {
1023-
case (ast.item_fn(?i, _, _, _)) {
1023+
case (ast.item_fn(?i, _, _, _, _)) {
10241024
index.insert(i, u-1u);
10251025
}
10261026
case (ast.item_mod(?i, _, _)) {
@@ -1043,6 +1043,14 @@ impure fn parse_item_fn(parser p) -> tup(ast.ident, @ast.item) {
10431043
auto lo = p.get_span();
10441044
expect(p, token.FN);
10451045
auto id = parse_ident(p);
1046+
1047+
let vec[ast.ty_param] ty_params = vec();
1048+
if (p.peek() == token.LBRACKET) {
1049+
auto pg = parse_ident; // FIXME: pass as lval directly
1050+
ty_params = parse_seq[ast.ty_param](token.LBRACKET, token.RBRACKET,
1051+
some(token.COMMA), pg, p).node;
1052+
}
1053+
10461054
auto pf = parse_arg;
10471055
let util.common.spanned[vec[ast.arg]] inputs =
10481056
// FIXME: passing parse_arg as an lval doesn't work at the
@@ -1067,7 +1075,7 @@ impure fn parse_item_fn(parser p) -> tup(ast.ident, @ast.item) {
10671075
output = output,
10681076
body = body);
10691077

1070-
auto item = ast.item_fn(id, f, p.next_def_id(), ast.ann_none);
1078+
auto item = ast.item_fn(id, f, ty_params, p.next_def_id(), ast.ann_none);
10711079
ret tup(id, @spanned(lo, body.span, item));
10721080
}
10731081

trunk/src/comp/middle/fold.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ type ast_fold[ENV] =
158158

159159
// Item folds.
160160
(fn(&ENV e, &span sp, ident ident,
161-
&ast._fn f, def_id id, ann a) -> @item) fold_item_fn,
161+
&ast._fn f,
162+
vec[ast.ty_param] ty_params,
163+
def_id id, ann a) -> @item) fold_item_fn,
162164

163165
(fn(&ENV e, &span sp, ident ident,
164166
&ast._mod m, def_id id) -> @item) fold_item_mod,
@@ -537,9 +539,9 @@ fn fold_item[ENV](&ENV env, ast_fold[ENV] fld, @item i) -> @item {
537539

538540
alt (i.node) {
539541

540-
case (ast.item_fn(?ident, ?ff, ?id, ?ann)) {
542+
case (ast.item_fn(?ident, ?ff, ?tps, ?id, ?ann)) {
541543
let ast._fn ff_ = fold_fn[ENV](env_, fld, ff);
542-
ret fld.fold_item_fn(env_, i.span, ident, ff_, id, ann);
544+
ret fld.fold_item_fn(env_, i.span, ident, ff_, tps, id, ann);
543545
}
544546

545547
case (ast.item_mod(?ident, ?mm, ?id)) {
@@ -798,8 +800,9 @@ fn identity_fold_stmt_expr[ENV](&ENV e, &span sp, @expr x) -> @stmt {
798800
// Item identities.
799801

800802
fn identity_fold_item_fn[ENV](&ENV e, &span sp, ident i,
801-
&ast._fn f, def_id id, ann a) -> @item {
802-
ret @respan(sp, ast.item_fn(i, f, id, a));
803+
&ast._fn f, vec[ast.ty_param] ty_params,
804+
def_id id, ann a) -> @item {
805+
ret @respan(sp, ast.item_fn(i, f, ty_params, id, a));
803806
}
804807

805808
fn identity_fold_item_mod[ENV](&ENV e, &span sp, ident i,
@@ -933,7 +936,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
933936
= bind identity_fold_stmt_check_expr[ENV](_,_,_),
934937
fold_stmt_expr = bind identity_fold_stmt_expr[ENV](_,_,_),
935938

936-
fold_item_fn = bind identity_fold_item_fn[ENV](_,_,_,_,_,_),
939+
fold_item_fn = bind identity_fold_item_fn[ENV](_,_,_,_,_,_,_),
937940
fold_item_mod = bind identity_fold_item_mod[ENV](_,_,_,_,_),
938941
fold_item_ty = bind identity_fold_item_ty[ENV](_,_,_,_,_,_),
939942
fold_item_tag = bind identity_fold_item_tag[ENV](_,_,_,_,_),

trunk/src/comp/middle/resolve.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn lookup_name(&env e, ast.ident i) -> option.t[def] {
2929

3030
fn found_def_item(@ast.item i) -> option.t[def] {
3131
alt (i.node) {
32-
case (ast.item_fn(_, _, ?id, _)) {
32+
case (ast.item_fn(_, _, _, ?id, _)) {
3333
ret some[def](ast.def_fn(id));
3434
}
3535
case (ast.item_mod(_, _, ?id)) {
@@ -76,7 +76,7 @@ fn lookup_name(&env e, ast.ident i) -> option.t[def] {
7676

7777
case (scope_item(?it)) {
7878
alt (it.node) {
79-
case (ast.item_fn(_, ?f, _, _)) {
79+
case (ast.item_fn(_, ?f, _, _, _)) {
8080
for (ast.arg a in f.inputs) {
8181
if (_str.eq(a.ident, i)) {
8282
ret some[def](ast.def_arg(a.id));

trunk/src/comp/middle/trans.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ impure fn trans_fn(@crate_ctxt cx, &ast._fn f, ast.def_id fid) {
12951295

12961296
impure fn trans_item(@crate_ctxt cx, &ast.item item) {
12971297
alt (item.node) {
1298-
case (ast.item_fn(?name, ?f, ?fid, _)) {
1298+
case (ast.item_fn(?name, ?f, _, ?fid, _)) {
12991299
auto sub_cx = @rec(path=cx.path + "." + name with *cx);
13001300
trans_fn(sub_cx, f, fid);
13011301
}
@@ -1315,7 +1315,8 @@ impure fn trans_mod(@crate_ctxt cx, &ast._mod m) {
13151315

13161316
fn collect_item(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt {
13171317
alt (i.node) {
1318-
case (ast.item_fn(?name, ?f, ?fid, ?ann)) {
1318+
case (ast.item_fn(?name, ?f, _, ?fid, ?ann)) {
1319+
// TODO: type-params
13191320
cx.items.insert(fid, i);
13201321
auto llty = node_type(cx, ann);
13211322
let str s = cx.names.next("_rust_fn") + "." + name;

trunk/src/comp/middle/typeck.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,9 @@ fn collect_item_types(@ast.crate crate) -> tup(@ast.crate, @ty_table) {
310310
@ty_table item_to_ty,
311311
@ast.item it) -> @ty {
312312
alt (it.node) {
313-
case (ast.item_fn(?ident, ?fn_info, ?def_id, _)) {
313+
case (ast.item_fn(?ident, ?fn_info, _, ?def_id, _)) {
314+
// TODO: handle ty-params
315+
314316
auto f = bind trans_fn_arg_to_ty(id_to_ty_item, item_to_ty,
315317
_);
316318
auto input_tys = _vec.map[ast.arg,arg](f, fn_info.inputs);
@@ -362,9 +364,12 @@ fn collect_item_types(@ast.crate crate) -> tup(@ast.crate, @ty_table) {
362364
for (@ast.item it in module.items) {
363365
let ast.item_ result;
364366
alt (it.node) {
365-
case (ast.item_fn(?ident, ?fn_info, ?def_id, _)) {
367+
case (ast.item_fn(?ident, ?fn_info, ?tps, ?def_id, _)) {
368+
// TODO: type-params
369+
366370
auto t = trans_ty_item_to_ty(id_to_ty_item, item_to_ty, it);
367-
result = ast.item_fn(ident, fn_info, def_id, ast.ann_type(t));
371+
result = ast.item_fn(ident, fn_info, tps, def_id,
372+
ast.ann_type(t));
368373
}
369374
case (ast.item_ty(?ident, ?referent_ty, ?def_id, _)) {
370375
auto t = trans_ty_item_to_ty(id_to_ty_item, item_to_ty, it);
@@ -1274,7 +1279,8 @@ fn check_block(&fn_ctxt fcx, &ast.block block) -> ast.block {
12741279
}
12751280

12761281
fn check_fn(&@crate_ctxt ccx, &span sp, ast.ident ident, &ast._fn f,
1277-
ast.def_id id, ast.ann ann) -> @ast.item {
1282+
vec[ast.ty_param] ty_params, ast.def_id id,
1283+
ast.ann ann) -> @ast.item {
12781284
auto local_ty_table = @common.new_def_hash[@ty]();
12791285

12801286
// Store the type of each argument in the table.
@@ -1296,7 +1302,8 @@ fn check_fn(&@crate_ctxt ccx, &span sp, ast.ident ident, &ast._fn f,
12961302
auto block_t = check_block(fcx, f.body);
12971303
auto block_wb = writeback(fcx, block_t);
12981304
auto fn_t = rec(inputs=f.inputs, output=f.output, body=block_wb);
1299-
ret @fold.respan[ast.item_](sp, ast.item_fn(ident, fn_t, id, fn_ann));
1305+
auto item = ast.item_fn(ident, fn_t, ty_params, id, fn_ann);
1306+
ret @fold.respan[ast.item_](sp, item);
13001307
}
13011308

13021309
fn check_crate(session.session sess, @ast.crate crate) -> @ast.crate {

0 commit comments

Comments
 (0)