use super::{Component, Id, Primitive};
use std::collections::HashMap;
#[derive(Debug, Default)]
pub struct LibrarySignatures {
pub sigs: HashMap<Id, Primitive>,
pub paths: Vec<String>,
}
impl LibrarySignatures {
pub fn find_primitive<S>(&self, name: S) -> Option<&Primitive>
where
S: AsRef<str>,
{
self.sigs.get(&Id::from(name.as_ref()))
}
pub fn get_primitive<S>(&self, name: S) -> &Primitive
where
S: AsRef<str>,
{
&self.sigs[&Id::from(name.as_ref())]
}
}
impl From<Vec<(String, Vec<Primitive>)>> for LibrarySignatures {
fn from(externs: Vec<(String, Vec<Primitive>)>) -> Self {
let mut lib = LibrarySignatures::default();
for (path, prims) in externs {
lib.sigs
.extend(prims.into_iter().map(|p| (p.name.clone(), p)));
lib.paths.push(path);
}
lib
}
}
#[derive(Debug)]
pub struct Context {
pub components: Vec<Component>,
pub lib: LibrarySignatures,
pub debug_mode: bool,
pub synthesis_mode: bool,
pub imports: Vec<String>,
}