1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
use crate::ir::{Local, LocalId};
use crate::ty::ValType;
use id_arena::Arena;
#[derive(Debug, Default)]
pub struct ModuleLocals {
arena: Arena<Local>,
}
impl ModuleLocals {
pub fn add(&mut self, ty: ValType) -> LocalId {
let id = self.arena.next_id();
let id2 = self.arena.alloc(Local::new(id, ty));
debug_assert_eq!(id, id2);
id
}
pub fn get(&self, id: LocalId) -> &Local {
&self.arena[id]
}
pub fn get_mut(&mut self, id: LocalId) -> &mut Local {
&mut self.arena[id]
}
pub fn iter(&self) -> impl Iterator<Item = &Local> {
self.arena.iter().map(|(_, f)| f)
}
}