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
use super::utils::id_is_gensym;
use super::{Fmt, Formatter};
use wast::core::{Global, GlobalKind, GlobalType};
impl<'src> Fmt for &Global<'src> {
fn fmt(&self, formatter: &mut Formatter) {
formatter.start_line();
formatter.write("(global ");
if let Some(id) = &self.id {
if !id_is_gensym(id) {
formatter.fmt(id);
formatter.write(" ");
}
};
if !self.exports.names.is_empty() {
formatter.fmt(&self.exports);
formatter.write(" ");
};
if let GlobalKind::Import(inline_import) = &self.kind {
formatter.fmt(inline_import);
};
formatter.fmt(&self.ty);
if let GlobalKind::Inline(expression) = &self.kind {
formatter.write(" ");
formatter.fmt(expression);
};
formatter.write(")");
formatter.end_line();
}
}
impl<'src> Fmt for &GlobalType<'src> {
fn fmt(&self, formatter: &mut Formatter) {
if self.mutable {
formatter.write("(mut ");
formatter.fmt(&self.ty);
formatter.write(")");
} else {
formatter.fmt(&self.ty);
}
}
}