use lex_bytecode::Value;
use std::collections::HashMap;
use std::sync::OnceLock;
pub(crate) mod list;
pub(crate) mod str;
pub(crate) type BuiltinFn = fn(Vec<Value>) -> Result<Value, String>;
pub(crate) type Entry = (&'static str, BuiltinFn);
pub(crate) fn entries() -> Vec<((&'static str, &'static str), BuiltinFn)> {
let mut out = Vec::new();
for (module, table) in [("str", str::TABLE), ("list", list::TABLE)] {
for (name, f) in table {
out.push(((module, *name), *f));
}
}
out
}
pub(crate) fn lookup(module: &str, name: &str) -> Option<BuiltinFn> {
static TABLE: OnceLock<HashMap<(&'static str, &'static str), BuiltinFn>> = OnceLock::new();
let table = TABLE.get_or_init(|| entries().into_iter().collect());
table.get(&(module, name)).copied()
}