1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
use cfg_match::cfg_match;
cfg_match! {
all(any(has_feature_c_unwind = "stable"), rustcall_is_fastcall) => {
/// A macro which allows definining functions, function pointer types, and extern blocks using the `"rustcall"` abi.
/// This abi matches the ABI used by lcrust v0 for `extern "Rust"` functions, without `#[track_caller]` support.
/// See [The LCRust v0 ABI](https://github.com/LightningCreations/lccc/lcrust/docs/abi/v0.md#Function-ABI) for details on the interface.
///
/// The exact expansion of this macro is unspecified and unstable. You cannot rely on the type of functions or function pointers produced by this interface, only the ABI.
///
/// Due to [a defect](https://github.com/LightningCreations/lccc/issues/6), it is undefined behaviour to panic out of functions defined with this ABI.
/// This is intended to be fixed in the future on as many compilers as possible
#[allow(clippy::doc_markdown)] // No, clippy, LCRust is not an item, it's the name of the ABI
#[macro_export]
macro_rules! rustcall {
($(#[$meta:meta])* extern "rustcall" fn $($tt:tt)*) => {
$(#[$meta])* extern "fastcall-unwind" fn $($tt)*
};
($(#[$meta:meta])* unsafe extern "rustcall" fn $($tt:tt)*) => {
$(#[$meta])* unsafe extern "fastcall-unwind" fn $($tt)*
};
($(#[$meta:meta])* $vis:vis extern "rustcall" fn $($tt:tt)*) => {
$(#[$meta])* $vis extern "fastcall-unwind" fn $($tt)*
};
($(#[$meta:meta])* $vis:vis unsafe extern "rustcall" fn $($tt:tt)*) => {
$(#[$meta])* $vis unsafe extern "fastcall-unwind" fn $($tt)*
};
($(#[$meta:meta])* extern "rustcall" { $($item:item)*}) => {
$(#[$meta])*
extern "fastcall-unwind" {
$($item)*
}
}
}
}
any(has_feature_c_unwind = "stable") => {
/// A macro which allows definining functions, function pointer types, and extern blocks using the `"rustcall"` abi.
/// This abi matches the ABI used by lcrust v0 for `extern "Rust"` functions, without `#[track_caller]` support.
/// See [The LCRust v0 ABI](https://github.com/LightningCreations/lccc/lcrust/docs/abi/v0.md#Function-ABI) for details on the interface.
///
/// The exact expansion of this macro is unspecified and unstable. You cannot rely on the type of functions or function pointers produced by this interface, only the ABI.
///
/// Due to [a defect](https://github.com/LightningCreations/lccc/issues/6), it is undefined behaviour to panic out of functions defined with this ABI.
/// This is intended to be fixed in the future on as many compilers as possible
#[allow(clippy::doc_markdown)] // No, clippy, LCRust is not an item, it's the name of the ABI
#[macro_export]
macro_rules! rustcall {
($(#[$meta:meta])* extern "rustcall" fn $($tt:tt)*) => {
$(#[$meta])* extern "C-unwind" fn $($tt)*
};
($(#[$meta:meta])* unsafe extern "rustcall" fn $($tt:tt)*) => {
$(#[$meta])* unsafe extern "C-unwind" fn $($tt)*
};
($(#[$meta:meta])* $vis:vis extern "rustcall" fn $($tt:tt)*) => {
$(#[$meta])* $vis extern "C-unwind" fn $($tt)*
};
($(#[$meta:meta])* $vis:vis unsafe extern "rustcall" fn $($tt:tt)*) => {
$(#[$meta])* $vis unsafe extern "C-unwind" fn $($tt)*
};
($(#[$meta:meta])* extern "rustcall" { $($item:item)*}) => {
$(#[$meta])*
extern "C-unwind" {
$($item)*
}
}
}
}
rustcall_is_fastcall => {
/// A macro which allows definining functions, function pointer types, and extern blocks using the `"rustcall"` abi.
/// This abi matches the ABI used by lcrust v0 for `extern "Rust"` functions, without `#[track_caller]` support.
/// See [The LCRust v0 ABI](https://github.com/LightningCreations/lccc/lcrust/docs/abi/v0.md#Function-ABI) for details on the interface.
///
/// The exact expansion of this macro is unspecified and unstable. You cannot rely on the type of functions or function pointers produced by this interface, only the ABI.
///
/// Due to [a defect](https://github.com/LightningCreations/lccc/issues/6), it is undefined behaviour to panic out of functions defined with this ABI.
/// This is intended to be fixed in the future on as many compilers as possible
#[allow(clippy::doc_markdown)] // No, clippy, LCRust is not an item, it's the name of the ABI
#[macro_export]
macro_rules! rustcall {
($(#[$meta:meta])* extern "rustcall" fn $($tt:tt)*) => {
$(#[$meta])* extern "fastcall" fn $($tt)*
};
($(#[$meta:meta])* unsafe extern "rustcall" fn $($tt:tt)*) => {
$(#[$meta])* unsafe extern "fastcall" fn $($tt)*
};
($(#[$meta:meta])* $vis:vis extern "rustcall" fn $($tt:tt)*) => {
$(#[$meta])* $vis extern "fastcall" fn $($tt)*
};
($(#[$meta:meta])* $vis:vis unsafe extern "rustcall" fn $($tt:tt)*) => {
$(#[$meta])* $vis unsafe extern "fastcall" fn $($tt)*
};
($(#[$meta:meta])* extern "rustcall" { $($item:item)*}) => {
$(#[$meta])*
extern "fastcall" {
$($item)*
}
}
}
}
_ => {
/// A macro which allows definining functions, function pointer types, and extern blocks using the `"rustcall"` abi.
/// This abi matches the ABI used by lcrust v0 for `extern "Rust"` functions, without `#[track_caller]` support.
/// See [The LCRust v0 ABI](https://github.com/LightningCreations/lccc/lcrust/docs/abi/v0.md#Function-ABI) for details on the interface.
///
/// The exact expansion of this macro is unspecified and unstable. You cannot rely on the type of functions or function pointers produced by this interface, only the ABI.
///
/// Due to [a defect](https://github.com/LightningCreations/lccc/issues/6), it is undefined behaviour to panic out of functions defined with this ABI.
/// This is intended to be fixed in the future on as many compilers as possible
#[allow(clippy::doc_markdown)] // No, clippy, LCRust is not an item, it's the name of the ABI
#[macro_export]
macro_rules! rustcall {
($(#[$meta:meta])* extern "rustcall" fn $($tt:tt)*) => {
$(#[$meta])* extern "C" fn $($tt)*
};
($(#[$meta:meta])* unsafe extern "rustcall" fn $($tt:tt)*) => {
$(#[$meta])* unsafe extern "C" fn $($tt)*
};
($(#[$meta:meta])* $vis:vis extern "rustcall" fn $($tt:tt)*) => {
$(#[$meta])* $vis extern "C" fn $($tt)*
};
($(#[$meta:meta])* $vis:vis unsafe extern "rustcall" fn $($tt:tt)*) => {
$(#[$meta])* $vis unsafe extern "C" fn $($tt)*
};
($(#[$meta:meta])* extern "rustcall" { $($item:item)*}) => {
$(#[$meta])*
extern "C" {
$($item)*
}
}
}
}
}