diff --git a/src/Makefile b/src/Makefile index 56a98b984f56..46afb56a0a2d 100644 --- a/src/Makefile +++ b/src/Makefile @@ -475,6 +475,7 @@ TEST_XFAILS_RUSTC := $(filter-out \ linear-for-loop.rs \ multiline-comment.rs \ mutual-recursion-group.rs \ + native2.rs \ obj-drop.rs \ obj-recursion.rs \ obj-with-vec.rs \ diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs index 10bcd5c4562f..9c71bcd98a3b 100644 --- a/src/comp/front/ast.rs +++ b/src/comp/front/ast.rs @@ -226,6 +226,8 @@ type _mod = rec(vec[@view_item] view_items, vec[@item] items, mod_index index); +type native_mod = rec(str native_name); + type variant_arg = rec(@ty ty, def_id id); type variant = rec(str name, vec[variant_arg] args, def_id id, ann ann); @@ -240,6 +242,7 @@ tag item_ { item_const(ident, @ty, @expr, def_id, ann); item_fn(ident, _fn, vec[ty_param], def_id, ann); item_mod(ident, _mod, def_id); + item_native_mod(ident, native_mod, def_id); item_ty(ident, @ty, vec[ty_param], def_id, ann); item_tag(ident, vec[variant], vec[ty_param], def_id); item_obj(ident, _obj, vec[ty_param], def_id, ann); @@ -267,6 +270,9 @@ fn index_item(mod_index index, @item it) { case (ast.item_mod(?id, _, _)) { index.insert(id, ast.mie_item(it)); } + case (ast.item_native_mod(?id, _, _)) { + index.insert(id, ast.mie_item(it)); + } case (ast.item_ty(?id, _, _, _, _)) { index.insert(id, ast.mie_item(it)); } diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index bef37a3cc7ea..fed71fda60b4 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -1555,6 +1555,20 @@ impure fn parse_item_mod(parser p) -> @ast.item { ret @spanned(lo, hi, item); } +impure fn parse_item_native_mod(parser p) -> @ast.item { + auto lo = p.get_span(); + expect(p, token.NATIVE); + auto native_name = parse_str_lit(p); + expect(p, token.MOD); + auto id = parse_ident(p); + expect(p, token.LBRACE); + auto m = rec(native_name = native_name); + auto hi = p.get_span(); + expect(p, token.RBRACE); + auto item = ast.item_native_mod(id, m, p.next_def_id()); + ret @spanned(lo, hi, item); +} + impure fn parse_item_type(parser p) -> @ast.item { auto lo = p.get_span(); expect(p, token.TYPE); @@ -1695,6 +1709,11 @@ impure fn parse_item(parser p) -> @ast.item { check (lyr == ast.layer_value); ret parse_item_mod(p); } + case (token.NATIVE) { + check (eff == ast.eff_pure); + check (lyr == ast.layer_value); + ret parse_item_native_mod(p); + } case (token.TYPE) { check (eff == ast.eff_pure); ret parse_item_type(p); diff --git a/src/comp/middle/fold.rs b/src/comp/middle/fold.rs index 67c260140b72..528518e7e03c 100644 --- a/src/comp/middle/fold.rs +++ b/src/comp/middle/fold.rs @@ -194,6 +194,9 @@ type ast_fold[ENV] = (fn(&ENV e, &span sp, ident ident, &ast._mod m, def_id id) -> @item) fold_item_mod, + (fn(&ENV e, &span sp, ident ident, + &ast.native_mod m, def_id id) -> @item) fold_item_native_mod, + (fn(&ENV e, &span sp, ident ident, @ty t, vec[ast.ty_param] ty_params, def_id id, ann a) -> @item) fold_item_ty, @@ -227,6 +230,8 @@ type ast_fold[ENV] = (fn(&ENV e, &ast._mod m) -> ast._mod) fold_mod, + (fn(&ENV e, &ast.native_mod m) -> ast.native_mod) fold_native_mod, + (fn(&ENV e, &span sp, &ast._mod m) -> @ast.crate) fold_crate, @@ -768,6 +773,11 @@ fn fold_item[ENV](&ENV env, ast_fold[ENV] fld, @item i) -> @item { ret fld.fold_item_mod(env_, i.span, ident, mm_, id); } + case (ast.item_native_mod(?ident, ?mm, ?id)) { + let ast.native_mod mm_ = fold_native_mod[ENV](env_, fld, mm); + ret fld.fold_item_native_mod(env_, i.span, ident, mm_, id); + } + case (ast.item_ty(?ident, ?ty, ?params, ?id, ?ann)) { let @ast.ty ty_ = fold_ty[ENV](env_, fld, ty); ret fld.fold_item_ty(env_, i.span, ident, ty_, params, id, ann); @@ -798,7 +808,6 @@ fn fold_item[ENV](&ENV env, ast_fold[ENV] fld, @item i) -> @item { fail; } - fn fold_mod[ENV](&ENV e, ast_fold[ENV] fld, &ast._mod m) -> ast._mod { let vec[@view_item] view_items = vec(); @@ -818,7 +827,12 @@ fn fold_mod[ENV](&ENV e, ast_fold[ENV] fld, &ast._mod m) -> ast._mod { } ret fld.fold_mod(e, rec(view_items=view_items, items=items, index=index)); - } +} + +fn fold_native_mod[ENV](&ENV e, ast_fold[ENV] fld, + &ast.native_mod m) -> ast.native_mod { + ret fld.fold_native_mod(e, rec(native_name = m.native_name)); +} fn fold_crate[ENV](&ENV env, ast_fold[ENV] fld, @ast.crate c) -> @ast.crate { let ENV env_ = fld.update_env_for_crate(env, c); @@ -1092,6 +1106,11 @@ fn identity_fold_item_mod[ENV](&ENV e, &span sp, ident i, ret @respan(sp, ast.item_mod(i, m, id)); } +fn identity_fold_item_native_mod[ENV](&ENV e, &span sp, ident i, + &ast.native_mod m, def_id id) -> @item { + ret @respan(sp, ast.item_native_mod(i, m, id)); +} + fn identity_fold_item_ty[ENV](&ENV e, &span sp, ident i, @ty t, vec[ast.ty_param] ty_params, def_id id, ann a) -> @item { @@ -1146,6 +1165,11 @@ fn identity_fold_mod[ENV](&ENV e, &ast._mod m) -> ast._mod { ret m; } +fn identity_fold_native_mod[ENV](&ENV e, + &ast.native_mod m) -> ast.native_mod { + ret m; +} + fn identity_fold_crate[ENV](&ENV e, &span sp, &ast._mod m) -> @ast.crate { ret @respan(sp, rec(module=m)); } @@ -1268,6 +1292,8 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] { fold_item_const= bind identity_fold_item_const[ENV](_,_,_,_,_,_,_), fold_item_fn = bind identity_fold_item_fn[ENV](_,_,_,_,_,_,_), fold_item_mod = bind identity_fold_item_mod[ENV](_,_,_,_,_), + fold_item_native_mod = + bind identity_fold_item_native_mod[ENV](_,_,_,_,_), fold_item_ty = bind identity_fold_item_ty[ENV](_,_,_,_,_,_,_), fold_item_tag = bind identity_fold_item_tag[ENV](_,_,_,_,_,_), fold_item_obj = bind identity_fold_item_obj[ENV](_,_,_,_,_,_,_), @@ -1280,6 +1306,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] { fold_block = bind identity_fold_block[ENV](_,_,_), fold_fn = bind identity_fold_fn[ENV](_,_,_,_,_,_), fold_mod = bind identity_fold_mod[ENV](_,_), + fold_native_mod = bind identity_fold_native_mod[ENV](_,_), fold_crate = bind identity_fold_crate[ENV](_,_,_), fold_obj = bind identity_fold_obj[ENV](_,_,_), diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index ea9002aeccbe..76dc3fb4fccf 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -376,6 +376,7 @@ fn collect_item_types(session.session sess, @ast.crate crate) } case (ast.item_mod(_, _, _)) { fail; } + case (ast.item_native_mod(_, _, _)) { fail; } } } @@ -455,6 +456,9 @@ fn collect_item_types(session.session sess, @ast.crate crate) case (ast.item_mod(_, _, _)) { // ignore item_mod, it has no type. } + case (ast.item_native_mod(_, _, _)) { + // ignore item_native_mod, it has no type. + } case (_) { // This call populates the ty_table with the converted type of // the item in passing; we don't need to do anything else. diff --git a/src/test/run-pass/native2.rs b/src/test/run-pass/native2.rs new file mode 100644 index 000000000000..abb6335249a0 --- /dev/null +++ b/src/test/run-pass/native2.rs @@ -0,0 +1,5 @@ +native "rust" mod rustrt { +} + +fn main(vec[str] args) { +}