aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRafael Ávila de Espíndola <[email protected]>2011-02-01 13:40:04 -0500
committerGraydon Hoare <[email protected]>2011-02-01 16:57:33 -0800
commit4b06dc574ba7d3ae50795cbe4f10d4be6e9c64a1 (patch)
tree1a0d2181f0bd124dfb13277fe74ca674c9db757e /src
parentPick up case for expr_block from brson's other branch. (diff)
downloadrust-4b06dc574ba7d3ae50795cbe4f10d4be6e9c64a1.tar.xz
rust-4b06dc574ba7d3ae50795cbe4f10d4be6e9c64a1.zip
Add very minimal support for native modules. For now they must be empty.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile1
-rw-r--r--src/comp/front/ast.rs6
-rw-r--r--src/comp/front/parser.rs19
-rw-r--r--src/comp/middle/fold.rs31
-rw-r--r--src/comp/middle/typeck.rs4
-rw-r--r--src/test/run-pass/native2.rs5
6 files changed, 64 insertions, 2 deletions
diff --git a/src/Makefile b/src/Makefile
index ac7dfcbb..221ec9ff 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -476,6 +476,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 be47615a..5f527f2d 100644
--- a/src/comp/front/ast.rs
+++ b/src/comp/front/ast.rs
@@ -227,6 +227,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);
@@ -241,6 +243,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);
@@ -268,6 +271,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 0c90df5c..16adfedb 100644
--- a/src/comp/front/parser.rs
+++ b/src/comp/front/parser.rs
@@ -1577,6 +1577,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);
@@ -1717,6 +1731,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 7e6839a8..2426d8ae 100644
--- a/src/comp/middle/fold.rs
+++ b/src/comp/middle/fold.rs
@@ -197,6 +197,9 @@ type ast_fold[ENV] =
&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,
@@ -229,6 +232,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,
@@ -780,6 +785,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);
@@ -810,7 +820,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();
@@ -830,7 +839,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);
@@ -1105,6 +1119,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 {
@@ -1159,6 +1178,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));
}
@@ -1281,6 +1305,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](_,_,_,_,_,_,_),
@@ -1293,6 +1319,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 725c02fd..43d35b37 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 00000000..abb63352
--- /dev/null
+++ b/src/test/run-pass/native2.rs
@@ -0,0 +1,5 @@
+native "rust" mod rustrt {
+}
+
+fn main(vec[str] args) {
+}