2019-01-08 17:09:47 +00:00
|
|
|
use crate::{
|
2019-01-09 02:57:28 +00:00
|
|
|
types::{FuncSig, Map, MapIndex, SigIndex},
|
2019-01-08 17:09:47 +00:00
|
|
|
vm,
|
|
|
|
};
|
2019-01-10 04:43:18 +00:00
|
|
|
// use hashbrown::HashMap;
|
2019-01-08 17:09:47 +00:00
|
|
|
|
|
|
|
pub struct SigRegistry {
|
2019-01-10 04:43:18 +00:00
|
|
|
// func_table: HashMap<FuncSig, SigIndex>,
|
2019-01-08 17:09:47 +00:00
|
|
|
sig_assoc: Map<SigIndex, FuncSig>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl SigRegistry {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
Self {
|
2019-01-10 04:43:18 +00:00
|
|
|
// func_table: HashMap::new(),
|
2019-01-08 17:09:47 +00:00
|
|
|
sig_assoc: Map::new(),
|
|
|
|
}
|
|
|
|
}
|
2019-01-09 02:57:28 +00:00
|
|
|
|
2019-01-08 17:09:47 +00:00
|
|
|
pub fn register(&mut self, func_sig: FuncSig) -> SigIndex {
|
2019-01-10 04:43:18 +00:00
|
|
|
self.sig_assoc.push(func_sig)
|
|
|
|
// let func_table = &mut self.func_table;
|
|
|
|
// let sig_assoc = &mut self.sig_assoc;
|
|
|
|
// *func_table
|
|
|
|
// .entry(func_sig.clone())
|
|
|
|
// .or_insert_with(|| sig_assoc.push(func_sig))
|
2019-01-08 17:09:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn lookup_func_sig(&self, sig_index: SigIndex) -> &FuncSig {
|
|
|
|
&self.sig_assoc[sig_index]
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn into_vm_sigid(&self) -> Box<[vm::SigId]> {
|
2019-01-09 02:57:28 +00:00
|
|
|
let v: Vec<_> = self
|
|
|
|
.sig_assoc
|
|
|
|
.iter()
|
|
|
|
.map(|(sig_index, _)| vm::SigId(sig_index.index() as u32))
|
|
|
|
.collect();
|
2019-01-08 17:09:47 +00:00
|
|
|
v.into_boxed_slice()
|
|
|
|
}
|
|
|
|
}
|