hara_native/vm/
source_map.rs1use crate::kernel::Position;
4
5#[derive(Debug, Clone, Default, PartialEq)]
9pub struct SourceMap {
10 positions: Vec<Option<Position>>,
11}
12
13impl SourceMap {
14 pub(crate) fn record(&mut self, position: Option<Position>) {
15 self.positions.push(position);
16 }
17
18 pub(crate) fn pop(&mut self) {
19 self.positions.pop();
20 }
21
22 pub fn position(&self, instruction: usize) -> Option<Position> {
24 self.positions.get(instruction).copied().flatten()
25 }
26
27 pub fn len(&self) -> usize {
28 self.positions.len()
29 }
30
31 pub fn is_empty(&self) -> bool {
32 self.positions.is_empty()
33 }
34}