use sim_kernel::{CodecId, Lib};
use crate::catalog::LibCatalog;
pub struct SeededLibCatalog {
libs: Vec<Box<dyn Lib>>,
}
impl SeededLibCatalog {
pub fn standard() -> Self {
let libs: Vec<Box<dyn Lib>> = vec![
Box::new(sim_lib_numbers_i64::I64NumbersLib::new()),
Box::new(sim_lib_numbers_arith::NumbersArithmeticLib::new()),
Box::new(sim_lib_numbers_bigint::BigIntNumbersLib::new()),
Box::new(sim_lib_numbers_bool::BoolNumbersLib::new()),
Box::new(sim_lib_numbers_f64::F64NumbersLib::new()),
Box::new(sim_lib_numbers_rational::RationalNumbersLib::new()),
Box::new(sim_lib_numbers_complex::ComplexNumbersLib::new()),
Box::new(sim_lib_numbers_func::FuncNumbersLib::new()),
Box::new(sim_lib_numbers_cas::CasNumbersLib::new()),
Box::new(sim_lib_numbers_tensor::TensorNumbersLib::new()),
Box::new(sim_lib_numbers_tensor_bcast::TensorBroadcastLib::new()),
Box::new(sim_lib_discrete::DiscreteLib),
Box::new(sim_lib_binding::BindingLib),
Box::new(sim_lib_control::ControlLib),
Box::new(sim_lib_sequence::SequenceLib),
Box::new(sim_lib_pattern::PatternLib),
Box::new(sim_codec_algol::AlgolCodecLib::new(CodecId(201))),
Box::new(sim_lib_lang_scheme::SchemeCodecLib::new(CodecId(202))),
Box::new(sim_lib_midi_core::MidiDigestLib),
];
Self { libs }
}
}
impl LibCatalog for SeededLibCatalog {
fn resolve(&self, name: &str) -> Option<&dyn Lib> {
self.libs
.iter()
.find(|lib| {
let id = lib.manifest().id;
id.as_qualified_str() == name || id.name.as_ref() == name
})
.map(|lib| lib.as_ref())
}
}