Skip to content

Commit 7d5789d

Browse files
committed
---
yaml --- r: 1419 b: refs/heads/master c: ffcb461 h: refs/heads/master i: 1417: 7d171da 1415: 4a628b3 v: v3
1 parent 9a32ed6 commit 7d5789d

File tree

5 files changed

+50
-12
lines changed

5 files changed

+50
-12
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: 6849abcf7df583f58f390eb55c7b0e84dfb1bd25
2+
refs/heads/master: ffcb4613700c968041f891985927b77f70a51c0c

trunk/src/comp/front/ast.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,13 @@ type _mod = rec(vec[@view_item] view_items,
241241
vec[@item] items,
242242
mod_index index);
243243

244+
tag native_abi {
245+
native_abi_rust;
246+
native_abi_cdecl;
247+
}
248+
244249
type native_mod = rec(str native_name,
250+
native_abi abi,
245251
vec[@native_item] items,
246252
native_mod_index index);
247253
type native_mod_index = hashmap[ident,@native_item];

trunk/src/comp/front/parser.rs

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,7 +1723,8 @@ impure fn parse_native_item(parser p) -> @ast.native_item {
17231723
}
17241724

17251725
impure fn parse_native_mod_items(parser p,
1726-
str native_name) -> ast.native_mod {
1726+
str native_name,
1727+
ast.native_abi abi) -> ast.native_mod {
17271728
auto index = new_str_hash[@ast.native_item]();
17281729
let vec[@ast.native_item] items = vec();
17291730
while (p.peek() != token.RBRACE) {
@@ -1733,28 +1734,49 @@ impure fn parse_native_mod_items(parser p,
17331734
// Index the item.
17341735
ast.index_native_item(index, item);
17351736
}
1736-
ret rec(native_name=native_name, items=items, index=index);
1737+
ret rec(native_name=native_name, abi=abi,
1738+
items=items, index=index);
1739+
}
1740+
1741+
fn default_native_name(session.session sess, str id) -> str {
1742+
alt (sess.get_targ_cfg().os) {
1743+
case (session.os_win32) {
1744+
ret id + ".dll";
1745+
}
1746+
case (session.os_macos) {
1747+
ret "lib" + id + ".dylib";
1748+
}
1749+
case (session.os_linux) {
1750+
ret "lib" + id + ".so";
1751+
}
1752+
}
17371753
}
17381754

17391755
impure fn parse_item_native_mod(parser p) -> @ast.item {
17401756
auto lo = p.get_span();
17411757
expect(p, token.NATIVE);
1742-
auto has_eq;
1743-
auto native_name = "";
1744-
if (p.peek() == token.MOD) {
1745-
has_eq = true;
1746-
} else {
1747-
native_name = parse_str_lit(p);
1748-
has_eq = false;
1758+
auto abi = ast.native_abi_cdecl;
1759+
if (p.peek() != token.MOD) {
1760+
auto t = parse_str_lit(p);
1761+
if (t == "cdecl") {
1762+
} else if (t == "rust") {
1763+
abi = ast.native_abi_rust;
1764+
} else {
1765+
p.err("unsupported abi: " + t);
1766+
fail;
1767+
}
17491768
}
17501769
expect(p, token.MOD);
17511770
auto id = parse_ident(p);
1752-
if (has_eq) {
1771+
auto native_name;
1772+
if (p.peek() == token.EQ) {
17531773
expect(p, token.EQ);
17541774
native_name = parse_str_lit(p);
1775+
} else {
1776+
native_name = default_native_name(p.get_session(), id);
17551777
}
17561778
expect(p, token.LBRACE);
1757-
auto m = parse_native_mod_items(p, native_name);
1779+
auto m = parse_native_mod_items(p, native_name, ast.native_abi_cdecl);
17581780
auto hi = p.get_span();
17591781
expect(p, token.RBRACE);
17601782
auto item = ast.item_native_mod(id, m, p.next_def_id());

trunk/src/comp/middle/fold.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,7 @@ fn fold_native_mod[ENV](&ENV e, ast_fold[ENV] fld,
944944
}
945945

946946
ret fld.fold_native_mod(e, rec(native_name=m.native_name,
947+
abi=m.abi,
947948
items=items,
948949
index=index));
949950
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,18 @@ native "rust" mod rustrt {
33
fn vec_buf[T](vec[T] v, uint offset) -> vbuf;
44
}
55

6+
native "rust" mod bar = "foo" {
7+
}
8+
9+
native mod zed {
10+
}
11+
612
native mod libc = "libc.dylib" {
713
fn write(int fd, rustrt.vbuf buf, uint count) -> int;
814
}
915

16+
native "cdecl" mod baz {
17+
}
18+
1019
fn main(vec[str] args) {
1120
}

0 commit comments

Comments
 (0)