Skip to content

Commit 8ca8d12

Browse files
committed
---
yaml --- r: 1339 b: refs/heads/master c: 57bb9d8 h: refs/heads/master i: 1337: 2b8eb5a 1335: 2c60317 v: v3
1 parent e37fbc6 commit 8ca8d12

File tree

8 files changed

+102
-44
lines changed

8 files changed

+102
-44
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: 302cafa81dcc868e840c78f2bfbf41929de8a487
2+
refs/heads/master: 57bb9d809bb029caf7b38042a433153bb965e1fb

trunk/src/comp/front/ast.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,11 @@ tag ty_ {
201201
}
202202

203203
type arg = rec(mode mode, @ty ty, ident ident, def_id id);
204-
type _fn = rec(effect effect,
204+
type fn_decl = rec(effect effect,
205+
vec[arg] inputs,
206+
@ty output);
207+
type _fn = rec(fn_decl decl,
205208
bool is_iter,
206-
vec[arg] inputs,
207-
@ty output,
208209
block body);
209210

210211

@@ -254,6 +255,7 @@ tag item_ {
254255
type native_item = spanned[native_item_];
255256
tag native_item_ {
256257
native_item_ty(ident, def_id);
258+
native_item_fn(ident, fn_decl, vec[ty_param], def_id);
257259
}
258260

259261
fn index_view_item(mod_index index, @view_item it) {
@@ -304,6 +306,9 @@ fn index_native_item(native_mod_index index, @native_item it) {
304306
case (ast.native_item_ty(?id, _)) {
305307
index.insert(id, it);
306308
}
309+
case (ast.native_item_fn(?id, _, _, _)) {
310+
index.insert(id, it);
311+
}
307312
}
308313
}
309314

trunk/src/comp/front/parser.rs

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1441,7 +1441,7 @@ impure fn parse_ty_params(parser p) -> vec[ast.ty_param] {
14411441
ret ty_params;
14421442
}
14431443

1444-
impure fn parse_fn(parser p, ast.effect eff, bool is_iter) -> ast._fn {
1444+
impure fn parse_fn_decl(parser p, ast.effect eff) -> ast.fn_decl {
14451445
auto pf = parse_arg;
14461446
let util.common.spanned[vec[ast.arg]] inputs =
14471447
// FIXME: passing parse_arg as an lval doesn't work at the
@@ -1459,18 +1459,19 @@ impure fn parse_fn(parser p, ast.effect eff, bool is_iter) -> ast._fn {
14591459
} else {
14601460
output = @spanned(inputs.span, inputs.span, ast.ty_nil);
14611461
}
1462+
ret rec(effect=eff, inputs=inputs.node, output=output);
1463+
}
14621464

1465+
impure fn parse_fn(parser p, ast.effect eff, bool is_iter) -> ast._fn {
1466+
auto decl = parse_fn_decl(p, eff);
14631467
auto body = parse_block(p);
1464-
1465-
ret rec(effect = eff,
1468+
ret rec(decl = decl,
14661469
is_iter = is_iter,
1467-
inputs = inputs.node,
1468-
output = output,
14691470
body = body);
14701471
}
14711472

1472-
impure fn parse_item_fn_or_iter(parser p, ast.effect eff,
1473-
bool is_iter) -> @ast.item {
1473+
impure fn parse_fn_header(parser p, bool is_iter) -> tup(span, ast.ident,
1474+
vec[ast.ty_param]) {
14741475
auto lo = p.get_span();
14751476
if (is_iter) {
14761477
expect(p, token.ITER);
@@ -1479,10 +1480,16 @@ impure fn parse_item_fn_or_iter(parser p, ast.effect eff,
14791480
}
14801481
auto id = parse_ident(p);
14811482
auto ty_params = parse_ty_params(p);
1483+
ret tup(lo, id, ty_params);
1484+
}
1485+
1486+
impure fn parse_item_fn_or_iter(parser p, ast.effect eff,
1487+
bool is_iter) -> @ast.item {
1488+
auto t = parse_fn_header(p, is_iter);
14821489
auto f = parse_fn(p, eff, is_iter);
1483-
auto item = ast.item_fn(id, f, ty_params,
1490+
auto item = ast.item_fn(t._1, f, t._2,
14841491
p.next_def_id(), ast.ann_none);
1485-
ret @spanned(lo, f.body.span, item);
1492+
ret @spanned(t._0, f.body.span, item);
14861493
}
14871494

14881495

@@ -1585,11 +1592,24 @@ impure fn parse_item_native_type(parser p) -> @ast.native_item {
15851592
ret @spanned(t._0, hi, item);
15861593
}
15871594

1595+
impure fn parse_item_native_fn(parser p, ast.effect eff) -> @ast.native_item {
1596+
auto t = parse_fn_header(p, false);
1597+
auto decl = parse_fn_decl(p, eff);
1598+
auto hi = p.get_span();
1599+
expect(p, token.SEMI);
1600+
auto item = ast.native_item_fn(t._1, decl, t._2, p.next_def_id());
1601+
ret @spanned(t._0, hi, item);
1602+
}
1603+
15881604
impure fn parse_native_item(parser p) -> @ast.native_item {
1605+
let ast.effect eff = parse_effect(p);
15891606
alt (p.peek()) {
15901607
case (token.TYPE) {
15911608
ret parse_item_native_type(p);
15921609
}
1610+
case (token.FN) {
1611+
ret parse_item_native_fn(p, eff);
1612+
}
15931613
}
15941614
}
15951615

trunk/src/comp/middle/fold.rs

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import util.common.ty_mach;
1010
import util.common.append;
1111

1212
import front.ast;
13+
import front.ast.fn_decl;
1314
import front.ast.ident;
1415
import front.ast.path;
1516
import front.ast.mutability;
@@ -194,6 +195,11 @@ type ast_fold[ENV] =
194195
vec[ast.ty_param] ty_params,
195196
def_id id, ann a) -> @item) fold_item_fn,
196197

198+
(fn(&ENV e, &span sp, ident ident,
199+
&ast.fn_decl decl,
200+
vec[ast.ty_param] ty_params,
201+
def_id id) -> @native_item) fold_native_item_fn,
202+
197203
(fn(&ENV e, &span sp, ident ident,
198204
&ast._mod m, def_id id) -> @item) fold_item_mod,
199205

@@ -229,10 +235,13 @@ type ast_fold[ENV] =
229235
(fn(&ENV e, &span sp,
230236
&ast.block_) -> block) fold_block,
231237

232-
(fn(&ENV e, ast.effect effect,
238+
(fn(&ENV e, &fn_decl decl,
233239
bool is_iter,
240+
&block body) -> ast._fn) fold_fn,
241+
242+
(fn(&ENV e, ast.effect effect,
234243
vec[arg] inputs,
235-
@ty output, &block body) -> ast._fn) fold_fn,
244+
@ty output) -> ast.fn_decl) fold_fn_decl,
236245

237246
(fn(&ENV e, &ast._mod m) -> ast._mod) fold_mod,
238247

@@ -688,17 +697,22 @@ fn fold_arg[ENV](&ENV env, ast_fold[ENV] fld, &arg a) -> arg {
688697
ret rec(ty=ty with a);
689698
}
690699

691-
692-
fn fold_fn[ENV](&ENV env, ast_fold[ENV] fld, &ast._fn f) -> ast._fn {
693-
700+
fn fold_fn_decl[ENV](&ENV env, ast_fold[ENV] fld,
701+
&ast.fn_decl decl) -> ast.fn_decl {
694702
let vec[ast.arg] inputs = vec();
695-
for (ast.arg a in f.inputs) {
703+
for (ast.arg a in decl.inputs) {
696704
inputs += fold_arg(env, fld, a);
697705
}
698-
auto output = fold_ty[ENV](env, fld, f.output);
706+
auto output = fold_ty[ENV](env, fld, decl.output);
707+
ret fld.fold_fn_decl(env, decl.effect, inputs, output);
708+
}
709+
710+
fn fold_fn[ENV](&ENV env, ast_fold[ENV] fld, &ast._fn f) -> ast._fn {
711+
auto decl = fold_fn_decl(env, fld, f.decl);
712+
699713
auto body = fold_block[ENV](env, fld, f.body);
700714

701-
ret fld.fold_fn(env, f.effect, f.is_iter, inputs, output, body);
715+
ret fld.fold_fn(env, decl, f.is_iter, body);
702716
}
703717

704718

@@ -857,6 +871,10 @@ fn fold_native_item[ENV](&ENV env, ast_fold[ENV] fld,
857871
case (ast.native_item_ty(?ident, ?id)) {
858872
ret fld.fold_native_item_ty(env_, i.span, ident, id);
859873
}
874+
case (ast.native_item_fn(?ident, ?fn_decl, ?ty_params, ?id)) {
875+
ret fld.fold_native_item_fn(env_, i.span, ident, fn_decl,
876+
ty_params, id);
877+
}
860878
}
861879
}
862880

@@ -1144,6 +1162,13 @@ fn identity_fold_item_fn[ENV](&ENV e, &span sp, ident i,
11441162
ret @respan(sp, ast.item_fn(i, f, ty_params, id, a));
11451163
}
11461164

1165+
fn identity_fold_native_item_fn[ENV](&ENV e, &span sp, ident i,
1166+
&ast.fn_decl decl,
1167+
vec[ast.ty_param] ty_params,
1168+
def_id id) -> @native_item {
1169+
ret @respan(sp, ast.native_item_fn(i, decl, ty_params, id));
1170+
}
1171+
11471172
fn identity_fold_item_mod[ENV](&ENV e, &span sp, ident i,
11481173
&ast._mod m, def_id id) -> @item {
11491174
ret @respan(sp, ast.item_mod(i, m, id));
@@ -1199,14 +1224,18 @@ fn identity_fold_block[ENV](&ENV e, &span sp, &ast.block_ blk) -> block {
11991224
ret respan(sp, blk);
12001225
}
12011226

1227+
fn identity_fold_fn_decl[ENV](&ENV e,
1228+
ast.effect effect,
1229+
vec[arg] inputs,
1230+
@ty output) -> ast.fn_decl {
1231+
ret rec(effect=effect, inputs=inputs, output=output);
1232+
}
1233+
12021234
fn identity_fold_fn[ENV](&ENV e,
1203-
ast.effect effect,
1235+
&fn_decl decl,
12041236
bool is_iter,
1205-
vec[arg] inputs,
1206-
@ast.ty output,
12071237
&block body) -> ast._fn {
1208-
ret rec(effect=effect, is_iter=is_iter, inputs=inputs,
1209-
output=output, body=body);
1238+
ret rec(decl=decl, is_iter=is_iter, body=body);
12101239
}
12111240

12121241
fn identity_fold_mod[ENV](&ENV e, &ast._mod m) -> ast._mod {
@@ -1343,6 +1372,8 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
13431372

13441373
fold_item_const= bind identity_fold_item_const[ENV](_,_,_,_,_,_,_),
13451374
fold_item_fn = bind identity_fold_item_fn[ENV](_,_,_,_,_,_,_),
1375+
fold_native_item_fn =
1376+
bind identity_fold_native_item_fn[ENV](_,_,_,_,_,_),
13461377
fold_item_mod = bind identity_fold_item_mod[ENV](_,_,_,_,_),
13471378
fold_item_native_mod =
13481379
bind identity_fold_item_native_mod[ENV](_,_,_,_,_),
@@ -1358,7 +1389,8 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
13581389
bind identity_fold_view_item_import[ENV](_,_,_,_,_,_),
13591390

13601391
fold_block = bind identity_fold_block[ENV](_,_,_),
1361-
fold_fn = bind identity_fold_fn[ENV](_,_,_,_,_,_),
1392+
fold_fn = bind identity_fold_fn[ENV](_,_,_,_),
1393+
fold_fn_decl = bind identity_fold_fn_decl[ENV](_,_,_,_),
13621394
fold_mod = bind identity_fold_mod[ENV](_,_),
13631395
fold_native_mod = bind identity_fold_native_mod[ENV](_,_),
13641396
fold_crate = bind identity_fold_crate[ENV](_,_,_),

trunk/src/comp/middle/resolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ fn lookup_name_wrapped(&env e, ast.ident i) -> option.t[tup(@env, def_wrap)] {
283283
case (scope_item(?it)) {
284284
alt (it.node) {
285285
case (ast.item_fn(_, ?f, ?ty_params, _, _)) {
286-
for (ast.arg a in f.inputs) {
286+
for (ast.arg a in f.decl.inputs) {
287287
if (_str.eq(a.ident, i)) {
288288
auto t = ast.def_arg(a.id);
289289
ret some(def_wrap_other(t));

trunk/src/comp/middle/trans.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3553,10 +3553,10 @@ fn trans_fn(@crate_ctxt cx, &ast._fn f, ast.def_id fid,
35533553

35543554
auto fcx = new_fn_ctxt(cx, cx.path, llfndecl);
35553555
create_llargs_for_fn_args(fcx, ty_self, ret_ty_of_fn(ann),
3556-
f.inputs, ty_params);
3556+
f.decl.inputs, ty_params);
35573557
auto bcx = new_top_block_ctxt(fcx);
35583558

3559-
copy_args_to_allocas(bcx, ty_self, f.inputs,
3559+
copy_args_to_allocas(bcx, ty_self, f.decl.inputs,
35603560
arg_tys_of_fn(ann));
35613561

35623562
alt (fcx.llself) {

trunk/src/comp/middle/typeck.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,8 @@ fn collect_item_types(session.session sess, @ast.crate crate)
285285
auto get = bind getter(id_to_ty_item, item_to_ty, _);
286286
auto convert = bind ast_ty_to_ty(get, _);
287287
auto f = bind ty_of_arg(id_to_ty_item, item_to_ty, _);
288-
auto inputs = _vec.map[ast.arg,arg](f, m.node.meth.inputs);
289-
auto output = convert(m.node.meth.output);
288+
auto inputs = _vec.map[ast.arg,arg](f, m.node.meth.decl.inputs);
289+
auto output = convert(m.node.meth.decl.output);
290290
ret rec(ident=m.node.ident, inputs=inputs, output=output);
291291
}
292292

@@ -339,8 +339,9 @@ fn collect_item_types(session.session sess, @ast.crate crate)
339339
// TODO: handle ty-params
340340

341341
auto f = bind ty_of_arg(id_to_ty_item, item_to_ty, _);
342-
auto input_tys = _vec.map[ast.arg,arg](f, fn_info.inputs);
343-
auto output_ty = convert(fn_info.output);
342+
auto input_tys = _vec.map[ast.arg,arg](f,
343+
fn_info.decl.inputs);
344+
auto output_ty = convert(fn_info.decl.output);
344345

345346
auto t_fn = plain_ty(ty.ty_fn(input_tys, output_ty));
346347
item_to_ty.insert(def_id, t_fn);
@@ -1773,9 +1774,8 @@ fn check_const(&@crate_ctxt ccx, &span sp, ast.ident ident, @ast.ty t,
17731774
ret @fold.respan[ast.item_](sp, item);
17741775
}
17751776

1776-
fn check_fn(&@crate_ctxt ccx, ast.effect effect,
1777-
bool is_iter, vec[ast.arg] inputs,
1778-
@ast.ty output, &ast.block body) -> ast._fn {
1777+
fn check_fn(&@crate_ctxt ccx, &ast.fn_decl decl,
1778+
bool is_iter, &ast.block body) -> ast._fn {
17791779
auto local_ty_table = @common.new_def_hash[@ty.t]();
17801780

17811781
// FIXME: duplicate work: the item annotation already has the arg types
@@ -1789,21 +1789,21 @@ fn check_fn(&@crate_ctxt ccx, ast.effect effect,
17891789
}
17901790

17911791
// Store the type of each argument in the table.
1792-
for (ast.arg arg in inputs) {
1792+
for (ast.arg arg in decl.inputs) {
17931793
auto input_ty = ast_ty_to_ty_crate(ccx, arg.ty);
17941794
local_ty_table.insert(arg.id, input_ty);
17951795
}
17961796

1797-
let @fn_ctxt fcx = @rec(ret_ty = ast_ty_to_ty_crate(ccx, output),
1797+
let @fn_ctxt fcx = @rec(ret_ty = ast_ty_to_ty_crate(ccx, decl.output),
17981798
locals = local_ty_table,
17991799
ccx = ccx);
18001800

18011801
// TODO: Make sure the type of the block agrees with the function type.
18021802
auto block_t = check_block(fcx, body);
18031803
auto block_wb = writeback(fcx, block_t);
18041804

1805-
auto fn_t = rec(effect=effect, is_iter=is_iter,
1806-
inputs=inputs, output=output, body=block_wb);
1805+
auto fn_t = rec(decl=decl, is_iter=is_iter,
1806+
body=block_wb);
18071807
ret fn_t;
18081808
}
18091809

@@ -1816,12 +1816,12 @@ fn check_item_fn(&@crate_ctxt ccx, &span sp, ast.ident ident, &ast._fn f,
18161816
// again here, we can extract them.
18171817

18181818
let vec[arg] inputs = vec();
1819-
for (ast.arg arg in f.inputs) {
1819+
for (ast.arg arg in f.decl.inputs) {
18201820
auto input_ty = ast_ty_to_ty_crate(ccx, arg.ty);
18211821
inputs += vec(rec(mode=arg.mode, ty=input_ty));
18221822
}
18231823

1824-
auto output_ty = ast_ty_to_ty_crate(ccx, f.output);
1824+
auto output_ty = ast_ty_to_ty_crate(ccx, f.decl.output);
18251825
auto fn_sty = ty.ty_fn(inputs, output_ty);
18261826
auto fn_ann = ast.ann_type(plain_ty(fn_sty));
18271827

@@ -1854,7 +1854,7 @@ fn check_crate(session.session sess, @ast.crate crate) -> @ast.crate {
18541854
auto fld = fold.new_identity_fold[@crate_ctxt]();
18551855

18561856
fld = @rec(update_env_for_item = bind update_obj_fields(_, _),
1857-
fold_fn = bind check_fn(_,_,_,_,_,_),
1857+
fold_fn = bind check_fn(_,_,_,_),
18581858
fold_item_fn = bind check_item_fn(_,_,_,_,_,_,_)
18591859
with *fld);
18601860
ret fold.fold_crate[@crate_ctxt](ccx, fld, result._0);

trunk/src/test/run-pass/native2.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
native "rust" mod rustrt {
22
type vbuf;
3+
fn vec_buf[T](vec[T] v, uint offset) -> vbuf;
34
}
45

56
fn main(vec[str] args) {

0 commit comments

Comments
 (0)