use crate::collections::HashMap;
use crate::context::Handler;
use crate::{ConstValue, Hash, Item, TypeCheck};
use std::fmt;
use std::sync::Arc;
#[derive(Default)]
pub struct RuntimeContext {
pub(crate) functions: HashMap<Hash, Arc<Handler>>,
pub(crate) types: HashMap<Hash, TypeCheck>,
pub(crate) constants: HashMap<Hash, ConstValue>,
}
impl RuntimeContext {
pub fn new() -> Self {
Self::default()
}
pub fn type_check_for(&self, item: &Item) -> Option<TypeCheck> {
Some(*self.types.get(&Hash::type_hash(item))?)
}
pub fn lookup(&self, hash: Hash) -> Option<&Arc<Handler>> {
self.functions.get(&hash)
}
pub fn constant(&self, hash: Hash) -> Option<&ConstValue> {
self.constants.get(&hash)
}
}
impl fmt::Debug for RuntimeContext {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "RuntimeContext")
}
}
#[cfg(test)]
static_assertions::assert_impl_all!(RuntimeContext: Send, Sync);