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;
29
30use super::error::CodeGenError;
31use std::collections::HashMap;
32use std::fmt::Write as _;
33use std::sync::LazyLock;
34
35pub struct RuntimeDecl {
37 pub decl: &'static str,
39 pub category: Option<&'static str>,
41}
42
43pub static RUNTIME_DECLARATIONS: LazyLock<Vec<&'static RuntimeDecl>> = LazyLock::new(|| {
45 let slices: &[&[RuntimeDecl]] = &[
46 stdio::DECLS,
47 arith::DECLS,
48 stack::DECLS,
49 callable::DECLS,
50 closure::DECLS,
51 concurrency::DECLS,
52 args_exit::DECLS,
53 fs::DECLS,
54 collections::DECLS,
55 tcp::DECLS,
56 os::DECLS,
57 text::DECLS,
58 adt::DECLS,
59 float::DECLS,
60 test_time::DECLS,
61 misc::DECLS,
62 ];
63 slices.iter().flat_map(|s| s.iter()).collect()
64});
65
66pub static BUILTIN_SYMBOLS: LazyLock<HashMap<&'static str, &'static str>> = LazyLock::new(|| {
73 let slices: &[&[(&str, &str)]] = &[
74 stdio::SYMBOLS,
75 args_exit::SYMBOLS,
76 arith::SYMBOLS,
77 stack::SYMBOLS,
78 concurrency::SYMBOLS,
79 callable::SYMBOLS,
80 closure::SYMBOLS,
81 tcp::SYMBOLS,
82 os::SYMBOLS,
83 text::SYMBOLS,
84 misc::SYMBOLS,
85 adt::SYMBOLS,
86 fs::SYMBOLS,
87 collections::SYMBOLS,
88 float::SYMBOLS,
89 test_time::SYMBOLS,
90 ];
91 slices.iter().flat_map(|s| s.iter().copied()).collect()
92});
93
94pub fn emit_runtime_decls(ir: &mut String) -> Result<(), CodeGenError> {
96 for decl in RUNTIME_DECLARATIONS.iter() {
97 if let Some(cat) = decl.category {
98 writeln!(ir, "{}", cat)?;
99 }
100 writeln!(ir, "{}", decl.decl)?;
101 }
102 writeln!(ir)?;
103 Ok(())
104}