Skip to content

Commit a35eb9c

Browse files
author
Rafael Avila de Espindola
committed
---
yaml --- r: 1395 b: refs/heads/master c: 012fa69 h: refs/heads/master i: 1393: e91a460 1391: e15ebb2 v: v3
1 parent c7b7f7e commit a35eb9c

File tree

8 files changed

+66
-17
lines changed

8 files changed

+66
-17
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: d4bf67dde638fdeea4361daf16bee421d479628e
2+
refs/heads/master: 012fa69ea500aa31cb3dd2cd3df67ecd3eefd44e

trunk/src/comp/front/ast.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ tag item_ {
263263
type native_item = spanned[native_item_];
264264
tag native_item_ {
265265
native_item_ty(ident, def_id);
266-
native_item_fn(ident, fn_decl, vec[ty_param], def_id);
266+
native_item_fn(ident, fn_decl, vec[ty_param], def_id, ann);
267267
}
268268

269269
fn index_view_item(mod_index index, @view_item it) {
@@ -314,7 +314,7 @@ fn index_native_item(native_mod_index index, @native_item it) {
314314
case (ast.native_item_ty(?id, _)) {
315315
index.insert(id, it);
316316
}
317-
case (ast.native_item_fn(?id, _, _, _)) {
317+
case (ast.native_item_fn(?id, _, _, _, _)) {
318318
index.insert(id, it);
319319
}
320320
}

trunk/src/comp/front/parser.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1693,7 +1693,8 @@ impure fn parse_item_native_fn(parser p, ast.effect eff) -> @ast.native_item {
16931693
auto decl = parse_fn_decl(p, eff);
16941694
auto hi = p.get_span();
16951695
expect(p, token.SEMI);
1696-
auto item = ast.native_item_fn(t._1, decl, t._2, p.next_def_id());
1696+
auto item = ast.native_item_fn(t._1, decl, t._2, p.next_def_id(),
1697+
ast.ann_none);
16971698
ret @spanned(t._0, hi, item);
16981699
}
16991700

trunk/src/comp/middle/fold.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ type ast_fold[ENV] =
214214
(fn(&ENV e, &span sp, ident ident,
215215
&ast.fn_decl decl,
216216
vec[ast.ty_param] ty_params,
217-
def_id id) -> @native_item) fold_native_item_fn,
217+
def_id id, ann a) -> @native_item) fold_native_item_fn,
218218

219219
(fn(&ENV e, &span sp, ident ident,
220220
&ast._mod m, def_id id) -> @item) fold_item_mod,
@@ -921,10 +921,10 @@ fn fold_native_item[ENV](&ENV env, ast_fold[ENV] fld,
921921
case (ast.native_item_ty(?ident, ?id)) {
922922
ret fld.fold_native_item_ty(env_, i.span, ident, id);
923923
}
924-
case (ast.native_item_fn(?ident, ?fn_decl, ?ty_params, ?id)) {
924+
case (ast.native_item_fn(?ident, ?fn_decl, ?ty_params, ?id, ?ann)) {
925925
auto d = fold_fn_decl[ENV](env_, fld, fn_decl);
926926
ret fld.fold_native_item_fn(env_, i.span, ident, d,
927-
ty_params, id);
927+
ty_params, id, ann);
928928
}
929929
}
930930
}
@@ -1240,8 +1240,8 @@ fn identity_fold_item_fn[ENV](&ENV e, &span sp, ident i,
12401240
fn identity_fold_native_item_fn[ENV](&ENV e, &span sp, ident i,
12411241
&ast.fn_decl decl,
12421242
vec[ast.ty_param] ty_params,
1243-
def_id id) -> @native_item {
1244-
ret @respan(sp, ast.native_item_fn(i, decl, ty_params, id));
1243+
def_id id, ann a) -> @native_item {
1244+
ret @respan(sp, ast.native_item_fn(i, decl, ty_params, id, a));
12451245
}
12461246

12471247
fn identity_fold_item_mod[ENV](&ENV e, &span sp, ident i,
@@ -1454,7 +1454,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
14541454
fold_item_const= bind identity_fold_item_const[ENV](_,_,_,_,_,_,_),
14551455
fold_item_fn = bind identity_fold_item_fn[ENV](_,_,_,_,_,_,_),
14561456
fold_native_item_fn =
1457-
bind identity_fold_native_item_fn[ENV](_,_,_,_,_,_),
1457+
bind identity_fold_native_item_fn[ENV](_,_,_,_,_,_,_),
14581458
fold_item_mod = bind identity_fold_item_mod[ENV](_,_,_,_,_),
14591459
fold_item_native_mod =
14601460
bind identity_fold_item_native_mod[ENV](_,_,_,_,_),

trunk/src/comp/middle/resolve.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ fn lookup_name_wrapped(&env e, ast.ident i) -> option.t[tup(@env, def_wrap)] {
233233
case (ast.native_item_ty(_, ?id)) {
234234
ret def_wrap_other(ast.def_native_ty(id));
235235
}
236-
case (ast.native_item_fn(_, _, _, ?id)) {
236+
case (ast.native_item_fn(_, _, _, ?id, _)) {
237237
ret def_wrap_other(ast.def_native_fn(id));
238238
}
239239
}
@@ -381,7 +381,7 @@ fn lookup_name_wrapped(&env e, ast.ident i) -> option.t[tup(@env, def_wrap)] {
381381

382382
case (scope_native_item(?it)) {
383383
alt (it.node) {
384-
case (ast.native_item_fn(_, ?decl, ?ty_params, _)) {
384+
case (ast.native_item_fn(_, ?decl, ?ty_params, _, _)) {
385385
ret handle_fn_decl(i, decl, ty_params);
386386
}
387387
}

trunk/src/comp/middle/trans.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ state type crate_ctxt = rec(session.session sess,
7070
hashmap[str, ValueRef] item_names,
7171
hashmap[ast.def_id, ValueRef] item_ids,
7272
hashmap[ast.def_id, @ast.item] items,
73+
hashmap[ast.def_id, @ast.native_item] native_items,
7374
hashmap[ast.def_id, @tag_info] tags,
7475
hashmap[ast.def_id, ValueRef] fn_pairs,
7576
hashmap[ast.def_id, ValueRef] consts,
@@ -440,6 +441,7 @@ fn type_of_fn(@crate_ctxt cx, vec[ty.arg] inputs, @ty.t output) -> TypeRef {
440441

441442
fn type_of_inner(@crate_ctxt cx, @ty.t t) -> TypeRef {
442443
alt (t.struct) {
444+
case (ty.ty_native) { ret T_ptr(T_i8()); }
443445
case (ty.ty_nil) { ret T_nil(); }
444446
case (ty.ty_bool) { ret T_bool(); }
445447
case (ty.ty_int) { ret T_int(); }
@@ -2429,6 +2431,12 @@ fn trans_path(@block_ctxt cx, &ast.path p, &option.t[ast.def] dopt,
24292431
check (cx.fcx.ccx.consts.contains_key(did));
24302432
ret lval_mem(cx, cx.fcx.ccx.consts.get(did));
24312433
}
2434+
case (ast.def_native_fn(?did)) {
2435+
check (cx.fcx.ccx.native_items.contains_key(did));
2436+
auto fn_item = cx.fcx.ccx.native_items.get(did);
2437+
ret lval_generic_fn(cx, ty.native_item_ty(fn_item),
2438+
did, ann);
2439+
}
24322440
case (_) {
24332441
cx.fcx.ccx.sess.unimpl("def variant in trans");
24342442
}
@@ -4053,6 +4061,18 @@ fn decl_fn_and_pair(@crate_ctxt cx,
40534061
cx.fn_pairs.insert(id, gvar);
40544062
}
40554063

4064+
fn collect_native_item(&@crate_ctxt cx, @ast.native_item i) -> @crate_ctxt {
4065+
alt (i.node) {
4066+
case (ast.native_item_fn(?name, _, _, ?fid, ?ann)) {
4067+
cx.native_items.insert(fid, i);
4068+
if (! cx.obj_methods.contains_key(fid)) {
4069+
decl_fn_and_pair(cx, "fn", name, ann, fid);
4070+
}
4071+
}
4072+
case (_) { /* fall through */ }
4073+
}
4074+
ret cx;
4075+
}
40564076

40574077
fn collect_item(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt {
40584078

@@ -4101,7 +4121,8 @@ fn collect_items(@crate_ctxt cx, @ast.crate crate) {
41014121
let fold.ast_fold[@crate_ctxt] fld =
41024122
fold.new_identity_fold[@crate_ctxt]();
41034123

4104-
fld = @rec( update_env_for_item = bind collect_item(_,_)
4124+
fld = @rec( update_env_for_item = bind collect_item(_,_),
4125+
update_env_for_native_item = bind collect_native_item(_,_)
41054126
with *fld );
41064127

41074128
fold.fold_crate[@crate_ctxt](cx, fld, crate);
@@ -4559,6 +4580,7 @@ fn trans_crate(session.session sess, @ast.crate crate, str output,
45594580
item_names = new_str_hash[ValueRef](),
45604581
item_ids = new_def_hash[ValueRef](),
45614582
items = new_def_hash[@ast.item](),
4583+
native_items = new_def_hash[@ast.native_item](),
45624584
tags = new_def_hash[@tag_info](),
45634585
fn_pairs = new_def_hash[ValueRef](),
45644586
consts = new_def_hash[ValueRef](),

trunk/src/comp/middle/ty.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,22 @@ fn is_fn_ty(@t fty) -> bool {
599599
// Given an item, returns the associated type as well as a list of the IDs of
600600
// its type parameters.
601601
type ty_params_and_ty = tup(vec[ast.def_id], @t);
602+
fn native_item_ty(@ast.native_item it) -> ty_params_and_ty {
603+
auto ty_params;
604+
auto result_ty;
605+
alt (it.node) {
606+
case (ast.native_item_fn(_, _, ?tps, _, ?ann)) {
607+
ty_params = tps;
608+
result_ty = ann_to_type(ann);
609+
}
610+
}
611+
let vec[ast.def_id] ty_param_ids = vec();
612+
for (ast.ty_param tp in ty_params) {
613+
ty_param_ids += vec(tp.id);
614+
}
615+
ret tup(ty_param_ids, result_ty);
616+
}
617+
602618
fn item_ty(@ast.item it) -> ty_params_and_ty {
603619
let vec[ast.ty_param] ty_params;
604620
auto result_ty;

trunk/src/comp/middle/typeck.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ fn ty_params_of_item(@ast.item item) -> vec[ast.ty_param] {
266266

267267
fn ty_params_of_native_item(@ast.native_item item) -> vec[ast.ty_param] {
268268
alt (item.node) {
269-
case (ast.native_item_fn(_, _, ?p, _)) {
269+
case (ast.native_item_fn(_, _, ?p, _, _)) {
270270
ret p;
271271
}
272272
case (_) {
@@ -432,7 +432,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
432432
@ty_table item_to_ty,
433433
@ast.native_item it) -> @ty.t {
434434
alt (it.node) {
435-
case (ast.native_item_fn(?ident, ?fn_decl, ?params, ?def_id)) {
435+
case (ast.native_item_fn(?ident, ?fn_decl, ?params, ?def_id, _)) {
436436
auto get = bind getter(id_to_ty_item, item_to_ty, _);
437437
auto convert = bind ast_ty_to_ty(get, _);
438438
auto f = bind ty_of_arg(id_to_ty_item, item_to_ty, _);
@@ -512,8 +512,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
512512
case (ast.native_item_ty(_, ?def_id)) {
513513
id_to_ty_item.insert(def_id, any_item_native(i));
514514
}
515-
case (ast.native_item_fn(_, _, _, ?def_id)) {
516-
id_to_ty_item.insert(def_id, any_item_native(i));
515+
case (_) {
517516
}
518517
}
519518
ret id_to_ty_item;
@@ -578,6 +577,16 @@ fn collect_item_types(session.session sess, @ast.crate crate)
578577
ret @fold.respan[ast.item_](sp, item);
579578
}
580579

580+
fn fold_native_item_fn(&@env e, &span sp, ast.ident i,
581+
&ast.fn_decl d, vec[ast.ty_param] ty_params,
582+
ast.def_id id, ast.ann a) -> @ast.native_item {
583+
check (e.item_to_ty.contains_key(id));
584+
auto ty = e.item_to_ty.get(id);
585+
auto item = ast.native_item_fn(i, d, ty_params, id,
586+
ast.ann_type(ty));
587+
ret @fold.respan[ast.native_item_](sp, item);
588+
}
589+
581590
fn get_ctor_obj_methods(@ty.t t) -> vec[method] {
582591
alt (t.struct) {
583592
case (ty.ty_fn(_,?tobj)) {
@@ -663,6 +672,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
663672
update_env_for_native_item = bind convert_native(_,_),
664673
fold_item_const = bind fold_item_const(_,_,_,_,_,_,_),
665674
fold_item_fn = bind fold_item_fn(_,_,_,_,_,_,_),
675+
fold_native_item_fn = bind fold_native_item_fn(_,_,_,_,_,_,_),
666676
fold_item_obj = bind fold_item_obj(_,_,_,_,_,_,_),
667677
fold_item_ty = bind fold_item_ty(_,_,_,_,_,_,_),
668678
fold_item_tag = bind fold_item_tag(_,_,_,_,_,_)

0 commit comments

Comments
 (0)