use std::sync::Arc;
use sim_kernel::{Cx, Lib, LibManifest, Linker, Result, Symbol, TableBackend, Value};
use crate::LazyTable;
pub struct LazyBackend;
impl TableBackend for LazyBackend {
fn name(&self) -> &str {
"lazy"
}
fn new_table(&self, cx: &mut Cx, entries: Vec<(Symbol, Value)>) -> Result<Value> {
cx.factory()
.opaque(Arc::new(LazyTable::with_entries(entries)))
}
}
pub struct LazyTableLib;
impl Lib for LazyTableLib {
fn manifest(&self) -> LibManifest {
sim_table_core::backend_manifest(
Symbol::qualified("table", "lazy"),
env!("CARGO_PKG_VERSION"),
)
}
fn load(&self, _cx: &mut sim_kernel::LoadCx, _linker: &mut Linker<'_>) -> Result<()> {
Ok(())
}
}
pub fn install_lazy_table_lib(cx: &mut Cx) -> Result<()> {
let lib_id = Symbol::qualified("table", "lazy");
if cx.registry().lib(&lib_id).is_some() {
return Ok(());
}
cx.table_registry_mut().register(Arc::new(LazyBackend));
cx.load_lib(&LazyTableLib).map(|_| ())
}