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
#[macro_export]
macro_rules! foreach_builtin_function {
($mac:ident) => {
$mac! {
memory32_grow(vmctx, i32, i32) -> (i32);
table_copy(vmctx, i32, i32, i32, i32, i32) -> ();
table_init(vmctx, i32, i32, i32, i32, i32) -> ();
elem_drop(vmctx, i32) -> ();
memory_copy(vmctx, i32, i32, i32, i32, i32) -> ();
memory_fill(vmctx, i32, i32, i32, i32) -> ();
memory_init(vmctx, i32, i32, i32, i32, i32) -> ();
data_drop(vmctx, i32) -> ();
table_grow_funcref(vmctx, i32, i32, pointer) -> (i32);
table_grow_externref(vmctx, i32, i32, reference) -> (i32);
table_fill_externref(vmctx, i32, i32, reference, i32) -> ();
table_fill_funcref(vmctx, i32, i32, pointer, i32) -> ();
drop_externref(pointer) -> ();
activations_table_insert_with_gc(vmctx, reference) -> ();
externref_global_get(vmctx, i32) -> (reference);
externref_global_set(vmctx, i32, reference) -> ();
memory_atomic_notify(vmctx, i32, i32, i32) -> (i32);
memory_atomic_wait32(vmctx, i32, i32, i32, i64) -> (i32);
memory_atomic_wait64(vmctx, i32, i32, i64, i64) -> (i32);
out_of_gas(vmctx) -> ();
}
};
}
#[derive(Copy, Clone, Debug)]
pub struct BuiltinFunctionIndex(u32);
impl BuiltinFunctionIndex {
pub const fn from_u32(i: u32) -> Self {
Self(i)
}
pub const fn index(&self) -> u32 {
self.0
}
}
macro_rules! declare_indexes {
(
$(
$( #[$attr:meta] )*
$name:ident( $( $param:ident ),* ) -> ( $( $result:ident ),* );
)*
) => {
impl BuiltinFunctionIndex {
declare_indexes!(
@indices;
0;
$( $( #[$attr] )* $name; )*
);
}
};
(
@indices;
$len:expr;
) => {
pub const fn builtin_functions_total_number() -> u32 {
$len
}
};
(
@indices;
$index:expr;
$( #[$this_attr:meta] )*
$this_name:ident;
$(
$( #[$rest_attr:meta] )*
$rest_name:ident;
)*
) => {
$( #[$this_attr] )*
pub const fn $this_name() -> Self {
Self($index)
}
declare_indexes!(
@indices;
($index + 1);
$( $( #[$rest_attr] )* $rest_name; )*
);
}
}
foreach_builtin_function!(declare_indexes);