mod adt;
mod args_exit;
mod arith;
mod callable;
mod closure;
mod collections;
mod concurrency;
mod float;
mod fs;
mod misc;
mod os;
mod stack;
mod stdio;
mod tcp;
mod test_time;
mod text;
use super::error::CodeGenError;
use std::collections::HashMap;
use std::fmt::Write as _;
use std::sync::LazyLock;
pub struct RuntimeDecl {
pub decl: &'static str,
pub category: Option<&'static str>,
}
pub static RUNTIME_DECLARATIONS: LazyLock<Vec<&'static RuntimeDecl>> = LazyLock::new(|| {
let slices: &[&[RuntimeDecl]] = &[
stdio::DECLS,
arith::DECLS,
stack::DECLS,
callable::DECLS,
closure::DECLS,
concurrency::DECLS,
args_exit::DECLS,
fs::DECLS,
collections::DECLS,
tcp::DECLS,
os::DECLS,
text::DECLS,
adt::DECLS,
float::DECLS,
test_time::DECLS,
misc::DECLS,
];
slices.iter().flat_map(|s| s.iter()).collect()
});
pub static BUILTIN_SYMBOLS: LazyLock<HashMap<&'static str, &'static str>> = LazyLock::new(|| {
let slices: &[&[(&str, &str)]] = &[
stdio::SYMBOLS,
args_exit::SYMBOLS,
arith::SYMBOLS,
stack::SYMBOLS,
concurrency::SYMBOLS,
callable::SYMBOLS,
closure::SYMBOLS,
tcp::SYMBOLS,
os::SYMBOLS,
text::SYMBOLS,
misc::SYMBOLS,
adt::SYMBOLS,
fs::SYMBOLS,
collections::SYMBOLS,
float::SYMBOLS,
test_time::SYMBOLS,
];
slices.iter().flat_map(|s| s.iter().copied()).collect()
});
pub fn emit_runtime_decls(ir: &mut String) -> Result<(), CodeGenError> {
for decl in RUNTIME_DECLARATIONS.iter() {
if let Some(cat) = decl.category {
writeln!(ir, "{}", cat)?;
}
writeln!(ir, "{}", decl.decl)?;
}
writeln!(ir)?;
Ok(())
}