Skip to content

Commit 87b31a0

Browse files
cixtorgraydon
authored andcommitted
---
yaml --- r: 1331 b: refs/heads/master c: 4b06dc5 h: refs/heads/master i: 1329: 3cb9781 1327: 06c6375 v: v3
1 parent 0308e3a commit 87b31a0

File tree

7 files changed

+65
-3
lines changed

7 files changed

+65
-3
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: b3689e7c209d6caf6a0a551b9fbfe87942be723d
2+
refs/heads/master: 4b06dc574ba7d3ae50795cbe4f10d4be6e9c64a1

trunk/src/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,7 @@ TEST_XFAILS_RUSTC := $(filter-out \
476476
linear-for-loop.rs \
477477
multiline-comment.rs \
478478
mutual-recursion-group.rs \
479+
native2.rs \
479480
obj-drop.rs \
480481
obj-recursion.rs \
481482
obj-with-vec.rs \

trunk/src/comp/front/ast.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ type _mod = rec(vec[@view_item] view_items,
227227
vec[@item] items,
228228
mod_index index);
229229

230+
type native_mod = rec(str native_name);
231+
230232
type variant_arg = rec(@ty ty, def_id id);
231233
type variant = rec(str name, vec[variant_arg] args, def_id id, ann ann);
232234

@@ -241,6 +243,7 @@ tag item_ {
241243
item_const(ident, @ty, @expr, def_id, ann);
242244
item_fn(ident, _fn, vec[ty_param], def_id, ann);
243245
item_mod(ident, _mod, def_id);
246+
item_native_mod(ident, native_mod, def_id);
244247
item_ty(ident, @ty, vec[ty_param], def_id, ann);
245248
item_tag(ident, vec[variant], vec[ty_param], def_id);
246249
item_obj(ident, _obj, vec[ty_param], def_id, ann);
@@ -268,6 +271,9 @@ fn index_item(mod_index index, @item it) {
268271
case (ast.item_mod(?id, _, _)) {
269272
index.insert(id, ast.mie_item(it));
270273
}
274+
case (ast.item_native_mod(?id, _, _)) {
275+
index.insert(id, ast.mie_item(it));
276+
}
271277
case (ast.item_ty(?id, _, _, _, _)) {
272278
index.insert(id, ast.mie_item(it));
273279
}

trunk/src/comp/front/parser.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,20 @@ impure fn parse_item_mod(parser p) -> @ast.item {
15771577
ret @spanned(lo, hi, item);
15781578
}
15791579

1580+
impure fn parse_item_native_mod(parser p) -> @ast.item {
1581+
auto lo = p.get_span();
1582+
expect(p, token.NATIVE);
1583+
auto native_name = parse_str_lit(p);
1584+
expect(p, token.MOD);
1585+
auto id = parse_ident(p);
1586+
expect(p, token.LBRACE);
1587+
auto m = rec(native_name = native_name);
1588+
auto hi = p.get_span();
1589+
expect(p, token.RBRACE);
1590+
auto item = ast.item_native_mod(id, m, p.next_def_id());
1591+
ret @spanned(lo, hi, item);
1592+
}
1593+
15801594
impure fn parse_item_type(parser p) -> @ast.item {
15811595
auto lo = p.get_span();
15821596
expect(p, token.TYPE);
@@ -1717,6 +1731,11 @@ impure fn parse_item(parser p) -> @ast.item {
17171731
check (lyr == ast.layer_value);
17181732
ret parse_item_mod(p);
17191733
}
1734+
case (token.NATIVE) {
1735+
check (eff == ast.eff_pure);
1736+
check (lyr == ast.layer_value);
1737+
ret parse_item_native_mod(p);
1738+
}
17201739
case (token.TYPE) {
17211740
check (eff == ast.eff_pure);
17221741
ret parse_item_type(p);

trunk/src/comp/middle/fold.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ type ast_fold[ENV] =
196196
(fn(&ENV e, &span sp, ident ident,
197197
&ast._mod m, def_id id) -> @item) fold_item_mod,
198198

199+
(fn(&ENV e, &span sp, ident ident,
200+
&ast.native_mod m, def_id id) -> @item) fold_item_native_mod,
201+
199202
(fn(&ENV e, &span sp, ident ident,
200203
@ty t, vec[ast.ty_param] ty_params,
201204
def_id id, ann a) -> @item) fold_item_ty,
@@ -229,6 +232,8 @@ type ast_fold[ENV] =
229232

230233
(fn(&ENV e, &ast._mod m) -> ast._mod) fold_mod,
231234

235+
(fn(&ENV e, &ast.native_mod m) -> ast.native_mod) fold_native_mod,
236+
232237
(fn(&ENV e, &span sp,
233238
&ast._mod m) -> @ast.crate) fold_crate,
234239

@@ -780,6 +785,11 @@ fn fold_item[ENV](&ENV env, ast_fold[ENV] fld, @item i) -> @item {
780785
ret fld.fold_item_mod(env_, i.span, ident, mm_, id);
781786
}
782787

788+
case (ast.item_native_mod(?ident, ?mm, ?id)) {
789+
let ast.native_mod mm_ = fold_native_mod[ENV](env_, fld, mm);
790+
ret fld.fold_item_native_mod(env_, i.span, ident, mm_, id);
791+
}
792+
783793
case (ast.item_ty(?ident, ?ty, ?params, ?id, ?ann)) {
784794
let @ast.ty ty_ = fold_ty[ENV](env_, fld, ty);
785795
ret fld.fold_item_ty(env_, i.span, ident, ty_, params, id, ann);
@@ -810,7 +820,6 @@ fn fold_item[ENV](&ENV env, ast_fold[ENV] fld, @item i) -> @item {
810820
fail;
811821
}
812822

813-
814823
fn fold_mod[ENV](&ENV e, ast_fold[ENV] fld, &ast._mod m) -> ast._mod {
815824

816825
let vec[@view_item] view_items = vec();
@@ -830,7 +839,12 @@ fn fold_mod[ENV](&ENV e, ast_fold[ENV] fld, &ast._mod m) -> ast._mod {
830839
}
831840

832841
ret fld.fold_mod(e, rec(view_items=view_items, items=items, index=index));
833-
}
842+
}
843+
844+
fn fold_native_mod[ENV](&ENV e, ast_fold[ENV] fld,
845+
&ast.native_mod m) -> ast.native_mod {
846+
ret fld.fold_native_mod(e, rec(native_name = m.native_name));
847+
}
834848

835849
fn fold_crate[ENV](&ENV env, ast_fold[ENV] fld, @ast.crate c) -> @ast.crate {
836850
let ENV env_ = fld.update_env_for_crate(env, c);
@@ -1105,6 +1119,11 @@ fn identity_fold_item_mod[ENV](&ENV e, &span sp, ident i,
11051119
ret @respan(sp, ast.item_mod(i, m, id));
11061120
}
11071121

1122+
fn identity_fold_item_native_mod[ENV](&ENV e, &span sp, ident i,
1123+
&ast.native_mod m, def_id id) -> @item {
1124+
ret @respan(sp, ast.item_native_mod(i, m, id));
1125+
}
1126+
11081127
fn identity_fold_item_ty[ENV](&ENV e, &span sp, ident i,
11091128
@ty t, vec[ast.ty_param] ty_params,
11101129
def_id id, ann a) -> @item {
@@ -1159,6 +1178,11 @@ fn identity_fold_mod[ENV](&ENV e, &ast._mod m) -> ast._mod {
11591178
ret m;
11601179
}
11611180

1181+
fn identity_fold_native_mod[ENV](&ENV e,
1182+
&ast.native_mod m) -> ast.native_mod {
1183+
ret m;
1184+
}
1185+
11621186
fn identity_fold_crate[ENV](&ENV e, &span sp, &ast._mod m) -> @ast.crate {
11631187
ret @respan(sp, rec(module=m));
11641188
}
@@ -1281,6 +1305,8 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
12811305
fold_item_const= bind identity_fold_item_const[ENV](_,_,_,_,_,_,_),
12821306
fold_item_fn = bind identity_fold_item_fn[ENV](_,_,_,_,_,_,_),
12831307
fold_item_mod = bind identity_fold_item_mod[ENV](_,_,_,_,_),
1308+
fold_item_native_mod =
1309+
bind identity_fold_item_native_mod[ENV](_,_,_,_,_),
12841310
fold_item_ty = bind identity_fold_item_ty[ENV](_,_,_,_,_,_,_),
12851311
fold_item_tag = bind identity_fold_item_tag[ENV](_,_,_,_,_,_),
12861312
fold_item_obj = bind identity_fold_item_obj[ENV](_,_,_,_,_,_,_),
@@ -1293,6 +1319,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
12931319
fold_block = bind identity_fold_block[ENV](_,_,_),
12941320
fold_fn = bind identity_fold_fn[ENV](_,_,_,_,_,_),
12951321
fold_mod = bind identity_fold_mod[ENV](_,_),
1322+
fold_native_mod = bind identity_fold_native_mod[ENV](_,_),
12961323
fold_crate = bind identity_fold_crate[ENV](_,_,_),
12971324
fold_obj = bind identity_fold_obj[ENV](_,_,_),
12981325

trunk/src/comp/middle/typeck.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
376376
}
377377

378378
case (ast.item_mod(_, _, _)) { fail; }
379+
case (ast.item_native_mod(_, _, _)) { fail; }
379380
}
380381
}
381382

@@ -455,6 +456,9 @@ fn collect_item_types(session.session sess, @ast.crate crate)
455456
case (ast.item_mod(_, _, _)) {
456457
// ignore item_mod, it has no type.
457458
}
459+
case (ast.item_native_mod(_, _, _)) {
460+
// ignore item_native_mod, it has no type.
461+
}
458462
case (_) {
459463
// This call populates the ty_table with the converted type of
460464
// the item in passing; we don't need to do anything else.

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
native "rust" mod rustrt {
2+
}
3+
4+
fn main(vec[str] args) {
5+
}

0 commit comments

Comments
 (0)