1mod adt;
14mod args_exit;
15mod arith;
16mod callable;
17mod closure;
18mod collections;
19mod concurrency;
20mod float;
21mod fs;
22mod misc;
23mod os;
24mod stack;
25mod stdio;
26mod tcp;
27mod test_time;
28mod text;
29mod udp;
30
31use super::error::CodeGenError;
32use std::collections::HashMap;
33use std::fmt::Write as _;
34use std::sync::LazyLock;
35
36pub struct RuntimeDecl {
38 pub decl: &'static str,
40 pub category: Option<&'static str>,
42}
43
44pub static RUNTIME_DECLARATIONS: LazyLock<Vec<&'static RuntimeDecl>> = LazyLock::new(|| {
46 let slices: &[&[RuntimeDecl]] = &[
47 stdio::DECLS,
48 arith::DECLS,
49 stack::DECLS,
50 callable::DECLS,
51 closure::DECLS,
52 concurrency::DECLS,
53 args_exit::DECLS,
54 fs::DECLS,
55 collections::DECLS,
56 tcp::DECLS,
57 udp::DECLS,
58 os::DECLS,
59 text::DECLS,
60 adt::DECLS,
61 float::DECLS,
62 test_time::DECLS,
63 misc::DECLS,
64 ];
65 slices.iter().flat_map(|s| s.iter()).collect()
66});
67
68pub static BUILTIN_SYMBOLS: LazyLock<HashMap<&'static str, &'static str>> = LazyLock::new(|| {
75 let slices: &[&[(&str, &str)]] = &[
76 stdio::SYMBOLS,
77 args_exit::SYMBOLS,
78 arith::SYMBOLS,
79 stack::SYMBOLS,
80 concurrency::SYMBOLS,
81 callable::SYMBOLS,
82 closure::SYMBOLS,
83 tcp::SYMBOLS,
84 udp::SYMBOLS,
85 os::SYMBOLS,
86 text::SYMBOLS,
87 misc::SYMBOLS,
88 adt::SYMBOLS,
89 fs::SYMBOLS,
90 collections::SYMBOLS,
91 float::SYMBOLS,
92 test_time::SYMBOLS,
93 ];
94 slices.iter().flat_map(|s| s.iter().copied()).collect()
95});
96
97pub fn emit_runtime_decls(ir: &mut String) -> Result<(), CodeGenError> {
99 for decl in RUNTIME_DECLARATIONS.iter() {
100 if let Some(cat) = decl.category {
101 writeln!(ir, "{}", cat)?;
102 }
103 writeln!(ir, "{}", decl.decl)?;
104 }
105 writeln!(ir)?;
106 Ok(())
107}