Add AbiSet and integrate it into the AST.

I believe this patch incorporates all expected syntax changes from extern
function reform (#3678). You can now write things like:

    extern "<abi>" fn foo(s: S) -> T { ... }
    extern "<abi>" mod { ... }
    extern "<abi>" fn(S) -> T

The ABI for foreign functions is taken from this syntax (rather than from an
annotation).  We support the full ABI specification I described on the mailing
list.  The correct ABI is chosen based on the target architecture.

Calls by pointer to C functions are not yet supported, and the Rust type of
crust fns is still *u8.
This commit is contained in:
Niko Matsakis 2013-03-13 22:25:28 -04:00 committed by Brian Anderson
parent f864934f54
commit 6965fe4bce
72 changed files with 879 additions and 352 deletions

View file

@ -10,7 +10,7 @@
pub mod rusti {
#[abi = "rust-intrinsic"]
pub extern {
pub extern "rust-intrinsic" {
fn atomic_cxchg(dst: &mut int, old: int, src: int) -> int;
fn atomic_cxchg_acq(dst: &mut int, old: int, src: int) -> int;
fn atomic_cxchg_rel(dst: &mut int, old: int, src: int) -> int;
@ -18,11 +18,11 @@ pub mod rusti {
fn atomic_xchg(dst: &mut int, src: int) -> int;
fn atomic_xchg_acq(dst: &mut int, src: int) -> int;
fn atomic_xchg_rel(dst: &mut int, src: int) -> int;
fn atomic_xadd(dst: &mut int, src: int) -> int;
fn atomic_xadd_acq(dst: &mut int, src: int) -> int;
fn atomic_xadd_rel(dst: &mut int, src: int) -> int;
fn atomic_xsub(dst: &mut int, src: int) -> int;
fn atomic_xsub_acq(dst: &mut int, src: int) -> int;
fn atomic_xsub_rel(dst: &mut int, src: int) -> int;

View file

@ -19,5 +19,5 @@ fn main() {
}
f(g);
//~^ ERROR mismatched types: expected `extern fn(extern fn(extern fn()))`
//~^ ERROR mismatched types: expected `extern "Rust" fn(extern "Rust" fn(extern "Rust" fn()))`
}

View file

@ -9,5 +9,5 @@
// except according to those terms.
fn main() -> char {
//~^ ERROR Wrong type in main function: found `extern fn() -> char`
//~^ ERROR Wrong type in main function: found `extern "Rust" fn() -> char`
}

View file

@ -14,5 +14,5 @@ struct S {
}
fn main(foo: S) {
//~^ ERROR Wrong type in main function: found `extern fn(S)`
//~^ ERROR Wrong type in main function: found `extern "Rust" fn(S)`
}

View file

@ -14,6 +14,6 @@ fn foo(f: &fn()) { f() }
fn main() {
~"" || 42; //~ ERROR binary operation || cannot be applied to type `~str`
foo || {}; //~ ERROR binary operation || cannot be applied to type `extern fn(&fn())`
foo || {}; //~ ERROR binary operation || cannot be applied to type `extern "Rust" fn(&fn())`
//~^ NOTE did you forget the `do` keyword for the call?
}

View file

@ -10,7 +10,7 @@
// pp-exact
fn from_foreign_fn(x: extern fn()) { }
fn from_foreign_fn(x: extern "Rust" fn()) { }
fn from_stack_closure(x: &fn()) { }
fn from_box_closure(x: @fn()) { }
fn from_unique_closure(x: ~fn()) { }

View file

@ -12,7 +12,7 @@
mod rusti {
#[abi = "rust-intrinsic"]
pub extern {
pub extern "rust-intrinsic" {
pub fn pref_align_of<T>() -> uint;
pub fn min_align_of<T>() -> uint;
}

View file

@ -10,7 +10,7 @@
mod rusti {
#[abi = "rust-intrinsic"]
pub extern {
pub extern "rust-intrinsic" {
pub fn atomic_cxchg(dst: &mut int, old: int, src: int) -> int;
pub fn atomic_cxchg_acq(dst: &mut int, old: int, src: int) -> int;
pub fn atomic_cxchg_rel(dst: &mut int, old: int, src: int) -> int;
@ -18,11 +18,11 @@ mod rusti {
pub fn atomic_xchg(dst: &mut int, src: int) -> int;
pub fn atomic_xchg_acq(dst: &mut int, src: int) -> int;
pub fn atomic_xchg_rel(dst: &mut int, src: int) -> int;
pub fn atomic_xadd(dst: &mut int, src: int) -> int;
pub fn atomic_xadd_acq(dst: &mut int, src: int) -> int;
pub fn atomic_xadd_rel(dst: &mut int, src: int) -> int;
pub fn atomic_xsub(dst: &mut int, src: int) -> int;
pub fn atomic_xsub_acq(dst: &mut int, src: int) -> int;
pub fn atomic_xsub_rel(dst: &mut int, src: int) -> int;

View file

@ -13,7 +13,7 @@
mod rusti {
#[abi = "rust-intrinsic"]
pub extern {
pub extern "rust-intrinsic" {
pub fn frame_address(f: &once fn(*u8));
}
}

View file

@ -10,7 +10,7 @@
mod rusti {
#[abi = "rust-intrinsic"]
pub extern {
pub extern "rust-intrinsic" {
pub fn move_val_init<T>(dst: &mut T, +src: T);
pub fn move_val<T>(dst: &mut T, +src: T);
}

View file

@ -13,8 +13,8 @@
extern mod std;
mod rusti {
#[abi = "rust-intrinsic"]
pub extern {
#[abi = "rust-intrinsic"]
pub extern "rust-intrinsic" {
fn ctpop8(x: i8) -> i8;
fn ctpop16(x: i16) -> i16;
fn ctpop32(x: i32) -> i32;

View file

@ -15,8 +15,8 @@ extern mod std;
use std::cmp::FuzzyEq;
mod rusti {
#[abi = "rust-intrinsic"]
pub extern {
#[abi = "rust-intrinsic"]
pub extern "rust-intrinsic" {
fn sqrtf32(x: f32) -> f32;
fn sqrtf64(x: f64) -> f64;
fn powif32(a: f32, x: i32) -> f32;

View file

@ -45,7 +45,6 @@ pub mod pipes {
}
}
#[abi = "rust-intrinsic"]
mod rusti {
pub fn atomic_xchg(_dst: &mut int, _src: int) -> int { fail!(); }
pub fn atomic_xchg_acq(_dst: &mut int, _src: int) -> int { fail!(); }

View file

@ -11,7 +11,7 @@
mod rusti {
#[nolink]
#[abi = "rust-intrinsic"]
pub extern {
pub extern "rust-intrinsic" {
pub fn morestack_addr() -> *();
}
}

View file

@ -12,7 +12,7 @@
mod rusti {
#[abi = "rust-intrinsic"]
pub extern {
pub extern "rust-intrinsic" {
pub fn pref_align_of<T>() -> uint;
pub fn min_align_of<T>() -> uint;
}

View file

@ -12,7 +12,7 @@
mod rusti {
#[abi = "rust-intrinsic"]
pub extern {
pub extern "rust-intrinsic" {
pub fn pref_align_of<T>() -> uint;
pub fn min_align_of<T>() -> uint;
}

View file

@ -19,7 +19,7 @@ mod kernel32 {
#[cfg(target_os = "win32")]
#[abi = "stdcall"]
pub extern {
pub extern "stdcall" {
pub fn GetProcessHeap() -> HANDLE;
pub fn HeapAlloc(hHeap: HANDLE, dwFlags: DWORD, dwBytes: SIZE_T)
-> LPVOID;