Skip to content

Commit 9cfe4cd

Browse files
committed
WIP: macro games
1 parent 12a027a commit 9cfe4cd

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ crate-type = ["cdylib"]
1616
name = "data_type"
1717
crate-type = ["cdylib"]
1818

19+
[[example]]
20+
name = "macro_games"
21+
crate-type = ["cdylib"]
22+
1923
[dependencies]
2024
bitflags = "1.0"
2125
libc = "0.2"

examples/macro_games.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
//#![feature(trace_macros)]
2+
3+
#[macro_export]
4+
macro_rules! foo {
5+
( $prefix:ident, $( $x:ident ),* ) => {
6+
$(
7+
#[no_mangle]
8+
extern fn $prefix$x() { let i = $x; }
9+
)*
10+
};
11+
}
12+
13+
//trace_macros!(true);
14+
//foo![prefix, alloc_set, alloc_get, alloc_del];
15+
//trace_macros!(false);
16+
17+
fn bar() {
18+
let v = vec![1,2,3];
19+
stringify!(1);
20+
}
21+
22+
fn foo1() {
23+
#[no_mangle]
24+
extern fn foo1a() {}
25+
}
26+
27+
fn foo2() {
28+
// #[no_mangle]
29+
extern fn foo1a() {}
30+
}
31+
32+
#[macro_export]
33+
macro_rules! vec {
34+
( $( $x:expr ),* ) => {
35+
{
36+
let mut temp_vec = Vec::new();
37+
$(
38+
temp_vec.push($x);
39+
)*
40+
temp_vec
41+
}
42+
};
43+
}
44+

0 commit comments

Comments
 (0)